diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2016-04-15 16:46:31 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2016-04-15 16:46:31 -0400 |
commit | f5e7150cd9a7779a54b192d21afb9245384db8bc (patch) | |
tree | e061fe5d0e029765c5c4e57d68cc503198f66bba /tools | |
parent | 056149932602ef905f1e26fc4fe242ef0533a597 (diff) |
perf evlist: Expose perf_event_mlock_kb_in_pages() helper
When the user doesn't set --mmap-pages, perf_evlist__mmap() will do it
by reading the maximum possible for a non-root user from the
/proc/sys/kernel/perf_event_mlock_kb file.
Expose that function so that 'perf trace' can, for root users, to bump
mmap-pages to a higher value for root, based on the contents of this
proc file.
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Milian Wolff <milian.wolff@kdab.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-xay69plylwibpb3l4isrpl1k@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/perf/util/evlist.c | 42 | ||||
-rw-r--r-- | tools/perf/util/evlist.h | 2 |
2 files changed, 27 insertions, 17 deletions
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 4c9f510ae18d..6fb5725821de 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c | |||
@@ -986,26 +986,34 @@ out_unmap: | |||
986 | return -1; | 986 | return -1; |
987 | } | 987 | } |
988 | 988 | ||
989 | static size_t perf_evlist__mmap_size(unsigned long pages) | 989 | unsigned long perf_event_mlock_kb_in_pages(void) |
990 | { | 990 | { |
991 | if (pages == UINT_MAX) { | 991 | unsigned long pages; |
992 | int max; | 992 | int max; |
993 | 993 | ||
994 | if (sysctl__read_int("kernel/perf_event_mlock_kb", &max) < 0) { | 994 | if (sysctl__read_int("kernel/perf_event_mlock_kb", &max) < 0) { |
995 | /* | 995 | /* |
996 | * Pick a once upon a time good value, i.e. things look | 996 | * Pick a once upon a time good value, i.e. things look |
997 | * strange since we can't read a sysctl value, but lets not | 997 | * strange since we can't read a sysctl value, but lets not |
998 | * die yet... | 998 | * die yet... |
999 | */ | 999 | */ |
1000 | max = 512; | 1000 | max = 512; |
1001 | } else { | 1001 | } else { |
1002 | max -= (page_size / 1024); | 1002 | max -= (page_size / 1024); |
1003 | } | 1003 | } |
1004 | |||
1005 | pages = (max * 1024) / page_size; | ||
1006 | if (!is_power_of_2(pages)) | ||
1007 | pages = rounddown_pow_of_two(pages); | ||
1004 | 1008 | ||
1005 | pages = (max * 1024) / page_size; | 1009 | return pages; |
1006 | if (!is_power_of_2(pages)) | 1010 | } |
1007 | pages = rounddown_pow_of_two(pages); | 1011 | |
1008 | } else if (!is_power_of_2(pages)) | 1012 | static size_t perf_evlist__mmap_size(unsigned long pages) |
1013 | { | ||
1014 | if (pages == UINT_MAX) | ||
1015 | pages = perf_event_mlock_kb_in_pages(); | ||
1016 | else if (!is_power_of_2(pages)) | ||
1009 | return 0; | 1017 | return 0; |
1010 | 1018 | ||
1011 | return (pages + 1) * page_size; | 1019 | return (pages + 1) * page_size; |
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index da46423998e8..208897a646ca 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h | |||
@@ -158,6 +158,8 @@ int perf_evlist__parse_mmap_pages(const struct option *opt, | |||
158 | const char *str, | 158 | const char *str, |
159 | int unset); | 159 | int unset); |
160 | 160 | ||
161 | unsigned long perf_event_mlock_kb_in_pages(void); | ||
162 | |||
161 | int perf_evlist__mmap_ex(struct perf_evlist *evlist, unsigned int pages, | 163 | int perf_evlist__mmap_ex(struct perf_evlist *evlist, unsigned int pages, |
162 | bool overwrite, unsigned int auxtrace_pages, | 164 | bool overwrite, unsigned int auxtrace_pages, |
163 | bool auxtrace_overwrite); | 165 | bool auxtrace_overwrite); |