op_model_cell.c 49 KB

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