README 4.7 KB

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