Re: [PATCH 1/4] perf tool: Parse general/raw events from sysfs

From: Stephane Eranian
Date: Mon Jan 02 2012 - 06:07:30 EST


Robert,

I must be missing somerthing but which patch adds:

/sys/bus/event_source/devices/ibs_op/events/r0

It seems the modified perf tool insists on getting the event encoding from sysfs
yet I don't see that in your patchset.

On Thu, Dec 15, 2011 at 5:23 PM, Robert Richter <robert.richter@xxxxxxx> wrote:
> From: Lin Ming <ming.m.lin@xxxxxxxxx>
>
> PMU can export general events to sysfs, for example,
>
> /sys/bus/event_source/devices/uncore/events
> âââ cycle
>
> Then specify the event as <pmu>:<event>,
>
> $ sudo perf stat -a -C 0 -e uncore:cycle
> ^C
> ÂPerformance counter stats for 'CPU 0':
>
> Â Â Â Â56,547,314 uncore:cycle
>
> Raw event can be specified as <pmu>:rXXXX
>
> $ sudo perf stat -a -C 0 -e uncore:r0101
> ^C
> ÂPerformance counter stats for 'CPU 0':
>
> Â Â Â Â Â Â 8,504 uncore:r0101
>
> Signed-off-by: Lin Ming <ming.m.lin@xxxxxxxxx>
> ---
> Âtools/perf/util/parse-events.c | Â 84 +++++++++++++++++++++++++++++++++++++++-
> Â1 files changed, 82 insertions(+), 2 deletions(-)
>
> diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
> index 586ab3f..4ce9404 100644
> --- a/tools/perf/util/parse-events.c
> +++ b/tools/perf/util/parse-events.c
> @@ -685,7 +685,7 @@ parse_symbolic_event(const char **strp, struct perf_event_attr *attr)
> Â}
>
> Âstatic enum event_result
> -parse_raw_event(const char **strp, struct perf_event_attr *attr)
> +parse_raw_config(const char **strp, struct perf_event_attr *attr)
> Â{
> Â Â Â Âconst char *str = *strp;
> Â Â Â Âu64 config;
> @@ -700,7 +700,6 @@ parse_raw_event(const char **strp, struct perf_event_attr *attr)
> Â Â Â Â Â Â Â Â Â Â Â Âreturn EVT_FAILED;
>
> Â Â Â Â Â Â Â Â*strp = end;
> - Â Â Â Â Â Â Â attr->type = PERF_TYPE_RAW;
> Â Â Â Â Â Â Â Âattr->config = config;
> Â Â Â Â Â Â Â Âreturn EVT_HANDLED;
> Â Â Â Â}
> @@ -708,6 +707,83 @@ parse_raw_event(const char **strp, struct perf_event_attr *attr)
> Â}
>
> Âstatic enum event_result
> +parse_raw_event(const char **strp, struct perf_event_attr *attr)
> +{
> + Â Â Â if (parse_raw_config(strp, attr) != EVT_HANDLED)
> + Â Â Â Â Â Â Â return EVT_FAILED;
> +
> + Â Â Â attr->type = PERF_TYPE_RAW;
> + Â Â Â return EVT_HANDLED;
> +}
> +
> +#define EVENT_SOURCE_DIR "/sys/bus/event_source/devices"
> +
> +static u64 read_sysfs_entry(const char *path)
> +{
> + Â Â Â char buf[19];
> + Â Â Â int fd;
> +
> + Â Â Â fd = open(path, O_RDONLY);
> + Â Â Â if (fd < 0)
> + Â Â Â Â Â Â Â return -1;
> +
> + Â Â Â if (read(fd, buf, sizeof(buf)) < 0) {
> + Â Â Â Â Â Â Â close(fd);
> + Â Â Â Â Â Â Â return -1;
> + Â Â Â }
> +
> + Â Â Â close(fd);
> + Â Â Â return atoll(buf);
> +}
> +
> +static u64 get_pmu_type(const char *pmu_name)
> +{
> + Â Â Â char evt_path[MAXPATHLEN];
> +
> + Â Â Â snprintf(evt_path, MAXPATHLEN, "%s/%s/type", EVENT_SOURCE_DIR,
> + Â Â Â Â Â Â Â Âpmu_name);
> +
> + Â Â Â return read_sysfs_entry(evt_path);
> +}
> +
> +static u64 get_pmu_event_config(const char *pmu_name, const char *evt_name)
> +{
> + Â Â Â char evt_path[MAXPATHLEN];
> +
> + Â Â Â snprintf(evt_path, MAXPATHLEN, "%s/%s/events/%s", EVENT_SOURCE_DIR,
> + Â Â Â Â Â Â Â Âpmu_name, evt_name);
> +
> + Â Â Â return read_sysfs_entry(evt_path);
> +}
> +
> +static enum event_result
> +parse_sysfs_event(const char **strp, struct perf_event_attr *attr)
> +{
> + Â Â Â char *pmu_name, *evt_name;
> + Â Â Â u64 type, config;
> +
> + Â Â Â pmu_name = strchr(*strp, ':');
> + Â Â Â if (!pmu_name)
> + Â Â Â Â Â Â Â return EVT_FAILED;
> + Â Â Â pmu_name = strndup(*strp, pmu_name - *strp);
> + Â Â Â type = get_pmu_type(pmu_name);
> + Â Â Â if ((int)type < 0)
> + Â Â Â Â Â Â Â return EVT_FAILED;
> + Â Â Â attr->type = type;
> +
> + Â Â Â evt_name = strchr(*strp, ':') + 1;
> + Â Â Â config = get_pmu_event_config(pmu_name, evt_name);
> + Â Â Â *strp += strlen(pmu_name) + 1; /* + 1 for the ':' */
> +
> + Â Â Â if ((int)config < 0)
> + Â Â Â Â Â Â Â return parse_raw_config(strp, attr);
> +
> + Â Â Â attr->config = config;
> + Â Â Â *strp += strlen(evt_name);
> + Â Â Â return EVT_HANDLED;
> +}
> +
> +static enum event_result
> Âparse_numeric_event(const char **strp, struct perf_event_attr *attr)
> Â{
> Â Â Â Âconst char *str = *strp;
> @@ -788,6 +864,10 @@ parse_event_symbols(struct perf_evlist *evlist, const char **str,
> Â{
> Â Â Â Âenum event_result ret;
>
> + Â Â Â ret = parse_sysfs_event(str, attr);
> + Â Â Â if (ret != EVT_FAILED)
> + Â Â Â Â Â Â Â goto modifier;
> +
> Â Â Â Âret = parse_tracepoint_event(evlist, str, attr);
> Â Â Â Âif (ret != EVT_FAILED)
> Â Â Â Â Â Â Â Âgoto modifier;
> --
> 1.7.7
>
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/