lkml.org 
[lkml]   [2021]   [Jan]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 08/12] perf tools: Support PERF_SAMPLE_WEIGHT_EXT
    Date
    From: Kan Liang <kan.liang@linux.intel.com>

    The new sample type, PERF_SAMPLE_WEIGHT_EXT, is an extension of the
    PERF_SAMPLE_WEIGHT sample type. Enable the sample type if the sample by
    weight option is applied.

    Add weight_ext in the struct perf_sample to record the value of the new
    sample type. For the old kernel which doesn't support the new sample
    type, clear the sample type.

    Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
    ---
    tools/perf/util/event.h | 1 +
    tools/perf/util/evsel.c | 22 +++++++++++++++++++---
    tools/perf/util/evsel.h | 1 +
    tools/perf/util/synthetic-events.c | 8 ++++++++
    4 files changed, 29 insertions(+), 3 deletions(-)

    diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
    index ff403ea..0852c86 100644
    --- a/tools/perf/util/event.h
    +++ b/tools/perf/util/event.h
    @@ -128,6 +128,7 @@ struct perf_sample {
    u64 stream_id;
    u64 period;
    u64 weight;
    + union perf_weight_ext weight_ext;
    u64 transaction;
    u64 insn_cnt;
    u64 cyc_cnt;
    diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
    index 97acde2..bb05687 100644
    --- a/tools/perf/util/evsel.c
    +++ b/tools/perf/util/evsel.c
    @@ -1165,8 +1165,10 @@ void evsel__config(struct evsel *evsel, struct record_opts *opts,
    attr->branch_sample_type = opts->branch_stack;
    }

    - if (opts->sample_weight)
    + if (opts->sample_weight) {
    evsel__set_sample_bit(evsel, WEIGHT);
    + evsel__set_sample_bit(evsel, WEIGHT_EXT);
    + }

    attr->task = track;
    attr->mmap = track;
    @@ -1735,6 +1737,8 @@ static int evsel__open_cpu(struct evsel *evsel, struct perf_cpu_map *cpus,
    }

    fallback_missing_features:
    + if (perf_missing_features.weight_ext)
    + evsel__reset_sample_bit(evsel, WEIGHT_EXT);
    if (perf_missing_features.clockid_wrong)
    evsel->core.attr.clockid = CLOCK_MONOTONIC; /* should always work */
    if (perf_missing_features.clockid) {
    @@ -1873,8 +1877,13 @@ static int evsel__open_cpu(struct evsel *evsel, struct perf_cpu_map *cpus,
    * Must probe features in the order they were added to the
    * perf_event_attr interface.
    */
    - if (!perf_missing_features.data_page_size &&
    - (evsel->core.attr.sample_type & PERF_SAMPLE_DATA_PAGE_SIZE)) {
    + if (!perf_missing_features.weight_ext &&
    + (evsel->core.attr.sample_type & PERF_SAMPLE_WEIGHT_EXT)) {
    + perf_missing_features.weight_ext = true;
    + pr_debug2("switching off weight extension support\n");
    + goto fallback_missing_features;
    + } else if (!perf_missing_features.data_page_size &&
    + (evsel->core.attr.sample_type & PERF_SAMPLE_DATA_PAGE_SIZE)) {
    perf_missing_features.data_page_size = true;
    pr_debug2_peo("Kernel has no PERF_SAMPLE_DATA_PAGE_SIZE support, bailing out\n");
    goto out_close;
    @@ -2382,6 +2391,13 @@ int evsel__parse_sample(struct evsel *evsel, union perf_event *event,
    array = (void *)array + sz;
    }

    + data->weight_ext.val = 0;
    + if (type & PERF_SAMPLE_WEIGHT_EXT) {
    + OVERFLOW_CHECK_u64(array);
    + data->weight_ext.val = *array;
    + array++;
    + }
    +
    return 0;
    }

    diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
    index cd1d8dd..ec598a6 100644
    --- a/tools/perf/util/evsel.h
    +++ b/tools/perf/util/evsel.h
    @@ -145,6 +145,7 @@ struct perf_missing_features {
    bool branch_hw_idx;
    bool cgroup;
    bool data_page_size;
    + bool weight_ext;
    };

    extern struct perf_missing_features perf_missing_features;
    diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic-events.c
    index 2947e3f..69291a9 100644
    --- a/tools/perf/util/synthetic-events.c
    +++ b/tools/perf/util/synthetic-events.c
    @@ -1417,6 +1417,9 @@ size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type,
    result += sample->aux_sample.size;
    }

    + if (type & PERF_SAMPLE_WEIGHT_EXT)
    + result += sizeof(u64);
    +
    return result;
    }

    @@ -1603,6 +1606,11 @@ int perf_event__synthesize_sample(union perf_event *event, u64 type, u64 read_fo
    array = (void *)array + sz;
    }

    + if (type & PERF_SAMPLE_WEIGHT_EXT) {
    + *array = sample->weight_ext.val;
    + array++;
    + }
    +
    return 0;
    }

    --
    2.7.4
    \
     
     \ /
      Last update: 2021-01-19 21:49    [W:3.958 / U:0.316 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site