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

perf evsel: Rename evsel__increase_rlimit to rlimit__increase_nofile

evsel__increase_rlimit() helper does nothing with evsel, and description
of the functionality is inaccurate, rename it and move to util/rlimit.c.

By the way, fix a checkppatch warning about misplaced license tag:

WARNING: Misplaced SPDX-License-Identifier tag - use line 1 instead
#160: FILE: tools/perf/util/rlimit.h:3:
/* SPDX-License-Identifier: LGPL-2.1 */

No functional change.

Signed-off-by: Yang Jihong <yangjihong1@huawei.com>
Link: https://lore.kernel.org/r/20231023033144.1011896-1-yangjihong1@huawei.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>

authored by

Yang Jihong and committed by
Namhyung Kim
e093a222 79a3371b

+42 -34
+2 -2
tools/perf/util/data.c
··· 17 17 #include "util.h" // rm_rf_perf_data() 18 18 #include "debug.h" 19 19 #include "header.h" 20 - #include "evsel.h" 20 + #include "rlimit.h" 21 21 #include <internal/lib.h> 22 22 23 23 static void close_dir(struct perf_data_file *files, int nr) ··· 64 64 * perf record needs at least 6 fds per CPU. 65 65 * When we run out of them try to increase the limits. 66 66 */ 67 - if (errno == EMFILE && evsel__increase_rlimit(&set_rlimit)) 67 + if (errno == EMFILE && rlimit__increase_nofile(&set_rlimit)) 68 68 goto retry_open; 69 69 70 70 ret = -errno;
+2 -28
tools/perf/util/evsel.c
··· 49 49 #include "off_cpu.h" 50 50 #include "pmu.h" 51 51 #include "pmus.h" 52 + #include "rlimit.h" 52 53 #include "../perf-sys.h" 53 54 #include "util/parse-branch-options.h" 54 55 #include "util/bpf-filter.h" ··· 1990 1989 } 1991 1990 } 1992 1991 1993 - bool evsel__increase_rlimit(enum rlimit_action *set_rlimit) 1994 - { 1995 - int old_errno; 1996 - struct rlimit l; 1997 - 1998 - if (*set_rlimit < INCREASED_MAX) { 1999 - old_errno = errno; 2000 - 2001 - if (getrlimit(RLIMIT_NOFILE, &l) == 0) { 2002 - if (*set_rlimit == NO_CHANGE) { 2003 - l.rlim_cur = l.rlim_max; 2004 - } else { 2005 - l.rlim_cur = l.rlim_max + 1000; 2006 - l.rlim_max = l.rlim_cur; 2007 - } 2008 - if (setrlimit(RLIMIT_NOFILE, &l) == 0) { 2009 - (*set_rlimit) += 1; 2010 - errno = old_errno; 2011 - return true; 2012 - } 2013 - } 2014 - errno = old_errno; 2015 - } 2016 - 2017 - return false; 2018 - } 2019 - 2020 1992 static int evsel__open_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, 2021 1993 struct perf_thread_map *threads, 2022 1994 int start_cpu_map_idx, int end_cpu_map_idx) ··· 2117 2143 * perf stat needs between 5 and 22 fds per CPU. When we run out 2118 2144 * of them try to increase the limits. 2119 2145 */ 2120 - if (err == -EMFILE && evsel__increase_rlimit(&set_rlimit)) 2146 + if (err == -EMFILE && rlimit__increase_nofile(&set_rlimit)) 2121 2147 goto retry_open; 2122 2148 2123 2149 if (err != -EINVAL || idx > 0 || thread > 0)
-3
tools/perf/util/evsel.h
··· 330 330 struct perf_thread_map *threads); 331 331 bool evsel__detect_missing_features(struct evsel *evsel); 332 332 333 - enum rlimit_action { NO_CHANGE, SET_TO_MAX, INCREASED_MAX }; 334 - bool evsel__increase_rlimit(enum rlimit_action *set_rlimit); 335 - 336 333 bool evsel__precise_ip_fallback(struct evsel *evsel); 337 334 338 335 struct perf_sample;
+28
tools/perf/util/rlimit.c
··· 1 1 /* SPDX-License-Identifier: LGPL-2.1 */ 2 2 3 + #include <errno.h> 3 4 #include "util/debug.h" 4 5 #include "util/rlimit.h" 5 6 #include <sys/time.h> ··· 27 26 pr_debug("Couldn't bump rlimit(MEMLOCK), failures may take place when creating BPF maps, etc\n"); 28 27 } 29 28 } 29 + } 30 + 31 + bool rlimit__increase_nofile(enum rlimit_action *set_rlimit) 32 + { 33 + int old_errno; 34 + struct rlimit l; 35 + 36 + if (*set_rlimit < INCREASED_MAX) { 37 + old_errno = errno; 38 + 39 + if (getrlimit(RLIMIT_NOFILE, &l) == 0) { 40 + if (*set_rlimit == NO_CHANGE) { 41 + l.rlim_cur = l.rlim_max; 42 + } else { 43 + l.rlim_cur = l.rlim_max + 1000; 44 + l.rlim_max = l.rlim_cur; 45 + } 46 + if (setrlimit(RLIMIT_NOFILE, &l) == 0) { 47 + (*set_rlimit) += 1; 48 + errno = old_errno; 49 + return true; 50 + } 51 + } 52 + errno = old_errno; 53 + } 54 + 55 + return false; 30 56 }
+10 -1
tools/perf/util/rlimit.h
··· 1 + /* SPDX-License-Identifier: LGPL-2.1 */ 1 2 #ifndef __PERF_RLIMIT_H_ 2 3 #define __PERF_RLIMIT_H_ 3 - /* SPDX-License-Identifier: LGPL-2.1 */ 4 + 5 + enum rlimit_action { 6 + NO_CHANGE, 7 + SET_TO_MAX, 8 + INCREASED_MAX 9 + }; 4 10 5 11 void rlimit__bump_memlock(void); 12 + 13 + bool rlimit__increase_nofile(enum rlimit_action *set_rlimit); 14 + 6 15 #endif // __PERF_RLIMIT_H_