Skip to content

Commit 9c5d00c

Browse files
committed
Merge tag 'perf-tools-fixes-for-v6.6-2-2023-10-20' of git://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools
Pull perf tools fixes from Arnaldo Carvalho de Melo: - Fix regression in reading scale and unit files from sysfs for PMU events, so that we can use that info to pretty print instead of printing raw numbers: # perf stat -e power/energy-ram/,power/energy-gpu/ sleep 2 Performance counter stats for 'system wide': 1.64 Joules power/energy-ram/ 0.20 Joules power/energy-gpu/ 2.001228914 seconds time elapsed # # grep -m1 "model name" /proc/cpuinfo model name : Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz # - The small llvm.cpp file used to check if the llvm devel files are present was incorrectly deleted when removing the BPF event in 'perf trace', put it back as it is also used by tools/bpf/bpftool, that uses llvm routines to do disassembly of BPF object files. - Fix use of addr_location__exit() in dlfilter__object_code(), making sure that it is only used to pair a previous addr_location__init() call. * tag 'perf-tools-fixes-for-v6.6-2-2023-10-20' of git://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools: tools build: Fix llvm feature detection, still used by bpftool perf dlfilter: Add a test for object_code() perf dlfilter: Fix use of addr_location__exit() in dlfilter__object_code() perf pmu: Fix perf stat output with correct scale and unit
2 parents 444ccf1 + 4fa008a commit 9c5d00c

File tree

5 files changed

+55
-23
lines changed

5 files changed

+55
-23
lines changed

tools/build/feature/test-llvm.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
#include "llvm/Support/ManagedStatic.h"
3+
#include "llvm/Support/raw_ostream.h"
4+
#define NUM_VERSION (((LLVM_VERSION_MAJOR) << 16) + (LLVM_VERSION_MINOR << 8) + LLVM_VERSION_PATCH)
5+
6+
#if NUM_VERSION < 0x030900
7+
# error "LLVM version too low"
8+
#endif
9+
int main()
10+
{
11+
llvm::errs() << "Hello World!\n";
12+
llvm::llvm_shutdown();
13+
return 0;
14+
}

tools/perf/dlfilters/dlfilter-test-api-v0.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,15 @@ static int check_attr(void *ctx)
289289
return 0;
290290
}
291291

292+
static int check_object_code(void *ctx, const struct perf_dlfilter_sample *sample)
293+
{
294+
__u8 buf[15];
295+
296+
CHECK(perf_dlfilter_fns.object_code(ctx, sample->ip, buf, sizeof(buf)) > 0);
297+
298+
return 0;
299+
}
300+
292301
static int do_checks(void *data, const struct perf_dlfilter_sample *sample, void *ctx, bool early)
293302
{
294303
struct filter_data *d = data;
@@ -314,7 +323,8 @@ static int do_checks(void *data, const struct perf_dlfilter_sample *sample, void
314323
if (early && !d->do_early)
315324
return 0;
316325

317-
if (check_al(ctx) || check_addr_al(ctx) || check_address_al(ctx, sample))
326+
if (check_al(ctx) || check_addr_al(ctx) || check_address_al(ctx, sample) ||
327+
check_object_code(ctx, sample))
318328
return -1;
319329

320330
if (early)

tools/perf/dlfilters/dlfilter-test-api-v2.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,15 @@ static int check_attr(void *ctx)
308308
return 0;
309309
}
310310

311+
static int check_object_code(void *ctx, const struct perf_dlfilter_sample *sample)
312+
{
313+
__u8 buf[15];
314+
315+
CHECK(perf_dlfilter_fns.object_code(ctx, sample->ip, buf, sizeof(buf)) > 0);
316+
317+
return 0;
318+
}
319+
311320
static int do_checks(void *data, const struct perf_dlfilter_sample *sample, void *ctx, bool early)
312321
{
313322
struct filter_data *d = data;
@@ -333,7 +342,8 @@ static int do_checks(void *data, const struct perf_dlfilter_sample *sample, void
333342
if (early && !d->do_early)
334343
return 0;
335344

336-
if (check_al(ctx) || check_addr_al(ctx) || check_address_al(ctx, sample))
345+
if (check_al(ctx) || check_addr_al(ctx) || check_address_al(ctx, sample) ||
346+
check_object_code(ctx, sample))
337347
return -1;
338348

339349
if (early)

tools/perf/util/dlfilter.c

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -282,13 +282,21 @@ static struct perf_event_attr *dlfilter__attr(void *ctx)
282282
return &d->evsel->core.attr;
283283
}
284284

285+
static __s32 code_read(__u64 ip, struct map *map, struct machine *machine, void *buf, __u32 len)
286+
{
287+
u64 offset = map__map_ip(map, ip);
288+
289+
if (ip + len >= map__end(map))
290+
len = map__end(map) - ip;
291+
292+
return dso__data_read_offset(map__dso(map), machine, offset, buf, len);
293+
}
294+
285295
static __s32 dlfilter__object_code(void *ctx, __u64 ip, void *buf, __u32 len)
286296
{
287297
struct dlfilter *d = (struct dlfilter *)ctx;
288298
struct addr_location *al;
289299
struct addr_location a;
290-
struct map *map;
291-
u64 offset;
292300
__s32 ret;
293301

294302
if (!d->ctx_valid)
@@ -298,27 +306,17 @@ static __s32 dlfilter__object_code(void *ctx, __u64 ip, void *buf, __u32 len)
298306
if (!al)
299307
return -1;
300308

301-
map = al->map;
302-
303-
if (map && ip >= map__start(map) && ip < map__end(map) &&
309+
if (al->map && ip >= map__start(al->map) && ip < map__end(al->map) &&
304310
machine__kernel_ip(d->machine, ip) == machine__kernel_ip(d->machine, d->sample->ip))
305-
goto have_map;
311+
return code_read(ip, al->map, d->machine, buf, len);
306312

307313
addr_location__init(&a);
314+
308315
thread__find_map_fb(al->thread, d->sample->cpumode, ip, &a);
309-
if (!a.map) {
310-
ret = -1;
311-
goto out;
312-
}
316+
ret = a.map ? code_read(ip, a.map, d->machine, buf, len) : -1;
313317

314-
map = a.map;
315-
have_map:
316-
offset = map__map_ip(map, ip);
317-
if (ip + len >= map__end(map))
318-
len = map__end(map) - ip;
319-
ret = dso__data_read_offset(map__dso(map), d->machine, offset, buf, len);
320-
out:
321318
addr_location__exit(&a);
319+
322320
return ret;
323321
}
324322

tools/perf/util/pmu.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ static int perf_pmu__parse_scale(struct perf_pmu *pmu, struct perf_pmu_alias *al
295295
len = perf_pmu__event_source_devices_scnprintf(path, sizeof(path));
296296
if (!len)
297297
return 0;
298-
scnprintf(path + len, sizeof(path) - len, "%s/%s.scale", pmu->name, alias->name);
298+
scnprintf(path + len, sizeof(path) - len, "%s/events/%s.scale", pmu->name, alias->name);
299299

300300
fd = open(path, O_RDONLY);
301301
if (fd == -1)
@@ -330,7 +330,7 @@ static int perf_pmu__parse_unit(struct perf_pmu *pmu, struct perf_pmu_alias *ali
330330
len = perf_pmu__event_source_devices_scnprintf(path, sizeof(path));
331331
if (!len)
332332
return 0;
333-
scnprintf(path + len, sizeof(path) - len, "%s/%s.unit", pmu->name, alias->name);
333+
scnprintf(path + len, sizeof(path) - len, "%s/events/%s.unit", pmu->name, alias->name);
334334

335335
fd = open(path, O_RDONLY);
336336
if (fd == -1)
@@ -364,7 +364,7 @@ perf_pmu__parse_per_pkg(struct perf_pmu *pmu, struct perf_pmu_alias *alias)
364364
len = perf_pmu__event_source_devices_scnprintf(path, sizeof(path));
365365
if (!len)
366366
return 0;
367-
scnprintf(path + len, sizeof(path) - len, "%s/%s.per-pkg", pmu->name, alias->name);
367+
scnprintf(path + len, sizeof(path) - len, "%s/events/%s.per-pkg", pmu->name, alias->name);
368368

369369
fd = open(path, O_RDONLY);
370370
if (fd == -1)
@@ -385,7 +385,7 @@ static int perf_pmu__parse_snapshot(struct perf_pmu *pmu, struct perf_pmu_alias
385385
len = perf_pmu__event_source_devices_scnprintf(path, sizeof(path));
386386
if (!len)
387387
return 0;
388-
scnprintf(path + len, sizeof(path) - len, "%s/%s.snapshot", pmu->name, alias->name);
388+
scnprintf(path + len, sizeof(path) - len, "%s/events/%s.snapshot", pmu->name, alias->name);
389389

390390
fd = open(path, O_RDONLY);
391391
if (fd == -1)

0 commit comments

Comments
 (0)