diff options
Diffstat (limited to 'tools/perf/util/expr.c')
| -rw-r--r-- | tools/perf/util/expr.c | 49 | 
1 files changed, 32 insertions, 17 deletions
diff --git a/tools/perf/util/expr.c b/tools/perf/util/expr.c index c1da20b868db..f4e52919324e 100644 --- a/tools/perf/util/expr.c +++ b/tools/perf/util/expr.c @@ -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> @@ -85,8 +86,8 @@ void ids__free(struct hashmap *ids)  		return;  	hashmap__for_each_entry(ids, cur, bkt) { -		free((void *)cur->pkey); -		free((void *)cur->pvalue); +		zfree(&cur->pkey); +		zfree(&cur->pvalue);  	}  	hashmap__free(ids); @@ -310,8 +311,8 @@ void expr__ctx_clear(struct expr_parse_ctx *ctx)  	size_t bkt;  	hashmap__for_each_entry(ctx->ids, cur, bkt) { -		free((void *)cur->pkey); -		free(cur->pvalue); +		zfree(&cur->pkey); +		zfree(&cur->pvalue);  	}  	hashmap__clear(ctx->ids);  } @@ -324,10 +325,10 @@ void expr__ctx_free(struct expr_parse_ctx *ctx)  	if (!ctx)  		return; -	free(ctx->sctx.user_requested_cpu_list); +	zfree(&ctx->sctx.user_requested_cpu_list);  	hashmap__for_each_entry(ctx->ids, cur, bkt) { -		free((void *)cur->pkey); -		free(cur->pvalue); +		zfree(&cur->pkey); +		zfree(&cur->pvalue);  	}  	hashmap__free(ctx->ids);  	free(ctx); @@ -400,9 +401,23 @@ 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)  { -	static struct cpu_topology *topology; +	const struct cpu_topology *topology;  	double result = NAN;  	if (!strcmp("#num_cpus", literal)) { @@ -421,31 +436,27 @@ double expr__get_literal(const char *literal, const struct expr_scanner_ctx *ctx  	 * these strings gives an indication of the number of packages, dies,  	 * etc.  	 */ -	if (!topology) { -		topology = cpu_topology__new(); -		if (!topology) { -			pr_err("Error creating CPU topology"); -			goto out; -		} -	}  	if (!strcasecmp("#smt_on", literal)) { -		result = smt_on(topology) ? 1.0 : 0.0; +		result = smt_on() ? 1.0 : 0.0;  		goto out;  	}  	if (!strcmp("#core_wide", literal)) { -		result = core_wide(ctx->system_wide, ctx->user_requested_cpu_list, topology) +		result = core_wide(ctx->system_wide, ctx->user_requested_cpu_list)  			? 1.0 : 0.0;  		goto out;  	}  	if (!strcmp("#num_packages", literal)) { +		topology = online_topology();  		result = topology->package_cpus_lists;  		goto out;  	}  	if (!strcmp("#num_dies", literal)) { +		topology = online_topology();  		result = topology->die_cpus_lists;  		goto out;  	}  	if (!strcmp("#num_cores", literal)) { +		topology = online_topology();  		result = topology->core_cpus_lists;  		goto out;  	} @@ -453,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:  | 
