Re: [PATCH 6/7] perf: Add support to dynamically get cacheline size

From: Jiri Olsa
Date: Fri May 23 2014 - 12:54:54 EST


On Mon, May 19, 2014 at 03:13:52PM -0400, Don Zickus wrote:
> Different arches may have different cacheline sizes. Look it up and set
> a global variable for reference.
>
> Signed-off-by: Don Zickus <dzickus@xxxxxxxxxx>
> ---
> tools/perf/util/cpumap.c | 31 +++++++++++++++++++++++++++++++
> tools/perf/util/cpumap.h | 12 ++++++++++++
> tools/perf/util/sort.c | 3 +++
> 3 files changed, 46 insertions(+)
>
> diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c
> index c4e55b7..d833238 100644
> --- a/tools/perf/util/cpumap.c
> +++ b/tools/perf/util/cpumap.c
> @@ -477,3 +477,34 @@ int cpu__setup_cpunode_map(void)
> closedir(dir1);
> return 0;
> }
> +
> +int cpu__setup_cacheline_size(void)
> +{
> + const char *mnt;
> + char path[PATH_MAX];
> + int n, ret, size;
> + FILE *fp;
> +
> +
> + mnt = sysfs__mountpoint();
> + if (!mnt)
> + return -1;
> +
> + n = snprintf(path, PATH_MAX, "%s/devices/system/cpu/cpu0/cache/index0/coherency_line_size", mnt);
> + if (n == PATH_MAX) {
> + pr_err("sysfs path crossed PATH_MAX(%d) size\n", PATH_MAX);
> + return -1;
> + }
> +
> + fp = fopen(path, "r");
> + if (!fp)
> + return -1;
> + ret = fscanf(fp, "%d", &size);
> + fclose(fp);
> + if (ret != 1)
> + return -1;

you can use filename__read_int

jirka
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/