Home | History | Annotate | Line # | Download | only in arch
tprof_x86.c revision 1.15.2.1
      1  1.15.2.1    martin /*	$NetBSD: tprof_x86.c,v 1.15.2.1 2023/06/21 22:34:51 martin Exp $	*/
      2       1.1      maxv 
      3       1.1      maxv /*
      4       1.8      maxv  * Copyright (c) 2018-2019 The NetBSD Foundation, Inc.
      5       1.1      maxv  * All rights reserved.
      6       1.1      maxv  *
      7       1.1      maxv  * This code is derived from software contributed to The NetBSD Foundation
      8       1.1      maxv  * by Maxime Villard.
      9       1.1      maxv  *
     10       1.1      maxv  * Redistribution and use in source and binary forms, with or without
     11       1.1      maxv  * modification, are permitted provided that the following conditions
     12       1.1      maxv  * are met:
     13       1.1      maxv  * 1. Redistributions of source code must retain the above copyright
     14       1.1      maxv  *    notice, this list of conditions and the following disclaimer.
     15       1.1      maxv  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.1      maxv  *    notice, this list of conditions and the following disclaimer in the
     17       1.1      maxv  *    documentation and/or other materials provided with the distribution.
     18       1.1      maxv  *
     19       1.1      maxv  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20       1.1      maxv  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21       1.1      maxv  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22       1.1      maxv  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23       1.1      maxv  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24       1.1      maxv  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25       1.1      maxv  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26       1.1      maxv  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27       1.1      maxv  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28       1.1      maxv  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29       1.1      maxv  * POSSIBILITY OF SUCH DAMAGE.
     30       1.1      maxv  */
     31       1.1      maxv 
     32       1.1      maxv #include <sys/cdefs.h>
     33       1.1      maxv #include <stdio.h>
     34       1.1      maxv #include <stdlib.h>
     35       1.1      maxv #include <stdbool.h>
     36       1.1      maxv #include <string.h>
     37       1.1      maxv #include <unistd.h>
     38       1.1      maxv #include <err.h>
     39       1.1      maxv #include <machine/specialreg.h>
     40       1.1      maxv #include <dev/tprof/tprof_ioctl.h>
     41       1.1      maxv #include "../tprof.h"
     42       1.1      maxv 
     43       1.1      maxv int tprof_event_init(uint32_t);
     44       1.1      maxv void tprof_event_list(void);
     45       1.1      maxv void tprof_event_lookup(const char *, struct tprof_param *);
     46       1.1      maxv 
     47       1.1      maxv struct name_to_event {
     48       1.1      maxv 	const char *name;
     49       1.1      maxv 	uint64_t event;
     50       1.1      maxv 	uint64_t unit;
     51       1.1      maxv 	bool enabled;
     52       1.1      maxv };
     53       1.1      maxv 
     54       1.1      maxv struct event_table {
     55       1.1      maxv 	const char *tablename;
     56       1.1      maxv 	struct name_to_event *names;
     57       1.1      maxv 	size_t nevents;
     58       1.1      maxv 	struct event_table *next;
     59       1.1      maxv };
     60       1.1      maxv 
     61       1.1      maxv static struct event_table *cpuevents = NULL;
     62       1.1      maxv 
     63  1.15.2.1    martin static void
     64  1.15.2.1    martin x86_cpuid(unsigned int *eax, unsigned int *ebx,
     65       1.1      maxv     unsigned int *ecx, unsigned int *edx)
     66       1.1      maxv {
     67       1.1      maxv 	asm volatile("cpuid"
     68       1.1      maxv 	    : "=a" (*eax),
     69       1.1      maxv 	      "=b" (*ebx),
     70       1.1      maxv 	      "=c" (*ecx),
     71       1.1      maxv 	      "=d" (*edx)
     72       1.1      maxv 	    : "0" (*eax), "2" (*ecx));
     73       1.1      maxv }
     74       1.1      maxv 
     75      1.13   msaitoh /* ------------------------------------------------------------------------- */
     76       1.1      maxv 
     77       1.1      maxv /*
     78       1.1      maxv  * Intel Architectural Version 1.
     79       1.1      maxv  */
     80       1.1      maxv static struct name_to_event intel_arch1_names[] = {
     81       1.1      maxv 	/* Event Name - Event Select - UMask */
     82      1.14   msaitoh 	{ "unhalted-core-cycles",	0x3c, 0x00, true },
     83      1.14   msaitoh 	{ "instruction-retired",	0xc0, 0x00, true },
     84      1.14   msaitoh 	{ "unhalted-reference-cycles",	0x3c, 0x01, true },
     85      1.14   msaitoh 	{ "llc-reference",		0x2e, 0x4f, true },
     86      1.14   msaitoh 	{ "llc-misses",			0x2e, 0x41, true },
     87      1.14   msaitoh 	{ "branch-instruction-retired",	0xc4, 0x00, true },
     88      1.14   msaitoh 	{ "branch-misses-retired",	0xc5, 0x00, true },
     89      1.14   msaitoh 	{ "topdown-slots",		0xa4, 0x01, true },
     90       1.1      maxv };
     91       1.1      maxv 
     92       1.1      maxv static struct event_table intel_arch1 = {
     93       1.1      maxv 	.tablename = "Intel Architectural Version 1",
     94       1.1      maxv 	.names = intel_arch1_names,
     95       1.1      maxv 	.nevents = sizeof(intel_arch1_names) /
     96       1.1      maxv 	    sizeof(struct name_to_event),
     97       1.1      maxv 	.next = NULL
     98       1.1      maxv };
     99       1.1      maxv 
    100       1.1      maxv static struct event_table *
    101       1.1      maxv init_intel_arch1(void)
    102       1.1      maxv {
    103      1.12   msaitoh 	unsigned int eax, ebx, ecx, edx, vectorlen;
    104       1.1      maxv 	struct event_table *table;
    105       1.1      maxv 	size_t i;
    106       1.1      maxv 
    107      1.14   msaitoh 	eax = 0x0a;
    108       1.1      maxv 	ebx = 0;
    109       1.1      maxv 	ecx = 0;
    110       1.1      maxv 	edx = 0;
    111       1.1      maxv 	x86_cpuid(&eax, &ebx, &ecx, &edx);
    112       1.1      maxv 
    113      1.12   msaitoh 	vectorlen = __SHIFTOUT(eax, CPUID_PERF_BVECLEN);
    114      1.12   msaitoh 
    115       1.1      maxv 	table = &intel_arch1;
    116       1.1      maxv 	for (i = 0; i < table->nevents; i++) {
    117      1.12   msaitoh 		/*
    118      1.12   msaitoh 		 * Disable the unsupported events from:
    119      1.12   msaitoh 		 * a) the bit vector length in EAX.
    120      1.12   msaitoh 		 * b) the disable bit in EBX.
    121      1.12   msaitoh 		 */
    122      1.12   msaitoh 		if (i >= vectorlen)
    123      1.12   msaitoh 			table->names[i].enabled = false;
    124       1.1      maxv 		if ((ebx & (i << 1)) != 0)
    125       1.1      maxv 			table->names[i].enabled = false;
    126       1.1      maxv 	}
    127       1.1      maxv 
    128       1.1      maxv 	return table;
    129       1.1      maxv }
    130       1.1      maxv 
    131       1.1      maxv /*
    132       1.5  knakahar  * Intel Silvermont/Airmont.
    133       1.5  knakahar  */
    134       1.5  knakahar static struct name_to_event intel_silvermont_airmont_names[] = {
    135       1.5  knakahar 	{ "REHABQ.LD_BLOCK_ST_FORWARD",		0x03, 0x01, true },
    136       1.5  knakahar 	{ "REHABQ.LD_BLOCK_STD_NOTREADY",	0x03, 0x02, true },
    137       1.5  knakahar 	{ "REHABQ.ST_SPLITS",			0x03, 0x04, true },
    138       1.5  knakahar 	{ "REHABQ.LD_SPLITS",			0x03, 0x08, true },
    139       1.5  knakahar 	{ "REHABQ.LOCK",			0x03, 0x10, true },
    140       1.5  knakahar 	{ "REHABQ.STA_FULL",			0x03, 0x20, true },
    141       1.5  knakahar 	{ "REHABQ.ANY_LD",			0x03, 0x40, true },
    142       1.5  knakahar 	{ "REHABQ.ANY_ST",			0x03, 0x80, true },
    143       1.5  knakahar 	{ "MEM_UOPS_RETIRED.L1_MISS_LOADS",	0x04, 0x01, true },
    144       1.5  knakahar 	{ "MEM_UOPS_RETIRED.L2_HIT_LOADS",	0x04, 0x02, true },
    145       1.5  knakahar 	{ "MEM_UOPS_RETIRED.L2_MISS_LOADS",	0x04, 0x04, true },
    146       1.5  knakahar 	{ "MEM_UOPS_RETIRED.DTLB_MISS_LOADS",	0x04, 0x08, true },
    147       1.5  knakahar 	{ "MEM_UOPS_RETIRED.UTLB_MISS",		0x04, 0x10, true },
    148       1.5  knakahar 	{ "MEM_UOPS_RETIRED.HITM",		0x04, 0x20, true },
    149       1.5  knakahar 	{ "MEM_UOPS_RETIRED.ALL_LOADS",		0x04, 0x40, true },
    150       1.5  knakahar 	{ "MEM_UOP_RETIRED.ALL_STORES",		0x04, 0x80, true },
    151       1.5  knakahar 	{ "PAGE_WALKS.D_SIDE_CYCLES",		0x05, 0x01, true },
    152       1.5  knakahar 	{ "PAGE_WALKS.I_SIDE_CYCLES",		0x05, 0x02, true },
    153       1.5  knakahar 	{ "PAGE_WALKS.WALKS",			0x05, 0x03, true },
    154      1.14   msaitoh 	{ "LONGEST_LAT_CACHE.MISS",		0x2e, 0x41, true },
    155      1.14   msaitoh 	{ "LONGEST_LAT_CACHE.REFERENCE",	0x2e, 0x4f, true },
    156       1.5  knakahar 	{ "L2_REJECT_XQ.ALL",			0x30, 0x00, true },
    157       1.5  knakahar 	{ "CORE_REJECT_L2Q.ALL",		0x31, 0x00, true },
    158      1.14   msaitoh 	{ "CPU_CLK_UNHALTED.CORE_P",		0x3c, 0x00, true },
    159      1.14   msaitoh 	{ "CPU_CLK_UNHALTED.REF_P",		0x3c, 0x01, true },
    160       1.5  knakahar 	{ "ICACHE.HIT",				0x80, 0x01, true },
    161       1.5  knakahar 	{ "ICACHE.MISSES",			0x80, 0x02, true },
    162       1.5  knakahar 	{ "ICACHE.ACCESSES",			0x80, 0x03, true },
    163      1.14   msaitoh 	{ "OFFCORE_RESPONSE_0",			0xb7, 0x01, true },
    164      1.14   msaitoh 	{ "OFFCORE_RESPONSE_1",			0xb7, 0x02, true },
    165      1.14   msaitoh 	{ "INST_RETIRED.ANY_P",			0xc0, 0x00, true },
    166      1.14   msaitoh 	{ "UOPS_RETIRED.MS",			0xc2, 0x01, true },
    167      1.14   msaitoh 	{ "UOPS_RETIRED.ALL",			0xc2, 0x10, true },
    168      1.14   msaitoh 	{ "MACHINE_CLEARS.SMC",			0xc3, 0x01, true },
    169      1.14   msaitoh 	{ "MACHINE_CLEARS.MEMORY_ORDERING",	0xc3, 0x02, true },
    170      1.14   msaitoh 	{ "MACHINE_CLEARS.FP_ASSIST",		0xc3, 0x04, true },
    171      1.14   msaitoh 	{ "MACHINE_CLEARS.ALL",			0xc3, 0x08, true },
    172      1.14   msaitoh 	{ "BR_INST_RETIRED.ALL_BRANCHES",	0xc4, 0x00, true },
    173      1.14   msaitoh 	{ "BR_INST_RETIRED.JCC",		0xc4, 0x7e, true },
    174      1.14   msaitoh 	{ "BR_INST_RETIRED.FAR_BRANCH",		0xc4, 0xbf, true },
    175      1.14   msaitoh 	{ "BR_INST_RETIRED.NON_RETURN_IND",	0xc4, 0xeb, true },
    176      1.14   msaitoh 	{ "BR_INST_RETIRED.RETURN",		0xc4, 0xf7, true },
    177      1.14   msaitoh 	{ "BR_INST_RETIRED.CALL",		0xc4, 0xf9, true },
    178      1.14   msaitoh 	{ "BR_INST_RETIRED.IND_CALL",		0xc4, 0xfb, true },
    179      1.14   msaitoh 	{ "BR_INST_RETIRED.REL_CALL",		0xc4, 0xfd, true },
    180      1.14   msaitoh 	{ "BR_INST_RETIRED.TAKEN_JCC",		0xc4, 0xfe, true },
    181      1.14   msaitoh 	{ "BR_MISP_RETIRED.ALL_BRANCHES",	0xc5, 0x00, true },
    182      1.14   msaitoh 	{ "BR_MISP_RETIRED.JCC",		0xc5, 0x7e, true },
    183      1.14   msaitoh 	{ "BR_MISP_RETIRED.FAR",		0xc5, 0xbf, true },
    184      1.14   msaitoh 	{ "BR_MISP_RETIRED.NON_RETURN_IND",	0xc5, 0xeb, true },
    185      1.14   msaitoh 	{ "BR_MISP_RETIRED.RETURN",		0xc5, 0xf7, true },
    186      1.14   msaitoh 	{ "BR_MISP_RETIRED.CALL",		0xc5, 0xf9, true },
    187      1.14   msaitoh 	{ "BR_MISP_RETIRED.IND_CALL",		0xc5, 0xfb, true },
    188      1.14   msaitoh 	{ "BR_MISP_RETIRED.REL_CALL",		0xc5, 0xfd, true },
    189      1.14   msaitoh 	{ "BR_MISP_RETIRED.TAKEN_JCC",		0xc5, 0xfe, true },
    190      1.14   msaitoh 	{ "NO_ALLOC_CYCLES.ROB_FULL",		0xca, 0x01, true },
    191      1.14   msaitoh 	{ "NO_ALLOC_CYCLES.RAT_STALL",		0xca, 0x20, true },
    192      1.14   msaitoh 	{ "NO_ALLOC_CYCLES.ALL",		0xca, 0x3f, true },
    193      1.14   msaitoh 	{ "NO_ALLOC_CYCLES.NOT_DELIVERED",	0xca, 0x50, true },
    194      1.14   msaitoh 	{ "RS_FULL_STALL.MEC",			0xcb, 0x01, true },
    195      1.14   msaitoh 	{ "RS_FULL_STALL.ALL",			0xcb, 0x1f, true },
    196      1.14   msaitoh 	{ "CYCLES_DIV_BUSY.ANY",		0xcd, 0x01, true },
    197      1.14   msaitoh 	{ "BACLEARS.ALL",			0xe6, 0x01, true },
    198      1.14   msaitoh 	{ "BACLEARS.RETURN",			0xe6, 0x08, true },
    199      1.14   msaitoh 	{ "BACLEARS.COND",			0xe6, 0x10, true },
    200      1.14   msaitoh 	{ "MS_DECODED.MS_ENTRY",		0xe7, 0x01, true },
    201       1.5  knakahar };
    202       1.5  knakahar 
    203       1.5  knakahar static struct event_table intel_silvermont_airmont = {
    204       1.5  knakahar 	.tablename = "Intel Silvermont/Airmont",
    205       1.5  knakahar 	.names = intel_silvermont_airmont_names,
    206       1.5  knakahar 	.nevents = sizeof(intel_silvermont_airmont_names) /
    207       1.5  knakahar 	    sizeof(struct name_to_event),
    208       1.5  knakahar 	.next = NULL
    209       1.5  knakahar };
    210       1.5  knakahar 
    211       1.5  knakahar static struct event_table *
    212       1.5  knakahar init_intel_silvermont_airmont(void)
    213       1.5  knakahar {
    214       1.5  knakahar 
    215       1.5  knakahar 	return &intel_silvermont_airmont;
    216       1.5  knakahar }
    217       1.5  knakahar 
    218       1.5  knakahar /*
    219       1.6  knakahar  * Intel Goldmont
    220       1.6  knakahar  */
    221       1.6  knakahar static struct name_to_event intel_goldmont_names[] = {
    222       1.6  knakahar 	{ "LD_BLOCKS.ALL_BLOCK",			0x03,	0x10, true },
    223       1.6  knakahar 	{ "LD_BLOCKS.UTLB_MISS",			0x03,	0x08, true },
    224       1.6  knakahar 	{ "LD_BLOCKS.STORE_FORWARD",			0x03,	0x02, true },
    225       1.6  knakahar 	{ "LD_BLOCKS.DATA_UNKNOWN",			0x03,	0x01, true },
    226       1.6  knakahar 	{ "LD_BLOCKS.4K_ALIAS",				0x03,	0x04, true },
    227       1.6  knakahar 	{ "PAGE_WALKS.D_SIDE_CYCLES",			0x05,	0x01, true },
    228       1.6  knakahar 	{ "PAGE_WALKS.I_SIDE_CYCLES",			0x05,	0x02, true },
    229       1.6  knakahar 	{ "PAGE_WALKS.CYCLES",				0x05,	0x03, true },
    230      1.14   msaitoh 	{ "UOPS_ISSUED.ANY",				0x0e,	0x00, true },
    231       1.6  knakahar 	{ "MISALIGN_MEM_REF.LOAD_PAGE_SPLIT",		0x13,	0x02, true },
    232       1.6  knakahar 	{ "MISALIGN_MEM_REF.STORE_PAGE_SPLIT",		0x13,	0x04, true },
    233      1.14   msaitoh 	{ "LONGEST_LAT_CACHE.REFERENCE",		0x2e,	0x4f, true },
    234      1.14   msaitoh 	{ "LONGEST_LAT_CACHE.MISS",			0x2e,	0x41, true },
    235       1.6  knakahar 	{ "L2_REJECT_XQ.ALL",				0x30,	0x00, true },
    236       1.6  knakahar 	{ "CORE_REJECT_L2Q.ALL",			0x31,	0x00, true },
    237      1.14   msaitoh 	{ "CPU_CLK_UNHALTED.CORE_P",			0x3c,	0x00, true },
    238      1.14   msaitoh 	{ "CPU_CLK_UNHALTED.REF",			0x3c,	0x01, true },
    239       1.6  knakahar 	{ "DL1.DIRTY_EVICTION",				0x51,	0x01, true },
    240       1.6  knakahar 	{ "ICACHE.HIT",					0x80,	0x01, true },
    241       1.6  knakahar 	{ "ICACHE.MISSES",				0x80,	0x02, true },
    242       1.6  knakahar 	{ "ICACHE.ACCESSES",				0x80,	0x03, true },
    243       1.6  knakahar 	{ "ITLB.MISS",					0x81,	0x04, true },
    244       1.6  knakahar 	{ "FETCH_STALL.ALL",				0x86,	0x00, true },
    245       1.6  knakahar 	{ "FETCH_STALL.ITLB_FILL_PENDING_CYCLES",	0x86,	0x01, true },
    246       1.6  knakahar 	{ "FETCH_STALL.ICACHE_FILL_PENDING_CYCLES",	0x86,	0x02, true },
    247      1.14   msaitoh 	{ "UOPS_NOT_DELIVERED.ANY",			0x9c,	0x00, true },
    248      1.14   msaitoh 	{ "OFFCORE_RESPONSE.0",				0xb7,	0x01, true },
    249      1.14   msaitoh 	{ "OFFCORE_RESPONSE.1",				0xb7,	0x02, true },
    250      1.14   msaitoh 	{ "INST_RETIRED.ANY_P",				0xc0,	0x00, true },
    251      1.14   msaitoh 	{ "UOPS_RETIRED.ANY",				0xc2,	0x00, true },
    252      1.14   msaitoh 	{ "UOPS_RETIRED.MS",				0xc2,	0x01, true },
    253      1.14   msaitoh 	{ "UOPS_RETIRED.FPDIV",				0xc2,	0x08, true },
    254      1.14   msaitoh 	{ "UOPS_RETIRED.IDIV",				0xc2,	0x10, true },
    255      1.14   msaitoh 	{ "MACHINE_CLEARS.SMC",				0xc3,	0x01, true },
    256      1.14   msaitoh 	{ "MACHINE_CLEARS.MEMORY_ORDERING",		0xc3,	0x02, true },
    257      1.14   msaitoh 	{ "MACHINE_CLEARS.FP_ASSIST",			0xc3,	0x04, true },
    258      1.14   msaitoh 	{ "MACHINE_CLEARS.DISAMBIGUATION",		0xc3,	0x08, true },
    259      1.14   msaitoh 	{ "MACHINE_CLEARS.ALL",				0xc3,	0x00, true },
    260      1.14   msaitoh 	{ "BR_INST_RETIRED.ALL_BRANCHES",		0xc4,	0x00, true },
    261      1.14   msaitoh 	{ "BR_INST_RETIRED.JCC",			0xc4,	0x7e, true },
    262      1.14   msaitoh 	{ "BR_INST_RETIRED.ALL_TAKEN_BRANCHES",		0xc4,	0x80, true },
    263      1.14   msaitoh 	{ "BR_INST_RETIRED.TAKEN_JCC",			0xc4,	0xfe, true },
    264      1.14   msaitoh 	{ "BR_INST_RETIRED.CALL",			0xc4,	0xf9, true },
    265      1.14   msaitoh 	{ "BR_INST_RETIRED.REL_CALL",			0xc4,	0xfd, true },
    266      1.14   msaitoh 	{ "BR_INST_RETIRED.IND_CALL",			0xc4,	0xfb, true },
    267      1.14   msaitoh 	{ "BR_INST_RETIRED.RETURN",			0xc4,	0xf7, true },
    268      1.14   msaitoh 	{ "BR_INST_RETIRED.NON_RETURN_IND",		0xc4,	0xeb, true },
    269      1.14   msaitoh 	{ "BR_INST_RETIRED.FAR_BRANCH",			0xc4,	0xbf, true },
    270      1.14   msaitoh 	{ "BR_MISP_RETIRED.ALL_BRANCHES",		0xc5,	0x00, true },
    271      1.14   msaitoh 	{ "BR_MISP_RETIRED.JCC",			0xc5,	0x7e, true },
    272      1.14   msaitoh 	{ "BR_MISP_RETIRED.TAKEN_JCC",			0xc5,	0xfe, true },
    273      1.14   msaitoh 	{ "BR_MISP_RETIRED.IND_CALL",			0xc5,	0xfb, true },
    274      1.14   msaitoh 	{ "BR_MISP_RETIRED.RETURN",			0xc5,	0xf7, true },
    275      1.14   msaitoh 	{ "BR_MISP_RETIRED.NON_RETURN_IND",		0xc5,	0xeb, true },
    276      1.14   msaitoh 	{ "ISSUE_SLOTS_NOT_CONSUMED.RESOURCE_FULL",	0xca,	0x01, true },
    277      1.14   msaitoh 	{ "ISSUE_SLOTS_NOT_CONSUMED.RECOVERY",		0xca,	0x02, true },
    278      1.14   msaitoh 	{ "ISSUE_SLOTS_NOT_CONSUMED.ANY",		0xca,	0x00, true },
    279      1.14   msaitoh 	{ "HW_INTERRUPTS.RECEIVED",			0xcb,	0x01, true },
    280      1.14   msaitoh 	{ "HW_INTERRUPTS.MASKED",			0xcb,	0x02, true },
    281      1.14   msaitoh 	{ "HW_INTERRUPTS.PENDING_AND_MASKED",		0xcb,	0x04, true },
    282      1.14   msaitoh 	{ "CYCLES_DIV_BUSY.ALL",			0xcd,	0x00, true },
    283      1.14   msaitoh 	{ "CYCLES_DIV_BUSY.IDIV",			0xcd,	0x01, true },
    284      1.14   msaitoh 	{ "CYCLES_DIV_BUSY.FPDIV",			0xcd,	0x02, true },
    285      1.14   msaitoh 	{ "MEM_UOPS_RETIRED.ALL_LOADS",			0xd0,	0x81, true },
    286      1.14   msaitoh 	{ "MEM_UOPS_RETIRED.ALL_STORES",		0xd0,	0x82, true },
    287      1.14   msaitoh 	{ "MEM_UOPS_RETIRED.ALL",			0xd0,	0x83, true },
    288      1.14   msaitoh 	{ "MEM_UOPS_RETIRED.DTLB_MISS_LOADS",		0xd0,	0x11, true },
    289      1.14   msaitoh 	{ "MEM_UOPS_RETIRED.DTLB_MISS_STORES",		0xd0,	0x12, true },
    290      1.14   msaitoh 	{ "MEM_UOPS_RETIRED.DTLB_MISS",			0xd0,	0x13, true },
    291      1.14   msaitoh 	{ "MEM_UOPS_RETIRED.LOCK_LOADS",		0xd0,	0x21, true },
    292      1.14   msaitoh 	{ "MEM_UOPS_RETIRED.SPLIT_LOADS",		0xd0,	0x41, true },
    293      1.14   msaitoh 	{ "MEM_UOPS_RETIRED.SPLIT_STORES",		0xd0,	0x42, true },
    294      1.14   msaitoh 	{ "MEM_UOPS_RETIRED.SPLIT",			0xd0,	0x43, true },
    295      1.14   msaitoh 	{ "MEM_LOAD_UOPS_RETIRED.L1_HIT",		0xd1,	0x01, true },
    296      1.14   msaitoh 	{ "MEM_LOAD_UOPS_RETIRED.L1_MISS",		0xd1,	0x08, true },
    297      1.14   msaitoh 	{ "MEM_LOAD_UOPS_RETIRED.L2_HIT",		0xd1,	0x02, true },
    298      1.14   msaitoh 	{ "MEM_LOAD_UOPS_RETIRED.L2_MISS",		0xd1,	0x10, true },
    299      1.14   msaitoh 	{ "MEM_LOAD_UOPS_RETIRED.HITM",			0xd1,	0x20, true },
    300      1.14   msaitoh 	{ "MEM_LOAD_UOPS_RETIRED.WCB_HIT",		0xd1,	0x40, true },
    301      1.14   msaitoh 	{ "MEM_LOAD_UOPS_RETIRED.DRAM_HIT",		0xd1,	0x80, true },
    302      1.14   msaitoh 	{ "BACLEARS.ALL",				0xe6,	0x01, true },
    303      1.14   msaitoh 	{ "BACLEARS.RETURN",				0xe6,	0x08, true },
    304      1.14   msaitoh 	{ "BACLEAR.CONDS",				0xe6,	0x10, true },
    305      1.14   msaitoh 	{ "MS_DECODED.MS_ENTRY",			0xe7,	0x01, true },
    306      1.14   msaitoh 	{ "DECODED_RESTRICTION.PREDECODE_WRONG",	0xe9,	0x01, true },
    307       1.6  knakahar };
    308       1.6  knakahar 
    309       1.6  knakahar static struct event_table intel_goldmont = {
    310       1.6  knakahar 	.tablename = "Intel Goldmont",
    311       1.6  knakahar 	.names = intel_goldmont_names,
    312       1.6  knakahar 	.nevents = sizeof(intel_goldmont_names) /
    313       1.6  knakahar 	    sizeof(struct name_to_event),
    314       1.6  knakahar 	.next = NULL
    315       1.6  knakahar };
    316       1.6  knakahar 
    317       1.6  knakahar static struct event_table *
    318       1.6  knakahar init_intel_goldmont(void)
    319       1.6  knakahar {
    320       1.6  knakahar 
    321       1.6  knakahar 	return &intel_goldmont;
    322       1.6  knakahar }
    323       1.6  knakahar 
    324       1.6  knakahar /*
    325       1.7  knakahar  * Intel Goldmont Plus (Additions from Goldmont)
    326       1.7  knakahar  */
    327       1.7  knakahar static struct name_to_event intel_goldmontplus_names[] = {
    328       1.7  knakahar 	{ "INST_RETIRED.ANY",				0x00,	0x01, true },
    329       1.7  knakahar 	{ "DTLB_LOAD_MISSES.WALK_COMPLETED_4K",		0x08,	0x02, true },
    330       1.7  knakahar 	{ "DTLB_LOAD_MISSES.WALK_COMPLETED_2M_4M",	0x08,	0x04, true },
    331       1.7  knakahar 	{ "DTLB_LOAD_MISSES.WALK_COMPLETED_1GB",	0x08,	0x08, true },
    332       1.7  knakahar 	{ "DTLB_LOAD_MISSES.WALK_PENDING",		0x08,	0x10, true },
    333       1.7  knakahar 	{ "DTLB_STORE_MISSES.WALK_COMPLETED_4K",	0x49,	0x02, true },
    334       1.7  knakahar 	{ "DTLB_STORE_MISSES.WALK_COMPLETED_2M_4M",	0x49,	0x04, true },
    335       1.7  knakahar 	{ "DTLB_STORE_MISSES.WALK_COMPLETED_1GB",	0x49,	0x08, true },
    336       1.7  knakahar 	{ "DTLB_STORE_MISSES.WALK_PENDING",		0x49,	0x10, true },
    337      1.14   msaitoh 	{ "EPT.WALK_PENDING",				0x4f,	0x10, true },
    338       1.7  knakahar 	{ "ITLB_MISSES.WALK_COMPLETED_4K",		0x85,	0x08, true },
    339       1.7  knakahar 	{ "ITLB_MISSES.WALK_COMPLETED_2M_4M",		0x85,	0x04, true },
    340       1.7  knakahar 	{ "ITLB_MISSES.WALK_COMPLETED_1GB",		0x85,	0x08, true },
    341       1.7  knakahar 	{ "ITLB_MISSES.WALK_PENDING",			0x85,	0x10, true },
    342      1.14   msaitoh 	{ "TLB_FLUSHES.STLB_ANY",			0xbd,	0x20, true },
    343      1.14   msaitoh 	{ "MACHINE_CLEARS.PAGE_FAULT",			0xc3,	0x20, true },
    344       1.7  knakahar };
    345       1.7  knakahar 
    346       1.7  knakahar static struct event_table intel_goldmontplus = {
    347       1.7  knakahar 	.tablename = "Intel Goldmont Plus",
    348       1.7  knakahar 	.names = intel_goldmontplus_names,
    349       1.7  knakahar 	.nevents = sizeof(intel_goldmontplus_names) /
    350       1.7  knakahar 	    sizeof(struct name_to_event),
    351       1.7  knakahar 	.next = NULL
    352       1.7  knakahar };
    353       1.7  knakahar 
    354       1.7  knakahar static struct event_table *
    355       1.7  knakahar init_intel_goldmontplus(void)
    356       1.7  knakahar {
    357       1.7  knakahar 
    358       1.7  knakahar 	intel_goldmont.next = &intel_goldmontplus;
    359       1.7  knakahar 
    360       1.7  knakahar 	return &intel_goldmont;
    361       1.7  knakahar }
    362       1.7  knakahar 
    363       1.7  knakahar /*
    364       1.4      maxv  * Intel Skylake/Kabylake.
    365       1.4      maxv  *
    366       1.4      maxv  * The events that are not listed, because they are of little interest or
    367       1.4      maxv  * require extra configuration:
    368       1.4      maxv  *     TX_*
    369       1.4      maxv  *     FRONTEND_RETIRED.*
    370       1.4      maxv  *     FP_ARITH_INST_RETIRED.*
    371       1.4      maxv  *     HLE_RETIRED.*
    372       1.4      maxv  *     RTM_RETIRED.*
    373       1.4      maxv  *     MEM_TRANS_RETIRED.*
    374       1.4      maxv  *     UOPS_DISPATCHED_PORT.*
    375       1.1      maxv  */
    376       1.1      maxv static struct name_to_event intel_skylake_kabylake_names[] = {
    377       1.1      maxv 	/* Event Name - Event Select - UMask */
    378      1.13   msaitoh 	{ "LD_BLOCKS.STORE_FORWARD",			0x03, 0x02, true },
    379      1.13   msaitoh 	{ "LD_BLOCKS.NO_SR",				0x03, 0x08, true },
    380      1.13   msaitoh 	{ "LD_BLOCKS_PARTIAL.ADDRESS_ALIAS",		0x07, 0x01, true },
    381      1.13   msaitoh 	{ "DTLB_LOAD_MISSES.MISS_CAUSES_A_WALK",	0x08, 0x01, true },
    382      1.13   msaitoh 	{ "DTLB_LOAD_MISSES.WALK_COMPLETED_4K",		0x08, 0x02, true },
    383      1.13   msaitoh 	{ "DTLB_LOAD_MISSES.WALK_COMPLETED_2M_4M",	0x08, 0x04, true },
    384      1.13   msaitoh 	{ "DTLB_LOAD_MISSES.WALK_COMPLETED_1G",		0x08, 0x08, true },
    385      1.14   msaitoh 	{ "DTLB_LOAD_MISSES.WALK_COMPLETED",		0x08, 0x0e, true },
    386      1.13   msaitoh 	{ "DTLB_LOAD_MISSES.WALK_PENDING",		0x08, 0x10, true },
    387      1.13   msaitoh 	{ "DTLB_LOAD_MISSES.STLB_HIT",			0x08, 0x20, true },
    388      1.14   msaitoh 	{ "INT_MISC.RECOVERY_CYCLES",			0x0d, 0x01, true },
    389      1.14   msaitoh 	{ "INT_MISC.CLEAR_RESTEER_CYCLES",		0x0d, 0x80, true },
    390      1.14   msaitoh 	{ "UOPS_ISSUED.ANY",				0x0e, 0x01, true },
    391      1.14   msaitoh 	{ "UOPS_ISSUED.VECTOR_WIDTH_MISMATCH",		0x0e, 0x02, true },
    392      1.14   msaitoh 	{ "UOPS_ISSUED.SLOW_LEA",			0x0e, 0x20, true },
    393      1.13   msaitoh 	{ "L2_RQSTS.DEMAND_DATA_RD_MISS",		0x24, 0x21, true },
    394      1.13   msaitoh 	{ "L2_RQSTS.RFO_MISS",				0x24, 0x22, true },
    395      1.13   msaitoh 	{ "L2_RQSTS.CODE_RD_MISS",			0x24, 0x24, true },
    396      1.13   msaitoh 	{ "L2_RQSTS.ALL_DEMAND_MISS",			0x24, 0x27, true },
    397      1.13   msaitoh 	{ "L2_RQSTS.PF_MISS",				0x24, 0x38, true },
    398      1.14   msaitoh 	{ "L2_RQSTS.MISS",				0x24, 0x3f, true },
    399      1.13   msaitoh 	{ "L2_RQSTS.DEMAND_DATA_RD_HIT",		0x24, 0x41, true },
    400      1.13   msaitoh 	{ "L2_RQSTS.RFO_HIT",				0x24, 0x42, true },
    401      1.13   msaitoh 	{ "L2_RQSTS.CODE_RD_HIT",			0x24, 0x44, true },
    402      1.14   msaitoh 	{ "L2_RQSTS.PF_HIT",				0x24, 0xd8, true },
    403      1.14   msaitoh 	{ "L2_RQSTS.ALL_DEMAND_DATA_RD",		0x24, 0xe1, true },
    404      1.14   msaitoh 	{ "L2_RQSTS.ALL_RFO",				0x24, 0xe2, true },
    405      1.14   msaitoh 	{ "L2_RQSTS.ALL_CODE_RD",			0x24, 0xe4, true },
    406      1.14   msaitoh 	{ "L2_RQSTS.ALL_DEMAND_REFERENCES",		0x24, 0xe7, true },
    407      1.14   msaitoh 	{ "L2_RQSTS.ALL_PF",				0x24, 0xf8, true },
    408      1.14   msaitoh 	{ "L2_RQSTS.REFERENCES",			0x24, 0xff, true },
    409      1.13   msaitoh 	{ "SW_PREFETCH_ACCESS.NTA",			0x32, 0x01, true },
    410      1.13   msaitoh 	{ "SW_PREFETCH_ACCESS.T0",			0x32, 0x02, true },
    411      1.13   msaitoh 	{ "SW_PREFETCH_ACCESS.T1_T2",			0x32, 0x04, true },
    412      1.13   msaitoh 	{ "SW_PREFETCH_ACCESS.PREFETCHW",		0x32, 0x08, true },
    413      1.14   msaitoh 	{ "CPU_CLK_THREAD_UNHALTED.ONE_THREAD_ACTIVE",	0x3c, 0x02, true },
    414      1.14   msaitoh 	{ "CPU_CLK_UNHALTED.ONE_THREAD_ACTIVE",		0x3c, 0x02, true },
    415      1.13   msaitoh 	{ "L1D_PEND_MISS.PENDING",			0x48, 0x01, true },
    416      1.13   msaitoh 	{ "L1D_PEND_MISS.FB_FULL",			0x48, 0x02, true },
    417      1.13   msaitoh 	{ "DTLB_STORE_MISSES.MISS_CAUSES_A_WALK",	0x49, 0x01, true },
    418      1.13   msaitoh 	{ "DTLB_STORE_MISSES.WALK_COMPLETED_4K",	0x49, 0x02, true },
    419      1.13   msaitoh 	{ "DTLB_STORE_MISSES.WALK_COMPLETED_2M_4M",	0x49, 0x04, true },
    420      1.13   msaitoh 	{ "DTLB_STORE_MISSES.WALK_COMPLETED_1G",	0x49, 0x08, true },
    421      1.14   msaitoh 	{ "DTLB_STORE_MISSES.WALK_COMPLETED",		0x49, 0x0e, true },
    422      1.13   msaitoh 	{ "DTLB_STORE_MISSES.WALK_PENDING",		0x49, 0x10, true },
    423      1.13   msaitoh 	{ "DTLB_STORE_MISSES.STLB_HIT",			0x49, 0x20, true },
    424      1.14   msaitoh 	{ "LOAD_HIT_PRE.SW_PF",				0x4c, 0x01, true },
    425      1.14   msaitoh 	{ "EPT.WALK_PENDING",				0x4f, 0x10, true },
    426      1.13   msaitoh 	{ "L1D.REPLACEMENT",				0x51, 0x01, true },
    427      1.14   msaitoh 	{ "RS_EVENTS.EMPTY_CYCLES",			0x5e, 0x01, true },
    428      1.13   msaitoh 	{ "OFFCORE_REQUESTS_OUTSTANDING.DEMAND_DATA_RD", 0x60, 0x01, true },
    429      1.13   msaitoh 	{ "OFFCORE_REQUESTS_OUTSTANDING.DEMAND_CODE_RD", 0x60, 0x02, true },
    430      1.13   msaitoh 	{ "OFFCORE_REQUESTS_OUTSTANDING.DEMAND_RFO",	0x60, 0x04, true },
    431      1.13   msaitoh 	{ "OFFCORE_REQUESTS_OUTSTANDING.ALL_DATA_RD",	0x60, 0x08, true },
    432      1.13   msaitoh 	{ "OFFCORE_REQUESTS_OUTSTANDING.L3_MISS_DEMAND_DATA_RD",
    433  1.15.2.1    martin 							0x60, 0x10, true },
    434      1.13   msaitoh 	{ "IDQ.MITE_UOPS",				0x79, 0x04, true },
    435      1.13   msaitoh 	{ "IDQ.DSB_UOPS",				0x79, 0x08, true },
    436      1.13   msaitoh 	{ "IDQ.MS_MITE_UOPS",				0x79, 0x20, true },
    437      1.13   msaitoh 	{ "IDQ.MS_UOPS",				0x79, 0x30, true },
    438      1.13   msaitoh 	{ "ICACHE_16B.IFDATA_STALL",			0x80, 0x04, true },
    439      1.13   msaitoh 	{ "ICACHE_64B.IFTAG_HIT",			0x83, 0x01, true },
    440      1.13   msaitoh 	{ "ICACHE_64B.IFTAG_MISS",			0x83, 0x02, true },
    441      1.13   msaitoh 	{ "ICACHE_64B.IFTAG_STALL",			0x83, 0x04, true },
    442      1.13   msaitoh 	{ "ITLB_MISSES.MISS_CAUSES_A_WALK",		0x85, 0x01, true },
    443      1.13   msaitoh 	{ "ITLB_MISSES.WALK_COMPLETED_4K",		0x85, 0x02, true },
    444      1.13   msaitoh 	{ "ITLB_MISSES.WALK_COMPLETED_2M_4M",		0x85, 0x04, true },
    445      1.13   msaitoh 	{ "ITLB_MISSES.WALK_COMPLETED_1G",		0x85, 0x08, true },
    446      1.14   msaitoh 	{ "ITLB_MISSES.WALK_COMPLETED",			0x85, 0x0e, true },
    447      1.13   msaitoh 	{ "ITLB_MISSES.WALK_PENDING",			0x85, 0x10, true },
    448      1.13   msaitoh 	{ "ITLB_MISSES.STLB_HIT",			0x85, 0x20, true },
    449      1.13   msaitoh 	{ "ILD_STALL.LCP",				0x87, 0x01, true },
    450      1.14   msaitoh 	{ "IDQ_UOPS_NOT_DELIVERED.CORE",		0x9c, 0x01, true },
    451      1.14   msaitoh 	{ "RESOURCE_STALLS.ANY",			0xa2, 0x01, true },
    452      1.14   msaitoh 	{ "RESOURCE_STALLS.SB",				0xa2, 0x08, true },
    453      1.14   msaitoh 	{ "EXE_ACTIVITY.EXE_BOUND_0_PORTS",		0xa6, 0x01, true },
    454      1.14   msaitoh 	{ "EXE_ACTIVITY.1_PORTS_UTIL",			0xa6, 0x02, true },
    455      1.14   msaitoh 	{ "EXE_ACTIVITY.2_PORTS_UTIL",			0xa6, 0x04, true },
    456      1.14   msaitoh 	{ "EXE_ACTIVITY.3_PORTS_UTIL",			0xa6, 0x08, true },
    457      1.14   msaitoh 	{ "EXE_ACTIVITY.4_PORTS_UTIL",			0xa6, 0x10, true },
    458      1.14   msaitoh 	{ "EXE_ACTIVITY.BOUND_ON_STORES",		0xa6, 0x40, true },
    459      1.14   msaitoh 	{ "LSD.UOPS",					0xa8, 0x01, true },
    460      1.14   msaitoh 	{ "DSB2MITE_SWITCHES.PENALTY_CYCLES",		0xab, 0x02, true },
    461      1.14   msaitoh 	{ "ITLB.ITLB_FLUSH",				0xae, 0x01, true },
    462      1.14   msaitoh 	{ "OFFCORE_REQUESTS.DEMAND_DATA_RD",		0xb0, 0x01, true },
    463      1.14   msaitoh 	{ "OFFCORE_REQUESTS.DEMAND_CODE_RD",		0xb0, 0x02, true },
    464      1.14   msaitoh 	{ "OFFCORE_REQUESTS.DEMAND_RFO",		0xb0, 0x04, true },
    465      1.14   msaitoh 	{ "OFFCORE_REQUESTS.ALL_DATA_RD",		0xb0, 0x08, true },
    466      1.14   msaitoh 	{ "OFFCORE_REQUESTS.L3_MISS_DEMAND_DATA_RD",	0xb0, 0x10, true },
    467      1.14   msaitoh 	{ "OFFCORE_REQUESTS.ALL_REQUESTS",		0xb0, 0x80, true },
    468      1.14   msaitoh 	{ "UOPS_EXECUTED.THREAD",			0xb1, 0x01, true },
    469      1.14   msaitoh 	{ "UOPS_EXECUTED.CORE",				0xb1, 0x02, true },
    470      1.14   msaitoh 	{ "UOPS_EXECUTED.X87",				0xb1, 0x10, true },
    471      1.14   msaitoh 	{ "OFFCORE_REQUESTS_BUFFER.SQ_FULL",		0xb2, 0x01, true },
    472      1.14   msaitoh 	{ "TLB_FLUSH.DTLB_THREAD",			0xbd, 0x01, true },
    473      1.14   msaitoh 	{ "TLB_FLUSH.STLB_ANY",				0xbd, 0x20, true },
    474      1.14   msaitoh 	{ "INST_RETIRED.PREC_DIST",			0xc0, 0x01, true },
    475      1.14   msaitoh 	{ "OTHER_ASSISTS.ANY",				0xc1, 0x3f, true },
    476      1.14   msaitoh 	{ "UOPS_RETIRED.RETIRE_SLOTS",			0xc2, 0x02, true },
    477      1.14   msaitoh 	{ "MACHINE_CLEARS.MEMORY_ORDERING",		0xc3, 0x02, true },
    478      1.14   msaitoh 	{ "MACHINE_CLEARS.SMC",				0xc3, 0x04, true },
    479      1.14   msaitoh 	{ "BR_INST_RETIRED.CONDITIONAL",		0xc4, 0x01, true },
    480      1.14   msaitoh 	{ "BR_INST_RETIRED.NEAR_CALL",			0xc4, 0x02, true },
    481      1.14   msaitoh 	{ "BR_INST_RETIRED.NEAR_RETURN",		0xc4, 0x08, true },
    482      1.14   msaitoh 	{ "BR_INST_RETIRED.NOT_TAKEN",			0xc4, 0x10, true },
    483      1.14   msaitoh 	{ "BR_INST_RETIRED.NEAR_TAKEN",			0xc4, 0x20, true },
    484      1.14   msaitoh 	{ "BR_INST_RETIRED.FAR_BRANCH",			0xc4, 0x40, true },
    485      1.14   msaitoh 	{ "BR_MISP_RETIRED.CONDITIONAL",		0xc5, 0x01, true },
    486      1.14   msaitoh 	{ "BR_MISP_RETIRED.NEAR_CALL",			0xc5, 0x02, true },
    487      1.14   msaitoh 	{ "BR_MISP_RETIRED.NEAR_TAKEN",			0xc5, 0x20, true },
    488      1.14   msaitoh 	{ "HW_INTERRUPTS.RECEIVED",			0xcb, 0x01, true },
    489      1.14   msaitoh 	{ "MEM_INST_RETIRED.STLB_MISS_LOADS",		0xd0, 0x11, true },
    490      1.14   msaitoh 	{ "MEM_INST_RETIRED.STLB_MISS_STORES",		0xd0, 0x12, true },
    491      1.14   msaitoh 	{ "MEM_INST_RETIRED.LOCK_LOADS",		0xd0, 0x21, true },
    492      1.14   msaitoh 	{ "MEM_INST_RETIRED.SPLIT_LOADS",		0xd0, 0x41, true },
    493      1.14   msaitoh 	{ "MEM_INST_RETIRED.SPLIT_STORES",		0xd0, 0x42, true },
    494      1.14   msaitoh 	{ "MEM_INST_RETIRED.ALL_LOADS",			0xd0, 0x81, true },
    495      1.14   msaitoh 	{ "MEM_INST_RETIRED.ALL_STORES",		0xd0, 0x82, true },
    496      1.14   msaitoh 	{ "MEM_LOAD_RETIRED.L1_HIT",			0xd1, 0x01, true },
    497      1.14   msaitoh 	{ "MEM_LOAD_RETIRED.L2_HIT",			0xd1, 0x02, true },
    498      1.14   msaitoh 	{ "MEM_LOAD_RETIRED.L3_HIT",			0xd1, 0x04, true },
    499      1.14   msaitoh 	{ "MEM_LOAD_RETIRED.L1_MISS",			0xd1, 0x08, true },
    500      1.14   msaitoh 	{ "MEM_LOAD_RETIRED.L2_MISS",			0xd1, 0x10, true },
    501      1.14   msaitoh 	{ "MEM_LOAD_RETIRED.L3_MISS",			0xd1, 0x20, true },
    502      1.14   msaitoh 	{ "MEM_LOAD_RETIRED.FB_HIT",			0xd1, 0x40, true },
    503      1.14   msaitoh 	{ "MEM_LOAD_L3_HIT_RETIRED.XSNP_MISS",		0xd2, 0x01, true },
    504      1.14   msaitoh 	{ "MEM_LOAD_L3_HIT_RETIRED.XSNP_HIT",		0xd2, 0x02, true },
    505      1.14   msaitoh 	{ "MEM_LOAD_L3_HIT_RETIRED.XSNP_HITM",		0xd2, 0x04, true },
    506      1.14   msaitoh 	{ "MEM_LOAD_L3_HIT_RETIRED.XSNP_NONE",		0xd2, 0x08, true },
    507      1.14   msaitoh 	{ "MEM_LOAD_MISC_RETIRED.UC",			0xd4, 0x04, true },
    508      1.14   msaitoh 	{ "BACLEARS.ANY",				0xe6, 0x01, true },
    509      1.14   msaitoh 	{ "L2_TRANS.L2_WB",				0xf0, 0x40, true },
    510      1.14   msaitoh 	{ "L2_LINES_IN.ALL",				0xf1, 0x1f, true },
    511      1.14   msaitoh 	{ "L2_LINES_OUT.SILENT",			0xf2, 0x01, true },
    512      1.14   msaitoh 	{ "L2_LINES_OUT.NON_SILENT",			0xf2, 0x02, true },
    513      1.14   msaitoh 	{ "L2_LINES_OUT.USELESS_HWPF",			0xf2, 0x04, true },
    514      1.14   msaitoh 	{ "SQ_MISC.SPLIT_LOCK",				0xf4, 0x10, true },
    515       1.1      maxv };
    516       1.1      maxv 
    517       1.1      maxv static struct event_table intel_skylake_kabylake = {
    518       1.1      maxv 	.tablename = "Intel Skylake/Kabylake",
    519       1.1      maxv 	.names = intel_skylake_kabylake_names,
    520       1.1      maxv 	.nevents = sizeof(intel_skylake_kabylake_names) /
    521       1.1      maxv 	    sizeof(struct name_to_event),
    522       1.1      maxv 	.next = NULL
    523       1.1      maxv };
    524       1.1      maxv 
    525       1.1      maxv static struct event_table *
    526       1.1      maxv init_intel_skylake_kabylake(void)
    527       1.1      maxv {
    528      1.13   msaitoh 
    529       1.1      maxv 	return &intel_skylake_kabylake;
    530       1.1      maxv }
    531       1.1      maxv 
    532       1.1      maxv static struct event_table *
    533       1.1      maxv init_intel_generic(void)
    534       1.1      maxv {
    535       1.1      maxv 	unsigned int eax, ebx, ecx, edx;
    536       1.1      maxv 	struct event_table *table;
    537       1.1      maxv 
    538       1.1      maxv 	/*
    539       1.1      maxv 	 * The kernel made sure the Architectural Version 1 PMCs were
    540       1.1      maxv 	 * present.
    541       1.1      maxv 	 */
    542       1.1      maxv 	table = init_intel_arch1();
    543       1.1      maxv 
    544       1.1      maxv 	/*
    545       1.1      maxv 	 * Now query the additional (non-architectural) events. They
    546       1.1      maxv 	 * depend on the CPU model.
    547       1.1      maxv 	 */
    548       1.1      maxv 	eax = 0x01;
    549       1.1      maxv 	ebx = 0;
    550       1.1      maxv 	ecx = 0;
    551       1.1      maxv 	edx = 0;
    552       1.1      maxv 	x86_cpuid(&eax, &ebx, &ecx, &edx);
    553       1.1      maxv 
    554       1.3      maxv 	if (CPUID_TO_FAMILY(eax) == 6) {
    555       1.3      maxv 		switch (CPUID_TO_MODEL(eax)) {
    556       1.5  knakahar 		case 0x37: /* Silvermont (Bay Trail) */
    557      1.14   msaitoh 		case 0x4a: /* Silvermont (Tangier) */
    558      1.14   msaitoh 		case 0x4c: /* Airmont (Braswell, Cherry Trail) */
    559      1.14   msaitoh 		case 0x4d: /* Silvermont (Avoton, Rangeley) */
    560      1.14   msaitoh 		case 0x5a: /* Silvermont (Anniedale) */
    561      1.14   msaitoh 		case 0x5d: /* Silvermont (SoFIA) */
    562       1.5  knakahar 			table->next = init_intel_silvermont_airmont();
    563       1.5  knakahar 			break;
    564      1.14   msaitoh 		case 0x5c: /* Goldmont (Apollo Lake) */
    565      1.14   msaitoh 		case 0x5f: /* Goldmont (Denverton) */
    566       1.6  knakahar 			table->next = init_intel_goldmont();
    567       1.6  knakahar 			break;
    568      1.14   msaitoh 		case 0x7a: /* Goldmont Plus (Gemini Lake) */
    569       1.7  knakahar 			table->next = init_intel_goldmontplus();
    570       1.7  knakahar 			break;
    571      1.14   msaitoh 		case 0x4e: /* Skylake */
    572      1.14   msaitoh 		case 0x5e: /* Skylake */
    573      1.14   msaitoh 		case 0x8e: /* Kabylake */
    574      1.14   msaitoh 		case 0x9e: /* Kabylake */
    575  1.15.2.1    martin 		case 0xa5: /* Cometlake */
    576  1.15.2.1    martin 		case 0xa6: /* Cometlake */
    577       1.3      maxv 			table->next = init_intel_skylake_kabylake();
    578       1.3      maxv 			break;
    579       1.3      maxv 		}
    580       1.1      maxv 	}
    581       1.1      maxv 
    582       1.1      maxv 	return table;
    583       1.1      maxv }
    584       1.1      maxv 
    585      1.13   msaitoh /* ------------------------------------------------------------------------- */
    586       1.1      maxv 
    587       1.1      maxv /*
    588       1.1      maxv  * AMD Family 10h
    589       1.1      maxv  */
    590       1.1      maxv static struct name_to_event amd_f10h_names[] = {
    591       1.2      maxv 	{ "seg-load-all",		0x20, 0x7f, true },
    592       1.2      maxv 	{ "seg-load-es",		0x20, 0x01, true },
    593       1.2      maxv 	{ "seg-load-cs",		0x20, 0x02, true },
    594       1.2      maxv 	{ "seg-load-ss",		0x20, 0x04, true },
    595       1.2      maxv 	{ "seg-load-ds",		0x20, 0x08, true },
    596       1.2      maxv 	{ "seg-load-fs",		0x20, 0x10, true },
    597       1.2      maxv 	{ "seg-load-gs",		0x20, 0x20, true },
    598       1.2      maxv 	{ "seg-load-hs",		0x20, 0x40, true },
    599       1.2      maxv 	{ "l1cache-access",		0x40, 0x00, true },
    600       1.2      maxv 	{ "l1cache-miss",		0x41, 0x00, true },
    601       1.2      maxv 	{ "l1cache-refill",		0x42, 0x1f, true },
    602       1.2      maxv 	{ "l1cache-refill-invalid",	0x42, 0x01, true },
    603       1.2      maxv 	{ "l1cache-refill-shared",	0x42, 0x02, true },
    604       1.2      maxv 	{ "l1cache-refill-exclusive",	0x42, 0x04, true },
    605       1.2      maxv 	{ "l1cache-refill-owner",	0x42, 0x08, true },
    606       1.2      maxv 	{ "l1cache-refill-modified",	0x42, 0x10, true },
    607       1.2      maxv 	{ "l1cache-load",		0x43, 0x1f, true },
    608       1.2      maxv 	{ "l1cache-load-invalid",	0x43, 0x01, true },
    609       1.2      maxv 	{ "l1cache-load-shared",	0x43, 0x02, true },
    610       1.2      maxv 	{ "l1cache-load-exclusive",	0x43, 0x04, true },
    611       1.2      maxv 	{ "l1cache-load-owner",		0x43, 0x08, true },
    612       1.2      maxv 	{ "l1cache-load-modified",	0x43, 0x10, true },
    613       1.2      maxv 	{ "l1cache-writeback",		0x44, 0x1f, true },
    614       1.2      maxv 	{ "l1cache-writeback-invalid",	0x44, 0x01, true },
    615       1.2      maxv 	{ "l1cache-writeback-shared",	0x44, 0x02, true },
    616       1.2      maxv 	{ "l1cache-writeback-exclusive",0x44, 0x04, true },
    617       1.2      maxv 	{ "l1cache-writeback-owner",	0x44, 0x08, true },
    618       1.2      maxv 	{ "l1cache-writeback-modified",	0x44, 0x10, true },
    619      1.14   msaitoh 	{ "l1DTLB-hit-all",		0x4d, 0x07, true },
    620      1.14   msaitoh 	{ "l1DTLB-hit-4Kpage",		0x4d, 0x01, true },
    621      1.14   msaitoh 	{ "l1DTLB-hit-2Mpage",		0x4d, 0x02, true },
    622      1.14   msaitoh 	{ "l1DTLB-hit-1Gpage",		0x4d, 0x04, true },
    623       1.2      maxv 	{ "l1DTLB-miss-all",		0x45, 0x07, true },
    624       1.2      maxv 	{ "l1DTLB-miss-4Kpage",		0x45, 0x01, true },
    625       1.2      maxv 	{ "l1DTLB-miss-2Mpage",		0x45, 0x02, true },
    626       1.2      maxv 	{ "l1DTLB-miss-1Gpage",		0x45, 0x04, true },
    627       1.2      maxv 	{ "l2DTLB-miss-all",		0x46, 0x03, true },
    628       1.2      maxv 	{ "l2DTLB-miss-4Kpage",		0x46, 0x01, true },
    629       1.2      maxv 	{ "l2DTLB-miss-2Mpage",		0x46, 0x02, true },
    630       1.1      maxv 	/* l2DTLB-miss-1Gpage: reserved on some revisions, so disabled */
    631       1.2      maxv 	{ "l1ITLB-miss",		0x84, 0x00, true },
    632       1.2      maxv 	{ "l2ITLB-miss-all",		0x85, 0x03, true },
    633       1.2      maxv 	{ "l2ITLB-miss-4Kpage",		0x85, 0x01, true },
    634       1.2      maxv 	{ "l2ITLB-miss-2Mpage",		0x85, 0x02, true },
    635       1.2      maxv 	{ "mem-misalign-ref",		0x47, 0x00, true },
    636       1.2      maxv 	{ "ins-fetch",			0x80, 0x00, true },
    637       1.2      maxv 	{ "ins-fetch-miss",		0x81, 0x00, true },
    638       1.2      maxv 	{ "ins-refill-l2",		0x82, 0x00, true },
    639       1.2      maxv 	{ "ins-refill-sys",		0x83, 0x00, true },
    640       1.2      maxv 	{ "ins-fetch-stall",		0x87, 0x00, true },
    641      1.14   msaitoh 	{ "ins-retired",		0xc0, 0x00, true },
    642      1.14   msaitoh 	{ "ins-empty",			0xd0, 0x00, true },
    643      1.14   msaitoh 	{ "ops-retired",		0xc1, 0x00, true },
    644      1.14   msaitoh 	{ "branch-retired",		0xc2, 0x00, true },
    645      1.14   msaitoh 	{ "branch-miss-retired",	0xc3, 0x00, true },
    646      1.14   msaitoh 	{ "branch-taken-retired",	0xc4, 0x00, true },
    647      1.14   msaitoh 	{ "branch-taken-miss-retired",	0xc5, 0x00, true },
    648      1.14   msaitoh 	{ "branch-far-retired",		0xc6, 0x00, true },
    649      1.14   msaitoh 	{ "branch-resync-retired",	0xc7, 0x00, true },
    650      1.14   msaitoh 	{ "branch-near-retired",	0xc8, 0x00, true },
    651      1.14   msaitoh 	{ "branch-near-miss-retired",	0xc9, 0x00, true },
    652      1.14   msaitoh 	{ "branch-indirect-miss-retired", 0xca, 0x00, true },
    653      1.14   msaitoh 	{ "int-hw",			0xcf, 0x00, true },
    654      1.14   msaitoh 	{ "int-cycles-masked",		0xcd, 0x00, true },
    655      1.14   msaitoh 	{ "int-cycles-masked-pending",	0xce, 0x00, true },
    656      1.14   msaitoh 	{ "fpu-exceptions",		0xdb, 0x00, true },
    657      1.14   msaitoh 	{ "break-match0",		0xdc, 0x00, true },
    658      1.14   msaitoh 	{ "break-match1",		0xdd, 0x00, true },
    659      1.14   msaitoh 	{ "break-match2",		0xde, 0x00, true },
    660      1.14   msaitoh 	{ "break-match3",		0xdf, 0x00, true },
    661       1.1      maxv };
    662       1.1      maxv 
    663       1.1      maxv static struct event_table amd_f10h = {
    664       1.1      maxv 	.tablename = "AMD Family 10h",
    665       1.1      maxv 	.names = amd_f10h_names,
    666       1.1      maxv 	.nevents = sizeof(amd_f10h_names) /
    667       1.1      maxv 	    sizeof(struct name_to_event),
    668       1.1      maxv 	.next = NULL
    669       1.1      maxv };
    670       1.1      maxv 
    671       1.8      maxv /*
    672       1.9  jmcneill  * AMD Family 15h
    673       1.9  jmcneill  */
    674       1.9  jmcneill static struct name_to_event amd_f15h_names[] = {
    675       1.9  jmcneill 	{ "FpPipeAssignment",		0x000, 0x77, true },
    676       1.9  jmcneill 	{ "FpSchedulerEmpty",		0x001, 0x00, true },
    677       1.9  jmcneill 	{ "FpRetSseAvxOps",		0x003, 0xff, true },
    678       1.9  jmcneill 	{ "FpNumMovElim",		0x004, 0x0f, true },
    679       1.9  jmcneill 	{ "FpRetiredSerOps",		0x005, 0x0f, true },
    680       1.9  jmcneill 	{ "LsSegRegLoads",		0x020, 0x7f, true },
    681       1.9  jmcneill 	{ "LsPipeRestartSelfMod",	0x021, 0x00, true },
    682       1.9  jmcneill 	{ "LsPipeRestartVarious",	0x022, 0x1f, true },
    683       1.9  jmcneill 	{ "LsLoadQueueStoreQFull",	0x023, 0x03, true },
    684       1.9  jmcneill 	{ "LsLockedOps",		0x024, 0x00, true },
    685       1.9  jmcneill 	{ "LsRetClflushInstr",		0x026, 0x00, true },
    686       1.9  jmcneill 	{ "LsRetCpuidInstr",		0x027, 0x00, true },
    687       1.9  jmcneill 	{ "LsDispatch",			0x029, 0x07, true },
    688       1.9  jmcneill 	{ "LsCanStoreToLoadFwOps",	0x02a, 0x03, true },
    689       1.9  jmcneill 	{ "LsSmisReceived",		0x02b, 0x00, true },
    690       1.9  jmcneill 	{ "LsExecClflushInstr",		0x030, 0x00, true },
    691       1.9  jmcneill 	{ "LsMisalignStore",		0x032, 0x00, true },
    692       1.9  jmcneill 	{ "LsFpLoadBufStall",		0x034, 0x00, true },
    693       1.9  jmcneill 	{ "LsStlf",			0x035, 0x00, true },
    694       1.9  jmcneill 	{ "DcCacheAccess",		0x040, 0x00, true },
    695       1.9  jmcneill 	{ "DcCacheMiss",		0x041, 0x00, true },
    696       1.9  jmcneill 	{ "DcCacheFillL2Sys",		0x042, 0x1f, true },
    697       1.9  jmcneill 	{ "DcCacheFillSys",		0x043, 0x00, true },
    698       1.9  jmcneill 	{ "DcUnifiedTlbHit",		0x045, 0x77, true },
    699       1.9  jmcneill 	{ "DcUnifiedTlbMiss",		0x046, 0x77, true },
    700       1.9  jmcneill 	{ "DcMisalignAccess",		0x047, 0x00, true },
    701       1.9  jmcneill 	{ "DcPrefetchInstrDisp",	0x04b, 0x07, true },
    702       1.9  jmcneill 	{ "DcIneffSwPrefetch",		0x052, 0x09, true },
    703       1.9  jmcneill 	{ "CuCmdVictimBuf",		0x060, 0x98, true },
    704       1.9  jmcneill 	{ "CuCmdMaskedOps",		0x061, 0x65, true },
    705       1.9  jmcneill 	{ "CuCmdReadBlkOps",		0x062, 0x77, true },
    706       1.9  jmcneill 	{ "CuCmdChgDirtyOps",		0x063, 0x08, true },
    707       1.9  jmcneill 	{ "CuDramSysReq",		0x064, 0x00, true },
    708       1.9  jmcneill 	{ "CuMemReqByType",		0x065, 0x83, true },
    709       1.9  jmcneill 	{ "CuDataCachePrefetch",	0x067, 0x03, true },
    710       1.9  jmcneill 	{ "CuMabReq",			0x068, 0xff, true },
    711       1.9  jmcneill 	{ "CuMabWaitCyc",		0x069, 0xff, true },
    712       1.9  jmcneill 	{ "CuSysRespCacheFill",		0x06c, 0x3f, true },
    713       1.9  jmcneill 	{ "CuOctwordsWritten",		0x06d, 0x01, true },
    714       1.9  jmcneill 	{ "CuCacheXInv",		0x075, 0x0f, true },
    715       1.9  jmcneill 	{ "CuCpuClkNotHalted",		0x076, 0x00, true },
    716       1.9  jmcneill 	{ "CuL2Req",			0x07d, 0x5f, true },
    717       1.9  jmcneill 	{ "CuL2Miss",			0x07e, 0x17, true },
    718       1.9  jmcneill 	{ "CuL2FillWb",			0x07f, 0x07, true },
    719       1.9  jmcneill 	{ "CuPageSplintering",		0x165, 0x07, true },
    720       1.9  jmcneill 	{ "CuL2PrefetchTrigEv",		0x16c, 0x03, true },
    721       1.9  jmcneill 	{ "CuXabAllocStall",		0x177, 0x03, true },
    722       1.9  jmcneill 	{ "CuFreeXabEntries",		0x17f, 0x01, true },
    723       1.9  jmcneill 	{ "IcCacheFetch",		0x080, 0x00, true },
    724       1.9  jmcneill 	{ "IcCacheMiss",		0x081, 0x00, true },
    725       1.9  jmcneill 	{ "IcCacheFillL2",		0x082, 0x00, true },
    726       1.9  jmcneill 	{ "IcCacheFillSys",		0x083, 0x00, true },
    727       1.9  jmcneill 	{ "IcL1TlbMissL2Hit",		0x084, 0x00, true },
    728       1.9  jmcneill 	{ "IcL1TlbMissL2Miss",		0x085, 0x07, true },
    729       1.9  jmcneill 	{ "IcPipeRestartInstrStrProbe",	0x086, 0x00, true },
    730       1.9  jmcneill 	{ "IcFetchStall",		0x087, 0x00, true },
    731       1.9  jmcneill 	{ "IcRetStackHits",		0x088, 0x00, true },
    732       1.9  jmcneill 	{ "IcRetStackOver",		0x089, 0x00, true },
    733       1.9  jmcneill 	{ "IcCacheVictims",		0x08b, 0x00, true },
    734       1.9  jmcneill 	{ "IcCacheLinesInv",		0x08c, 0x0f, true },
    735       1.9  jmcneill 	{ "IcTlbReload",		0x099, 0x00, true },
    736       1.9  jmcneill 	{ "IcTlbReloadAbort",		0x09a, 0x00, true },
    737       1.9  jmcneill 	{ "IcUopsDispatched",		0x186, 0x01, true },
    738       1.9  jmcneill 	{ "ExRetInstr",			0x0c0, 0x00, true },
    739       1.9  jmcneill 	{ "ExRetCops",			0x0c1, 0x00, true },
    740       1.9  jmcneill 	{ "ExRetBrn",			0x0c2, 0x00, true },
    741       1.9  jmcneill 	{ "ExRetBrnMisp",		0x0c3, 0x00, true },
    742       1.9  jmcneill 	{ "ExRetBrnTkn",		0x0c4, 0x00, true },
    743       1.9  jmcneill 	{ "ExRetBrnTknMisp",		0x0c5, 0x00, true },
    744       1.9  jmcneill 	{ "ExRetBrnFar",		0x0c6, 0x00, true },
    745       1.9  jmcneill 	{ "ExRetBrnResync",		0x0c7, 0x00, true },
    746       1.9  jmcneill 	{ "ExRetNearRet",		0x0c8, 0x00, true },
    747       1.9  jmcneill 	{ "ExRetNearRetMispred",	0x0c9, 0x00, true },
    748       1.9  jmcneill 	{ "ExRetBrnIndMisp",		0x0ca, 0x00, true },
    749       1.9  jmcneill 	{ "ExRetMmxFpInstr@X87",	0x0cb, 0x01, true },
    750       1.9  jmcneill 	{ "ExRetMmxFpInstr@Mmx",	0x0cb, 0x02, true },
    751       1.9  jmcneill 	{ "ExRetMmxFpInstr@Sse",	0x0cb, 0x04, true },
    752       1.9  jmcneill 	{ "ExIntMaskedCyc",		0x0cd, 0x00, true },
    753       1.9  jmcneill 	{ "ExIntMaskedCycIntPend",	0x0ce, 0x00, true },
    754       1.9  jmcneill 	{ "ExIntTaken",			0x0cf, 0x00, true },
    755       1.9  jmcneill 	{ "ExDecEmpty",			0x0d0, 0x00, true },
    756       1.9  jmcneill 	{ "ExDispStall",		0x0d1, 0x00, true },
    757       1.9  jmcneill 	{ "ExUseqStallSer",		0x0d2, 0x00, true },
    758       1.9  jmcneill 	{ "ExDispStallInstrRetQFull",	0x0d5, 0x00, true },
    759       1.9  jmcneill 	{ "ExDispStallIntSchedQFull",	0x0d6, 0x00, true },
    760       1.9  jmcneill 	{ "ExDispStallFpSchedQFull",	0x0d7, 0x00, true },
    761       1.9  jmcneill 	{ "ExDispStallLdqFull",		0x0d8, 0x00, true },
    762       1.9  jmcneill 	{ "ExUseqStallAllQuiet",	0x0d9, 0x00, true },
    763       1.9  jmcneill 	{ "ExFpuEx",			0x0db, 0x1f, true },
    764       1.9  jmcneill 	{ "ExBpDr0",			0x0dc, 0x8f, true },
    765       1.9  jmcneill 	{ "ExBpDr1",			0x0dd, 0x8f, true },
    766       1.9  jmcneill 	{ "ExBpDr2",			0x0de, 0x8f, true },
    767       1.9  jmcneill 	{ "ExBpDr3",			0x0df, 0x8f, true },
    768       1.9  jmcneill 	{ "ExRetx87FpOps",		0x1c0, 0x07, true },
    769       1.9  jmcneill 	{ "ExTaggedIbsOps",		0x1cf, 0x07, true },
    770       1.9  jmcneill 	{ "ExRetFusBrInstr",		0x1d0, 0x00, true },
    771       1.9  jmcneill 	{ "ExDispStallStqFull",		0x1d8, 0x00, true },
    772       1.9  jmcneill 	{ "ExCycNoDispIntPrfTok",	0x1dd, 0x00, true },
    773       1.9  jmcneill 	{ "ExCycNoDispfpPrfTok",	0x1de, 0x00, true },
    774       1.9  jmcneill 	{ "ExFpDispContention",		0x1df, 0x0f, true },
    775       1.9  jmcneill };
    776       1.9  jmcneill 
    777       1.9  jmcneill static struct event_table amd_f15h = {
    778       1.9  jmcneill 	.tablename = "AMD Family 15h",
    779       1.9  jmcneill 	.names = amd_f15h_names,
    780       1.9  jmcneill 	.nevents = sizeof(amd_f15h_names) /
    781       1.9  jmcneill 	    sizeof(struct name_to_event),
    782       1.9  jmcneill 	.next = NULL
    783       1.9  jmcneill };
    784       1.9  jmcneill 
    785       1.9  jmcneill /*
    786       1.8      maxv  * AMD Family 17h
    787       1.8      maxv  */
    788       1.8      maxv static struct name_to_event amd_f17h_names[] = {
    789       1.8      maxv 	{ "FpRetx87FpOps",		0x02, __BITS(2,0), true },
    790       1.8      maxv 	{ "FpRetSseAvxOps",		0x03, __BITS(7,0), true },
    791       1.8      maxv 	{ "FpRetiredSerOps",		0x05, __BITS(3,0), true },
    792       1.8      maxv 	{ "LsL1DTlbMiss",		0x45, __BITS(7,0), true },
    793       1.8      maxv 	{ "LsTableWalker",		0x46, __BITS(3,0), true },
    794       1.8      maxv 	{ "LsMisalAccesses",		0x47, 0x00, true },
    795       1.8      maxv 	{ "LsInefSwPref",		0x52, __BITS(1,0), true },
    796       1.8      maxv 	{ "LsNotHaltedCyc",		0x76, 0x00, true },
    797       1.8      maxv 	{ "IcFw32",			0x80, 0x00, true },
    798       1.8      maxv 	{ "IcFw32Miss",			0x81, 0x00, true },
    799       1.8      maxv 	{ "IcCacheFillL2",		0x82, 0x00, true },
    800       1.8      maxv 	{ "IcCacheFillSys",		0x83, 0x00, true },
    801       1.8      maxv 	{ "IcFetchStall",		0x87, __BITS(2,0), true },
    802      1.14   msaitoh 	{ "IcCacheInval",		0x8c, __BITS(1,0), true },
    803       1.8      maxv 	{ "BpL1TlbMissL2Hit",		0x84, 0x00, true },
    804       1.8      maxv 	{ "BpL1TlbMissL2Miss",		0x85, 0x00, true },
    805       1.8      maxv 	{ "BpSnpReSync",		0x86, 0x00, true },
    806      1.14   msaitoh 	{ "BpL1BTBCorrect",		0x8a, 0x00, true },
    807      1.14   msaitoh 	{ "BpL2BTBCorrect",		0x8b, 0x00, true },
    808       1.8      maxv 	{ "BpTlbRel",			0x99, 0x00, true },
    809      1.14   msaitoh 	{ "ExRetInstr",			0xc0, 0x00, true },
    810      1.14   msaitoh 	{ "ExRetCops",			0xc1, 0x00, true },
    811      1.14   msaitoh 	{ "ExRetBrn",			0xc2, 0x00, true },
    812      1.14   msaitoh 	{ "ExRetBrnMisp",		0xc3, 0x00, true },
    813      1.14   msaitoh 	{ "ExRetBrnTkn",		0xc4, 0x00, true },
    814      1.14   msaitoh 	{ "ExRetBrnTknMisp",		0xc5, 0x00, true },
    815      1.14   msaitoh 	{ "ExRetBrnFar",		0xc6, 0x00, true },
    816      1.14   msaitoh 	{ "ExRetBrnResync",		0xc7, 0x00, true },
    817      1.14   msaitoh 	{ "ExRetBrnIndMisp",		0xca, 0x00, true },
    818      1.14   msaitoh 	{ "ExRetNearRet",		0xc8, 0x00, true },
    819      1.14   msaitoh 	{ "ExRetNearRetMispred",	0xc9, 0x00, true },
    820      1.14   msaitoh 	{ "ExRetMmxFpInstr@X87",	0xcb, __BIT(0), true },
    821      1.14   msaitoh 	{ "ExRetMmxFpInstr@Mmx",	0xcb, __BIT(1), true },
    822      1.14   msaitoh 	{ "ExRetMmxFpInstr@Sse",	0xcb, __BIT(2), true },
    823      1.14   msaitoh 	{ "ExRetCond",			0xd1, 0x00, true },
    824      1.14   msaitoh 	{ "ExRetCondMisp",		0xd2, 0x00, true },
    825      1.14   msaitoh 	{ "ExDivBusy",			0xd3, 0x00, true },
    826      1.14   msaitoh 	{ "ExDivCount",			0xd4, 0x00, true },
    827       1.8      maxv };
    828       1.8      maxv 
    829       1.8      maxv static struct event_table amd_f17h = {
    830       1.8      maxv 	.tablename = "AMD Family 17h",
    831       1.8      maxv 	.names = amd_f17h_names,
    832       1.8      maxv 	.nevents = sizeof(amd_f17h_names) /
    833       1.8      maxv 	    sizeof(struct name_to_event),
    834       1.8      maxv 	.next = NULL
    835       1.8      maxv };
    836       1.1      maxv 
    837      1.15   msaitoh /*
    838      1.15   msaitoh  * AMD Family 19h
    839      1.15   msaitoh  * From PPR:
    840      1.15   msaitoh  *	- f19h model 01h B1 (zen3)
    841      1.15   msaitoh  *	- f19h model 11h B1 (zen4)
    842      1.15   msaitoh  *	- f19h model 21h B1 (zen3)
    843      1.15   msaitoh  *	- f19h model 51h A1 (zen3)
    844      1.15   msaitoh  */
    845      1.15   msaitoh static struct name_to_event amd_f19h_names[] = {
    846      1.15   msaitoh 	/* Model 1x only */
    847      1.15   msaitoh 	{ "FpRetx87FpOps",			0x02, __BITS(2,0), true },
    848      1.15   msaitoh 
    849      1.15   msaitoh 	/* Only model 1x has bit 4 */
    850      1.15   msaitoh 	{ "FpRetSseAvxOps",			0x03, __BITS(4,0), true },
    851      1.15   msaitoh 
    852      1.15   msaitoh 	{ "FpRetiredSerOps",			0x05, __BITS(3,0), true },
    853      1.15   msaitoh 
    854      1.15   msaitoh 	/* Model 1x only */
    855      1.15   msaitoh 	{ "FpOpsRetiredByWidth",		0x08, __BITS(5,0), true },
    856      1.15   msaitoh 	{ "FpOpsRetiredByType",			0x0a, __BITS(7,0), true },
    857      1.15   msaitoh 	{ "SseAvxOpsRetired",			0x0b, __BITS(7,0), true },
    858      1.15   msaitoh 	{ "FpPackOpsRetired",			0x0c, __BITS(7,0), true },
    859      1.15   msaitoh 	{ "PackedIntOpType",			0x0d, __BITS(7,0), true },
    860      1.15   msaitoh 
    861      1.15   msaitoh 	{ "FpDispFaults",			0x0e, __BITS(3,0), true },
    862      1.15   msaitoh 	{ "LsBadStatus2",			0x24, __BIT(1),	true },
    863      1.15   msaitoh 	{ "LsLocks",				0x25, __BIT(0), true },
    864      1.15   msaitoh 	{ "LsRetClClush",			0x26, 0x00, true },
    865      1.15   msaitoh 	{ "LsRetCpuid",				0x27, 0x00, true },
    866      1.15   msaitoh 	{ "LsDispatch",				0x29, __BITS(2,0), true },
    867      1.15   msaitoh 	{ "LsSmiRx",				0x2b, 0x00, true },
    868      1.15   msaitoh 	{ "LsIntTaken",				0x2c, 0x00, true },
    869      1.15   msaitoh 	{ "LsSTLF",				0x35, 0x00, true },
    870      1.15   msaitoh 	{ "LsStCommitCancel2",			0x37, __BIT(0), true },
    871      1.15   msaitoh 	{ "LsMabAlloc-ls",			0x41, 0x3f, true },
    872      1.15   msaitoh 	{ "LsMabAlloc-hp",			0x41, 0x40, true },
    873      1.15   msaitoh 	{ "LsMabAlloc-all",			0x41, 0x7f, true },
    874      1.15   msaitoh 	{ "LsDmndFillsFromSys",			0x43, 0x5f, true },
    875      1.15   msaitoh 
    876      1.15   msaitoh 	/* Only model 1x has bit 7 */
    877      1.15   msaitoh 	{ "LsAnyFillsFromSys",			0x44, 0xdf, true },
    878      1.15   msaitoh 
    879      1.15   msaitoh 	{ "LsL1DTlbMiss",			0x45, __BITS(7,0), true },
    880      1.15   msaitoh 	{ "LsMisalLoads-MA64",			0x47, __BIT(0), true },
    881      1.15   msaitoh 	{ "LsMisalLoads-MA4K",			0x47, __BIT(1), true },
    882      1.15   msaitoh 	{ "LsMisalLoads-all",			0x47, __BITS(1,0), true },
    883      1.15   msaitoh 	{ "LsPrefInstrDisp",			0x4b, __BITS(2,0), true },
    884      1.15   msaitoh 	{ "LsInefSwPref",			0x52, __BITS(1,0), true },
    885      1.15   msaitoh 
    886      1.15   msaitoh 	/* Only model 1x has bit 7 */
    887      1.15   msaitoh 	{ "LsSwPfDcFills",			0x59, 0xdf, true },
    888      1.15   msaitoh 	{ "LsHwPfDcFills",			0x5a, 0xdf, true },
    889      1.15   msaitoh 
    890      1.15   msaitoh 	{ "LsAllocMabCount",			0x5f, 0x00, true },
    891      1.15   msaitoh 	{ "LsNotHaltedCyc",			0x76, 0x00, true },
    892      1.15   msaitoh 
    893      1.15   msaitoh 	/* Model 0x, 1x and 2x only */
    894      1.15   msaitoh 	{ "LsTlbFlush",				0x78, 0xff, true },
    895      1.15   msaitoh 
    896      1.15   msaitoh 	/* Model 1x only */
    897      1.15   msaitoh 	{ "LsNotHaltedP0Cyc",			0x120, __BIT(0), true },
    898      1.15   msaitoh 
    899      1.15   msaitoh 	{ "IcCacheFillL2",			0x82, 0x00, true },
    900      1.15   msaitoh 	{ "IcCacheFillSys",			0x83, 0x00, true },
    901      1.15   msaitoh 	{ "BpL1TlbMissL2TlbHit",		0x84, 0x00, true },
    902      1.15   msaitoh 	{ "BpL1TlbMissL2TlbMiss-IF4K",		0x85, __BIT(0), true },
    903      1.15   msaitoh 	{ "BpL1TlbMissL2TlbMiss-IF2M",		0x85, __BIT(1), true },
    904      1.15   msaitoh 	{ "BpL1TlbMissL2TlbMiss-IF1G",		0x85, __BIT(2), true },
    905      1.15   msaitoh 	{ "BpL1TlbMissL2TlbMiss-Coalesced4K",	0x85, __BIT(3), true },
    906      1.15   msaitoh 	{ "BpL1TlbMissL2TlbMiss-all",		0x85, __BITS(3,0), true },
    907      1.15   msaitoh 
    908      1.15   msaitoh 	{ "BpL2BTBCorrect",			0x8b, 0x00, true },
    909      1.15   msaitoh 	{ "BpDynIndPred",			0x8e, 0x00, true },
    910      1.15   msaitoh 	{ "BpDeReDirect",			0x91, 0x00, true },
    911      1.15   msaitoh 	{ "BpL1TlbFetchHit-IF4K",		0x94, __BIT(0), true },
    912      1.15   msaitoh 	{ "BpL1TlbFetchHit-IF2M",		0x94, __BIT(1), true },
    913      1.15   msaitoh 	{ "BpL1TlbFetchHit-IF1G",		0x94, __BIT(2), true },
    914      1.15   msaitoh 	{ "BpL1TlbFetchHit-all",		0x94, __BITS(2,0), true },
    915      1.15   msaitoh 
    916      1.15   msaitoh 	/* Model 1x only */
    917      1.15   msaitoh 	{ "ResyncsOrNcRedirects",		0x96, 0x00, true },
    918      1.15   msaitoh 
    919      1.15   msaitoh 	{ "IcTagHitMiss-hit",			0x18e, 0x07, true },
    920      1.15   msaitoh 	{ "IcTagHitMiss-miss",			0x18e, 0x18, true },
    921      1.15   msaitoh 	{ "IcTagHitMiss-all",			0x18e, 0x1f, true },
    922      1.15   msaitoh 	{ "OpCacheHitMiss-hit",			0x28f, 0x03, true },
    923      1.15   msaitoh 	{ "OpCacheHitMiss-miss",		0x28f, 0x04, true },
    924      1.15   msaitoh 	{ "OpCacheHitMiss-all",			0x28f, 0x07, true },
    925      1.15   msaitoh 	{ "DeOpQueueEmpty",			0xa9, 0x00, true },
    926      1.15   msaitoh 
    927      1.15   msaitoh 	/*
    928      1.15   msaitoh 	 * Model 0x and 1x only.
    929      1.15   msaitoh 	 * Only model 1x has bit 2.
    930      1.15   msaitoh 	 */
    931      1.15   msaitoh 	{ "DeSrcOpDisp",			0xaa, __BITS(2,0), true },
    932      1.15   msaitoh 
    933      1.15   msaitoh 	{ "DeDisOpsFromDecoder-Fp-Ibs",		0xab, 0x04, true },
    934      1.15   msaitoh 	{ "DeDisOpsFromDecoder-Int-Ibs",	0xab, 0x08, true },
    935      1.15   msaitoh 
    936      1.15   msaitoh 	/* Model 0x, 2x and newer */
    937      1.15   msaitoh 	{ "DeDisOpsFromDecoder-Fp-Ret",		0xab, 0x84, true },
    938      1.15   msaitoh 	{ "DeDisOpsFromDecoder-Int-Ret",	0xab, 0x88, true },
    939      1.15   msaitoh 
    940      1.15   msaitoh 	{ "DeDisDispatchTokenStalls1",		0xae, 0xf7, true },
    941      1.15   msaitoh 	{ "DeDisDispatchTokenStalls2",		0xaf, 0x2f, true },
    942      1.15   msaitoh 
    943      1.15   msaitoh 	/* Model 1x only */
    944      1.15   msaitoh 	{ "DeNoDispatchPerSolt-empty",		0x1a0, 0x01, true },
    945      1.15   msaitoh 	{ "DeNoDispatchPerSolt-backend",	0x1a0, 0x1e, true },
    946      1.15   msaitoh 	{ "DeNoDispatchPerSolt-otherSMT",	0x1a0, 0x60, true },
    947      1.15   msaitoh 	{ "DeAdditionalResourceStalls",		0x1a2, 0x30, true },
    948      1.15   msaitoh 
    949      1.15   msaitoh 	{ "ExRetInstr",				0xc0, 0x00, true },
    950      1.15   msaitoh 	{ "ExRetCops",				0xc1, 0x00, true },
    951      1.15   msaitoh 	{ "ExRetBrn",				0xc2, 0x00, true },
    952      1.15   msaitoh 	{ "ExRetBrnMisp",			0xc3, 0x00, true },
    953      1.15   msaitoh 	{ "ExRetBrnTkn",			0xc4, 0x00, true },
    954      1.15   msaitoh 	{ "ExRetBrnTknMisp",			0xc5, 0x00, true },
    955      1.15   msaitoh 	{ "ExRetBrnFar",			0xc6, 0x00, true },
    956      1.15   msaitoh 	{ "ExRetBrnIndMisp",			0xca, 0x00, true },
    957      1.15   msaitoh 	{ "ExRetNearRet",			0xc8, 0x00, true },
    958      1.15   msaitoh 	{ "ExRetNearRetMispred",		0xc9, 0x00, true },
    959      1.15   msaitoh 	{ "ExRetMmxFpInstr@X87",		0xcb, __BIT(0), true },
    960      1.15   msaitoh 	{ "ExRetMmxFpInstr@Mmx",		0xcb, __BIT(1), true },
    961      1.15   msaitoh 	{ "ExRetMmxFpInstr@Sse",		0xcb, __BIT(2), true },
    962      1.15   msaitoh 	{ "ExRetIndBrchInstr",			0xcc, 0x00, true },
    963      1.15   msaitoh 	{ "ExRetCond",				0xd1, 0x00, true },
    964      1.15   msaitoh 	{ "ExDivBusy",				0xd3, 0x00, true },
    965      1.15   msaitoh 	{ "ExDivCount",				0xd4, 0x00, true },
    966      1.15   msaitoh 
    967      1.15   msaitoh 	/* Model 1x only */
    968      1.15   msaitoh 	{ "ExDivCount-LoadAndALU",		0xd6, 0x1f, true },
    969      1.15   msaitoh 	{ "ExDivCount-Load",			0xd6, 0xbf, true },
    970      1.15   msaitoh 	{ "ExRetUcodeInstr",			0x1c1, 0x00, true },
    971      1.15   msaitoh 	{ "ExRetUcodeOps",			0x1c2, 0x00, true },
    972      1.15   msaitoh 
    973      1.15   msaitoh 	{ "ExRetMsprdBrnchInstrDirMsmtch",	0x1c7, 0x00, true },
    974      1.15   msaitoh 
    975      1.15   msaitoh 	/* Model 1x only */
    976      1.15   msaitoh 	{ "ExRetUncondBrnchInstrMspred",	0x1c8, 0x00, true },
    977      1.15   msaitoh 	{ "ExRetUncondBrnchInstr",		0x1c8, 0x00, true },
    978      1.15   msaitoh 
    979      1.15   msaitoh 	{ "ExTaggedIbsOps",			0x1cf, __BITS(2,0), true },
    980      1.15   msaitoh 	{ "ExRetFusedInstr",			0x1d0, 0x00, true },
    981      1.15   msaitoh 
    982      1.15   msaitoh 	/* Only model 1x has bit 0 */
    983      1.15   msaitoh 	{ "L2RequestG1",			0x60, __BITS(7,1), true },
    984      1.15   msaitoh 
    985      1.15   msaitoh 	{ "L2CacheReqStart",			0x64, __BITS(7,0), true },
    986      1.15   msaitoh 	{ "L2PfHitL2-L2",			0x70, __BITS(4,0), true },
    987      1.15   msaitoh 	{ "L2PfHitL2-L1",			0x70, __BITS(7,5), true },
    988      1.15   msaitoh 	{ "L2PfHitL2-all",			0x70, __BITS(7,0), true },
    989      1.15   msaitoh 	{ "L2PfMissL2HitL3-L2",			0x71, __BITS(4,0), true },
    990      1.15   msaitoh 	{ "L2PfMissL2HitL3-L1",			0x71, __BITS(7,5), true },
    991      1.15   msaitoh 	{ "L2PfMIssL2HitL3-all",		0x71, __BITS(7,0), true },
    992      1.15   msaitoh 	{ "L2PfMissL2L3-L2",			0x72, __BITS(4,0), true },
    993      1.15   msaitoh 	{ "L2PfMissL2L3-L1",			0x72, __BITS(7,5), true },
    994      1.15   msaitoh 	{ "L2PfMIssL2L3-all",			0x72, __BITS(7,0), true },
    995      1.15   msaitoh 
    996      1.15   msaitoh 	{ "L3LookupState-L3Miss",		0x04, __BIT(0), true },
    997      1.15   msaitoh 	{ "L3LookupState-L3Hit",		0x04, __BITS(7,1), true },
    998      1.15   msaitoh 	{ "L3LookupState-all",			0x04, __BITS(7,0), true },
    999      1.15   msaitoh 
   1000      1.15   msaitoh 	/* Model 0x, 2x and newer */
   1001      1.15   msaitoh 	{ "XiSysFillLatency",			0x90, 0x00, true },
   1002      1.15   msaitoh 	{ "XiCcxSdpReq1",			0x9a, 0x00, true },
   1003      1.15   msaitoh 
   1004      1.15   msaitoh 	/* Model 1x only */
   1005      1.15   msaitoh 	{ "XiSampledLatency",			0xac, 0x00, true },
   1006      1.15   msaitoh 	{ "XiSampledLatencyRequests",		0xad, 0x00, true },
   1007      1.15   msaitoh };
   1008      1.15   msaitoh 
   1009      1.15   msaitoh static struct event_table amd_f19h = {
   1010      1.15   msaitoh 	.tablename = "AMD Family 19h",
   1011      1.15   msaitoh 	.names = amd_f19h_names,
   1012      1.15   msaitoh 	.nevents = sizeof(amd_f19h_names) /
   1013      1.15   msaitoh 	    sizeof(struct name_to_event),
   1014      1.15   msaitoh 	.next = NULL
   1015      1.15   msaitoh };
   1016      1.15   msaitoh 
   1017       1.1      maxv static struct event_table *
   1018       1.1      maxv init_amd_generic(void)
   1019       1.1      maxv {
   1020       1.1      maxv 	unsigned int eax, ebx, ecx, edx;
   1021       1.1      maxv 
   1022       1.1      maxv 	eax = 0x01;
   1023       1.1      maxv 	ebx = 0;
   1024       1.1      maxv 	ecx = 0;
   1025       1.1      maxv 	edx = 0;
   1026       1.1      maxv 	x86_cpuid(&eax, &ebx, &ecx, &edx);
   1027       1.1      maxv 
   1028       1.1      maxv 	switch (CPUID_TO_FAMILY(eax)) {
   1029       1.1      maxv 	case 0x10:
   1030       1.8      maxv 		return &amd_f10h;
   1031       1.9  jmcneill 	case 0x15:
   1032       1.9  jmcneill 		return &amd_f15h;
   1033       1.8      maxv 	case 0x17:
   1034       1.8      maxv 		return &amd_f17h;
   1035      1.15   msaitoh 	case 0x19:
   1036      1.15   msaitoh 		return &amd_f19h;
   1037       1.1      maxv 	}
   1038       1.1      maxv 
   1039       1.1      maxv 	return NULL;
   1040       1.1      maxv }
   1041       1.1      maxv 
   1042      1.13   msaitoh /* ------------------------------------------------------------------------- */
   1043       1.1      maxv 
   1044       1.1      maxv int
   1045       1.1      maxv tprof_event_init(uint32_t ident)
   1046       1.1      maxv {
   1047      1.13   msaitoh 
   1048       1.1      maxv 	switch (ident) {
   1049       1.1      maxv 	case TPROF_IDENT_NONE:
   1050       1.1      maxv 		return -1;
   1051       1.1      maxv 	case TPROF_IDENT_INTEL_GENERIC:
   1052       1.1      maxv 		cpuevents = init_intel_generic();
   1053       1.1      maxv 		break;
   1054       1.1      maxv 	case TPROF_IDENT_AMD_GENERIC:
   1055       1.1      maxv 		cpuevents = init_amd_generic();
   1056       1.1      maxv 		break;
   1057       1.1      maxv 	}
   1058       1.1      maxv 	return (cpuevents == NULL) ? -1 : 0;
   1059       1.1      maxv }
   1060       1.1      maxv 
   1061       1.1      maxv static void
   1062       1.1      maxv recursive_event_list(struct event_table *table)
   1063       1.1      maxv {
   1064       1.1      maxv 	size_t i;
   1065       1.1      maxv 
   1066       1.1      maxv 	printf("%s:\n", table->tablename);
   1067       1.1      maxv 	for (i = 0; i < table->nevents; i++) {
   1068       1.1      maxv 		if (!table->names[i].enabled)
   1069       1.1      maxv 			continue;
   1070       1.1      maxv 		printf("\t%s\n", table->names[i].name);
   1071       1.1      maxv 	}
   1072       1.1      maxv 
   1073      1.13   msaitoh 	if (table->next != NULL)
   1074       1.1      maxv 		recursive_event_list(table->next);
   1075       1.1      maxv }
   1076       1.1      maxv 
   1077       1.1      maxv void
   1078       1.1      maxv tprof_event_list(void)
   1079       1.1      maxv {
   1080      1.13   msaitoh 
   1081       1.1      maxv 	recursive_event_list(cpuevents);
   1082       1.1      maxv }
   1083       1.1      maxv 
   1084       1.1      maxv static void
   1085       1.1      maxv recursive_event_lookup(struct event_table *table, const char *name,
   1086       1.1      maxv     struct tprof_param *param)
   1087       1.1      maxv {
   1088       1.1      maxv 	size_t i;
   1089       1.1      maxv 
   1090       1.1      maxv 	for (i = 0; i < table->nevents; i++) {
   1091       1.1      maxv 		if (!table->names[i].enabled)
   1092       1.1      maxv 			continue;
   1093       1.1      maxv 		if (!strcmp(table->names[i].name, name)) {
   1094       1.1      maxv 			param->p_event = table->names[i].event;
   1095       1.1      maxv 			param->p_unit = table->names[i].unit;
   1096       1.1      maxv 			return;
   1097       1.1      maxv 		}
   1098       1.1      maxv 	}
   1099       1.1      maxv 
   1100      1.13   msaitoh 	if (table->next != NULL)
   1101       1.1      maxv 		recursive_event_lookup(table->next, name, param);
   1102      1.13   msaitoh 	else
   1103       1.1      maxv 		errx(EXIT_FAILURE, "event '%s' unknown", name);
   1104       1.1      maxv }
   1105       1.1      maxv 
   1106       1.1      maxv void
   1107       1.1      maxv tprof_event_lookup(const char *name, struct tprof_param *param)
   1108       1.1      maxv {
   1109      1.13   msaitoh 
   1110       1.1      maxv 	recursive_event_lookup(cpuevents, name, param);
   1111       1.1      maxv }
   1112