Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

perf lock: Dynamically allocate lockhash_table

lockhash_table is 32,768 bytes in .bss, make it a memory allocation so
that the space is freed for non-lock perf commands.

Signed-off-by: Ian Rogers <irogers@google.com>
Link: https://lore.kernel.org/r/20230526183401.2326121-10-irogers@google.com
Cc: K Prateek Nayak <kprateek.nayak@amd.com>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Ross Zwisler <zwisler@chromium.org>
Cc: Steven Rostedt (Google) <rostedt@goodmis.org>
Cc: Sean Christopherson <seanjc@google.com>
Cc: Yang Jihong <yangjihong1@huawei.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Tiezhu Yang <yangtiezhu@loongson.cn>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: linux-kernel@vger.kernel.org
Cc: linux-perf-users@vger.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Ian Rogers and committed by
Arnaldo Carvalho de Melo
eef4fee5 92294b90

+16 -4
+16 -4
tools/perf/builtin-lock.c
··· 48 48 #define LOCKHASH_BITS 12 49 49 #define LOCKHASH_SIZE (1UL << LOCKHASH_BITS) 50 50 51 - static struct hlist_head lockhash_table[LOCKHASH_SIZE]; 51 + static struct hlist_head *lockhash_table; 52 52 53 53 #define __lockhashfn(key) hash_long((unsigned long)key, LOCKHASH_BITS) 54 54 #define lockhashentry(key) (lockhash_table + __lockhashfn((key))) ··· 1871 1871 }; 1872 1872 struct lock_contention con = { 1873 1873 .target = &target, 1874 - .result = &lockhash_table[0], 1875 1874 .map_nr_entries = bpf_map_entries, 1876 1875 .max_stack = max_stack_depth, 1877 1876 .stack_skip = stack_skip, ··· 1879 1880 .owner = show_lock_owner, 1880 1881 }; 1881 1882 1883 + lockhash_table = calloc(LOCKHASH_SIZE, sizeof(*lockhash_table)); 1884 + if (!lockhash_table) 1885 + return -ENOMEM; 1886 + 1887 + con.result = &lockhash_table[0]; 1888 + 1882 1889 session = perf_session__new(use_bpf ? NULL : &data, &eops); 1883 1890 if (IS_ERR(session)) { 1884 1891 pr_err("Initializing perf session failed\n"); 1885 - return PTR_ERR(session); 1892 + err = PTR_ERR(session); 1893 + goto out_delete; 1886 1894 } 1887 1895 1888 1896 con.machine = &session->machines.host; ··· 1989 1983 evlist__delete(con.evlist); 1990 1984 lock_contention_finish(); 1991 1985 perf_session__delete(session); 1986 + zfree(&lockhash_table); 1992 1987 return err; 1993 1988 } 1994 1989 ··· 2355 2348 unsigned int i; 2356 2349 int rc = 0; 2357 2350 2351 + lockhash_table = calloc(LOCKHASH_SIZE, sizeof(*lockhash_table)); 2352 + if (!lockhash_table) 2353 + return -ENOMEM; 2354 + 2358 2355 for (i = 0; i < LOCKHASH_SIZE; i++) 2359 2356 INIT_HLIST_HEAD(lockhash_table + i); 2360 2357 ··· 2380 2369 rc = __cmd_report(false); 2381 2370 } else if (!strcmp(argv[0], "script")) { 2382 2371 /* Aliased to 'perf script' */ 2383 - return cmd_script(argc, argv); 2372 + rc = cmd_script(argc, argv); 2384 2373 } else if (!strcmp(argv[0], "info")) { 2385 2374 if (argc) { 2386 2375 argc = parse_options(argc, argv, ··· 2414 2403 usage_with_options(lock_usage, lock_options); 2415 2404 } 2416 2405 2406 + zfree(&lockhash_table); 2417 2407 return rc; 2418 2408 }