lkml.org 
[lkml]   [2014]   [May]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 6/7] perf: Add support to dynamically get cacheline size
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@redhat.com>
> ---
> 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


\
 
 \ /
  Last update: 2014-05-23 20:01    [W:0.102 / U:1.496 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site