On Mon, Nov 3, 2025 at 8:56 PM Namhyung Kim <namhyung@kernel.org> wrote:
>
> On Fri, Oct 24, 2025 at 10:58:42AM -0700, Ian Rogers wrote:
> > For CPU nanoseconds a lot of the stat-shadow metrics use either
> > task-clock or cpu-clock, the latter being used when
> > target__has_cpu. Add a #target_cpu literal so that json metrics can
> > perform the same test.
>
> Do we have documentation for the literals and metric expressions in
> general? I think it's getting complex and we should provide one.
So in general all these are documented in the tools events in `perf list`:
```
$ perf list
...
tool:
duration_time
[Wall clock interval time in nanoseconds. Unit: tool]
has_pmem
[1 if persistent memory installed otherwise 0. Unit: tool]
num_cores
[Number of cores. A core consists of 1 or more thread,with each
thread being associated
with a logical Linux CPU. Unit: tool]
num_cpus
[Number of logical Linux CPUs. There may be multiple such CPUs
on a core. Unit: tool]
num_cpus_online
[Number of online logical Linux CPUs. There may be multiple
such CPUs on a core. Unit: tool]
num_dies
[Number of dies. Each die has 1 or more cores. Unit: tool]
num_packages
[Number of packages. Each package has 1 or more die. Unit: tool]
smt_on
[1 if simultaneous multithreading (aka hyperthreading) is
enable otherwise 0. Unit: tool]
system_time
[System/kernel time in nanoseconds. Unit: tool]
system_tsc_freq
[The amount a Time Stamp Counter (TSC) increases per second. Unit: tool]
user_time
[User (non-kernel) time in nanoseconds. Unit: tool]
```
We haven't done that with #core_wide and I followed that pattern for
#target_cpu as they do similar things. The issue with these two
"literals", why they are hard to be tool events, is that they depend
on command line options that may be processed after the processing of
the metrics. We could make tool versions with some plumbing. I'll look
to add that.
Thanks,
Ian
> Thanks,
> Namhyung
>
> >
> > Signed-off-by: Ian Rogers <irogers@google.com>
> > ---
> > tools/perf/util/expr.c | 3 +++
> > 1 file changed, 3 insertions(+)
> >
> > diff --git a/tools/perf/util/expr.c b/tools/perf/util/expr.c
> > index 7fda0ff89c16..4df56f2b283d 100644
> > --- a/tools/perf/util/expr.c
> > +++ b/tools/perf/util/expr.c
> > @@ -409,6 +409,9 @@ double expr__get_literal(const char *literal, const struct expr_scanner_ctx *ctx
> > } else if (!strcmp("#core_wide", literal)) {
> > result = core_wide(ctx->system_wide, ctx->user_requested_cpu_list)
> > ? 1.0 : 0.0;
> > + } else if (!strcmp("#target_cpu", literal)) {
> > + result = (ctx->system_wide || ctx->user_requested_cpu_list)
> > + ? 1.0 : 0.0;
> > } else {
> > pr_err("Unrecognized literal '%s'", literal);
> > }
> > --
> > 2.51.1.821.gb6fe4d2222-goog
> >