From: Jiri Olsa <jolsa@redhat.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>,
Ian Rogers <irogers@google.com>,
linux-perf-users@vger.kernel.org
Subject: [PATCH 38/59] libperf: Move in parse_events__modifier_group/event functions
Date: Mon, 8 Nov 2021 14:36:49 +0100 [thread overview]
Message-ID: <20211108133710.1352822-39-jolsa@kernel.org> (raw)
In-Reply-To: <20211108133710.1352822-1-jolsa@kernel.org>
Moving parse_events__modifier_group/event functions to libperf.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
.../lib/perf/include/internal/parse-events.h | 2 +
tools/lib/perf/parse-events.c | 187 ++++++++++++++++++
tools/perf/util/parse-events.c | 186 -----------------
tools/perf/util/parse-events.h | 2 -
4 files changed, 189 insertions(+), 188 deletions(-)
diff --git a/tools/lib/perf/include/internal/parse-events.h b/tools/lib/perf/include/internal/parse-events.h
index e4b136a58484..88195ae2eb10 100644
--- a/tools/lib/perf/include/internal/parse-events.h
+++ b/tools/lib/perf/include/internal/parse-events.h
@@ -130,4 +130,6 @@ perf_evsel__add_event(struct parse_events_state *parse_state,
const char *name, const char *metric_id, struct perf_pmu *pmu,
struct list_head *config_terms, bool auto_merge_stats,
const char *cpu_list);
+int parse_events__modifier_event(struct list_head *list, char *str, bool add, bool guest);
+int parse_events__modifier_group(struct list_head *list, char *event_mod, bool guest);
#endif /* __LIBPERF_PARSE_EVENTS_H */
diff --git a/tools/lib/perf/parse-events.c b/tools/lib/perf/parse-events.c
index 6d840764c84d..3b93528f4569 100644
--- a/tools/lib/perf/parse-events.c
+++ b/tools/lib/perf/parse-events.c
@@ -6,6 +6,7 @@
#include <string.h>
#include <internal/parse-events.h>
#include <internal/pmu.h>
+#include <internal/evlist.h>
#include <internal/evsel.h>
#include <perf/cpumap.h>
#include <stdlib.h>
@@ -349,3 +350,189 @@ perf_evsel__add_event(struct parse_events_state *parse_state,
return evsel;
}
+
+struct event_modifier {
+ int eu;
+ int ek;
+ int eh;
+ int eH;
+ int eG;
+ int eI;
+ int precise;
+ int precise_max;
+ int exclude_GH;
+ int sample_read;
+ int pinned;
+ int weak;
+ int exclusive;
+ int bpf_counter;
+};
+
+static int get_event_modifier(struct event_modifier *mod, char *str,
+ struct perf_evsel *evsel, bool guest)
+{
+ int eu = evsel ? evsel->attr.exclude_user : 0;
+ int ek = evsel ? evsel->attr.exclude_kernel : 0;
+ int eh = evsel ? evsel->attr.exclude_hv : 0;
+ int eH = evsel ? evsel->attr.exclude_host : 0;
+ 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;
+ int exclusive = evsel ? evsel->attr.exclusive : 0;
+
+ int exclude = eu | ek | eh;
+ int exclude_GH = evsel ? evsel->exclude_GH : 0;
+ int weak = 0;
+ int bpf_counter = 0;
+
+ memset(mod, 0, sizeof(*mod));
+
+ while (*str) {
+ if (*str == 'u') {
+ if (!exclude)
+ exclude = eu = ek = eh = 1;
+ if (!exclude_GH && !guest)
+ eG = 1;
+ eu = 0;
+ } else if (*str == 'k') {
+ if (!exclude)
+ exclude = eu = ek = eh = 1;
+ ek = 0;
+ } else if (*str == 'h') {
+ if (!exclude)
+ exclude = eu = ek = eh = 1;
+ eh = 0;
+ } else if (*str == 'G') {
+ if (!exclude_GH)
+ exclude_GH = eG = eH = 1;
+ eG = 0;
+ } else if (*str == 'H') {
+ if (!exclude_GH)
+ exclude_GH = eG = eH = 1;
+ eH = 0;
+ } else if (*str == 'I') {
+ eI = 1;
+ } else if (*str == 'p') {
+ precise++;
+ /* 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') {
+ pinned = 1;
+ } else if (*str == 'e') {
+ exclusive = 1;
+ } else if (*str == 'W') {
+ weak = 1;
+ } else if (*str == 'b') {
+ bpf_counter = 1;
+ } else
+ break;
+
+ ++str;
+ }
+
+ /*
+ * precise ip:
+ *
+ * 0 - SAMPLE_IP can have arbitrary skid
+ * 1 - SAMPLE_IP must have constant skid
+ * 2 - SAMPLE_IP requested to have 0 skid
+ * 3 - SAMPLE_IP must have 0 skid
+ *
+ * See also PERF_RECORD_MISC_EXACT_IP
+ */
+ if (precise > 3)
+ return -EINVAL;
+
+ mod->eu = eu;
+ mod->ek = ek;
+ mod->eh = eh;
+ mod->eH = eH;
+ 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;
+ mod->weak = weak;
+ mod->bpf_counter = bpf_counter;
+ mod->exclusive = exclusive;
+
+ return 0;
+}
+
+/*
+ * Basic modifier sanity check to validate it contains only one
+ * instance of any modifier (apart from 'p') present.
+ */
+static int check_modifier(char *str)
+{
+ char *p = str;
+
+ /* The sizeof includes 0 byte as well. */
+ if (strlen(str) > (sizeof("ukhGHpppPSDIWeb") - 1))
+ return -1;
+
+ while (*p) {
+ if (*p != 'p' && strchr(p + 1, *p))
+ return -1;
+ p++;
+ }
+
+ return 0;
+}
+
+int parse_events__modifier_event(struct list_head *list, char *str,
+ bool add, bool guest)
+{
+ struct perf_evsel *evsel;
+ struct event_modifier mod;
+
+ if (str == NULL)
+ return 0;
+
+ if (check_modifier(str))
+ return -EINVAL;
+
+ if (!add && get_event_modifier(&mod, str, NULL, guest))
+ return -EINVAL;
+
+ __perf_evlist__for_each_entry(list, evsel) {
+ if (add && get_event_modifier(&mod, str, evsel, guest))
+ return -EINVAL;
+
+ evsel->attr.exclude_user = mod.eu;
+ evsel->attr.exclude_kernel = mod.ek;
+ evsel->attr.exclude_hv = mod.eh;
+ evsel->attr.precise_ip = mod.precise;
+ evsel->attr.exclude_host = mod.eH;
+ evsel->attr.exclude_guest = mod.eG;
+ evsel->attr.exclude_idle = mod.eI;
+ evsel->exclude_GH = mod.exclude_GH;
+ evsel->sample_read = mod.sample_read;
+ evsel->precise_max = mod.precise_max;
+ evsel->weak_group = mod.weak;
+ evsel->bpf_counter = mod.bpf_counter;
+
+ if (perf_evsel__is_group_leader(evsel)) {
+ evsel->attr.pinned = mod.pinned;
+ evsel->attr.exclusive = mod.exclusive;
+ }
+ }
+
+ return 0;
+}
+
+int parse_events__modifier_group(struct list_head *list,
+ char *event_mod, bool guest)
+{
+ return parse_events__modifier_event(list, event_mod, true, guest);
+}
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index e10f6476854f..ecbb7f284158 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -1617,12 +1617,6 @@ int parse_events_multi_pmu_add(struct parse_events_state *parse_state,
return ok ? 0 : -1;
}
-int parse_events__modifier_group(struct list_head *list,
- char *event_mod, bool guest)
-{
- return parse_events__modifier_event(list, event_mod, true, guest);
-}
-
/*
* Check if the two uncore PMUs are from the same uncore block
* The format of the uncore PMU name is uncore_#blockname_#pmuidx
@@ -1752,186 +1746,6 @@ void parse_events__set_leader(char *name, struct list_head *list,
leader->core.group_name = name ? strdup(name) : NULL;
}
-struct event_modifier {
- int eu;
- int ek;
- int eh;
- int eH;
- int eG;
- int eI;
- int precise;
- int precise_max;
- int exclude_GH;
- int sample_read;
- int pinned;
- int weak;
- int exclusive;
- int bpf_counter;
-};
-
-static int get_event_modifier(struct event_modifier *mod, char *str,
- struct perf_evsel *evsel, bool guest)
-{
- int eu = evsel ? evsel->attr.exclude_user : 0;
- int ek = evsel ? evsel->attr.exclude_kernel : 0;
- int eh = evsel ? evsel->attr.exclude_hv : 0;
- int eH = evsel ? evsel->attr.exclude_host : 0;
- 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;
- int exclusive = evsel ? evsel->attr.exclusive : 0;
-
- int exclude = eu | ek | eh;
- int exclude_GH = evsel ? evsel->exclude_GH : 0;
- int weak = 0;
- int bpf_counter = 0;
-
- memset(mod, 0, sizeof(*mod));
-
- while (*str) {
- if (*str == 'u') {
- if (!exclude)
- exclude = eu = ek = eh = 1;
- if (!exclude_GH && !guest)
- eG = 1;
- eu = 0;
- } else if (*str == 'k') {
- if (!exclude)
- exclude = eu = ek = eh = 1;
- ek = 0;
- } else if (*str == 'h') {
- if (!exclude)
- exclude = eu = ek = eh = 1;
- eh = 0;
- } else if (*str == 'G') {
- if (!exclude_GH)
- exclude_GH = eG = eH = 1;
- eG = 0;
- } else if (*str == 'H') {
- if (!exclude_GH)
- exclude_GH = eG = eH = 1;
- eH = 0;
- } else if (*str == 'I') {
- eI = 1;
- } else if (*str == 'p') {
- precise++;
- /* 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') {
- pinned = 1;
- } else if (*str == 'e') {
- exclusive = 1;
- } else if (*str == 'W') {
- weak = 1;
- } else if (*str == 'b') {
- bpf_counter = 1;
- } else
- break;
-
- ++str;
- }
-
- /*
- * precise ip:
- *
- * 0 - SAMPLE_IP can have arbitrary skid
- * 1 - SAMPLE_IP must have constant skid
- * 2 - SAMPLE_IP requested to have 0 skid
- * 3 - SAMPLE_IP must have 0 skid
- *
- * See also PERF_RECORD_MISC_EXACT_IP
- */
- if (precise > 3)
- return -EINVAL;
-
- mod->eu = eu;
- mod->ek = ek;
- mod->eh = eh;
- mod->eH = eH;
- 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;
- mod->weak = weak;
- mod->bpf_counter = bpf_counter;
- mod->exclusive = exclusive;
-
- return 0;
-}
-
-/*
- * Basic modifier sanity check to validate it contains only one
- * instance of any modifier (apart from 'p') present.
- */
-static int check_modifier(char *str)
-{
- char *p = str;
-
- /* The sizeof includes 0 byte as well. */
- if (strlen(str) > (sizeof("ukhGHpppPSDIWeb") - 1))
- return -1;
-
- while (*p) {
- if (*p != 'p' && strchr(p + 1, *p))
- return -1;
- p++;
- }
-
- return 0;
-}
-
-int parse_events__modifier_event(struct list_head *list, char *str,
- bool add, bool guest)
-{
- struct perf_evsel *evsel;
- struct event_modifier mod;
-
- if (str == NULL)
- return 0;
-
- if (check_modifier(str))
- return -EINVAL;
-
- if (!add && get_event_modifier(&mod, str, NULL, guest))
- return -EINVAL;
-
- __perf_evlist__for_each_entry(list, evsel) {
- if (add && get_event_modifier(&mod, str, evsel, guest))
- return -EINVAL;
-
- evsel->attr.exclude_user = mod.eu;
- evsel->attr.exclude_kernel = mod.ek;
- evsel->attr.exclude_hv = mod.eh;
- evsel->attr.precise_ip = mod.precise;
- evsel->attr.exclude_host = mod.eH;
- evsel->attr.exclude_guest = mod.eG;
- evsel->attr.exclude_idle = mod.eI;
- evsel->exclude_GH = mod.exclude_GH;
- evsel->sample_read = mod.sample_read;
- evsel->precise_max = mod.precise_max;
- evsel->weak_group = mod.weak;
- evsel->bpf_counter = mod.bpf_counter;
-
- if (perf_evsel__is_group_leader(evsel)) {
- evsel->attr.pinned = mod.pinned;
- evsel->attr.exclusive = mod.exclusive;
- }
- }
-
- return 0;
-}
-
int parse_events_name(struct list_head *list, const char *name)
{
struct evsel *evsel;
diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h
index 599ee3a760d7..78a8fa799b09 100644
--- a/tools/perf/util/parse-events.h
+++ b/tools/perf/util/parse-events.h
@@ -65,8 +65,6 @@ void parse_events__handle_error(struct parse_events_error *err, int idx,
char *str, char *help);
void parse_events__shrink_config_terms(void);
void parse_events__clear_array(struct parse_events_array *a);
-int parse_events__modifier_event(struct list_head *list, char *str, bool add, bool guest);
-int parse_events__modifier_group(struct list_head *list, char *event_mod, bool guest);
int parse_events_name(struct list_head *list, const char *name);
int parse_events_add_tracepoint(struct parse_events_state *parse_state,
struct list_head *list,
--
2.31.1
next prev parent reply other threads:[~2021-11-08 13:41 UTC|newest]
Thread overview: 78+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-08 13:36 [RFC 00/59] libperf: Move in event parse code Jiri Olsa
2021-11-08 13:36 ` [PATCH 01/59] libperf: Move pmu-events.h file to libperf Jiri Olsa
2021-11-08 13:36 ` [PATCH 03/59] libperf: Move pmu-events build " Jiri Olsa
2021-11-08 13:36 ` [PATCH 04/59] libperf: Move perf_pmu__format_parse " Jiri Olsa
2021-11-08 13:36 ` [PATCH 05/59] tools api fs: Move in the fncache from perf Jiri Olsa
2021-11-08 17:46 ` Ian Rogers
2021-11-08 21:15 ` Jiri Olsa
2021-11-08 13:36 ` [PATCH 06/59] libperf: Move in the pmu hybrid support Jiri Olsa
2021-11-08 13:36 ` [PATCH 07/59] libperf: Move name to perf_evsel Jiri Olsa
2021-11-08 13:36 ` [PATCH 08/59] libperf: Move auto_merge_stats " Jiri Olsa
2021-11-08 13:36 ` [PATCH 09/59] libperf: Move config_terms " Jiri Olsa
2021-11-08 13:36 ` [PATCH 10/59] libperf: Move metric_id " Jiri Olsa
2021-11-08 13:36 ` [PATCH 11/59] libperf: Move tool_event " Jiri Olsa
2021-11-08 13:36 ` [PATCH 12/59] libperf: Move unit " Jiri Olsa
2021-11-08 13:36 ` [PATCH 13/59] libperf: Move exclude_GH " Jiri Olsa
2021-11-08 17:53 ` Ian Rogers
2021-11-08 21:16 ` Jiri Olsa
2021-11-08 13:36 ` [PATCH 14/59] libperf: Move sample_read " Jiri Olsa
2021-11-08 13:36 ` [PATCH 15/59] libperf: Move precise_max " Jiri Olsa
2021-11-08 13:36 ` [PATCH 16/59] libperf: Move weak_group " Jiri Olsa
2021-11-08 13:36 ` [PATCH 17/59] libperf: Move bpf_counter " Jiri Olsa
2021-11-08 13:36 ` [PATCH 18/59] libperf: Move group_name " Jiri Olsa
2021-11-08 17:58 ` Ian Rogers
2021-11-08 18:07 ` Arnaldo Carvalho de Melo
2021-11-08 21:19 ` Jiri Olsa
2021-11-08 13:36 ` [PATCH 19/59] perf tools: Fix parse_events_term__num call Jiri Olsa
2021-11-08 18:15 ` Ian Rogers
2021-11-08 21:21 ` Jiri Olsa
2021-11-08 13:36 ` [PATCH 20/59] perf tools: Pass parse_state all the way down to __add_event Jiri Olsa
2021-11-08 13:36 ` [PATCH 21/59] perf tools: Pass parse_state all the way down to add_tracepoint Jiri Olsa
2021-11-08 13:36 ` [PATCH 22/59] perf tools: Add evsel__new callback to parse_state_ops Jiri Olsa
2021-11-08 13:36 ` [PATCH 23/59] perf tools: Add evsel__new_tp " Jiri Olsa
2021-11-08 13:36 ` [PATCH 24/59] perf tools: Add loc_term and loc_val helpers to parse_events_term__str Jiri Olsa
2021-11-08 13:36 ` [PATCH 25/59] perf tools: Add loc_term and loc_val helpers to parse_events_term__num Jiri Olsa
2021-11-08 13:36 ` [PATCH 26/59] libperf: Move in the event_symbols_hw/event_symbols_sw Jiri Olsa
2021-11-08 13:36 ` [PATCH 27/59] libperf: Move in struct parse_events_term code Jiri Olsa
2021-11-08 13:36 ` [PATCH 28/59] perf tools: Add perf_evsel__add_event function Jiri Olsa
2021-11-08 13:36 ` [PATCH 29/59] perf tools: Change struct parse_events_state::evlist to perf_evlist Jiri Olsa
2021-11-08 13:36 ` [PATCH 30/59] libperf: Move in struct parse_events_state Jiri Olsa
2021-11-08 18:21 ` Ian Rogers
2021-11-08 21:24 ` Jiri Olsa
2021-11-08 13:36 ` [PATCH 31/59] perf tools: Move event_attr_init in evsel__new_idx function Jiri Olsa
2021-11-08 13:36 ` [PATCH 32/59] libperf: Move in perf_pmu__warn_invalid_config function Jiri Olsa
2021-11-08 13:36 ` [PATCH 33/59] libperf: Move in perf_evsel__add_event function Jiri Olsa
2021-11-08 13:36 ` [PATCH 34/59] perf tools: Move parse_events_update_lists to parser unit Jiri Olsa
2021-11-08 13:36 ` [PATCH 35/59] libperf: Add perf_evsel__is_group_leader function Jiri Olsa
2021-11-08 13:36 ` [PATCH 36/59] perf tools: Make parse_events__modifier_event work over perf_evsel Jiri Olsa
2021-11-08 13:36 ` [PATCH 37/59] perf tool: Pass perf_guest in struct parse_events_state Jiri Olsa
2021-11-08 13:36 ` Jiri Olsa [this message]
2021-11-08 13:36 ` [PATCH 39/59] libperf: Move in parse_events__handle_error function Jiri Olsa
2021-11-08 13:36 ` [PATCH 40/59] libperf: Move in parse_events_evlist_error function Jiri Olsa
2021-11-08 13:36 ` [PATCH 41/59] perf tools: Add perf_evsel__delete callback to struct parse_events_ops Jiri Olsa
2021-11-08 13:36 ` [PATCH 42/59] libperf: Move in parse_events_name function Jiri Olsa
2021-11-08 18:23 ` Ian Rogers
2021-11-08 21:24 ` Jiri Olsa
2021-11-08 13:36 ` [PATCH 43/59] perf tools: Move out parse_events_add_pmu fallback from parser code Jiri Olsa
2021-11-08 13:36 ` [PATCH 44/59] perf tools: Add add_pmu callback to struct parse_events_ops Jiri Olsa
2021-11-08 13:36 ` [PATCH 45/59] perf tools: Add add_pmu_multi " Jiri Olsa
2021-11-08 13:36 ` [PATCH 46/59] perf tools: Add add_numeric " Jiri Olsa
2021-11-08 18:27 ` Ian Rogers
2021-11-08 21:34 ` Jiri Olsa
2021-11-08 13:36 ` [PATCH 47/59] perf tools: Add add_cache " Jiri Olsa
2021-11-08 13:36 ` [PATCH 48/59] perf tools: Add add_breakpoint " Jiri Olsa
2021-11-08 13:37 ` [PATCH 49/59] perf tools: Add add_tracepoint " Jiri Olsa
2021-11-08 13:37 ` [PATCH 50/59] perf tools: Add add_bpf " Jiri Olsa
2021-11-08 13:37 ` [PATCH 51/59] perf tools: Add add_tool " Jiri Olsa
2021-11-08 13:37 ` [PATCH 52/59] perf tools: Add set_leader " Jiri Olsa
2021-11-08 13:37 ` [PATCH 53/59] perf tools: Add parse_check " Jiri Olsa
2021-11-08 13:37 ` [PATCH 54/59] perf tools: Move PE_* enums in parse_events__scanner Jiri Olsa
2021-11-08 13:37 ` [PATCH 55/59] libperf: Move in parse-events flex/bison parser Jiri Olsa
2021-11-08 13:37 ` [PATCH 56/59] libperf: Move in parse_events_add_breakpoint function Jiri Olsa
2021-11-08 13:37 ` [PATCH 57/59] libperf: Move in some lib objects from perf Jiri Olsa
2021-11-08 13:37 ` [PATCH 58/59] libperf: Add libperf_parse_events function Jiri Olsa
2021-11-08 13:37 ` [PATCH 59/59] libperf: Add parse-events test Jiri Olsa
2021-11-08 18:32 ` Ian Rogers
2021-11-08 21:37 ` Jiri Olsa
2021-11-08 18:50 ` [RFC 00/59] libperf: Move in event parse code Ian Rogers
2021-11-08 21:50 ` Jiri Olsa
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211108133710.1352822-39-jolsa@kernel.org \
--to=jolsa@redhat.com \
--cc=acme@kernel.org \
--cc=irogers@google.com \
--cc=linux-perf-users@vger.kernel.org \
--cc=namhyung@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).