diff --git a/tools/perf/tests/dso-data.c b/tools/perf/tests/dso-data.c index 8cf0d9e189a8bea36c02c965d74e216d29409089..13725e09ba22447ed97b498e6751a34c2a027cbf 100644 --- a/tools/perf/tests/dso-data.c +++ b/tools/perf/tests/dso-data.c @@ -251,6 +251,9 @@ int test__dso_data_cache(int subtest __maybe_unused) long nr_end, nr = open_files_cnt(); int dso_cnt, limit, i, fd; + /* Rest the internal dso open counter limit. */ + reset_fd_limit(); + memset(&machine, 0, sizeof(machine)); /* set as system limit */ @@ -312,6 +315,9 @@ int test__dso_data_reopen(int subtest __maybe_unused) #define dso_1 (dsos[1]) #define dso_2 (dsos[2]) + /* Rest the internal dso open counter limit. */ + reset_fd_limit(); + memset(&machine, 0, sizeof(machine)); /* diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c index 5d286f5d7906798a6ffe1e5e91b8a52bf4bc1973..e1de6cc4863e89f3b1979140eb9b0a0e7b3402e5 100644 --- a/tools/perf/util/dso.c +++ b/tools/perf/util/dso.c @@ -442,17 +442,27 @@ static rlim_t get_fd_limit(void) return limit; } -static bool may_cache_fd(void) +static rlim_t fd_limit; + +/* + * Used only by tests/dso-data.c to reset the environment + * for tests. I dont expect we should change this during + * standard runtime. + */ +void reset_fd_limit(void) { - static rlim_t limit; + fd_limit = 0; +} - if (!limit) - limit = get_fd_limit(); +static bool may_cache_fd(void) +{ + if (!fd_limit) + fd_limit = get_fd_limit(); - if (limit == RLIM_INFINITY) + if (fd_limit == RLIM_INFINITY) return true; - return limit > (rlim_t) dso__data_open_cnt; + return fd_limit > (rlim_t) dso__data_open_cnt; } /* diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h index 76d79d070e21e5e41ca31172d6b779b90586f734..a571f24895caa81e84266baee6c7b477016ec22c 100644 --- a/tools/perf/util/dso.h +++ b/tools/perf/util/dso.h @@ -360,4 +360,6 @@ enum dso_type dso__type(struct dso *dso, struct machine *machine); int dso__strerror_load(struct dso *dso, char *buf, size_t buflen); +void reset_fd_limit(void); + #endif /* __PERF_DSO */