]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
perf metrics: Add has_pmem literal
authorIan Rogers <irogers@google.com>
Fri, 24 Mar 2023 07:22:17 +0000 (00:22 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 4 Apr 2023 12:39:55 +0000 (09:39 -0300)
Add literal so that if nvdimms aren't installed we can record fewer
events.  The file detection mechanism was suggested by Dan Williams
<dan.j.williams@intel.com> in:

  https://lore.kernel.org/linux-perf-users/641bbe1eced26_1b98bb29440@dwillia2-xfh.jf.intel.com.notmuch/

Reviewed-by: Kan Liang <kan.liang@linux.intel.com>
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Edward Baker <edward.baker@intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
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>
Cc: Samantha Alt <samantha.alt@intel.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: https://lore.kernel.org/r/20230324072218.181880-2-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/expr.c

index d46a1878bc9ee781bb633c322371151621d40f28..bb6ddad7e02179e145b3829a98fd2177a967886f 100644 (file)
@@ -14,6 +14,7 @@
 #include "util/hashmap.h"
 #include "smt.h"
 #include "tsc.h"
+#include <api/fs/fs.h>
 #include <linux/err.h>
 #include <linux/kernel.h>
 #include <linux/zalloc.h>
@@ -400,6 +401,20 @@ double arch_get_tsc_freq(void)
 }
 #endif
 
+static double has_pmem(void)
+{
+       static bool has_pmem, cached;
+       const char *sysfs = sysfs__mountpoint();
+       char path[PATH_MAX];
+
+       if (!cached) {
+               snprintf(path, sizeof(path), "%s/firmware/acpi/tables/NFIT", sysfs);
+               has_pmem = access(path, F_OK) == 0;
+               cached = true;
+       }
+       return has_pmem ? 1.0 : 0.0;
+}
+
 double expr__get_literal(const char *literal, const struct expr_scanner_ctx *ctx)
 {
        const struct cpu_topology *topology;
@@ -449,6 +464,10 @@ double expr__get_literal(const char *literal, const struct expr_scanner_ctx *ctx
                result = perf_pmu__cpu_slots_per_cycle();
                goto out;
        }
+       if (!strcmp("#has_pmem", literal)) {
+               result = has_pmem();
+               goto out;
+       }
 
        pr_err("Unrecognized literal '%s'", literal);
 out: