perf_event.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182
  1. /* Performance event support for sparc64.
  2. *
  3. * Copyright (C) 2009, 2010 David S. Miller <davem@davemloft.net>
  4. *
  5. * This code is based almost entirely upon the x86 perf event
  6. * code, which is:
  7. *
  8. * Copyright (C) 2008 Thomas Gleixner <tglx@linutronix.de>
  9. * Copyright (C) 2008-2009 Red Hat, Inc., Ingo Molnar
  10. * Copyright (C) 2009 Jaswinder Singh Rajput
  11. * Copyright (C) 2009 Advanced Micro Devices, Inc., Robert Richter
  12. * Copyright (C) 2008-2009 Red Hat, Inc., Peter Zijlstra <pzijlstr@redhat.com>
  13. */
  14. #include <linux/perf_event.h>
  15. #include <linux/kprobes.h>
  16. #include <linux/kernel.h>
  17. #include <linux/kdebug.h>
  18. #include <linux/mutex.h>
  19. #include <asm/stacktrace.h>
  20. #include <asm/cpudata.h>
  21. #include <asm/uaccess.h>
  22. #include <asm/atomic.h>
  23. #include <asm/nmi.h>
  24. #include <asm/pcr.h>
  25. #include "kstack.h"
  26. /* Sparc64 chips have two performance counters, 32-bits each, with
  27. * overflow interrupts generated on transition from 0xffffffff to 0.
  28. * The counters are accessed in one go using a 64-bit register.
  29. *
  30. * Both counters are controlled using a single control register. The
  31. * only way to stop all sampling is to clear all of the context (user,
  32. * supervisor, hypervisor) sampling enable bits. But these bits apply
  33. * to both counters, thus the two counters can't be enabled/disabled
  34. * individually.
  35. *
  36. * The control register has two event fields, one for each of the two
  37. * counters. It's thus nearly impossible to have one counter going
  38. * while keeping the other one stopped. Therefore it is possible to
  39. * get overflow interrupts for counters not currently "in use" and
  40. * that condition must be checked in the overflow interrupt handler.
  41. *
  42. * So we use a hack, in that we program inactive counters with the
  43. * "sw_count0" and "sw_count1" events. These count how many times
  44. * the instruction "sethi %hi(0xfc000), %g0" is executed. It's an
  45. * unusual way to encode a NOP and therefore will not trigger in
  46. * normal code.
  47. */
  48. #define MAX_HWEVENTS 2
  49. #define MAX_PERIOD ((1UL << 32) - 1)
  50. #define PIC_UPPER_INDEX 0
  51. #define PIC_LOWER_INDEX 1
  52. struct cpu_hw_events {
  53. struct perf_event *events[MAX_HWEVENTS];
  54. unsigned long used_mask[BITS_TO_LONGS(MAX_HWEVENTS)];
  55. unsigned long active_mask[BITS_TO_LONGS(MAX_HWEVENTS)];
  56. u64 pcr;
  57. int enabled;
  58. };
  59. DEFINE_PER_CPU(struct cpu_hw_events, cpu_hw_events) = { .enabled = 1, };
  60. struct perf_event_map {
  61. u16 encoding;
  62. u8 pic_mask;
  63. #define PIC_NONE 0x00
  64. #define PIC_UPPER 0x01
  65. #define PIC_LOWER 0x02
  66. };
  67. static unsigned long perf_event_encode(const struct perf_event_map *pmap)
  68. {
  69. return ((unsigned long) pmap->encoding << 16) | pmap->pic_mask;
  70. }
  71. static void perf_event_decode(unsigned long val, u16 *enc, u8 *msk)
  72. {
  73. *msk = val & 0xff;
  74. *enc = val >> 16;
  75. }
  76. #define C(x) PERF_COUNT_HW_CACHE_##x
  77. #define CACHE_OP_UNSUPPORTED 0xfffe
  78. #define CACHE_OP_NONSENSE 0xffff
  79. typedef struct perf_event_map cache_map_t
  80. [PERF_COUNT_HW_CACHE_MAX]
  81. [PERF_COUNT_HW_CACHE_OP_MAX]
  82. [PERF_COUNT_HW_CACHE_RESULT_MAX];
  83. struct sparc_pmu {
  84. const struct perf_event_map *(*event_map)(int);
  85. const cache_map_t *cache_map;
  86. int max_events;
  87. int upper_shift;
  88. int lower_shift;
  89. int event_mask;
  90. int hv_bit;
  91. int irq_bit;
  92. int upper_nop;
  93. int lower_nop;
  94. };
  95. static const struct perf_event_map ultra3_perfmon_event_map[] = {
  96. [PERF_COUNT_HW_CPU_CYCLES] = { 0x0000, PIC_UPPER | PIC_LOWER },
  97. [PERF_COUNT_HW_INSTRUCTIONS] = { 0x0001, PIC_UPPER | PIC_LOWER },
  98. [PERF_COUNT_HW_CACHE_REFERENCES] = { 0x0009, PIC_LOWER },
  99. [PERF_COUNT_HW_CACHE_MISSES] = { 0x0009, PIC_UPPER },
  100. };
  101. static const struct perf_event_map *ultra3_event_map(int event_id)
  102. {
  103. return &ultra3_perfmon_event_map[event_id];
  104. }
  105. static const cache_map_t ultra3_cache_map = {
  106. [C(L1D)] = {
  107. [C(OP_READ)] = {
  108. [C(RESULT_ACCESS)] = { 0x09, PIC_LOWER, },
  109. [C(RESULT_MISS)] = { 0x09, PIC_UPPER, },
  110. },
  111. [C(OP_WRITE)] = {
  112. [C(RESULT_ACCESS)] = { 0x0a, PIC_LOWER },
  113. [C(RESULT_MISS)] = { 0x0a, PIC_UPPER },
  114. },
  115. [C(OP_PREFETCH)] = {
  116. [C(RESULT_ACCESS)] = { CACHE_OP_UNSUPPORTED },
  117. [C(RESULT_MISS)] = { CACHE_OP_UNSUPPORTED },
  118. },
  119. },
  120. [C(L1I)] = {
  121. [C(OP_READ)] = {
  122. [C(RESULT_ACCESS)] = { 0x09, PIC_LOWER, },
  123. [C(RESULT_MISS)] = { 0x09, PIC_UPPER, },
  124. },
  125. [ C(OP_WRITE) ] = {
  126. [ C(RESULT_ACCESS) ] = { CACHE_OP_NONSENSE },
  127. [ C(RESULT_MISS) ] = { CACHE_OP_NONSENSE },
  128. },
  129. [ C(OP_PREFETCH) ] = {
  130. [ C(RESULT_ACCESS) ] = { CACHE_OP_UNSUPPORTED },
  131. [ C(RESULT_MISS) ] = { CACHE_OP_UNSUPPORTED },
  132. },
  133. },
  134. [C(LL)] = {
  135. [C(OP_READ)] = {
  136. [C(RESULT_ACCESS)] = { 0x0c, PIC_LOWER, },
  137. [C(RESULT_MISS)] = { 0x0c, PIC_UPPER, },
  138. },
  139. [C(OP_WRITE)] = {
  140. [C(RESULT_ACCESS)] = { 0x0c, PIC_LOWER },
  141. [C(RESULT_MISS)] = { 0x0c, PIC_UPPER },
  142. },
  143. [C(OP_PREFETCH)] = {
  144. [C(RESULT_ACCESS)] = { CACHE_OP_UNSUPPORTED },
  145. [C(RESULT_MISS)] = { CACHE_OP_UNSUPPORTED },
  146. },
  147. },
  148. [C(DTLB)] = {
  149. [C(OP_READ)] = {
  150. [C(RESULT_ACCESS)] = { CACHE_OP_UNSUPPORTED },
  151. [C(RESULT_MISS)] = { 0x12, PIC_UPPER, },
  152. },
  153. [ C(OP_WRITE) ] = {
  154. [ C(RESULT_ACCESS) ] = { CACHE_OP_UNSUPPORTED },
  155. [ C(RESULT_MISS) ] = { CACHE_OP_UNSUPPORTED },
  156. },
  157. [ C(OP_PREFETCH) ] = {
  158. [ C(RESULT_ACCESS) ] = { CACHE_OP_UNSUPPORTED },
  159. [ C(RESULT_MISS) ] = { CACHE_OP_UNSUPPORTED },
  160. },
  161. },
  162. [C(ITLB)] = {
  163. [C(OP_READ)] = {
  164. [C(RESULT_ACCESS)] = { CACHE_OP_UNSUPPORTED },
  165. [C(RESULT_MISS)] = { 0x11, PIC_UPPER, },
  166. },
  167. [ C(OP_WRITE) ] = {
  168. [ C(RESULT_ACCESS) ] = { CACHE_OP_UNSUPPORTED },
  169. [ C(RESULT_MISS) ] = { CACHE_OP_UNSUPPORTED },
  170. },
  171. [ C(OP_PREFETCH) ] = {
  172. [ C(RESULT_ACCESS) ] = { CACHE_OP_UNSUPPORTED },
  173. [ C(RESULT_MISS) ] = { CACHE_OP_UNSUPPORTED },
  174. },
  175. },
  176. [C(BPU)] = {
  177. [C(OP_READ)] = {
  178. [C(RESULT_ACCESS)] = { CACHE_OP_UNSUPPORTED },
  179. [C(RESULT_MISS)] = { CACHE_OP_UNSUPPORTED },
  180. },
  181. [ C(OP_WRITE) ] = {
  182. [ C(RESULT_ACCESS) ] = { CACHE_OP_UNSUPPORTED },
  183. [ C(RESULT_MISS) ] = { CACHE_OP_UNSUPPORTED },
  184. },
  185. [ C(OP_PREFETCH) ] = {
  186. [ C(RESULT_ACCESS) ] = { CACHE_OP_UNSUPPORTED },
  187. [ C(RESULT_MISS) ] = { CACHE_OP_UNSUPPORTED },
  188. },
  189. },
  190. };
  191. static const struct sparc_pmu ultra3_pmu = {
  192. .event_map = ultra3_event_map,
  193. .cache_map = &ultra3_cache_map,
  194. .max_events = ARRAY_SIZE(ultra3_perfmon_event_map),
  195. .upper_shift = 11,
  196. .lower_shift = 4,
  197. .event_mask = 0x3f,
  198. .upper_nop = 0x1c,
  199. .lower_nop = 0x14,
  200. };
  201. /* Niagara1 is very limited. The upper PIC is hard-locked to count
  202. * only instructions, so it is free running which creates all kinds of
  203. * problems. Some hardware designs make one wonder if the creator
  204. * even looked at how this stuff gets used by software.
  205. */
  206. static const struct perf_event_map niagara1_perfmon_event_map[] = {
  207. [PERF_COUNT_HW_CPU_CYCLES] = { 0x00, PIC_UPPER },
  208. [PERF_COUNT_HW_INSTRUCTIONS] = { 0x00, PIC_UPPER },
  209. [PERF_COUNT_HW_CACHE_REFERENCES] = { 0, PIC_NONE },
  210. [PERF_COUNT_HW_CACHE_MISSES] = { 0x03, PIC_LOWER },
  211. };
  212. static const struct perf_event_map *niagara1_event_map(int event_id)
  213. {
  214. return &niagara1_perfmon_event_map[event_id];
  215. }
  216. static const cache_map_t niagara1_cache_map = {
  217. [C(L1D)] = {
  218. [C(OP_READ)] = {
  219. [C(RESULT_ACCESS)] = { CACHE_OP_UNSUPPORTED },
  220. [C(RESULT_MISS)] = { 0x03, PIC_LOWER, },
  221. },
  222. [C(OP_WRITE)] = {
  223. [C(RESULT_ACCESS)] = { CACHE_OP_UNSUPPORTED },
  224. [C(RESULT_MISS)] = { 0x03, PIC_LOWER, },
  225. },
  226. [C(OP_PREFETCH)] = {
  227. [C(RESULT_ACCESS)] = { CACHE_OP_UNSUPPORTED },
  228. [C(RESULT_MISS)] = { CACHE_OP_UNSUPPORTED },
  229. },
  230. },
  231. [C(L1I)] = {
  232. [C(OP_READ)] = {
  233. [C(RESULT_ACCESS)] = { 0x00, PIC_UPPER },
  234. [C(RESULT_MISS)] = { 0x02, PIC_LOWER, },
  235. },
  236. [ C(OP_WRITE) ] = {
  237. [ C(RESULT_ACCESS) ] = { CACHE_OP_NONSENSE },
  238. [ C(RESULT_MISS) ] = { CACHE_OP_NONSENSE },
  239. },
  240. [ C(OP_PREFETCH) ] = {
  241. [ C(RESULT_ACCESS) ] = { CACHE_OP_UNSUPPORTED },
  242. [ C(RESULT_MISS) ] = { CACHE_OP_UNSUPPORTED },
  243. },
  244. },
  245. [C(LL)] = {
  246. [C(OP_READ)] = {
  247. [C(RESULT_ACCESS)] = { CACHE_OP_UNSUPPORTED },
  248. [C(RESULT_MISS)] = { 0x07, PIC_LOWER, },
  249. },
  250. [C(OP_WRITE)] = {
  251. [C(RESULT_ACCESS)] = { CACHE_OP_UNSUPPORTED },
  252. [C(RESULT_MISS)] = { 0x07, PIC_LOWER, },
  253. },
  254. [C(OP_PREFETCH)] = {
  255. [C(RESULT_ACCESS)] = { CACHE_OP_UNSUPPORTED },
  256. [C(RESULT_MISS)] = { CACHE_OP_UNSUPPORTED },
  257. },
  258. },
  259. [C(DTLB)] = {
  260. [C(OP_READ)] = {
  261. [C(RESULT_ACCESS)] = { CACHE_OP_UNSUPPORTED },
  262. [C(RESULT_MISS)] = { 0x05, PIC_LOWER, },
  263. },
  264. [ C(OP_WRITE) ] = {
  265. [ C(RESULT_ACCESS) ] = { CACHE_OP_UNSUPPORTED },
  266. [ C(RESULT_MISS) ] = { CACHE_OP_UNSUPPORTED },
  267. },
  268. [ C(OP_PREFETCH) ] = {
  269. [ C(RESULT_ACCESS) ] = { CACHE_OP_UNSUPPORTED },
  270. [ C(RESULT_MISS) ] = { CACHE_OP_UNSUPPORTED },
  271. },
  272. },
  273. [C(ITLB)] = {
  274. [C(OP_READ)] = {
  275. [C(RESULT_ACCESS)] = { CACHE_OP_UNSUPPORTED },
  276. [C(RESULT_MISS)] = { 0x04, PIC_LOWER, },
  277. },
  278. [ C(OP_WRITE) ] = {
  279. [ C(RESULT_ACCESS) ] = { CACHE_OP_UNSUPPORTED },
  280. [ C(RESULT_MISS) ] = { CACHE_OP_UNSUPPORTED },
  281. },
  282. [ C(OP_PREFETCH) ] = {
  283. [ C(RESULT_ACCESS) ] = { CACHE_OP_UNSUPPORTED },
  284. [ C(RESULT_MISS) ] = { CACHE_OP_UNSUPPORTED },
  285. },
  286. },
  287. [C(BPU)] = {
  288. [C(OP_READ)] = {
  289. [C(RESULT_ACCESS)] = { CACHE_OP_UNSUPPORTED },
  290. [C(RESULT_MISS)] = { CACHE_OP_UNSUPPORTED },
  291. },
  292. [ C(OP_WRITE) ] = {
  293. [ C(RESULT_ACCESS) ] = { CACHE_OP_UNSUPPORTED },
  294. [ C(RESULT_MISS) ] = { CACHE_OP_UNSUPPORTED },
  295. },
  296. [ C(OP_PREFETCH) ] = {
  297. [ C(RESULT_ACCESS) ] = { CACHE_OP_UNSUPPORTED },
  298. [ C(RESULT_MISS) ] = { CACHE_OP_UNSUPPORTED },
  299. },
  300. },
  301. };
  302. static const struct sparc_pmu niagara1_pmu = {
  303. .event_map = niagara1_event_map,
  304. .cache_map = &niagara1_cache_map,
  305. .max_events = ARRAY_SIZE(niagara1_perfmon_event_map),
  306. .upper_shift = 0,
  307. .lower_shift = 4,
  308. .event_mask = 0x7,
  309. .upper_nop = 0x0,
  310. .lower_nop = 0x0,
  311. };
  312. static const struct perf_event_map niagara2_perfmon_event_map[] = {
  313. [PERF_COUNT_HW_CPU_CYCLES] = { 0x02ff, PIC_UPPER | PIC_LOWER },
  314. [PERF_COUNT_HW_INSTRUCTIONS] = { 0x02ff, PIC_UPPER | PIC_LOWER },
  315. [PERF_COUNT_HW_CACHE_REFERENCES] = { 0x0208, PIC_UPPER | PIC_LOWER },
  316. [PERF_COUNT_HW_CACHE_MISSES] = { 0x0302, PIC_UPPER | PIC_LOWER },
  317. [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = { 0x0201, PIC_UPPER | PIC_LOWER },
  318. [PERF_COUNT_HW_BRANCH_MISSES] = { 0x0202, PIC_UPPER | PIC_LOWER },
  319. };
  320. static const struct perf_event_map *niagara2_event_map(int event_id)
  321. {
  322. return &niagara2_perfmon_event_map[event_id];
  323. }
  324. static const cache_map_t niagara2_cache_map = {
  325. [C(L1D)] = {
  326. [C(OP_READ)] = {
  327. [C(RESULT_ACCESS)] = { 0x0208, PIC_UPPER | PIC_LOWER, },
  328. [C(RESULT_MISS)] = { 0x0302, PIC_UPPER | PIC_LOWER, },
  329. },
  330. [C(OP_WRITE)] = {
  331. [C(RESULT_ACCESS)] = { 0x0210, PIC_UPPER | PIC_LOWER, },
  332. [C(RESULT_MISS)] = { 0x0302, PIC_UPPER | PIC_LOWER, },
  333. },
  334. [C(OP_PREFETCH)] = {
  335. [C(RESULT_ACCESS)] = { CACHE_OP_UNSUPPORTED },
  336. [C(RESULT_MISS)] = { CACHE_OP_UNSUPPORTED },
  337. },
  338. },
  339. [C(L1I)] = {
  340. [C(OP_READ)] = {
  341. [C(RESULT_ACCESS)] = { 0x02ff, PIC_UPPER | PIC_LOWER, },
  342. [C(RESULT_MISS)] = { 0x0301, PIC_UPPER | PIC_LOWER, },
  343. },
  344. [ C(OP_WRITE) ] = {
  345. [ C(RESULT_ACCESS) ] = { CACHE_OP_NONSENSE },
  346. [ C(RESULT_MISS) ] = { CACHE_OP_NONSENSE },
  347. },
  348. [ C(OP_PREFETCH) ] = {
  349. [ C(RESULT_ACCESS) ] = { CACHE_OP_UNSUPPORTED },
  350. [ C(RESULT_MISS) ] = { CACHE_OP_UNSUPPORTED },
  351. },
  352. },
  353. [C(LL)] = {
  354. [C(OP_READ)] = {
  355. [C(RESULT_ACCESS)] = { 0x0208, PIC_UPPER | PIC_LOWER, },
  356. [C(RESULT_MISS)] = { 0x0330, PIC_UPPER | PIC_LOWER, },
  357. },
  358. [C(OP_WRITE)] = {
  359. [C(RESULT_ACCESS)] = { 0x0210, PIC_UPPER | PIC_LOWER, },
  360. [C(RESULT_MISS)] = { 0x0320, PIC_UPPER | PIC_LOWER, },
  361. },
  362. [C(OP_PREFETCH)] = {
  363. [C(RESULT_ACCESS)] = { CACHE_OP_UNSUPPORTED },
  364. [C(RESULT_MISS)] = { CACHE_OP_UNSUPPORTED },
  365. },
  366. },
  367. [C(DTLB)] = {
  368. [C(OP_READ)] = {
  369. [C(RESULT_ACCESS)] = { CACHE_OP_UNSUPPORTED },
  370. [C(RESULT_MISS)] = { 0x0b08, PIC_UPPER | PIC_LOWER, },
  371. },
  372. [ C(OP_WRITE) ] = {
  373. [ C(RESULT_ACCESS) ] = { CACHE_OP_UNSUPPORTED },
  374. [ C(RESULT_MISS) ] = { CACHE_OP_UNSUPPORTED },
  375. },
  376. [ C(OP_PREFETCH) ] = {
  377. [ C(RESULT_ACCESS) ] = { CACHE_OP_UNSUPPORTED },
  378. [ C(RESULT_MISS) ] = { CACHE_OP_UNSUPPORTED },
  379. },
  380. },
  381. [C(ITLB)] = {
  382. [C(OP_READ)] = {
  383. [C(RESULT_ACCESS)] = { CACHE_OP_UNSUPPORTED },
  384. [C(RESULT_MISS)] = { 0xb04, PIC_UPPER | PIC_LOWER, },
  385. },
  386. [ C(OP_WRITE) ] = {
  387. [ C(RESULT_ACCESS) ] = { CACHE_OP_UNSUPPORTED },
  388. [ C(RESULT_MISS) ] = { CACHE_OP_UNSUPPORTED },
  389. },
  390. [ C(OP_PREFETCH) ] = {
  391. [ C(RESULT_ACCESS) ] = { CACHE_OP_UNSUPPORTED },
  392. [ C(RESULT_MISS) ] = { CACHE_OP_UNSUPPORTED },
  393. },
  394. },
  395. [C(BPU)] = {
  396. [C(OP_READ)] = {
  397. [C(RESULT_ACCESS)] = { CACHE_OP_UNSUPPORTED },
  398. [C(RESULT_MISS)] = { CACHE_OP_UNSUPPORTED },
  399. },
  400. [ C(OP_WRITE) ] = {
  401. [ C(RESULT_ACCESS) ] = { CACHE_OP_UNSUPPORTED },
  402. [ C(RESULT_MISS) ] = { CACHE_OP_UNSUPPORTED },
  403. },
  404. [ C(OP_PREFETCH) ] = {
  405. [ C(RESULT_ACCESS) ] = { CACHE_OP_UNSUPPORTED },
  406. [ C(RESULT_MISS) ] = { CACHE_OP_UNSUPPORTED },
  407. },
  408. },
  409. };
  410. static const struct sparc_pmu niagara2_pmu = {
  411. .event_map = niagara2_event_map,
  412. .cache_map = &niagara2_cache_map,
  413. .max_events = ARRAY_SIZE(niagara2_perfmon_event_map),
  414. .upper_shift = 19,
  415. .lower_shift = 6,
  416. .event_mask = 0xfff,
  417. .hv_bit = 0x8,
  418. .irq_bit = 0x30,
  419. .upper_nop = 0x220,
  420. .lower_nop = 0x220,
  421. };
  422. static const struct sparc_pmu *sparc_pmu __read_mostly;
  423. static u64 event_encoding(u64 event_id, int idx)
  424. {
  425. if (idx == PIC_UPPER_INDEX)
  426. event_id <<= sparc_pmu->upper_shift;
  427. else
  428. event_id <<= sparc_pmu->lower_shift;
  429. return event_id;
  430. }
  431. static u64 mask_for_index(int idx)
  432. {
  433. return event_encoding(sparc_pmu->event_mask, idx);
  434. }
  435. static u64 nop_for_index(int idx)
  436. {
  437. return event_encoding(idx == PIC_UPPER_INDEX ?
  438. sparc_pmu->upper_nop :
  439. sparc_pmu->lower_nop, idx);
  440. }
  441. static inline void sparc_pmu_enable_event(struct cpu_hw_events *cpuc, struct hw_perf_event *hwc, int idx)
  442. {
  443. u64 val, mask = mask_for_index(idx);
  444. val = cpuc->pcr;
  445. val &= ~mask;
  446. val |= hwc->config;
  447. cpuc->pcr = val;
  448. pcr_ops->write(cpuc->pcr);
  449. }
  450. static inline void sparc_pmu_disable_event(struct cpu_hw_events *cpuc, struct hw_perf_event *hwc, int idx)
  451. {
  452. u64 mask = mask_for_index(idx);
  453. u64 nop = nop_for_index(idx);
  454. u64 val;
  455. val = cpuc->pcr;
  456. val &= ~mask;
  457. val |= nop;
  458. cpuc->pcr = val;
  459. pcr_ops->write(cpuc->pcr);
  460. }
  461. void hw_perf_enable(void)
  462. {
  463. struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
  464. u64 val;
  465. int i;
  466. if (cpuc->enabled)
  467. return;
  468. cpuc->enabled = 1;
  469. barrier();
  470. val = cpuc->pcr;
  471. for (i = 0; i < MAX_HWEVENTS; i++) {
  472. struct perf_event *cp = cpuc->events[i];
  473. struct hw_perf_event *hwc;
  474. if (!cp)
  475. continue;
  476. hwc = &cp->hw;
  477. val |= hwc->config_base;
  478. }
  479. cpuc->pcr = val;
  480. pcr_ops->write(cpuc->pcr);
  481. }
  482. void hw_perf_disable(void)
  483. {
  484. struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
  485. u64 val;
  486. if (!cpuc->enabled)
  487. return;
  488. cpuc->enabled = 0;
  489. val = cpuc->pcr;
  490. val &= ~(PCR_UTRACE | PCR_STRACE |
  491. sparc_pmu->hv_bit | sparc_pmu->irq_bit);
  492. cpuc->pcr = val;
  493. pcr_ops->write(cpuc->pcr);
  494. }
  495. static u32 read_pmc(int idx)
  496. {
  497. u64 val;
  498. read_pic(val);
  499. if (idx == PIC_UPPER_INDEX)
  500. val >>= 32;
  501. return val & 0xffffffff;
  502. }
  503. static void write_pmc(int idx, u64 val)
  504. {
  505. u64 shift, mask, pic;
  506. shift = 0;
  507. if (idx == PIC_UPPER_INDEX)
  508. shift = 32;
  509. mask = ((u64) 0xffffffff) << shift;
  510. val <<= shift;
  511. read_pic(pic);
  512. pic &= ~mask;
  513. pic |= val;
  514. write_pic(pic);
  515. }
  516. static int sparc_perf_event_set_period(struct perf_event *event,
  517. struct hw_perf_event *hwc, int idx)
  518. {
  519. s64 left = atomic64_read(&hwc->period_left);
  520. s64 period = hwc->sample_period;
  521. int ret = 0;
  522. if (unlikely(left <= -period)) {
  523. left = period;
  524. atomic64_set(&hwc->period_left, left);
  525. hwc->last_period = period;
  526. ret = 1;
  527. }
  528. if (unlikely(left <= 0)) {
  529. left += period;
  530. atomic64_set(&hwc->period_left, left);
  531. hwc->last_period = period;
  532. ret = 1;
  533. }
  534. if (left > MAX_PERIOD)
  535. left = MAX_PERIOD;
  536. atomic64_set(&hwc->prev_count, (u64)-left);
  537. write_pmc(idx, (u64)(-left) & 0xffffffff);
  538. perf_event_update_userpage(event);
  539. return ret;
  540. }
  541. static int sparc_pmu_enable(struct perf_event *event)
  542. {
  543. struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
  544. struct hw_perf_event *hwc = &event->hw;
  545. int idx = hwc->idx;
  546. if (test_and_set_bit(idx, cpuc->used_mask))
  547. return -EAGAIN;
  548. sparc_pmu_disable_event(cpuc, hwc, idx);
  549. cpuc->events[idx] = event;
  550. set_bit(idx, cpuc->active_mask);
  551. sparc_perf_event_set_period(event, hwc, idx);
  552. sparc_pmu_enable_event(cpuc, hwc, idx);
  553. perf_event_update_userpage(event);
  554. return 0;
  555. }
  556. static u64 sparc_perf_event_update(struct perf_event *event,
  557. struct hw_perf_event *hwc, int idx)
  558. {
  559. int shift = 64 - 32;
  560. u64 prev_raw_count, new_raw_count;
  561. s64 delta;
  562. again:
  563. prev_raw_count = atomic64_read(&hwc->prev_count);
  564. new_raw_count = read_pmc(idx);
  565. if (atomic64_cmpxchg(&hwc->prev_count, prev_raw_count,
  566. new_raw_count) != prev_raw_count)
  567. goto again;
  568. delta = (new_raw_count << shift) - (prev_raw_count << shift);
  569. delta >>= shift;
  570. atomic64_add(delta, &event->count);
  571. atomic64_sub(delta, &hwc->period_left);
  572. return new_raw_count;
  573. }
  574. static void sparc_pmu_disable(struct perf_event *event)
  575. {
  576. struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
  577. struct hw_perf_event *hwc = &event->hw;
  578. int idx = hwc->idx;
  579. clear_bit(idx, cpuc->active_mask);
  580. sparc_pmu_disable_event(cpuc, hwc, idx);
  581. barrier();
  582. sparc_perf_event_update(event, hwc, idx);
  583. cpuc->events[idx] = NULL;
  584. clear_bit(idx, cpuc->used_mask);
  585. perf_event_update_userpage(event);
  586. }
  587. static void sparc_pmu_read(struct perf_event *event)
  588. {
  589. struct hw_perf_event *hwc = &event->hw;
  590. sparc_perf_event_update(event, hwc, hwc->idx);
  591. }
  592. static void sparc_pmu_unthrottle(struct perf_event *event)
  593. {
  594. struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
  595. struct hw_perf_event *hwc = &event->hw;
  596. sparc_pmu_enable_event(cpuc, hwc, hwc->idx);
  597. }
  598. static atomic_t active_events = ATOMIC_INIT(0);
  599. static DEFINE_MUTEX(pmc_grab_mutex);
  600. static void perf_stop_nmi_watchdog(void *unused)
  601. {
  602. struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
  603. stop_nmi_watchdog(NULL);
  604. cpuc->pcr = pcr_ops->read();
  605. }
  606. void perf_event_grab_pmc(void)
  607. {
  608. if (atomic_inc_not_zero(&active_events))
  609. return;
  610. mutex_lock(&pmc_grab_mutex);
  611. if (atomic_read(&active_events) == 0) {
  612. if (atomic_read(&nmi_active) > 0) {
  613. on_each_cpu(perf_stop_nmi_watchdog, NULL, 1);
  614. BUG_ON(atomic_read(&nmi_active) != 0);
  615. }
  616. atomic_inc(&active_events);
  617. }
  618. mutex_unlock(&pmc_grab_mutex);
  619. }
  620. void perf_event_release_pmc(void)
  621. {
  622. if (atomic_dec_and_mutex_lock(&active_events, &pmc_grab_mutex)) {
  623. if (atomic_read(&nmi_active) == 0)
  624. on_each_cpu(start_nmi_watchdog, NULL, 1);
  625. mutex_unlock(&pmc_grab_mutex);
  626. }
  627. }
  628. static const struct perf_event_map *sparc_map_cache_event(u64 config)
  629. {
  630. unsigned int cache_type, cache_op, cache_result;
  631. const struct perf_event_map *pmap;
  632. if (!sparc_pmu->cache_map)
  633. return ERR_PTR(-ENOENT);
  634. cache_type = (config >> 0) & 0xff;
  635. if (cache_type >= PERF_COUNT_HW_CACHE_MAX)
  636. return ERR_PTR(-EINVAL);
  637. cache_op = (config >> 8) & 0xff;
  638. if (cache_op >= PERF_COUNT_HW_CACHE_OP_MAX)
  639. return ERR_PTR(-EINVAL);
  640. cache_result = (config >> 16) & 0xff;
  641. if (cache_result >= PERF_COUNT_HW_CACHE_RESULT_MAX)
  642. return ERR_PTR(-EINVAL);
  643. pmap = &((*sparc_pmu->cache_map)[cache_type][cache_op][cache_result]);
  644. if (pmap->encoding == CACHE_OP_UNSUPPORTED)
  645. return ERR_PTR(-ENOENT);
  646. if (pmap->encoding == CACHE_OP_NONSENSE)
  647. return ERR_PTR(-EINVAL);
  648. return pmap;
  649. }
  650. static void hw_perf_event_destroy(struct perf_event *event)
  651. {
  652. perf_event_release_pmc();
  653. }
  654. /* Make sure all events can be scheduled into the hardware at
  655. * the same time. This is simplified by the fact that we only
  656. * need to support 2 simultaneous HW events.
  657. */
  658. static int sparc_check_constraints(unsigned long *events, int n_ev)
  659. {
  660. if (n_ev <= perf_max_events) {
  661. u8 msk1, msk2;
  662. u16 dummy;
  663. if (n_ev == 1)
  664. return 0;
  665. BUG_ON(n_ev != 2);
  666. perf_event_decode(events[0], &dummy, &msk1);
  667. perf_event_decode(events[1], &dummy, &msk2);
  668. /* If both events can go on any counter, OK. */
  669. if (msk1 == (PIC_UPPER | PIC_LOWER) &&
  670. msk2 == (PIC_UPPER | PIC_LOWER))
  671. return 0;
  672. /* If one event is limited to a specific counter,
  673. * and the other can go on both, OK.
  674. */
  675. if ((msk1 == PIC_UPPER || msk1 == PIC_LOWER) &&
  676. msk2 == (PIC_UPPER | PIC_LOWER))
  677. return 0;
  678. if ((msk2 == PIC_UPPER || msk2 == PIC_LOWER) &&
  679. msk1 == (PIC_UPPER | PIC_LOWER))
  680. return 0;
  681. /* If the events are fixed to different counters, OK. */
  682. if ((msk1 == PIC_UPPER && msk2 == PIC_LOWER) ||
  683. (msk1 == PIC_LOWER && msk2 == PIC_UPPER))
  684. return 0;
  685. /* Otherwise, there is a conflict. */
  686. }
  687. return -1;
  688. }
  689. static int check_excludes(struct perf_event **evts, int n_prev, int n_new)
  690. {
  691. int eu = 0, ek = 0, eh = 0;
  692. struct perf_event *event;
  693. int i, n, first;
  694. n = n_prev + n_new;
  695. if (n <= 1)
  696. return 0;
  697. first = 1;
  698. for (i = 0; i < n; i++) {
  699. event = evts[i];
  700. if (first) {
  701. eu = event->attr.exclude_user;
  702. ek = event->attr.exclude_kernel;
  703. eh = event->attr.exclude_hv;
  704. first = 0;
  705. } else if (event->attr.exclude_user != eu ||
  706. event->attr.exclude_kernel != ek ||
  707. event->attr.exclude_hv != eh) {
  708. return -EAGAIN;
  709. }
  710. }
  711. return 0;
  712. }
  713. static int collect_events(struct perf_event *group, int max_count,
  714. struct perf_event *evts[], unsigned long *events)
  715. {
  716. struct perf_event *event;
  717. int n = 0;
  718. if (!is_software_event(group)) {
  719. if (n >= max_count)
  720. return -1;
  721. evts[n] = group;
  722. events[n++] = group->hw.event_base;
  723. }
  724. list_for_each_entry(event, &group->sibling_list, group_entry) {
  725. if (!is_software_event(event) &&
  726. event->state != PERF_EVENT_STATE_OFF) {
  727. if (n >= max_count)
  728. return -1;
  729. evts[n] = event;
  730. events[n++] = event->hw.event_base;
  731. }
  732. }
  733. return n;
  734. }
  735. static int __hw_perf_event_init(struct perf_event *event)
  736. {
  737. struct perf_event_attr *attr = &event->attr;
  738. struct perf_event *evts[MAX_HWEVENTS];
  739. struct hw_perf_event *hwc = &event->hw;
  740. unsigned long events[MAX_HWEVENTS];
  741. const struct perf_event_map *pmap;
  742. u64 enc;
  743. int n;
  744. if (atomic_read(&nmi_active) < 0)
  745. return -ENODEV;
  746. if (attr->type == PERF_TYPE_HARDWARE) {
  747. if (attr->config >= sparc_pmu->max_events)
  748. return -EINVAL;
  749. pmap = sparc_pmu->event_map(attr->config);
  750. } else if (attr->type == PERF_TYPE_HW_CACHE) {
  751. pmap = sparc_map_cache_event(attr->config);
  752. if (IS_ERR(pmap))
  753. return PTR_ERR(pmap);
  754. } else
  755. return -EOPNOTSUPP;
  756. /* We save the enable bits in the config_base. So to
  757. * turn off sampling just write 'config', and to enable
  758. * things write 'config | config_base'.
  759. */
  760. hwc->config_base = sparc_pmu->irq_bit;
  761. if (!attr->exclude_user)
  762. hwc->config_base |= PCR_UTRACE;
  763. if (!attr->exclude_kernel)
  764. hwc->config_base |= PCR_STRACE;
  765. if (!attr->exclude_hv)
  766. hwc->config_base |= sparc_pmu->hv_bit;
  767. hwc->event_base = perf_event_encode(pmap);
  768. enc = pmap->encoding;
  769. n = 0;
  770. if (event->group_leader != event) {
  771. n = collect_events(event->group_leader,
  772. perf_max_events - 1,
  773. evts, events);
  774. if (n < 0)
  775. return -EINVAL;
  776. }
  777. events[n] = hwc->event_base;
  778. evts[n] = event;
  779. if (check_excludes(evts, n, 1))
  780. return -EINVAL;
  781. if (sparc_check_constraints(events, n + 1))
  782. return -EINVAL;
  783. /* Try to do all error checking before this point, as unwinding
  784. * state after grabbing the PMC is difficult.
  785. */
  786. perf_event_grab_pmc();
  787. event->destroy = hw_perf_event_destroy;
  788. if (!hwc->sample_period) {
  789. hwc->sample_period = MAX_PERIOD;
  790. hwc->last_period = hwc->sample_period;
  791. atomic64_set(&hwc->period_left, hwc->sample_period);
  792. }
  793. if (pmap->pic_mask & PIC_UPPER) {
  794. hwc->idx = PIC_UPPER_INDEX;
  795. enc <<= sparc_pmu->upper_shift;
  796. } else {
  797. hwc->idx = PIC_LOWER_INDEX;
  798. enc <<= sparc_pmu->lower_shift;
  799. }
  800. hwc->config |= enc;
  801. return 0;
  802. }
  803. static const struct pmu pmu = {
  804. .enable = sparc_pmu_enable,
  805. .disable = sparc_pmu_disable,
  806. .read = sparc_pmu_read,
  807. .unthrottle = sparc_pmu_unthrottle,
  808. };
  809. const struct pmu *hw_perf_event_init(struct perf_event *event)
  810. {
  811. int err = __hw_perf_event_init(event);
  812. if (err)
  813. return ERR_PTR(err);
  814. return &pmu;
  815. }
  816. void perf_event_print_debug(void)
  817. {
  818. unsigned long flags;
  819. u64 pcr, pic;
  820. int cpu;
  821. if (!sparc_pmu)
  822. return;
  823. local_irq_save(flags);
  824. cpu = smp_processor_id();
  825. pcr = pcr_ops->read();
  826. read_pic(pic);
  827. pr_info("\n");
  828. pr_info("CPU#%d: PCR[%016llx] PIC[%016llx]\n",
  829. cpu, pcr, pic);
  830. local_irq_restore(flags);
  831. }
  832. static int __kprobes perf_event_nmi_handler(struct notifier_block *self,
  833. unsigned long cmd, void *__args)
  834. {
  835. struct die_args *args = __args;
  836. struct perf_sample_data data;
  837. struct cpu_hw_events *cpuc;
  838. struct pt_regs *regs;
  839. int idx;
  840. if (!atomic_read(&active_events))
  841. return NOTIFY_DONE;
  842. switch (cmd) {
  843. case DIE_NMI:
  844. break;
  845. default:
  846. return NOTIFY_DONE;
  847. }
  848. regs = args->regs;
  849. data.addr = 0;
  850. cpuc = &__get_cpu_var(cpu_hw_events);
  851. /* If the PMU has the TOE IRQ enable bits, we need to do a
  852. * dummy write to the %pcr to clear the overflow bits and thus
  853. * the interrupt.
  854. *
  855. * Do this before we peek at the counters to determine
  856. * overflow so we don't lose any events.
  857. */
  858. if (sparc_pmu->irq_bit)
  859. pcr_ops->write(cpuc->pcr);
  860. for (idx = 0; idx < MAX_HWEVENTS; idx++) {
  861. struct perf_event *event = cpuc->events[idx];
  862. struct hw_perf_event *hwc;
  863. u64 val;
  864. if (!test_bit(idx, cpuc->active_mask))
  865. continue;
  866. hwc = &event->hw;
  867. val = sparc_perf_event_update(event, hwc, idx);
  868. if (val & (1ULL << 31))
  869. continue;
  870. data.period = event->hw.last_period;
  871. if (!sparc_perf_event_set_period(event, hwc, idx))
  872. continue;
  873. if (perf_event_overflow(event, 1, &data, regs))
  874. sparc_pmu_disable_event(cpuc, hwc, idx);
  875. }
  876. return NOTIFY_STOP;
  877. }
  878. static __read_mostly struct notifier_block perf_event_nmi_notifier = {
  879. .notifier_call = perf_event_nmi_handler,
  880. };
  881. static bool __init supported_pmu(void)
  882. {
  883. if (!strcmp(sparc_pmu_type, "ultra3") ||
  884. !strcmp(sparc_pmu_type, "ultra3+") ||
  885. !strcmp(sparc_pmu_type, "ultra3i") ||
  886. !strcmp(sparc_pmu_type, "ultra4+")) {
  887. sparc_pmu = &ultra3_pmu;
  888. return true;
  889. }
  890. if (!strcmp(sparc_pmu_type, "niagara")) {
  891. sparc_pmu = &niagara1_pmu;
  892. return true;
  893. }
  894. if (!strcmp(sparc_pmu_type, "niagara2")) {
  895. sparc_pmu = &niagara2_pmu;
  896. return true;
  897. }
  898. return false;
  899. }
  900. void __init init_hw_perf_events(void)
  901. {
  902. pr_info("Performance events: ");
  903. if (!supported_pmu()) {
  904. pr_cont("No support for PMU type '%s'\n", sparc_pmu_type);
  905. return;
  906. }
  907. pr_cont("Supported PMU type is '%s'\n", sparc_pmu_type);
  908. /* All sparc64 PMUs currently have 2 events. But this simple
  909. * driver only supports one active event at a time.
  910. */
  911. perf_max_events = 1;
  912. register_die_notifier(&perf_event_nmi_notifier);
  913. }
  914. static inline void callchain_store(struct perf_callchain_entry *entry, u64 ip)
  915. {
  916. if (entry->nr < PERF_MAX_STACK_DEPTH)
  917. entry->ip[entry->nr++] = ip;
  918. }
  919. static void perf_callchain_kernel(struct pt_regs *regs,
  920. struct perf_callchain_entry *entry)
  921. {
  922. unsigned long ksp, fp;
  923. callchain_store(entry, PERF_CONTEXT_KERNEL);
  924. callchain_store(entry, regs->tpc);
  925. ksp = regs->u_regs[UREG_I6];
  926. fp = ksp + STACK_BIAS;
  927. do {
  928. struct sparc_stackf *sf;
  929. struct pt_regs *regs;
  930. unsigned long pc;
  931. if (!kstack_valid(current_thread_info(), fp))
  932. break;
  933. sf = (struct sparc_stackf *) fp;
  934. regs = (struct pt_regs *) (sf + 1);
  935. if (kstack_is_trap_frame(current_thread_info(), regs)) {
  936. if (user_mode(regs))
  937. break;
  938. pc = regs->tpc;
  939. fp = regs->u_regs[UREG_I6] + STACK_BIAS;
  940. } else {
  941. pc = sf->callers_pc;
  942. fp = (unsigned long)sf->fp + STACK_BIAS;
  943. }
  944. callchain_store(entry, pc);
  945. } while (entry->nr < PERF_MAX_STACK_DEPTH);
  946. }
  947. static void perf_callchain_user_64(struct pt_regs *regs,
  948. struct perf_callchain_entry *entry)
  949. {
  950. unsigned long ufp;
  951. callchain_store(entry, PERF_CONTEXT_USER);
  952. callchain_store(entry, regs->tpc);
  953. ufp = regs->u_regs[UREG_I6] + STACK_BIAS;
  954. do {
  955. struct sparc_stackf *usf, sf;
  956. unsigned long pc;
  957. usf = (struct sparc_stackf *) ufp;
  958. if (__copy_from_user_inatomic(&sf, usf, sizeof(sf)))
  959. break;
  960. pc = sf.callers_pc;
  961. ufp = (unsigned long)sf.fp + STACK_BIAS;
  962. callchain_store(entry, pc);
  963. } while (entry->nr < PERF_MAX_STACK_DEPTH);
  964. }
  965. static void perf_callchain_user_32(struct pt_regs *regs,
  966. struct perf_callchain_entry *entry)
  967. {
  968. unsigned long ufp;
  969. callchain_store(entry, PERF_CONTEXT_USER);
  970. callchain_store(entry, regs->tpc);
  971. ufp = regs->u_regs[UREG_I6];
  972. do {
  973. struct sparc_stackf32 *usf, sf;
  974. unsigned long pc;
  975. usf = (struct sparc_stackf32 *) ufp;
  976. if (__copy_from_user_inatomic(&sf, usf, sizeof(sf)))
  977. break;
  978. pc = sf.callers_pc;
  979. ufp = (unsigned long)sf.fp;
  980. callchain_store(entry, pc);
  981. } while (entry->nr < PERF_MAX_STACK_DEPTH);
  982. }
  983. /* Like powerpc we can't get PMU interrupts within the PMU handler,
  984. * so no need for seperate NMI and IRQ chains as on x86.
  985. */
  986. static DEFINE_PER_CPU(struct perf_callchain_entry, callchain);
  987. struct perf_callchain_entry *perf_callchain(struct pt_regs *regs)
  988. {
  989. struct perf_callchain_entry *entry = &__get_cpu_var(callchain);
  990. entry->nr = 0;
  991. if (!user_mode(regs)) {
  992. stack_trace_flush();
  993. perf_callchain_kernel(regs, entry);
  994. if (current->mm)
  995. regs = task_pt_regs(current);
  996. else
  997. regs = NULL;
  998. }
  999. if (regs) {
  1000. flushw_user();
  1001. if (test_thread_flag(TIF_32BIT))
  1002. perf_callchain_user_32(regs, entry);
  1003. else
  1004. perf_callchain_user_64(regs, entry);
  1005. }
  1006. return entry;
  1007. }