Skip to content

Commit

Permalink
perf tools: Introduce 'P' modifier to request max precision
Browse files Browse the repository at this point in the history
The 'P' will cause the event to get maximum possible detected precise
level.

Following record:
  $ perf record -e cycles:P ...

will detect maximum precise level for 'cycles' event and use it.

Commiter note:

Testing it:

  $ perf record -e cycles:P usleep 1
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 0.013 MB perf.data (9 samples) ]
  $ perf evlist
  cycles:P
  $ perf evlist -v
  cycles:P: size: 112, { sample_period, sample_freq }: 4000, sample_type:
  IP|TID|TIME|PERIOD, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1,
  enable_on_exec: 1, task: 1, precise_ip: 2, sample_id_all: 1, mmap2: 1,
  comm_exec: 1
  $

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Kan Liang <kan.liang@intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1444068369-20978-6-git-send-email-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
Jiri Olsa authored and Arnaldo Carvalho de Melo committed Oct 5, 2015
1 parent 45cf6c3 commit 7f94af7
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions tools/perf/Documentation/perf-list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ counted. The following modifiers exist:
G - guest counting (in KVM guests)
H - host counting (not in KVM guests)
p - precise level
P - use maximum detected precise level
S - read sample value (PERF_SAMPLE_READ)
D - pin the event to the PMU

Expand Down
3 changes: 3 additions & 0 deletions tools/perf/util/evsel.c
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,9 @@ void perf_evsel__config(struct perf_evsel *evsel, struct record_opts *opts)
attr->clockid = opts->clockid;
}

if (evsel->precise_max)
perf_event_attr__set_max_precise_ip(attr);

/*
* Apply event specific term settings,
* it overloads any global configuration.
Expand Down
1 change: 1 addition & 0 deletions tools/perf/util/evsel.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ struct perf_evsel {
bool system_wide;
bool tracking;
bool per_pkg;
bool precise_max;
/* parse modifier helper */
int exclude_GH;
int nr_members;
Expand Down
8 changes: 7 additions & 1 deletion tools/perf/util/parse-events.c
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,7 @@ struct event_modifier {
int eG;
int eI;
int precise;
int precise_max;
int exclude_GH;
int sample_read;
int pinned;
Expand All @@ -938,6 +939,7 @@ static int get_event_modifier(struct event_modifier *mod, char *str,
int eG = evsel ? evsel->attr.exclude_guest : 0;
int eI = evsel ? evsel->attr.exclude_idle : 0;
int precise = evsel ? evsel->attr.precise_ip : 0;
int precise_max = 0;
int sample_read = 0;
int pinned = evsel ? evsel->attr.pinned : 0;

Expand Down Expand Up @@ -974,6 +976,8 @@ static int get_event_modifier(struct event_modifier *mod, char *str,
/* use of precise requires exclude_guest */
if (!exclude_GH)
eG = 1;
} else if (*str == 'P') {
precise_max = 1;
} else if (*str == 'S') {
sample_read = 1;
} else if (*str == 'D') {
Expand Down Expand Up @@ -1004,6 +1008,7 @@ static int get_event_modifier(struct event_modifier *mod, char *str,
mod->eG = eG;
mod->eI = eI;
mod->precise = precise;
mod->precise_max = precise_max;
mod->exclude_GH = exclude_GH;
mod->sample_read = sample_read;
mod->pinned = pinned;
Expand All @@ -1020,7 +1025,7 @@ static int check_modifier(char *str)
char *p = str;

/* The sizeof includes 0 byte as well. */
if (strlen(str) > (sizeof("ukhGHpppSDI") - 1))
if (strlen(str) > (sizeof("ukhGHpppPSDI") - 1))
return -1;

while (*p) {
Expand Down Expand Up @@ -1059,6 +1064,7 @@ int parse_events__modifier_event(struct list_head *list, char *str, bool add)
evsel->attr.exclude_idle = mod.eI;
evsel->exclude_GH = mod.exclude_GH;
evsel->sample_read = mod.sample_read;
evsel->precise_max = mod.precise_max;

if (perf_evsel__is_group_leader(evsel))
evsel->attr.pinned = mod.pinned;
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/util/parse-events.l
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ num_raw_hex [a-fA-F0-9]+
name [a-zA-Z_*?][a-zA-Z0-9_*?.]*
name_minus [a-zA-Z_*?][a-zA-Z0-9\-_*?.]*
/* If you add a modifier you need to update check_modifier() */
modifier_event [ukhpGHSDI]+
modifier_event [ukhpPGHSDI]+
modifier_bp [rwx]{1,3}

%%
Expand Down

0 comments on commit 7f94af7

Please sign in to comment.