perf tools: Add perf_event_max_sample_rate freq check
v2 cover perf tools: Add perf_event_max_sample_rate freq check
hi,
adding the check for maximum allowed frequency rate defined in perf_event_max_sample_rate.
Plus procfs mountpoint reading code. Reachable here:
git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
perf/max_rate
v2 changes:
naming changes suggested by Arnaldo in patch 1/3 patch 3/3:
- unify freq. config code for record and top
- add warning for default rate crossing the max
jirka
---
Jiri Olsa (3):
perf tools: Factor sysfs code into generic fs object perf tools: Add procfs support into fs object perf tools: Check maximum frequency rate for record/top
tools/perf/Makefile.perf | 4 ++-- tools/perf/builtin-record.c | 15 +----------- tools/perf/builtin-top.c | 15 +----------- tools/perf/tests/parse-events.c | 2 +- tools/perf/util/cpumap.c | 2 +- tools/perf/util/evlist.h | 1 + tools/perf/util/fs.c | 119 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/fs.h | 7 ++++++ tools/perf/util/include/linux/magic.h | 4 ++++ tools/perf/util/pmu.c | 2 +- tools/perf/util/python-ext-sources | 2 +- tools/perf/util/record.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/sysfs.c | 60 ----------------------------------------------- tools/perf/util/sysfs.h | 6 ----- 14 files changed, 211 insertions(+), 100 deletions(-) create mode 100644 tools/perf/util/fs.c create mode 100644 tools/perf/util/fs.h delete mode 100644 tools/perf/util/sysfs.c delete mode 100644 tools/perf/util/sysfs.h
PATCH v2 1/3 perf tools: Factor sysfs code into generic fs object
Moving sysfs code into generic fs object and preparing it to carry procfs support.
This should be merged with tools/lib/lk/debugfs.c at some point in the future.
--- tools/perf/Makefile.perf | 4 +- tools/perf/tests/parse-events.c | 2 +- tools/perf/util/cpumap.c | 2 +- tools/perf/util/fs.c | 107 +++++++++++++++++++++++++++++++++++++ tools/perf/util/fs.h | 6 +++ tools/perf/util/pmu.c | 2 +- tools/perf/util/python-ext-sources | 2 +- tools/perf/util/sysfs.c | 60 --------------------- tools/perf/util/sysfs.h | 6 --- 9 files changed, 119 insertions(+), 72 deletions(-) create mode 100644 tools/perf/util/fs.c create mode 100644 tools/perf/util/fs.h delete mode 100644 tools/perf/util/sysfs.c delete mode 100644 tools/perf/util/sysfs.h
tools/perf/Makefile.perf +2 -2
@@ -242,7 +242,7 @@ LIB_H += util/cache.h LIB_H += util/callchain.h LIB_H += util/build-id.h LIB_H += util/debug.h -LIB_H += util/sysfs.h +LIB_H += util/fs.h LIB_H += util/pmu.h LIB_H += util/event.h LIB_H += util/evsel.h
@@ -303,7 +303,7 @@ LIB_OBJS += $(OUTPUT)util/annotate.o LIB_OBJS += $(OUTPUT)util/build-id.o LIB_OBJS += $(OUTPUT)util/config.o LIB_OBJS += $(OUTPUT)util/ctype.o -LIB_OBJS += $(OUTPUT)util/sysfs.o +LIB_OBJS += $(OUTPUT)util/fs.o LIB_OBJS += $(OUTPUT)util/pmu.o LIB_OBJS += $(OUTPUT)util/environment.o LIB_OBJS += $(OUTPUT)util/event.o
tools/perf/tests/parse-events.c +1 -1
@@ -2,7 +2,7 @@#include "parse-events.h" #include "evsel.h" #include "evlist.h" -#include "sysfs.h" +#include "fs.h" #include <lk/debugfs.h> #include "tests.h" #include <linux/hw_breakpoint.h>
tools/perf/util/cpumap.c +1 -1
@@ -1,5 +1,5 @@#include "util.h" -#include "sysfs.h" +#include "fs.h" #include "../perf.h" #include "cpumap.h" #include <assert.h>
tools/perf/util/fs.c new file +107 -0
107 lines not on this page · raw message
tools/perf/util/fs.h new file +6 -0
@@ -0,0 +1,6 @@ +#ifndef __PERF_FS +#define __PERF_FS + +const char *sysfs_find_mountpoint (void ); + +#endif /* __PERF_FS */
tools/perf/util/pmu.c +1 -1
@@ -4,7 +4,7 @@#include <unistd.h> #include <stdio.h> #include <dirent.h> -#include "sysfs.h" +#include "fs.h" #include "util.h" #include "pmu.h" #include "parse-events.h"
tools/perf/util/python-ext-sources +1 -1
@@ -17,5 +17,5 @@ util/xyarray.c util/cgroup.c util/rblist.c util/strlist.c -util/sysfs.c +util/fs.c ../../lib/rbtree.c
tools/perf/util/sysfs.c deleted +0 -60
60 lines not on this page · raw message
tools/perf/util/sysfs.h deleted +0 -6
@@ -1,6 +0,0 @@ -#ifndef __SYSFS_H__ -#define __SYSFS_H__ - -const char *sysfs_find_mountpoint (void ); - -#endif /* __DEBUGFS_H__ */
Signature · 1 line
1.8.3.1
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf tools: Factor sysfs code into generic fs object
perf tools: Factor sysfs code into generic fs object
Commit-ID: 4299a549979783668d787959d61ba22b6b200877 Gitweb: http://git.kernel.org/tip/4299a549979783668d787959d61ba22b6b200877 Author: Jiri Olsa <[email protected]> AuthorDate: Tue, 5 Nov 2013 15:14:45 +0100 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Tue, 5 Nov 2013 14:44:26 -0300
perf tools: Factor sysfs code into generic fs object
Moving sysfs code into generic fs object and preparing it to carry procfs support.
This should be merged with tools/lib/lk/debugfs.c at some point in the future.
--- tools/perf/Makefile.perf | 4 +- tools/perf/tests/parse-events.c | 2 +- tools/perf/util/cpumap.c | 2 +- tools/perf/util/fs.c | 107 +++++++++++++++++++++++++++++++++++++ tools/perf/util/fs.h | 6 +++ tools/perf/util/pmu.c | 2 +- tools/perf/util/python-ext-sources | 2 +- tools/perf/util/sysfs.c | 60 --------------------- tools/perf/util/sysfs.h | 6 --- 9 files changed, 119 insertions(+), 72 deletions(-)
tools/perf/Makefile.perf +2 -2
@@ -242,7 +242,7 @@ LIB_H += util/cache.h LIB_H += util/callchain.h LIB_H += util/build-id.h LIB_H += util/debug.h -LIB_H += util/sysfs.h +LIB_H += util/fs.h LIB_H += util/pmu.h LIB_H += util/event.h LIB_H += util/evsel.h
@@ -304,7 +304,7 @@ LIB_OBJS += $(OUTPUT)util/annotate.o LIB_OBJS += $(OUTPUT)util/build-id.o LIB_OBJS += $(OUTPUT)util/config.o LIB_OBJS += $(OUTPUT)util/ctype.o -LIB_OBJS += $(OUTPUT)util/sysfs.o +LIB_OBJS += $(OUTPUT)util/fs.o LIB_OBJS += $(OUTPUT)util/pmu.o LIB_OBJS += $(OUTPUT)util/environment.o LIB_OBJS += $(OUTPUT)util/event.o
tools/perf/tests/parse-events.c +1 -1
@@ -2,7 +2,7 @@#include "parse-events.h" #include "evsel.h" #include "evlist.h" -#include "sysfs.h" +#include "fs.h" #include <lk/debugfs.h> #include "tests.h" #include <linux/hw_breakpoint.h>
tools/perf/util/cpumap.c +1 -1
@@ -1,5 +1,5 @@#include "util.h" -#include "sysfs.h" +#include "fs.h" #include "../perf.h" #include "cpumap.h" #include <assert.h>
tools/perf/util/fs.c new file +107 -0
107 lines not on this page · raw message
tools/perf/util/fs.h new file +6 -0
@@ -0,0 +1,6 @@ +#ifndef __PERF_FS +#define __PERF_FS + +const char *sysfs_find_mountpoint (void ); + +#endif /* __PERF_FS */
tools/perf/util/pmu.c +1 -1
@@ -4,7 +4,7 @@#include <unistd.h> #include <stdio.h> #include <dirent.h> -#include "sysfs.h" +#include "fs.h" #include "util.h" #include "pmu.h" #include "parse-events.h"
tools/perf/util/python-ext-sources +1 -1
@@ -17,5 +17,5 @@ util/xyarray.c util/cgroup.c util/rblist.c util/strlist.c -util/sysfs.c +util/fs.c ../../lib/rbtree.c
tools/perf/util/sysfs.c deleted +0 -60
60 lines not on this page · raw message
tools/perf/util/sysfs.h deleted +0 -6
@@ -1,6 +0,0 @@ -#ifndef __SYSFS_H__ -#define __SYSFS_H__ - -const char *sysfs_find_mountpoint (void ); - -#endif /* __DEBUGFS_H__ */
PATCH v2 2/3 perf tools: Add procfs support into fs object
In reply to Jiri OlsaAdding procfs support into fs object.
The interface function:
const char *procfs_find_mountpoint(void);
provides valid mountpoint path for procfs.
--- tools/perf/util/fs.c | 16 ++++++++++++++-- tools/perf/util/fs.h | 1 + tools/perf/util/include/linux/magic.h | 4 ++++ 3 files changed, 19 insertions(+), 2 deletions(-)
tools/perf/util/fs.c +14 -2
@@ -9,6 +9,11 @@ static const char * const sysfs_known_mountpoints[] = { 0, }; +static const char *const procfs_known_mountpoints[] = { +"/proc" , +0 , +}; +struct fs {const char *name;const char *const *mounts;
@@ -18,7 +23,8 @@ struct fs { };enum { -FS__SYSFS =0 , +FS__SYSFS =0 , +FS__PROCFS =1 , };static struct fs fs_entries[] = {
@@ -27,6 +33,11 @@ static struct fs fs_entries[] = { .mounts = sysfs_known_mountpoints, .magic = SYSFS_MAGIC, }, + [FS__PROCFS] = { + .name = "proc", + .mounts = procfs_known_mountpoints, + .magic = PROC_SUPER_MAGIC, + }, };static bool read_mounts (struct fs *fs)
@@ -104,4 +115,5 @@ const char *name##_find_mountpoint(void) \return find_mountpoint (idx); \ } -FIND_MOUNTPOINT (sysfs,FS__SYSFS ); +FIND_MOUNTPOINT (sysfs,FS__SYSFS ); +FIND_MOUNTPOINT (procfs,FS__PROCFS );
tools/perf/util/fs.h +1 -0
@@ -2,5 +2,6 @@#define __PERF_FSconst char *sysfs_find_mountpoint (void ); +const char *procfs_find_mountpoint (void );#endif /* __PERF_FS */
tools/perf/util/include/linux/magic.h +4 -0
@@ -9,4 +9,8 @@#define SYSFS_MAGIC 0x62656572#endif +#ifndef PROC_SUPER_MAGIC +#define PROC_SUPER_MAGIC 0x9fa0 +#endif +#endif
Signature · 1 line
1.8.3.1
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf fs: Add procfs support
perf fs: Add procfs support
Commit-ID: a9862418547e818aa5842840aecfa81d733b97e9 Gitweb: http://git.kernel.org/tip/a9862418547e818aa5842840aecfa81d733b97e9 Author: Jiri Olsa <[email protected]> AuthorDate: Tue, 5 Nov 2013 15:14:46 +0100 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Tue, 5 Nov 2013 15:15:07 -0300
perf fs: Add procfs support
Adding procfs support into fs class.
The interface function:
const char *procfs__mountpoint(void);
provides existing mountpoint path for procfs.
--- tools/perf/util/fs.c | 16 ++++++++++++++-- tools/perf/util/fs.h | 1 + tools/perf/util/include/linux/magic.h | 4 ++++ 3 files changed, 19 insertions(+), 2 deletions(-)
tools/perf/util/fs.c +14 -2
@@ -9,6 +9,11 @@ static const char * const sysfs__fs_known_mountpoints[] = { 0, }; +static const char *const procfs__known_mountpoints[] = { +"/proc" , +0 , +}; +struct fs {const char *name;const char *const *mounts;
@@ -18,7 +23,8 @@ struct fs { };enum { -FS__SYSFS =0 , +FS__SYSFS =0 , +FS__PROCFS =1 , };static struct fs fs__entries[] = {
@@ -27,6 +33,11 @@ static struct fs fs__entries[] = { .mounts = sysfs__fs_known_mountpoints, .magic = SYSFS_MAGIC, }, + [FS__PROCFS] = { + .name = "proc", + .mounts = procfs__known_mountpoints, + .magic = PROC_SUPER_MAGIC, + }, };static bool fs__read_mounts (struct fs *fs)
@@ -104,4 +115,5 @@ const char *name##__mountpoint(void) \return fs__mountpoint (idx); \ } -FS__MOUNTPOINT (sysfs,FS__SYSFS ); +FS__MOUNTPOINT (sysfs,FS__SYSFS ); +FS__MOUNTPOINT (procfs,FS__PROCFS );
tools/perf/util/fs.h +1 -0
@@ -2,5 +2,6 @@#define __PERF_FSconst char *sysfs__mountpoint (void ); +const char *procfs__mountpoint (void );#endif /* __PERF_FS */
tools/perf/util/include/linux/magic.h +4 -0
@@ -9,4 +9,8 @@#define SYSFS_MAGIC 0x62656572#endif +#ifndef PROC_SUPER_MAGIC +#define PROC_SUPER_MAGIC 0x9fa0 +#endif +#endif
PATCH v2 3/3 perf tools: Check maximum frequency rate for record/top
In reply to Jiri OlsaAdding the check for maximum allowed frequency rate defined in following file:
/proc/sys/kernel/perf_event_max_sample_rate
When we cross the maximum value we fail and display detailed error message with advise.
$ perf record -F 3000 ls Maximum frequency rate (2000) reached. Please use -F freq option with lower value or consider tweaking /proc/sys/kernel/perf_event_max_sample_rate.
In case user does not specify the frequency and the default value cross the maximum, we display warning and set the frequency value to the current maximum.
$ perf record ls Lowering default frequency rate to 2000. Please consider tweaking /proc/sys/kernel/perf_event_max_sample_rate.
Same messages are used for 'perf top'.
--- tools/perf/builtin-record.c | 15 +--------- tools/perf/builtin-top.c | 15 +--------- tools/perf/util/evlist.h | 1 + tools/perf/util/record.c | 72 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 75 insertions(+), 28 deletions(-)
tools/perf/builtin-record.c +1 -14
@@ -929,20 +929,7 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused)if (perf_evlist__create_maps (evsel_list, &rec->opts.target) <0 )usage_with_options (record_usage, record_options); -if (rec->opts.user_interval !=ULLONG_MAX ) - rec->opts.default_interval = rec->opts.user_interval; -if (rec->opts.user_freq !=UINT_MAX ) - rec->opts.freq = rec->opts.user_freq; - -/* -* User specified count overrides default frequency. -*/ -if (rec->opts.default_interval) - rec->opts.freq =0 ; -else if (rec->opts.freq) { - rec->opts.default_interval = rec->opts.freq; - }else { -ui__error ("frequency and count are zero, aborting\n" ); +if (perf_opts__config (&rec->opts)) { err = -EINVAL ; goto out_free_fd; }
tools/perf/builtin-top.c +1 -14
@@ -1203,20 +1203,7 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused)if (top.delay_secs <1 ) top.delay_secs =1 ; -if (opts->user_interval !=ULLONG_MAX ) - opts->default_interval = opts->user_interval; -if (opts->user_freq !=UINT_MAX ) - opts->freq = opts->user_freq; - -/* -* User specified count overrides default frequency. -*/ -if (opts->default_interval) - opts->freq =0 ; -else if (opts->freq) { - opts->default_interval = opts->freq; - }else { -ui__error ("frequency and count are zero, aborting\n" ); +if (perf_opts__config (opts)) { status = -EINVAL ; goto out_delete_maps; }
tools/perf/util/evlist.h +1 -0
@@ -99,6 +99,7 @@ void perf_evlist__set_id_pos(struct perf_evlist *evlist);bool perf_can_sample_identifier (void );void perf_evlist__config (struct perf_evlist *evlist,struct perf_record_opts *opts); +int perf_opts__config (struct perf_record_opts *opts); int perf_evlist__prepare_workload(struct perf_evlist *evlist, struct perf_target *target,
tools/perf/util/record.c +72 -0
81 lines not on this page · raw message
Signature · 1 line
1.8.3.1
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf tools: Check maximum frequency rate for record/top
perf tools: Check maximum frequency rate for record/top
Commit-ID: 714647bdc516330e4405b39677d7f763e016c685 Gitweb: http://git.kernel.org/tip/714647bdc516330e4405b39677d7f763e016c685 Author: Jiri Olsa <[email protected]> AuthorDate: Tue, 5 Nov 2013 15:14:47 +0100 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Tue, 5 Nov 2013 15:15:08 -0300
perf tools: Check maximum frequency rate for record/top
Adding the check for maximum allowed frequency rate defined in following file:
/proc/sys/kernel/perf_event_max_sample_rate
When we cross the maximum value we fail and display detailed error message with advise.
$ perf record -F 3000 ls Maximum frequency rate (2000) reached. Please use -F freq option with lower value or consider tweaking /proc/sys/kernel/perf_event_max_sample_rate.
In case user does not specify the frequency and the default value cross the maximum, we display warning and set the frequency value to the current maximum.
$ perf record ls Lowering default frequency rate to 2000. Please consider tweaking /proc/sys/kernel/perf_event_max_sample_rate.
Same messages are used for 'perf top'.
--- tools/perf/builtin-record.c | 15 +--------- tools/perf/builtin-top.c | 15 +--------- tools/perf/util/evlist.h | 1 + tools/perf/util/record.c | 71 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 74 insertions(+), 28 deletions(-)
tools/perf/builtin-record.c +1 -14
@@ -958,20 +958,7 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused)if (perf_evlist__create_maps (evsel_list, &rec->opts.target) <0 )usage_with_options (record_usage, record_options); -if (rec->opts.user_interval !=ULLONG_MAX ) - rec->opts.default_interval = rec->opts.user_interval; -if (rec->opts.user_freq !=UINT_MAX ) - rec->opts.freq = rec->opts.user_freq; - -/* -* User specified count overrides default frequency. -*/ -if (rec->opts.default_interval) - rec->opts.freq =0 ; -else if (rec->opts.freq) { - rec->opts.default_interval = rec->opts.freq; - }else { -ui__error ("frequency and count are zero, aborting\n" ); +if (perf_record_opts__config (&rec->opts)) { err = -EINVAL ; goto out_free_fd; }
tools/perf/builtin-top.c +1 -14
@@ -1209,20 +1209,7 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused)if (top.delay_secs <1 ) top.delay_secs =1 ; -if (opts->user_interval !=ULLONG_MAX ) - opts->default_interval = opts->user_interval; -if (opts->user_freq !=UINT_MAX ) - opts->freq = opts->user_freq; - -/* -* User specified count overrides default frequency. -*/ -if (opts->default_interval) - opts->freq =0 ; -else if (opts->freq) { - opts->default_interval = opts->freq; - }else { -ui__error ("frequency and count are zero, aborting\n" ); +if (perf_record_opts__config (opts)) { status = -EINVAL ; goto out_delete_maps; }
tools/perf/util/evlist.h +1 -0
@@ -99,6 +99,7 @@ void perf_evlist__set_id_pos(struct perf_evlist *evlist);bool perf_can_sample_identifier (void );void perf_evlist__config (struct perf_evlist *evlist,struct perf_record_opts *opts); +int perf_record_opts__config (struct perf_record_opts *opts); int perf_evlist__prepare_workload(struct perf_evlist *evlist, struct perf_target *target,
tools/perf/util/record.c +71 -0
80 lines not on this page · raw message