op_model_cell.c 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717
  1. /*
  2. * Cell Broadband Engine OProfile Support
  3. *
  4. * (C) Copyright IBM Corporation 2006
  5. *
  6. * Author: David Erb (djerb@us.ibm.com)
  7. * Modifications:
  8. * Carl Love <carll@us.ibm.com>
  9. * Maynard Johnson <maynardj@us.ibm.com>
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License
  13. * as published by the Free Software Foundation; either version
  14. * 2 of the License, or (at your option) any later version.
  15. */
  16. #include <linux/cpufreq.h>
  17. #include <linux/delay.h>
  18. #include <linux/jiffies.h>
  19. #include <linux/kthread.h>
  20. #include <linux/oprofile.h>
  21. #include <linux/percpu.h>
  22. #include <linux/smp.h>
  23. #include <linux/spinlock.h>
  24. #include <linux/timer.h>
  25. #include <asm/cell-pmu.h>
  26. #include <asm/cputable.h>
  27. #include <asm/firmware.h>
  28. #include <asm/io.h>
  29. #include <asm/oprofile_impl.h>
  30. #include <asm/processor.h>
  31. #include <asm/prom.h>
  32. #include <asm/ptrace.h>
  33. #include <asm/reg.h>
  34. #include <asm/rtas.h>
  35. #include <asm/cell-regs.h>
  36. #include "../platforms/cell/interrupt.h"
  37. #include "cell/pr_util.h"
  38. #define PPU_PROFILING 0
  39. #define SPU_PROFILING_CYCLES 1
  40. #define SPU_PROFILING_EVENTS 2
  41. #define SPU_EVENT_NUM_START 4100
  42. #define SPU_EVENT_NUM_STOP 4399
  43. #define SPU_PROFILE_EVENT_ADDR 4363 /* spu, address trace, decimal */
  44. #define SPU_PROFILE_EVENT_ADDR_MASK_A 0x146 /* sub unit set to zero */
  45. #define SPU_PROFILE_EVENT_ADDR_MASK_B 0x186 /* sub unit set to zero */
  46. #define NUM_SPUS_PER_NODE 8
  47. #define SPU_CYCLES_EVENT_NUM 2 /* event number for SPU_CYCLES */
  48. #define PPU_CYCLES_EVENT_NUM 1 /* event number for CYCLES */
  49. #define PPU_CYCLES_GRP_NUM 1 /* special group number for identifying
  50. * PPU_CYCLES event
  51. */
  52. #define CBE_COUNT_ALL_CYCLES 0x42800000 /* PPU cycle event specifier */
  53. #define NUM_THREADS 2 /* number of physical threads in
  54. * physical processor
  55. */
  56. #define NUM_DEBUG_BUS_WORDS 4
  57. #define NUM_INPUT_BUS_WORDS 2
  58. #define MAX_SPU_COUNT 0xFFFFFF /* maximum 24 bit LFSR value */
  59. /* Minimum HW interval timer setting to send value to trace buffer is 10 cycle.
  60. * To configure counter to send value every N cycles set counter to
  61. * 2^32 - 1 - N.
  62. */
  63. #define NUM_INTERVAL_CYC 0xFFFFFFFF - 10
  64. /*
  65. * spu_cycle_reset is the number of cycles between samples.
  66. * This variable is used for SPU profiling and should ONLY be set
  67. * at the beginning of cell_reg_setup; otherwise, it's read-only.
  68. */
  69. static unsigned int spu_cycle_reset;
  70. static unsigned int profiling_mode;
  71. static int spu_evnt_phys_spu_indx;
  72. struct pmc_cntrl_data {
  73. unsigned long vcntr;
  74. unsigned long evnts;
  75. unsigned long masks;
  76. unsigned long enabled;
  77. };
  78. /*
  79. * ibm,cbe-perftools rtas parameters
  80. */
  81. struct pm_signal {
  82. u16 cpu; /* Processor to modify */
  83. u16 sub_unit; /* hw subunit this applies to (if applicable)*/
  84. short int signal_group; /* Signal Group to Enable/Disable */
  85. u8 bus_word; /* Enable/Disable on this Trace/Trigger/Event
  86. * Bus Word(s) (bitmask)
  87. */
  88. u8 bit; /* Trigger/Event bit (if applicable) */
  89. };
  90. /*
  91. * rtas call arguments
  92. */
  93. enum {
  94. SUBFUNC_RESET = 1,
  95. SUBFUNC_ACTIVATE = 2,
  96. SUBFUNC_DEACTIVATE = 3,
  97. PASSTHRU_IGNORE = 0,
  98. PASSTHRU_ENABLE = 1,
  99. PASSTHRU_DISABLE = 2,
  100. };
  101. struct pm_cntrl {
  102. u16 enable;
  103. u16 stop_at_max;
  104. u16 trace_mode;
  105. u16 freeze;
  106. u16 count_mode;
  107. u16 spu_addr_trace;
  108. u8 trace_buf_ovflw;
  109. };
  110. static struct {
  111. u32 group_control;
  112. u32 debug_bus_control;
  113. struct pm_cntrl pm_cntrl;
  114. u32 pm07_cntrl[NR_PHYS_CTRS];
  115. } pm_regs;
  116. #define GET_SUB_UNIT(x) ((x & 0x0000f000) >> 12)
  117. #define GET_BUS_WORD(x) ((x & 0x000000f0) >> 4)
  118. #define GET_BUS_TYPE(x) ((x & 0x00000300) >> 8)
  119. #define GET_POLARITY(x) ((x & 0x00000002) >> 1)
  120. #define GET_COUNT_CYCLES(x) (x & 0x00000001)
  121. #define GET_INPUT_CONTROL(x) ((x & 0x00000004) >> 2)
  122. static DEFINE_PER_CPU(unsigned long[NR_PHYS_CTRS], pmc_values);
  123. static unsigned long spu_pm_cnt[MAX_NUMNODES * NUM_SPUS_PER_NODE];
  124. static struct pmc_cntrl_data pmc_cntrl[NUM_THREADS][NR_PHYS_CTRS];
  125. /*
  126. * The CELL profiling code makes rtas calls to setup the debug bus to
  127. * route the performance signals. Additionally, SPU profiling requires
  128. * a second rtas call to setup the hardware to capture the SPU PCs.
  129. * The EIO error value is returned if the token lookups or the rtas
  130. * call fail. The EIO error number is the best choice of the existing
  131. * error numbers. The probability of rtas related error is very low. But
  132. * by returning EIO and printing additional information to dmsg the user
  133. * will know that OProfile did not start and dmesg will tell them why.
  134. * OProfile does not support returning errors on Stop. Not a huge issue
  135. * since failure to reset the debug bus or stop the SPU PC collection is
  136. * not a fatel issue. Chances are if the Stop failed, Start doesn't work
  137. * either.
  138. */
  139. /*
  140. * Interpetation of hdw_thread:
  141. * 0 - even virtual cpus 0, 2, 4,...
  142. * 1 - odd virtual cpus 1, 3, 5, ...
  143. *
  144. * FIXME: this is strictly wrong, we need to clean this up in a number
  145. * of places. It works for now. -arnd
  146. */
  147. static u32 hdw_thread;
  148. static u32 virt_cntr_inter_mask;
  149. static struct timer_list timer_virt_cntr;
  150. static struct timer_list timer_spu_event_swap;
  151. /*
  152. * pm_signal needs to be global since it is initialized in
  153. * cell_reg_setup at the time when the necessary information
  154. * is available.
  155. */
  156. static struct pm_signal pm_signal[NR_PHYS_CTRS];
  157. static int pm_rtas_token; /* token for debug bus setup call */
  158. static int spu_rtas_token; /* token for SPU cycle profiling */
  159. static u32 reset_value[NR_PHYS_CTRS];
  160. static int num_counters;
  161. static int oprofile_running;
  162. static DEFINE_SPINLOCK(cntr_lock);
  163. static u32 ctr_enabled;
  164. static unsigned char input_bus[NUM_INPUT_BUS_WORDS];
  165. /*
  166. * Firmware interface functions
  167. */
  168. static int
  169. rtas_ibm_cbe_perftools(int subfunc, int passthru,
  170. void *address, unsigned long length)
  171. {
  172. u64 paddr = __pa(address);
  173. return rtas_call(pm_rtas_token, 5, 1, NULL, subfunc,
  174. passthru, paddr >> 32, paddr & 0xffffffff, length);
  175. }
  176. static void pm_rtas_reset_signals(u32 node)
  177. {
  178. int ret;
  179. struct pm_signal pm_signal_local;
  180. /*
  181. * The debug bus is being set to the passthru disable state.
  182. * However, the FW still expects atleast one legal signal routing
  183. * entry or it will return an error on the arguments. If we don't
  184. * supply a valid entry, we must ignore all return values. Ignoring
  185. * all return values means we might miss an error we should be
  186. * concerned about.
  187. */
  188. /* fw expects physical cpu #. */
  189. pm_signal_local.cpu = node;
  190. pm_signal_local.signal_group = 21;
  191. pm_signal_local.bus_word = 1;
  192. pm_signal_local.sub_unit = 0;
  193. pm_signal_local.bit = 0;
  194. ret = rtas_ibm_cbe_perftools(SUBFUNC_RESET, PASSTHRU_DISABLE,
  195. &pm_signal_local,
  196. sizeof(struct pm_signal));
  197. if (unlikely(ret))
  198. /*
  199. * Not a fatal error. For Oprofile stop, the oprofile
  200. * functions do not support returning an error for
  201. * failure to stop OProfile.
  202. */
  203. printk(KERN_WARNING "%s: rtas returned: %d\n",
  204. __func__, ret);
  205. }
  206. static int pm_rtas_activate_signals(u32 node, u32 count)
  207. {
  208. int ret;
  209. int i, j;
  210. struct pm_signal pm_signal_local[NR_PHYS_CTRS];
  211. /*
  212. * There is no debug setup required for the cycles event.
  213. * Note that only events in the same group can be used.
  214. * Otherwise, there will be conflicts in correctly routing
  215. * the signals on the debug bus. It is the responsibility
  216. * of the OProfile user tool to check the events are in
  217. * the same group.
  218. */
  219. i = 0;
  220. for (j = 0; j < count; j++) {
  221. if (pm_signal[j].signal_group != PPU_CYCLES_GRP_NUM) {
  222. /* fw expects physical cpu # */
  223. pm_signal_local[i].cpu = node;
  224. pm_signal_local[i].signal_group
  225. = pm_signal[j].signal_group;
  226. pm_signal_local[i].bus_word = pm_signal[j].bus_word;
  227. pm_signal_local[i].sub_unit = pm_signal[j].sub_unit;
  228. pm_signal_local[i].bit = pm_signal[j].bit;
  229. i++;
  230. }
  231. }
  232. if (i != 0) {
  233. ret = rtas_ibm_cbe_perftools(SUBFUNC_ACTIVATE, PASSTHRU_ENABLE,
  234. pm_signal_local,
  235. i * sizeof(struct pm_signal));
  236. if (unlikely(ret)) {
  237. printk(KERN_WARNING "%s: rtas returned: %d\n",
  238. __func__, ret);
  239. return -EIO;
  240. }
  241. }
  242. return 0;
  243. }
  244. /*
  245. * PM Signal functions
  246. */
  247. static void set_pm_event(u32 ctr, int event, u32 unit_mask)
  248. {
  249. struct pm_signal *p;
  250. u32 signal_bit;
  251. u32 bus_word, bus_type, count_cycles, polarity, input_control;
  252. int j, i;
  253. if (event == PPU_CYCLES_EVENT_NUM) {
  254. /* Special Event: Count all cpu cycles */
  255. pm_regs.pm07_cntrl[ctr] = CBE_COUNT_ALL_CYCLES;
  256. p = &(pm_signal[ctr]);
  257. p->signal_group = PPU_CYCLES_GRP_NUM;
  258. p->bus_word = 1;
  259. p->sub_unit = 0;
  260. p->bit = 0;
  261. goto out;
  262. } else {
  263. pm_regs.pm07_cntrl[ctr] = 0;
  264. }
  265. bus_word = GET_BUS_WORD(unit_mask);
  266. bus_type = GET_BUS_TYPE(unit_mask);
  267. count_cycles = GET_COUNT_CYCLES(unit_mask);
  268. polarity = GET_POLARITY(unit_mask);
  269. input_control = GET_INPUT_CONTROL(unit_mask);
  270. signal_bit = (event % 100);
  271. p = &(pm_signal[ctr]);
  272. p->signal_group = event / 100;
  273. p->bus_word = bus_word;
  274. p->sub_unit = GET_SUB_UNIT(unit_mask);
  275. pm_regs.pm07_cntrl[ctr] = 0;
  276. pm_regs.pm07_cntrl[ctr] |= PM07_CTR_COUNT_CYCLES(count_cycles);
  277. pm_regs.pm07_cntrl[ctr] |= PM07_CTR_POLARITY(polarity);
  278. pm_regs.pm07_cntrl[ctr] |= PM07_CTR_INPUT_CONTROL(input_control);
  279. /*
  280. * Some of the islands signal selection is based on 64 bit words.
  281. * The debug bus words are 32 bits, the input words to the performance
  282. * counters are defined as 32 bits. Need to convert the 64 bit island
  283. * specification to the appropriate 32 input bit and bus word for the
  284. * performance counter event selection. See the CELL Performance
  285. * monitoring signals manual and the Perf cntr hardware descriptions
  286. * for the details.
  287. */
  288. if (input_control == 0) {
  289. if (signal_bit > 31) {
  290. signal_bit -= 32;
  291. if (bus_word == 0x3)
  292. bus_word = 0x2;
  293. else if (bus_word == 0xc)
  294. bus_word = 0x8;
  295. }
  296. if ((bus_type == 0) && p->signal_group >= 60)
  297. bus_type = 2;
  298. if ((bus_type == 1) && p->signal_group >= 50)
  299. bus_type = 0;
  300. pm_regs.pm07_cntrl[ctr] |= PM07_CTR_INPUT_MUX(signal_bit);
  301. } else {
  302. pm_regs.pm07_cntrl[ctr] = 0;
  303. p->bit = signal_bit;
  304. }
  305. for (i = 0; i < NUM_DEBUG_BUS_WORDS; i++) {
  306. if (bus_word & (1 << i)) {
  307. pm_regs.debug_bus_control |=
  308. (bus_type << (30 - (2 * i)));
  309. for (j = 0; j < NUM_INPUT_BUS_WORDS; j++) {
  310. if (input_bus[j] == 0xff) {
  311. input_bus[j] = i;
  312. pm_regs.group_control |=
  313. (i << (30 - (2 * j)));
  314. break;
  315. }
  316. }
  317. }
  318. }
  319. out:
  320. ;
  321. }
  322. static void write_pm_cntrl(int cpu)
  323. {
  324. /*
  325. * Oprofile will use 32 bit counters, set bits 7:10 to 0
  326. * pmregs.pm_cntrl is a global
  327. */
  328. u32 val = 0;
  329. if (pm_regs.pm_cntrl.enable == 1)
  330. val |= CBE_PM_ENABLE_PERF_MON;
  331. if (pm_regs.pm_cntrl.stop_at_max == 1)
  332. val |= CBE_PM_STOP_AT_MAX;
  333. if (pm_regs.pm_cntrl.trace_mode != 0)
  334. val |= CBE_PM_TRACE_MODE_SET(pm_regs.pm_cntrl.trace_mode);
  335. if (pm_regs.pm_cntrl.trace_buf_ovflw == 1)
  336. val |= CBE_PM_TRACE_BUF_OVFLW(pm_regs.pm_cntrl.trace_buf_ovflw);
  337. if (pm_regs.pm_cntrl.freeze == 1)
  338. val |= CBE_PM_FREEZE_ALL_CTRS;
  339. val |= CBE_PM_SPU_ADDR_TRACE_SET(pm_regs.pm_cntrl.spu_addr_trace);
  340. /*
  341. * Routine set_count_mode must be called previously to set
  342. * the count mode based on the user selection of user and kernel.
  343. */
  344. val |= CBE_PM_COUNT_MODE_SET(pm_regs.pm_cntrl.count_mode);
  345. cbe_write_pm(cpu, pm_control, val);
  346. }
  347. static inline void
  348. set_count_mode(u32 kernel, u32 user)
  349. {
  350. /*
  351. * The user must specify user and kernel if they want them. If
  352. * neither is specified, OProfile will count in hypervisor mode.
  353. * pm_regs.pm_cntrl is a global
  354. */
  355. if (kernel) {
  356. if (user)
  357. pm_regs.pm_cntrl.count_mode = CBE_COUNT_ALL_MODES;
  358. else
  359. pm_regs.pm_cntrl.count_mode =
  360. CBE_COUNT_SUPERVISOR_MODE;
  361. } else {
  362. if (user)
  363. pm_regs.pm_cntrl.count_mode = CBE_COUNT_PROBLEM_MODE;
  364. else
  365. pm_regs.pm_cntrl.count_mode =
  366. CBE_COUNT_HYPERVISOR_MODE;
  367. }
  368. }
  369. static inline void enable_ctr(u32 cpu, u32 ctr, u32 *pm07_cntrl)
  370. {
  371. pm07_cntrl[ctr] |= CBE_PM_CTR_ENABLE;
  372. cbe_write_pm07_control(cpu, ctr, pm07_cntrl[ctr]);
  373. }
  374. /*
  375. * Oprofile is expected to collect data on all CPUs simultaneously.
  376. * However, there is one set of performance counters per node. There are
  377. * two hardware threads or virtual CPUs on each node. Hence, OProfile must
  378. * multiplex in time the performance counter collection on the two virtual
  379. * CPUs. The multiplexing of the performance counters is done by this
  380. * virtual counter routine.
  381. *
  382. * The pmc_values used below is defined as 'per-cpu' but its use is
  383. * more akin to 'per-node'. We need to store two sets of counter
  384. * values per node -- one for the previous run and one for the next.
  385. * The per-cpu[NR_PHYS_CTRS] gives us the storage we need. Each odd/even
  386. * pair of per-cpu arrays is used for storing the previous and next
  387. * pmc values for a given node.
  388. * NOTE: We use the per-cpu variable to improve cache performance.
  389. *
  390. * This routine will alternate loading the virtual counters for
  391. * virtual CPUs
  392. */
  393. static void cell_virtual_cntr(unsigned long data)
  394. {
  395. int i, prev_hdw_thread, next_hdw_thread;
  396. u32 cpu;
  397. unsigned long flags;
  398. /*
  399. * Make sure that the interrupt_hander and the virt counter are
  400. * not both playing with the counters on the same node.
  401. */
  402. spin_lock_irqsave(&cntr_lock, flags);
  403. prev_hdw_thread = hdw_thread;
  404. /* switch the cpu handling the interrupts */
  405. hdw_thread = 1 ^ hdw_thread;
  406. next_hdw_thread = hdw_thread;
  407. pm_regs.group_control = 0;
  408. pm_regs.debug_bus_control = 0;
  409. for (i = 0; i < NUM_INPUT_BUS_WORDS; i++)
  410. input_bus[i] = 0xff;
  411. /*
  412. * There are some per thread events. Must do the
  413. * set event, for the thread that is being started
  414. */
  415. for (i = 0; i < num_counters; i++)
  416. set_pm_event(i,
  417. pmc_cntrl[next_hdw_thread][i].evnts,
  418. pmc_cntrl[next_hdw_thread][i].masks);
  419. /*
  420. * The following is done only once per each node, but
  421. * we need cpu #, not node #, to pass to the cbe_xxx functions.
  422. */
  423. for_each_online_cpu(cpu) {
  424. if (cbe_get_hw_thread_id(cpu))
  425. continue;
  426. /*
  427. * stop counters, save counter values, restore counts
  428. * for previous thread
  429. */
  430. cbe_disable_pm(cpu);
  431. cbe_disable_pm_interrupts(cpu);
  432. for (i = 0; i < num_counters; i++) {
  433. per_cpu(pmc_values, cpu + prev_hdw_thread)[i]
  434. = cbe_read_ctr(cpu, i);
  435. if (per_cpu(pmc_values, cpu + next_hdw_thread)[i]
  436. == 0xFFFFFFFF)
  437. /* If the cntr value is 0xffffffff, we must
  438. * reset that to 0xfffffff0 when the current
  439. * thread is restarted. This will generate a
  440. * new interrupt and make sure that we never
  441. * restore the counters to the max value. If
  442. * the counters were restored to the max value,
  443. * they do not increment and no interrupts are
  444. * generated. Hence no more samples will be
  445. * collected on that cpu.
  446. */
  447. cbe_write_ctr(cpu, i, 0xFFFFFFF0);
  448. else
  449. cbe_write_ctr(cpu, i,
  450. per_cpu(pmc_values,
  451. cpu +
  452. next_hdw_thread)[i]);
  453. }
  454. /*
  455. * Switch to the other thread. Change the interrupt
  456. * and control regs to be scheduled on the CPU
  457. * corresponding to the thread to execute.
  458. */
  459. for (i = 0; i < num_counters; i++) {
  460. if (pmc_cntrl[next_hdw_thread][i].enabled) {
  461. /*
  462. * There are some per thread events.
  463. * Must do the set event, enable_cntr
  464. * for each cpu.
  465. */
  466. enable_ctr(cpu, i,
  467. pm_regs.pm07_cntrl);
  468. } else {
  469. cbe_write_pm07_control(cpu, i, 0);
  470. }
  471. }
  472. /* Enable interrupts on the CPU thread that is starting */
  473. cbe_enable_pm_interrupts(cpu, next_hdw_thread,
  474. virt_cntr_inter_mask);
  475. cbe_enable_pm(cpu);
  476. }
  477. spin_unlock_irqrestore(&cntr_lock, flags);
  478. mod_timer(&timer_virt_cntr, jiffies + HZ / 10);
  479. }
  480. static void start_virt_cntrs(void)
  481. {
  482. init_timer(&timer_virt_cntr);
  483. timer_virt_cntr.function = cell_virtual_cntr;
  484. timer_virt_cntr.data = 0UL;
  485. timer_virt_cntr.expires = jiffies + HZ / 10;
  486. add_timer(&timer_virt_cntr);
  487. }
  488. static int cell_reg_setup_spu_cycles(struct op_counter_config *ctr,
  489. struct op_system_config *sys, int num_ctrs)
  490. {
  491. spu_cycle_reset = ctr[0].count;
  492. /*
  493. * Each node will need to make the rtas call to start
  494. * and stop SPU profiling. Get the token once and store it.
  495. */
  496. spu_rtas_token = rtas_token("ibm,cbe-spu-perftools");
  497. if (unlikely(spu_rtas_token == RTAS_UNKNOWN_SERVICE)) {
  498. printk(KERN_ERR
  499. "%s: rtas token ibm,cbe-spu-perftools unknown\n",
  500. __func__);
  501. return -EIO;
  502. }
  503. return 0;
  504. }
  505. /* Unfortunately, the hardware will only support event profiling
  506. * on one SPU per node at a time. Therefore, we must time slice
  507. * the profiling across all SPUs in the node. Note, we do this
  508. * in parallel for each node. The following routine is called
  509. * periodically based on kernel timer to switch which SPU is
  510. * being monitored in a round robbin fashion.
  511. */
  512. static void spu_evnt_swap(unsigned long data)
  513. {
  514. int node;
  515. int cur_phys_spu, nxt_phys_spu, cur_spu_evnt_phys_spu_indx;
  516. unsigned long flags;
  517. int cpu;
  518. int ret;
  519. u32 interrupt_mask;
  520. /* enable interrupts on cntr 0 */
  521. interrupt_mask = CBE_PM_CTR_OVERFLOW_INTR(0);
  522. hdw_thread = 0;
  523. /* Make sure spu event interrupt handler and spu event swap
  524. * don't access the counters simultaneously.
  525. */
  526. spin_lock_irqsave(&cntr_lock, flags);
  527. cur_spu_evnt_phys_spu_indx = spu_evnt_phys_spu_indx;
  528. if (++(spu_evnt_phys_spu_indx) == NUM_SPUS_PER_NODE)
  529. spu_evnt_phys_spu_indx = 0;
  530. pm_signal[0].sub_unit = spu_evnt_phys_spu_indx;
  531. pm_signal[1].sub_unit = spu_evnt_phys_spu_indx;
  532. pm_signal[2].sub_unit = spu_evnt_phys_spu_indx;
  533. /* switch the SPU being profiled on each node */
  534. for_each_online_cpu(cpu) {
  535. if (cbe_get_hw_thread_id(cpu))
  536. continue;
  537. node = cbe_cpu_to_node(cpu);
  538. cur_phys_spu = (node * NUM_SPUS_PER_NODE)
  539. + cur_spu_evnt_phys_spu_indx;
  540. nxt_phys_spu = (node * NUM_SPUS_PER_NODE)
  541. + spu_evnt_phys_spu_indx;
  542. /*
  543. * stop counters, save counter values, restore counts
  544. * for previous physical SPU
  545. */
  546. cbe_disable_pm(cpu);
  547. cbe_disable_pm_interrupts(cpu);
  548. spu_pm_cnt[cur_phys_spu]
  549. = cbe_read_ctr(cpu, 0);
  550. /* restore previous count for the next spu to sample */
  551. /* NOTE, hardware issue, counter will not start if the
  552. * counter value is at max (0xFFFFFFFF).
  553. */
  554. if (spu_pm_cnt[nxt_phys_spu] >= 0xFFFFFFFF)
  555. cbe_write_ctr(cpu, 0, 0xFFFFFFF0);
  556. else
  557. cbe_write_ctr(cpu, 0, spu_pm_cnt[nxt_phys_spu]);
  558. pm_rtas_reset_signals(cbe_cpu_to_node(cpu));
  559. /* setup the debug bus measure the one event and
  560. * the two events to route the next SPU's PC on
  561. * the debug bus
  562. */
  563. ret = pm_rtas_activate_signals(cbe_cpu_to_node(cpu), 3);
  564. if (ret)
  565. printk(KERN_ERR "%s: pm_rtas_activate_signals failed, "
  566. "SPU event swap\n", __func__);
  567. /* clear the trace buffer, don't want to take PC for
  568. * previous SPU*/
  569. cbe_write_pm(cpu, trace_address, 0);
  570. enable_ctr(cpu, 0, pm_regs.pm07_cntrl);
  571. /* Enable interrupts on the CPU thread that is starting */
  572. cbe_enable_pm_interrupts(cpu, hdw_thread,
  573. interrupt_mask);
  574. cbe_enable_pm(cpu);
  575. }
  576. spin_unlock_irqrestore(&cntr_lock, flags);
  577. /* swap approximately every 0.1 seconds */
  578. mod_timer(&timer_spu_event_swap, jiffies + HZ / 25);
  579. }
  580. static void start_spu_event_swap(void)
  581. {
  582. init_timer(&timer_spu_event_swap);
  583. timer_spu_event_swap.function = spu_evnt_swap;
  584. timer_spu_event_swap.data = 0UL;
  585. timer_spu_event_swap.expires = jiffies + HZ / 25;
  586. add_timer(&timer_spu_event_swap);
  587. }
  588. static int cell_reg_setup_spu_events(struct op_counter_config *ctr,
  589. struct op_system_config *sys, int num_ctrs)
  590. {
  591. int i;
  592. /* routine is called once for all nodes */
  593. spu_evnt_phys_spu_indx = 0;
  594. /*
  595. * For all events except PPU CYCLEs, each node will need to make
  596. * the rtas cbe-perftools call to setup and reset the debug bus.
  597. * Make the token lookup call once and store it in the global
  598. * variable pm_rtas_token.
  599. */
  600. pm_rtas_token = rtas_token("ibm,cbe-perftools");
  601. if (unlikely(pm_rtas_token == RTAS_UNKNOWN_SERVICE)) {
  602. printk(KERN_ERR
  603. "%s: rtas token ibm,cbe-perftools unknown\n",
  604. __func__);
  605. return -EIO;
  606. }
  607. /* setup the pm_control register settings,
  608. * settings will be written per node by the
  609. * cell_cpu_setup() function.
  610. */
  611. pm_regs.pm_cntrl.trace_buf_ovflw = 1;
  612. /* Use the occurrence trace mode to have SPU PC saved
  613. * to the trace buffer. Occurrence data in trace buffer
  614. * is not used. Bit 2 must be set to store SPU addresses.
  615. */
  616. pm_regs.pm_cntrl.trace_mode = 2;
  617. pm_regs.pm_cntrl.spu_addr_trace = 0x1; /* using debug bus
  618. event 2 & 3 */
  619. /* setup the debug bus event array with the SPU PC routing events.
  620. * Note, pm_signal[0] will be filled in by set_pm_event() call below.
  621. */
  622. pm_signal[1].signal_group = SPU_PROFILE_EVENT_ADDR / 100;
  623. pm_signal[1].bus_word = GET_BUS_WORD(SPU_PROFILE_EVENT_ADDR_MASK_A);
  624. pm_signal[1].bit = SPU_PROFILE_EVENT_ADDR % 100;
  625. pm_signal[1].sub_unit = spu_evnt_phys_spu_indx;
  626. pm_signal[2].signal_group = SPU_PROFILE_EVENT_ADDR / 100;
  627. pm_signal[2].bus_word = GET_BUS_WORD(SPU_PROFILE_EVENT_ADDR_MASK_B);
  628. pm_signal[2].bit = SPU_PROFILE_EVENT_ADDR % 100;
  629. pm_signal[2].sub_unit = spu_evnt_phys_spu_indx;
  630. /* Set the user selected spu event to profile on,
  631. * note, only one SPU profiling event is supported
  632. */
  633. num_counters = 1; /* Only support one SPU event at a time */
  634. set_pm_event(0, ctr[0].event, ctr[0].unit_mask);
  635. reset_value[0] = 0xFFFFFFFF - ctr[0].count;
  636. /* global, used by cell_cpu_setup */
  637. ctr_enabled |= 1;
  638. /* Initialize the count for each SPU to the reset value */
  639. for (i=0; i < MAX_NUMNODES * NUM_SPUS_PER_NODE; i++)
  640. spu_pm_cnt[i] = reset_value[0];
  641. return 0;
  642. }
  643. static int cell_reg_setup_ppu(struct op_counter_config *ctr,
  644. struct op_system_config *sys, int num_ctrs)
  645. {
  646. /* routine is called once for all nodes */
  647. int i, j, cpu;
  648. num_counters = num_ctrs;
  649. if (unlikely(num_ctrs > NR_PHYS_CTRS)) {
  650. printk(KERN_ERR
  651. "%s: Oprofile, number of specified events " \
  652. "exceeds number of physical counters\n",
  653. __func__);
  654. return -EIO;
  655. }
  656. set_count_mode(sys->enable_kernel, sys->enable_user);
  657. /* Setup the thread 0 events */
  658. for (i = 0; i < num_ctrs; ++i) {
  659. pmc_cntrl[0][i].evnts = ctr[i].event;
  660. pmc_cntrl[0][i].masks = ctr[i].unit_mask;
  661. pmc_cntrl[0][i].enabled = ctr[i].enabled;
  662. pmc_cntrl[0][i].vcntr = i;
  663. for_each_possible_cpu(j)
  664. per_cpu(pmc_values, j)[i] = 0;
  665. }
  666. /*
  667. * Setup the thread 1 events, map the thread 0 event to the
  668. * equivalent thread 1 event.
  669. */
  670. for (i = 0; i < num_ctrs; ++i) {
  671. if ((ctr[i].event >= 2100) && (ctr[i].event <= 2111))
  672. pmc_cntrl[1][i].evnts = ctr[i].event + 19;
  673. else if (ctr[i].event == 2203)
  674. pmc_cntrl[1][i].evnts = ctr[i].event;
  675. else if ((ctr[i].event >= 2200) && (ctr[i].event <= 2215))
  676. pmc_cntrl[1][i].evnts = ctr[i].event + 16;
  677. else
  678. pmc_cntrl[1][i].evnts = ctr[i].event;
  679. pmc_cntrl[1][i].masks = ctr[i].unit_mask;
  680. pmc_cntrl[1][i].enabled = ctr[i].enabled;
  681. pmc_cntrl[1][i].vcntr = i;
  682. }
  683. for (i = 0; i < NUM_INPUT_BUS_WORDS; i++)
  684. input_bus[i] = 0xff;
  685. /*
  686. * Our counters count up, and "count" refers to
  687. * how much before the next interrupt, and we interrupt
  688. * on overflow. So we calculate the starting value
  689. * which will give us "count" until overflow.
  690. * Then we set the events on the enabled counters.
  691. */
  692. for (i = 0; i < num_counters; ++i) {
  693. /* start with virtual counter set 0 */
  694. if (pmc_cntrl[0][i].enabled) {
  695. /* Using 32bit counters, reset max - count */
  696. reset_value[i] = 0xFFFFFFFF - ctr[i].count;
  697. set_pm_event(i,
  698. pmc_cntrl[0][i].evnts,
  699. pmc_cntrl[0][i].masks);
  700. /* global, used by cell_cpu_setup */
  701. ctr_enabled |= (1 << i);
  702. }
  703. }
  704. /* initialize the previous counts for the virtual cntrs */
  705. for_each_online_cpu(cpu)
  706. for (i = 0; i < num_counters; ++i) {
  707. per_cpu(pmc_values, cpu)[i] = reset_value[i];
  708. }
  709. return 0;
  710. }
  711. /* This function is called once for all cpus combined */
  712. static int cell_reg_setup(struct op_counter_config *ctr,
  713. struct op_system_config *sys, int num_ctrs)
  714. {
  715. int ret=0;
  716. spu_cycle_reset = 0;
  717. /* initialize the spu_arr_trace value, will be reset if
  718. * doing spu event profiling.
  719. */
  720. pm_regs.group_control = 0;
  721. pm_regs.debug_bus_control = 0;
  722. pm_regs.pm_cntrl.stop_at_max = 1;
  723. pm_regs.pm_cntrl.trace_mode = 0;
  724. pm_regs.pm_cntrl.freeze = 1;
  725. pm_regs.pm_cntrl.trace_buf_ovflw = 0;
  726. pm_regs.pm_cntrl.spu_addr_trace = 0;
  727. /*
  728. * For all events except PPU CYCLEs, each node will need to make
  729. * the rtas cbe-perftools call to setup and reset the debug bus.
  730. * Make the token lookup call once and store it in the global
  731. * variable pm_rtas_token.
  732. */
  733. pm_rtas_token = rtas_token("ibm,cbe-perftools");
  734. if (unlikely(pm_rtas_token == RTAS_UNKNOWN_SERVICE)) {
  735. printk(KERN_ERR
  736. "%s: rtas token ibm,cbe-perftools unknown\n",
  737. __func__);
  738. return -EIO;
  739. }
  740. if (ctr[0].event == SPU_CYCLES_EVENT_NUM) {
  741. profiling_mode = SPU_PROFILING_CYCLES;
  742. ret = cell_reg_setup_spu_cycles(ctr, sys, num_ctrs);
  743. } else if ((ctr[0].event >= SPU_EVENT_NUM_START) &&
  744. (ctr[0].event <= SPU_EVENT_NUM_STOP)) {
  745. profiling_mode = SPU_PROFILING_EVENTS;
  746. spu_cycle_reset = ctr[0].count;
  747. /* for SPU event profiling, need to setup the
  748. * pm_signal array with the events to route the
  749. * SPU PC before making the FW call. Note, only
  750. * one SPU event for profiling can be specified
  751. * at a time.
  752. */
  753. cell_reg_setup_spu_events(ctr, sys, num_ctrs);
  754. } else {
  755. profiling_mode = PPU_PROFILING;
  756. ret = cell_reg_setup_ppu(ctr, sys, num_ctrs);
  757. }
  758. return ret;
  759. }
  760. /* This function is called once for each cpu */
  761. static int cell_cpu_setup(struct op_counter_config *cntr)
  762. {
  763. u32 cpu = smp_processor_id();
  764. u32 num_enabled = 0;
  765. int i;
  766. int ret;
  767. /* Cycle based SPU profiling does not use the performance
  768. * counters. The trace array is configured to collect
  769. * the data.
  770. */
  771. if (profiling_mode == SPU_PROFILING_CYCLES)
  772. return 0;
  773. /* There is one performance monitor per processor chip (i.e. node),
  774. * so we only need to perform this function once per node.
  775. */
  776. if (cbe_get_hw_thread_id(cpu))
  777. return 0;
  778. /* Stop all counters */
  779. cbe_disable_pm(cpu);
  780. cbe_disable_pm_interrupts(cpu);
  781. cbe_write_pm(cpu, pm_start_stop, 0);
  782. cbe_write_pm(cpu, group_control, pm_regs.group_control);
  783. cbe_write_pm(cpu, debug_bus_control, pm_regs.debug_bus_control);
  784. write_pm_cntrl(cpu);
  785. for (i = 0; i < num_counters; ++i) {
  786. if (ctr_enabled & (1 << i)) {
  787. pm_signal[num_enabled].cpu = cbe_cpu_to_node(cpu);
  788. num_enabled++;
  789. }
  790. }
  791. /*
  792. * The pm_rtas_activate_signals will return -EIO if the FW
  793. * call failed.
  794. */
  795. if (profiling_mode == SPU_PROFILING_EVENTS) {
  796. /* For SPU event profiling also need to setup the
  797. * pm interval timer
  798. */
  799. ret = pm_rtas_activate_signals(cbe_cpu_to_node(cpu),
  800. num_enabled+2);
  801. /* store PC from debug bus to Trace buffer as often
  802. * as possible (every 10 cycles)
  803. */
  804. cbe_write_pm(cpu, pm_interval, NUM_INTERVAL_CYC);
  805. return ret;
  806. } else
  807. return pm_rtas_activate_signals(cbe_cpu_to_node(cpu),
  808. num_enabled);
  809. }
  810. #define ENTRIES 303
  811. #define MAXLFSR 0xFFFFFF
  812. /* precomputed table of 24 bit LFSR values */
  813. static int initial_lfsr[] = {
  814. 8221349, 12579195, 5379618, 10097839, 7512963, 7519310, 3955098, 10753424,
  815. 15507573, 7458917, 285419, 2641121, 9780088, 3915503, 6668768, 1548716,
  816. 4885000, 8774424, 9650099, 2044357, 2304411, 9326253, 10332526, 4421547,
  817. 3440748, 10179459, 13332843, 10375561, 1313462, 8375100, 5198480, 6071392,
  818. 9341783, 1526887, 3985002, 1439429, 13923762, 7010104, 11969769, 4547026,
  819. 2040072, 4025602, 3437678, 7939992, 11444177, 4496094, 9803157, 10745556,
  820. 3671780, 4257846, 5662259, 13196905, 3237343, 12077182, 16222879, 7587769,
  821. 14706824, 2184640, 12591135, 10420257, 7406075, 3648978, 11042541, 15906893,
  822. 11914928, 4732944, 10695697, 12928164, 11980531, 4430912, 11939291, 2917017,
  823. 6119256, 4172004, 9373765, 8410071, 14788383, 5047459, 5474428, 1737756,
  824. 15967514, 13351758, 6691285, 8034329, 2856544, 14394753, 11310160, 12149558,
  825. 7487528, 7542781, 15668898, 12525138, 12790975, 3707933, 9106617, 1965401,
  826. 16219109, 12801644, 2443203, 4909502, 8762329, 3120803, 6360315, 9309720,
  827. 15164599, 10844842, 4456529, 6667610, 14924259, 884312, 6234963, 3326042,
  828. 15973422, 13919464, 5272099, 6414643, 3909029, 2764324, 5237926, 4774955,
  829. 10445906, 4955302, 5203726, 10798229, 11443419, 2303395, 333836, 9646934,
  830. 3464726, 4159182, 568492, 995747, 10318756, 13299332, 4836017, 8237783,
  831. 3878992, 2581665, 11394667, 5672745, 14412947, 3159169, 9094251, 16467278,
  832. 8671392, 15230076, 4843545, 7009238, 15504095, 1494895, 9627886, 14485051,
  833. 8304291, 252817, 12421642, 16085736, 4774072, 2456177, 4160695, 15409741,
  834. 4902868, 5793091, 13162925, 16039714, 782255, 11347835, 14884586, 366972,
  835. 16308990, 11913488, 13390465, 2958444, 10340278, 1177858, 1319431, 10426302,
  836. 2868597, 126119, 5784857, 5245324, 10903900, 16436004, 3389013, 1742384,
  837. 14674502, 10279218, 8536112, 10364279, 6877778, 14051163, 1025130, 6072469,
  838. 1988305, 8354440, 8216060, 16342977, 13112639, 3976679, 5913576, 8816697,
  839. 6879995, 14043764, 3339515, 9364420, 15808858, 12261651, 2141560, 5636398,
  840. 10345425, 10414756, 781725, 6155650, 4746914, 5078683, 7469001, 6799140,
  841. 10156444, 9667150, 10116470, 4133858, 2121972, 1124204, 1003577, 1611214,
  842. 14304602, 16221850, 13878465, 13577744, 3629235, 8772583, 10881308, 2410386,
  843. 7300044, 5378855, 9301235, 12755149, 4977682, 8083074, 10327581, 6395087,
  844. 9155434, 15501696, 7514362, 14520507, 15808945, 3244584, 4741962, 9658130,
  845. 14336147, 8654727, 7969093, 15759799, 14029445, 5038459, 9894848, 8659300,
  846. 13699287, 8834306, 10712885, 14753895, 10410465, 3373251, 309501, 9561475,
  847. 5526688, 14647426, 14209836, 5339224, 207299, 14069911, 8722990, 2290950,
  848. 3258216, 12505185, 6007317, 9218111, 14661019, 10537428, 11731949, 9027003,
  849. 6641507, 9490160, 200241, 9720425, 16277895, 10816638, 1554761, 10431375,
  850. 7467528, 6790302, 3429078, 14633753, 14428997, 11463204, 3576212, 2003426,
  851. 6123687, 820520, 9992513, 15784513, 5778891, 6428165, 8388607
  852. };
  853. /*
  854. * The hardware uses an LFSR counting sequence to determine when to capture
  855. * the SPU PCs. An LFSR sequence is like a puesdo random number sequence
  856. * where each number occurs once in the sequence but the sequence is not in
  857. * numerical order. The SPU PC capture is done when the LFSR sequence reaches
  858. * the last value in the sequence. Hence the user specified value N
  859. * corresponds to the LFSR number that is N from the end of the sequence.
  860. *
  861. * To avoid the time to compute the LFSR, a lookup table is used. The 24 bit
  862. * LFSR sequence is broken into four ranges. The spacing of the precomputed
  863. * values is adjusted in each range so the error between the user specifed
  864. * number (N) of events between samples and the actual number of events based
  865. * on the precomputed value will be les then about 6.2%. Note, if the user
  866. * specifies N < 2^16, the LFSR value that is 2^16 from the end will be used.
  867. * This is to prevent the loss of samples because the trace buffer is full.
  868. *
  869. * User specified N Step between Index in
  870. * precomputed values precomputed
  871. * table
  872. * 0 to 2^16-1 ---- 0
  873. * 2^16 to 2^16+2^19-1 2^12 1 to 128
  874. * 2^16+2^19 to 2^16+2^19+2^22-1 2^15 129 to 256
  875. * 2^16+2^19+2^22 to 2^24-1 2^18 257 to 302
  876. *
  877. *
  878. * For example, the LFSR values in the second range are computed for 2^16,
  879. * 2^16+2^12, ... , 2^19-2^16, 2^19 and stored in the table at indicies
  880. * 1, 2,..., 127, 128.
  881. *
  882. * The 24 bit LFSR value for the nth number in the sequence can be
  883. * calculated using the following code:
  884. *
  885. * #define size 24
  886. * int calculate_lfsr(int n)
  887. * {
  888. * int i;
  889. * unsigned int newlfsr0;
  890. * unsigned int lfsr = 0xFFFFFF;
  891. * unsigned int howmany = n;
  892. *
  893. * for (i = 2; i < howmany + 2; i++) {
  894. * newlfsr0 = (((lfsr >> (size - 1 - 0)) & 1) ^
  895. * ((lfsr >> (size - 1 - 1)) & 1) ^
  896. * (((lfsr >> (size - 1 - 6)) & 1) ^
  897. * ((lfsr >> (size - 1 - 23)) & 1)));
  898. *
  899. * lfsr >>= 1;
  900. * lfsr = lfsr | (newlfsr0 << (size - 1));
  901. * }
  902. * return lfsr;
  903. * }
  904. */
  905. #define V2_16 (0x1 << 16)
  906. #define V2_19 (0x1 << 19)
  907. #define V2_22 (0x1 << 22)
  908. static int calculate_lfsr(int n)
  909. {
  910. /*
  911. * The ranges and steps are in powers of 2 so the calculations
  912. * can be done using shifts rather then divide.
  913. */
  914. int index;
  915. if ((n >> 16) == 0)
  916. index = 0;
  917. else if (((n - V2_16) >> 19) == 0)
  918. index = ((n - V2_16) >> 12) + 1;
  919. else if (((n - V2_16 - V2_19) >> 22) == 0)
  920. index = ((n - V2_16 - V2_19) >> 15 ) + 1 + 128;
  921. else if (((n - V2_16 - V2_19 - V2_22) >> 24) == 0)
  922. index = ((n - V2_16 - V2_19 - V2_22) >> 18 ) + 1 + 256;
  923. else
  924. index = ENTRIES-1;
  925. /* make sure index is valid */
  926. if ((index >= ENTRIES) || (index < 0))
  927. index = ENTRIES-1;
  928. return initial_lfsr[index];
  929. }
  930. static int pm_rtas_activate_spu_profiling(u32 node)
  931. {
  932. int ret, i;
  933. struct pm_signal pm_signal_local[NUM_SPUS_PER_NODE];
  934. /*
  935. * Set up the rtas call to configure the debug bus to
  936. * route the SPU PCs. Setup the pm_signal for each SPU
  937. */
  938. for (i = 0; i < ARRAY_SIZE(pm_signal_local); i++) {
  939. pm_signal_local[i].cpu = node;
  940. pm_signal_local[i].signal_group = 41;
  941. /* spu i on word (i/2) */
  942. pm_signal_local[i].bus_word = 1 << i / 2;
  943. /* spu i */
  944. pm_signal_local[i].sub_unit = i;
  945. pm_signal_local[i].bit = 63;
  946. }
  947. ret = rtas_ibm_cbe_perftools(SUBFUNC_ACTIVATE,
  948. PASSTHRU_ENABLE, pm_signal_local,
  949. (ARRAY_SIZE(pm_signal_local)
  950. * sizeof(struct pm_signal)));
  951. if (unlikely(ret)) {
  952. printk(KERN_WARNING "%s: rtas returned: %d\n",
  953. __func__, ret);
  954. return -EIO;
  955. }
  956. return 0;
  957. }
  958. #ifdef CONFIG_CPU_FREQ
  959. static int
  960. oprof_cpufreq_notify(struct notifier_block *nb, unsigned long val, void *data)
  961. {
  962. int ret = 0;
  963. struct cpufreq_freqs *frq = data;
  964. if ((val == CPUFREQ_PRECHANGE && frq->old < frq->new) ||
  965. (val == CPUFREQ_POSTCHANGE && frq->old > frq->new))
  966. set_spu_profiling_frequency(frq->new, spu_cycle_reset);
  967. return ret;
  968. }
  969. static struct notifier_block cpu_freq_notifier_block = {
  970. .notifier_call = oprof_cpufreq_notify
  971. };
  972. #endif
  973. /*
  974. * Note the generic OProfile stop calls do not support returning
  975. * an error on stop. Hence, will not return an error if the FW
  976. * calls fail on stop. Failure to reset the debug bus is not an issue.
  977. * Failure to disable the SPU profiling is not an issue. The FW calls
  978. * to enable the performance counters and debug bus will work even if
  979. * the hardware was not cleanly reset.
  980. */
  981. static void cell_global_stop_spu_cycles(void)
  982. {
  983. int subfunc, rtn_value;
  984. unsigned int lfsr_value;
  985. int cpu;
  986. oprofile_running = 0;
  987. smp_wmb();
  988. #ifdef CONFIG_CPU_FREQ
  989. cpufreq_unregister_notifier(&cpu_freq_notifier_block,
  990. CPUFREQ_TRANSITION_NOTIFIER);
  991. #endif
  992. for_each_online_cpu(cpu) {
  993. if (cbe_get_hw_thread_id(cpu))
  994. continue;
  995. subfunc = 3; /*
  996. * 2 - activate SPU tracing,
  997. * 3 - deactivate
  998. */
  999. lfsr_value = 0x8f100000;
  1000. rtn_value = rtas_call(spu_rtas_token, 3, 1, NULL,
  1001. subfunc, cbe_cpu_to_node(cpu),
  1002. lfsr_value);
  1003. if (unlikely(rtn_value != 0)) {
  1004. printk(KERN_ERR
  1005. "%s: rtas call ibm,cbe-spu-perftools " \
  1006. "failed, return = %d\n",
  1007. __func__, rtn_value);
  1008. }
  1009. /* Deactivate the signals */
  1010. pm_rtas_reset_signals(cbe_cpu_to_node(cpu));
  1011. }
  1012. stop_spu_profiling_cycles();
  1013. }
  1014. static void cell_global_stop_spu_events(void)
  1015. {
  1016. int cpu;
  1017. oprofile_running = 0;
  1018. stop_spu_profiling_events();
  1019. smp_wmb();
  1020. for_each_online_cpu(cpu) {
  1021. if (cbe_get_hw_thread_id(cpu))
  1022. continue;
  1023. cbe_sync_irq(cbe_cpu_to_node(cpu));
  1024. /* Stop the counters */
  1025. cbe_disable_pm(cpu);
  1026. cbe_write_pm07_control(cpu, 0, 0);
  1027. /* Deactivate the signals */
  1028. pm_rtas_reset_signals(cbe_cpu_to_node(cpu));
  1029. /* Deactivate interrupts */
  1030. cbe_disable_pm_interrupts(cpu);
  1031. }
  1032. del_timer_sync(&timer_spu_event_swap);
  1033. }
  1034. static void cell_global_stop_ppu(void)
  1035. {
  1036. int cpu;
  1037. /*
  1038. * This routine will be called once for the system.
  1039. * There is one performance monitor per node, so we
  1040. * only need to perform this function once per node.
  1041. */
  1042. del_timer_sync(&timer_virt_cntr);
  1043. oprofile_running = 0;
  1044. smp_wmb();
  1045. for_each_online_cpu(cpu) {
  1046. if (cbe_get_hw_thread_id(cpu))
  1047. continue;
  1048. cbe_sync_irq(cbe_cpu_to_node(cpu));
  1049. /* Stop the counters */
  1050. cbe_disable_pm(cpu);
  1051. /* Deactivate the signals */
  1052. pm_rtas_reset_signals(cbe_cpu_to_node(cpu));
  1053. /* Deactivate interrupts */
  1054. cbe_disable_pm_interrupts(cpu);
  1055. }
  1056. }
  1057. static void cell_global_stop(void)
  1058. {
  1059. if (profiling_mode == PPU_PROFILING)
  1060. cell_global_stop_ppu();
  1061. else if (profiling_mode == SPU_PROFILING_EVENTS)
  1062. cell_global_stop_spu_events();
  1063. else
  1064. cell_global_stop_spu_cycles();
  1065. }
  1066. static int cell_global_start_spu_cycles(struct op_counter_config *ctr)
  1067. {
  1068. int subfunc;
  1069. unsigned int lfsr_value;
  1070. int cpu;
  1071. int ret;
  1072. int rtas_error;
  1073. unsigned int cpu_khzfreq = 0;
  1074. /* The SPU profiling uses time-based profiling based on
  1075. * cpu frequency, so if configured with the CPU_FREQ
  1076. * option, we should detect frequency changes and react
  1077. * accordingly.
  1078. */
  1079. #ifdef CONFIG_CPU_FREQ
  1080. ret = cpufreq_register_notifier(&cpu_freq_notifier_block,
  1081. CPUFREQ_TRANSITION_NOTIFIER);
  1082. if (ret < 0)
  1083. /* this is not a fatal error */
  1084. printk(KERN_ERR "CPU freq change registration failed: %d\n",
  1085. ret);
  1086. else
  1087. cpu_khzfreq = cpufreq_quick_get(smp_processor_id());
  1088. #endif
  1089. set_spu_profiling_frequency(cpu_khzfreq, spu_cycle_reset);
  1090. for_each_online_cpu(cpu) {
  1091. if (cbe_get_hw_thread_id(cpu))
  1092. continue;
  1093. /*
  1094. * Setup SPU cycle-based profiling.
  1095. * Set perf_mon_control bit 0 to a zero before
  1096. * enabling spu collection hardware.
  1097. */
  1098. cbe_write_pm(cpu, pm_control, 0);
  1099. if (spu_cycle_reset > MAX_SPU_COUNT)
  1100. /* use largest possible value */
  1101. lfsr_value = calculate_lfsr(MAX_SPU_COUNT-1);
  1102. else
  1103. lfsr_value = calculate_lfsr(spu_cycle_reset);
  1104. /* must use a non zero value. Zero disables data collection. */
  1105. if (lfsr_value == 0)
  1106. lfsr_value = calculate_lfsr(1);
  1107. lfsr_value = lfsr_value << 8; /* shift lfsr to correct
  1108. * register location
  1109. */
  1110. /* debug bus setup */
  1111. ret = pm_rtas_activate_spu_profiling(cbe_cpu_to_node(cpu));
  1112. if (unlikely(ret)) {
  1113. rtas_error = ret;
  1114. goto out;
  1115. }
  1116. subfunc = 2; /* 2 - activate SPU tracing, 3 - deactivate */
  1117. /* start profiling */
  1118. ret = rtas_call(spu_rtas_token, 3, 1, NULL, subfunc,
  1119. cbe_cpu_to_node(cpu), lfsr_value);
  1120. if (unlikely(ret != 0)) {
  1121. printk(KERN_ERR
  1122. "%s: rtas call ibm,cbe-spu-perftools failed, " \
  1123. "return = %d\n", __func__, ret);
  1124. rtas_error = -EIO;
  1125. goto out;
  1126. }
  1127. }
  1128. rtas_error = start_spu_profiling_cycles(spu_cycle_reset);
  1129. if (rtas_error)
  1130. goto out_stop;
  1131. oprofile_running = 1;
  1132. return 0;
  1133. out_stop:
  1134. cell_global_stop_spu_cycles(); /* clean up the PMU/debug bus */
  1135. out:
  1136. return rtas_error;
  1137. }
  1138. static int cell_global_start_spu_events(struct op_counter_config *ctr)
  1139. {
  1140. int cpu;
  1141. u32 interrupt_mask = 0;
  1142. int rtn = 0;
  1143. hdw_thread = 0;
  1144. /* spu event profiling, uses the performance counters to generate
  1145. * an interrupt. The hardware is setup to store the SPU program
  1146. * counter into the trace array. The occurrence mode is used to
  1147. * enable storing data to the trace buffer. The bits are set
  1148. * to send/store the SPU address in the trace buffer. The debug
  1149. * bus must be setup to route the SPU program counter onto the
  1150. * debug bus. The occurrence data in the trace buffer is not used.
  1151. */
  1152. /* This routine gets called once for the system.
  1153. * There is one performance monitor per node, so we
  1154. * only need to perform this function once per node.
  1155. */
  1156. for_each_online_cpu(cpu) {
  1157. if (cbe_get_hw_thread_id(cpu))
  1158. continue;
  1159. /*
  1160. * Setup SPU event-based profiling.
  1161. * Set perf_mon_control bit 0 to a zero before
  1162. * enabling spu collection hardware.
  1163. *
  1164. * Only support one SPU event on one SPU per node.
  1165. */
  1166. if (ctr_enabled & 1) {
  1167. cbe_write_ctr(cpu, 0, reset_value[0]);
  1168. enable_ctr(cpu, 0, pm_regs.pm07_cntrl);
  1169. interrupt_mask |=
  1170. CBE_PM_CTR_OVERFLOW_INTR(0);
  1171. } else {
  1172. /* Disable counter */
  1173. cbe_write_pm07_control(cpu, 0, 0);
  1174. }
  1175. cbe_get_and_clear_pm_interrupts(cpu);
  1176. cbe_enable_pm_interrupts(cpu, hdw_thread, interrupt_mask);
  1177. cbe_enable_pm(cpu);
  1178. /* clear the trace buffer */
  1179. cbe_write_pm(cpu, trace_address, 0);
  1180. }
  1181. /* Start the timer to time slice collecting the event profile
  1182. * on each of the SPUs. Note, can collect profile on one SPU
  1183. * per node at a time.
  1184. */
  1185. start_spu_event_swap();
  1186. start_spu_profiling_events();
  1187. oprofile_running = 1;
  1188. smp_wmb();
  1189. return rtn;
  1190. }
  1191. static int cell_global_start_ppu(struct op_counter_config *ctr)
  1192. {
  1193. u32 cpu, i;
  1194. u32 interrupt_mask = 0;
  1195. /* This routine gets called once for the system.
  1196. * There is one performance monitor per node, so we
  1197. * only need to perform this function once per node.
  1198. */
  1199. for_each_online_cpu(cpu) {
  1200. if (cbe_get_hw_thread_id(cpu))
  1201. continue;
  1202. interrupt_mask = 0;
  1203. for (i = 0; i < num_counters; ++i) {
  1204. if (ctr_enabled & (1 << i)) {
  1205. cbe_write_ctr(cpu, i, reset_value[i]);
  1206. enable_ctr(cpu, i, pm_regs.pm07_cntrl);
  1207. interrupt_mask |= CBE_PM_CTR_OVERFLOW_INTR(i);
  1208. } else {
  1209. /* Disable counter */
  1210. cbe_write_pm07_control(cpu, i, 0);
  1211. }
  1212. }
  1213. cbe_get_and_clear_pm_interrupts(cpu);
  1214. cbe_enable_pm_interrupts(cpu, hdw_thread, interrupt_mask);
  1215. cbe_enable_pm(cpu);
  1216. }
  1217. virt_cntr_inter_mask = interrupt_mask;
  1218. oprofile_running = 1;
  1219. smp_wmb();
  1220. /*
  1221. * NOTE: start_virt_cntrs will result in cell_virtual_cntr() being
  1222. * executed which manipulates the PMU. We start the "virtual counter"
  1223. * here so that we do not need to synchronize access to the PMU in
  1224. * the above for-loop.
  1225. */
  1226. start_virt_cntrs();
  1227. return 0;
  1228. }
  1229. static int cell_global_start(struct op_counter_config *ctr)
  1230. {
  1231. if (profiling_mode == SPU_PROFILING_CYCLES)
  1232. return cell_global_start_spu_cycles(ctr);
  1233. else if (profiling_mode == SPU_PROFILING_EVENTS)
  1234. return cell_global_start_spu_events(ctr);
  1235. else
  1236. return cell_global_start_ppu(ctr);
  1237. }
  1238. /* The SPU interrupt handler
  1239. *
  1240. * SPU event profiling works as follows:
  1241. * The pm_signal[0] holds the one SPU event to be measured. It is routed on
  1242. * the debug bus using word 0 or 1. The value of pm_signal[1] and
  1243. * pm_signal[2] contain the necessary events to route the SPU program
  1244. * counter for the selected SPU onto the debug bus using words 2 and 3.
  1245. * The pm_interval register is setup to write the SPU PC value into the
  1246. * trace buffer at the maximum rate possible. The trace buffer is configured
  1247. * to store the PCs, wrapping when it is full. The performance counter is
  1248. * initialized to the max hardware count minus the number of events, N, between
  1249. * samples. Once the N events have occurred, a HW counter overflow occurs
  1250. * causing the generation of a HW counter interrupt which also stops the
  1251. * writing of the SPU PC values to the trace buffer. Hence the last PC
  1252. * written to the trace buffer is the SPU PC that we want. Unfortunately,
  1253. * we have to read from the beginning of the trace buffer to get to the
  1254. * last value written. We just hope the PPU has nothing better to do then
  1255. * service this interrupt. The PC for the specific SPU being profiled is
  1256. * extracted from the trace buffer processed and stored. The trace buffer
  1257. * is cleared, interrupts are cleared, the counter is reset to max - N.
  1258. * A kernel timer is used to periodically call the routine spu_evnt_swap()
  1259. * to switch to the next physical SPU in the node to profile in round robbin
  1260. * order. This way data is collected for all SPUs on the node. It does mean
  1261. * that we need to use a relatively small value of N to ensure enough samples
  1262. * on each SPU are collected each SPU is being profiled 1/8 of the time.
  1263. * It may also be necessary to use a longer sample collection period.
  1264. */
  1265. static void cell_handle_interrupt_spu(struct pt_regs *regs,
  1266. struct op_counter_config *ctr)
  1267. {
  1268. u32 cpu, cpu_tmp;
  1269. u64 trace_entry;
  1270. u32 interrupt_mask;
  1271. u64 trace_buffer[2];
  1272. u64 last_trace_buffer;
  1273. u32 sample;
  1274. u32 trace_addr;
  1275. unsigned long sample_array_lock_flags;
  1276. int spu_num;
  1277. unsigned long flags;
  1278. /* Make sure spu event interrupt handler and spu event swap
  1279. * don't access the counters simultaneously.
  1280. */
  1281. cpu = smp_processor_id();
  1282. spin_lock_irqsave(&cntr_lock, flags);
  1283. cpu_tmp = cpu;
  1284. cbe_disable_pm(cpu);
  1285. interrupt_mask = cbe_get_and_clear_pm_interrupts(cpu);
  1286. sample = 0xABCDEF;
  1287. trace_entry = 0xfedcba;
  1288. last_trace_buffer = 0xdeadbeaf;
  1289. if ((oprofile_running == 1) && (interrupt_mask != 0)) {
  1290. /* disable writes to trace buff */
  1291. cbe_write_pm(cpu, pm_interval, 0);
  1292. /* only have one perf cntr being used, cntr 0 */
  1293. if ((interrupt_mask & CBE_PM_CTR_OVERFLOW_INTR(0))
  1294. && ctr[0].enabled)
  1295. /* The SPU PC values will be read
  1296. * from the trace buffer, reset counter
  1297. */
  1298. cbe_write_ctr(cpu, 0, reset_value[0]);
  1299. trace_addr = cbe_read_pm(cpu, trace_address);
  1300. while (!(trace_addr & CBE_PM_TRACE_BUF_EMPTY)) {
  1301. /* There is data in the trace buffer to process
  1302. * Read the buffer until you get to the last
  1303. * entry. This is the value we want.
  1304. */
  1305. cbe_read_trace_buffer(cpu, trace_buffer);
  1306. trace_addr = cbe_read_pm(cpu, trace_address);
  1307. }
  1308. /* SPU Address 16 bit count format for 128 bit
  1309. * HW trace buffer is used for the SPU PC storage
  1310. * HDR bits 0:15
  1311. * SPU Addr 0 bits 16:31
  1312. * SPU Addr 1 bits 32:47
  1313. * unused bits 48:127
  1314. *
  1315. * HDR: bit4 = 1 SPU Address 0 valid
  1316. * HDR: bit5 = 1 SPU Address 1 valid
  1317. * - unfortunately, the valid bits don't seem to work
  1318. *
  1319. * Note trace_buffer[0] holds bits 0:63 of the HW
  1320. * trace buffer, trace_buffer[1] holds bits 64:127
  1321. */
  1322. trace_entry = trace_buffer[0]
  1323. & 0x00000000FFFF0000;
  1324. /* only top 16 of the 18 bit SPU PC address
  1325. * is stored in trace buffer, hence shift right
  1326. * by 16 -2 bits */
  1327. sample = trace_entry >> 14;
  1328. last_trace_buffer = trace_buffer[0];
  1329. spu_num = spu_evnt_phys_spu_indx
  1330. + (cbe_cpu_to_node(cpu) * NUM_SPUS_PER_NODE);
  1331. /* make sure only one process at a time is calling
  1332. * spu_sync_buffer()
  1333. */
  1334. spin_lock_irqsave(&oprof_spu_smpl_arry_lck,
  1335. sample_array_lock_flags);
  1336. spu_sync_buffer(spu_num, &sample, 1);
  1337. spin_unlock_irqrestore(&oprof_spu_smpl_arry_lck,
  1338. sample_array_lock_flags);
  1339. smp_wmb(); /* insure spu event buffer updates are written
  1340. * don't want events intermingled... */
  1341. /* The counters were frozen by the interrupt.
  1342. * Reenable the interrupt and restart the counters.
  1343. */
  1344. cbe_write_pm(cpu, pm_interval, NUM_INTERVAL_CYC);
  1345. cbe_enable_pm_interrupts(cpu, hdw_thread,
  1346. virt_cntr_inter_mask);
  1347. /* clear the trace buffer, re-enable writes to trace buff */
  1348. cbe_write_pm(cpu, trace_address, 0);
  1349. cbe_write_pm(cpu, pm_interval, NUM_INTERVAL_CYC);
  1350. /* The writes to the various performance counters only writes
  1351. * to a latch. The new values (interrupt setting bits, reset
  1352. * counter value etc.) are not copied to the actual registers
  1353. * until the performance monitor is enabled. In order to get
  1354. * this to work as desired, the performance monitor needs to
  1355. * be disabled while writing to the latches. This is a
  1356. * HW design issue.
  1357. */
  1358. write_pm_cntrl(cpu);
  1359. cbe_enable_pm(cpu);
  1360. }
  1361. spin_unlock_irqrestore(&cntr_lock, flags);
  1362. }
  1363. static void cell_handle_interrupt_ppu(struct pt_regs *regs,
  1364. struct op_counter_config *ctr)
  1365. {
  1366. u32 cpu;
  1367. u64 pc;
  1368. int is_kernel;
  1369. unsigned long flags = 0;
  1370. u32 interrupt_mask;
  1371. int i;
  1372. cpu = smp_processor_id();
  1373. /*
  1374. * Need to make sure the interrupt handler and the virt counter
  1375. * routine are not running at the same time. See the
  1376. * cell_virtual_cntr() routine for additional comments.
  1377. */
  1378. spin_lock_irqsave(&cntr_lock, flags);
  1379. /*
  1380. * Need to disable and reenable the performance counters
  1381. * to get the desired behavior from the hardware. This
  1382. * is hardware specific.
  1383. */
  1384. cbe_disable_pm(cpu);
  1385. interrupt_mask = cbe_get_and_clear_pm_interrupts(cpu);
  1386. /*
  1387. * If the interrupt mask has been cleared, then the virt cntr
  1388. * has cleared the interrupt. When the thread that generated
  1389. * the interrupt is restored, the data count will be restored to
  1390. * 0xffffff0 to cause the interrupt to be regenerated.
  1391. */
  1392. if ((oprofile_running == 1) && (interrupt_mask != 0)) {
  1393. pc = regs->nip;
  1394. is_kernel = is_kernel_addr(pc);
  1395. for (i = 0; i < num_counters; ++i) {
  1396. if ((interrupt_mask & CBE_PM_CTR_OVERFLOW_INTR(i))
  1397. && ctr[i].enabled) {
  1398. oprofile_add_ext_sample(pc, regs, i, is_kernel);
  1399. cbe_write_ctr(cpu, i, reset_value[i]);
  1400. }
  1401. }
  1402. /*
  1403. * The counters were frozen by the interrupt.
  1404. * Reenable the interrupt and restart the counters.
  1405. * If there was a race between the interrupt handler and
  1406. * the virtual counter routine. The virtual counter
  1407. * routine may have cleared the interrupts. Hence must
  1408. * use the virt_cntr_inter_mask to re-enable the interrupts.
  1409. */
  1410. cbe_enable_pm_interrupts(cpu, hdw_thread,
  1411. virt_cntr_inter_mask);
  1412. /*
  1413. * The writes to the various performance counters only writes
  1414. * to a latch. The new values (interrupt setting bits, reset
  1415. * counter value etc.) are not copied to the actual registers
  1416. * until the performance monitor is enabled. In order to get
  1417. * this to work as desired, the performance monitor needs to
  1418. * be disabled while writing to the latches. This is a
  1419. * HW design issue.
  1420. */
  1421. cbe_enable_pm(cpu);
  1422. }
  1423. spin_unlock_irqrestore(&cntr_lock, flags);
  1424. }
  1425. static void cell_handle_interrupt(struct pt_regs *regs,
  1426. struct op_counter_config *ctr)
  1427. {
  1428. if (profiling_mode == PPU_PROFILING)
  1429. cell_handle_interrupt_ppu(regs, ctr);
  1430. else
  1431. cell_handle_interrupt_spu(regs, ctr);
  1432. }
  1433. /*
  1434. * This function is called from the generic OProfile
  1435. * driver. When profiling PPUs, we need to do the
  1436. * generic sync start; otherwise, do spu_sync_start.
  1437. */
  1438. static int cell_sync_start(void)
  1439. {
  1440. if ((profiling_mode == SPU_PROFILING_CYCLES) ||
  1441. (profiling_mode == SPU_PROFILING_EVENTS))
  1442. return spu_sync_start();
  1443. else
  1444. return DO_GENERIC_SYNC;
  1445. }
  1446. static int cell_sync_stop(void)
  1447. {
  1448. if ((profiling_mode == SPU_PROFILING_CYCLES) ||
  1449. (profiling_mode == SPU_PROFILING_EVENTS))
  1450. return spu_sync_stop();
  1451. else
  1452. return 1;
  1453. }
  1454. struct op_powerpc_model op_model_cell = {
  1455. .reg_setup = cell_reg_setup,
  1456. .cpu_setup = cell_cpu_setup,
  1457. .global_start = cell_global_start,
  1458. .global_stop = cell_global_stop,
  1459. .sync_start = cell_sync_start,
  1460. .sync_stop = cell_sync_stop,
  1461. .handle_interrupt = cell_handle_interrupt,
  1462. };