Skip to content

Commit e093a22

Browse files
Yang Jihongnamhyung
authored andcommitted
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 torvalds#160: FILE: tools/perf/util/rlimit.h:3: /* SPDX-License-Identifier: LGPL-2.1 */ No functional change. Signed-off-by: Yang Jihong <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Namhyung Kim <[email protected]>
1 parent 79a3371 commit e093a22

File tree

5 files changed

+42
-34
lines changed

5 files changed

+42
-34
lines changed

tools/perf/util/data.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include "util.h" // rm_rf_perf_data()
1818
#include "debug.h"
1919
#include "header.h"
20-
#include "evsel.h"
20+
#include "rlimit.h"
2121
#include <internal/lib.h>
2222

2323
static void close_dir(struct perf_data_file *files, int nr)
@@ -64,7 +64,7 @@ int perf_data__create_dir(struct perf_data *data, int nr)
6464
* perf record needs at least 6 fds per CPU.
6565
* When we run out of them try to increase the limits.
6666
*/
67-
if (errno == EMFILE && evsel__increase_rlimit(&set_rlimit))
67+
if (errno == EMFILE && rlimit__increase_nofile(&set_rlimit))
6868
goto retry_open;
6969

7070
ret = -errno;

tools/perf/util/evsel.c

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include "off_cpu.h"
5050
#include "pmu.h"
5151
#include "pmus.h"
52+
#include "rlimit.h"
5253
#include "../perf-sys.h"
5354
#include "util/parse-branch-options.h"
5455
#include "util/bpf-filter.h"
@@ -1989,33 +1990,6 @@ bool evsel__detect_missing_features(struct evsel *evsel)
19891990
}
19901991
}
19911992

1992-
bool evsel__increase_rlimit(enum rlimit_action *set_rlimit)
1993-
{
1994-
int old_errno;
1995-
struct rlimit l;
1996-
1997-
if (*set_rlimit < INCREASED_MAX) {
1998-
old_errno = errno;
1999-
2000-
if (getrlimit(RLIMIT_NOFILE, &l) == 0) {
2001-
if (*set_rlimit == NO_CHANGE) {
2002-
l.rlim_cur = l.rlim_max;
2003-
} else {
2004-
l.rlim_cur = l.rlim_max + 1000;
2005-
l.rlim_max = l.rlim_cur;
2006-
}
2007-
if (setrlimit(RLIMIT_NOFILE, &l) == 0) {
2008-
(*set_rlimit) += 1;
2009-
errno = old_errno;
2010-
return true;
2011-
}
2012-
}
2013-
errno = old_errno;
2014-
}
2015-
2016-
return false;
2017-
}
2018-
20191993
static int evsel__open_cpu(struct evsel *evsel, struct perf_cpu_map *cpus,
20201994
struct perf_thread_map *threads,
20211995
int start_cpu_map_idx, int end_cpu_map_idx)
@@ -2143,7 +2117,7 @@ static int evsel__open_cpu(struct evsel *evsel, struct perf_cpu_map *cpus,
21432117
* perf stat needs between 5 and 22 fds per CPU. When we run out
21442118
* of them try to increase the limits.
21452119
*/
2146-
if (err == -EMFILE && evsel__increase_rlimit(&set_rlimit))
2120+
if (err == -EMFILE && rlimit__increase_nofile(&set_rlimit))
21472121
goto retry_open;
21482122

21492123
if (err != -EINVAL || idx > 0 || thread > 0)

tools/perf/util/evsel.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,6 @@ int evsel__prepare_open(struct evsel *evsel, struct perf_cpu_map *cpus,
330330
struct perf_thread_map *threads);
331331
bool evsel__detect_missing_features(struct evsel *evsel);
332332

333-
enum rlimit_action { NO_CHANGE, SET_TO_MAX, INCREASED_MAX };
334-
bool evsel__increase_rlimit(enum rlimit_action *set_rlimit);
335-
336333
bool evsel__precise_ip_fallback(struct evsel *evsel);
337334

338335
struct perf_sample;

tools/perf/util/rlimit.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* SPDX-License-Identifier: LGPL-2.1 */
22

3+
#include <errno.h>
34
#include "util/debug.h"
45
#include "util/rlimit.h"
56
#include <sys/time.h>
@@ -27,3 +28,30 @@ void rlimit__bump_memlock(void)
2728
}
2829
}
2930
}
31+
32+
bool rlimit__increase_nofile(enum rlimit_action *set_rlimit)
33+
{
34+
int old_errno;
35+
struct rlimit l;
36+
37+
if (*set_rlimit < INCREASED_MAX) {
38+
old_errno = errno;
39+
40+
if (getrlimit(RLIMIT_NOFILE, &l) == 0) {
41+
if (*set_rlimit == NO_CHANGE) {
42+
l.rlim_cur = l.rlim_max;
43+
} else {
44+
l.rlim_cur = l.rlim_max + 1000;
45+
l.rlim_max = l.rlim_cur;
46+
}
47+
if (setrlimit(RLIMIT_NOFILE, &l) == 0) {
48+
(*set_rlimit) += 1;
49+
errno = old_errno;
50+
return true;
51+
}
52+
}
53+
errno = old_errno;
54+
}
55+
56+
return false;
57+
}

tools/perf/util/rlimit.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1+
/* SPDX-License-Identifier: LGPL-2.1 */
12
#ifndef __PERF_RLIMIT_H_
23
#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+
};
410

511
void rlimit__bump_memlock(void);
12+
13+
bool rlimit__increase_nofile(enum rlimit_action *set_rlimit);
14+
615
#endif // __PERF_RLIMIT_H_

0 commit comments

Comments
 (0)