evsel.c (d21fc5f077f7760bbae5742e185691718518f255) evsel.c (71efc48a4cbd208707b4ee4464b9eabd3b6438aa)
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Copyright (C) 2011, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
4 *
5 * Parts came from builtin-{top,stat,record}.c, see those files for further
6 * copyright notes.
7 */
8

--- 1917 unchanged lines hidden (view full) ---

1926 perf_missing_features.group_read = true;
1927 pr_debug2_peo("switching off group read\n");
1928 return true;
1929 } else {
1930 return false;
1931 }
1932}
1933
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Copyright (C) 2011, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
4 *
5 * Parts came from builtin-{top,stat,record}.c, see those files for further
6 * copyright notes.
7 */
8

--- 1917 unchanged lines hidden (view full) ---

1926 perf_missing_features.group_read = true;
1927 pr_debug2_peo("switching off group read\n");
1928 return true;
1929 } else {
1930 return false;
1931 }
1932}
1933
1934bool evsel__increase_rlimit(enum rlimit_action *set_rlimit)
1935{
1936 int old_errno;
1937 struct rlimit l;
1938
1939 if (*set_rlimit < INCREASED_MAX) {
1940 old_errno = errno;
1941
1942 if (getrlimit(RLIMIT_NOFILE, &l) == 0) {
1943 if (*set_rlimit == NO_CHANGE) {
1944 l.rlim_cur = l.rlim_max;
1945 } else {
1946 l.rlim_cur = l.rlim_max + 1000;
1947 l.rlim_max = l.rlim_cur;
1948 }
1949 if (setrlimit(RLIMIT_NOFILE, &l) == 0) {
1950 (*set_rlimit) += 1;
1951 errno = old_errno;
1952 return true;
1953 }
1954 }
1955 errno = old_errno;
1956 }
1957
1958 return false;
1959}
1960
1934static int evsel__open_cpu(struct evsel *evsel, struct perf_cpu_map *cpus,
1935 struct perf_thread_map *threads,
1936 int start_cpu, int end_cpu)
1937{
1938 int cpu, thread, nthreads;
1939 int pid = -1, err, old_errno;
1961static int evsel__open_cpu(struct evsel *evsel, struct perf_cpu_map *cpus,
1962 struct perf_thread_map *threads,
1963 int start_cpu, int end_cpu)
1964{
1965 int cpu, thread, nthreads;
1966 int pid = -1, err, old_errno;
1940 enum { NO_CHANGE, SET_TO_MAX, INCREASED_MAX } set_rlimit = NO_CHANGE;
1967 enum rlimit_action set_rlimit = NO_CHANGE;
1941
1942 err = __evsel__prepare_open(evsel, cpus, threads);
1943 if (err)
1944 return err;
1945
1946 if (cpus == NULL)
1947 cpus = empty_cpu_map;
1948

--- 92 unchanged lines hidden (view full) ---

2041
2042 return 0;
2043
2044try_fallback:
2045 /*
2046 * perf stat needs between 5 and 22 fds per CPU. When we run out
2047 * of them try to increase the limits.
2048 */
1968
1969 err = __evsel__prepare_open(evsel, cpus, threads);
1970 if (err)
1971 return err;
1972
1973 if (cpus == NULL)
1974 cpus = empty_cpu_map;
1975

--- 92 unchanged lines hidden (view full) ---

2068
2069 return 0;
2070
2071try_fallback:
2072 /*
2073 * perf stat needs between 5 and 22 fds per CPU. When we run out
2074 * of them try to increase the limits.
2075 */
2049 if (err == -EMFILE && set_rlimit < INCREASED_MAX) {
2050 struct rlimit l;
2076 if (err == -EMFILE && evsel__increase_rlimit(&set_rlimit))
2077 goto retry_open;
2051
2078
2052 old_errno = errno;
2053 if (getrlimit(RLIMIT_NOFILE, &l) == 0) {
2054 if (set_rlimit == NO_CHANGE)
2055 l.rlim_cur = l.rlim_max;
2056 else {
2057 l.rlim_cur = l.rlim_max + 1000;
2058 l.rlim_max = l.rlim_cur;
2059 }
2060 if (setrlimit(RLIMIT_NOFILE, &l) == 0) {
2061 set_rlimit++;
2062 errno = old_errno;
2063 goto retry_open;
2064 }
2065 }
2066 errno = old_errno;
2067 }
2068
2069 if (err != -EINVAL || cpu > 0 || thread > 0)
2070 goto out_close;
2071
2072 if (evsel__detect_missing_features(evsel))
2073 goto fallback_missing_features;
2074out_close:
2075 if (err)
2076 threads->err_thread = thread;

--- 844 unchanged lines hidden ---
2079 if (err != -EINVAL || cpu > 0 || thread > 0)
2080 goto out_close;
2081
2082 if (evsel__detect_missing_features(evsel))
2083 goto fallback_missing_features;
2084out_close:
2085 if (err)
2086 threads->err_thread = thread;

--- 844 unchanged lines hidden ---