xref: /openbmc/linux/arch/arc/include/asm/perf_event.h (revision e6b1d126bb748103824087189e30febc88c4db73)
19c57564eSVineet Gupta /*
20dd450feSMischa Jonker  * Linux performance counter support for ARC
30dd450feSMischa Jonker  *
4fb7c5725SVineet Gupta  * Copyright (C) 2014-2015 Synopsys, Inc. (www.synopsys.com)
50dd450feSMischa Jonker  * Copyright (C) 2011-2013 Synopsys, Inc. (www.synopsys.com)
69c57564eSVineet Gupta  *
79c57564eSVineet Gupta  * This program is free software; you can redistribute it and/or modify
89c57564eSVineet Gupta  * it under the terms of the GNU General Public License version 2 as
99c57564eSVineet Gupta  * published by the Free Software Foundation.
109c57564eSVineet Gupta  *
119c57564eSVineet Gupta  */
129c57564eSVineet Gupta 
139c57564eSVineet Gupta #ifndef __ASM_PERF_EVENT_H
149c57564eSVineet Gupta #define __ASM_PERF_EVENT_H
159c57564eSVineet Gupta 
16fb7c5725SVineet Gupta /* Max number of counters that PCT block may ever have */
17fb7c5725SVineet Gupta #define ARC_PERF_MAX_COUNTERS	32
180dd450feSMischa Jonker 
190dd450feSMischa Jonker #define ARC_REG_CC_BUILD	0xF6
200dd450feSMischa Jonker #define ARC_REG_CC_INDEX	0x240
210dd450feSMischa Jonker #define ARC_REG_CC_NAME0	0x241
220dd450feSMischa Jonker #define ARC_REG_CC_NAME1	0x242
230dd450feSMischa Jonker 
240dd450feSMischa Jonker #define ARC_REG_PCT_BUILD	0xF5
250dd450feSMischa Jonker #define ARC_REG_PCT_COUNTL	0x250
260dd450feSMischa Jonker #define ARC_REG_PCT_COUNTH	0x251
270dd450feSMischa Jonker #define ARC_REG_PCT_SNAPL	0x252
280dd450feSMischa Jonker #define ARC_REG_PCT_SNAPH	0x253
290dd450feSMischa Jonker #define ARC_REG_PCT_CONFIG	0x254
300dd450feSMischa Jonker #define ARC_REG_PCT_CONTROL	0x255
310dd450feSMischa Jonker #define ARC_REG_PCT_INDEX	0x256
3236481cf7SAlexey Brodkin #define ARC_REG_PCT_INT_CNTL	0x25C
3336481cf7SAlexey Brodkin #define ARC_REG_PCT_INT_CNTH	0x25D
3436481cf7SAlexey Brodkin #define ARC_REG_PCT_INT_CTRL	0x25E
3536481cf7SAlexey Brodkin #define ARC_REG_PCT_INT_ACT	0x25F
360dd450feSMischa Jonker 
37*e6b1d126SAlexey Brodkin #define ARC_REG_PCT_CONFIG_USER	(1 << 18)	/* count in user mode */
38*e6b1d126SAlexey Brodkin #define ARC_REG_PCT_CONFIG_KERN	(1 << 19)	/* count in kernel mode */
39*e6b1d126SAlexey Brodkin 
400dd450feSMischa Jonker #define ARC_REG_PCT_CONTROL_CC	(1 << 16)	/* clear counts */
410dd450feSMischa Jonker #define ARC_REG_PCT_CONTROL_SN	(1 << 17)	/* snapshot */
420dd450feSMischa Jonker 
430dd450feSMischa Jonker struct arc_reg_pct_build {
440dd450feSMischa Jonker #ifdef CONFIG_CPU_BIG_ENDIAN
4536481cf7SAlexey Brodkin 	unsigned int m:8, c:8, r:5, i:1, s:2, v:8;
460dd450feSMischa Jonker #else
4736481cf7SAlexey Brodkin 	unsigned int v:8, s:2, i:1, r:5, c:8, m:8;
480dd450feSMischa Jonker #endif
490dd450feSMischa Jonker };
500dd450feSMischa Jonker 
510dd450feSMischa Jonker struct arc_reg_cc_build {
520dd450feSMischa Jonker #ifdef CONFIG_CPU_BIG_ENDIAN
530dd450feSMischa Jonker 	unsigned int c:16, r:8, v:8;
540dd450feSMischa Jonker #else
550dd450feSMischa Jonker 	unsigned int v:8, r:8, c:16;
560dd450feSMischa Jonker #endif
570dd450feSMischa Jonker };
580dd450feSMischa Jonker 
590dd450feSMischa Jonker #define PERF_COUNT_ARC_DCLM	(PERF_COUNT_HW_MAX + 0)
600dd450feSMischa Jonker #define PERF_COUNT_ARC_DCSM	(PERF_COUNT_HW_MAX + 1)
610dd450feSMischa Jonker #define PERF_COUNT_ARC_ICM	(PERF_COUNT_HW_MAX + 2)
620dd450feSMischa Jonker #define PERF_COUNT_ARC_BPOK	(PERF_COUNT_HW_MAX + 3)
630dd450feSMischa Jonker #define PERF_COUNT_ARC_EDTLB	(PERF_COUNT_HW_MAX + 4)
640dd450feSMischa Jonker #define PERF_COUNT_ARC_EITLB	(PERF_COUNT_HW_MAX + 5)
650a8a4767SVineet Gupta #define PERF_COUNT_ARC_LDC	(PERF_COUNT_HW_MAX + 6)
660a8a4767SVineet Gupta #define PERF_COUNT_ARC_STC	(PERF_COUNT_HW_MAX + 7)
670a8a4767SVineet Gupta 
680a8a4767SVineet Gupta #define PERF_COUNT_ARC_HW_MAX	(PERF_COUNT_HW_MAX + 8)
690dd450feSMischa Jonker 
700dd450feSMischa Jonker /*
71bde80c23SVineet Gupta  * Some ARC pct quirks:
720dd450feSMischa Jonker  *
730dd450feSMischa Jonker  * PERF_COUNT_HW_STALLED_CYCLES_BACKEND
740dd450feSMischa Jonker  * PERF_COUNT_HW_STALLED_CYCLES_FRONTEND
750dd450feSMischa Jonker  *	The ARC 700 can either measure stalls per pipeline stage, or all stalls
760dd450feSMischa Jonker  *	combined; for now we assign all stalls to STALLED_CYCLES_BACKEND
770dd450feSMischa Jonker  *	and all pipeline flushes (e.g. caused by mispredicts, etc.) to
780dd450feSMischa Jonker  *	STALLED_CYCLES_FRONTEND.
790dd450feSMischa Jonker  *
800dd450feSMischa Jonker  *	We could start multiple performance counters and combine everything
810dd450feSMischa Jonker  *	afterwards, but that makes it complicated.
820dd450feSMischa Jonker  *
830dd450feSMischa Jonker  *	Note that I$ cache misses aren't counted by either of the two!
840dd450feSMischa Jonker  */
850dd450feSMischa Jonker 
86bde80c23SVineet Gupta /*
87bde80c23SVineet Gupta  * ARC PCT has hardware conditions with fixed "names" but variable "indexes"
88bde80c23SVineet Gupta  * (based on a specific RTL build)
89bde80c23SVineet Gupta  * Below is the static map between perf generic/arc specific event_id and
90bde80c23SVineet Gupta  * h/w condition names.
91bde80c23SVineet Gupta  * At the time of probe, we loop thru each index and find it's name to
92bde80c23SVineet Gupta  * complete the mapping of perf event_id to h/w index as latter is needed
93bde80c23SVineet Gupta  * to program the counter really
94bde80c23SVineet Gupta  */
950dd450feSMischa Jonker static const char * const arc_pmu_ev_hw_map[] = {
96bde80c23SVineet Gupta 	/* count cycles */
970dd450feSMischa Jonker 	[PERF_COUNT_HW_CPU_CYCLES] = "crun",
980dd450feSMischa Jonker 	[PERF_COUNT_HW_REF_CPU_CYCLES] = "crun",
990dd450feSMischa Jonker 	[PERF_COUNT_HW_BUS_CYCLES] = "crun",
100bde80c23SVineet Gupta 
1010dd450feSMischa Jonker 	[PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = "bflush",
1020dd450feSMischa Jonker 	[PERF_COUNT_HW_STALLED_CYCLES_BACKEND] = "bstall",
103bde80c23SVineet Gupta 
104bde80c23SVineet Gupta 	/* counts condition */
105bde80c23SVineet Gupta 	[PERF_COUNT_HW_INSTRUCTIONS] = "iall",
10609074950SVineet Gupta 	[PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = "ijmp", /* Excludes ZOL jumps */
107bde80c23SVineet Gupta 	[PERF_COUNT_ARC_BPOK]         = "bpok",	  /* NP-NT, PT-T, PNT-NT */
108bde80c23SVineet Gupta 	[PERF_COUNT_HW_BRANCH_MISSES] = "bpfail", /* NP-T, PT-NT, PNT-T */
109bde80c23SVineet Gupta 
1100a8a4767SVineet Gupta 	[PERF_COUNT_ARC_LDC] = "imemrdc",	/* Instr: mem read cached */
1110a8a4767SVineet Gupta 	[PERF_COUNT_ARC_STC] = "imemwrc",	/* Instr: mem write cached */
1120a8a4767SVineet Gupta 
113bde80c23SVineet Gupta 	[PERF_COUNT_ARC_DCLM] = "dclm",		/* D-cache Load Miss */
114bde80c23SVineet Gupta 	[PERF_COUNT_ARC_DCSM] = "dcsm",		/* D-cache Store Miss */
115bde80c23SVineet Gupta 	[PERF_COUNT_ARC_ICM] = "icm",		/* I-cache Miss */
116bde80c23SVineet Gupta 	[PERF_COUNT_ARC_EDTLB] = "edtlb",	/* D-TLB Miss */
117bde80c23SVineet Gupta 	[PERF_COUNT_ARC_EITLB] = "eitlb",	/* I-TLB Miss */
1180dd450feSMischa Jonker };
1190dd450feSMischa Jonker 
1200dd450feSMischa Jonker #define C(_x)			PERF_COUNT_HW_CACHE_##_x
1210dd450feSMischa Jonker #define CACHE_OP_UNSUPPORTED	0xffff
1220dd450feSMischa Jonker 
1230dd450feSMischa Jonker static const unsigned arc_pmu_cache_map[C(MAX)][C(OP_MAX)][C(RESULT_MAX)] = {
1240dd450feSMischa Jonker 	[C(L1D)] = {
1250dd450feSMischa Jonker 		[C(OP_READ)] = {
1260a8a4767SVineet Gupta 			[C(RESULT_ACCESS)]	= PERF_COUNT_ARC_LDC,
1270dd450feSMischa Jonker 			[C(RESULT_MISS)]	= PERF_COUNT_ARC_DCLM,
1280dd450feSMischa Jonker 		},
1290dd450feSMischa Jonker 		[C(OP_WRITE)] = {
1300a8a4767SVineet Gupta 			[C(RESULT_ACCESS)]	= PERF_COUNT_ARC_STC,
1310dd450feSMischa Jonker 			[C(RESULT_MISS)]	= PERF_COUNT_ARC_DCSM,
1320dd450feSMischa Jonker 		},
1330dd450feSMischa Jonker 		[C(OP_PREFETCH)] = {
1340dd450feSMischa Jonker 			[C(RESULT_ACCESS)]	= CACHE_OP_UNSUPPORTED,
1350dd450feSMischa Jonker 			[C(RESULT_MISS)]	= CACHE_OP_UNSUPPORTED,
1360dd450feSMischa Jonker 		},
1370dd450feSMischa Jonker 	},
1380dd450feSMischa Jonker 	[C(L1I)] = {
1390dd450feSMischa Jonker 		[C(OP_READ)] = {
1400a8a4767SVineet Gupta 			[C(RESULT_ACCESS)]	= PERF_COUNT_HW_INSTRUCTIONS,
1410dd450feSMischa Jonker 			[C(RESULT_MISS)]	= PERF_COUNT_ARC_ICM,
1420dd450feSMischa Jonker 		},
1430dd450feSMischa Jonker 		[C(OP_WRITE)] = {
1440dd450feSMischa Jonker 			[C(RESULT_ACCESS)]	= CACHE_OP_UNSUPPORTED,
1450dd450feSMischa Jonker 			[C(RESULT_MISS)]	= CACHE_OP_UNSUPPORTED,
1460dd450feSMischa Jonker 		},
1470dd450feSMischa Jonker 		[C(OP_PREFETCH)] = {
1480dd450feSMischa Jonker 			[C(RESULT_ACCESS)]	= CACHE_OP_UNSUPPORTED,
1490dd450feSMischa Jonker 			[C(RESULT_MISS)]	= CACHE_OP_UNSUPPORTED,
1500dd450feSMischa Jonker 		},
1510dd450feSMischa Jonker 	},
1520dd450feSMischa Jonker 	[C(LL)] = {
1530dd450feSMischa Jonker 		[C(OP_READ)] = {
1540dd450feSMischa Jonker 			[C(RESULT_ACCESS)]	= CACHE_OP_UNSUPPORTED,
1550dd450feSMischa Jonker 			[C(RESULT_MISS)]	= CACHE_OP_UNSUPPORTED,
1560dd450feSMischa Jonker 		},
1570dd450feSMischa Jonker 		[C(OP_WRITE)] = {
1580dd450feSMischa Jonker 			[C(RESULT_ACCESS)]	= CACHE_OP_UNSUPPORTED,
1590dd450feSMischa Jonker 			[C(RESULT_MISS)]	= CACHE_OP_UNSUPPORTED,
1600dd450feSMischa Jonker 		},
1610dd450feSMischa Jonker 		[C(OP_PREFETCH)] = {
1620dd450feSMischa Jonker 			[C(RESULT_ACCESS)]	= CACHE_OP_UNSUPPORTED,
1630dd450feSMischa Jonker 			[C(RESULT_MISS)]	= CACHE_OP_UNSUPPORTED,
1640dd450feSMischa Jonker 		},
1650dd450feSMischa Jonker 	},
1660dd450feSMischa Jonker 	[C(DTLB)] = {
1670dd450feSMischa Jonker 		[C(OP_READ)] = {
1680a8a4767SVineet Gupta 			[C(RESULT_ACCESS)]	= PERF_COUNT_ARC_LDC,
1690dd450feSMischa Jonker 			[C(RESULT_MISS)]	= PERF_COUNT_ARC_EDTLB,
1700dd450feSMischa Jonker 		},
1710a8a4767SVineet Gupta 			/* DTLB LD/ST Miss not segregated by h/w*/
1720dd450feSMischa Jonker 		[C(OP_WRITE)] = {
1730dd450feSMischa Jonker 			[C(RESULT_ACCESS)]	= CACHE_OP_UNSUPPORTED,
1740dd450feSMischa Jonker 			[C(RESULT_MISS)]	= CACHE_OP_UNSUPPORTED,
1750dd450feSMischa Jonker 		},
1760dd450feSMischa Jonker 		[C(OP_PREFETCH)] = {
1770dd450feSMischa Jonker 			[C(RESULT_ACCESS)]	= CACHE_OP_UNSUPPORTED,
1780dd450feSMischa Jonker 			[C(RESULT_MISS)]	= CACHE_OP_UNSUPPORTED,
1790dd450feSMischa Jonker 		},
1800dd450feSMischa Jonker 	},
1810dd450feSMischa Jonker 	[C(ITLB)] = {
1820dd450feSMischa Jonker 		[C(OP_READ)] = {
1830dd450feSMischa Jonker 			[C(RESULT_ACCESS)]	= CACHE_OP_UNSUPPORTED,
1840dd450feSMischa Jonker 			[C(RESULT_MISS)]	= PERF_COUNT_ARC_EITLB,
1850dd450feSMischa Jonker 		},
1860dd450feSMischa Jonker 		[C(OP_WRITE)] = {
1870dd450feSMischa Jonker 			[C(RESULT_ACCESS)]	= CACHE_OP_UNSUPPORTED,
1880dd450feSMischa Jonker 			[C(RESULT_MISS)]	= CACHE_OP_UNSUPPORTED,
1890dd450feSMischa Jonker 		},
1900dd450feSMischa Jonker 		[C(OP_PREFETCH)] = {
1910dd450feSMischa Jonker 			[C(RESULT_ACCESS)]	= CACHE_OP_UNSUPPORTED,
1920dd450feSMischa Jonker 			[C(RESULT_MISS)]	= CACHE_OP_UNSUPPORTED,
1930dd450feSMischa Jonker 		},
1940dd450feSMischa Jonker 	},
1950dd450feSMischa Jonker 	[C(BPU)] = {
1960dd450feSMischa Jonker 		[C(OP_READ)] = {
1970dd450feSMischa Jonker 			[C(RESULT_ACCESS)] = PERF_COUNT_HW_BRANCH_INSTRUCTIONS,
1980dd450feSMischa Jonker 			[C(RESULT_MISS)]	= PERF_COUNT_HW_BRANCH_MISSES,
1990dd450feSMischa Jonker 		},
2000dd450feSMischa Jonker 		[C(OP_WRITE)] = {
2010dd450feSMischa Jonker 			[C(RESULT_ACCESS)]	= CACHE_OP_UNSUPPORTED,
2020dd450feSMischa Jonker 			[C(RESULT_MISS)]	= CACHE_OP_UNSUPPORTED,
2030dd450feSMischa Jonker 		},
2040dd450feSMischa Jonker 		[C(OP_PREFETCH)] = {
2050dd450feSMischa Jonker 			[C(RESULT_ACCESS)]	= CACHE_OP_UNSUPPORTED,
2060dd450feSMischa Jonker 			[C(RESULT_MISS)]	= CACHE_OP_UNSUPPORTED,
2070dd450feSMischa Jonker 		},
2080dd450feSMischa Jonker 	},
2090dd450feSMischa Jonker 	[C(NODE)] = {
2100dd450feSMischa Jonker 		[C(OP_READ)] = {
2110dd450feSMischa Jonker 			[C(RESULT_ACCESS)]	= CACHE_OP_UNSUPPORTED,
2120dd450feSMischa Jonker 			[C(RESULT_MISS)]	= CACHE_OP_UNSUPPORTED,
2130dd450feSMischa Jonker 		},
2140dd450feSMischa Jonker 		[C(OP_WRITE)] = {
2150dd450feSMischa Jonker 			[C(RESULT_ACCESS)]	= CACHE_OP_UNSUPPORTED,
2160dd450feSMischa Jonker 			[C(RESULT_MISS)]	= CACHE_OP_UNSUPPORTED,
2170dd450feSMischa Jonker 		},
2180dd450feSMischa Jonker 		[C(OP_PREFETCH)] = {
2190dd450feSMischa Jonker 			[C(RESULT_ACCESS)]	= CACHE_OP_UNSUPPORTED,
2200dd450feSMischa Jonker 			[C(RESULT_MISS)]	= CACHE_OP_UNSUPPORTED,
2210dd450feSMischa Jonker 		},
2220dd450feSMischa Jonker 	},
2230dd450feSMischa Jonker };
2240dd450feSMischa Jonker 
2259c57564eSVineet Gupta #endif /* __ASM_PERF_EVENT_H */
226