18c2ecf20Sopenharmony_ci
28c2ecf20Sopenharmony_ciThe contents of this directory allow users to specify PMU events in their
38c2ecf20Sopenharmony_ciCPUs by their symbolic names rather than raw event codes (see example below).
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ciThe main program in this directory, is the 'jevents', which is built and
68c2ecf20Sopenharmony_ciexecuted _BEFORE_ the perf binary itself is built.
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ciThe 'jevents' program tries to locate and process JSON files in the directory
98c2ecf20Sopenharmony_citree tools/perf/pmu-events/arch/foo.
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci	- Regular files with '.json' extension in the name are assumed to be
128c2ecf20Sopenharmony_ci	  JSON files, each of which describes a set of PMU events.
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci	- The CSV file that maps a specific CPU to its set of PMU events is to
158c2ecf20Sopenharmony_ci	  be named 'mapfile.csv' (see below for mapfile format).
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci	- Directories are traversed, but all other files are ignored.
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci	- To reduce JSON event duplication per architecture, platform JSONs may
208c2ecf20Sopenharmony_ci	  use "ArchStdEvent" keyword to dereference an "Architecture standard
218c2ecf20Sopenharmony_ci	  events", defined in architecture standard JSONs.
228c2ecf20Sopenharmony_ci	  Architecture standard JSONs must be located in the architecture root
238c2ecf20Sopenharmony_ci	  folder. Matching is based on the "EventName" field.
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ciThe PMU events supported by a CPU model are expected to grouped into topics
268c2ecf20Sopenharmony_cisuch as Pipelining, Cache, Memory, Floating-point etc. All events for a topic
278c2ecf20Sopenharmony_cishould be placed in a separate JSON file - where the file name identifies
288c2ecf20Sopenharmony_cithe topic. Eg: "Floating-point.json".
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ciAll the topic JSON files for a CPU model/family should be in a separate
318c2ecf20Sopenharmony_cisub directory. Thus for the Silvermont X86 CPU:
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci	$ ls tools/perf/pmu-events/arch/x86/silvermont
348c2ecf20Sopenharmony_ci	cache.json     memory.json    virtual-memory.json
358c2ecf20Sopenharmony_ci	frontend.json  pipeline.json
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ciThe JSONs folder for a CPU model/family may be placed in the root arch
388c2ecf20Sopenharmony_cifolder, or may be placed in a vendor sub-folder under the arch folder
398c2ecf20Sopenharmony_cifor instances where the arch and vendor are not the same.
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ciUsing the JSON files and the mapfile, 'jevents' generates the C source file,
428c2ecf20Sopenharmony_ci'pmu-events.c', which encodes the two sets of tables:
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci	- Set of 'PMU events tables' for all known CPUs in the architecture,
458c2ecf20Sopenharmony_ci	  (one table like the following, per JSON file; table name 'pme_power8'
468c2ecf20Sopenharmony_ci	  is derived from JSON file name, 'power8.json').
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci		struct pmu_event pme_power8[] = {
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci			...
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci			{
538c2ecf20Sopenharmony_ci				.name = "pm_1plus_ppc_cmpl",
548c2ecf20Sopenharmony_ci				.event = "event=0x100f2",
558c2ecf20Sopenharmony_ci				.desc = "1 or more ppc insts finished,",
568c2ecf20Sopenharmony_ci			},
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci			...
598c2ecf20Sopenharmony_ci		}
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci	- A 'mapping table' that maps each CPU of the architecture, to its
628c2ecf20Sopenharmony_ci	  'PMU events table'
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci		struct pmu_events_map pmu_events_map[] = {
658c2ecf20Sopenharmony_ci		{
668c2ecf20Sopenharmony_ci			.cpuid = "004b0000",
678c2ecf20Sopenharmony_ci			.version = "1",
688c2ecf20Sopenharmony_ci			.type = "core",
698c2ecf20Sopenharmony_ci			.table = pme_power8
708c2ecf20Sopenharmony_ci		},
718c2ecf20Sopenharmony_ci			...
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci		};
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ciAfter the 'pmu-events.c' is generated, it is compiled and the resulting
768c2ecf20Sopenharmony_ci'pmu-events.o' is added to 'libperf.a' which is then used to build perf.
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ciNOTES:
798c2ecf20Sopenharmony_ci	1. Several CPUs can support same set of events and hence use a common
808c2ecf20Sopenharmony_ci	   JSON file. Hence several entries in the pmu_events_map[] could map
818c2ecf20Sopenharmony_ci	   to a single 'PMU events table'.
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci	2. The 'pmu-events.h' has an extern declaration for the mapping table
848c2ecf20Sopenharmony_ci	   and the generated 'pmu-events.c' defines this table.
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci	3. _All_ known CPU tables for architecture are included in the perf
878c2ecf20Sopenharmony_ci	   binary.
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ciAt run time, perf determines the actual CPU it is running on, finds the
908c2ecf20Sopenharmony_cimatching events table and builds aliases for those events. This allows
918c2ecf20Sopenharmony_ciusers to specify events by their name:
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci	$ perf stat -e pm_1plus_ppc_cmpl sleep 1
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ciwhere 'pm_1plus_ppc_cmpl' is a Power8 PMU event.
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ciHowever some errors in processing may cause the alias build to fail.
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ciMapfile format
1008c2ecf20Sopenharmony_ci===============
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ciThe mapfile enables multiple CPU models to share a single set of PMU events.
1038c2ecf20Sopenharmony_ciIt is required even if such mapping is 1:1.
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ciThe mapfile.csv format is expected to be:
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci	Header line
1088c2ecf20Sopenharmony_ci	CPUID,Version,Dir/path/name,Type
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ciwhere:
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci	Comma:
1138c2ecf20Sopenharmony_ci		is the required field delimiter (i.e other fields cannot
1148c2ecf20Sopenharmony_ci		have commas within them).
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ci	Comments:
1178c2ecf20Sopenharmony_ci		Lines in which the first character is either '\n' or '#'
1188c2ecf20Sopenharmony_ci		are ignored.
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci	Header line
1218c2ecf20Sopenharmony_ci		The header line is the first line in the file, which is
1228c2ecf20Sopenharmony_ci		always _IGNORED_. It can be empty.
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_ci	CPUID:
1258c2ecf20Sopenharmony_ci		CPUID is an arch-specific char string, that can be used
1268c2ecf20Sopenharmony_ci		to identify CPU (and associate it with a set of PMU events
1278c2ecf20Sopenharmony_ci		it supports). Multiple CPUIDS can point to the same
1288c2ecf20Sopenharmony_ci		File/path/name.json.
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_ci		Example:
1318c2ecf20Sopenharmony_ci			CPUID == 'GenuineIntel-6-2E' (on x86).
1328c2ecf20Sopenharmony_ci			CPUID == '004b0100' (PVR value in Powerpc)
1338c2ecf20Sopenharmony_ci	Version:
1348c2ecf20Sopenharmony_ci		is the Version of the mapfile.
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_ci	Dir/path/name:
1378c2ecf20Sopenharmony_ci		is the pathname to the directory containing the CPU's JSON
1388c2ecf20Sopenharmony_ci		files, relative to the directory containing the mapfile.csv
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_ci	Type:
1418c2ecf20Sopenharmony_ci		indicates whether the events are "core" or "uncore" events.
1428c2ecf20Sopenharmony_ci
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_ci	Eg:
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_ci	$ grep silvermont tools/perf/pmu-events/arch/x86/mapfile.csv
1478c2ecf20Sopenharmony_ci	GenuineIntel-6-37,v13,silvermont,core
1488c2ecf20Sopenharmony_ci	GenuineIntel-6-4D,v13,silvermont,core
1498c2ecf20Sopenharmony_ci	GenuineIntel-6-4C,v13,silvermont,core
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ci	i.e the three CPU models use the JSON files (i.e PMU events) listed
1528c2ecf20Sopenharmony_ci	in the directory 'tools/perf/pmu-events/arch/x86/silvermont'.
153