perf tools: No need to unconditionally read the max_stack sysctls
authorArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 17 May 2018 19:31:32 +0000 (16:31 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 17 May 2018 19:31:32 +0000 (16:31 -0300)
Let tools that need to have those variables with the sysctl current
values use a function that will read them.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: https://lkml.kernel.org/n/tip-1ljj3oeo5kpt2n1icfd9vowe@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-top.c
tools/perf/builtin-trace.c
tools/perf/perf.c
tools/perf/util/evsel.c
tools/perf/util/util.c
tools/perf/util/util.h

index 3c061c57afb67950b2dd6953b2a8a73571d1a354..7a349fcd38642c9cd9fb4c1f14b53fc45ff23871 100644 (file)
@@ -1264,7 +1264,7 @@ int cmd_top(int argc, const char **argv)
                        .proc_map_timeout    = 500,
                        .overwrite      = 1,
                },
-               .max_stack           = sysctl_perf_event_max_stack,
+               .max_stack           = sysctl__max_stack(),
                .sym_pcnt_filter     = 5,
                .nr_threads_synthesize = UINT_MAX,
        };
index c7effcfc40ed1c3649f0d12ac1df7fd62c10acb9..560aed7da36a44df845928d3b46c627e27cc71d3 100644 (file)
@@ -3162,7 +3162,7 @@ int cmd_trace(int argc, const char **argv)
                mmap_pages_user_set = false;
 
        if (trace.max_stack == UINT_MAX) {
-               trace.max_stack = input_name ? PERF_MAX_STACK_DEPTH : sysctl_perf_event_max_stack;
+               trace.max_stack = input_name ? PERF_MAX_STACK_DEPTH : sysctl__max_stack();
                max_stack_user_set = false;
        }
 
index cefd8f74630cfd1365444b44f128a0c28ce38725..51c81509a315ba26ce508a59ebafe5a9179559df 100644 (file)
@@ -426,7 +426,6 @@ int main(int argc, const char **argv)
        int err;
        const char *cmd;
        char sbuf[STRERR_BUFSIZE];
-       int value;
 
        /* libsubcmd init */
        exec_cmd_init("perf", PREFIX, PERF_EXEC_PATH, EXEC_PATH_ENVIRONMENT);
@@ -435,12 +434,6 @@ int main(int argc, const char **argv)
        /* The page_size is placed in util object. */
        page_size = sysconf(_SC_PAGE_SIZE);
 
-       if (sysctl__read_int("kernel/perf_event_max_stack", &value) == 0)
-               sysctl_perf_event_max_stack = value;
-
-       if (sysctl__read_int("kernel/perf_event_max_contexts_per_stack", &value) == 0)
-               sysctl_perf_event_max_contexts_per_stack = value;
-
        cmd = extract_argv0_path(argv[0]);
        if (!cmd)
                cmd = "perf-help";
index 4cd2cf93f7263e97307b69ec65d0e5c752be51fa..150db5ed7400e3ea374477e233b5255dff49215d 100644 (file)
@@ -2862,7 +2862,7 @@ int perf_evsel__open_strerror(struct perf_evsel *evsel, struct target *target,
                        return scnprintf(msg, size,
                                         "Not enough memory to setup event with callchain.\n"
                                         "Hint: Try tweaking /proc/sys/kernel/perf_event_max_stack\n"
-                                        "Hint: Current value: %d", sysctl_perf_event_max_stack);
+                                        "Hint: Current value: %d", sysctl__max_stack());
                break;
        case ENODEV:
                if (target->cpu_list)
index 99ab52165680749b085963a3bb92f41838fd85f1..eac5b858a3716426be8e900bd6587e54b860cd2c 100644 (file)
@@ -62,6 +62,19 @@ int cacheline_size(void)
 int sysctl_perf_event_max_stack = PERF_MAX_STACK_DEPTH;
 int sysctl_perf_event_max_contexts_per_stack = PERF_MAX_CONTEXTS_PER_STACK;
 
+int sysctl__max_stack(void)
+{
+       int value;
+
+       if (sysctl__read_int("kernel/perf_event_max_stack", &value) == 0)
+               sysctl_perf_event_max_stack = value;
+
+       if (sysctl__read_int("kernel/perf_event_max_contexts_per_stack", &value) == 0)
+               sysctl_perf_event_max_contexts_per_stack = value;
+
+       return sysctl_perf_event_max_stack;
+}
+
 bool test_attr__enabled;
 
 bool perf_host  = true;
index 74d21dfe0d2979dc4ab5ebeee9c4eb119ba98c49..dc58254a2b696a9ee38c384845481632ab25c236 100644 (file)
@@ -45,6 +45,8 @@ int hex2u64(const char *ptr, u64 *val);
 extern unsigned int page_size;
 int __pure cacheline_size(void);
 
+int sysctl__max_stack(void);
+
 int fetch_kernel_version(unsigned int *puint,
                         char *str, size_t str_sz);
 #define KVER_VERSION(x)                (((x) >> 16) & 0xff)