op_model_cell.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220
  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. if (unlikely(num_ctrs > NR_PHYS_CTRS)) {
  504. printk(KERN_ERR
  505. "%s: Oprofile, number of specified events " \
  506. "exceeds number of physical counters\n",
  507. __func__);
  508. return -EIO;
  509. }
  510. pm_regs.group_control = 0;
  511. pm_regs.debug_bus_control = 0;
  512. /* setup the pm_control register */
  513. memset(&pm_regs.pm_cntrl, 0, sizeof(struct pm_cntrl));
  514. pm_regs.pm_cntrl.stop_at_max = 1;
  515. pm_regs.pm_cntrl.trace_mode = 0;
  516. pm_regs.pm_cntrl.freeze = 1;
  517. set_count_mode(sys->enable_kernel, sys->enable_user);
  518. /* Setup the thread 0 events */
  519. for (i = 0; i < num_ctrs; ++i) {
  520. pmc_cntrl[0][i].evnts = ctr[i].event;
  521. pmc_cntrl[0][i].masks = ctr[i].unit_mask;
  522. pmc_cntrl[0][i].enabled = ctr[i].enabled;
  523. pmc_cntrl[0][i].vcntr = i;
  524. for_each_possible_cpu(j)
  525. per_cpu(pmc_values, j)[i] = 0;
  526. }
  527. /*
  528. * Setup the thread 1 events, map the thread 0 event to the
  529. * equivalent thread 1 event.
  530. */
  531. for (i = 0; i < num_ctrs; ++i) {
  532. if ((ctr[i].event >= 2100) && (ctr[i].event <= 2111))
  533. pmc_cntrl[1][i].evnts = ctr[i].event + 19;
  534. else if (ctr[i].event == 2203)
  535. pmc_cntrl[1][i].evnts = ctr[i].event;
  536. else if ((ctr[i].event >= 2200) && (ctr[i].event <= 2215))
  537. pmc_cntrl[1][i].evnts = ctr[i].event + 16;
  538. else
  539. pmc_cntrl[1][i].evnts = ctr[i].event;
  540. pmc_cntrl[1][i].masks = ctr[i].unit_mask;
  541. pmc_cntrl[1][i].enabled = ctr[i].enabled;
  542. pmc_cntrl[1][i].vcntr = i;
  543. }
  544. for (i = 0; i < NUM_INPUT_BUS_WORDS; i++)
  545. input_bus[i] = 0xff;
  546. /*
  547. * Our counters count up, and "count" refers to
  548. * how much before the next interrupt, and we interrupt
  549. * on overflow. So we calculate the starting value
  550. * which will give us "count" until overflow.
  551. * Then we set the events on the enabled counters.
  552. */
  553. for (i = 0; i < num_counters; ++i) {
  554. /* start with virtual counter set 0 */
  555. if (pmc_cntrl[0][i].enabled) {
  556. /* Using 32bit counters, reset max - count */
  557. reset_value[i] = 0xFFFFFFFF - ctr[i].count;
  558. set_pm_event(i,
  559. pmc_cntrl[0][i].evnts,
  560. pmc_cntrl[0][i].masks);
  561. /* global, used by cell_cpu_setup */
  562. ctr_enabled |= (1 << i);
  563. }
  564. }
  565. /* initialize the previous counts for the virtual cntrs */
  566. for_each_online_cpu(cpu)
  567. for (i = 0; i < num_counters; ++i) {
  568. per_cpu(pmc_values, cpu)[i] = reset_value[i];
  569. }
  570. return 0;
  571. }
  572. /* This function is called once for each cpu */
  573. static int cell_cpu_setup(struct op_counter_config *cntr)
  574. {
  575. u32 cpu = smp_processor_id();
  576. u32 num_enabled = 0;
  577. int i;
  578. if (spu_cycle_reset)
  579. return 0;
  580. /* There is one performance monitor per processor chip (i.e. node),
  581. * so we only need to perform this function once per node.
  582. */
  583. if (cbe_get_hw_thread_id(cpu))
  584. return 0;
  585. /* Stop all counters */
  586. cbe_disable_pm(cpu);
  587. cbe_disable_pm_interrupts(cpu);
  588. cbe_write_pm(cpu, pm_interval, 0);
  589. cbe_write_pm(cpu, pm_start_stop, 0);
  590. cbe_write_pm(cpu, group_control, pm_regs.group_control);
  591. cbe_write_pm(cpu, debug_bus_control, pm_regs.debug_bus_control);
  592. write_pm_cntrl(cpu);
  593. for (i = 0; i < num_counters; ++i) {
  594. if (ctr_enabled & (1 << i)) {
  595. pm_signal[num_enabled].cpu = cbe_cpu_to_node(cpu);
  596. num_enabled++;
  597. }
  598. }
  599. /*
  600. * The pm_rtas_activate_signals will return -EIO if the FW
  601. * call failed.
  602. */
  603. return pm_rtas_activate_signals(cbe_cpu_to_node(cpu), num_enabled);
  604. }
  605. #define ENTRIES 303
  606. #define MAXLFSR 0xFFFFFF
  607. /* precomputed table of 24 bit LFSR values */
  608. static int initial_lfsr[] = {
  609. 8221349, 12579195, 5379618, 10097839, 7512963, 7519310, 3955098, 10753424,
  610. 15507573, 7458917, 285419, 2641121, 9780088, 3915503, 6668768, 1548716,
  611. 4885000, 8774424, 9650099, 2044357, 2304411, 9326253, 10332526, 4421547,
  612. 3440748, 10179459, 13332843, 10375561, 1313462, 8375100, 5198480, 6071392,
  613. 9341783, 1526887, 3985002, 1439429, 13923762, 7010104, 11969769, 4547026,
  614. 2040072, 4025602, 3437678, 7939992, 11444177, 4496094, 9803157, 10745556,
  615. 3671780, 4257846, 5662259, 13196905, 3237343, 12077182, 16222879, 7587769,
  616. 14706824, 2184640, 12591135, 10420257, 7406075, 3648978, 11042541, 15906893,
  617. 11914928, 4732944, 10695697, 12928164, 11980531, 4430912, 11939291, 2917017,
  618. 6119256, 4172004, 9373765, 8410071, 14788383, 5047459, 5474428, 1737756,
  619. 15967514, 13351758, 6691285, 8034329, 2856544, 14394753, 11310160, 12149558,
  620. 7487528, 7542781, 15668898, 12525138, 12790975, 3707933, 9106617, 1965401,
  621. 16219109, 12801644, 2443203, 4909502, 8762329, 3120803, 6360315, 9309720,
  622. 15164599, 10844842, 4456529, 6667610, 14924259, 884312, 6234963, 3326042,
  623. 15973422, 13919464, 5272099, 6414643, 3909029, 2764324, 5237926, 4774955,
  624. 10445906, 4955302, 5203726, 10798229, 11443419, 2303395, 333836, 9646934,
  625. 3464726, 4159182, 568492, 995747, 10318756, 13299332, 4836017, 8237783,
  626. 3878992, 2581665, 11394667, 5672745, 14412947, 3159169, 9094251, 16467278,
  627. 8671392, 15230076, 4843545, 7009238, 15504095, 1494895, 9627886, 14485051,
  628. 8304291, 252817, 12421642, 16085736, 4774072, 2456177, 4160695, 15409741,
  629. 4902868, 5793091, 13162925, 16039714, 782255, 11347835, 14884586, 366972,
  630. 16308990, 11913488, 13390465, 2958444, 10340278, 1177858, 1319431, 10426302,
  631. 2868597, 126119, 5784857, 5245324, 10903900, 16436004, 3389013, 1742384,
  632. 14674502, 10279218, 8536112, 10364279, 6877778, 14051163, 1025130, 6072469,
  633. 1988305, 8354440, 8216060, 16342977, 13112639, 3976679, 5913576, 8816697,
  634. 6879995, 14043764, 3339515, 9364420, 15808858, 12261651, 2141560, 5636398,
  635. 10345425, 10414756, 781725, 6155650, 4746914, 5078683, 7469001, 6799140,
  636. 10156444, 9667150, 10116470, 4133858, 2121972, 1124204, 1003577, 1611214,
  637. 14304602, 16221850, 13878465, 13577744, 3629235, 8772583, 10881308, 2410386,
  638. 7300044, 5378855, 9301235, 12755149, 4977682, 8083074, 10327581, 6395087,
  639. 9155434, 15501696, 7514362, 14520507, 15808945, 3244584, 4741962, 9658130,
  640. 14336147, 8654727, 7969093, 15759799, 14029445, 5038459, 9894848, 8659300,
  641. 13699287, 8834306, 10712885, 14753895, 10410465, 3373251, 309501, 9561475,
  642. 5526688, 14647426, 14209836, 5339224, 207299, 14069911, 8722990, 2290950,
  643. 3258216, 12505185, 6007317, 9218111, 14661019, 10537428, 11731949, 9027003,
  644. 6641507, 9490160, 200241, 9720425, 16277895, 10816638, 1554761, 10431375,
  645. 7467528, 6790302, 3429078, 14633753, 14428997, 11463204, 3576212, 2003426,
  646. 6123687, 820520, 9992513, 15784513, 5778891, 6428165, 8388607
  647. };
  648. /*
  649. * The hardware uses an LFSR counting sequence to determine when to capture
  650. * the SPU PCs. An LFSR sequence is like a puesdo random number sequence
  651. * where each number occurs once in the sequence but the sequence is not in
  652. * numerical order. The SPU PC capture is done when the LFSR sequence reaches
  653. * the last value in the sequence. Hence the user specified value N
  654. * corresponds to the LFSR number that is N from the end of the sequence.
  655. *
  656. * To avoid the time to compute the LFSR, a lookup table is used. The 24 bit
  657. * LFSR sequence is broken into four ranges. The spacing of the precomputed
  658. * values is adjusted in each range so the error between the user specifed
  659. * number (N) of events between samples and the actual number of events based
  660. * on the precomputed value will be les then about 6.2%. Note, if the user
  661. * specifies N < 2^16, the LFSR value that is 2^16 from the end will be used.
  662. * This is to prevent the loss of samples because the trace buffer is full.
  663. *
  664. * User specified N Step between Index in
  665. * precomputed values precomputed
  666. * table
  667. * 0 to 2^16-1 ---- 0
  668. * 2^16 to 2^16+2^19-1 2^12 1 to 128
  669. * 2^16+2^19 to 2^16+2^19+2^22-1 2^15 129 to 256
  670. * 2^16+2^19+2^22 to 2^24-1 2^18 257 to 302
  671. *
  672. *
  673. * For example, the LFSR values in the second range are computed for 2^16,
  674. * 2^16+2^12, ... , 2^19-2^16, 2^19 and stored in the table at indicies
  675. * 1, 2,..., 127, 128.
  676. *
  677. * The 24 bit LFSR value for the nth number in the sequence can be
  678. * calculated using the following code:
  679. *
  680. * #define size 24
  681. * int calculate_lfsr(int n)
  682. * {
  683. * int i;
  684. * unsigned int newlfsr0;
  685. * unsigned int lfsr = 0xFFFFFF;
  686. * unsigned int howmany = n;
  687. *
  688. * for (i = 2; i < howmany + 2; i++) {
  689. * newlfsr0 = (((lfsr >> (size - 1 - 0)) & 1) ^
  690. * ((lfsr >> (size - 1 - 1)) & 1) ^
  691. * (((lfsr >> (size - 1 - 6)) & 1) ^
  692. * ((lfsr >> (size - 1 - 23)) & 1)));
  693. *
  694. * lfsr >>= 1;
  695. * lfsr = lfsr | (newlfsr0 << (size - 1));
  696. * }
  697. * return lfsr;
  698. * }
  699. */
  700. #define V2_16 (0x1 << 16)
  701. #define V2_19 (0x1 << 19)
  702. #define V2_22 (0x1 << 22)
  703. static int calculate_lfsr(int n)
  704. {
  705. /*
  706. * The ranges and steps are in powers of 2 so the calculations
  707. * can be done using shifts rather then divide.
  708. */
  709. int index;
  710. if ((n >> 16) == 0)
  711. index = 0;
  712. else if (((n - V2_16) >> 19) == 0)
  713. index = ((n - V2_16) >> 12) + 1;
  714. else if (((n - V2_16 - V2_19) >> 22) == 0)
  715. index = ((n - V2_16 - V2_19) >> 15 ) + 1 + 128;
  716. else if (((n - V2_16 - V2_19 - V2_22) >> 24) == 0)
  717. index = ((n - V2_16 - V2_19 - V2_22) >> 18 ) + 1 + 256;
  718. else
  719. index = ENTRIES-1;
  720. /* make sure index is valid */
  721. if ((index > ENTRIES) || (index < 0))
  722. index = ENTRIES-1;
  723. return initial_lfsr[index];
  724. }
  725. static int pm_rtas_activate_spu_profiling(u32 node)
  726. {
  727. int ret, i;
  728. struct pm_signal pm_signal_local[NUM_SPUS_PER_NODE];
  729. /*
  730. * Set up the rtas call to configure the debug bus to
  731. * route the SPU PCs. Setup the pm_signal for each SPU
  732. */
  733. for (i = 0; i < ARRAY_SIZE(pm_signal_local); i++) {
  734. pm_signal_local[i].cpu = node;
  735. pm_signal_local[i].signal_group = 41;
  736. /* spu i on word (i/2) */
  737. pm_signal_local[i].bus_word = 1 << i / 2;
  738. /* spu i */
  739. pm_signal_local[i].sub_unit = i;
  740. pm_signal_local[i].bit = 63;
  741. }
  742. ret = rtas_ibm_cbe_perftools(SUBFUNC_ACTIVATE,
  743. PASSTHRU_ENABLE, pm_signal_local,
  744. (ARRAY_SIZE(pm_signal_local)
  745. * sizeof(struct pm_signal)));
  746. if (unlikely(ret)) {
  747. printk(KERN_WARNING "%s: rtas returned: %d\n",
  748. __func__, ret);
  749. return -EIO;
  750. }
  751. return 0;
  752. }
  753. #ifdef CONFIG_CPU_FREQ
  754. static int
  755. oprof_cpufreq_notify(struct notifier_block *nb, unsigned long val, void *data)
  756. {
  757. int ret = 0;
  758. struct cpufreq_freqs *frq = data;
  759. if ((val == CPUFREQ_PRECHANGE && frq->old < frq->new) ||
  760. (val == CPUFREQ_POSTCHANGE && frq->old > frq->new) ||
  761. (val == CPUFREQ_RESUMECHANGE || val == CPUFREQ_SUSPENDCHANGE))
  762. set_spu_profiling_frequency(frq->new, spu_cycle_reset);
  763. return ret;
  764. }
  765. static struct notifier_block cpu_freq_notifier_block = {
  766. .notifier_call = oprof_cpufreq_notify
  767. };
  768. #endif
  769. static int cell_global_start_spu(struct op_counter_config *ctr)
  770. {
  771. int subfunc;
  772. unsigned int lfsr_value;
  773. int cpu;
  774. int ret;
  775. int rtas_error;
  776. unsigned int cpu_khzfreq = 0;
  777. /* The SPU profiling uses time-based profiling based on
  778. * cpu frequency, so if configured with the CPU_FREQ
  779. * option, we should detect frequency changes and react
  780. * accordingly.
  781. */
  782. #ifdef CONFIG_CPU_FREQ
  783. ret = cpufreq_register_notifier(&cpu_freq_notifier_block,
  784. CPUFREQ_TRANSITION_NOTIFIER);
  785. if (ret < 0)
  786. /* this is not a fatal error */
  787. printk(KERN_ERR "CPU freq change registration failed: %d\n",
  788. ret);
  789. else
  790. cpu_khzfreq = cpufreq_quick_get(smp_processor_id());
  791. #endif
  792. set_spu_profiling_frequency(cpu_khzfreq, spu_cycle_reset);
  793. for_each_online_cpu(cpu) {
  794. if (cbe_get_hw_thread_id(cpu))
  795. continue;
  796. /*
  797. * Setup SPU cycle-based profiling.
  798. * Set perf_mon_control bit 0 to a zero before
  799. * enabling spu collection hardware.
  800. */
  801. cbe_write_pm(cpu, pm_control, 0);
  802. if (spu_cycle_reset > MAX_SPU_COUNT)
  803. /* use largest possible value */
  804. lfsr_value = calculate_lfsr(MAX_SPU_COUNT-1);
  805. else
  806. lfsr_value = calculate_lfsr(spu_cycle_reset);
  807. /* must use a non zero value. Zero disables data collection. */
  808. if (lfsr_value == 0)
  809. lfsr_value = calculate_lfsr(1);
  810. lfsr_value = lfsr_value << 8; /* shift lfsr to correct
  811. * register location
  812. */
  813. /* debug bus setup */
  814. ret = pm_rtas_activate_spu_profiling(cbe_cpu_to_node(cpu));
  815. if (unlikely(ret)) {
  816. rtas_error = ret;
  817. goto out;
  818. }
  819. subfunc = 2; /* 2 - activate SPU tracing, 3 - deactivate */
  820. /* start profiling */
  821. ret = rtas_call(spu_rtas_token, 3, 1, NULL, subfunc,
  822. cbe_cpu_to_node(cpu), lfsr_value);
  823. if (unlikely(ret != 0)) {
  824. printk(KERN_ERR
  825. "%s: rtas call ibm,cbe-spu-perftools failed, return = %d\n",
  826. __func__, ret);
  827. rtas_error = -EIO;
  828. goto out;
  829. }
  830. }
  831. rtas_error = start_spu_profiling(spu_cycle_reset);
  832. if (rtas_error)
  833. goto out_stop;
  834. oprofile_running = 1;
  835. return 0;
  836. out_stop:
  837. cell_global_stop_spu(); /* clean up the PMU/debug bus */
  838. out:
  839. return rtas_error;
  840. }
  841. static int cell_global_start_ppu(struct op_counter_config *ctr)
  842. {
  843. u32 cpu, i;
  844. u32 interrupt_mask = 0;
  845. /* This routine gets called once for the system.
  846. * There is one performance monitor per node, so we
  847. * only need to perform this function once per node.
  848. */
  849. for_each_online_cpu(cpu) {
  850. if (cbe_get_hw_thread_id(cpu))
  851. continue;
  852. interrupt_mask = 0;
  853. for (i = 0; i < num_counters; ++i) {
  854. if (ctr_enabled & (1 << i)) {
  855. cbe_write_ctr(cpu, i, reset_value[i]);
  856. enable_ctr(cpu, i, pm_regs.pm07_cntrl);
  857. interrupt_mask |=
  858. CBE_PM_CTR_OVERFLOW_INTR(i);
  859. } else {
  860. /* Disable counter */
  861. cbe_write_pm07_control(cpu, i, 0);
  862. }
  863. }
  864. cbe_get_and_clear_pm_interrupts(cpu);
  865. cbe_enable_pm_interrupts(cpu, hdw_thread, interrupt_mask);
  866. cbe_enable_pm(cpu);
  867. }
  868. virt_cntr_inter_mask = interrupt_mask;
  869. oprofile_running = 1;
  870. smp_wmb();
  871. /*
  872. * NOTE: start_virt_cntrs will result in cell_virtual_cntr() being
  873. * executed which manipulates the PMU. We start the "virtual counter"
  874. * here so that we do not need to synchronize access to the PMU in
  875. * the above for-loop.
  876. */
  877. start_virt_cntrs();
  878. return 0;
  879. }
  880. static int cell_global_start(struct op_counter_config *ctr)
  881. {
  882. if (spu_cycle_reset)
  883. return cell_global_start_spu(ctr);
  884. else
  885. return cell_global_start_ppu(ctr);
  886. }
  887. /*
  888. * Note the generic OProfile stop calls do not support returning
  889. * an error on stop. Hence, will not return an error if the FW
  890. * calls fail on stop. Failure to reset the debug bus is not an issue.
  891. * Failure to disable the SPU profiling is not an issue. The FW calls
  892. * to enable the performance counters and debug bus will work even if
  893. * the hardware was not cleanly reset.
  894. */
  895. static void cell_global_stop_spu(void)
  896. {
  897. int subfunc, rtn_value;
  898. unsigned int lfsr_value;
  899. int cpu;
  900. oprofile_running = 0;
  901. #ifdef CONFIG_CPU_FREQ
  902. cpufreq_unregister_notifier(&cpu_freq_notifier_block,
  903. CPUFREQ_TRANSITION_NOTIFIER);
  904. #endif
  905. for_each_online_cpu(cpu) {
  906. if (cbe_get_hw_thread_id(cpu))
  907. continue;
  908. subfunc = 3; /*
  909. * 2 - activate SPU tracing,
  910. * 3 - deactivate
  911. */
  912. lfsr_value = 0x8f100000;
  913. rtn_value = rtas_call(spu_rtas_token, 3, 1, NULL,
  914. subfunc, cbe_cpu_to_node(cpu),
  915. lfsr_value);
  916. if (unlikely(rtn_value != 0)) {
  917. printk(KERN_ERR
  918. "%s: rtas call ibm,cbe-spu-perftools failed, return = %d\n",
  919. __func__, rtn_value);
  920. }
  921. /* Deactivate the signals */
  922. pm_rtas_reset_signals(cbe_cpu_to_node(cpu));
  923. }
  924. stop_spu_profiling();
  925. }
  926. static void cell_global_stop_ppu(void)
  927. {
  928. int cpu;
  929. /*
  930. * This routine will be called once for the system.
  931. * There is one performance monitor per node, so we
  932. * only need to perform this function once per node.
  933. */
  934. del_timer_sync(&timer_virt_cntr);
  935. oprofile_running = 0;
  936. smp_wmb();
  937. for_each_online_cpu(cpu) {
  938. if (cbe_get_hw_thread_id(cpu))
  939. continue;
  940. cbe_sync_irq(cbe_cpu_to_node(cpu));
  941. /* Stop the counters */
  942. cbe_disable_pm(cpu);
  943. /* Deactivate the signals */
  944. pm_rtas_reset_signals(cbe_cpu_to_node(cpu));
  945. /* Deactivate interrupts */
  946. cbe_disable_pm_interrupts(cpu);
  947. }
  948. }
  949. static void cell_global_stop(void)
  950. {
  951. if (spu_cycle_reset)
  952. cell_global_stop_spu();
  953. else
  954. cell_global_stop_ppu();
  955. }
  956. static void cell_handle_interrupt(struct pt_regs *regs,
  957. struct op_counter_config *ctr)
  958. {
  959. u32 cpu;
  960. u64 pc;
  961. int is_kernel;
  962. unsigned long flags = 0;
  963. u32 interrupt_mask;
  964. int i;
  965. cpu = smp_processor_id();
  966. /*
  967. * Need to make sure the interrupt handler and the virt counter
  968. * routine are not running at the same time. See the
  969. * cell_virtual_cntr() routine for additional comments.
  970. */
  971. spin_lock_irqsave(&virt_cntr_lock, flags);
  972. /*
  973. * Need to disable and reenable the performance counters
  974. * to get the desired behavior from the hardware. This
  975. * is hardware specific.
  976. */
  977. cbe_disable_pm(cpu);
  978. interrupt_mask = cbe_get_and_clear_pm_interrupts(cpu);
  979. /*
  980. * If the interrupt mask has been cleared, then the virt cntr
  981. * has cleared the interrupt. When the thread that generated
  982. * the interrupt is restored, the data count will be restored to
  983. * 0xffffff0 to cause the interrupt to be regenerated.
  984. */
  985. if ((oprofile_running == 1) && (interrupt_mask != 0)) {
  986. pc = regs->nip;
  987. is_kernel = is_kernel_addr(pc);
  988. for (i = 0; i < num_counters; ++i) {
  989. if ((interrupt_mask & CBE_PM_CTR_OVERFLOW_INTR(i))
  990. && ctr[i].enabled) {
  991. oprofile_add_ext_sample(pc, regs, i, is_kernel);
  992. cbe_write_ctr(cpu, i, reset_value[i]);
  993. }
  994. }
  995. /*
  996. * The counters were frozen by the interrupt.
  997. * Reenable the interrupt and restart the counters.
  998. * If there was a race between the interrupt handler and
  999. * the virtual counter routine. The virutal counter
  1000. * routine may have cleared the interrupts. Hence must
  1001. * use the virt_cntr_inter_mask to re-enable the interrupts.
  1002. */
  1003. cbe_enable_pm_interrupts(cpu, hdw_thread,
  1004. virt_cntr_inter_mask);
  1005. /*
  1006. * The writes to the various performance counters only writes
  1007. * to a latch. The new values (interrupt setting bits, reset
  1008. * counter value etc.) are not copied to the actual registers
  1009. * until the performance monitor is enabled. In order to get
  1010. * this to work as desired, the permormance monitor needs to
  1011. * be disabled while writing to the latches. This is a
  1012. * HW design issue.
  1013. */
  1014. cbe_enable_pm(cpu);
  1015. }
  1016. spin_unlock_irqrestore(&virt_cntr_lock, flags);
  1017. }
  1018. /*
  1019. * This function is called from the generic OProfile
  1020. * driver. When profiling PPUs, we need to do the
  1021. * generic sync start; otherwise, do spu_sync_start.
  1022. */
  1023. static int cell_sync_start(void)
  1024. {
  1025. if (spu_cycle_reset)
  1026. return spu_sync_start();
  1027. else
  1028. return DO_GENERIC_SYNC;
  1029. }
  1030. static int cell_sync_stop(void)
  1031. {
  1032. if (spu_cycle_reset)
  1033. return spu_sync_stop();
  1034. else
  1035. return 1;
  1036. }
  1037. struct op_powerpc_model op_model_cell = {
  1038. .reg_setup = cell_reg_setup,
  1039. .cpu_setup = cell_cpu_setup,
  1040. .global_start = cell_global_start,
  1041. .global_stop = cell_global_stop,
  1042. .sync_start = cell_sync_start,
  1043. .sync_stop = cell_sync_stop,
  1044. .handle_interrupt = cell_handle_interrupt,
  1045. };