Skip to content

Commit f0005f1

Browse files
captain5050acmel
authored andcommitted
perf metric: Add #num_cpus_online literal
Returns the number of CPUs online, unlike #num_cpus that returns the number present. Add a test of the property. This will be used in future Intel metrics. Reviewed-by: Kan Liang <kan.liang@linux.intel.com> Signed-off-by: Ian Rogers <irogers@google.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Eduard Zingerman <eddyz87@gmail.com> Cc: James Clark <james.clark@arm.com> Cc: Jing Zhang <renyu.zj@linux.alibaba.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: John Garry <john.g.garry@oracle.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Perry Taylor <perry.taylor@intel.com> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lore.kernel.org/lkml/20230830073026.1829912-1-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 30f0b43 commit f0005f1

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

tools/perf/tests/expr.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ static int test__expr(struct test_suite *t __maybe_unused, int subtest __maybe_u
7070
{
7171
struct expr_id_data *val_ptr;
7272
const char *p;
73-
double val, num_cpus, num_cores, num_dies, num_packages;
73+
double val, num_cpus_online, num_cpus, num_cores, num_dies, num_packages;
7474
int ret;
7575
struct expr_parse_ctx *ctx;
7676
bool is_intel = false;
@@ -227,7 +227,10 @@ static int test__expr(struct test_suite *t __maybe_unused, int subtest __maybe_u
227227

228228
/* Test toplogy constants appear well ordered. */
229229
expr__ctx_clear(ctx);
230+
TEST_ASSERT_VAL("#num_cpus_online",
231+
expr__parse(&num_cpus_online, ctx, "#num_cpus_online") == 0);
230232
TEST_ASSERT_VAL("#num_cpus", expr__parse(&num_cpus, ctx, "#num_cpus") == 0);
233+
TEST_ASSERT_VAL("#num_cpus >= #num_cpus_online", num_cpus >= num_cpus_online);
231234
TEST_ASSERT_VAL("#num_cores", expr__parse(&num_cores, ctx, "#num_cores") == 0);
232235
TEST_ASSERT_VAL("#num_cpus >= #num_cores", num_cpus >= num_cores);
233236
TEST_ASSERT_VAL("#num_dies", expr__parse(&num_dies, ctx, "#num_dies") == 0);

tools/perf/util/expr.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,13 @@ double expr__get_literal(const char *literal, const struct expr_scanner_ctx *ctx
427427
result = cpu__max_present_cpu().cpu;
428428
goto out;
429429
}
430+
if (!strcmp("#num_cpus_online", literal)) {
431+
struct perf_cpu_map *online = cpu_map__online();
432+
433+
if (online)
434+
result = perf_cpu_map__nr(online);
435+
goto out;
436+
}
430437

431438
if (!strcasecmp("#system_tsc_freq", literal)) {
432439
result = arch_get_tsc_freq();

0 commit comments

Comments
 (0)