xref: /openbmc/linux/arch/arc/include/asm/perf_event.h (revision 0a8a47679351f00145ddeaa0a05b510e67b780be)
19c57564eSVineet Gupta /*
20dd450feSMischa Jonker  * Linux performance counter support for ARC
30dd450feSMischa Jonker  *
40dd450feSMischa Jonker  * Copyright (C) 2011-2013 Synopsys, Inc. (www.synopsys.com)
59c57564eSVineet Gupta  *
69c57564eSVineet Gupta  * This program is free software; you can redistribute it and/or modify
79c57564eSVineet Gupta  * it under the terms of the GNU General Public License version 2 as
89c57564eSVineet Gupta  * published by the Free Software Foundation.
99c57564eSVineet Gupta  *
109c57564eSVineet Gupta  */
119c57564eSVineet Gupta 
129c57564eSVineet Gupta #ifndef __ASM_PERF_EVENT_H
139c57564eSVineet Gupta #define __ASM_PERF_EVENT_H
149c57564eSVineet Gupta 
150dd450feSMischa Jonker /* real maximum varies per CPU, this is the maximum supported by the driver */
160dd450feSMischa Jonker #define ARC_PMU_MAX_HWEVENTS	64
170dd450feSMischa Jonker 
180dd450feSMischa Jonker #define ARC_REG_CC_BUILD	0xF6
190dd450feSMischa Jonker #define ARC_REG_CC_INDEX	0x240
200dd450feSMischa Jonker #define ARC_REG_CC_NAME0	0x241
210dd450feSMischa Jonker #define ARC_REG_CC_NAME1	0x242
220dd450feSMischa Jonker 
230dd450feSMischa Jonker #define ARC_REG_PCT_BUILD	0xF5
240dd450feSMischa Jonker #define ARC_REG_PCT_COUNTL	0x250
250dd450feSMischa Jonker #define ARC_REG_PCT_COUNTH	0x251
260dd450feSMischa Jonker #define ARC_REG_PCT_SNAPL	0x252
270dd450feSMischa Jonker #define ARC_REG_PCT_SNAPH	0x253
280dd450feSMischa Jonker #define ARC_REG_PCT_CONFIG	0x254
290dd450feSMischa Jonker #define ARC_REG_PCT_CONTROL	0x255
300dd450feSMischa Jonker #define ARC_REG_PCT_INDEX	0x256
310dd450feSMischa Jonker 
320dd450feSMischa Jonker #define ARC_REG_PCT_CONTROL_CC	(1 << 16)	/* clear counts */
330dd450feSMischa Jonker #define ARC_REG_PCT_CONTROL_SN	(1 << 17)	/* snapshot */
340dd450feSMischa Jonker 
350dd450feSMischa Jonker struct arc_reg_pct_build {
360dd450feSMischa Jonker #ifdef CONFIG_CPU_BIG_ENDIAN
370dd450feSMischa Jonker 	unsigned int m:8, c:8, r:6, s:2, v:8;
380dd450feSMischa Jonker #else
390dd450feSMischa Jonker 	unsigned int v:8, s:2, r:6, c:8, m:8;
400dd450feSMischa Jonker #endif
410dd450feSMischa Jonker };
420dd450feSMischa Jonker 
430dd450feSMischa Jonker struct arc_reg_cc_build {
440dd450feSMischa Jonker #ifdef CONFIG_CPU_BIG_ENDIAN
450dd450feSMischa Jonker 	unsigned int c:16, r:8, v:8;
460dd450feSMischa Jonker #else
470dd450feSMischa Jonker 	unsigned int v:8, r:8, c:16;
480dd450feSMischa Jonker #endif
490dd450feSMischa Jonker };
500dd450feSMischa Jonker 
510dd450feSMischa Jonker #define PERF_COUNT_ARC_DCLM	(PERF_COUNT_HW_MAX + 0)
520dd450feSMischa Jonker #define PERF_COUNT_ARC_DCSM	(PERF_COUNT_HW_MAX + 1)
530dd450feSMischa Jonker #define PERF_COUNT_ARC_ICM	(PERF_COUNT_HW_MAX + 2)
540dd450feSMischa Jonker #define PERF_COUNT_ARC_BPOK	(PERF_COUNT_HW_MAX + 3)
550dd450feSMischa Jonker #define PERF_COUNT_ARC_EDTLB	(PERF_COUNT_HW_MAX + 4)
560dd450feSMischa Jonker #define PERF_COUNT_ARC_EITLB	(PERF_COUNT_HW_MAX + 5)
57*0a8a4767SVineet Gupta #define PERF_COUNT_ARC_LDC	(PERF_COUNT_HW_MAX + 6)
58*0a8a4767SVineet Gupta #define PERF_COUNT_ARC_STC	(PERF_COUNT_HW_MAX + 7)
59*0a8a4767SVineet Gupta 
60*0a8a4767SVineet Gupta #define PERF_COUNT_ARC_HW_MAX	(PERF_COUNT_HW_MAX + 8)
610dd450feSMischa Jonker 
620dd450feSMischa Jonker /*
63bde80c23SVineet Gupta  * Some ARC pct quirks:
640dd450feSMischa Jonker  *
650dd450feSMischa Jonker  * PERF_COUNT_HW_STALLED_CYCLES_BACKEND
660dd450feSMischa Jonker  * PERF_COUNT_HW_STALLED_CYCLES_FRONTEND
670dd450feSMischa Jonker  *	The ARC 700 can either measure stalls per pipeline stage, or all stalls
680dd450feSMischa Jonker  *	combined; for now we assign all stalls to STALLED_CYCLES_BACKEND
690dd450feSMischa Jonker  *	and all pipeline flushes (e.g. caused by mispredicts, etc.) to
700dd450feSMischa Jonker  *	STALLED_CYCLES_FRONTEND.
710dd450feSMischa Jonker  *
720dd450feSMischa Jonker  *	We could start multiple performance counters and combine everything
730dd450feSMischa Jonker  *	afterwards, but that makes it complicated.
740dd450feSMischa Jonker  *
750dd450feSMischa Jonker  *	Note that I$ cache misses aren't counted by either of the two!
760dd450feSMischa Jonker  */
770dd450feSMischa Jonker 
78bde80c23SVineet Gupta /*
79bde80c23SVineet Gupta  * ARC PCT has hardware conditions with fixed "names" but variable "indexes"
80bde80c23SVineet Gupta  * (based on a specific RTL build)
81bde80c23SVineet Gupta  * Below is the static map between perf generic/arc specific event_id and
82bde80c23SVineet Gupta  * h/w condition names.
83bde80c23SVineet Gupta  * At the time of probe, we loop thru each index and find it's name to
84bde80c23SVineet Gupta  * complete the mapping of perf event_id to h/w index as latter is needed
85bde80c23SVineet Gupta  * to program the counter really
86bde80c23SVineet Gupta  */
870dd450feSMischa Jonker static const char * const arc_pmu_ev_hw_map[] = {
88bde80c23SVineet Gupta 	/* count cycles */
890dd450feSMischa Jonker 	[PERF_COUNT_HW_CPU_CYCLES] = "crun",
900dd450feSMischa Jonker 	[PERF_COUNT_HW_REF_CPU_CYCLES] = "crun",
910dd450feSMischa Jonker 	[PERF_COUNT_HW_BUS_CYCLES] = "crun",
92bde80c23SVineet Gupta 
930dd450feSMischa Jonker 	[PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = "bflush",
940dd450feSMischa Jonker 	[PERF_COUNT_HW_STALLED_CYCLES_BACKEND] = "bstall",
95bde80c23SVineet Gupta 
96bde80c23SVineet Gupta 	/* counts condition */
97bde80c23SVineet Gupta 	[PERF_COUNT_HW_INSTRUCTIONS] = "iall",
98bde80c23SVineet Gupta 	[PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = "ijmp",
99bde80c23SVineet Gupta 	[PERF_COUNT_ARC_BPOK]         = "bpok",	  /* NP-NT, PT-T, PNT-NT */
100bde80c23SVineet Gupta 	[PERF_COUNT_HW_BRANCH_MISSES] = "bpfail", /* NP-T, PT-NT, PNT-T */
101bde80c23SVineet Gupta 
102*0a8a4767SVineet Gupta 	[PERF_COUNT_ARC_LDC] = "imemrdc",	/* Instr: mem read cached */
103*0a8a4767SVineet Gupta 	[PERF_COUNT_ARC_STC] = "imemwrc",	/* Instr: mem write cached */
104*0a8a4767SVineet Gupta 
105bde80c23SVineet Gupta 	[PERF_COUNT_ARC_DCLM] = "dclm",		/* D-cache Load Miss */
106bde80c23SVineet Gupta 	[PERF_COUNT_ARC_DCSM] = "dcsm",		/* D-cache Store Miss */
107bde80c23SVineet Gupta 	[PERF_COUNT_ARC_ICM] = "icm",		/* I-cache Miss */
108bde80c23SVineet Gupta 	[PERF_COUNT_ARC_EDTLB] = "edtlb",	/* D-TLB Miss */
109bde80c23SVineet Gupta 	[PERF_COUNT_ARC_EITLB] = "eitlb",	/* I-TLB Miss */
1100dd450feSMischa Jonker };
1110dd450feSMischa Jonker 
1120dd450feSMischa Jonker #define C(_x)			PERF_COUNT_HW_CACHE_##_x
1130dd450feSMischa Jonker #define CACHE_OP_UNSUPPORTED	0xffff
1140dd450feSMischa Jonker 
1150dd450feSMischa Jonker static const unsigned arc_pmu_cache_map[C(MAX)][C(OP_MAX)][C(RESULT_MAX)] = {
1160dd450feSMischa Jonker 	[C(L1D)] = {
1170dd450feSMischa Jonker 		[C(OP_READ)] = {
118*0a8a4767SVineet Gupta 			[C(RESULT_ACCESS)]	= PERF_COUNT_ARC_LDC,
1190dd450feSMischa Jonker 			[C(RESULT_MISS)]	= PERF_COUNT_ARC_DCLM,
1200dd450feSMischa Jonker 		},
1210dd450feSMischa Jonker 		[C(OP_WRITE)] = {
122*0a8a4767SVineet Gupta 			[C(RESULT_ACCESS)]	= PERF_COUNT_ARC_STC,
1230dd450feSMischa Jonker 			[C(RESULT_MISS)]	= PERF_COUNT_ARC_DCSM,
1240dd450feSMischa Jonker 		},
1250dd450feSMischa Jonker 		[C(OP_PREFETCH)] = {
1260dd450feSMischa Jonker 			[C(RESULT_ACCESS)]	= CACHE_OP_UNSUPPORTED,
1270dd450feSMischa Jonker 			[C(RESULT_MISS)]	= CACHE_OP_UNSUPPORTED,
1280dd450feSMischa Jonker 		},
1290dd450feSMischa Jonker 	},
1300dd450feSMischa Jonker 	[C(L1I)] = {
1310dd450feSMischa Jonker 		[C(OP_READ)] = {
132*0a8a4767SVineet Gupta 			[C(RESULT_ACCESS)]	= PERF_COUNT_HW_INSTRUCTIONS,
1330dd450feSMischa Jonker 			[C(RESULT_MISS)]	= PERF_COUNT_ARC_ICM,
1340dd450feSMischa Jonker 		},
1350dd450feSMischa Jonker 		[C(OP_WRITE)] = {
1360dd450feSMischa Jonker 			[C(RESULT_ACCESS)]	= CACHE_OP_UNSUPPORTED,
1370dd450feSMischa Jonker 			[C(RESULT_MISS)]	= CACHE_OP_UNSUPPORTED,
1380dd450feSMischa Jonker 		},
1390dd450feSMischa Jonker 		[C(OP_PREFETCH)] = {
1400dd450feSMischa Jonker 			[C(RESULT_ACCESS)]	= CACHE_OP_UNSUPPORTED,
1410dd450feSMischa Jonker 			[C(RESULT_MISS)]	= CACHE_OP_UNSUPPORTED,
1420dd450feSMischa Jonker 		},
1430dd450feSMischa Jonker 	},
1440dd450feSMischa Jonker 	[C(LL)] = {
1450dd450feSMischa Jonker 		[C(OP_READ)] = {
1460dd450feSMischa Jonker 			[C(RESULT_ACCESS)]	= CACHE_OP_UNSUPPORTED,
1470dd450feSMischa Jonker 			[C(RESULT_MISS)]	= CACHE_OP_UNSUPPORTED,
1480dd450feSMischa Jonker 		},
1490dd450feSMischa Jonker 		[C(OP_WRITE)] = {
1500dd450feSMischa Jonker 			[C(RESULT_ACCESS)]	= CACHE_OP_UNSUPPORTED,
1510dd450feSMischa Jonker 			[C(RESULT_MISS)]	= CACHE_OP_UNSUPPORTED,
1520dd450feSMischa Jonker 		},
1530dd450feSMischa Jonker 		[C(OP_PREFETCH)] = {
1540dd450feSMischa Jonker 			[C(RESULT_ACCESS)]	= CACHE_OP_UNSUPPORTED,
1550dd450feSMischa Jonker 			[C(RESULT_MISS)]	= CACHE_OP_UNSUPPORTED,
1560dd450feSMischa Jonker 		},
1570dd450feSMischa Jonker 	},
1580dd450feSMischa Jonker 	[C(DTLB)] = {
1590dd450feSMischa Jonker 		[C(OP_READ)] = {
160*0a8a4767SVineet Gupta 			[C(RESULT_ACCESS)]	= PERF_COUNT_ARC_LDC,
1610dd450feSMischa Jonker 			[C(RESULT_MISS)]	= PERF_COUNT_ARC_EDTLB,
1620dd450feSMischa Jonker 		},
163*0a8a4767SVineet Gupta 			/* DTLB LD/ST Miss not segregated by h/w*/
1640dd450feSMischa Jonker 		[C(OP_WRITE)] = {
1650dd450feSMischa Jonker 			[C(RESULT_ACCESS)]	= CACHE_OP_UNSUPPORTED,
1660dd450feSMischa Jonker 			[C(RESULT_MISS)]	= CACHE_OP_UNSUPPORTED,
1670dd450feSMischa Jonker 		},
1680dd450feSMischa Jonker 		[C(OP_PREFETCH)] = {
1690dd450feSMischa Jonker 			[C(RESULT_ACCESS)]	= CACHE_OP_UNSUPPORTED,
1700dd450feSMischa Jonker 			[C(RESULT_MISS)]	= CACHE_OP_UNSUPPORTED,
1710dd450feSMischa Jonker 		},
1720dd450feSMischa Jonker 	},
1730dd450feSMischa Jonker 	[C(ITLB)] = {
1740dd450feSMischa Jonker 		[C(OP_READ)] = {
1750dd450feSMischa Jonker 			[C(RESULT_ACCESS)]	= CACHE_OP_UNSUPPORTED,
1760dd450feSMischa Jonker 			[C(RESULT_MISS)]	= PERF_COUNT_ARC_EITLB,
1770dd450feSMischa Jonker 		},
1780dd450feSMischa Jonker 		[C(OP_WRITE)] = {
1790dd450feSMischa Jonker 			[C(RESULT_ACCESS)]	= CACHE_OP_UNSUPPORTED,
1800dd450feSMischa Jonker 			[C(RESULT_MISS)]	= CACHE_OP_UNSUPPORTED,
1810dd450feSMischa Jonker 		},
1820dd450feSMischa Jonker 		[C(OP_PREFETCH)] = {
1830dd450feSMischa Jonker 			[C(RESULT_ACCESS)]	= CACHE_OP_UNSUPPORTED,
1840dd450feSMischa Jonker 			[C(RESULT_MISS)]	= CACHE_OP_UNSUPPORTED,
1850dd450feSMischa Jonker 		},
1860dd450feSMischa Jonker 	},
1870dd450feSMischa Jonker 	[C(BPU)] = {
1880dd450feSMischa Jonker 		[C(OP_READ)] = {
1890dd450feSMischa Jonker 			[C(RESULT_ACCESS)] = PERF_COUNT_HW_BRANCH_INSTRUCTIONS,
1900dd450feSMischa Jonker 			[C(RESULT_MISS)]	= PERF_COUNT_HW_BRANCH_MISSES,
1910dd450feSMischa Jonker 		},
1920dd450feSMischa Jonker 		[C(OP_WRITE)] = {
1930dd450feSMischa Jonker 			[C(RESULT_ACCESS)]	= CACHE_OP_UNSUPPORTED,
1940dd450feSMischa Jonker 			[C(RESULT_MISS)]	= CACHE_OP_UNSUPPORTED,
1950dd450feSMischa Jonker 		},
1960dd450feSMischa Jonker 		[C(OP_PREFETCH)] = {
1970dd450feSMischa Jonker 			[C(RESULT_ACCESS)]	= CACHE_OP_UNSUPPORTED,
1980dd450feSMischa Jonker 			[C(RESULT_MISS)]	= CACHE_OP_UNSUPPORTED,
1990dd450feSMischa Jonker 		},
2000dd450feSMischa Jonker 	},
2010dd450feSMischa Jonker 	[C(NODE)] = {
2020dd450feSMischa Jonker 		[C(OP_READ)] = {
2030dd450feSMischa Jonker 			[C(RESULT_ACCESS)]	= CACHE_OP_UNSUPPORTED,
2040dd450feSMischa Jonker 			[C(RESULT_MISS)]	= CACHE_OP_UNSUPPORTED,
2050dd450feSMischa Jonker 		},
2060dd450feSMischa Jonker 		[C(OP_WRITE)] = {
2070dd450feSMischa Jonker 			[C(RESULT_ACCESS)]	= CACHE_OP_UNSUPPORTED,
2080dd450feSMischa Jonker 			[C(RESULT_MISS)]	= CACHE_OP_UNSUPPORTED,
2090dd450feSMischa Jonker 		},
2100dd450feSMischa Jonker 		[C(OP_PREFETCH)] = {
2110dd450feSMischa Jonker 			[C(RESULT_ACCESS)]	= CACHE_OP_UNSUPPORTED,
2120dd450feSMischa Jonker 			[C(RESULT_MISS)]	= CACHE_OP_UNSUPPORTED,
2130dd450feSMischa Jonker 		},
2140dd450feSMischa Jonker 	},
2150dd450feSMischa Jonker };
2160dd450feSMischa Jonker 
2179c57564eSVineet Gupta #endif /* __ASM_PERF_EVENT_H */
218