Re: [PATCH 6/7] perf: Add support to dynamically get cacheline size
On Tue, 27 May 2014 12:28:06 -0400, Don Zickus wrote: > Different arches may have different cacheline sizes. Look it up and set > a global variable for reference. [SNIP] > diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c > index 635cd8f..6e06567 100644 > --- a/tools/perf/util/sort.c > +++ b/tools/perf/util/sort.c > @@ -2,6 +2,7 @@ > #include "hist.h" > #include "comm.h" > #include "symbol.h" > +#include "cpumap.h" It seems not needed anymore? Thanks, Namhyung > > regex_t parent_regex; > const char default_parent_pattern[] = "^sys_|^do_page_fault"; -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[PATCH 6/7] perf: Add support to dynamically get cacheline size
Different arches may have different cacheline sizes. Look it up and set a global variable for reference. Signed-off-by: Don Zickus --- V2: change to be global and setup in perf.c use filename__read_int for setup --- tools/perf/perf.c| 5 + tools/perf/util/cpumap.c | 27 +++ tools/perf/util/cpumap.h | 3 +++ tools/perf/util/sort.c | 1 + tools/perf/util/util.c | 1 + tools/perf/util/util.h | 1 + 6 files changed, 38 insertions(+) diff --git a/tools/perf/perf.c b/tools/perf/perf.c index 431798a..dabf08b 100644 --- a/tools/perf/perf.c +++ b/tools/perf/perf.c @@ -13,6 +13,7 @@ #include "util/quote.h" #include "util/run-command.h" #include "util/parse-events.h" +#include "util/cpumap.h" #include #include @@ -459,6 +460,10 @@ int main(int argc, const char **argv) /* The page_size is placed in util object. */ page_size = sysconf(_SC_PAGE_SIZE); + /* The cacheline_size is placed in util objet */ + if (cpu__setup_cacheline_size() < 0) + goto out; + cmd = perf_extract_argv0_path(argv[0]); if (!cmd) cmd = "perf-help"; diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index c4e55b7..1029982 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c @@ -477,3 +477,30 @@ 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, size; + + + 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; + } + + if (filename__read_int(path, &size)) { + pr_err("Can not read cacheline size\n"); + return -1; + } + + cacheline_size = size; + + return 0; +} diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h index 61a6548..507d7fd 100644 --- a/tools/perf/util/cpumap.h +++ b/tools/perf/util/cpumap.h @@ -5,6 +5,7 @@ #include #include "perf.h" +#include "util/util.h" #include "util/debug.h" struct cpu_map { @@ -81,4 +82,6 @@ static inline int cpu__get_node(int cpu) return cpunode_map[cpu]; } +int cpu__setup_cacheline_size(void); + #endif /* __PERF_CPUMAP_H */ diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c index 635cd8f..6e06567 100644 --- a/tools/perf/util/sort.c +++ b/tools/perf/util/sort.c @@ -2,6 +2,7 @@ #include "hist.h" #include "comm.h" #include "symbol.h" +#include "cpumap.h" regex_tparent_regex; const char default_parent_pattern[] = "^sys_|^do_page_fault"; diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c index 7fff6be..95aefa7 100644 --- a/tools/perf/util/util.c +++ b/tools/perf/util/util.c @@ -17,6 +17,7 @@ * XXX We need to find a better place for these things... */ unsigned int page_size; +int cacheline_size; bool test_attr__enabled; diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h index b03da44..6686436 100644 --- a/tools/perf/util/util.h +++ b/tools/perf/util/util.h @@ -304,6 +304,7 @@ char *rtrim(char *s); void dump_stack(void); extern unsigned int page_size; +extern int cacheline_size; void get_term_dimensions(struct winsize *ws); -- 1.7.11.7 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH 6/7] perf: Add support to dynamically get cacheline size
On Fri, May 23, 2014 at 07:09:01PM +0200, Jiri Olsa wrote: > On Mon, May 19, 2014 at 03:13:52PM -0400, Don Zickus wrote: > > SNIP > > > diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h > > index 61a6548..b3e7b22 100644 > > --- a/tools/perf/util/cpumap.h > > +++ b/tools/perf/util/cpumap.h > > @@ -81,4 +81,16 @@ static inline int cpu__get_node(int cpu) > > return cpunode_map[cpu]; > > } > > > > +int cacheline_size; > > hum, so cacheline_size does not need to be global, if you use > cpu__cacheline_size in your next patch, right? I made cpu__cacheline_size an inline so I think it does. If I stick that function in cpumap.c then yeah I would agree it would not need to be global. Being that is was going to be called repeatedly while processing each event I opted to make it an inline. I guess I could change that if it matters. > > > + > > +int cpu__setup_cacheline_size(void); > > + > > +static inline int cpu__cacheline_size(void) > > +{ > > + if (unlikely(!cacheline_size)) > > + pr_debug("cacheline size not initialized\n"); > > + > > + return cacheline_size; > > +} > > + > > #endif /* __PERF_CPUMAP_H */ > > diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c > > index 635cd8f..50adbfb 100644 > > --- a/tools/perf/util/sort.c > > +++ b/tools/perf/util/sort.c > > @@ -2,6 +2,7 @@ > > #include "hist.h" > > #include "comm.h" > > #include "symbol.h" > > +#include "cpumap.h" > > > > regex_tparent_regex; > > const char default_parent_pattern[] = "^sys_|^do_page_fault"; > > @@ -1117,6 +1118,8 @@ int setup_sorting(void) > > return -ENOMEM; > > } > > > > + cpu__setup_cacheline_size(); > > + > > I dont think this is the best place to call the setup, > on the other hand I can't think of any suitable ;-) > > how about lazy initialization from cpu__cacheline_size? > > We also have page_size variable which gets initialized > in main and is globaly accesable. I wonder we should > add the cacheline_size variable in the same way. That seems to make sense. I can stick the variable in util.c|h then? Cheers, Don -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH 6/7] perf: Add support to dynamically get cacheline size
On Fri, May 23, 2014 at 06:54:06PM +0200, Jiri Olsa wrote: > 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 > > --- > > 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 Doh. I forgot about that. I can respin this patch or the whole series for that. Perhaps on Tuesday when we come back from our US Holiday. Cheers, Don -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH 6/7] perf: Add support to dynamically get cacheline size
On Mon, May 19, 2014 at 03:13:52PM -0400, Don Zickus wrote: SNIP > diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h > index 61a6548..b3e7b22 100644 > --- a/tools/perf/util/cpumap.h > +++ b/tools/perf/util/cpumap.h > @@ -81,4 +81,16 @@ static inline int cpu__get_node(int cpu) > return cpunode_map[cpu]; > } > > +int cacheline_size; hum, so cacheline_size does not need to be global, if you use cpu__cacheline_size in your next patch, right? > + > +int cpu__setup_cacheline_size(void); > + > +static inline int cpu__cacheline_size(void) > +{ > + if (unlikely(!cacheline_size)) > + pr_debug("cacheline size not initialized\n"); > + > + return cacheline_size; > +} > + > #endif /* __PERF_CPUMAP_H */ > diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c > index 635cd8f..50adbfb 100644 > --- a/tools/perf/util/sort.c > +++ b/tools/perf/util/sort.c > @@ -2,6 +2,7 @@ > #include "hist.h" > #include "comm.h" > #include "symbol.h" > +#include "cpumap.h" > > regex_t parent_regex; > const char default_parent_pattern[] = "^sys_|^do_page_fault"; > @@ -1117,6 +1118,8 @@ int setup_sorting(void) > return -ENOMEM; > } > > + cpu__setup_cacheline_size(); > + I dont think this is the best place to call the setup, on the other hand I can't think of any suitable ;-) how about lazy initialization from cpu__cacheline_size? We also have page_size variable which gets initialized in main and is globaly accesable. I wonder we should add the cacheline_size variable in the same way. jirka -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [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 > --- > 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 majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[PATCH 6/7] perf: Add support to dynamically get cacheline size
Different arches may have different cacheline sizes. Look it up and set a global variable for reference. Signed-off-by: Don Zickus --- 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; + + cacheline_size = size; + + return 0; +} diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h index 61a6548..b3e7b22 100644 --- a/tools/perf/util/cpumap.h +++ b/tools/perf/util/cpumap.h @@ -81,4 +81,16 @@ static inline int cpu__get_node(int cpu) return cpunode_map[cpu]; } +int cacheline_size; + +int cpu__setup_cacheline_size(void); + +static inline int cpu__cacheline_size(void) +{ + if (unlikely(!cacheline_size)) + pr_debug("cacheline size not initialized\n"); + + return cacheline_size; +} + #endif /* __PERF_CPUMAP_H */ diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c index 635cd8f..50adbfb 100644 --- a/tools/perf/util/sort.c +++ b/tools/perf/util/sort.c @@ -2,6 +2,7 @@ #include "hist.h" #include "comm.h" #include "symbol.h" +#include "cpumap.h" regex_tparent_regex; const char default_parent_pattern[] = "^sys_|^do_page_fault"; @@ -1117,6 +1118,8 @@ int setup_sorting(void) return -ENOMEM; } + cpu__setup_cacheline_size(); + for (tok = strtok_r(str, ", ", &tmp); tok; tok = strtok_r(NULL, ", ", &tmp)) { ret = sort_dimension__add(tok); -- 1.7.11.7 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/