162306a36Sopenharmony_ci
262306a36Sopenharmony_ciThe contents of this directory allow users to specify PMU events in their
362306a36Sopenharmony_ciCPUs by their symbolic names rather than raw event codes (see example below).
462306a36Sopenharmony_ci
562306a36Sopenharmony_ciThe main program in this directory, is the 'jevents', which is built and
662306a36Sopenharmony_ciexecuted _BEFORE_ the perf binary itself is built.
762306a36Sopenharmony_ci
862306a36Sopenharmony_ciThe 'jevents' program tries to locate and process JSON files in the directory
962306a36Sopenharmony_citree tools/perf/pmu-events/arch/foo.
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci	- Regular files with '.json' extension in the name are assumed to be
1262306a36Sopenharmony_ci	  JSON files, each of which describes a set of PMU events.
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci	- The CSV file that maps a specific CPU to its set of PMU events is to
1562306a36Sopenharmony_ci	  be named 'mapfile.csv' (see below for mapfile format).
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_ci	- Directories are traversed, but all other files are ignored.
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_ci	- To reduce JSON event duplication per architecture, platform JSONs may
2062306a36Sopenharmony_ci	  use "ArchStdEvent" keyword to dereference an "Architecture standard
2162306a36Sopenharmony_ci	  events", defined in architecture standard JSONs.
2262306a36Sopenharmony_ci	  Architecture standard JSONs must be located in the architecture root
2362306a36Sopenharmony_ci	  folder. Matching is based on the "EventName" field.
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_ciThe PMU events supported by a CPU model are expected to grouped into topics
2662306a36Sopenharmony_cisuch as Pipelining, Cache, Memory, Floating-point etc. All events for a topic
2762306a36Sopenharmony_cishould be placed in a separate JSON file - where the file name identifies
2862306a36Sopenharmony_cithe topic. Eg: "Floating-point.json".
2962306a36Sopenharmony_ci
3062306a36Sopenharmony_ciAll the topic JSON files for a CPU model/family should be in a separate
3162306a36Sopenharmony_cisub directory. Thus for the Silvermont X86 CPU:
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ci	$ ls tools/perf/pmu-events/arch/x86/silvermont
3462306a36Sopenharmony_ci	cache.json     memory.json    virtual-memory.json
3562306a36Sopenharmony_ci	frontend.json  pipeline.json
3662306a36Sopenharmony_ci
3762306a36Sopenharmony_ciThe JSONs folder for a CPU model/family may be placed in the root arch
3862306a36Sopenharmony_cifolder, or may be placed in a vendor sub-folder under the arch folder
3962306a36Sopenharmony_cifor instances where the arch and vendor are not the same.
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ciUsing the JSON files and the mapfile, 'jevents' generates the C source file,
4262306a36Sopenharmony_ci'pmu-events.c', which encodes the two sets of tables:
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_ci	- Set of 'PMU events tables' for all known CPUs in the architecture,
4562306a36Sopenharmony_ci	  (one table like the following, per JSON file; table name 'pme_power8'
4662306a36Sopenharmony_ci	  is derived from JSON file name, 'power8.json').
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ci		struct pmu_event pme_power8[] = {
4962306a36Sopenharmony_ci
5062306a36Sopenharmony_ci			...
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ci			{
5362306a36Sopenharmony_ci				.name = "pm_1plus_ppc_cmpl",
5462306a36Sopenharmony_ci				.event = "event=0x100f2",
5562306a36Sopenharmony_ci				.desc = "1 or more ppc insts finished,",
5662306a36Sopenharmony_ci			},
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ci			...
5962306a36Sopenharmony_ci		}
6062306a36Sopenharmony_ci
6162306a36Sopenharmony_ci	- A 'mapping table' that maps each CPU of the architecture, to its
6262306a36Sopenharmony_ci	  'PMU events table'
6362306a36Sopenharmony_ci
6462306a36Sopenharmony_ci		struct pmu_events_map pmu_events_map[] = {
6562306a36Sopenharmony_ci		{
6662306a36Sopenharmony_ci			.cpuid = "004b0000",
6762306a36Sopenharmony_ci			.version = "1",
6862306a36Sopenharmony_ci			.type = "core",
6962306a36Sopenharmony_ci			.table = pme_power8
7062306a36Sopenharmony_ci		},
7162306a36Sopenharmony_ci			...
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_ci		};
7462306a36Sopenharmony_ci
7562306a36Sopenharmony_ciAfter the 'pmu-events.c' is generated, it is compiled and the resulting
7662306a36Sopenharmony_ci'pmu-events.o' is added to 'libperf.a' which is then used to build perf.
7762306a36Sopenharmony_ci
7862306a36Sopenharmony_ciNOTES:
7962306a36Sopenharmony_ci	1. Several CPUs can support same set of events and hence use a common
8062306a36Sopenharmony_ci	   JSON file. Hence several entries in the pmu_events_map[] could map
8162306a36Sopenharmony_ci	   to a single 'PMU events table'.
8262306a36Sopenharmony_ci
8362306a36Sopenharmony_ci	2. The 'pmu-events.h' has an extern declaration for the mapping table
8462306a36Sopenharmony_ci	   and the generated 'pmu-events.c' defines this table.
8562306a36Sopenharmony_ci
8662306a36Sopenharmony_ci	3. _All_ known CPU tables for architecture are included in the perf
8762306a36Sopenharmony_ci	   binary.
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_ciAt run time, perf determines the actual CPU it is running on, finds the
9062306a36Sopenharmony_cimatching events table and builds aliases for those events. This allows
9162306a36Sopenharmony_ciusers to specify events by their name:
9262306a36Sopenharmony_ci
9362306a36Sopenharmony_ci	$ perf stat -e pm_1plus_ppc_cmpl sleep 1
9462306a36Sopenharmony_ci
9562306a36Sopenharmony_ciwhere 'pm_1plus_ppc_cmpl' is a Power8 PMU event.
9662306a36Sopenharmony_ci
9762306a36Sopenharmony_ciHowever some errors in processing may cause the alias build to fail.
9862306a36Sopenharmony_ci
9962306a36Sopenharmony_ciMapfile format
10062306a36Sopenharmony_ci===============
10162306a36Sopenharmony_ci
10262306a36Sopenharmony_ciThe mapfile enables multiple CPU models to share a single set of PMU events.
10362306a36Sopenharmony_ciIt is required even if such mapping is 1:1.
10462306a36Sopenharmony_ci
10562306a36Sopenharmony_ciThe mapfile.csv format is expected to be:
10662306a36Sopenharmony_ci
10762306a36Sopenharmony_ci	Header line
10862306a36Sopenharmony_ci	CPUID,Version,Dir/path/name,Type
10962306a36Sopenharmony_ci
11062306a36Sopenharmony_ciwhere:
11162306a36Sopenharmony_ci
11262306a36Sopenharmony_ci	Comma:
11362306a36Sopenharmony_ci		is the required field delimiter (i.e other fields cannot
11462306a36Sopenharmony_ci		have commas within them).
11562306a36Sopenharmony_ci
11662306a36Sopenharmony_ci	Comments:
11762306a36Sopenharmony_ci		Lines in which the first character is either '\n' or '#'
11862306a36Sopenharmony_ci		are ignored.
11962306a36Sopenharmony_ci
12062306a36Sopenharmony_ci	Header line
12162306a36Sopenharmony_ci		The header line is the first line in the file, which is
12262306a36Sopenharmony_ci		always _IGNORED_. It can be empty.
12362306a36Sopenharmony_ci
12462306a36Sopenharmony_ci	CPUID:
12562306a36Sopenharmony_ci		CPUID is an arch-specific char string, that can be used
12662306a36Sopenharmony_ci		to identify CPU (and associate it with a set of PMU events
12762306a36Sopenharmony_ci		it supports). Multiple CPUIDS can point to the same
12862306a36Sopenharmony_ci		File/path/name.json.
12962306a36Sopenharmony_ci
13062306a36Sopenharmony_ci		Example:
13162306a36Sopenharmony_ci			CPUID == 'GenuineIntel-6-2E' (on x86).
13262306a36Sopenharmony_ci			CPUID == '004b0100' (PVR value in Powerpc)
13362306a36Sopenharmony_ci	Version:
13462306a36Sopenharmony_ci		is the Version of the mapfile.
13562306a36Sopenharmony_ci
13662306a36Sopenharmony_ci	Dir/path/name:
13762306a36Sopenharmony_ci		is the pathname to the directory containing the CPU's JSON
13862306a36Sopenharmony_ci		files, relative to the directory containing the mapfile.csv
13962306a36Sopenharmony_ci
14062306a36Sopenharmony_ci	Type:
14162306a36Sopenharmony_ci		indicates whether the events are "core" or "uncore" events.
14262306a36Sopenharmony_ci
14362306a36Sopenharmony_ci
14462306a36Sopenharmony_ci	Eg:
14562306a36Sopenharmony_ci
14662306a36Sopenharmony_ci	$ grep silvermont tools/perf/pmu-events/arch/x86/mapfile.csv
14762306a36Sopenharmony_ci	GenuineIntel-6-37,v13,silvermont,core
14862306a36Sopenharmony_ci	GenuineIntel-6-4D,v13,silvermont,core
14962306a36Sopenharmony_ci	GenuineIntel-6-4C,v13,silvermont,core
15062306a36Sopenharmony_ci
15162306a36Sopenharmony_ci	i.e the three CPU models use the JSON files (i.e PMU events) listed
15262306a36Sopenharmony_ci	in the directory 'tools/perf/pmu-events/arch/x86/silvermont'.
153