opteron_pcbe.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. /* Copyright (C) 2021 Free Software Foundation, Inc.
  2. Contributed by Oracle.
  3. This file is part of GNU Binutils.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3, or (at your option)
  7. any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, 51 Franklin Street - Fifth Floor, Boston,
  15. MA 02110-1301, USA. */
  16. /*
  17. * This file contains preset event names from the Performance Application
  18. * Programming Interface v3.5 which included the following notice:
  19. *
  20. * Copyright (c) 2005,6
  21. * Innovative Computing Labs
  22. * Computer Science Department,
  23. * University of Tennessee,
  24. * Knoxville, TN.
  25. * All Rights Reserved.
  26. *
  27. *
  28. * Redistribution and use in source and binary forms, with or without
  29. * modification, are permitted provided that the following conditions are met:
  30. *
  31. * * Redistributions of source code must retain the above copyright notice,
  32. * this list of conditions and the following disclaimer.
  33. * * Redistributions in binary form must reproduce the above copyright
  34. * notice, this list of conditions and the following disclaimer in the
  35. * documentation and/or other materials provided with the distribution.
  36. * * Neither the name of the University of Tennessee nor the names of its
  37. * contributors may be used to endorse or promote products derived from
  38. * this software without specific prior written permission.
  39. *
  40. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  41. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  42. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  43. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  44. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  45. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  46. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  47. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  48. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  49. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  50. * POSSIBILITY OF SUCH DAMAGE.
  51. *
  52. *
  53. * This open source software license conforms to the BSD License template.
  54. */
  55. /*
  56. * Performance Counter Back-End for AMD Opteron and AMD Athlon 64 processors.
  57. */
  58. #include <sys/types.h>
  59. #include "hwcdrv.h"
  60. #define CPU /* used by cpuid_get*() functions */
  61. typedef struct _amd_event
  62. {
  63. char *name;
  64. uint16_t emask; /* Event mask setting */
  65. uint8_t umask_valid; /* Mask of unreserved UNIT_MASK bits */
  66. } amd_event_t;
  67. typedef struct _amd_generic_event
  68. {
  69. char *name;
  70. char *event;
  71. uint8_t umask;
  72. } amd_generic_event_t;
  73. #define EV_END { NULL, 0, 0 }
  74. #define GEN_EV_END { NULL, NULL, 0 }
  75. #define AMD_cmn_events \
  76. { "FP_dispatched_fpu_ops", 0x00, 0x3F }, \
  77. { "FP_cycles_no_fpu_ops_retired", 0x01, 0x0 }, \
  78. { "FP_dispatched_fpu_ops_ff", 0x02, 0x0 }, \
  79. { "LS_seg_reg_load", 0x20, 0x7F }, \
  80. { "LS_uarch_resync_self_modify", 0x21, 0x0 }, \
  81. { "LS_uarch_resync_snoop", 0x22, 0x0 }, \
  82. { "LS_buffer_2_full", 0x23, 0x0 }, \
  83. { "LS_retired_cflush", 0x26, 0x0 }, \
  84. { "LS_retired_cpuid", 0x27, 0x0 }, \
  85. { "DC_access", 0x40, 0x0 }, \
  86. { "DC_miss", 0x41, 0x0 }, \
  87. { "DC_refill_from_L2", 0x42, 0x1F }, \
  88. { "DC_refill_from_system", 0x43, 0x1F }, \
  89. { "DC_misaligned_data_ref", 0x47, 0x0 }, \
  90. { "DC_uarch_late_cancel_access", 0x48, 0x0 }, \
  91. { "DC_uarch_early_cancel_access", 0x49, 0x0 }, \
  92. { "DC_dispatched_prefetch_instr", 0x4B, 0x7 }, \
  93. { "DC_dcache_accesses_by_locks", 0x4C, 0x2 }, \
  94. { "BU_memory_requests", 0x65, 0x83}, \
  95. { "BU_data_prefetch", 0x67, 0x3 }, \
  96. { "BU_cpu_clk_unhalted", 0x76, 0x0 }, \
  97. { "IC_fetch", 0x80, 0x0 }, \
  98. { "IC_miss", 0x81, 0x0 }, \
  99. { "IC_refill_from_L2", 0x82, 0x0 }, \
  100. { "IC_refill_from_system", 0x83, 0x0 }, \
  101. { "IC_itlb_L1_miss_L2_hit", 0x84, 0x0 }, \
  102. { "IC_uarch_resync_snoop", 0x86, 0x0 }, \
  103. { "IC_instr_fetch_stall", 0x87, 0x0 }, \
  104. { "IC_return_stack_hit", 0x88, 0x0 }, \
  105. { "IC_return_stack_overflow", 0x89, 0x0 }, \
  106. { "FR_retired_x86_instr_w_excp_intr", 0xC0, 0x0 }, \
  107. { "FR_retired_uops", 0xC1, 0x0 }, \
  108. { "FR_retired_branches_w_excp_intr", 0xC2, 0x0 }, \
  109. { "FR_retired_branches_mispred", 0xC3, 0x0 }, \
  110. { "FR_retired_taken_branches", 0xC4, 0x0 }, \
  111. { "FR_retired_taken_branches_mispred", 0xC5, 0x0 }, \
  112. { "FR_retired_far_ctl_transfer", 0xC6, 0x0 }, \
  113. { "FR_retired_resyncs", 0xC7, 0x0 }, \
  114. { "FR_retired_near_rets", 0xC8, 0x0 }, \
  115. { "FR_retired_near_rets_mispred", 0xC9, 0x0 }, \
  116. { "FR_retired_taken_branches_mispred_addr_miscomp", 0xCA, 0x0 }, \
  117. { "FR_retired_fastpath_double_op_instr", 0xCC, 0x7 }, \
  118. { "FR_intr_masked_cycles", 0xCD, 0x0 }, \
  119. { "FR_intr_masked_while_pending_cycles", 0xCE, 0x0 }, \
  120. { "FR_taken_hardware_intrs", 0xCF, 0x0 }, \
  121. { "FR_nothing_to_dispatch", 0xD0, 0x0 }, \
  122. { "FR_dispatch_stalls", 0xD1, 0x0 }, \
  123. { "FR_dispatch_stall_branch_abort_to_retire", 0xD2, 0x0 }, \
  124. { "FR_dispatch_stall_serialization", 0xD3, 0x0 }, \
  125. { "FR_dispatch_stall_segment_load", 0xD4, 0x0 }, \
  126. { "FR_dispatch_stall_reorder_buffer_full", 0xD5, 0x0 }, \
  127. { "FR_dispatch_stall_resv_stations_full", 0xD6, 0x0 }, \
  128. { "FR_dispatch_stall_fpu_full", 0xD7, 0x0 }, \
  129. { "FR_dispatch_stall_ls_full", 0xD8, 0x0 }, \
  130. { "FR_dispatch_stall_waiting_all_quiet", 0xD9, 0x0 }, \
  131. { "FR_dispatch_stall_far_ctl_trsfr_resync_branch_pend", 0xDA, 0x0 },\
  132. { "FR_fpu_exception", 0xDB, 0xF }, \
  133. { "FR_num_brkpts_dr0", 0xDC, 0x0 }, \
  134. { "FR_num_brkpts_dr1", 0xDD, 0x0 }, \
  135. { "FR_num_brkpts_dr2", 0xDE, 0x0 }, \
  136. { "FR_num_brkpts_dr3", 0xDF, 0x0 }, \
  137. { "NB_mem_ctrlr_bypass_counter_saturation", 0xE4, 0xF }
  138. #define OPT_events \
  139. { "LS_locked_operation", 0x24, 0x7 }, \
  140. { "DC_copyback", 0x44, 0x1F }, \
  141. { "DC_dtlb_L1_miss_L2_hit", 0x45, 0x0 }, \
  142. { "DC_dtlb_L1_miss_L2_miss", 0x46, 0x0 }, \
  143. { "DC_1bit_ecc_error_found", 0x4A, 0x3 }, \
  144. { "BU_system_read_responses", 0x6C, 0x7 }, \
  145. { "BU_quadwords_written_to_system", 0x6D, 0x1 }, \
  146. { "BU_internal_L2_req", 0x7D, 0x1F }, \
  147. { "BU_fill_req_missed_L2", 0x7E, 0x7 }, \
  148. { "BU_fill_into_L2", 0x7F, 0x1 }, \
  149. { "IC_itlb_L1_miss_L2_miss", 0x85, 0x0 }, \
  150. { "FR_retired_fpu_instr", 0xCB, 0xF }, \
  151. { "NB_mem_ctrlr_page_access", 0xE0, 0x7 }, \
  152. { "NB_mem_ctrlr_page_table_overflow", 0xE1, 0x0 }, \
  153. { "NB_mem_ctrlr_turnaround", 0xE3, 0x7 }, \
  154. { "NB_ECC_errors", 0xE8, 0x80}, \
  155. { "NB_sized_commands", 0xEB, 0x7F }, \
  156. { "NB_probe_result", 0xEC, 0x7F}, \
  157. { "NB_gart_events", 0xEE, 0x7 }, \
  158. { "NB_ht_bus0_bandwidth", 0xF6, 0xF }, \
  159. { "NB_ht_bus1_bandwidth", 0xF7, 0xF }, \
  160. { "NB_ht_bus2_bandwidth", 0xF8, 0xF }
  161. #define OPT_RevD_events \
  162. { "NB_sized_blocks", 0xE5, 0x3C }
  163. #define OPT_RevE_events \
  164. { "NB_cpu_io_to_mem_io", 0xE9, 0xFF}, \
  165. { "NB_cache_block_commands", 0xEA, 0x3D}
  166. #define AMD_FAMILY_10h_cmn_events \
  167. { "FP_retired_sse_ops", 0x3, 0x7F}, \
  168. { "FP_retired_move_ops", 0x4, 0xF}, \
  169. { "FP_retired_serialize_ops", 0x5, 0xF}, \
  170. { "FP_serialize_ops_cycles", 0x6, 0x3}, \
  171. { "DC_copyback", 0x44, 0x7F }, \
  172. { "DC_dtlb_L1_miss_L2_hit", 0x45, 0x3 }, \
  173. { "DC_dtlb_L1_miss_L2_miss", 0x46, 0x7 }, \
  174. { "DC_1bit_ecc_error_found", 0x4A, 0xF }, \
  175. { "DC_dtlb_L1_hit", 0x4D, 0x7 }, \
  176. { "BU_system_read_responses", 0x6C, 0x17 }, \
  177. { "BU_octwords_written_to_system", 0x6D, 0x1 }, \
  178. { "BU_internal_L2_req", 0x7D, 0x3F }, \
  179. { "BU_fill_req_missed_L2", 0x7E, 0xF }, \
  180. { "BU_fill_into_L2", 0x7F, 0x3 }, \
  181. { "IC_itlb_L1_miss_L2_miss", 0x85, 0x3 }, \
  182. { "IC_eviction", 0x8B, 0x0 }, \
  183. { "IC_cache_lines_invalidate", 0x8C, 0xF }, \
  184. { "IC_itlb_reload", 0x99, 0x0 }, \
  185. { "IC_itlb_reload_aborted", 0x9A, 0x0 }, \
  186. { "FR_retired_mmx_sse_fp_instr", 0xCB, 0x7 }, \
  187. { "NB_mem_ctrlr_page_access", 0xE0, 0xFF }, \
  188. { "NB_mem_ctrlr_page_table_overflow", 0xE1, 0x3 }, \
  189. { "NB_mem_ctrlr_turnaround", 0xE3, 0x3F }, \
  190. { "NB_thermal_status", 0xE8, 0x7C}, \
  191. { "NB_sized_commands", 0xEB, 0x3F }, \
  192. { "NB_probe_results_upstream_req", 0xEC, 0xFF}, \
  193. { "NB_gart_events", 0xEE, 0xFF }, \
  194. { "NB_ht_bus0_bandwidth", 0xF6, 0xBF }, \
  195. { "NB_ht_bus1_bandwidth", 0xF7, 0xBF }, \
  196. { "NB_ht_bus2_bandwidth", 0xF8, 0xBF }, \
  197. { "NB_ht_bus3_bandwidth", 0x1F9, 0xBF }, \
  198. { "LS_locked_operation", 0x24, 0xF }, \
  199. { "LS_cancelled_store_to_load_fwd_ops", 0x2A, 0x7 }, \
  200. { "LS_smi_received", 0x2B, 0x0 }, \
  201. { "LS_ineffective_prefetch", 0x52, 0x9 }, \
  202. { "LS_global_tlb_flush", 0x54, 0x0 }, \
  203. { "NB_mem_ctrlr_dram_cmd_slots_missed", 0xE2, 0x3 }, \
  204. { "NB_mem_ctrlr_req", 0x1F0, 0xFF }, \
  205. { "CB_cpu_to_dram_req_to_target", 0x1E0, 0xFF }, \
  206. { "CB_io_to_dram_req_to_target", 0x1E1, 0xFF }, \
  207. { "CB_cpu_read_cmd_latency_to_target_0_to_3", 0x1E2, 0xFF }, \
  208. { "CB_cpu_read_cmd_req_to_target_0_to_3", 0x1E3, 0xFF }, \
  209. { "CB_cpu_read_cmd_latency_to_target_4_to_7", 0x1E4, 0xFF }, \
  210. { "CB_cpu_read_cmd_req_to_target_4_to_7", 0x1E5, 0xFF }, \
  211. { "CB_cpu_cmd_latency_to_target_0_to_7", 0x1E6, 0xFF }, \
  212. { "CB_cpu_req_to_target_0_to_7", 0x1E7, 0xFF }, \
  213. { "L3_read_req", 0x4E0, 0xF7 }, \
  214. { "L3_miss", 0x4E1, 0xF7 }, \
  215. { "L3_l2_eviction_l3_fill", 0x4E2, 0xFF }, \
  216. { "L3_eviction", 0x4E3, 0xF }
  217. #define AMD_cmn_generic_events \
  218. { "PAPI_br_ins", "FR_retired_branches_w_excp_intr", 0x0 },\
  219. { "PAPI_br_msp", "FR_retired_branches_mispred", 0x0 }, \
  220. { "PAPI_br_tkn", "FR_retired_taken_branches", 0x0 }, \
  221. { "PAPI_fp_ops", "FP_dispatched_fpu_ops", 0x3 }, \
  222. { "PAPI_fad_ins", "FP_dispatched_fpu_ops", 0x1 }, \
  223. { "PAPI_fml_ins", "FP_dispatched_fpu_ops", 0x2 }, \
  224. { "PAPI_fpu_idl", "FP_cycles_no_fpu_ops_retired", 0x0 }, \
  225. { "PAPI_tot_cyc", "BU_cpu_clk_unhalted", 0x0 }, \
  226. { "PAPI_tot_ins", "FR_retired_x86_instr_w_excp_intr", 0x0 }, \
  227. { "PAPI_l1_dca", "DC_access", 0x0 }, \
  228. { "PAPI_l1_dcm", "DC_miss", 0x0 }, \
  229. { "PAPI_l1_ldm", "DC_refill_from_L2", 0xe }, \
  230. { "PAPI_l1_stm", "DC_refill_from_L2", 0x10 }, \
  231. { "PAPI_l1_ica", "IC_fetch", 0x0 }, \
  232. { "PAPI_l1_icm", "IC_miss", 0x0 }, \
  233. { "PAPI_l1_icr", "IC_fetch", 0x0 }, \
  234. { "PAPI_l2_dch", "DC_refill_from_L2", 0x1e }, \
  235. { "PAPI_l2_dcm", "DC_refill_from_system", 0x1e }, \
  236. { "PAPI_l2_dcr", "DC_refill_from_L2", 0xe }, \
  237. { "PAPI_l2_dcw", "DC_refill_from_L2", 0x10 }, \
  238. { "PAPI_l2_ich", "IC_refill_from_L2", 0x0 }, \
  239. { "PAPI_l2_icm", "IC_refill_from_system", 0x0 }, \
  240. { "PAPI_l2_ldm", "DC_refill_from_system", 0xe }, \
  241. { "PAPI_l2_stm", "DC_refill_from_system", 0x10 }, \
  242. { "PAPI_res_stl", "FR_dispatch_stalls", 0x0 }, \
  243. { "PAPI_stl_icy", "FR_nothing_to_dispatch", 0x0 }, \
  244. { "PAPI_hw_int", "FR_taken_hardware_intrs", 0x0 }
  245. #define OPT_cmn_generic_events \
  246. { "PAPI_tlb_dm", "DC_dtlb_L1_miss_L2_miss", 0x0 }, \
  247. { "PAPI_tlb_im", "IC_itlb_L1_miss_L2_miss", 0x0 }, \
  248. { "PAPI_fp_ins", "FR_retired_fpu_instr", 0xd }, \
  249. { "PAPI_vec_ins", "FR_retired_fpu_instr", 0x4 }
  250. #define AMD_FAMILY_10h_generic_events \
  251. { "PAPI_tlb_dm", "DC_dtlb_L1_miss_L2_miss", 0x7 }, \
  252. { "PAPI_tlb_im", "IC_itlb_L1_miss_L2_miss", 0x3 }, \
  253. { "PAPI_l3_dcr", "L3_read_req", 0xf1 }, \
  254. { "PAPI_l3_icr", "L3_read_req", 0xf2 }, \
  255. { "PAPI_l3_tcr", "L3_read_req", 0xf7 }, \
  256. { "PAPI_l3_stm", "L3_miss", 0xf4 }, \
  257. { "PAPI_l3_ldm", "L3_miss", 0xf3 }, \
  258. { "PAPI_l3_tcm", "L3_miss", 0xf7 }
  259. static amd_event_t opt_events_rev_E[] = {
  260. AMD_cmn_events,
  261. OPT_events,
  262. OPT_RevD_events,
  263. OPT_RevE_events,
  264. EV_END
  265. };
  266. static amd_event_t family_10h_events[] = {
  267. AMD_cmn_events,
  268. OPT_RevE_events,
  269. AMD_FAMILY_10h_cmn_events,
  270. EV_END
  271. };
  272. static amd_generic_event_t opt_generic_events[] = {
  273. AMD_cmn_generic_events,
  274. OPT_cmn_generic_events,
  275. GEN_EV_END
  276. };
  277. static amd_generic_event_t family_10h_generic_events[] = {
  278. AMD_cmn_generic_events,
  279. AMD_FAMILY_10h_generic_events,
  280. GEN_EV_END
  281. };
  282. static amd_event_t *amd_events = NULL;
  283. static uint_t amd_family;
  284. static amd_generic_event_t *amd_generic_events = NULL;
  285. #define BITS(v, u, l) (((v) >> (l)) & ((1 << (1 + (u) - (l))) - 1))
  286. #define OPTERON_FAMILY 0x0f
  287. #define AMD_FAMILY_10H 0x10
  288. static int
  289. opt_pcbe_init (void)
  290. {
  291. amd_family = cpuid_getfamily ();
  292. /*
  293. * Make sure this really _is_ an Opteron or Athlon 64 system. The kernel
  294. * loads this module based on its name in the module directory, but it
  295. * could have been renamed.
  296. */
  297. if (cpuid_getvendor () != X86_VENDOR_AMD
  298. || (amd_family != OPTERON_FAMILY && amd_family != AMD_FAMILY_10H))
  299. return (-1);
  300. /*
  301. * Figure out processor revision here and assign appropriate
  302. * event configuration.
  303. */
  304. if (amd_family == OPTERON_FAMILY)
  305. {
  306. amd_events = opt_events_rev_E;
  307. amd_generic_events = opt_generic_events;
  308. }
  309. else
  310. {
  311. amd_events = family_10h_events;
  312. amd_generic_events = family_10h_generic_events;
  313. }
  314. return (0);
  315. }
  316. static uint_t
  317. opt_pcbe_ncounters (void)
  318. {
  319. return (4);
  320. }
  321. static const char *
  322. opt_pcbe_impl_name (void)
  323. {
  324. if (amd_family == OPTERON_FAMILY)
  325. return ("AMD Opteron & Athlon64");
  326. else if (amd_family == AMD_FAMILY_10H)
  327. return ("AMD Family 10h");
  328. else
  329. return ("Unknown AMD processor");
  330. }
  331. static const char *
  332. opt_pcbe_cpuref (void)
  333. {
  334. if (amd_family == OPTERON_FAMILY)
  335. return GTXT ("See Chapter 10 of the \"BIOS and Kernel Developer's Guide for the AMD Athlon 64 and AMD Opteron Processors,\"\nAMD publication #26094");
  336. else if (amd_family == AMD_FAMILY_10H)
  337. return GTXT ("See section 3.15 of the \"BIOS and Kernel Developer's Guide (BKDG) For AMD Family 10h Processors,\"\nAMD publication #31116");
  338. else
  339. return GTXT ("Unknown AMD processor");
  340. }
  341. static int
  342. opt_pcbe_get_events (hwcf_hwc_cb_t *hwc_cb)
  343. {
  344. int count = 0;
  345. for (uint_t kk = 0; amd_events && amd_events[kk].name; kk++)
  346. for (uint_t jj = 0; jj < opt_pcbe_ncounters (); jj++)
  347. {
  348. hwc_cb (jj, amd_events[kk].name);
  349. count++;
  350. }
  351. for (uint_t kk = 0; amd_generic_events && amd_generic_events[kk].name; kk++)
  352. for (uint_t jj = 0; jj < opt_pcbe_ncounters (); jj++)
  353. {
  354. hwc_cb (jj, amd_generic_events[kk].name);
  355. count++;
  356. }
  357. return count;
  358. }
  359. static int
  360. opt_pcbe_get_eventnum (const char *eventname, uint_t pmc, eventsel_t *eventsel,
  361. eventsel_t *event_valid_umask, uint_t *pmc_sel)
  362. {
  363. uint_t kk;
  364. *pmc_sel = pmc; /* for AMD, pmc doesn't need to be adjusted */
  365. *eventsel = (eventsel_t) - 1;
  366. *event_valid_umask = 0x0;
  367. /* search table */
  368. for (kk = 0; amd_events && amd_events[kk].name; kk++)
  369. {
  370. if (strcmp (eventname, amd_events[kk].name) == 0)
  371. {
  372. *eventsel = EXTENDED_EVNUM_2_EVSEL (amd_events[kk].emask);
  373. *event_valid_umask = amd_events[kk].umask_valid;
  374. return 0;
  375. }
  376. }
  377. /* search generic */
  378. int generic = 0;
  379. eventsel_t tmp_umask = 0;
  380. for (kk = 0; amd_generic_events && amd_generic_events[kk].name; kk++)
  381. {
  382. if (strcmp (eventname, amd_generic_events[kk].name) == 0)
  383. {
  384. generic = 1;
  385. eventname = amd_generic_events[kk].event;
  386. tmp_umask = amd_generic_events[kk].umask;
  387. break;
  388. }
  389. }
  390. if (!generic)
  391. return -1;
  392. /* find real event # for generic event */
  393. for (kk = 0; amd_events && amd_events[kk].name; kk++)
  394. {
  395. if (strcmp (eventname, amd_events[kk].name) == 0)
  396. {
  397. *eventsel = EXTENDED_EVNUM_2_EVSEL (amd_events[kk].emask);
  398. *eventsel |= (tmp_umask << PERFCTR_UMASK_SHIFT);
  399. *event_valid_umask = 0; /* user umask not allowed w/generic events */
  400. return 0;
  401. }
  402. }
  403. return -1;
  404. }
  405. static hdrv_pcbe_api_t hdrv_pcbe_opteron_api = {
  406. opt_pcbe_init,
  407. opt_pcbe_ncounters,
  408. opt_pcbe_impl_name,
  409. opt_pcbe_cpuref,
  410. opt_pcbe_get_events,
  411. opt_pcbe_get_eventnum
  412. };