op_model_cell.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213
  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/system.h>
  37. #include <asm/cell-regs.h>
  38. #include "../platforms/cell/interrupt.h"
  39. #include "cell/pr_util.h"
  40. static void cell_global_stop_spu(void);
  41. /*
  42. * spu_cycle_reset is the number of cycles between samples.
  43. * This variable is used for SPU profiling and should ONLY be set
  44. * at the beginning of cell_reg_setup; otherwise, it's read-only.
  45. */
  46. static unsigned int spu_cycle_reset;
  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. struct pmc_cntrl_data {
  61. unsigned long vcntr;
  62. unsigned long evnts;
  63. unsigned long masks;
  64. unsigned long enabled;
  65. };
  66. /*
  67. * ibm,cbe-perftools rtas parameters
  68. */
  69. struct pm_signal {
  70. u16 cpu; /* Processor to modify */
  71. u16 sub_unit; /* hw subunit this applies to (if applicable)*/
  72. short int signal_group; /* Signal Group to Enable/Disable */
  73. u8 bus_word; /* Enable/Disable on this Trace/Trigger/Event
  74. * Bus Word(s) (bitmask)
  75. */
  76. u8 bit; /* Trigger/Event bit (if applicable) */
  77. };
  78. /*
  79. * rtas call arguments
  80. */
  81. enum {
  82. SUBFUNC_RESET = 1,
  83. SUBFUNC_ACTIVATE = 2,
  84. SUBFUNC_DEACTIVATE = 3,
  85. PASSTHRU_IGNORE = 0,
  86. PASSTHRU_ENABLE = 1,
  87. PASSTHRU_DISABLE = 2,
  88. };
  89. struct pm_cntrl {
  90. u16 enable;
  91. u16 stop_at_max;
  92. u16 trace_mode;
  93. u16 freeze;
  94. u16 count_mode;
  95. };
  96. static struct {
  97. u32 group_control;
  98. u32 debug_bus_control;
  99. struct pm_cntrl pm_cntrl;
  100. u32 pm07_cntrl[NR_PHYS_CTRS];
  101. } pm_regs;
  102. #define GET_SUB_UNIT(x) ((x & 0x0000f000) >> 12)
  103. #define GET_BUS_WORD(x) ((x & 0x000000f0) >> 4)
  104. #define GET_BUS_TYPE(x) ((x & 0x00000300) >> 8)
  105. #define GET_POLARITY(x) ((x & 0x00000002) >> 1)
  106. #define GET_COUNT_CYCLES(x) (x & 0x00000001)
  107. #define GET_INPUT_CONTROL(x) ((x & 0x00000004) >> 2)
  108. static DEFINE_PER_CPU(unsigned long[NR_PHYS_CTRS], pmc_values);
  109. static struct pmc_cntrl_data pmc_cntrl[NUM_THREADS][NR_PHYS_CTRS];
  110. /*
  111. * The CELL profiling code makes rtas calls to setup the debug bus to
  112. * route the performance signals. Additionally, SPU profiling requires
  113. * a second rtas call to setup the hardware to capture the SPU PCs.
  114. * The EIO error value is returned if the token lookups or the rtas
  115. * call fail. The EIO error number is the best choice of the existing
  116. * error numbers. The probability of rtas related error is very low. But
  117. * by returning EIO and printing additional information to dmsg the user
  118. * will know that OProfile did not start and dmesg will tell them why.
  119. * OProfile does not support returning errors on Stop. Not a huge issue
  120. * since failure to reset the debug bus or stop the SPU PC collection is
  121. * not a fatel issue. Chances are if the Stop failed, Start doesn't work
  122. * either.
  123. */
  124. /*
  125. * Interpetation of hdw_thread:
  126. * 0 - even virtual cpus 0, 2, 4,...
  127. * 1 - odd virtual cpus 1, 3, 5, ...
  128. *
  129. * FIXME: this is strictly wrong, we need to clean this up in a number
  130. * of places. It works for now. -arnd
  131. */
  132. static u32 hdw_thread;
  133. static u32 virt_cntr_inter_mask;
  134. static struct timer_list timer_virt_cntr;
  135. /*
  136. * pm_signal needs to be global since it is initialized in
  137. * cell_reg_setup at the time when the necessary information
  138. * is available.
  139. */
  140. static struct pm_signal pm_signal[NR_PHYS_CTRS];
  141. static int pm_rtas_token; /* token for debug bus setup call */
  142. static int spu_rtas_token; /* token for SPU cycle profiling */
  143. static u32 reset_value[NR_PHYS_CTRS];
  144. static int num_counters;
  145. static int oprofile_running;
  146. static DEFINE_SPINLOCK(virt_cntr_lock);
  147. static u32 ctr_enabled;
  148. static unsigned char input_bus[NUM_INPUT_BUS_WORDS];
  149. /*
  150. * Firmware interface functions
  151. */
  152. static int
  153. rtas_ibm_cbe_perftools(int subfunc, int passthru,
  154. void *address, unsigned long length)
  155. {
  156. u64 paddr = __pa(address);
  157. return rtas_call(pm_rtas_token, 5, 1, NULL, subfunc,
  158. passthru, paddr >> 32, paddr & 0xffffffff, length);
  159. }
  160. static void pm_rtas_reset_signals(u32 node)
  161. {
  162. int ret;
  163. struct pm_signal pm_signal_local;
  164. /*
  165. * The debug bus is being set to the passthru disable state.
  166. * However, the FW still expects atleast one legal signal routing
  167. * entry or it will return an error on the arguments. If we don't
  168. * supply a valid entry, we must ignore all return values. Ignoring
  169. * all return values means we might miss an error we should be
  170. * concerned about.
  171. */
  172. /* fw expects physical cpu #. */
  173. pm_signal_local.cpu = node;
  174. pm_signal_local.signal_group = 21;
  175. pm_signal_local.bus_word = 1;
  176. pm_signal_local.sub_unit = 0;
  177. pm_signal_local.bit = 0;
  178. ret = rtas_ibm_cbe_perftools(SUBFUNC_RESET, PASSTHRU_DISABLE,
  179. &pm_signal_local,
  180. sizeof(struct pm_signal));
  181. if (unlikely(ret))
  182. /*
  183. * Not a fatal error. For Oprofile stop, the oprofile
  184. * functions do not support returning an error for
  185. * failure to stop OProfile.
  186. */
  187. printk(KERN_WARNING "%s: rtas returned: %d\n",
  188. __func__, ret);
  189. }
  190. static int pm_rtas_activate_signals(u32 node, u32 count)
  191. {
  192. int ret;
  193. int i, j;
  194. struct pm_signal pm_signal_local[NR_PHYS_CTRS];
  195. /*
  196. * There is no debug setup required for the cycles event.
  197. * Note that only events in the same group can be used.
  198. * Otherwise, there will be conflicts in correctly routing
  199. * the signals on the debug bus. It is the responsiblity
  200. * of the OProfile user tool to check the events are in
  201. * the same group.
  202. */
  203. i = 0;
  204. for (j = 0; j < count; j++) {
  205. if (pm_signal[j].signal_group != PPU_CYCLES_GRP_NUM) {
  206. /* fw expects physical cpu # */
  207. pm_signal_local[i].cpu = node;
  208. pm_signal_local[i].signal_group
  209. = pm_signal[j].signal_group;
  210. pm_signal_local[i].bus_word = pm_signal[j].bus_word;
  211. pm_signal_local[i].sub_unit = pm_signal[j].sub_unit;
  212. pm_signal_local[i].bit = pm_signal[j].bit;
  213. i++;
  214. }
  215. }
  216. if (i != 0) {
  217. ret = rtas_ibm_cbe_perftools(SUBFUNC_ACTIVATE, PASSTHRU_ENABLE,
  218. pm_signal_local,
  219. i * sizeof(struct pm_signal));
  220. if (unlikely(ret)) {
  221. printk(KERN_WARNING "%s: rtas returned: %d\n",
  222. __func__, ret);
  223. return -EIO;
  224. }
  225. }
  226. return 0;
  227. }
  228. /*
  229. * PM Signal functions
  230. */
  231. static void set_pm_event(u32 ctr, int event, u32 unit_mask)
  232. {
  233. struct pm_signal *p;
  234. u32 signal_bit;
  235. u32 bus_word, bus_type, count_cycles, polarity, input_control;
  236. int j, i;
  237. if (event == PPU_CYCLES_EVENT_NUM) {
  238. /* Special Event: Count all cpu cycles */
  239. pm_regs.pm07_cntrl[ctr] = CBE_COUNT_ALL_CYCLES;
  240. p = &(pm_signal[ctr]);
  241. p->signal_group = PPU_CYCLES_GRP_NUM;
  242. p->bus_word = 1;
  243. p->sub_unit = 0;
  244. p->bit = 0;
  245. goto out;
  246. } else {
  247. pm_regs.pm07_cntrl[ctr] = 0;
  248. }
  249. bus_word = GET_BUS_WORD(unit_mask);
  250. bus_type = GET_BUS_TYPE(unit_mask);
  251. count_cycles = GET_COUNT_CYCLES(unit_mask);
  252. polarity = GET_POLARITY(unit_mask);
  253. input_control = GET_INPUT_CONTROL(unit_mask);
  254. signal_bit = (event % 100);
  255. p = &(pm_signal[ctr]);
  256. p->signal_group = event / 100;
  257. p->bus_word = bus_word;
  258. p->sub_unit = GET_SUB_UNIT(unit_mask);
  259. pm_regs.pm07_cntrl[ctr] = 0;
  260. pm_regs.pm07_cntrl[ctr] |= PM07_CTR_COUNT_CYCLES(count_cycles);
  261. pm_regs.pm07_cntrl[ctr] |= PM07_CTR_POLARITY(polarity);
  262. pm_regs.pm07_cntrl[ctr] |= PM07_CTR_INPUT_CONTROL(input_control);
  263. /*
  264. * Some of the islands signal selection is based on 64 bit words.
  265. * The debug bus words are 32 bits, the input words to the performance
  266. * counters are defined as 32 bits. Need to convert the 64 bit island
  267. * specification to the appropriate 32 input bit and bus word for the
  268. * performance counter event selection. See the CELL Performance
  269. * monitoring signals manual and the Perf cntr hardware descriptions
  270. * for the details.
  271. */
  272. if (input_control == 0) {
  273. if (signal_bit > 31) {
  274. signal_bit -= 32;
  275. if (bus_word == 0x3)
  276. bus_word = 0x2;
  277. else if (bus_word == 0xc)
  278. bus_word = 0x8;
  279. }
  280. if ((bus_type == 0) && p->signal_group >= 60)
  281. bus_type = 2;
  282. if ((bus_type == 1) && p->signal_group >= 50)
  283. bus_type = 0;
  284. pm_regs.pm07_cntrl[ctr] |= PM07_CTR_INPUT_MUX(signal_bit);
  285. } else {
  286. pm_regs.pm07_cntrl[ctr] = 0;
  287. p->bit = signal_bit;
  288. }
  289. for (i = 0; i < NUM_DEBUG_BUS_WORDS; i++) {
  290. if (bus_word & (1 << i)) {
  291. pm_regs.debug_bus_control |=
  292. (bus_type << (30 - (2 * i)));
  293. for (j = 0; j < NUM_INPUT_BUS_WORDS; j++) {
  294. if (input_bus[j] == 0xff) {
  295. input_bus[j] = i;
  296. pm_regs.group_control |=
  297. (i << (30 - (2 * j)));
  298. break;
  299. }
  300. }
  301. }
  302. }
  303. out:
  304. ;
  305. }
  306. static void write_pm_cntrl(int cpu)
  307. {
  308. /*
  309. * Oprofile will use 32 bit counters, set bits 7:10 to 0
  310. * pmregs.pm_cntrl is a global
  311. */
  312. u32 val = 0;
  313. if (pm_regs.pm_cntrl.enable == 1)
  314. val |= CBE_PM_ENABLE_PERF_MON;
  315. if (pm_regs.pm_cntrl.stop_at_max == 1)
  316. val |= CBE_PM_STOP_AT_MAX;
  317. if (pm_regs.pm_cntrl.trace_mode == 1)
  318. val |= CBE_PM_TRACE_MODE_SET(pm_regs.pm_cntrl.trace_mode);
  319. if (pm_regs.pm_cntrl.freeze == 1)
  320. val |= CBE_PM_FREEZE_ALL_CTRS;
  321. /*
  322. * Routine set_count_mode must be called previously to set
  323. * the count mode based on the user selection of user and kernel.
  324. */
  325. val |= CBE_PM_COUNT_MODE_SET(pm_regs.pm_cntrl.count_mode);
  326. cbe_write_pm(cpu, pm_control, val);
  327. }
  328. static inline void
  329. set_count_mode(u32 kernel, u32 user)
  330. {
  331. /*
  332. * The user must specify user and kernel if they want them. If
  333. * neither is specified, OProfile will count in hypervisor mode.
  334. * pm_regs.pm_cntrl is a global
  335. */
  336. if (kernel) {
  337. if (user)
  338. pm_regs.pm_cntrl.count_mode = CBE_COUNT_ALL_MODES;
  339. else
  340. pm_regs.pm_cntrl.count_mode =
  341. CBE_COUNT_SUPERVISOR_MODE;
  342. } else {
  343. if (user)
  344. pm_regs.pm_cntrl.count_mode = CBE_COUNT_PROBLEM_MODE;
  345. else
  346. pm_regs.pm_cntrl.count_mode =
  347. CBE_COUNT_HYPERVISOR_MODE;
  348. }
  349. }
  350. static inline void enable_ctr(u32 cpu, u32 ctr, u32 * pm07_cntrl)
  351. {
  352. pm07_cntrl[ctr] |= CBE_PM_CTR_ENABLE;
  353. cbe_write_pm07_control(cpu, ctr, pm07_cntrl[ctr]);
  354. }
  355. /*
  356. * Oprofile is expected to collect data on all CPUs simultaneously.
  357. * However, there is one set of performance counters per node. There are
  358. * two hardware threads or virtual CPUs on each node. Hence, OProfile must
  359. * multiplex in time the performance counter collection on the two virtual
  360. * CPUs. The multiplexing of the performance counters is done by this
  361. * virtual counter routine.
  362. *
  363. * The pmc_values used below is defined as 'per-cpu' but its use is
  364. * more akin to 'per-node'. We need to store two sets of counter
  365. * values per node -- one for the previous run and one for the next.
  366. * The per-cpu[NR_PHYS_CTRS] gives us the storage we need. Each odd/even
  367. * pair of per-cpu arrays is used for storing the previous and next
  368. * pmc values for a given node.
  369. * NOTE: We use the per-cpu variable to improve cache performance.
  370. *
  371. * This routine will alternate loading the virtual counters for
  372. * virtual CPUs
  373. */
  374. static void cell_virtual_cntr(unsigned long data)
  375. {
  376. int i, prev_hdw_thread, next_hdw_thread;
  377. u32 cpu;
  378. unsigned long flags;
  379. /*
  380. * Make sure that the interrupt_hander and the virt counter are
  381. * not both playing with the counters on the same node.
  382. */
  383. spin_lock_irqsave(&virt_cntr_lock, flags);
  384. prev_hdw_thread = hdw_thread;
  385. /* switch the cpu handling the interrupts */
  386. hdw_thread = 1 ^ hdw_thread;
  387. next_hdw_thread = hdw_thread;
  388. pm_regs.group_control = 0;
  389. pm_regs.debug_bus_control = 0;
  390. for (i = 0; i < NUM_INPUT_BUS_WORDS; i++)
  391. input_bus[i] = 0xff;
  392. /*
  393. * There are some per thread events. Must do the
  394. * set event, for the thread that is being started
  395. */
  396. for (i = 0; i < num_counters; i++)
  397. set_pm_event(i,
  398. pmc_cntrl[next_hdw_thread][i].evnts,
  399. pmc_cntrl[next_hdw_thread][i].masks);
  400. /*
  401. * The following is done only once per each node, but
  402. * we need cpu #, not node #, to pass to the cbe_xxx functions.
  403. */
  404. for_each_online_cpu(cpu) {
  405. if (cbe_get_hw_thread_id(cpu))
  406. continue;
  407. /*
  408. * stop counters, save counter values, restore counts
  409. * for previous thread
  410. */
  411. cbe_disable_pm(cpu);
  412. cbe_disable_pm_interrupts(cpu);
  413. for (i = 0; i < num_counters; i++) {
  414. per_cpu(pmc_values, cpu + prev_hdw_thread)[i]
  415. = cbe_read_ctr(cpu, i);
  416. if (per_cpu(pmc_values, cpu + next_hdw_thread)[i]
  417. == 0xFFFFFFFF)
  418. /* If the cntr value is 0xffffffff, we must
  419. * reset that to 0xfffffff0 when the current
  420. * thread is restarted. This will generate a
  421. * new interrupt and make sure that we never
  422. * restore the counters to the max value. If
  423. * the counters were restored to the max value,
  424. * they do not increment and no interrupts are
  425. * generated. Hence no more samples will be
  426. * collected on that cpu.
  427. */
  428. cbe_write_ctr(cpu, i, 0xFFFFFFF0);
  429. else
  430. cbe_write_ctr(cpu, i,
  431. per_cpu(pmc_values,
  432. cpu +
  433. next_hdw_thread)[i]);
  434. }
  435. /*
  436. * Switch to the other thread. Change the interrupt
  437. * and control regs to be scheduled on the CPU
  438. * corresponding to the thread to execute.
  439. */
  440. for (i = 0; i < num_counters; i++) {
  441. if (pmc_cntrl[next_hdw_thread][i].enabled) {
  442. /*
  443. * There are some per thread events.
  444. * Must do the set event, enable_cntr
  445. * for each cpu.
  446. */
  447. enable_ctr(cpu, i,
  448. pm_regs.pm07_cntrl);
  449. } else {
  450. cbe_write_pm07_control(cpu, i, 0);
  451. }
  452. }
  453. /* Enable interrupts on the CPU thread that is starting */
  454. cbe_enable_pm_interrupts(cpu, next_hdw_thread,
  455. virt_cntr_inter_mask);
  456. cbe_enable_pm(cpu);
  457. }
  458. spin_unlock_irqrestore(&virt_cntr_lock, flags);
  459. mod_timer(&timer_virt_cntr, jiffies + HZ / 10);
  460. }
  461. static void start_virt_cntrs(void)
  462. {
  463. init_timer(&timer_virt_cntr);
  464. timer_virt_cntr.function = cell_virtual_cntr;
  465. timer_virt_cntr.data = 0UL;
  466. timer_virt_cntr.expires = jiffies + HZ / 10;
  467. add_timer(&timer_virt_cntr);
  468. }
  469. /* This function is called once for all cpus combined */
  470. static int cell_reg_setup(struct op_counter_config *ctr,
  471. struct op_system_config *sys, int num_ctrs)
  472. {
  473. int i, j, cpu;
  474. spu_cycle_reset = 0;
  475. if (ctr[0].event == SPU_CYCLES_EVENT_NUM) {
  476. spu_cycle_reset = ctr[0].count;
  477. /*
  478. * Each node will need to make the rtas call to start
  479. * and stop SPU profiling. Get the token once and store it.
  480. */
  481. spu_rtas_token = rtas_token("ibm,cbe-spu-perftools");
  482. if (unlikely(spu_rtas_token == RTAS_UNKNOWN_SERVICE)) {
  483. printk(KERN_ERR
  484. "%s: rtas token ibm,cbe-spu-perftools unknown\n",
  485. __func__);
  486. return -EIO;
  487. }
  488. }
  489. pm_rtas_token = rtas_token("ibm,cbe-perftools");
  490. /*
  491. * For all events excetp PPU CYCLEs, each node will need to make
  492. * the rtas cbe-perftools call to setup and reset the debug bus.
  493. * Make the token lookup call once and store it in the global
  494. * variable pm_rtas_token.
  495. */
  496. if (unlikely(pm_rtas_token == RTAS_UNKNOWN_SERVICE)) {
  497. printk(KERN_ERR
  498. "%s: rtas token ibm,cbe-perftools unknown\n",
  499. __func__);
  500. return -EIO;
  501. }
  502. num_counters = num_ctrs;
  503. pm_regs.group_control = 0;
  504. pm_regs.debug_bus_control = 0;
  505. /* setup the pm_control register */
  506. memset(&pm_regs.pm_cntrl, 0, sizeof(struct pm_cntrl));
  507. pm_regs.pm_cntrl.stop_at_max = 1;
  508. pm_regs.pm_cntrl.trace_mode = 0;
  509. pm_regs.pm_cntrl.freeze = 1;
  510. set_count_mode(sys->enable_kernel, sys->enable_user);
  511. /* Setup the thread 0 events */
  512. for (i = 0; i < num_ctrs; ++i) {
  513. pmc_cntrl[0][i].evnts = ctr[i].event;
  514. pmc_cntrl[0][i].masks = ctr[i].unit_mask;
  515. pmc_cntrl[0][i].enabled = ctr[i].enabled;
  516. pmc_cntrl[0][i].vcntr = i;
  517. for_each_possible_cpu(j)
  518. per_cpu(pmc_values, j)[i] = 0;
  519. }
  520. /*
  521. * Setup the thread 1 events, map the thread 0 event to the
  522. * equivalent thread 1 event.
  523. */
  524. for (i = 0; i < num_ctrs; ++i) {
  525. if ((ctr[i].event >= 2100) && (ctr[i].event <= 2111))
  526. pmc_cntrl[1][i].evnts = ctr[i].event + 19;
  527. else if (ctr[i].event == 2203)
  528. pmc_cntrl[1][i].evnts = ctr[i].event;
  529. else if ((ctr[i].event >= 2200) && (ctr[i].event <= 2215))
  530. pmc_cntrl[1][i].evnts = ctr[i].event + 16;
  531. else
  532. pmc_cntrl[1][i].evnts = ctr[i].event;
  533. pmc_cntrl[1][i].masks = ctr[i].unit_mask;
  534. pmc_cntrl[1][i].enabled = ctr[i].enabled;
  535. pmc_cntrl[1][i].vcntr = i;
  536. }
  537. for (i = 0; i < NUM_INPUT_BUS_WORDS; i++)
  538. input_bus[i] = 0xff;
  539. /*
  540. * Our counters count up, and "count" refers to
  541. * how much before the next interrupt, and we interrupt
  542. * on overflow. So we calculate the starting value
  543. * which will give us "count" until overflow.
  544. * Then we set the events on the enabled counters.
  545. */
  546. for (i = 0; i < num_counters; ++i) {
  547. /* start with virtual counter set 0 */
  548. if (pmc_cntrl[0][i].enabled) {
  549. /* Using 32bit counters, reset max - count */
  550. reset_value[i] = 0xFFFFFFFF - ctr[i].count;
  551. set_pm_event(i,
  552. pmc_cntrl[0][i].evnts,
  553. pmc_cntrl[0][i].masks);
  554. /* global, used by cell_cpu_setup */
  555. ctr_enabled |= (1 << i);
  556. }
  557. }
  558. /* initialize the previous counts for the virtual cntrs */
  559. for_each_online_cpu(cpu)
  560. for (i = 0; i < num_counters; ++i) {
  561. per_cpu(pmc_values, cpu)[i] = reset_value[i];
  562. }
  563. return 0;
  564. }
  565. /* This function is called once for each cpu */
  566. static int cell_cpu_setup(struct op_counter_config *cntr)
  567. {
  568. u32 cpu = smp_processor_id();
  569. u32 num_enabled = 0;
  570. int i;
  571. if (spu_cycle_reset)
  572. return 0;
  573. /* There is one performance monitor per processor chip (i.e. node),
  574. * so we only need to perform this function once per node.
  575. */
  576. if (cbe_get_hw_thread_id(cpu))
  577. return 0;
  578. /* Stop all counters */
  579. cbe_disable_pm(cpu);
  580. cbe_disable_pm_interrupts(cpu);
  581. cbe_write_pm(cpu, pm_interval, 0);
  582. cbe_write_pm(cpu, pm_start_stop, 0);
  583. cbe_write_pm(cpu, group_control, pm_regs.group_control);
  584. cbe_write_pm(cpu, debug_bus_control, pm_regs.debug_bus_control);
  585. write_pm_cntrl(cpu);
  586. for (i = 0; i < num_counters; ++i) {
  587. if (ctr_enabled & (1 << i)) {
  588. pm_signal[num_enabled].cpu = cbe_cpu_to_node(cpu);
  589. num_enabled++;
  590. }
  591. }
  592. /*
  593. * The pm_rtas_activate_signals will return -EIO if the FW
  594. * call failed.
  595. */
  596. return pm_rtas_activate_signals(cbe_cpu_to_node(cpu), num_enabled);
  597. }
  598. #define ENTRIES 303
  599. #define MAXLFSR 0xFFFFFF
  600. /* precomputed table of 24 bit LFSR values */
  601. static int initial_lfsr[] = {
  602. 8221349, 12579195, 5379618, 10097839, 7512963, 7519310, 3955098, 10753424,
  603. 15507573, 7458917, 285419, 2641121, 9780088, 3915503, 6668768, 1548716,
  604. 4885000, 8774424, 9650099, 2044357, 2304411, 9326253, 10332526, 4421547,
  605. 3440748, 10179459, 13332843, 10375561, 1313462, 8375100, 5198480, 6071392,
  606. 9341783, 1526887, 3985002, 1439429, 13923762, 7010104, 11969769, 4547026,
  607. 2040072, 4025602, 3437678, 7939992, 11444177, 4496094, 9803157, 10745556,
  608. 3671780, 4257846, 5662259, 13196905, 3237343, 12077182, 16222879, 7587769,
  609. 14706824, 2184640, 12591135, 10420257, 7406075, 3648978, 11042541, 15906893,
  610. 11914928, 4732944, 10695697, 12928164, 11980531, 4430912, 11939291, 2917017,
  611. 6119256, 4172004, 9373765, 8410071, 14788383, 5047459, 5474428, 1737756,
  612. 15967514, 13351758, 6691285, 8034329, 2856544, 14394753, 11310160, 12149558,
  613. 7487528, 7542781, 15668898, 12525138, 12790975, 3707933, 9106617, 1965401,
  614. 16219109, 12801644, 2443203, 4909502, 8762329, 3120803, 6360315, 9309720,
  615. 15164599, 10844842, 4456529, 6667610, 14924259, 884312, 6234963, 3326042,
  616. 15973422, 13919464, 5272099, 6414643, 3909029, 2764324, 5237926, 4774955,
  617. 10445906, 4955302, 5203726, 10798229, 11443419, 2303395, 333836, 9646934,
  618. 3464726, 4159182, 568492, 995747, 10318756, 13299332, 4836017, 8237783,
  619. 3878992, 2581665, 11394667, 5672745, 14412947, 3159169, 9094251, 16467278,
  620. 8671392, 15230076, 4843545, 7009238, 15504095, 1494895, 9627886, 14485051,
  621. 8304291, 252817, 12421642, 16085736, 4774072, 2456177, 4160695, 15409741,
  622. 4902868, 5793091, 13162925, 16039714, 782255, 11347835, 14884586, 366972,
  623. 16308990, 11913488, 13390465, 2958444, 10340278, 1177858, 1319431, 10426302,
  624. 2868597, 126119, 5784857, 5245324, 10903900, 16436004, 3389013, 1742384,
  625. 14674502, 10279218, 8536112, 10364279, 6877778, 14051163, 1025130, 6072469,
  626. 1988305, 8354440, 8216060, 16342977, 13112639, 3976679, 5913576, 8816697,
  627. 6879995, 14043764, 3339515, 9364420, 15808858, 12261651, 2141560, 5636398,
  628. 10345425, 10414756, 781725, 6155650, 4746914, 5078683, 7469001, 6799140,
  629. 10156444, 9667150, 10116470, 4133858, 2121972, 1124204, 1003577, 1611214,
  630. 14304602, 16221850, 13878465, 13577744, 3629235, 8772583, 10881308, 2410386,
  631. 7300044, 5378855, 9301235, 12755149, 4977682, 8083074, 10327581, 6395087,
  632. 9155434, 15501696, 7514362, 14520507, 15808945, 3244584, 4741962, 9658130,
  633. 14336147, 8654727, 7969093, 15759799, 14029445, 5038459, 9894848, 8659300,
  634. 13699287, 8834306, 10712885, 14753895, 10410465, 3373251, 309501, 9561475,
  635. 5526688, 14647426, 14209836, 5339224, 207299, 14069911, 8722990, 2290950,
  636. 3258216, 12505185, 6007317, 9218111, 14661019, 10537428, 11731949, 9027003,
  637. 6641507, 9490160, 200241, 9720425, 16277895, 10816638, 1554761, 10431375,
  638. 7467528, 6790302, 3429078, 14633753, 14428997, 11463204, 3576212, 2003426,
  639. 6123687, 820520, 9992513, 15784513, 5778891, 6428165, 8388607
  640. };
  641. /*
  642. * The hardware uses an LFSR counting sequence to determine when to capture
  643. * the SPU PCs. An LFSR sequence is like a puesdo random number sequence
  644. * where each number occurs once in the sequence but the sequence is not in
  645. * numerical order. The SPU PC capture is done when the LFSR sequence reaches
  646. * the last value in the sequence. Hence the user specified value N
  647. * corresponds to the LFSR number that is N from the end of the sequence.
  648. *
  649. * To avoid the time to compute the LFSR, a lookup table is used. The 24 bit
  650. * LFSR sequence is broken into four ranges. The spacing of the precomputed
  651. * values is adjusted in each range so the error between the user specifed
  652. * number (N) of events between samples and the actual number of events based
  653. * on the precomputed value will be les then about 6.2%. Note, if the user
  654. * specifies N < 2^16, the LFSR value that is 2^16 from the end will be used.
  655. * This is to prevent the loss of samples because the trace buffer is full.
  656. *
  657. * User specified N Step between Index in
  658. * precomputed values precomputed
  659. * table
  660. * 0 to 2^16-1 ---- 0
  661. * 2^16 to 2^16+2^19-1 2^12 1 to 128
  662. * 2^16+2^19 to 2^16+2^19+2^22-1 2^15 129 to 256
  663. * 2^16+2^19+2^22 to 2^24-1 2^18 257 to 302
  664. *
  665. *
  666. * For example, the LFSR values in the second range are computed for 2^16,
  667. * 2^16+2^12, ... , 2^19-2^16, 2^19 and stored in the table at indicies
  668. * 1, 2,..., 127, 128.
  669. *
  670. * The 24 bit LFSR value for the nth number in the sequence can be
  671. * calculated using the following code:
  672. *
  673. * #define size 24
  674. * int calculate_lfsr(int n)
  675. * {
  676. * int i;
  677. * unsigned int newlfsr0;
  678. * unsigned int lfsr = 0xFFFFFF;
  679. * unsigned int howmany = n;
  680. *
  681. * for (i = 2; i < howmany + 2; i++) {
  682. * newlfsr0 = (((lfsr >> (size - 1 - 0)) & 1) ^
  683. * ((lfsr >> (size - 1 - 1)) & 1) ^
  684. * (((lfsr >> (size - 1 - 6)) & 1) ^
  685. * ((lfsr >> (size - 1 - 23)) & 1)));
  686. *
  687. * lfsr >>= 1;
  688. * lfsr = lfsr | (newlfsr0 << (size - 1));
  689. * }
  690. * return lfsr;
  691. * }
  692. */
  693. #define V2_16 (0x1 << 16)
  694. #define V2_19 (0x1 << 19)
  695. #define V2_22 (0x1 << 22)
  696. static int calculate_lfsr(int n)
  697. {
  698. /*
  699. * The ranges and steps are in powers of 2 so the calculations
  700. * can be done using shifts rather then divide.
  701. */
  702. int index;
  703. if ((n >> 16) == 0)
  704. index = 0;
  705. else if (((n - V2_16) >> 19) == 0)
  706. index = ((n - V2_16) >> 12) + 1;
  707. else if (((n - V2_16 - V2_19) >> 22) == 0)
  708. index = ((n - V2_16 - V2_19) >> 15 ) + 1 + 128;
  709. else if (((n - V2_16 - V2_19 - V2_22) >> 24) == 0)
  710. index = ((n - V2_16 - V2_19 - V2_22) >> 18 ) + 1 + 256;
  711. else
  712. index = ENTRIES-1;
  713. /* make sure index is valid */
  714. if ((index > ENTRIES) || (index < 0))
  715. index = ENTRIES-1;
  716. return initial_lfsr[index];
  717. }
  718. static int pm_rtas_activate_spu_profiling(u32 node)
  719. {
  720. int ret, i;
  721. struct pm_signal pm_signal_local[NR_PHYS_CTRS];
  722. /*
  723. * Set up the rtas call to configure the debug bus to
  724. * route the SPU PCs. Setup the pm_signal for each SPU
  725. */
  726. for (i = 0; i < NUM_SPUS_PER_NODE; i++) {
  727. pm_signal_local[i].cpu = node;
  728. pm_signal_local[i].signal_group = 41;
  729. /* spu i on word (i/2) */
  730. pm_signal_local[i].bus_word = 1 << i / 2;
  731. /* spu i */
  732. pm_signal_local[i].sub_unit = i;
  733. pm_signal_local[i].bit = 63;
  734. }
  735. ret = rtas_ibm_cbe_perftools(SUBFUNC_ACTIVATE,
  736. PASSTHRU_ENABLE, pm_signal_local,
  737. (NUM_SPUS_PER_NODE
  738. * sizeof(struct pm_signal)));
  739. if (unlikely(ret)) {
  740. printk(KERN_WARNING "%s: rtas returned: %d\n",
  741. __func__, ret);
  742. return -EIO;
  743. }
  744. return 0;
  745. }
  746. #ifdef CONFIG_CPU_FREQ
  747. static int
  748. oprof_cpufreq_notify(struct notifier_block *nb, unsigned long val, void *data)
  749. {
  750. int ret = 0;
  751. struct cpufreq_freqs *frq = data;
  752. if ((val == CPUFREQ_PRECHANGE && frq->old < frq->new) ||
  753. (val == CPUFREQ_POSTCHANGE && frq->old > frq->new) ||
  754. (val == CPUFREQ_RESUMECHANGE || val == CPUFREQ_SUSPENDCHANGE))
  755. set_spu_profiling_frequency(frq->new, spu_cycle_reset);
  756. return ret;
  757. }
  758. static struct notifier_block cpu_freq_notifier_block = {
  759. .notifier_call = oprof_cpufreq_notify
  760. };
  761. #endif
  762. static int cell_global_start_spu(struct op_counter_config *ctr)
  763. {
  764. int subfunc;
  765. unsigned int lfsr_value;
  766. int cpu;
  767. int ret;
  768. int rtas_error;
  769. unsigned int cpu_khzfreq = 0;
  770. /* The SPU profiling uses time-based profiling based on
  771. * cpu frequency, so if configured with the CPU_FREQ
  772. * option, we should detect frequency changes and react
  773. * accordingly.
  774. */
  775. #ifdef CONFIG_CPU_FREQ
  776. ret = cpufreq_register_notifier(&cpu_freq_notifier_block,
  777. CPUFREQ_TRANSITION_NOTIFIER);
  778. if (ret < 0)
  779. /* this is not a fatal error */
  780. printk(KERN_ERR "CPU freq change registration failed: %d\n",
  781. ret);
  782. else
  783. cpu_khzfreq = cpufreq_quick_get(smp_processor_id());
  784. #endif
  785. set_spu_profiling_frequency(cpu_khzfreq, spu_cycle_reset);
  786. for_each_online_cpu(cpu) {
  787. if (cbe_get_hw_thread_id(cpu))
  788. continue;
  789. /*
  790. * Setup SPU cycle-based profiling.
  791. * Set perf_mon_control bit 0 to a zero before
  792. * enabling spu collection hardware.
  793. */
  794. cbe_write_pm(cpu, pm_control, 0);
  795. if (spu_cycle_reset > MAX_SPU_COUNT)
  796. /* use largest possible value */
  797. lfsr_value = calculate_lfsr(MAX_SPU_COUNT-1);
  798. else
  799. lfsr_value = calculate_lfsr(spu_cycle_reset);
  800. /* must use a non zero value. Zero disables data collection. */
  801. if (lfsr_value == 0)
  802. lfsr_value = calculate_lfsr(1);
  803. lfsr_value = lfsr_value << 8; /* shift lfsr to correct
  804. * register location
  805. */
  806. /* debug bus setup */
  807. ret = pm_rtas_activate_spu_profiling(cbe_cpu_to_node(cpu));
  808. if (unlikely(ret)) {
  809. rtas_error = ret;
  810. goto out;
  811. }
  812. subfunc = 2; /* 2 - activate SPU tracing, 3 - deactivate */
  813. /* start profiling */
  814. ret = rtas_call(spu_rtas_token, 3, 1, NULL, subfunc,
  815. cbe_cpu_to_node(cpu), lfsr_value);
  816. if (unlikely(ret != 0)) {
  817. printk(KERN_ERR
  818. "%s: rtas call ibm,cbe-spu-perftools failed, return = %d\n",
  819. __func__, ret);
  820. rtas_error = -EIO;
  821. goto out;
  822. }
  823. }
  824. rtas_error = start_spu_profiling(spu_cycle_reset);
  825. if (rtas_error)
  826. goto out_stop;
  827. oprofile_running = 1;
  828. return 0;
  829. out_stop:
  830. cell_global_stop_spu(); /* clean up the PMU/debug bus */
  831. out:
  832. return rtas_error;
  833. }
  834. static int cell_global_start_ppu(struct op_counter_config *ctr)
  835. {
  836. u32 cpu, i;
  837. u32 interrupt_mask = 0;
  838. /* This routine gets called once for the system.
  839. * There is one performance monitor per node, so we
  840. * only need to perform this function once per node.
  841. */
  842. for_each_online_cpu(cpu) {
  843. if (cbe_get_hw_thread_id(cpu))
  844. continue;
  845. interrupt_mask = 0;
  846. for (i = 0; i < num_counters; ++i) {
  847. if (ctr_enabled & (1 << i)) {
  848. cbe_write_ctr(cpu, i, reset_value[i]);
  849. enable_ctr(cpu, i, pm_regs.pm07_cntrl);
  850. interrupt_mask |=
  851. CBE_PM_CTR_OVERFLOW_INTR(i);
  852. } else {
  853. /* Disable counter */
  854. cbe_write_pm07_control(cpu, i, 0);
  855. }
  856. }
  857. cbe_get_and_clear_pm_interrupts(cpu);
  858. cbe_enable_pm_interrupts(cpu, hdw_thread, interrupt_mask);
  859. cbe_enable_pm(cpu);
  860. }
  861. virt_cntr_inter_mask = interrupt_mask;
  862. oprofile_running = 1;
  863. smp_wmb();
  864. /*
  865. * NOTE: start_virt_cntrs will result in cell_virtual_cntr() being
  866. * executed which manipulates the PMU. We start the "virtual counter"
  867. * here so that we do not need to synchronize access to the PMU in
  868. * the above for-loop.
  869. */
  870. start_virt_cntrs();
  871. return 0;
  872. }
  873. static int cell_global_start(struct op_counter_config *ctr)
  874. {
  875. if (spu_cycle_reset)
  876. return cell_global_start_spu(ctr);
  877. else
  878. return cell_global_start_ppu(ctr);
  879. }
  880. /*
  881. * Note the generic OProfile stop calls do not support returning
  882. * an error on stop. Hence, will not return an error if the FW
  883. * calls fail on stop. Failure to reset the debug bus is not an issue.
  884. * Failure to disable the SPU profiling is not an issue. The FW calls
  885. * to enable the performance counters and debug bus will work even if
  886. * the hardware was not cleanly reset.
  887. */
  888. static void cell_global_stop_spu(void)
  889. {
  890. int subfunc, rtn_value;
  891. unsigned int lfsr_value;
  892. int cpu;
  893. oprofile_running = 0;
  894. #ifdef CONFIG_CPU_FREQ
  895. cpufreq_unregister_notifier(&cpu_freq_notifier_block,
  896. CPUFREQ_TRANSITION_NOTIFIER);
  897. #endif
  898. for_each_online_cpu(cpu) {
  899. if (cbe_get_hw_thread_id(cpu))
  900. continue;
  901. subfunc = 3; /*
  902. * 2 - activate SPU tracing,
  903. * 3 - deactivate
  904. */
  905. lfsr_value = 0x8f100000;
  906. rtn_value = rtas_call(spu_rtas_token, 3, 1, NULL,
  907. subfunc, cbe_cpu_to_node(cpu),
  908. lfsr_value);
  909. if (unlikely(rtn_value != 0)) {
  910. printk(KERN_ERR
  911. "%s: rtas call ibm,cbe-spu-perftools failed, return = %d\n",
  912. __func__, rtn_value);
  913. }
  914. /* Deactivate the signals */
  915. pm_rtas_reset_signals(cbe_cpu_to_node(cpu));
  916. }
  917. stop_spu_profiling();
  918. }
  919. static void cell_global_stop_ppu(void)
  920. {
  921. int cpu;
  922. /*
  923. * This routine will be called once for the system.
  924. * There is one performance monitor per node, so we
  925. * only need to perform this function once per node.
  926. */
  927. del_timer_sync(&timer_virt_cntr);
  928. oprofile_running = 0;
  929. smp_wmb();
  930. for_each_online_cpu(cpu) {
  931. if (cbe_get_hw_thread_id(cpu))
  932. continue;
  933. cbe_sync_irq(cbe_cpu_to_node(cpu));
  934. /* Stop the counters */
  935. cbe_disable_pm(cpu);
  936. /* Deactivate the signals */
  937. pm_rtas_reset_signals(cbe_cpu_to_node(cpu));
  938. /* Deactivate interrupts */
  939. cbe_disable_pm_interrupts(cpu);
  940. }
  941. }
  942. static void cell_global_stop(void)
  943. {
  944. if (spu_cycle_reset)
  945. cell_global_stop_spu();
  946. else
  947. cell_global_stop_ppu();
  948. }
  949. static void cell_handle_interrupt(struct pt_regs *regs,
  950. struct op_counter_config *ctr)
  951. {
  952. u32 cpu;
  953. u64 pc;
  954. int is_kernel;
  955. unsigned long flags = 0;
  956. u32 interrupt_mask;
  957. int i;
  958. cpu = smp_processor_id();
  959. /*
  960. * Need to make sure the interrupt handler and the virt counter
  961. * routine are not running at the same time. See the
  962. * cell_virtual_cntr() routine for additional comments.
  963. */
  964. spin_lock_irqsave(&virt_cntr_lock, flags);
  965. /*
  966. * Need to disable and reenable the performance counters
  967. * to get the desired behavior from the hardware. This
  968. * is hardware specific.
  969. */
  970. cbe_disable_pm(cpu);
  971. interrupt_mask = cbe_get_and_clear_pm_interrupts(cpu);
  972. /*
  973. * If the interrupt mask has been cleared, then the virt cntr
  974. * has cleared the interrupt. When the thread that generated
  975. * the interrupt is restored, the data count will be restored to
  976. * 0xffffff0 to cause the interrupt to be regenerated.
  977. */
  978. if ((oprofile_running == 1) && (interrupt_mask != 0)) {
  979. pc = regs->nip;
  980. is_kernel = is_kernel_addr(pc);
  981. for (i = 0; i < num_counters; ++i) {
  982. if ((interrupt_mask & CBE_PM_CTR_OVERFLOW_INTR(i))
  983. && ctr[i].enabled) {
  984. oprofile_add_ext_sample(pc, regs, i, is_kernel);
  985. cbe_write_ctr(cpu, i, reset_value[i]);
  986. }
  987. }
  988. /*
  989. * The counters were frozen by the interrupt.
  990. * Reenable the interrupt and restart the counters.
  991. * If there was a race between the interrupt handler and
  992. * the virtual counter routine. The virutal counter
  993. * routine may have cleared the interrupts. Hence must
  994. * use the virt_cntr_inter_mask to re-enable the interrupts.
  995. */
  996. cbe_enable_pm_interrupts(cpu, hdw_thread,
  997. virt_cntr_inter_mask);
  998. /*
  999. * The writes to the various performance counters only writes
  1000. * to a latch. The new values (interrupt setting bits, reset
  1001. * counter value etc.) are not copied to the actual registers
  1002. * until the performance monitor is enabled. In order to get
  1003. * this to work as desired, the permormance monitor needs to
  1004. * be disabled while writing to the latches. This is a
  1005. * HW design issue.
  1006. */
  1007. cbe_enable_pm(cpu);
  1008. }
  1009. spin_unlock_irqrestore(&virt_cntr_lock, flags);
  1010. }
  1011. /*
  1012. * This function is called from the generic OProfile
  1013. * driver. When profiling PPUs, we need to do the
  1014. * generic sync start; otherwise, do spu_sync_start.
  1015. */
  1016. static int cell_sync_start(void)
  1017. {
  1018. if (spu_cycle_reset)
  1019. return spu_sync_start();
  1020. else
  1021. return DO_GENERIC_SYNC;
  1022. }
  1023. static int cell_sync_stop(void)
  1024. {
  1025. if (spu_cycle_reset)
  1026. return spu_sync_stop();
  1027. else
  1028. return 1;
  1029. }
  1030. struct op_powerpc_model op_model_cell = {
  1031. .reg_setup = cell_reg_setup,
  1032. .cpu_setup = cell_cpu_setup,
  1033. .global_start = cell_global_start,
  1034. .global_stop = cell_global_stop,
  1035. .sync_start = cell_sync_start,
  1036. .sync_stop = cell_sync_stop,
  1037. .handle_interrupt = cell_handle_interrupt,
  1038. };