mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-10-28 23:24:50 +00:00
6d18804b96
A common problem is confusing CPU map indices with the CPU, by wrapping the CPU with a struct then this is avoided. This approach is similar to atomic_t. Committer notes: To make it build with BUILD_BPF_SKEL=1 these files needed the conversions to 'struct perf_cpu' usage: tools/perf/util/bpf_counter.c tools/perf/util/bpf_counter_cgroup.c tools/perf/util/bpf_ftrace.c Also perf_env__get_cpu() was removed back in "perf cpumap: Switch cpu_map__build_map to cpu function". Additionally these needed to be fixed for the ARM builds to complete: tools/perf/arch/arm/util/cs-etm.c tools/perf/arch/arm64/util/pmu.c Suggested-by: John Garry <john.garry@huawei.com> Signed-off-by: Ian Rogers <irogers@google.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: James Clark <james.clark@arm.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Kajol Jain <kjain@linux.ibm.com> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Leo Yan <leo.yan@linaro.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Mathieu Poirier <mathieu.poirier@linaro.org> Cc: Mike Leach <mike.leach@linaro.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Paul Clarke <pc@us.ibm.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Riccardo Mancini <rickyman7@gmail.com> Cc: Stephane Eranian <eranian@google.com> Cc: Suzuki Poulouse <suzuki.poulose@arm.com> Cc: Vineet Singh <vineet.singh@intel.com> Cc: coresight@lists.linaro.org Cc: linux-arm-kernel@lists.infradead.org Cc: zhengjun.xing@intel.com Link: https://lore.kernel.org/r/20220105061351.120843-49-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
126 lines
4 KiB
C
126 lines
4 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
#include <linux/compiler.h>
|
|
#include <perf/cpumap.h>
|
|
#include <string.h>
|
|
#include "cpumap.h"
|
|
#include "evlist.h"
|
|
#include "evsel.h"
|
|
#include "header.h"
|
|
#include "machine.h"
|
|
#include "util/synthetic-events.h"
|
|
#include "tool.h"
|
|
#include "tests.h"
|
|
#include "debug.h"
|
|
|
|
static int process_event_unit(struct perf_tool *tool __maybe_unused,
|
|
union perf_event *event,
|
|
struct perf_sample *sample __maybe_unused,
|
|
struct machine *machine __maybe_unused)
|
|
{
|
|
struct perf_record_event_update *ev = (struct perf_record_event_update *)event;
|
|
|
|
TEST_ASSERT_VAL("wrong id", ev->id == 123);
|
|
TEST_ASSERT_VAL("wrong id", ev->type == PERF_EVENT_UPDATE__UNIT);
|
|
TEST_ASSERT_VAL("wrong unit", !strcmp(ev->data, "KRAVA"));
|
|
return 0;
|
|
}
|
|
|
|
static int process_event_scale(struct perf_tool *tool __maybe_unused,
|
|
union perf_event *event,
|
|
struct perf_sample *sample __maybe_unused,
|
|
struct machine *machine __maybe_unused)
|
|
{
|
|
struct perf_record_event_update *ev = (struct perf_record_event_update *)event;
|
|
struct perf_record_event_update_scale *ev_data;
|
|
|
|
ev_data = (struct perf_record_event_update_scale *)ev->data;
|
|
|
|
TEST_ASSERT_VAL("wrong id", ev->id == 123);
|
|
TEST_ASSERT_VAL("wrong id", ev->type == PERF_EVENT_UPDATE__SCALE);
|
|
TEST_ASSERT_VAL("wrong scale", ev_data->scale == 0.123);
|
|
return 0;
|
|
}
|
|
|
|
struct event_name {
|
|
struct perf_tool tool;
|
|
const char *name;
|
|
};
|
|
|
|
static int process_event_name(struct perf_tool *tool,
|
|
union perf_event *event,
|
|
struct perf_sample *sample __maybe_unused,
|
|
struct machine *machine __maybe_unused)
|
|
{
|
|
struct event_name *tmp = container_of(tool, struct event_name, tool);
|
|
struct perf_record_event_update *ev = (struct perf_record_event_update *)event;
|
|
|
|
TEST_ASSERT_VAL("wrong id", ev->id == 123);
|
|
TEST_ASSERT_VAL("wrong id", ev->type == PERF_EVENT_UPDATE__NAME);
|
|
TEST_ASSERT_VAL("wrong name", !strcmp(ev->data, tmp->name));
|
|
return 0;
|
|
}
|
|
|
|
static int process_event_cpus(struct perf_tool *tool __maybe_unused,
|
|
union perf_event *event,
|
|
struct perf_sample *sample __maybe_unused,
|
|
struct machine *machine __maybe_unused)
|
|
{
|
|
struct perf_record_event_update *ev = (struct perf_record_event_update *)event;
|
|
struct perf_record_event_update_cpus *ev_data;
|
|
struct perf_cpu_map *map;
|
|
|
|
ev_data = (struct perf_record_event_update_cpus *) ev->data;
|
|
|
|
map = cpu_map__new_data(&ev_data->cpus);
|
|
|
|
TEST_ASSERT_VAL("wrong id", ev->id == 123);
|
|
TEST_ASSERT_VAL("wrong type", ev->type == PERF_EVENT_UPDATE__CPUS);
|
|
TEST_ASSERT_VAL("wrong cpus", map->nr == 3);
|
|
TEST_ASSERT_VAL("wrong cpus", map->map[0].cpu == 1);
|
|
TEST_ASSERT_VAL("wrong cpus", map->map[1].cpu == 2);
|
|
TEST_ASSERT_VAL("wrong cpus", map->map[2].cpu == 3);
|
|
perf_cpu_map__put(map);
|
|
return 0;
|
|
}
|
|
|
|
static int test__event_update(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
|
|
{
|
|
struct evsel *evsel;
|
|
struct event_name tmp;
|
|
struct evlist *evlist = evlist__new_default();
|
|
|
|
TEST_ASSERT_VAL("failed to get evlist", evlist);
|
|
|
|
evsel = evlist__first(evlist);
|
|
|
|
TEST_ASSERT_VAL("failed to allocate ids",
|
|
!perf_evsel__alloc_id(&evsel->core, 1, 1));
|
|
|
|
perf_evlist__id_add(&evlist->core, &evsel->core, 0, 0, 123);
|
|
|
|
free((char *)evsel->unit);
|
|
evsel->unit = strdup("KRAVA");
|
|
|
|
TEST_ASSERT_VAL("failed to synthesize attr update unit",
|
|
!perf_event__synthesize_event_update_unit(NULL, evsel, process_event_unit));
|
|
|
|
evsel->scale = 0.123;
|
|
|
|
TEST_ASSERT_VAL("failed to synthesize attr update scale",
|
|
!perf_event__synthesize_event_update_scale(NULL, evsel, process_event_scale));
|
|
|
|
tmp.name = evsel__name(evsel);
|
|
|
|
TEST_ASSERT_VAL("failed to synthesize attr update name",
|
|
!perf_event__synthesize_event_update_name(&tmp.tool, evsel, process_event_name));
|
|
|
|
evsel->core.own_cpus = perf_cpu_map__new("1,2,3");
|
|
|
|
TEST_ASSERT_VAL("failed to synthesize attr update cpus",
|
|
!perf_event__synthesize_event_update_cpus(&tmp.tool, evsel, process_event_cpus));
|
|
|
|
evlist__delete(evlist);
|
|
return 0;
|
|
}
|
|
|
|
DEFINE_SUITE("Synthesize attr update", event_update);
|