README 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. The contents of this directory allow users to specify PMU events in their
  2. CPUs by their symbolic names rather than raw event codes (see example below).
  3. The main program in this directory, is the 'jevents', which is built and
  4. executed _BEFORE_ the perf binary itself is built.
  5. The 'jevents' program tries to locate and process JSON files in the directory
  6. tree tools/perf/pmu-events/arch/foo.
  7. - Regular files with '.json' extension in the name are assumed to be
  8. JSON files, each of which describes a set of PMU events.
  9. - Regular files with basename starting with 'mapfile.csv' are assumed
  10. to be a CSV file that maps a specific CPU to its set of PMU events.
  11. (see below for mapfile format)
  12. - Directories are traversed, but all other files are ignored.
  13. The PMU events supported by a CPU model are expected to grouped into topics
  14. such as Pipelining, Cache, Memory, Floating-point etc. All events for a topic
  15. should be placed in a separate JSON file - where the file name identifies
  16. the topic. Eg: "Floating-point.json".
  17. All the topic JSON files for a CPU model/family should be in a separate
  18. sub directory. Thus for the Silvermont X86 CPU:
  19. $ ls tools/perf/pmu-events/arch/x86/Silvermont_core
  20. Cache.json Memory.json Virtual-Memory.json
  21. Frontend.json Pipeline.json
  22. Using the JSON files and the mapfile, 'jevents' generates the C source file,
  23. 'pmu-events.c', which encodes the two sets of tables:
  24. - Set of 'PMU events tables' for all known CPUs in the architecture,
  25. (one table like the following, per JSON file; table name 'pme_power8'
  26. is derived from JSON file name, 'power8.json').
  27. struct pmu_event pme_power8[] = {
  28. ...
  29. {
  30. .name = "pm_1plus_ppc_cmpl",
  31. .event = "event=0x100f2",
  32. .desc = "1 or more ppc insts finished,",
  33. },
  34. ...
  35. }
  36. - A 'mapping table' that maps each CPU of the architecture, to its
  37. 'PMU events table'
  38. struct pmu_events_map pmu_events_map[] = {
  39. {
  40. .cpuid = "004b0000",
  41. .version = "1",
  42. .type = "core",
  43. .table = pme_power8
  44. },
  45. ...
  46. };
  47. After the 'pmu-events.c' is generated, it is compiled and the resulting
  48. 'pmu-events.o' is added to 'libperf.a' which is then used to build perf.
  49. NOTES:
  50. 1. Several CPUs can support same set of events and hence use a common
  51. JSON file. Hence several entries in the pmu_events_map[] could map
  52. to a single 'PMU events table'.
  53. 2. The 'pmu-events.h' has an extern declaration for the mapping table
  54. and the generated 'pmu-events.c' defines this table.
  55. 3. _All_ known CPU tables for architecture are included in the perf
  56. binary.
  57. At run time, perf determines the actual CPU it is running on, finds the
  58. matching events table and builds aliases for those events. This allows
  59. users to specify events by their name:
  60. $ perf stat -e pm_1plus_ppc_cmpl sleep 1
  61. where 'pm_1plus_ppc_cmpl' is a Power8 PMU event.
  62. In case of errors when processing files in the tools/perf/pmu-events/arch
  63. directory, 'jevents' tries to create an empty mapping file to allow the perf
  64. build to succeed even if the PMU event aliases cannot be used.
  65. However some errors in processing may cause the perf build to fail.
  66. Mapfile format
  67. ===============
  68. The mapfile enables multiple CPU models to share a single set of PMU events.
  69. It is required even if such mapping is 1:1.
  70. The mapfile.csv format is expected to be:
  71. Header line
  72. CPUID,Version,Dir/path/name,Type
  73. where:
  74. Comma:
  75. is the required field delimiter (i.e other fields cannot
  76. have commas within them).
  77. Comments:
  78. Lines in which the first character is either '\n' or '#'
  79. are ignored.
  80. Header line
  81. The header line is the first line in the file, which is
  82. always _IGNORED_. It can empty.
  83. CPUID:
  84. CPUID is an arch-specific char string, that can be used
  85. to identify CPU (and associate it with a set of PMU events
  86. it supports). Multiple CPUIDS can point to the same
  87. File/path/name.json.
  88. Example:
  89. CPUID == 'GenuineIntel-6-2E' (on x86).
  90. CPUID == '004b0100' (PVR value in Powerpc)
  91. Version:
  92. is the Version of the mapfile.
  93. Dir/path/name:
  94. is the pathname to the directory containing the CPU's JSON
  95. files, relative to the directory containing the mapfile.csv
  96. Type:
  97. indicates whether the events or "core" or "uncore" events.
  98. Eg:
  99. $ grep Silvermont tools/perf/pmu-events/arch/x86/mapfile.csv
  100. GenuineIntel-6-37,V13,Silvermont_core,core
  101. GenuineIntel-6-4D,V13,Silvermont_core,core
  102. GenuineIntel-6-4C,V13,Silvermont_core,core
  103. i.e the three CPU models use the JSON files (i.e PMU events) listed
  104. in the directory 'tools/perf/pmu-events/arch/x86/Silvermont_core'.