Skip to content

Commit b09c236

Browse files
committed
perf record: Throttle user defined frequencies to the maximum allowed
# perf record -F 200000 sleep 1 warning: Maximum frequency rate (15,000 Hz) exceeded, throttling from 200,000 Hz to 15,000 Hz. The limit can be raised via /proc/sys/kernel/perf_event_max_sample_rate. The kernel will lower it when perf's interrupts take too long. Use --strict-freq to disable this throttling, refusing to record. [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.019 MB perf.data (15 samples) ] # perf evlist -v cycles:ppp: size: 112, { sample_period, sample_freq }: 15000, sample_type: IP|TID|TIME|PERIOD, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1, enable_on_exec: 1, task: 1, precise_ip: 3, sample_id_all: 1, exclude_guest: 1, mmap2: 1, comm_exec: 1 For those wanting that it fails if the desired frequency can't be used: # perf record --strict-freq -F 200000 sleep 1 error: Maximum frequency rate (15,000 Hz) exceeded. Please use -F freq option with a lower value or consider tweaking /proc/sys/kernel/perf_event_max_sample_rate. # Suggested-by: Ingo Molnar <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: David Ahern <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Wang Nan <[email protected]> Link: https://lkml.kernel.org/n/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 7831bf2 commit b09c236

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

tools/perf/Documentation/perf-record.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,16 @@ OPTIONS
191191
-i::
192192
--no-inherit::
193193
Child tasks do not inherit counters.
194+
194195
-F::
195196
--freq=::
196197
Profile at this frequency. Use 'max' to use the currently maximum
197198
allowed frequency, i.e. the value in the kernel.perf_event_max_sample_rate
198-
sysctl.
199+
sysctl. Will throttle down to the currently maximum allowed frequency.
200+
See --strict-freq.
201+
202+
--strict-freq::
203+
Fail if the specified frequency can't be used.
199204

200205
-m::
201206
--mmap-pages=::

tools/perf/builtin-record.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,6 +1543,8 @@ static struct option __record_options[] = {
15431543
OPT_BOOLEAN(0, "tail-synthesize", &record.opts.tail_synthesize,
15441544
"synthesize non-sample events at the end of output"),
15451545
OPT_BOOLEAN(0, "overwrite", &record.opts.overwrite, "use overwrite mode"),
1546+
OPT_BOOLEAN(0, "strict-freq", &record.opts.strict_freq,
1547+
"Fail if the specified frequency can't be used"),
15461548
OPT_CALLBACK('F', "freq", &record.opts, "freq or 'max'",
15471549
"profile at this frequency",
15481550
record__parse_freq),

tools/perf/perf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ struct record_opts {
6161
bool tail_synthesize;
6262
bool overwrite;
6363
bool ignore_missing_thread;
64+
bool strict_freq;
6465
unsigned int freq;
6566
unsigned int mmap_pages;
6667
unsigned int auxtrace_mmap_pages;

tools/perf/util/record.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,21 @@ static int record_opts__config_freq(struct record_opts *opts)
216216
* User specified frequency is over current maximum.
217217
*/
218218
if (user_freq && (max_rate < opts->freq)) {
219-
pr_err("Maximum frequency rate (%u) reached.\n"
220-
"Please use -F freq option with lower value or consider\n"
221-
"tweaking /proc/sys/kernel/perf_event_max_sample_rate.\n",
222-
max_rate);
223-
return -1;
219+
if (opts->strict_freq) {
220+
pr_err("error: Maximum frequency rate (%'u Hz) exceeded.\n"
221+
" Please use -F freq option with a lower value or consider\n"
222+
" tweaking /proc/sys/kernel/perf_event_max_sample_rate.\n",
223+
max_rate);
224+
return -1;
225+
} else {
226+
pr_warning("warning: Maximum frequency rate (%'u Hz) exceeded, throttling from %'u Hz to %'u Hz.\n"
227+
" The limit can be raised via /proc/sys/kernel/perf_event_max_sample_rate.\n"
228+
" The kernel will lower it when perf's interrupts take too long.\n"
229+
" Use --strict-freq to disable this throttling, refusing to record.\n",
230+
max_rate, opts->freq, max_rate);
231+
232+
opts->freq = max_rate;
233+
}
224234
}
225235

226236
/*

0 commit comments

Comments
 (0)