From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 77A7FC43334 for ; Tue, 19 Jul 2022 17:09:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237779AbiGSRJX (ORCPT ); Tue, 19 Jul 2022 13:09:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237770AbiGSRJT (ORCPT ); Tue, 19 Jul 2022 13:09:19 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65D534F1A3 for ; Tue, 19 Jul 2022 10:09:18 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id p26-20020a1c545a000000b003a2fb7c1274so7814563wmi.1 for ; Tue, 19 Jul 2022 10:09:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=AHFK/Ws0HkMtSGr6JyX7gyAaX6z2dwuYDOmxJ/uuHbM=; b=XYR3Qk2vD8KyHQSmdb6ChddMuI8wX9gtmxQeTkyAOHrh18Sl3ZOokOJUjndbgDd3OR UyYhwLS5ayUD419ocx49QYGct4CEl/d6JYemo9eaNuv5gVnrYyuaxymM+2/W6PNLeOJJ n1ekHRIDeGuFZDVmlGkYO5MJ+qo5LouCG86lBmYccW88q/PJd40T07d+fFNbntooeuXS 6CAwF/jzOCu7TfDZMQrhOJIa35KLcSVN38dHLOSTnUciEzxOnwIAjdyEy078/CbYgjHv dBTD8mWr10tIluxSZ0jbWxtELcpMMipWq1MOfUD54KFoLrXNfzguXFMJO996LoIgjyDn rjiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=AHFK/Ws0HkMtSGr6JyX7gyAaX6z2dwuYDOmxJ/uuHbM=; b=u730D889aQFm39jByZa6GVASI0N+MbYWf55yANBkJuachqSwpZquB2f/4f19N0KQY6 9KROr31iCOUZgHOKyaQ5ZCXAbh9LYs4jwmLfqDBb0QtJMX8TAIF/x6fMjrjUZB+dSd0S N3Lw3l4q85bUMmdixZ1ASKTPInRL1mtWdLgq9tx4c8XzsS4EaCXimm6EDnhNopC7lQxR dqURB7YaEULE+IumTdayBKi/69oesWveFhA1OF9kKeNr2+wKwnSmFgWHIL2TxHjnoUnt DkhsonzE2hn88obAqCQj7redrWJM/P0Hwzhx0OHB2th8ehzaPEhgHYIlyJn2z+ZZzKeN V57g== X-Gm-Message-State: AJIora9XPZv79Lpbotqx8d/YmGwS/5uzIgBTQeODtw0Eqwg4GQY6/IL5 QO713Eo22dQnXuv5TwsY126VcerbPNpygixBNa+8jA== X-Google-Smtp-Source: AGRyM1srBjMkatgJomJDmzmYp4yZG1rVQNKYI013Rwv53viY4pCO2XG83rMauV2CdR7GmxK95jrTlLqEuu8nUDGfvZ0= X-Received: by 2002:a05:600c:2854:b0:3a3:1551:d7d with SMTP id r20-20020a05600c285400b003a315510d7dmr269156wmb.174.1658250556794; Tue, 19 Jul 2022 10:09:16 -0700 (PDT) MIME-Version: 1.0 References: <20220711093218.10967-1-adrian.hunter@intel.com> <20220711093218.10967-6-adrian.hunter@intel.com> In-Reply-To: <20220711093218.10967-6-adrian.hunter@intel.com> From: Ian Rogers Date: Tue, 19 Jul 2022 10:09:04 -0700 Message-ID: Subject: Re: [PATCH 05/35] perf tools: Factor out evsel__id_hdr_size() To: Adrian Hunter Cc: Arnaldo Carvalho de Melo , Jiri Olsa , Namhyung Kim , Andi Kleen , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 11, 2022 at 2:32 AM Adrian Hunter wrote: > > Factor out evsel__id_hdr_size() so it can be reused. > > This is needed by perf inject. When injecting events from a guest perf.data > file, there is a possibility that the sample ID numbers conflict. To > re-write an ID sample, the old one needs to be removed first, which means > determining how big it is with evsel__id_hdr_size() and then subtracting > that from the event size. > > Signed-off-by: Adrian Hunter > --- > tools/perf/util/evlist.c | 28 +--------------------------- > tools/perf/util/evsel.c | 26 ++++++++++++++++++++++++++ > tools/perf/util/evsel.h | 2 ++ > 3 files changed, 29 insertions(+), 27 deletions(-) > > diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c > index 48af7d379d82..03fbe151b0c4 100644 > --- a/tools/perf/util/evlist.c > +++ b/tools/perf/util/evlist.c > @@ -1244,34 +1244,8 @@ bool evlist__valid_read_format(struct evlist *evlist) > u16 evlist__id_hdr_size(struct evlist *evlist) > { > struct evsel *first = evlist__first(evlist); > - struct perf_sample *data; > - u64 sample_type; > - u16 size = 0; > > - if (!first->core.attr.sample_id_all) > - goto out; > - > - sample_type = first->core.attr.sample_type; > - > - if (sample_type & PERF_SAMPLE_TID) > - size += sizeof(data->tid) * 2; > - > - if (sample_type & PERF_SAMPLE_TIME) > - size += sizeof(data->time); > - > - if (sample_type & PERF_SAMPLE_ID) > - size += sizeof(data->id); > - > - if (sample_type & PERF_SAMPLE_STREAM_ID) > - size += sizeof(data->stream_id); > - > - if (sample_type & PERF_SAMPLE_CPU) > - size += sizeof(data->cpu) * 2; > - > - if (sample_type & PERF_SAMPLE_IDENTIFIER) > - size += sizeof(data->id); > -out: > - return size; > + return first->core.attr.sample_id_all ? evsel__id_hdr_size(first) : 0; > } > > bool evlist__valid_sample_id_all(struct evlist *evlist) > diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c > index a67cc3f2fa74..9a30ccb7b104 100644 > --- a/tools/perf/util/evsel.c > +++ b/tools/perf/util/evsel.c > @@ -2724,6 +2724,32 @@ int evsel__parse_sample_timestamp(struct evsel *evsel, union perf_event *event, > return 0; > } > > +u16 evsel__id_hdr_size(struct evsel *evsel) > +{ > + u64 sample_type = evsel->core.attr.sample_type; As this just uses core, would it be more appropriate to put it in libperf? > + u16 size = 0; Perhaps size_t or int? u16 seems odd. > + > + if (sample_type & PERF_SAMPLE_TID) > + size += sizeof(u64); > + > + if (sample_type & PERF_SAMPLE_TIME) > + size += sizeof(u64); > + > + if (sample_type & PERF_SAMPLE_ID) > + size += sizeof(u64); > + > + if (sample_type & PERF_SAMPLE_STREAM_ID) > + size += sizeof(u64); > + > + if (sample_type & PERF_SAMPLE_CPU) > + size += sizeof(u64); > + > + if (sample_type & PERF_SAMPLE_IDENTIFIER) > + size += sizeof(u64); > + > + return size; > +} > + > struct tep_format_field *evsel__field(struct evsel *evsel, const char *name) > { > return tep_find_field(evsel->tp_format, name); > diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h > index 92bed8e2f7d8..699448f2bc2b 100644 > --- a/tools/perf/util/evsel.h > +++ b/tools/perf/util/evsel.h > @@ -381,6 +381,8 @@ int evsel__parse_sample(struct evsel *evsel, union perf_event *event, > int evsel__parse_sample_timestamp(struct evsel *evsel, union perf_event *event, > u64 *timestamp); > > +u16 evsel__id_hdr_size(struct evsel *evsel); > + A comment would be nice, I know this is just moving code about but this is a new function. Thanks, Ian > static inline struct evsel *evsel__next(struct evsel *evsel) > { > return list_entry(evsel->core.node.next, struct evsel, core.node); > -- > 2.25.1 >