Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf tools: Update topdown documentation for Sapphire Rapids

Update Topdown extension on Sapphire Rapids and how to collect the L2
events.

Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Madhavan Srinivasan <maddy@linux.vnet.ibm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lore.kernel.org/lkml/1612296553-21962-10-git-send-email-kan.liang@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Kan Liang and committed by
Arnaldo Carvalho de Melo
7d91e818 63e39aa6

+74 -4
+74 -4
tools/perf/Documentation/topdown.txt
··· 121 121 #define RDPMC_METRIC (1 << 29) /* return metric counters */ 122 122 123 123 #define FIXED_COUNTER_SLOTS 3 124 - #define METRIC_COUNTER_TOPDOWN_L1 0 124 + #define METRIC_COUNTER_TOPDOWN_L1_L2 0 125 125 126 126 static inline uint64_t read_slots(void) 127 127 { ··· 130 130 131 131 static inline uint64_t read_metrics(void) 132 132 { 133 - return _rdpmc(RDPMC_METRIC | METRIC_COUNTER_TOPDOWN_L1); 133 + return _rdpmc(RDPMC_METRIC | METRIC_COUNTER_TOPDOWN_L1_L2); 134 134 } 135 135 136 136 Then the program can be instrumented to read these metrics at different ··· 152 152 153 153 #define GET_METRIC(m, i) (((m) >> (i*8)) & 0xff) 154 154 155 + /* L1 Topdown metric events */ 155 156 #define TOPDOWN_RETIRING(val) ((float)GET_METRIC(val, 0) / 0xff) 156 157 #define TOPDOWN_BAD_SPEC(val) ((float)GET_METRIC(val, 1) / 0xff) 157 158 #define TOPDOWN_FE_BOUND(val) ((float)GET_METRIC(val, 2) / 0xff) 158 159 #define TOPDOWN_BE_BOUND(val) ((float)GET_METRIC(val, 3) / 0xff) 160 + 161 + /* 162 + * L2 Topdown metric events. 163 + * Available on Sapphire Rapids and later platforms. 164 + */ 165 + #define TOPDOWN_HEAVY_OPS(val) ((float)GET_METRIC(val, 4) / 0xff) 166 + #define TOPDOWN_BR_MISPREDICT(val) ((float)GET_METRIC(val, 5) / 0xff) 167 + #define TOPDOWN_FETCH_LAT(val) ((float)GET_METRIC(val, 6) / 0xff) 168 + #define TOPDOWN_MEM_BOUND(val) ((float)GET_METRIC(val, 7) / 0xff) 159 169 160 170 and then converted to percent for printing. 161 171 ··· 200 190 fe_bound_slots = GET_METRIC(metric_b, 2) * slots_b - fe_bound_slots_a 201 191 be_bound_slots = GET_METRIC(metric_b, 3) * slots_b - be_bound_slots_a 202 192 203 - Later the individual ratios for the measurement period can be recreated 204 - from these counts. 193 + Later the individual ratios of L1 metric events for the measurement period can 194 + be recreated from these counts. 205 195 206 196 slots_delta = slots_b - slots_a 207 197 retiring_ratio = (float)retiring_slots / slots_delta ··· 214 204 bad_spec_ratio * 100., 215 205 fe_bound_ratio * 100., 216 206 be_bound_ratio * 100.); 207 + 208 + The individual ratios of L2 metric events for the measurement period can be 209 + recreated from L1 and L2 metric counters. (Available on Sapphire Rapids and 210 + later platforms) 211 + 212 + # compute scaled metrics for measurement a 213 + heavy_ops_slots_a = GET_METRIC(metric_a, 4) * slots_a 214 + br_mispredict_slots_a = GET_METRIC(metric_a, 5) * slots_a 215 + fetch_lat_slots_a = GET_METRIC(metric_a, 6) * slots_a 216 + mem_bound_slots_a = GET_METRIC(metric_a, 7) * slots_a 217 + 218 + # compute delta scaled metrics between b and a 219 + heavy_ops_slots = GET_METRIC(metric_b, 4) * slots_b - heavy_ops_slots_a 220 + br_mispredict_slots = GET_METRIC(metric_b, 5) * slots_b - br_mispredict_slots_a 221 + fetch_lat_slots = GET_METRIC(metric_b, 6) * slots_b - fetch_lat_slots_a 222 + mem_bound_slots = GET_METRIC(metric_b, 7) * slots_b - mem_bound_slots_a 223 + 224 + slots_delta = slots_b - slots_a 225 + heavy_ops_ratio = (float)heavy_ops_slots / slots_delta 226 + light_ops_ratio = retiring_ratio - heavy_ops_ratio; 227 + 228 + br_mispredict_ratio = (float)br_mispredict_slots / slots_delta 229 + machine_clears_ratio = bad_spec_ratio - br_mispredict_ratio; 230 + 231 + fetch_lat_ratio = (float)fetch_lat_slots / slots_delta 232 + fetch_bw_ratio = fe_bound_ratio - fetch_lat_ratio; 233 + 234 + mem_bound_ratio = (float)mem_bound_slots / slota_delta 235 + core_bound_ratio = be_bound_ratio - mem_bound_ratio; 236 + 237 + printf("Heavy Operations %.2f%% Light Operations %.2f%% " 238 + "Branch Mispredict %.2f%% Machine Clears %.2f%% " 239 + "Fetch Latency %.2f%% Fetch Bandwidth %.2f%% " 240 + "Mem Bound %.2f%% Core Bound %.2f%%\n", 241 + heavy_ops_ratio * 100., 242 + light_ops_ratio * 100., 243 + br_mispredict_ratio * 100., 244 + machine_clears_ratio * 100., 245 + fetch_lat_ratio * 100., 246 + fetch_bw_ratio * 100., 247 + mem_bound_ratio * 100., 248 + core_bound_ratio * 100.); 217 249 218 250 Resetting metrics counters 219 251 ========================== ··· 299 247 a sampling read group. Since the SLOTS event must be the leader of a TopDown 300 248 group, the second event of the group is the sampling event. 301 249 For example, perf record -e '{slots, $sampling_event, topdown-retiring}:S' 250 + 251 + Extension on Sapphire Rapids Server 252 + =================================== 253 + The metrics counter is extended to support TMA method level 2 metrics. 254 + The lower half of the register is the TMA level 1 metrics (legacy). 255 + The upper half is also divided into four 8-bit fields for the new level 2 256 + metrics. Four more TopDown metric events are exposed for the end-users, 257 + topdown-heavy-ops, topdown-br-mispredict, topdown-fetch-lat and 258 + topdown-mem-bound. 259 + 260 + Each of the new level 2 metrics in the upper half is a subset of the 261 + corresponding level 1 metric in the lower half. Software can deduce the 262 + other four level 2 metrics by subtracting corresponding metrics as below. 263 + 264 + Light_Operations = Retiring - Heavy_Operations 265 + Machine_Clears = Bad_Speculation - Branch_Mispredicts 266 + Fetch_Bandwidth = Frontend_Bound - Fetch_Latency 267 + Core_Bound = Backend_Bound - Memory_Bound 302 268 303 269 304 270 [1] https://software.intel.com/en-us/top-down-microarchitecture-analysis-method-win