op_model_cell.c 34 KB

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