From nobody Mon Oct 6 06:46:43 2025 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DACDC2EF9DD for ; Thu, 24 Jul 2025 16:34:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753374847; cv=none; b=Oee1zIR5UyqnpXtNt8Tmr862uWRQPnh8sZvUJyFwmjsCxS2HFe/6dd+Nn+ni+EXxfspv0eKaOKR1v5fpZDQ9hPZDvgArTmnBy7mVfHliO0gtI0GPZwH42nnqQhmOre52QnSLLL6oGSaj0ANuDZqMLbMGTmeoBQs+iOTH5OYVsDI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753374847; c=relaxed/simple; bh=GOtxzQlYe3sbLjIN3sN75f+UTSNIwyDGS/2BGS2Boyo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=oXVOUP3gX+XTijC22y+QNOiRDGUy4ChWi2GNQnFY3pr2H9vAE2WkufnSvLsEucFsar3DBpep17rEEip4SE7DFKJpL5fR4BMXPeZ52eYVVkFz1u6Eg+5IVRQuaUW6GT8AKw/kHGDkm2uUxnv1gdw9LAOxdQmz7uRh3rZIj/LBd1E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=wQA2mWTu; arc=none smtp.client-ip=209.85.214.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="wQA2mWTu" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-235e1d70d67so11711075ad.0 for ; Thu, 24 Jul 2025 09:34:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1753374845; x=1753979645; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=fdxw9xzQEGKIPLNVqIHrpPLnMAqAFNBUSxOmG1YpohM=; b=wQA2mWTuPmtO2RLGNoh1A6TRNTcfpGqyAqGBoulbXfF6+x03lkRDREluiXl+hkYCnz Hl42x2ZQ8jw78fHgZu1DCgMGOJ9Tsg6zDf1jvXj/0DIwI2IFfdKbKWwJh5hw9tMzPDZ+ Yel/MzuplV9QD3SauS/Ui8+lXY3SRhHQ2Y7Q8eJaVXB1kej18rkbcVVxWo5lY3Qkr5wX 84vvn9HI78n9MU22uuDyNBMc63PeSDXz/zRpzQX9J7Uaa0MBxZedhQz2dU4lV6wlz5tl 949++8KUzAyQ9ev1I+7NW3IRNoHQPqI1nBRhNa7Uz6UhG0ncLAfTm35sUPYpdQpQQFnx 39Pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753374845; x=1753979645; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=fdxw9xzQEGKIPLNVqIHrpPLnMAqAFNBUSxOmG1YpohM=; b=SeluzMco66NbrBB8gwVY/33wCkJ4PCuM+/KfzOgEqxsmteOWN+f3/UfxvlMtoFIKsR X/dgzcBqygVBjnpynMw42rU0gZLlsstQvqvX6dmergPCI7E2kI02XxwRy8GsInh2wPrO 76JN6IRuVOBQlzIbYUnzU7IDf4JUQCOaHyVm5B0tXx6cPVNC6ecSJa8ceNFEzaoyAouo PgrrjzWNyiSUXqjO/MPoXjB662wsurkuXSrkvLXSiwOz/TGpJdxX12rcoTCJijw8ddBd 5TwJmCPw3arlk3M3Lf1wSNd8dhVID2ysjFkbt8Bnty1m+McEopUb9vMVsnzSwSZgA/JZ BVYA== X-Forwarded-Encrypted: i=1; AJvYcCXUs4fyQZb6CtwvR2nZvEili8ZmYxoqL6bipnFoIDRXcwKthfuDfgCz5sdlSzm6hR1hw5t+FAR//nYzDFg=@vger.kernel.org X-Gm-Message-State: AOJu0YxkEbddxW5q8tdLx+gH8e9iFE7ydNmg8I4dfCkehb7xVzC1CDbU Hj+kielp1fjzewDCEpc3mP4Tl36LqUqbgyoUXYnpsdvRKw5802+qSqFc8t6EfBsw2xIM1jw0SX1 unXazfSvLIw== X-Google-Smtp-Source: AGHT+IHCRpyU9ii804LfL6OKryNgB2KgE4vQP+Q33YtbQkKZ/CvrsDCaeciYUlVcmHbFDYslJMqvcmI/97sy X-Received: from pjbos14.prod.google.com ([2002:a17:90b:1cce:b0:30a:31eb:ec8e]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:d486:b0:234:ed31:fc98 with SMTP id d9443c01a7336-23f981cca92mr97923225ad.37.1753374844805; Thu, 24 Jul 2025 09:34:04 -0700 (PDT) Date: Thu, 24 Jul 2025 09:33:00 -0700 In-Reply-To: <20250724163302.596743-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250724163302.596743-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250724163302.596743-21-irogers@google.com> Subject: [PATCH v6 20/22] perf sample: Remove arch notion of sample parsing From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , "Masami Hiramatsu (Google)" , Ravi Bangoria , Charlie Jenkins , Colin Ian King , Andi Kleen , Dmitry Vyukov , Graham Woodward , Ilkka Koskinen , Zhongqiu Han , Yicong Yang , Athira Rajeev , Kajol Jain , Li Huafei , "Steinar H. Gunderson" , Stephen Brennan , Chun-Tse Shao , Yujie Liu , "Dr. David Alan Gilbert" , Levi Yun , Howard Chu , Weilin Wang , Thomas Falcon , Matt Fleming , "=?UTF-8?q?Krzysztof=20=C5=81opatowski?=" , Zixian Cai , Steve Clevenger , Ben Gainey , Chaitanya S Prakash , Martin Liska , "=?UTF-8?q?Martin=20Li=C5=A1ka?=" , Song Liu , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" By definition arch sample parsing and synthesis will inhibit certain kinds of cross-platform record then analysis (report, script, etc.). Remove arch_perf_parse_sample_weight and arch_perf_synthesize_sample_weight replacing with a common implementation. Combine perf_sample p_stage_cyc and retire_lat as weight3 to capture the differing uses regardless of compiled for architecture. Signed-off-by: Ian Rogers --- tools/perf/arch/powerpc/util/event.c | 26 --------------------- tools/perf/arch/x86/tests/sample-parsing.c | 4 ++-- tools/perf/arch/x86/util/event.c | 27 ---------------------- tools/perf/builtin-script.c | 2 +- tools/perf/util/dlfilter.c | 2 +- tools/perf/util/event.h | 2 -- tools/perf/util/evsel.c | 17 ++++++++++---- tools/perf/util/hist.c | 4 ++-- tools/perf/util/hist.h | 3 ++- tools/perf/util/intel-tpebs.c | 4 ++-- tools/perf/util/sample.h | 6 ++--- tools/perf/util/session.c | 2 +- tools/perf/util/sort.c | 7 +++--- tools/perf/util/synthetic-events.c | 10 ++++++-- 14 files changed, 36 insertions(+), 80 deletions(-) diff --git a/tools/perf/arch/powerpc/util/event.c b/tools/perf/arch/powerpc= /util/event.c index 77d8cc2b5691..024ac8b54c33 100644 --- a/tools/perf/arch/powerpc/util/event.c +++ b/tools/perf/arch/powerpc/util/event.c @@ -11,32 +11,6 @@ #include "../../../util/debug.h" #include "../../../util/sample.h" =20 -void arch_perf_parse_sample_weight(struct perf_sample *data, - const __u64 *array, u64 type) -{ - union perf_sample_weight weight; - - weight.full =3D *array; - if (type & PERF_SAMPLE_WEIGHT) - data->weight =3D weight.full; - else { - data->weight =3D weight.var1_dw; - data->ins_lat =3D weight.var2_w; - data->p_stage_cyc =3D weight.var3_w; - } -} - -void arch_perf_synthesize_sample_weight(const struct perf_sample *data, - __u64 *array, u64 type) -{ - *array =3D data->weight; - - if (type & PERF_SAMPLE_WEIGHT_STRUCT) { - *array &=3D 0xffffffff; - *array |=3D ((u64)data->ins_lat << 32); - } -} - const char *arch_perf_header_entry(const char *se_header) { if (!strcmp(se_header, "Local INSTR Latency")) diff --git a/tools/perf/arch/x86/tests/sample-parsing.c b/tools/perf/arch/x= 86/tests/sample-parsing.c index a061e8619267..22feec23e53d 100644 --- a/tools/perf/arch/x86/tests/sample-parsing.c +++ b/tools/perf/arch/x86/tests/sample-parsing.c @@ -29,7 +29,7 @@ static bool samples_same(const struct perf_sample *s1, { if (type & PERF_SAMPLE_WEIGHT_STRUCT) { COMP(ins_lat); - COMP(retire_lat); + COMP(weight3); } =20 return true; @@ -50,7 +50,7 @@ static int do_test(u64 sample_type) struct perf_sample sample =3D { .weight =3D 101, .ins_lat =3D 102, - .retire_lat =3D 103, + .weight3 =3D 103, }; struct perf_sample sample_out; size_t i, sz, bufsz; diff --git a/tools/perf/arch/x86/util/event.c b/tools/perf/arch/x86/util/ev= ent.c index a0400707180c..576c1c36046c 100644 --- a/tools/perf/arch/x86/util/event.c +++ b/tools/perf/arch/x86/util/event.c @@ -92,33 +92,6 @@ int perf_event__synthesize_extra_kmaps(const struct perf= _tool *tool, =20 #endif =20 -void arch_perf_parse_sample_weight(struct perf_sample *data, - const __u64 *array, u64 type) -{ - union perf_sample_weight weight; - - weight.full =3D *array; - if (type & PERF_SAMPLE_WEIGHT) - data->weight =3D weight.full; - else { - data->weight =3D weight.var1_dw; - data->ins_lat =3D weight.var2_w; - data->retire_lat =3D weight.var3_w; - } -} - -void arch_perf_synthesize_sample_weight(const struct perf_sample *data, - __u64 *array, u64 type) -{ - *array =3D data->weight; - - if (type & PERF_SAMPLE_WEIGHT_STRUCT) { - *array &=3D 0xffffffff; - *array |=3D ((u64)data->ins_lat << 32); - *array |=3D ((u64)data->retire_lat << 48); - } -} - const char *arch_perf_header_entry(const char *se_header) { if (!strcmp(se_header, "Local Pipeline Stage Cycle")) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index f2b5620165b4..d9fbdcf72f25 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -2252,7 +2252,7 @@ static void process_event(struct perf_script *script, fprintf(fp, "%16" PRIu16, sample->ins_lat); =20 if (PRINT_FIELD(RETIRE_LAT)) - fprintf(fp, "%16" PRIu16, sample->retire_lat); + fprintf(fp, "%16" PRIu16, sample->weight3); =20 if (PRINT_FIELD(CGROUP)) { const char *cgrp_name; diff --git a/tools/perf/util/dlfilter.c b/tools/perf/util/dlfilter.c index ddacef881af2..c0afcbd954f8 100644 --- a/tools/perf/util/dlfilter.c +++ b/tools/perf/util/dlfilter.c @@ -513,6 +513,7 @@ int dlfilter__do_filter_event(struct dlfilter *d, d->d_addr_al =3D &d_addr_al; =20 d_sample.size =3D sizeof(d_sample); + d_sample.p_stage_cyc =3D sample->weight3; d_ip_al.size =3D 0; /* To indicate d_ip_al is not initialized */ d_addr_al.size =3D 0; /* To indicate d_addr_al is not initialized */ =20 @@ -526,7 +527,6 @@ int dlfilter__do_filter_event(struct dlfilter *d, ASSIGN(period); ASSIGN(weight); ASSIGN(ins_lat); - ASSIGN(p_stage_cyc); ASSIGN(transaction); ASSIGN(insn_cnt); ASSIGN(cyc_cnt); diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h index 67ad4a2014bc..b13385a6068b 100644 --- a/tools/perf/util/event.h +++ b/tools/perf/util/event.h @@ -391,8 +391,6 @@ extern unsigned int proc_map_timeout; #define PAGE_SIZE_NAME_LEN 32 char *get_page_size_name(u64 size, char *str); =20 -void arch_perf_parse_sample_weight(struct perf_sample *data, const __u64 *= array, u64 type); -void arch_perf_synthesize_sample_weight(const struct perf_sample *data, __= u64 *array, u64 type); const char *arch_perf_header_entry(const char *se_header); int arch_support_sort_key(const char *sort_key); =20 diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index e4a52f4b0af0..8f1dfe53bc06 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -2867,11 +2867,18 @@ perf_event__check_size(union perf_event *event, uns= igned int sample_size) return 0; } =20 -void __weak arch_perf_parse_sample_weight(struct perf_sample *data, - const __u64 *array, - u64 type __maybe_unused) +static void perf_parse_sample_weight(struct perf_sample *data, const __u64= *array, u64 type) { - data->weight =3D *array; + union perf_sample_weight weight; + + weight.full =3D *array; + if (type & PERF_SAMPLE_WEIGHT_STRUCT) { + data->weight =3D weight.var1_dw; + data->ins_lat =3D weight.var2_w; + data->weight3 =3D weight.var3_w; + } else { + data->weight =3D weight.full; + } } =20 u64 evsel__bitfield_swap_branch_flags(u64 value) @@ -3257,7 +3264,7 @@ int evsel__parse_sample(struct evsel *evsel, union pe= rf_event *event, =20 if (type & PERF_SAMPLE_WEIGHT_TYPE) { OVERFLOW_CHECK_u64(array); - arch_perf_parse_sample_weight(data, array, type); + perf_parse_sample_weight(data, array, type); array++; } =20 diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index afc6855327ab..64ff427040c3 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c @@ -829,7 +829,7 @@ __hists__add_entry(struct hists *hists, .period =3D sample->period, .weight1 =3D sample->weight, .weight2 =3D sample->ins_lat, - .weight3 =3D sample->p_stage_cyc, + .weight3 =3D sample->weight3, .latency =3D al->latency, }, .parent =3D sym_parent, @@ -846,7 +846,7 @@ __hists__add_entry(struct hists *hists, .time =3D hist_time(sample->time), .weight =3D sample->weight, .ins_lat =3D sample->ins_lat, - .p_stage_cyc =3D sample->p_stage_cyc, + .weight3 =3D sample->weight3, .simd_flags =3D sample->simd_flags, }, *he =3D hists__findnew_entry(hists, &entry, al, sample_self); =20 diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h index c64254088fc7..70438d03ca9c 100644 --- a/tools/perf/util/hist.h +++ b/tools/perf/util/hist.h @@ -255,7 +255,8 @@ struct hist_entry { u64 code_page_size; u64 weight; u64 ins_lat; - u64 p_stage_cyc; + /** @weight3: On x86 holds retire_lat, on powerpc holds p_stage_cyc. */ + u64 weight3; s32 socket; s32 cpu; int parallelism; diff --git a/tools/perf/util/intel-tpebs.c b/tools/perf/util/intel-tpebs.c index 3b92ebf5c112..8c9aee157ec4 100644 --- a/tools/perf/util/intel-tpebs.c +++ b/tools/perf/util/intel-tpebs.c @@ -210,8 +210,8 @@ static int process_sample_event(const struct perf_tool = *tool __maybe_unused, * latency value will be used. Save the number of samples and the sum of * retire latency value for each event. */ - t->last =3D sample->retire_lat; - update_stats(&t->stats, sample->retire_lat); + t->last =3D sample->weight3; + update_stats(&t->stats, sample->weight3); mutex_unlock(tpebs_mtx_get()); return 0; } diff --git a/tools/perf/util/sample.h b/tools/perf/util/sample.h index 0e96240052e9..fae834144ef4 100644 --- a/tools/perf/util/sample.h +++ b/tools/perf/util/sample.h @@ -104,10 +104,8 @@ struct perf_sample { u8 cpumode; u16 misc; u16 ins_lat; - union { - u16 p_stage_cyc; - u16 retire_lat; - }; + /** @weight3: On x86 holds retire_lat, on powerpc holds p_stage_cyc. */ + u16 weight3; bool no_hw_idx; /* No hw_idx collected in branch_stack */ char insn[MAX_INSN]; void *raw_data; diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 2a79e6844f36..26ae078278cd 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -1099,7 +1099,7 @@ static void dump_sample(struct evsel *evsel, union pe= rf_event *event, printf("... weight: %" PRIu64 "", sample->weight); if (sample_type & PERF_SAMPLE_WEIGHT_STRUCT) { printf(",0x%"PRIx16"", sample->ins_lat); - printf(",0x%"PRIx16"", sample->p_stage_cyc); + printf(",0x%"PRIx16"", sample->weight3); } printf("\n"); } diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c index 7969d64a47bf..0ba2ce1b1c07 100644 --- a/tools/perf/util/sort.c +++ b/tools/perf/util/sort.c @@ -1884,21 +1884,20 @@ struct sort_entry sort_global_ins_lat =3D { static int64_t sort__p_stage_cyc_cmp(struct hist_entry *left, struct hist_entry *right) { - return left->p_stage_cyc - right->p_stage_cyc; + return left->weight3 - right->weight3; } =20 static int hist_entry__global_p_stage_cyc_snprintf(struct hist_entry *he, = char *bf, size_t size, unsigned int width) { - return repsep_snprintf(bf, size, "%-*u", width, - he->p_stage_cyc * he->stat.nr_events); + return repsep_snprintf(bf, size, "%-*u", width, he->weight3 * he->stat.nr= _events); } =20 =20 static int hist_entry__p_stage_cyc_snprintf(struct hist_entry *he, char *b= f, size_t size, unsigned int width) { - return repsep_snprintf(bf, size, "%-*u", width, he->p_stage_cyc); + return repsep_snprintf(bf, size, "%-*u", width, he->weight3); } =20 struct sort_entry sort_local_p_stage_cyc =3D { diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic= -events.c index 638d7dd7fa4b..6afdcfd14224 100644 --- a/tools/perf/util/synthetic-events.c +++ b/tools/perf/util/synthetic-events.c @@ -1573,10 +1573,16 @@ size_t perf_event__sample_event_size(const struct p= erf_sample *sample, u64 type, return result; } =20 -void __weak arch_perf_synthesize_sample_weight(const struct perf_sample *d= ata, +static void perf_synthesize_sample_weight(const struct perf_sample *data, __u64 *array, u64 type __maybe_unused) { *array =3D data->weight; + + if (type & PERF_SAMPLE_WEIGHT_STRUCT) { + *array &=3D 0xffffffff; + *array |=3D ((u64)data->ins_lat << 32); + *array |=3D ((u64)data->weight3 << 48); + } } =20 static __u64 *copy_read_group_values(__u64 *array, __u64 read_format, @@ -1736,7 +1742,7 @@ int perf_event__synthesize_sample(union perf_event *e= vent, u64 type, u64 read_fo } =20 if (type & PERF_SAMPLE_WEIGHT_TYPE) { - arch_perf_synthesize_sample_weight(sample, array, type); + perf_synthesize_sample_weight(sample, array, type); array++; } =20 --=20 2.50.0.727.gbf7dc18ff4-goog