From nobody Sat Feb 7 12:29:48 2026 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.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 D055B13CFB8 for ; Sat, 17 Aug 2024 06:45:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723877106; cv=none; b=Ocvf1/VO6dSRtKbaxg21uvBgf9pWElLXpRyUDjK1x14SaAZAgMt1HGs3fqbQM1l2c+jrL1veUXnLWLCv+aqxhQNJPqavOF8SN0r4ma8bz2p04nGy2I7xlqB7gjdraxv7ksvgKlV+iTFST/1lvo1ElFCSrcDWo8de6GPa4JMaZPw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723877106; c=relaxed/simple; bh=8O1Y6scYhFyMobEhQv8IUwAJvsd4pajhjp1TTW88UH8=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=Qqi3yho+mjdQSUKuK5h42kLcJVTvp5liuR2gIRt7r4ZpGm8Cy/qciZlC6H85VkYJw6wF895e09fY7w8Mc6s63BO/NBZx+T0By2j/SYEioRiDg8b92pizH1fjYLqYLF4WL1MulxudwUfanBj8yDHgIrsTb0PNpqYD2biYy29uEVA= 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=FAj2ohnl; arc=none smtp.client-ip=209.85.128.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="FAj2ohnl" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6b46a237b48so11848487b3.1 for ; Fri, 16 Aug 2024 23:45:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1723877104; x=1724481904; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=mqApkqpthfyxrYsLzWSBaC2fZccyqsDwIPuPbR5JMvQ=; b=FAj2ohnlzB9VygWL/EvZj2BLGj5zVsb9Mt+6+EaW4pFQ1z0X81CASUOwAwELKK28qB +s0brJ1CfCG9jneXcGPbnyhWgcpat11CImHsUPN14DmmOLNEHW18f6R1WjdIoiWJbnMO ZNptJ33p3+g/yM4h4Q+mzLK8D/IPWuIBTSR4JWepiVOBCZ6oJSvil7OBc5651rI52819 iRbD8GXonWtz3cv13JAjgT6/pW5HiUCIrIBERDJyYrFnWMadqGYy3tjxdLc2nZTRyXkP V7Zy+LF1yad20MJaTvmz02Q39mUM/2c/9vviG2a7a5o0qYF4gdkAs9LX0ZoYRarXaHsP 9BwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723877104; x=1724481904; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=mqApkqpthfyxrYsLzWSBaC2fZccyqsDwIPuPbR5JMvQ=; b=hq4R2ZwK/rLPNgExdX8dUWwB6Pt/QAlcMcyvsoOxrChSEYk4EgRef7Qh8yQ6sn02pB OXeYuPg1op9yjYEnhg+J0syMqjpr2Trq885EGXjzTxSsB36XlUYKHphzVL0k2bugIPS0 SFObgo5kz3XlvvFQE8mP07Gznxstm3cqrzm9eYkq1mtnA1/gJnD+4Q4WqUMvZuMio2nM NskEXlx5+qZDf5IAFsKbolk36wRIHuj0ksoX6srgkJMoDMCpnmlSHucc2Imrr95iP/7R nFnWsQ2nGw6Hr0PiHzHqxA2gcCJmY8Zlz46Z40eDlDz07C8cJCrqe7zVOHt7Bf4ufeoS ABlQ== X-Forwarded-Encrypted: i=1; AJvYcCW+GXeCiUN0Bt22RKVIUslDGmSr+Odv6uvx5hoy6XDYEW4V2DdtAmtuqOcKlyRnVTiJD8oMKwK3A9kiRRMlWGF5ZptR23Q1pRnbE2DC X-Gm-Message-State: AOJu0YzJ2GKyYGWf5+Zz+rw8TsJ210BmgxO0yoAKmz+o7UJYPZ0Eg3Td WZKf4pzXc1oDZz6/usZsHYVZX3L+7AfxWUwIxkn1P1A8AZEn+v4DRtWLIL/qk5N8Zp5SV87eyLB owBolzg== X-Google-Smtp-Source: AGHT+IGg3LRJosB9auNcaghrQgueNTv/MMX58STgLkl4G0wV2VDI1N2aFQK4MBeoUYtE82hs2DHfVEmhWdmH X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:78c9:5e58:734f:c59f]) (user=irogers job=sendgmr) by 2002:a05:690c:4c82:b0:6b2:7ff8:ca3 with SMTP id 00721157ae682-6b280074fafmr1410557b3.4.1723877103765; Fri, 16 Aug 2024 23:45:03 -0700 (PDT) Date: Fri, 16 Aug 2024 23:44:30 -0700 In-Reply-To: <20240817064442.2152089-1-irogers@google.com> Message-Id: <20240817064442.2152089-2-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240817064442.2152089-1-irogers@google.com> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog Subject: [PATCH v1 01/13] perf synthetic-events: Avoid unnecessary memset 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 , Masahiro Yamada , Arnd Bergmann , Jann Horn , Colin Ian King , Casey Chen , Athira Rajeev , Chaitanya S Prakash , James Clark , Ze Gao , Yang Jihong , Yunseong Kim , Weilin Wang , Dominique Martinet , Anne Macedo , Sun Haiyong , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Make sure the memset of a synthesized event only zeros the necessary tracing data part of the event, as a full event can be over 4kb in size. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/util/synthetic-events.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic= -events.c index 7f884d70de81..0a7f93ae76fb 100644 --- a/tools/perf/util/synthetic-events.c +++ b/tools/perf/util/synthetic-events.c @@ -2200,7 +2200,7 @@ int perf_event__synthesize_tracing_data(const struct = perf_tool *tool, int fd, st if (!tdata) return -1; =20 - memset(&ev, 0, sizeof(ev)); + memset(&ev, 0, sizeof(ev.tracing_data)); =20 ev.tracing_data.header.type =3D PERF_RECORD_HEADER_TRACING_DATA; size =3D tdata->size; --=20 2.46.0.184.g6999bdac58-goog From nobody Sat Feb 7 12:29:48 2026 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.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 47F7513E41D for ; Sat, 17 Aug 2024 06:45:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723877108; cv=none; b=tvHMY7mgTGaYg8ToPA0i0x2BUg6pEOypbGMk7xRB4MZfRMdxC3a6s+/zqcYvWs04NiN5hYly9GHsVN+ph1wb20k2lb52U7j/jujilZaNf8su38WZwxfdPv+6cXeoyecaJzb/F8hCcVEjlJRp4OVLiQe9R/4M8dPVt0nlSxSjLaw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723877108; c=relaxed/simple; bh=gTRDFpYLNlrakknneQA/FAQIcyaR80SGVOx61iwej84=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=HtDyM+gDLwi3vl4TLySatrbtTh5VjZB9aF9XaYQcKNyblJdsXy0Y+iwgd1CD2nBUGztGumAwElpxGGtA0QPs0lG7f8Eq8Pul4mv5FvjtlCgMSDa6aRpAM5Rbbyqac6qkDipIipNhdbaJmWx4z4zpU/3DXd4bit4jODAQLVj+0A4= 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=XOJqmw/W; arc=none smtp.client-ip=209.85.219.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="XOJqmw/W" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e0be1808a36so4307895276.1 for ; Fri, 16 Aug 2024 23:45:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1723877106; x=1724481906; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=rN2bQVk5OkgIwB1Fv0zphF3BxkmyT/Y2fj34BjcoCDI=; b=XOJqmw/WC79ReUdYoYhLVn+xzW4zqiC+GCzR8AhU99ZLirUGQH7stoNbxvzx9K4TUV jrDkxethYcWqBAlKUGeAefJ2NDdG3JkYVGvxzvU8GGLkmPDax5nUfxhoBcSzUwVeSajX 16gpAtToU6yW4f7o3DRJsr6by2JrF0BVEgWkQ7p2G/Zx2haI/MNgn4I21h7yuJeelZR4 SRfeRgZovJc5+9bAR8/BADVjxYLLb5sjEUI+y7plJkZM4KnbZ8zHGxDHukZI4IyHAY9q kOfhe0YyEwAYKzuJbEaFMTB9w0AR8glglY9Tm7iJuLafxEROaHkkMfw+tYhn7WmPH5eF TPCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723877106; x=1724481906; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=rN2bQVk5OkgIwB1Fv0zphF3BxkmyT/Y2fj34BjcoCDI=; b=tA/gyMMlwk1Pqx2TArdAfiB1ng3xjC1H3pE5wLfhuifmIVLTlhhOoeygMapYLd+u/U +kxbVovrMfOk5FWuRMVq3VGdiHf78DQrdJz+ZdtYCsL7OpJacu3MBDCar3jrc3kNkwg1 /tmx8t1hfx9nv0RFRQXrGBLg0v9Np+lQ6F6OWipFkcnVsmFB9sBTaeO7YBvNdyl6e+2A gfVZ9h2WjLIWFb5TC3eyuJl0mp97q1xbcTk32oNTQpgcWnn5ezKcQkFERyXlWjaEA2mz 3s9B4sSKBF5Bs/L5jvJ73LCseYflQwG7n/hSWzGkHVnLfOy5B9pA6b92WZKFTX83cAJ+ 709Q== X-Forwarded-Encrypted: i=1; AJvYcCWGawt09NCOtZ6Vi/bUA5KGOxFquTBcukY7SY/hNQ4xVOwtDAf1ZiydvwRoyyjLaZXTxxqBMUfGdEc84r9lDD7r5I6Wrfsg4t9oUP3D X-Gm-Message-State: AOJu0Yz2HnMDbzfh8OfOzxc8tmr7FF1ogX95us4jxUnyLgEm0uwK0H9k UN7oMkrVG6yivcJgYdI9ubVDb8sPWeJ8tj7tHUR/0/pii/dKvTageHRMIdPhauUo6rCcdTxY3gd DWbKHrg== X-Google-Smtp-Source: AGHT+IFz/d7kKhLXM3B8opmAt9DpVCoXyHPmqqZ9siDIPulFjBaWeU2wl7wRQzaoGMjKbtKBLqj4blJlvBJ1 X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:78c9:5e58:734f:c59f]) (user=irogers job=sendgmr) by 2002:a05:6902:11:b0:e0b:fe07:1e22 with SMTP id 3f1490d57ef6-e1180e61040mr21103276.1.1723877106044; Fri, 16 Aug 2024 23:45:06 -0700 (PDT) Date: Fri, 16 Aug 2024 23:44:31 -0700 In-Reply-To: <20240817064442.2152089-1-irogers@google.com> Message-Id: <20240817064442.2152089-3-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240817064442.2152089-1-irogers@google.com> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog Subject: [PATCH v1 02/13] perf map: API clean up 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 , Masahiro Yamada , Arnd Bergmann , Jann Horn , Colin Ian King , Casey Chen , Athira Rajeev , Chaitanya S Prakash , James Clark , Ze Gao , Yang Jihong , Yunseong Kim , Weilin Wang , Dominique Martinet , Anne Macedo , Sun Haiyong , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" map__init is only used internally so make it static. Assume memory is zero initialized, which will better support adding fields to struct map in the future and was already the case for map__new2. To reduce complexity, change set_priv and set_erange_warned to not take a value to assign as they always assign true. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/builtin-top.c | 2 +- tools/perf/tests/vmlinux-kallsyms.c | 4 ++-- tools/perf/util/map.c | 24 ++++++++++++------------ tools/perf/util/map.h | 11 ++++------- 4 files changed, 19 insertions(+), 22 deletions(-) diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index 881b861c35ee..724a79386321 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -191,7 +191,7 @@ static void ui__warn_map_erange(struct map *map, struct= symbol *sym, u64 ip) if (use_browser <=3D 0) sleep(5); =20 - map__set_erange_warned(map, true); + map__set_erange_warned(map); } =20 static void perf_top__record_precise_ip(struct perf_top *top, diff --git a/tools/perf/tests/vmlinux-kallsyms.c b/tools/perf/tests/vmlinux= -kallsyms.c index cd3b480d20bd..74cdbd2ce9d0 100644 --- a/tools/perf/tests/vmlinux-kallsyms.c +++ b/tools/perf/tests/vmlinux-kallsyms.c @@ -131,7 +131,7 @@ static int test__vmlinux_matches_kallsyms_cb1(struct ma= p *map, void *data) (dso__kernel(dso) ? dso__short_name(dso) : dso__name(dso))); =20 if (pair) { - map__set_priv(pair, 1); + map__set_priv(pair); map__put(pair); } else { if (!args->header_printed) { @@ -166,7 +166,7 @@ static int test__vmlinux_matches_kallsyms_cb2(struct ma= p *map, void *data) pr_info(":\nWARN: *%" PRIx64 "-%" PRIx64 " %" PRIx64, map__start(pair), map__end(pair), map__pgoff(pair)); pr_info(" %s\n", dso__name(dso)); - map__set_priv(pair, 1); + map__set_priv(pair); } map__put(pair); return 0; diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c index e1d14936a60d..e781c8d56a9a 100644 --- a/tools/perf/util/map.c +++ b/tools/perf/util/map.c @@ -102,16 +102,20 @@ static inline bool replace_android_lib(const char *fi= lename, char *newfilename) return false; } =20 -void map__init(struct map *map, u64 start, u64 end, u64 pgoff, struct dso = *dso) +static void map__init(struct map *map, u64 start, u64 end, u64 pgoff, + struct dso *dso, u32 prot, u32 flags) { map__set_start(map, start); map__set_end(map, end); map__set_pgoff(map, pgoff); - map__set_reloc(map, 0); + assert(map__reloc(map) =3D=3D 0); map__set_dso(map, dso__get(dso)); - map__set_mapping_type(map, MAPPING_TYPE__DSO); - map__set_erange_warned(map, false); refcount_set(map__refcnt(map), 1); + RC_CHK_ACCESS(map)->prot =3D prot; + RC_CHK_ACCESS(map)->flags =3D flags; + map__set_mapping_type(map, MAPPING_TYPE__DSO); + assert(map__erange_warned(map) =3D=3D false); + assert(map__priv(map) =3D=3D false); } =20 struct map *map__new(struct machine *machine, u64 start, u64 len, @@ -124,7 +128,7 @@ struct map *map__new(struct machine *machine, u64 start= , u64 len, struct nsinfo *nsi =3D NULL; struct nsinfo *nnsi; =20 - map =3D malloc(sizeof(*map)); + map =3D zalloc(sizeof(*map)); if (ADD_RC_CHK(result, map)) { char newfilename[PATH_MAX]; struct dso *dso, *header_bid_dso; @@ -134,8 +138,6 @@ struct map *map__new(struct machine *machine, u64 start= , u64 len, anon =3D is_anon_memory(filename) || flags & MAP_HUGETLB; vdso =3D is_vdso_map(filename); no_dso =3D is_no_dso_memory(filename); - map->prot =3D prot; - map->flags =3D flags; nsi =3D nsinfo__get(thread__nsinfo(thread)); =20 if ((anon || no_dso) && nsi && (prot & PROT_EXEC)) { @@ -169,7 +171,7 @@ struct map *map__new(struct machine *machine, u64 start= , u64 len, goto out_delete; =20 assert(!dso__kernel(dso)); - map__init(result, start, start + len, pgoff, dso); + map__init(result, start, start + len, pgoff, dso, prot, flags); =20 if (anon || no_dso) { map->mapping_type =3D MAPPING_TYPE__IDENTITY; @@ -223,10 +225,8 @@ struct map *map__new2(u64 start, struct dso *dso) =20 map =3D calloc(1, sizeof(*map) + (dso__kernel(dso) ? sizeof(struct kmap) = : 0)); if (ADD_RC_CHK(result, map)) { - /* - * ->end will be filled after we load all the symbols - */ - map__init(result, start, 0, 0, dso); + /* ->end will be filled after we load all the symbols. */ + map__init(result, start, /*end=3D*/0, /*pgoff=3D*/0, dso, /*prot=3D*/0, = /*flags=3D*/0); } =20 return result; diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h index 65e2609fa1b1..6c43f31a9fe0 100644 --- a/tools/perf/util/map.h +++ b/tools/perf/util/map.h @@ -166,9 +166,6 @@ struct thread; #define map__for_each_symbol_by_name(map, sym_name, pos, idx) \ __map__for_each_symbol_by_name(map, sym_name, (pos), idx) =20 -void map__init(struct map *map, - u64 start, u64 end, u64 pgoff, struct dso *dso); - struct dso_id; struct build_id; =20 @@ -285,14 +282,14 @@ static inline void map__set_reloc(struct map *map, u6= 4 reloc) RC_CHK_ACCESS(map)->reloc =3D reloc; } =20 -static inline void map__set_priv(struct map *map, int priv) +static inline void map__set_priv(struct map *map) { - RC_CHK_ACCESS(map)->priv =3D priv; + RC_CHK_ACCESS(map)->priv =3D true; } =20 -static inline void map__set_erange_warned(struct map *map, bool erange_war= ned) +static inline void map__set_erange_warned(struct map *map) { - RC_CHK_ACCESS(map)->erange_warned =3D erange_warned; + RC_CHK_ACCESS(map)->erange_warned =3D true; } =20 static inline void map__set_dso(struct map *map, struct dso *dso) --=20 2.46.0.184.g6999bdac58-goog From nobody Sat Feb 7 12:29:48 2026 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.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 5FDFA1422D2 for ; Sat, 17 Aug 2024 06:45:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723877110; cv=none; b=C0ssAjug6KjFjTloQiCnlvHaOHdpqcKh2fernckaQYtBisZKNDVMm9Q7nk0/kgvCQYfE+Ehwnu7nH+iVMSttPlBe5E2Of+NsZKNEkM5KAxoFepij8cMSkk7yijjXprjJ0I4jEuUij+h8H+sisNi8X1wNnX0ThMt6y16iDxLQSDc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723877110; c=relaxed/simple; bh=0zxhIml3fB+ZAPhpBZe1OmJSjv1p7ZchaNoCdcZ96uU=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=IARQ70LTJiP/WxGAU6AxuXvHzaVNXH7B76EzJU+s7IIkQIOEqNBsiYStAslfrdjrRRZGen/hpNeQT5BYhLpfuZFTA/P0haaj5vY+aTWMaJyNJKlNIsuokiQLzcGV3vrQ998ol4Q1XqFpbEfKWTr3taZ9EIqoVROvxjMCPL3lCZw= 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=oLhnyFIu; arc=none smtp.client-ip=209.85.219.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="oLhnyFIu" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e13cfd506b8so958071276.0 for ; Fri, 16 Aug 2024 23:45:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1723877108; x=1724481908; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=xGFdZ9DcdfWihKggJ77z6/NZRnt1NtgUjW3p1fvjlS8=; b=oLhnyFIur6uQ3j3wUWN89/hoy/IIY7d0aD7vjR1w7eYt0tHYTm7m6vQsXMogsOggar mvzU9lceDI2/5fheBTNdsLITOdz4R2+T3Bh/YCFda6gtmKFDMtcvrcn2NJ7wLWZiZXJx GQVOyUtpKQByj5T4J+hzYDCDSV3HWpEK85/Gg1fe+Wjl8W8zWxfFJX8xp/VAAMTdi3i2 9b0gl4S8OweVyV/ngECfOz23FQFaxss7HHvD11CGA8DaVvuCBEUVA1UO8sGAaoF5hjGB 4tTzt2scWpsruE0yUJy5PSP4Ipspik5T532h5djI6ZLJhrMDBr4phxHxZ5PbwXo73XMl 1etQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723877108; x=1724481908; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=xGFdZ9DcdfWihKggJ77z6/NZRnt1NtgUjW3p1fvjlS8=; b=T6GQWeJQeE8PFMhDjZ1xOcWFwvd2DjM+ruTOcH5Oah51Z5QOPhYjJgca7i2xwo/qqm Hr8xU2SotTDrf3p5bE5QW96AgMxFop9tAFaeUswouc15ToR9u+VHExwoCUSa1fuX//cR m6DgskyjduDd5xW1O+46FP3+IhyJsnUrAKQBeYQV3EhdpaCIslMTIsP84XtLQQtV8tP1 KWfiQBGKdH1ZFmNoVQnpzPYfYjIfxbLjigBAm68WylutPRT9/ZN39I+o2JH66mGcMrO+ 8bfYkKPzFpaVBdjpVJwX74xtVqh2Z1GIJdq+0mZIZOiQGZw4jCzK3aa1VICJoXp/SuOB rmvQ== X-Forwarded-Encrypted: i=1; AJvYcCUzU1UtOxMv/eCelFr3iHJnWo0s20EKUhJFdx8Way6ud9UDPJL0OTWg+cmJcPW24oSOjegH5lRPRFbugUrQs8Wg3RRaUAeHqkMwDqao X-Gm-Message-State: AOJu0YzTpYZszj138c9B0a2OqxGznf/petfLyo7HMaU3d4P1oH++yinQ hcViRyC5fQUz2Z18HeXZiWzwL/am9Qq6w44r5JdBO7zeAbkPpp7LyZfBhMrPo17oDo+FTBEPgJR nZLC8EA== X-Google-Smtp-Source: AGHT+IG4wRBLH0MwXQQb6vBslDjy0fDjEZYGtNBW1YLAD/9o/ZBpj4yYUkV3n9X4DRweyz5BIO2a6MW5rzni X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:78c9:5e58:734f:c59f]) (user=irogers job=sendgmr) by 2002:a25:8741:0:b0:e11:69f2:e39 with SMTP id 3f1490d57ef6-e1180f6c6e6mr271670276.9.1723877108430; Fri, 16 Aug 2024 23:45:08 -0700 (PDT) Date: Fri, 16 Aug 2024 23:44:32 -0700 In-Reply-To: <20240817064442.2152089-1-irogers@google.com> Message-Id: <20240817064442.2152089-4-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240817064442.2152089-1-irogers@google.com> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog Subject: [PATCH v1 03/13] perf jit: Constify filename argument 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 , Masahiro Yamada , Arnd Bergmann , Jann Horn , Colin Ian King , Casey Chen , Athira Rajeev , Chaitanya S Prakash , James Clark , Ze Gao , Yang Jihong , Yunseong Kim , Weilin Wang , Dominique Martinet , Anne Macedo , Sun Haiyong , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Make it clearer the argument is just being used as a string. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/util/jit.h | 3 ++- tools/perf/util/jitdump.c | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/jit.h b/tools/perf/util/jit.h index fb810e1b2de7..f4037203e9ec 100644 --- a/tools/perf/util/jit.h +++ b/tools/perf/util/jit.h @@ -5,7 +5,8 @@ #include =20 int jit_process(struct perf_session *session, struct perf_data *output, - struct machine *machine, char *filename, pid_t pid, pid_t tid, u64 *nbyt= es); + struct machine *machine, const char *filename, + pid_t pid, pid_t tid, u64 *nbytes); =20 int jit_inject_record(const char *filename); =20 diff --git a/tools/perf/util/jitdump.c b/tools/perf/util/jitdump.c index 5ce13653512b..346513e5e9b7 100644 --- a/tools/perf/util/jitdump.c +++ b/tools/perf/util/jitdump.c @@ -710,7 +710,7 @@ jit_process_dump(struct jit_buf_desc *jd) } =20 static int -jit_inject(struct jit_buf_desc *jd, char *path) +jit_inject(struct jit_buf_desc *jd, const char *path) { int ret; =20 @@ -737,7 +737,7 @@ jit_inject(struct jit_buf_desc *jd, char *path) * as captured in the RECORD_MMAP record */ static int -jit_detect(char *mmap_name, pid_t pid, struct nsinfo *nsi) +jit_detect(const char *mmap_name, pid_t pid, struct nsinfo *nsi) { char *p; char *end =3D NULL; @@ -821,7 +821,7 @@ int jit_process(struct perf_session *session, struct perf_data *output, struct machine *machine, - char *filename, + const char *filename, pid_t pid, pid_t tid, u64 *nbytes) --=20 2.46.0.184.g6999bdac58-goog From nobody Sat Feb 7 12:29:48 2026 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.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 DDDB8F507 for ; Sat, 17 Aug 2024 06:45:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723877113; cv=none; b=O7W1UMRQUa8Ywx8UwkJ4JW+mWc87u/VGkDtPm0RxXfzaPidUxHKxHTjJ/ZVlVkdUkO9JjbB9BaPLHmtVST9VR7CUvn1w9tNE9KvyhinKbrNuI+E806jBBi3oQc2WxqXhVMc6hEzwuIixA435sFtAtUpAZ2ULkkaKhl49ebBYYAU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723877113; c=relaxed/simple; bh=vaGNKEiJXAzzF4hjfF7Oz41w5agr1IFSb6If7kSm75Q=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=hq0mYDaQ0IuRNjD9YpUwQLlQ+IbsLlnQ1DEyXbHTkp1KokG24tnHIXzAIyQxvNlcbmv+MEieOr/1EwD6NAq09UH0B4TR2r7DzHgzy3Qe8olnzYMpXFcj8P7vDRIWhiiCQwuWb8FwQc3IVyXBUAXsejNG0x9yTBtmaABCY2HoE9k= 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=i+V14js1; arc=none smtp.client-ip=209.85.128.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="i+V14js1" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6b44f75f886so12277017b3.1 for ; Fri, 16 Aug 2024 23:45:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1723877111; x=1724481911; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=5r7bnvRFUBWrS5kWDeEcwFQiANlYqgPSEcymYDkpBqs=; b=i+V14js1oSvZxMz89m0m/dMRtXO5O7f0ffJKXO/Fqv4rHKu7Eojj9Uctc21x0fL7zA 8mAYWLkw/HW1VAkMrhC0khpzzyneyDgjDfLKYxQyZ0kSoAxCg3YAeF1tdO1Y5uZACzLV kQrvpEcE1qU4400OOsONvpc/zND3lUkmhmz8wFYtLMHG7BkkJnrtx+PCEzM055QV8Gdv L8t0RpcfysrQrMqo9Pjqb0NW/2hnJez6qEGnQRRQp079Q91eaIQS9hEowK6diC/1b4Ve uNVmJWr0NKtKdnQP6qK5UgPYra6rkRmZbWmd0bQS2vSwnKuAwXkkNCjpMu7iyvK5cW9b zlHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723877111; x=1724481911; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=5r7bnvRFUBWrS5kWDeEcwFQiANlYqgPSEcymYDkpBqs=; b=QSspIfD339RjuTLHRNhxpwk1zrkb5pNqD+kG1WLbWQPpFHeSf2MZzKfTMkcpC0mN/k 5TkqdHdOdtAj5fr5HpUoxOmTV/BdxbtTeBhC6ztxGrZrHIK9fhqEBLVViO8Uxu8bD8O4 MxKs4T7n2lvCd7w51sIfZjCrUFiKaxhcH5YDAIR1S8hj2/AFJkhO4vnNFWoEv3k8AG6X mBd6R9HhDQq7TLJuJBYP9FT9XmSYgM9AsZSscQ2kUtyb6ocXnfs6jqMpFFBJVGCLCKcr iBqyNcNEjaMbmKeXV1v+N28dQcTBvyI8X3C3Jj6IoFpRfO863ZbOc1y+QBdyKocmuEPg 74KA== X-Forwarded-Encrypted: i=1; AJvYcCU2q30n1Pq1pmk6o/VP2UFykYht14Zd93MFVrKKL8N8wqF5LIQGQzpiXNIgBim8dUo7yuYSkiLRgHXUVQMaKTKGFL5tJ/r6nZa2HtnX X-Gm-Message-State: AOJu0YzvkLaDxliVEBwSCVYOmj/tdYxK0OEPfk/iWLIgBCJfO55Pd2+H XiIJ/DmGomrgVMacLCKedCEeiXJsDYcsxLKUUASDDUgXjiBRVuor+MJxZaKVvPKPm5bzdpOXSew pcUBnlA== X-Google-Smtp-Source: AGHT+IGlcPF2a10mg0azJ+yMp/FA6xLrTtvwRfHpENN3NxES0vbVTMocPo1rsrKU6ZIuhjb7odPV92DivNS3 X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:78c9:5e58:734f:c59f]) (user=irogers job=sendgmr) by 2002:a05:690c:2b13:b0:673:b39a:92f2 with SMTP id 00721157ae682-6b1baeae4ccmr292407b3.7.1723877110786; Fri, 16 Aug 2024 23:45:10 -0700 (PDT) Date: Fri, 16 Aug 2024 23:44:33 -0700 In-Reply-To: <20240817064442.2152089-1-irogers@google.com> Message-Id: <20240817064442.2152089-5-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240817064442.2152089-1-irogers@google.com> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog Subject: [PATCH v1 04/13] perf dso: Constify dso_id 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 , Masahiro Yamada , Arnd Bergmann , Jann Horn , Colin Ian King , Casey Chen , Athira Rajeev , Chaitanya S Prakash , James Clark , Ze Gao , Yang Jihong , Yunseong Kim , Weilin Wang , Dominique Martinet , Anne Macedo , Sun Haiyong , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The passed dso_id is copied and so is never an out argument. Remove its mutability. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/builtin-inject.c | 2 +- tools/perf/util/dso.c | 4 ++-- tools/perf/util/dso.h | 4 ++-- tools/perf/util/dsos.c | 12 ++++++------ tools/perf/util/dsos.h | 2 +- tools/perf/util/machine.c | 3 ++- tools/perf/util/machine.h | 3 ++- 7 files changed, 16 insertions(+), 14 deletions(-) diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index a35bde3f3c09..8440ddfbf4fe 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -411,7 +411,7 @@ static int perf_event__jit_repipe_mmap(const struct per= f_tool *tool, #endif =20 static struct dso *findnew_dso(int pid, int tid, const char *filename, - struct dso_id *id, struct machine *machine) + const struct dso_id *id, struct machine *machine) { struct thread *thread; struct nsinfo *nsi =3D NULL; diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c index 67414944f245..5c6e85fdae0d 100644 --- a/tools/perf/util/dso.c +++ b/tools/perf/util/dso.c @@ -1327,7 +1327,7 @@ bool dso_id__empty(const struct dso_id *id) return !id->maj && !id->min && !id->ino && !id->ino_generation; } =20 -void __dso__inject_id(struct dso *dso, struct dso_id *id) +void __dso__inject_id(struct dso *dso, const struct dso_id *id) { struct dsos *dsos =3D dso__dsos(dso); struct dso_id *dso_id =3D dso__id(dso); @@ -1417,7 +1417,7 @@ void dso__set_sorted_by_name(struct dso *dso) RC_CHK_ACCESS(dso)->sorted_by_name =3D true; } =20 -struct dso *dso__new_id(const char *name, struct dso_id *id) +struct dso *dso__new_id(const char *name, const struct dso_id *id) { RC_STRUCT(dso) *dso =3D zalloc(sizeof(*dso) + strlen(name) + 1); struct dso *res; diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h index ed0068251c65..bb8e8f444054 100644 --- a/tools/perf/util/dso.h +++ b/tools/perf/util/dso.h @@ -640,14 +640,14 @@ static inline void dso__set_text_offset(struct dso *d= so, u64 val) int dso_id__cmp(const struct dso_id *a, const struct dso_id *b); bool dso_id__empty(const struct dso_id *id); =20 -struct dso *dso__new_id(const char *name, struct dso_id *id); +struct dso *dso__new_id(const char *name, const struct dso_id *id); struct dso *dso__new(const char *name); void dso__delete(struct dso *dso); =20 int dso__cmp_id(struct dso *a, struct dso *b); void dso__set_short_name(struct dso *dso, const char *name, bool name_allo= cated); void dso__set_long_name(struct dso *dso, const char *name, bool name_alloc= ated); -void __dso__inject_id(struct dso *dso, struct dso_id *id); +void __dso__inject_id(struct dso *dso, const struct dso_id *id); =20 int dso__name_len(const struct dso *dso); =20 diff --git a/tools/perf/util/dsos.c b/tools/perf/util/dsos.c index d4acdb37f046..e0998e2a7c4e 100644 --- a/tools/perf/util/dsos.c +++ b/tools/perf/util/dsos.c @@ -155,7 +155,7 @@ static int dsos__cmp_key_long_name_id(const void *vkey,= const void *vdso) */ static struct dso *__dsos__find_by_longname_id(struct dsos *dsos, const char *name, - struct dso_id *id, + const struct dso_id *id, bool write_locked) { struct dsos__key key =3D { @@ -244,7 +244,7 @@ int dsos__add(struct dsos *dsos, struct dso *dso) =20 struct dsos__find_id_cb_args { const char *name; - struct dso_id *id; + const struct dso_id *id; struct dso *res; }; =20 @@ -260,7 +260,7 @@ static int dsos__find_id_cb(struct dso *dso, void *data) =20 } =20 -static struct dso *__dsos__find_id(struct dsos *dsos, const char *name, st= ruct dso_id *id, +static struct dso *__dsos__find_id(struct dsos *dsos, const char *name, co= nst struct dso_id *id, bool cmp_short, bool write_locked) { struct dso *res; @@ -321,7 +321,7 @@ static void dso__set_basename(struct dso *dso) dso__set_short_name(dso, base, true); } =20 -static struct dso *__dsos__addnew_id(struct dsos *dsos, const char *name, = struct dso_id *id) +static struct dso *__dsos__addnew_id(struct dsos *dsos, const char *name, = const struct dso_id *id) { struct dso *dso =3D dso__new_id(name, id); =20 @@ -337,7 +337,7 @@ static struct dso *__dsos__addnew_id(struct dsos *dsos,= const char *name, struct return dso; } =20 -static struct dso *__dsos__findnew_id(struct dsos *dsos, const char *name,= struct dso_id *id) +static struct dso *__dsos__findnew_id(struct dsos *dsos, const char *name,= const struct dso_id *id) { struct dso *dso =3D __dsos__find_id(dsos, name, id, false, /*write_locked= =3D*/true); =20 @@ -347,7 +347,7 @@ static struct dso *__dsos__findnew_id(struct dsos *dsos= , const char *name, struc return dso ? dso : __dsos__addnew_id(dsos, name, id); } =20 -struct dso *dsos__findnew_id(struct dsos *dsos, const char *name, struct d= so_id *id) +struct dso *dsos__findnew_id(struct dsos *dsos, const char *name, const st= ruct dso_id *id) { struct dso *dso; down_write(&dsos->lock); diff --git a/tools/perf/util/dsos.h b/tools/perf/util/dsos.h index 6c13b65648bc..a26774950866 100644 --- a/tools/perf/util/dsos.h +++ b/tools/perf/util/dsos.h @@ -32,7 +32,7 @@ int __dsos__add(struct dsos *dsos, struct dso *dso); int dsos__add(struct dsos *dsos, struct dso *dso); struct dso *dsos__find(struct dsos *dsos, const char *name, bool cmp_short= ); =20 -struct dso *dsos__findnew_id(struct dsos *dsos, const char *name, struct d= so_id *id); +struct dso *dsos__findnew_id(struct dsos *dsos, const char *name, const st= ruct dso_id *id); =20 bool dsos__read_build_ids(struct dsos *dsos, bool with_hits); =20 diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index c08774d06d14..cd79a830abae 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -3128,7 +3128,8 @@ u8 machine__addr_cpumode(struct machine *machine, u8 = cpumode, u64 addr) return addr_cpumode; } =20 -struct dso *machine__findnew_dso_id(struct machine *machine, const char *f= ilename, struct dso_id *id) +struct dso *machine__findnew_dso_id(struct machine *machine, const char *f= ilename, + const struct dso_id *id) { return dsos__findnew_id(&machine->dsos, filename, id); } diff --git a/tools/perf/util/machine.h b/tools/perf/util/machine.h index 82a47bac8023..a687876e3453 100644 --- a/tools/perf/util/machine.h +++ b/tools/perf/util/machine.h @@ -207,7 +207,8 @@ int machine__nr_cpus_avail(struct machine *machine); =20 struct thread *machine__findnew_thread(struct machine *machine, pid_t pid,= pid_t tid); =20 -struct dso *machine__findnew_dso_id(struct machine *machine, const char *f= ilename, struct dso_id *id); +struct dso *machine__findnew_dso_id(struct machine *machine, const char *f= ilename, + const struct dso_id *id); struct dso *machine__findnew_dso(struct machine *machine, const char *file= name); =20 size_t machine__fprintf(struct machine *machine, FILE *fp); --=20 2.46.0.184.g6999bdac58-goog From nobody Sat Feb 7 12:29:48 2026 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 65F0E13D533 for ; Sat, 17 Aug 2024 06:45:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723877115; cv=none; b=HZYDWVzXz9+Bk0lAzvSS4uitARB8QwjxxRtX3XGlsGZPseTtTKY/bgPCmMLHjYPb1Te2fWMrj4GeASXK7Qq+dEvze+V/cMNroFFY0O7BSbeYpaGLXuNfGYtQtQvaE8xfxS2D52gMalVz29PtFnMoIYGGNRWIBSrcwTsVB5mEMRY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723877115; c=relaxed/simple; bh=Rb69KRKaI/u5A/8MYxV4P2TpQD+CHCaIYh533YAFMbc=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=quh2x+ZjlF1BFqS7zJkJ3BahKgVmz/azV+lvRQEoY9RjPQW+RwHkJoqulhTKzdeBwIVBDgmIUxmYJypBNLxLmFyTupqhG5ljG042YPbMuDs4PWnmrkJQOUxfNSUauDz1YXKMvwHhJXVJBWNaSkxgpxj8VkX1ciZmA8zurMUPpEs= 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=KlcxmJZz; arc=none smtp.client-ip=209.85.128.202 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="KlcxmJZz" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6b46b3dcc96so10544877b3.1 for ; Fri, 16 Aug 2024 23:45:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1723877113; x=1724481913; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=oUA8AhsoJNih2SdQBlGMtrsJvyfXDO16nIF63MLLSZI=; b=KlcxmJZz8S+i/TH8jg3hz0ttl0oIxPnUV4uUqLYGfqVW3uDLklrA92+HBUTvyrmMVI P+QbhkLTIGi4F2K98HvTT1QWffNo/wc1iAALkNrQe0guhOMCvQs/6wl3tFoxU5xIP3qb 1TUyiw7i9wB88uhXvqWFS1i7KQxC5SijCT1JNsRT6Eu4g+Rai+5Gx8UCuEZ2VkjVNeVd NZ7D4UxrLl8b3RQmkaWCaA5+AqlqFeGJKulatdA8J86H6XPTzzCdvLCxTZ8Hq0vq9Cmy iMUlwMU5hMpNmui5mZsViaDqSmxeVztWg0o72GyMPCFG4V/kZAJLc2icGu+/gkV4cHbS hChA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723877113; x=1724481913; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=oUA8AhsoJNih2SdQBlGMtrsJvyfXDO16nIF63MLLSZI=; b=SiAMAs3BZBXFwYH3tocq2DqZmCZAhysTiERqvT2qiDTg8l4ZWKmV//AWfTcKokRaJu v9ZeMTzNHKh0OSnBr9J9GFOHZe01z3b4ZNRl1NZktUP+wp7h9P0HO4nJiaS6InGqdZKI FYY75aUXnhO7KPb7w/XBL2a4UR+IveMRYI7a0UoePAWqbCLmF0Afe8kXyuMHFmson8nB Z0HZtA4nE+cVm2zkArNgJaDwWWi4uUH2XqqOU4KbLOnCrxiAmbH1THZQg8URBP0Y10ae h/wbeog2FWboPd4VImv/b7l8KMvm2kbr5hAIGbLeWFnMSV5f+SHA9h2zSB4FTar62X/A PF7w== X-Forwarded-Encrypted: i=1; AJvYcCU6eTBK6cvzSo7V2qdjNzxx4h6/QItj8Wy562EzwDWf48/v6vRmlACOq+4YhcTypCmrLOfK/VzkK/fY+90+YGIazq7YDq/eaA9vkDFT X-Gm-Message-State: AOJu0Yw3oCMuDEdwUYFKJx439iMZRIqyZojW/7V1o0Akt7hHSn5i3qdZ Ofia29uPtfncONkhDOut+r6SvoZcY75ebd4YEARI9RkW5RlycG8xKoQmxMcnof8Gz8eO8WloypP 4IvIv/w== X-Google-Smtp-Source: AGHT+IF6UXe62Ch7dXHjA82oHLXQrRvck/l/nZacvEl3Mldvm/x0HxqD1wmw0YpclopA5YWKR3dSdsq8Yluo X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:78c9:5e58:734f:c59f]) (user=irogers job=sendgmr) by 2002:a05:690c:2e86:b0:65c:1db1:9235 with SMTP id 00721157ae682-6b1b16adf5fmr649637b3.0.1723877113170; Fri, 16 Aug 2024 23:45:13 -0700 (PDT) Date: Fri, 16 Aug 2024 23:44:34 -0700 In-Reply-To: <20240817064442.2152089-1-irogers@google.com> Message-Id: <20240817064442.2152089-6-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240817064442.2152089-1-irogers@google.com> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog Subject: [PATCH v1 05/13] perf evsel: Constify evsel__id_hdr_size argument 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 , Masahiro Yamada , Arnd Bergmann , Jann Horn , Colin Ian King , Casey Chen , Athira Rajeev , Chaitanya S Prakash , James Clark , Ze Gao , Yang Jihong , Yunseong Kim , Weilin Wang , Dominique Martinet , Anne Macedo , Sun Haiyong , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Allows evsel__id_hdr_size to be used when the evsel is const. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/util/evsel.c | 2 +- tools/perf/util/evsel.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 38a74d6dde49..49cc71511c0c 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -3048,7 +3048,7 @@ int evsel__parse_sample_timestamp(struct evsel *evsel= , union perf_event *event, return 0; } =20 -u16 evsel__id_hdr_size(struct evsel *evsel) +u16 evsel__id_hdr_size(const struct evsel *evsel) { u64 sample_type =3D evsel->core.attr.sample_type; u16 size =3D 0; diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 4316992f6a69..15acf293e12a 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -442,7 +442,7 @@ int evsel__parse_sample(struct evsel *evsel, union perf= _event *event, int evsel__parse_sample_timestamp(struct evsel *evsel, union perf_event *e= vent, u64 *timestamp); =20 -u16 evsel__id_hdr_size(struct evsel *evsel); +u16 evsel__id_hdr_size(const struct evsel *evsel); =20 static inline struct evsel *evsel__next(struct evsel *evsel) { --=20 2.46.0.184.g6999bdac58-goog From nobody Sat Feb 7 12:29:48 2026 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 3B33F14533F for ; Sat, 17 Aug 2024 06:45:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723877117; cv=none; b=DiPJsPFtw6VtLzkiwBfYNSAQdQIuxnWt+mw5yZ2dzgyQ5JaEy2TSAVLdEmVvhWzXJkElMWaD/QcPmmVNSmxhk9Y7b97nHm/ByMmY4Ex4b+KmaoGuKksbgwrcyv0C8OPBMHvd9TB8uKG5fdBYYiZDHmTWrIC7ICvvpDVSSgo0J7Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723877117; c=relaxed/simple; bh=svsXcTMaRqZcv7GQdX5SDwbX/PNPLJVnzNXlCv1HOwg=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=OIaiYAd/D5CquVhnn4IwAQQPuMWkxZSne6S+1ZAg7JCiGjr9a+TFEmVF0tedjrWGsLd9H6vZyBT7KmbBNqX7AJBMK99IuNaxdnLsPP5ZHNozyPj5u6nziKzsqQ0oeevg5sva7988yh8GjO3g280gyWsDCfURY1A5FKscXICZtNk= 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=o7F4B4a7; arc=none smtp.client-ip=209.85.128.202 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="o7F4B4a7" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6886cd07673so49592527b3.3 for ; Fri, 16 Aug 2024 23:45:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1723877115; x=1724481915; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=uiIb0LHFpPGuH8DbvZrhFnBLb6AIQ7thHhf5YFck8Ko=; b=o7F4B4a72LTF0ZtAZDSYFB+3PzHhy77VR9b9FUa0cGmPfKIU1iIk0Q6Pjt3IVk0oo+ 8wVCO6ZtlzbUh7gO93+SA3XsBMTaPBzliuHi6NJJFh0GiUnRfRaXy249BiFYo5Jkw6UO 9h/a6/5E3PBS6hqH2f/x93+yoPKqi6FfvgQGVoiVVBEF+oZ4cjygUyMNiHVHwazWWtDZ TO4uzD4Zov4gKgJTYqrBpSf0c0uBgO4zILHyTtbWMOogZ/k9+oj2Wzg9bd/awnTWoYyv baKuHGAjDKyYPlWJEHYWX85UB+BFjkVMpUqN1OX5qNxse89Iihrd+Nr3izoxfdWITSAy hSgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723877115; x=1724481915; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=uiIb0LHFpPGuH8DbvZrhFnBLb6AIQ7thHhf5YFck8Ko=; b=P+VdfCz6pfXv1r15qwj3VjTRJV3u6aHtUl5obHfXkgxrSINDAcjoddYpgklonppn4r tWYWCx2dFwxq568kueiEo4ZM7C2ErJ2dlpUNiN6BMx4FSyHu64gOK79WKBSEolJ2Ty42 pHafTqmMUQuK60VStrsI2oAKVc0OOn6fI8Vhb5ZQBs9I9Xf/KaBQyyuahY0x4qRHLopi yPR2suEV+5qc8RG/UwoeFb8Ok0T4BVcG1OuI7ewR6Glh0du6kkG6J1dB+hrXge9E2ks6 3toDhxcrJs/ZC0w20/W+UI65ecE13SLUMmQxmTATytJbYYzYhtE+7ljhxvjPPRvpK65P IoKA== X-Forwarded-Encrypted: i=1; AJvYcCXsPvN5Ql2dnd96XCsm54c6UOpNWTn74puzx28tnROgjrjYfwuE4BqLB9kscIi5fH7XZ9UJWAki735y3ECt5KtkR0ph/mGBCe/a/ypX X-Gm-Message-State: AOJu0Yx13HYhlx1Uw+waiRyliH4Lh8+1pMgKppBYUZ1Vqg8+dH6sZJNU CJ10mcpUQj1Xb2x1/MtYJZwZ1GNYsVOk8WmtjpnK14i5zL1YPdRpgxoOJXvXho9fyv79xKNc6f3 jngWisQ== X-Google-Smtp-Source: AGHT+IHpIQH3Z4+neJvbwuE+BMqXxfg4n05M1ztGFk7NZrFg4BazntZ8QBZQfcIgDAHYHp5Rx83a8q7z27Ab X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:78c9:5e58:734f:c59f]) (user=irogers job=sendgmr) by 2002:a05:690c:2f0b:b0:6ad:9825:6a2f with SMTP id 00721157ae682-6b1b6cb7a10mr534947b3.1.1723877115221; Fri, 16 Aug 2024 23:45:15 -0700 (PDT) Date: Fri, 16 Aug 2024 23:44:35 -0700 In-Reply-To: <20240817064442.2152089-1-irogers@google.com> Message-Id: <20240817064442.2152089-7-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240817064442.2152089-1-irogers@google.com> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog Subject: [PATCH v1 06/13] perf test: Expand pipe/inject test 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 , Masahiro Yamada , Arnd Bergmann , Jann Horn , Colin Ian King , Casey Chen , Athira Rajeev , Chaitanya S Prakash , James Clark , Ze Gao , Yang Jihong , Yunseong Kim , Weilin Wang , Dominique Martinet , Anne Macedo , Sun Haiyong , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Test recording of call-graphs and injecting --build-all. Add/expand trap handler. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/tests/shell/pipe_test.sh | 101 ++++++++++++++++++++++------ 1 file changed, 79 insertions(+), 22 deletions(-) diff --git a/tools/perf/tests/shell/pipe_test.sh b/tools/perf/tests/shell/p= ipe_test.sh index a78d35d2cff0..ad10012fdc29 100755 --- a/tools/perf/tests/shell/pipe_test.sh +++ b/tools/perf/tests/shell/pipe_test.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # perf pipe recording and injection test # SPDX-License-Identifier: GPL-2.0 =20 @@ -12,30 +12,87 @@ skip_test_missing_symbol ${sym} =20 data=3D$(mktemp /tmp/perf.data.XXXXXX) prog=3D"perf test -w noploop" -task=3D"perf" +err=3D0 =20 -if ! perf record -e task-clock:u -o - ${prog} | perf report -i - --task | = grep ${task}; then - echo "cannot find the test file in the perf report" - exit 1 -fi +set -e =20 -if ! perf record -e task-clock:u -o - ${prog} | perf inject -b | perf repo= rt -i - | grep ${sym}; then - echo "cannot find noploop function in pipe #1" - exit 1 -fi +cleanup() { + rm -rf "${data}" + rm -rf "${data}".old =20 -perf record -e task-clock:u -o - ${prog} | perf inject -b -o ${data} -if ! perf report -i ${data} | grep ${sym}; then - echo "cannot find noploop function in pipe #2" - exit 1 -fi + trap - EXIT TERM INT +} =20 -perf record -e task-clock:u -o ${data} ${prog} -if ! perf inject -b -i ${data} | perf report -i - | grep ${sym}; then - echo "cannot find noploop function in pipe #3" - exit 1 -fi +trap_cleanup() { + echo "Unexpected signal in ${FUNCNAME[1]}" + cleanup + exit 1 +} +trap trap_cleanup EXIT TERM INT =20 +test_record_report() { + echo + echo "Record+report pipe test" + + task=3D"perf" + if ! perf record -e task-clock:u -o - ${prog} | perf report -i - --task = | grep -q ${task} + then + echo "Record+report pipe test [Failed - cannot find the test file in t= he perf report #1]" + err=3D1 + return + fi + + if ! perf record -g -e task-clock:u -o - ${prog} | perf report -i - --ta= sk | grep -q ${task} + then + echo "Record+report pipe test [Failed - cannot find the test file in t= he perf report #2]" + err=3D1 + return + fi + + echo "Record+report pipe test [Success]" +} + +test_inject_bids() { + inject_opt=3D$1 + + echo + echo "Inject ${inject_opt} build-ids test" + + if ! perf record -e task-clock:u -o - ${prog} | perf inject ${inject_opt= }| perf report -i - | grep -q ${sym} + then + echo "Inject build-ids test [Failed - cannot find noploop function in = pipe #1]" + err=3D1 + return + fi + + if ! perf record -g -e task-clock:u -o - ${prog} | perf inject ${inject_= opt} | perf report -i - | grep -q ${sym} + then + echo "Inject ${inject_opt} build-ids test [Failed - cannot find noploo= p function in pipe #2]" + err=3D1 + return + fi + + perf record -e task-clock:u -o - ${prog} | perf inject ${inject_opt} -o = ${data} + if ! perf report -i ${data} | grep -q ${sym}; then + echo "Inject ${inject_opt} build-ids test [Failed - cannot find noploo= p function in pipe #3]" + err=3D1 + return + fi + + perf record -e task-clock:u -o ${data} ${prog} + if ! perf inject ${inject_opt} -i ${data} | perf report -i - | grep -q $= {sym}; then + echo "Inject ${inject_opt} build-ids test [Failed - cannot find noploo= p function in pipe #4]" + err=3D1 + return + fi + + echo "Inject ${inject_opt} build-ids test [Success]" +} + +test_record_report +test_inject_bids -b +test_inject_bids --buildid-all + +cleanup +exit $err =20 -rm -f ${data} ${data}.old -exit 0 --=20 2.46.0.184.g6999bdac58-goog From nobody Sat Feb 7 12:29:48 2026 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 7C85D145FEB for ; Sat, 17 Aug 2024 06:45:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723877120; cv=none; b=iysl+IYl1U04r3r+ZNa73enbdPuDozd+6s1Ic1JxuW+MYeV5wnnMi999w92XZvygP6F3EI1eYTNibc+V7JijsaPXicLPPBCvlU37kUx9ptETMv1Hsy1c9XYu5cPwB3+v2NJa64H2RvrGKqKOQ9Fg/KBmDK0v1OxMR+PPSsVuiTw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723877120; c=relaxed/simple; bh=pRY5AZfCbwpYgGVAWMLYaicbhD2xuRtNblur1R1C4z8=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=hJzwuz6CS59TsY+TMnweb1jA9Dbyr9QfqBxcP3lxXPyvfYReB35e5sYVR/eaKH6eJ9uTTVe7dGka1q8H6nDtP9lbdEgObUAIUNZTu0F2m7DOhwL6Bh/0nczTbX8tKd09EzQUdyF0hGgG37lZLfICNkV8c5e9AcgNkms2p2ByKdM= 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=FCi8ExA4; arc=none smtp.client-ip=209.85.128.202 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="FCi8ExA4" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6acf8ac7569so52015297b3.3 for ; Fri, 16 Aug 2024 23:45:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1723877117; x=1724481917; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=wAJzyWm13hc0XphEnwse3Fp8/0A+sQVmN1fNLb1gecE=; b=FCi8ExA4ISx306zIPeeadGugF1ffeTgK9NRLZR45pqPkb3ew/4cMCajkVfwlvGtrLi 8LAOn+3rMhGElMx5KinBcs/qYIy69XPbLZNnpdjhv//wLxQoa+xuag1xalQby9Y0i2cn 5Ws1oHZF/Ip0TV7Zhsk6SR1wrrMl2ZiKLMzBPtigsHI0/KdAQMJfbYmm/pwSoEY4xAh3 z2CbckixxoHReN80WBC0oz0+MOiIPmHN9CUsRyMcqkLsGZ1gRuFi7XbATSfGMnPZuEgy Bf8A102E0NpL1Du37P5AkU+aPsI7KvbMgqrewR4gNP5E/gWzHnwgqqas4TPSwfatjkkN i/LA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723877117; x=1724481917; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=wAJzyWm13hc0XphEnwse3Fp8/0A+sQVmN1fNLb1gecE=; b=PzSnKtsdhHmH+yhzwPz0UDyhc8/7XAE+okWG/j+ngv91ZBgH4c8U1oQYWf2oMeKgFL jfSZ1T8C1lmAx3lc8yq7AKtBJrwSfHW3pA+YqQXLy+p2Om2NPc1wmkHOpPIxoEQ1Xbsz 7Ix7azEZrUVThJW8xh3qf7kCSzaJjekcIVLnCREhCy5XqldvjPjg2k7AUQBh3OpkZS8I q1DhbWm4VkYe7puKR0J2Ty7hxaHX7F2HUrNMMHCbBreFN4v8zQ/PLpTlQ+xnr3kq/Pzi n+HtmGxs08acMMlCxTieSogh6Q6JVbz+HRlYFch5Kx/HTaoA3V5hek2KkRbXUhvFzk8i O5BQ== X-Forwarded-Encrypted: i=1; AJvYcCXU8O/uzD3r6vRufFDPIadSeBuTr1HbJPWEtfwXVBYx6IQXOpHuoRh+3lKoLSzy8WTtp1XZIM4baB1sGJ80GDBKtJcyBD/4nRLEIahF X-Gm-Message-State: AOJu0YyLigwvG5E9mkdVYIkcwFGMUSBWxHtMiI0K8sRVBXSJnE8miv9I JkLeanzwEu9p+90gg9NxGno/tuQtlDRXiGN48D5ZwmXQNyBgZ7Bl512ySdzvAc2LYEwCx6IAvV0 ItFhmXA== X-Google-Smtp-Source: AGHT+IH7Yu232gNnniV3EHstk3fBHEEIjNkNXlA2pzSz4OdB3zq/IUPHPuAWRECkAxMJmLLflc2sJAA69/1d X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:78c9:5e58:734f:c59f]) (user=irogers job=sendgmr) by 2002:a05:690c:4606:b0:691:2f66:4b1c with SMTP id 00721157ae682-6b1baeadc0amr594057b3.6.1723877117487; Fri, 16 Aug 2024 23:45:17 -0700 (PDT) Date: Fri, 16 Aug 2024 23:44:36 -0700 In-Reply-To: <20240817064442.2152089-1-irogers@google.com> Message-Id: <20240817064442.2152089-8-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240817064442.2152089-1-irogers@google.com> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog Subject: [PATCH v1 07/13] perf inject: Combine build_ids and build_id_all into enum 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 , Masahiro Yamada , Arnd Bergmann , Jann Horn , Colin Ian King , Casey Chen , Athira Rajeev , Chaitanya S Prakash , James Clark , Ze Gao , Yang Jihong , Yunseong Kim , Weilin Wang , Dominique Martinet , Anne Macedo , Sun Haiyong , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" It is clearer to have a single enum that determines how build ids are injected, it also allows for future extension. Set the header build ID feature whether lazy or all are generated, previously only the lazy case would set it. Allow parsing of known build IDs for either the lazy or all cases. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/builtin-inject.c | 51 ++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index 8440ddfbf4fe..865d16ceead2 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -103,11 +103,16 @@ struct guest_session { struct guest_event ev; }; =20 +enum build_id_rewrite_style { + BID_RWS__NONE =3D 0, + BID_RWS__INJECT_HEADER_LAZY, + BID_RWS__INJECT_HEADER_ALL, +}; + struct perf_inject { struct perf_tool tool; struct perf_session *session; - bool build_ids; - bool build_id_all; + enum build_id_rewrite_style build_id_style; bool sched_stat; bool have_auxtrace; bool strip; @@ -2015,8 +2020,8 @@ static int __cmd_inject(struct perf_inject *inject) =20 signal(SIGINT, sig_handler); =20 - if (inject->build_ids || inject->sched_stat || - inject->itrace_synth_opts.set || inject->build_id_all) { + if (inject->build_id_style !=3D BID_RWS__NONE || inject->sched_stat || + inject->itrace_synth_opts.set) { inject->tool.mmap =3D perf_event__repipe_mmap; inject->tool.mmap2 =3D perf_event__repipe_mmap2; inject->tool.fork =3D perf_event__repipe_fork; @@ -2027,10 +2032,10 @@ static int __cmd_inject(struct perf_inject *inject) =20 output_data_offset =3D perf_session__data_offset(session->evlist); =20 - if (inject->build_id_all) { + if (inject->build_id_style =3D=3D BID_RWS__INJECT_HEADER_ALL) { inject->tool.mmap =3D perf_event__repipe_buildid_mmap; inject->tool.mmap2 =3D perf_event__repipe_buildid_mmap2; - } else if (inject->build_ids) { + } else if (inject->build_id_style =3D=3D BID_RWS__INJECT_HEADER_LAZY) { inject->tool.sample =3D perf_event__inject_buildid; } else if (inject->sched_stat) { struct evsel *evsel; @@ -2148,9 +2153,9 @@ static int __cmd_inject(struct perf_inject *inject) .inject =3D inject, }; =20 - if (inject->build_ids) - perf_header__set_feat(&session->header, - HEADER_BUILD_ID); + if (inject->build_id_style =3D=3D BID_RWS__INJECT_HEADER_LAZY || + inject->build_id_style =3D=3D BID_RWS__INJECT_HEADER_ALL) + perf_header__set_feat(&session->header, HEADER_BUILD_ID); /* * Keep all buildids when there is unprocessed AUX data because * it is not known which ones the AUX trace hits. @@ -2211,11 +2216,13 @@ int cmd_inject(int argc, const char **argv) int ret; bool repipe =3D true; const char *known_build_ids =3D NULL; + bool build_ids; + bool build_id_all; =20 struct option options[] =3D { - OPT_BOOLEAN('b', "build-ids", &inject.build_ids, + OPT_BOOLEAN('b', "build-ids", &build_ids, "Inject build-ids into the output stream"), - OPT_BOOLEAN(0, "buildid-all", &inject.build_id_all, + OPT_BOOLEAN(0, "buildid-all", &build_id_all, "Inject build-ids of all DSOs into the output stream"), OPT_STRING(0, "known-build-ids", &known_build_ids, "buildid path [,buildid path...]", @@ -2313,6 +2320,10 @@ int cmd_inject(int argc, const char **argv) return -1; } } + if (build_ids) + inject.build_id_style =3D BID_RWS__INJECT_HEADER_LAZY; + if (build_id_all) + inject.build_id_style =3D BID_RWS__INJECT_HEADER_ALL; =20 data.path =3D inject.input_name; if (!strcmp(inject.input_name, "-") || inject.output.is_pipe) { @@ -2326,7 +2337,7 @@ int cmd_inject(int argc, const char **argv) repipe =3D false; } ordered_events =3D inject.jit_mode || inject.sched_stat || - (inject.build_ids && !inject.build_id_all); + (inject.build_id_style =3D=3D BID_RWS__INJECT_HEADER_LAZY); perf_tool__init(&inject.tool, ordered_events); inject.tool.sample =3D perf_event__repipe_sample; inject.tool.read =3D perf_event__repipe_sample; @@ -2398,7 +2409,7 @@ int cmd_inject(int argc, const char **argv) goto out_delete; } =20 - if (inject.build_ids && !inject.build_id_all) { + if (inject.build_id_style =3D=3D BID_RWS__INJECT_HEADER_LAZY) { /* * to make sure the mmap records are ordered correctly * and so that the correct especially due to jitted code @@ -2406,14 +2417,14 @@ int cmd_inject(int argc, const char **argv) * inject the jit mmaps at the same time for now. */ inject.tool.ordering_requires_timestamps =3D true; - if (known_build_ids !=3D NULL) { - inject.known_build_ids =3D - perf_inject__parse_known_build_ids(known_build_ids); + } + if (inject.build_id_style !=3D BID_RWS__NONE && known_build_ids !=3D NULL= ) { + inject.known_build_ids =3D + perf_inject__parse_known_build_ids(known_build_ids); =20 - if (inject.known_build_ids =3D=3D NULL) { - pr_err("Couldn't parse known build ids.\n"); - goto out_delete; - } + if (inject.known_build_ids =3D=3D NULL) { + pr_err("Couldn't parse known build ids.\n"); + goto out_delete; } } =20 --=20 2.46.0.184.g6999bdac58-goog From nobody Sat Feb 7 12:29:48 2026 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.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 B11F214659D for ; Sat, 17 Aug 2024 06:45:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723877122; cv=none; b=KbhmMVwvNAMB7bKAlwq8aQCTH8oGHt+vual5GcAEHUZcc4Roegt7/kA5u6e+IPC8Jv4Acp3UBJqIa3Gve6hDIYgUE1434Rh2TEXOUF/bFrM4qHWD/drAQACRd+CSE2Li5wXGF1rM8wLmhQlwVozsPplYM//139u8FAxWTpSIR14= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723877122; c=relaxed/simple; bh=WW1VpISX2ocellr2odfdikhDznsZtCHPvqIBB2Ouivw=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=ua+YBFSSEsawe6HJGr07x6xUMAUr+TUrV6ILw227Fh03C3g7lxTy/kmI7ufGLfA3mg37wCjBFTq++IVHknuiiau4CQ3rCo62GLWSbQKcf+v2DwJiEAWjX8WDHedh8Ep9UAKMfoAIecQNsVDww8ULs+97Y21podOhd2NBS3np9zA= 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=FQWMugF3; arc=none smtp.client-ip=209.85.219.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="FQWMugF3" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e116c697904so4991169276.1 for ; Fri, 16 Aug 2024 23:45:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1723877120; x=1724481920; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=CgTxrjJSN3UEpj2V6TaLEsH3nbDGy1R5SWod1sFWZ8c=; b=FQWMugF39G5RanQ9cS21+F0MOil3LvrnnI6Mhjqo1xUlCz3mUN7PqDJiz6gAhAznaz 7JTWSqmrWTYBvED/TxY0vt5I8qgQ+QoKwg4fp+RcEqLidWg/DgvOEybLofOh7RVywacn kl/3tY+xb/bhJ+DJuitA0V4lVADn31e4eGlYbC/3ccYEYEb4vx7xi5Zpdc888udcYjVv wUBt6C0bQjjVi8umAzCgNDcq05PnF/j5+0DX8LizkbTkk4JdB52I7hJ+lvK5yxp2Dp8v zwf98/XKhHdwzcekKYY26LW0vKcQuOVhQtRdZwW84GEAY9wPfYuOKYxQkCRTDP2l8D42 zZXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723877120; x=1724481920; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=CgTxrjJSN3UEpj2V6TaLEsH3nbDGy1R5SWod1sFWZ8c=; b=K3e8BxrOlNSLfMYjQjYkMpwTYyBeaYdyhn4TkrEdxzI6LLZmCbwDMyuegrY4WmiOeu v7MkuUL2evmkCgnEKQV1ImORbdQ3pQxuBSpN1JOixQ8jvLwk2/YTfTnKQkJAk83h//wJ 8XmKHMwK2wK4n4JNr9PwR3FnhDfu5TvMcZ3aK99RkyZfDSWdA2/PrrnhMlx6gl7ywEIn SK/sPXhUQwC+Kixo7gDy+s6hSEyOwHk9yGveeF17tlkXM1yzsp6SvWlhGKr3rGp0WkKg EvVqxAz7whRJ18UG82Mxknkf9gC26R2hWZurux96up9K6bxaEcR5JlxjW0cSCuybJ7zE z8Hg== X-Forwarded-Encrypted: i=1; AJvYcCVpA5xL4brha5JeFxXvNj9+wp3zt3e70mS/gCBh1I29TK8CtcdsDtVqZM16zneVOnigtakf0rJfa9GXByc9P8zgTQohEUdHEd9qEb4I X-Gm-Message-State: AOJu0YxmPE9qzDwhXtm8+UerGk2KCssdVjvkwJdYLLA3NmHudQfvCgSh YQii/USRLfPe3EK7MyZOvTLtqFNc30MexJHia9WELwSqbON5yc0EJzebCbVXLAjO9Y0frYmtlGl iiOTtrA== X-Google-Smtp-Source: AGHT+IERi9GSRMxTnykwrvZUawENrgJqpnxu9ZqGvySjlAvzwYvNnKXGoblaCJvhtARlkORt4uKlhsK9fAHn X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:78c9:5e58:734f:c59f]) (user=irogers job=sendgmr) by 2002:a25:83d0:0:b0:e11:584f:c2ca with SMTP id 3f1490d57ef6-e1180e8eb8emr212527276.6.1723877119735; Fri, 16 Aug 2024 23:45:19 -0700 (PDT) Date: Fri, 16 Aug 2024 23:44:37 -0700 In-Reply-To: <20240817064442.2152089-1-irogers@google.com> Message-Id: <20240817064442.2152089-9-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240817064442.2152089-1-irogers@google.com> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog Subject: [PATCH v1 08/13] perf inject: Combine different mmap and mmap2 functions 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 , Masahiro Yamada , Arnd Bergmann , Jann Horn , Colin Ian King , Casey Chen , Athira Rajeev , Chaitanya S Prakash , James Clark , Ze Gao , Yang Jihong , Yunseong Kim , Weilin Wang , Dominique Martinet , Anne Macedo , Sun Haiyong , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" There are repipe, build ID and JIT dump variants of the mmap and mmap2 repipe functions. The organization doesn't allow JIT dump to work with build ID injection and the structure is less than clear. Combine the function and enable the different behaviors based on ifs. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/builtin-inject.c | 199 ++++++++++++++---------------------- 1 file changed, 76 insertions(+), 123 deletions(-) diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index 865d16ceead2..d99868953ff2 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -377,44 +377,6 @@ static int perf_event__repipe_sample(const struct perf= _tool *tool, return perf_event__repipe_synth(tool, event); } =20 -static int perf_event__repipe_mmap(const struct perf_tool *tool, - union perf_event *event, - struct perf_sample *sample, - struct machine *machine) -{ - int err; - - err =3D perf_event__process_mmap(tool, event, sample, machine); - perf_event__repipe(tool, event, sample, machine); - - return err; -} - -#ifdef HAVE_JITDUMP -static int perf_event__jit_repipe_mmap(const struct perf_tool *tool, - union perf_event *event, - struct perf_sample *sample, - struct machine *machine) -{ - struct perf_inject *inject =3D container_of(tool, struct perf_inject, too= l); - u64 n =3D 0; - int ret; - - /* - * if jit marker, then inject jit mmaps and generate ELF images - */ - ret =3D jit_process(inject->session, &inject->output, machine, - event->mmap.filename, event->mmap.pid, event->mmap.tid, &n); - if (ret < 0) - return ret; - if (ret) { - inject->bytes_written +=3D n; - return 0; - } - return perf_event__repipe_mmap(tool, event, sample, machine); -} -#endif - static struct dso *findnew_dso(int pid, int tid, const char *filename, const struct dso_id *id, struct machine *machine) { @@ -460,114 +422,108 @@ static struct dso *findnew_dso(int pid, int tid, co= nst char *filename, return dso; } =20 -static int perf_event__repipe_buildid_mmap(const struct perf_tool *tool, - union perf_event *event, - struct perf_sample *sample, - struct machine *machine) -{ - struct dso *dso; - - dso =3D findnew_dso(event->mmap.pid, event->mmap.tid, - event->mmap.filename, NULL, machine); - - if (dso && !dso__hit(dso)) { - dso__set_hit(dso); - dso__inject_build_id(dso, tool, machine, sample->cpumode, 0); - } - dso__put(dso); - - return perf_event__repipe(tool, event, sample, machine); -} - -static int perf_event__repipe_mmap2(const struct perf_tool *tool, +static int perf_event__repipe_mmap(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, struct machine *machine) { - int err; + struct perf_inject *inject =3D container_of(tool, struct perf_inject, too= l); =20 - err =3D perf_event__process_mmap2(tool, event, sample, machine); - perf_event__repipe(tool, event, sample, machine); +#ifdef HAVE_JITDUMP + if (inject->jit_mode) { + u64 n =3D 0; + int ret; =20 - if (event->header.misc & PERF_RECORD_MISC_MMAP_BUILD_ID) { - struct dso *dso; + /* If jit marker, then inject jit mmaps and generate ELF images. */ + ret =3D jit_process(inject->session, &inject->output, machine, + event->mmap.filename, event->mmap.pid, event->mmap.tid, &n); + if (ret < 0) + return ret; + if (ret) { + inject->bytes_written +=3D n; + return 0; + } + } +#endif + if (inject->build_id_style =3D=3D BID_RWS__INJECT_HEADER_ALL) { + struct dso *dso =3D findnew_dso(event->mmap.pid, event->mmap.tid, + event->mmap.filename, NULL, machine); =20 - dso =3D findnew_dso(event->mmap2.pid, event->mmap2.tid, - event->mmap2.filename, NULL, machine); - if (dso) { - /* mark it not to inject build-id */ + if (dso && !dso__hit(dso)) { dso__set_hit(dso); + dso__inject_build_id(dso, tool, machine, sample->cpumode, 0); } dso__put(dso); - } + } else { + /* Create the thread, map, etc. Not done for the unordered inject all ca= se. */ + int err =3D perf_event__process_mmap(tool, event, sample, machine); =20 - return err; + if (err) + return err; + } + return perf_event__repipe(tool, event, sample, machine); } =20 -#ifdef HAVE_JITDUMP -static int perf_event__jit_repipe_mmap2(const struct perf_tool *tool, - union perf_event *event, - struct perf_sample *sample, - struct machine *machine) +static int perf_event__repipe_mmap2(const struct perf_tool *tool, + union perf_event *event, + struct perf_sample *sample, + struct machine *machine) { struct perf_inject *inject =3D container_of(tool, struct perf_inject, too= l); - u64 n =3D 0; - int ret; + struct dso *dso =3D NULL; =20 - /* - * if jit marker, then inject jit mmaps and generate ELF images - */ - ret =3D jit_process(inject->session, &inject->output, machine, - event->mmap2.filename, event->mmap2.pid, event->mmap2.tid, &n); - if (ret < 0) - return ret; - if (ret) { - inject->bytes_written +=3D n; - return 0; +#ifdef HAVE_JITDUMP + if (inject->jit_mode) { + u64 n =3D 0; + int ret; + + /* If jit marker, then inject jit mmaps and generate ELF images. */ + ret =3D jit_process(inject->session, &inject->output, machine, + event->mmap2.filename, event->mmap2.pid, event->mmap2.tid, &n); + if (ret < 0) + return ret; + if (ret) { + inject->bytes_written +=3D n; + return 0; + } } - return perf_event__repipe_mmap2(tool, event, sample, machine); -} #endif - -static int perf_event__repipe_buildid_mmap2(const struct perf_tool *tool, - union perf_event *event, - struct perf_sample *sample, - struct machine *machine) -{ - struct dso_id dso_id =3D { - .maj =3D event->mmap2.maj, - .min =3D event->mmap2.min, - .ino =3D event->mmap2.ino, - .ino_generation =3D event->mmap2.ino_generation, - }; - struct dso *dso; - if (event->header.misc & PERF_RECORD_MISC_MMAP_BUILD_ID) { - /* cannot use dso_id since it'd have invalid info */ dso =3D findnew_dso(event->mmap2.pid, event->mmap2.tid, event->mmap2.filename, NULL, machine); if (dso) { /* mark it not to inject build-id */ dso__set_hit(dso); } - dso__put(dso); - perf_event__repipe(tool, event, sample, machine); - return 0; } + if (inject->build_id_style =3D=3D BID_RWS__INJECT_HEADER_ALL) { + if (!(event->header.misc & PERF_RECORD_MISC_MMAP_BUILD_ID)) { + struct dso_id dso_id =3D { + .maj =3D event->mmap2.maj, + .min =3D event->mmap2.min, + .ino =3D event->mmap2.ino, + .ino_generation =3D event->mmap2.ino_generation, + }; + + dso =3D findnew_dso(event->mmap2.pid, event->mmap2.tid, + event->mmap2.filename, &dso_id, machine); + } + if (dso && !dso__hit(dso)) { + dso__set_hit(dso); + dso__inject_build_id(dso, tool, machine, sample->cpumode, + event->mmap2.flags); + } + } else { + /* Create the thread, map, etc. Not done for the unordered inject all ca= se. */ + int err =3D perf_event__process_mmap(tool, event, sample, machine); =20 - dso =3D findnew_dso(event->mmap2.pid, event->mmap2.tid, - event->mmap2.filename, &dso_id, machine); - - if (dso && !dso__hit(dso)) { - dso__set_hit(dso); - dso__inject_build_id(dso, tool, machine, sample->cpumode, - event->mmap2.flags); + if (err) { + dso__put(dso); + return err; + } } dso__put(dso); - - perf_event__repipe(tool, event, sample, machine); - - return 0; + return perf_event__repipe(tool, event, sample, machine); } =20 static int perf_event__repipe_fork(const struct perf_tool *tool, @@ -2032,10 +1988,7 @@ static int __cmd_inject(struct perf_inject *inject) =20 output_data_offset =3D perf_session__data_offset(session->evlist); =20 - if (inject->build_id_style =3D=3D BID_RWS__INJECT_HEADER_ALL) { - inject->tool.mmap =3D perf_event__repipe_buildid_mmap; - inject->tool.mmap2 =3D perf_event__repipe_buildid_mmap2; - } else if (inject->build_id_style =3D=3D BID_RWS__INJECT_HEADER_LAZY) { + if (inject->build_id_style =3D=3D BID_RWS__INJECT_HEADER_LAZY) { inject->tool.sample =3D perf_event__inject_buildid; } else if (inject->sched_stat) { struct evsel *evsel; @@ -2430,8 +2383,8 @@ int cmd_inject(int argc, const char **argv) =20 #ifdef HAVE_JITDUMP if (inject.jit_mode) { - inject.tool.mmap2 =3D perf_event__jit_repipe_mmap2; - inject.tool.mmap =3D perf_event__jit_repipe_mmap; + inject.tool.mmap2 =3D perf_event__repipe_mmap2; + inject.tool.mmap =3D perf_event__repipe_mmap; inject.tool.ordering_requires_timestamps =3D true; /* * JIT MMAP injection injects all MMAP events in one go, so it --=20 2.46.0.184.g6999bdac58-goog From nobody Sat Feb 7 12:29:48 2026 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (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 17084146A76 for ; Sat, 17 Aug 2024 06:45:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723877124; cv=none; b=bJhIXjuhfThtIKiwzu4N44AE9bve+Ai5bWqcOMtmYU1GB7UvLak0qXFSZxF15Fu9j1Plbc70EBiowyoE21QbF0lyNoLA2XJVnC2hAltdg+jwBkcndURm8qt4YyI3pVIP7WDiWQY4dSwdLl5lXBMk+0OpPHljMhuaZXe3EqCmS7Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723877124; c=relaxed/simple; bh=cjMuPQXu9IACAGVGoPDWUv1/bqr9YjWSdf2bVeZ3IZE=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=LF67eftHUeadKpETwXZaynzo6p2iZdGdMtRcp7s2unYbjGn004aDKTWMBni9nOZZYzOyWtjeSHdQPNxQNwJv7ZyaCrEggSoUb6Zeu14xFmnWUFUjEv9frZQrk4SoQmZ4ksEAhgwjZORJC012unOw96TzHmG2qthrUW2uRYcNx/E= 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=SnhwGqYx; arc=none smtp.client-ip=209.85.219.202 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="SnhwGqYx" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e035949cc4eso5057934276.1 for ; Fri, 16 Aug 2024 23:45:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1723877122; x=1724481922; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=lk32N9pvvuO1iq6Lb13ZpGlJ9Q0Am70MOwkGMMj+lus=; b=SnhwGqYxAgJeqgBs2u0D396C4z4VWTOGg54LmfCqihW/dd7j+I2X7M7nc7AuBFWL31 aZ/FHxC4PM4lyyg8+n6JYCUeyQTrwzvVjEEcXYLgrJHH94uGV/Toj/s6tOFvkadEcZjf 2M0ulcaAmuSA+CClJWFHXZGpw8Q7JpRhSxyJ96G86lbmYMpo6SgKvQpe5W4jSg/fsXiX +HglOG6Bo2/SNZUVTwJFPdqZju28fHjZL399XkGaWRxrJj8mKU8+uxhbVHs5laXhlkjo etGXXpT6MJ58jjUX3oRaG30Q6zSRX8YtwZ34dxOofyFfRve5YDN2vNgsv9y8DdAqqVYt X4Qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723877122; x=1724481922; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=lk32N9pvvuO1iq6Lb13ZpGlJ9Q0Am70MOwkGMMj+lus=; b=ZH/2gHwelwJinp6MBmI9nScrZ+lmAHI63TkDYTfj7CfjzqaoXAcVcTuIZ+FGBVr+vu NWT/9ZuW+Ct6F4FWck2XsPztTN3ih/Am0pD8dUmsRcayM0Tm15yeXAoh1pooe+KI5Is7 HdMkIMwuu7Htl12CbyWjHwG9oM+1rl5ymJlH1SxiwH3tnCJB0Levp8Nju3JGWSp+kQiw iNAtow2tFXhyzMK3A6iuCbCMG/AMrCfJCHMVJgWI9ODkYgiF4/GpGoAZfaOVe/xo6JDL DXEl4PdMLIVssSoCydJt31LWDUF7yU87AsCA3czWmIRC8fN5vjwfW8lzOPL5pgdwl0Zh mnFA== X-Forwarded-Encrypted: i=1; AJvYcCUIcp9s3tFRBrle/ObbhURYh7A3zc92uYUoEJZyVpCUtwazk+xq2SIgZQnN5WHydF7PBByXRtM7tnSypx0Dh7AHVmLFPWKPnSVDHmeH X-Gm-Message-State: AOJu0YyacLhF/yzs5gKhjz42sdxJgZuAXxSnM2a5cxPOqGtSrhcwuUan /rDtj26PDceWTP09Q2Z5HIfCOgiBGJ/3Vd4RTh8mPIXa13SP/84SGJdRXNG6MnjJAYELM2BcaI3 xnIwqbQ== X-Google-Smtp-Source: AGHT+IFvfA7vAmjPNZy7qGhrh2RYYfzoR7Jxn8U6eVGXjUE8Vjbs6B8sZflti14WgVmg+rH5R96N86Y6/l68 X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:78c9:5e58:734f:c59f]) (user=irogers job=sendgmr) by 2002:a25:26c9:0:b0:e08:5ee3:7a18 with SMTP id 3f1490d57ef6-e1180e9d382mr253251276.5.1723877122126; Fri, 16 Aug 2024 23:45:22 -0700 (PDT) Date: Fri, 16 Aug 2024 23:44:38 -0700 In-Reply-To: <20240817064442.2152089-1-irogers@google.com> Message-Id: <20240817064442.2152089-10-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240817064442.2152089-1-irogers@google.com> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog Subject: [PATCH v1 09/13] perf inject: Combine mmap and mmap2 handling 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 , Masahiro Yamada , Arnd Bergmann , Jann Horn , Colin Ian King , Casey Chen , Athira Rajeev , Chaitanya S Prakash , James Clark , Ze Gao , Yang Jihong , Yunseong Kim , Weilin Wang , Dominique Martinet , Anne Macedo , Sun Haiyong , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The handling of mmap and mmap2 events is near identical. Add a common helper function and call that by the two event handling functions. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/builtin-inject.c | 118 +++++++++++++++++------------------- 1 file changed, 56 insertions(+), 62 deletions(-) diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index d99868953ff2..a7c859db2e15 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -422,55 +422,21 @@ static struct dso *findnew_dso(int pid, int tid, cons= t char *filename, return dso; } =20 -static int perf_event__repipe_mmap(const struct perf_tool *tool, - union perf_event *event, - struct perf_sample *sample, - struct machine *machine) -{ - struct perf_inject *inject =3D container_of(tool, struct perf_inject, too= l); - -#ifdef HAVE_JITDUMP - if (inject->jit_mode) { - u64 n =3D 0; - int ret; - - /* If jit marker, then inject jit mmaps and generate ELF images. */ - ret =3D jit_process(inject->session, &inject->output, machine, - event->mmap.filename, event->mmap.pid, event->mmap.tid, &n); - if (ret < 0) - return ret; - if (ret) { - inject->bytes_written +=3D n; - return 0; - } - } -#endif - if (inject->build_id_style =3D=3D BID_RWS__INJECT_HEADER_ALL) { - struct dso *dso =3D findnew_dso(event->mmap.pid, event->mmap.tid, - event->mmap.filename, NULL, machine); - - if (dso && !dso__hit(dso)) { - dso__set_hit(dso); - dso__inject_build_id(dso, tool, machine, sample->cpumode, 0); - } - dso__put(dso); - } else { - /* Create the thread, map, etc. Not done for the unordered inject all ca= se. */ - int err =3D perf_event__process_mmap(tool, event, sample, machine); - - if (err) - return err; - } - return perf_event__repipe(tool, event, sample, machine); -} - -static int perf_event__repipe_mmap2(const struct perf_tool *tool, - union perf_event *event, - struct perf_sample *sample, - struct machine *machine) +static int perf_event__repipe_common_mmap(const struct perf_tool *tool, + union perf_event *event, + struct perf_sample *sample, + struct machine *machine, + __u32 pid, __u32 tid, __u32 flags, + const char *filename, + const struct dso_id *dso_id, + int (*perf_event_process)(const struct perf_tool *tool, + union perf_event *event, + struct perf_sample *sample, + struct machine *machine)) { struct perf_inject *inject =3D container_of(tool, struct perf_inject, too= l); struct dso *dso =3D NULL; + bool dso_sought =3D false; =20 #ifdef HAVE_JITDUMP if (inject->jit_mode) { @@ -479,7 +445,7 @@ static int perf_event__repipe_mmap2(const struct perf_t= ool *tool, =20 /* If jit marker, then inject jit mmaps and generate ELF images. */ ret =3D jit_process(inject->session, &inject->output, machine, - event->mmap2.filename, event->mmap2.pid, event->mmap2.tid, &n); + filename, pid, tid, &n); if (ret < 0) return ret; if (ret) { @@ -489,33 +455,26 @@ static int perf_event__repipe_mmap2(const struct perf= _tool *tool, } #endif if (event->header.misc & PERF_RECORD_MISC_MMAP_BUILD_ID) { - dso =3D findnew_dso(event->mmap2.pid, event->mmap2.tid, - event->mmap2.filename, NULL, machine); + dso =3D findnew_dso(pid, tid, filename, dso_id, machine); + dso_sought =3D true; if (dso) { /* mark it not to inject build-id */ dso__set_hit(dso); } } if (inject->build_id_style =3D=3D BID_RWS__INJECT_HEADER_ALL) { - if (!(event->header.misc & PERF_RECORD_MISC_MMAP_BUILD_ID)) { - struct dso_id dso_id =3D { - .maj =3D event->mmap2.maj, - .min =3D event->mmap2.min, - .ino =3D event->mmap2.ino, - .ino_generation =3D event->mmap2.ino_generation, - }; - - dso =3D findnew_dso(event->mmap2.pid, event->mmap2.tid, - event->mmap2.filename, &dso_id, machine); + if (!dso_sought) { + dso =3D findnew_dso(pid, tid, filename, dso_id, machine); + dso_sought =3D true; } + if (dso && !dso__hit(dso)) { dso__set_hit(dso); - dso__inject_build_id(dso, tool, machine, sample->cpumode, - event->mmap2.flags); + dso__inject_build_id(dso, tool, machine, sample->cpumode, flags); } } else { /* Create the thread, map, etc. Not done for the unordered inject all ca= se. */ - int err =3D perf_event__process_mmap(tool, event, sample, machine); + int err =3D perf_event_process(tool, event, sample, machine); =20 if (err) { dso__put(dso); @@ -526,6 +485,41 @@ static int perf_event__repipe_mmap2(const struct perf_= tool *tool, return perf_event__repipe(tool, event, sample, machine); } =20 +static int perf_event__repipe_mmap(const struct perf_tool *tool, + union perf_event *event, + struct perf_sample *sample, + struct machine *machine) +{ + return perf_event__repipe_common_mmap( + tool, event, sample, machine, + event->mmap.pid, event->mmap.tid, /*flags=3D*/0, + event->mmap.filename, /*dso_id=3D*/NULL, + perf_event__process_mmap); +} + +static int perf_event__repipe_mmap2(const struct perf_tool *tool, + union perf_event *event, + struct perf_sample *sample, + struct machine *machine) +{ + struct dso_id id; + struct dso_id *dso_id =3D NULL; + + if (!(event->header.misc & PERF_RECORD_MISC_MMAP_BUILD_ID)) { + id.maj =3D event->mmap2.maj; + id.min =3D event->mmap2.min; + id.ino =3D event->mmap2.ino; + id.ino_generation =3D event->mmap2.ino_generation; + dso_id =3D &id; + } + + return perf_event__repipe_common_mmap( + tool, event, sample, machine, + event->mmap2.pid, event->mmap2.tid, event->mmap2.flags, + event->mmap2.filename, dso_id, + perf_event__process_mmap2); +} + static int perf_event__repipe_fork(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, --=20 2.46.0.184.g6999bdac58-goog From nobody Sat Feb 7 12:29:48 2026 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.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 8DF511474A7 for ; Sat, 17 Aug 2024 06:45:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723877127; cv=none; b=peP3jNzSjzt4yA+hvfnA0ZnrwRIdF498DeMNBIj/iAjWlng2SM+/apyrXBFaiUBwr7ISItSFr0T19FsAH2tLEvp7uI6WUBI1PbJS5bsWL39C+bDXIP2kz4E8wxRHt0osBInVRunkK5aeMYFxXquFkqI1DkhUXua0+IQjhqgTO9I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723877127; c=relaxed/simple; bh=4zMaRa9g/3QhnnPegvdyD6R5WG7LgxkQaz3wvOp74c0=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=ZrIyk1VbFj6PpQLBd14NpB1KoHqr5nVJtI37ZMJ5/tLNgpYrVTXkShzPo6h08wQa5lsM7Ed6eUz64fesZkQNP1LrV9T4Qu256xCLGM0/j5ARSL+6sZnXY2ZxaJ80LtYkRhqRxR3EEwev2FFZ5oVlxfmii7OdPiGIynOZqHCJYPI= 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=DjKTHVN/; arc=none smtp.client-ip=209.85.128.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="DjKTHVN/" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6b1adbdbec9so32066847b3.0 for ; Fri, 16 Aug 2024 23:45:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1723877124; x=1724481924; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=limJFhYtfcwn5BoDQ5nprHbguRK6HBwBTzbehLiX19U=; b=DjKTHVN/Rz6FvkcWho8/AMwWLBhM62IHI8mJdcgrvTPJafKSg1OfUGVyq9E82rchQf qWWq9CFUksmpteA+rOMrJR+KfJwTwscFi619mfmwvyzvDZWw2PIl3kNmJWWh73mf8Nfb /QQnSTjfy2C+UvTV25fuDlI0cyjhJNk15plMKX6cHbW7y/byVEbvlaTjj4oTTzMDjr7G k0y9FhuSnj+swnoaz9oWO8jBZoR0T9F0TF1wfZeyb+iJMawvfCtbs6PxDIGLeBIhcGw/ Gjvvo4tPMwUgCo/dhNiSQrLAxiqUMA7fKzC5w9TGM2oqCw7JQLaB/58JrEaoogpm6OEg QI7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723877124; x=1724481924; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=limJFhYtfcwn5BoDQ5nprHbguRK6HBwBTzbehLiX19U=; b=AC2845NTlM3Pl2ztVdxX0JMzeK7S8HTkcee6ZczM9eVuJru5Brr8HMiXc8kjhP/9bm Ooo/iAAiyDEjh9Ocqqz9xxbgpBCPT1iFLJSLWJTvsbmtWHNYGcZZj/7iTrg9i/9Q+G6u jg5FqBDylR5J0Eh5s5ZgoSGRd3eLNhL/82eJCr8qpXBcYVQJjaBjUTSzjphv7vddxK7P NJZ8Kpu2j+F64HkBDkq44JSLv9VHPikBkVrCWip+KnjzsZoFQxuXKRHI3XWfiXQ1HW9T A9wRWFpRDQLnuvy8C8ZcvMTgp9vuUWMdpy6BcmzuvdJwcHYNyEdaUz67zQiSy6Dj+HCn K2gw== X-Forwarded-Encrypted: i=1; AJvYcCUZnGrwIqiVQy6uD8EcBhDTsWvM/CPmbav50Afl7dWFAbEu2pn+dZXkCHzr6siU7IbZEqEhlFihU0JG0iVHnTwSZfNNGDBb++/aG5QK X-Gm-Message-State: AOJu0YwG8QTDeIPlfo9/4d4s1pPBjUFKYxGNpsxcO7Y9OkZN8Orh+dAU R7I7PaCbzCt69iu9GMaTsZ03MX0cjy75NobY+NFs8gv3RHMFEUGkFxB0hIuqG8cHOyXVLrE5uN/ I5SevnQ== X-Google-Smtp-Source: AGHT+IEPiNa/qXZIt6ptn3zb83g/dXuvDVY4QxjK7uEvC8k1JxADUoMklonPkghHC6QCr9hBOAcIijNYfqge X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:78c9:5e58:734f:c59f]) (user=irogers job=sendgmr) by 2002:a5b:4cb:0:b0:e11:7a38:8883 with SMTP id 3f1490d57ef6-e1180f71f9dmr8127276.7.1723877124512; Fri, 16 Aug 2024 23:45:24 -0700 (PDT) Date: Fri, 16 Aug 2024 23:44:39 -0700 In-Reply-To: <20240817064442.2152089-1-irogers@google.com> Message-Id: <20240817064442.2152089-11-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240817064442.2152089-1-irogers@google.com> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog Subject: [PATCH v1 10/13] perf inject: Fix build ID injection 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 , Masahiro Yamada , Arnd Bergmann , Jann Horn , Colin Ian King , Casey Chen , Athira Rajeev , Chaitanya S Prakash , James Clark , Ze Gao , Yang Jihong , Yunseong Kim , Weilin Wang , Dominique Martinet , Anne Macedo , Sun Haiyong , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Build ID injection wasn't inserting a sample ID and aligning events to 64 bytes rather than 8. No sample ID means events are unordered and two different build_id events for the same path, as happens when a file is replaced, can't be differentiated. Add in sample ID insertion for the build_id events alongside some refactoring. The refactoring better aligns the function arguments for different use cases, such as synthesizing build_id events without needing to have a dso. The misc bits are explicitly passed as with callchains the maps/dsos may span user and kernel land, so using sample->cpumode isn't good enough. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/builtin-inject.c | 170 ++++++++++++++++++++++------- tools/perf/util/build-id.c | 6 +- tools/perf/util/synthetic-events.c | 44 ++++++-- tools/perf/util/synthetic-events.h | 10 +- 4 files changed, 175 insertions(+), 55 deletions(-) diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index a7c859db2e15..84a4bdb5cb0a 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -131,6 +131,7 @@ struct perf_inject { struct perf_file_section secs[HEADER_FEAT_BITS]; struct guest_session guest_session; struct strlist *known_build_ids; + const struct evsel *mmap_evsel; }; =20 struct event_entry { @@ -139,8 +140,13 @@ struct event_entry { union perf_event event[]; }; =20 -static int dso__inject_build_id(struct dso *dso, const struct perf_tool *t= ool, - struct machine *machine, u8 cpumode, u32 flags); +static int dso__inject_build_id(const struct perf_tool *tool, + struct perf_sample *sample, + struct machine *machine, + const struct evsel *evsel, + __u16 misc, + const char *filename, + struct dso *dso, u32 flags); =20 static int output_bytes(struct perf_inject *inject, void *buf, size_t sz) { @@ -422,6 +428,28 @@ static struct dso *findnew_dso(int pid, int tid, const= char *filename, return dso; } =20 +/* + * The evsel used for the sample ID for mmap events. Typically stashed when + * processing mmap events. If not stashed, search the evlist for the first= mmap + * gathering event. + */ +static const struct evsel *inject__mmap_evsel(struct perf_inject *inject) +{ + struct evsel *pos; + + if (inject->mmap_evsel) + return inject->mmap_evsel; + + evlist__for_each_entry(inject->session->evlist, pos) { + if (pos->core.attr.mmap) { + inject->mmap_evsel =3D pos; + return pos; + } + } + pr_err("No mmap events found\n"); + return NULL; +} + static int perf_event__repipe_common_mmap(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, @@ -469,12 +497,28 @@ static int perf_event__repipe_common_mmap(const struc= t perf_tool *tool, } =20 if (dso && !dso__hit(dso)) { - dso__set_hit(dso); - dso__inject_build_id(dso, tool, machine, sample->cpumode, flags); + struct evsel *evsel =3D evlist__event2evsel(inject->session->evlist, ev= ent); + + if (evsel) { + dso__set_hit(dso); + dso__inject_build_id(tool, sample, machine, evsel, + /*misc=3D*/sample->cpumode, + filename, dso, flags); + } } } else { + int err; + + /* + * Remember the evsel for lazy build id generation. It is used + * for the sample id header type. + */ + if (inject->build_id_style =3D=3D BID_RWS__INJECT_HEADER_LAZY && + !inject->mmap_evsel) + inject->mmap_evsel =3D evlist__event2evsel(inject->session->evlist, eve= nt); + /* Create the thread, map, etc. Not done for the unordered inject all ca= se. */ - int err =3D perf_event_process(tool, event, sample, machine); + err =3D perf_event_process(tool, event, sample, machine); =20 if (err) { dso__put(dso); @@ -667,16 +711,20 @@ static bool perf_inject__lookup_known_build_id(struct= perf_inject *inject, return false; } =20 -static int dso__inject_build_id(struct dso *dso, const struct perf_tool *t= ool, - struct machine *machine, u8 cpumode, u32 flags) +static int dso__inject_build_id(const struct perf_tool *tool, + struct perf_sample *sample, + struct machine *machine, + const struct evsel *evsel, + __u16 misc, + const char *filename, + struct dso *dso, u32 flags) { - struct perf_inject *inject =3D container_of(tool, struct perf_inject, - tool); + struct perf_inject *inject =3D container_of(tool, struct perf_inject, too= l); int err; =20 - if (is_anon_memory(dso__long_name(dso)) || flags & MAP_HUGETLB) + if (is_anon_memory(filename) || flags & MAP_HUGETLB) return 0; - if (is_no_dso_memory(dso__long_name(dso))) + if (is_no_dso_memory(filename)) return 0; =20 if (inject->known_build_ids !=3D NULL && @@ -684,24 +732,65 @@ static int dso__inject_build_id(struct dso *dso, cons= t struct perf_tool *tool, return 1; =20 if (dso__read_build_id(dso) < 0) { - pr_debug("no build_id found for %s\n", dso__long_name(dso)); + pr_debug("no build_id found for %s\n", filename); return -1; } =20 - err =3D perf_event__synthesize_build_id(tool, dso, cpumode, - perf_event__repipe, machine); + err =3D perf_event__synthesize_build_id(tool, sample, machine, + perf_event__repipe, + evsel, misc, dso__bid(dso), + filename); if (err) { - pr_err("Can't synthesize build_id event for %s\n", dso__long_name(dso)); + pr_err("Can't synthesize build_id event for %s\n", filename); return -1; } =20 return 0; } =20 +static int mark_dso_hit(const struct perf_tool *tool, + struct perf_sample *sample, + struct machine *machine, + const struct evsel *mmap_evsel, + struct map *map, bool sample_in_dso) +{ + struct dso *dso; + u16 misc =3D sample->cpumode; + + if (!map) + return 0; + + if (!sample_in_dso) { + u16 guest_mask =3D PERF_RECORD_MISC_GUEST_KERNEL | + PERF_RECORD_MISC_GUEST_USER; + + if ((misc & guest_mask) !=3D 0) { + misc &=3D PERF_RECORD_MISC_HYPERVISOR; + misc |=3D __map__is_kernel(map) + ? PERF_RECORD_MISC_GUEST_KERNEL + : PERF_RECORD_MISC_GUEST_USER; + } else { + misc &=3D PERF_RECORD_MISC_HYPERVISOR; + misc |=3D __map__is_kernel(map) + ? PERF_RECORD_MISC_KERNEL + : PERF_RECORD_MISC_USER; + } + } + dso =3D map__dso(map); + if (dso && !dso__hit(dso)) { + dso__set_hit(dso); + dso__inject_build_id(tool, sample, machine, + mmap_evsel, misc, dso__long_name(dso), dso, + map__flags(map)); + } + return 0; +} + struct mark_dso_hit_args { const struct perf_tool *tool; + struct perf_sample *sample; struct machine *machine; - u8 cpumode; + const struct evsel *mmap_evsel; }; =20 static int mark_dso_hit_callback(struct callchain_cursor_node *node, void = *data) @@ -709,16 +798,8 @@ static int mark_dso_hit_callback(struct callchain_curs= or_node *node, void *data) struct mark_dso_hit_args *args =3D data; struct map *map =3D node->ms.map; =20 - if (map) { - struct dso *dso =3D map__dso(map); - - if (dso && !dso__hit(dso)) { - dso__set_hit(dso); - dso__inject_build_id(dso, args->tool, args->machine, - args->cpumode, map__flags(map)); - } - } - return 0; + return mark_dso_hit(args->tool, args->sample, args->machine, + args->mmap_evsel, map, /*sample_in_dso=3D*/false); } =20 int perf_event__inject_buildid(const struct perf_tool *tool, union perf_ev= ent *event, @@ -728,10 +809,16 @@ int perf_event__inject_buildid(const struct perf_tool= *tool, union perf_event *e { struct addr_location al; struct thread *thread; + struct perf_inject *inject =3D container_of(tool, struct perf_inject, too= l); struct mark_dso_hit_args args =3D { .tool =3D tool, + /* + * Use the parsed sample data of the sample event, which will + * have a later timestamp than the mmap event. + */ + .sample =3D sample, .machine =3D machine, - .cpumode =3D sample->cpumode, + .mmap_evsel =3D inject__mmap_evsel(inject), }; =20 addr_location__init(&al); @@ -743,13 +830,8 @@ int perf_event__inject_buildid(const struct perf_tool = *tool, union perf_event *e } =20 if (thread__find_map(thread, sample->cpumode, sample->ip, &al)) { - struct dso *dso =3D map__dso(al.map); - - if (!dso__hit(dso)) { - dso__set_hit(dso); - dso__inject_build_id(dso, tool, machine, - sample->cpumode, map__flags(al.map)); - } + mark_dso_hit(tool, sample, machine, args.mmap_evsel, al.map, + /*sample_in_dso=3D*/true); } =20 sample__for_each_callchain_node(thread, evsel, sample, PERF_MAX_STACK_DEP= TH, @@ -1159,17 +1241,27 @@ static int process_build_id(const struct perf_tool = *tool, static int synthesize_build_id(struct perf_inject *inject, struct dso *dso= , pid_t machine_pid) { struct machine *machine =3D perf_session__findnew_machine(inject->session= , machine_pid); - u8 cpumode =3D dso__is_in_kernel_space(dso) ? - PERF_RECORD_MISC_GUEST_KERNEL : - PERF_RECORD_MISC_GUEST_USER; + struct perf_sample synth_sample =3D { + .pid =3D -1, + .tid =3D -1, + .time =3D -1, + .stream_id =3D -1, + .cpu =3D -1, + .period =3D 1, + .cpumode =3D dso__is_in_kernel_space(dso) + ? PERF_RECORD_MISC_GUEST_KERNEL + : PERF_RECORD_MISC_GUEST_USER, + }; =20 if (!machine) return -ENOMEM; =20 dso__set_hit(dso); =20 - return perf_event__synthesize_build_id(&inject->tool, dso, cpumode, - process_build_id, machine); + return perf_event__synthesize_build_id(&inject->tool, &synth_sample, mach= ine, + process_build_id, inject__mmap_evsel(inject), + /*misc=3D*/synth_sample.cpumode, + dso__bid(dso), dso__long_name(dso)); } =20 static int guest_session__add_build_ids_cb(struct dso *dso, void *data) diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c index 451d145fa4ed..8982f68e7230 100644 --- a/tools/perf/util/build-id.c +++ b/tools/perf/util/build-id.c @@ -277,8 +277,8 @@ static int write_buildid(const char *name, size_t name_= len, struct build_id *bid struct perf_record_header_build_id b; size_t len; =20 - len =3D name_len + 1; - len =3D PERF_ALIGN(len, NAME_ALIGN); + len =3D sizeof(b) + name_len + 1; + len =3D PERF_ALIGN(len, sizeof(u64)); =20 memset(&b, 0, sizeof(b)); memcpy(&b.data, bid->data, bid->size); @@ -286,7 +286,7 @@ static int write_buildid(const char *name, size_t name_= len, struct build_id *bid misc |=3D PERF_RECORD_MISC_BUILD_ID_SIZE; b.pid =3D pid; b.header.misc =3D misc; - b.header.size =3D sizeof(b) + len; + b.header.size =3D len; =20 err =3D do_write(fd, &b, sizeof(b)); if (err < 0) diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic= -events.c index 0a7f93ae76fb..6bb62e4e2d5d 100644 --- a/tools/perf/util/synthetic-events.c +++ b/tools/perf/util/synthetic-events.c @@ -2225,28 +2225,48 @@ int perf_event__synthesize_tracing_data(const struc= t perf_tool *tool, int fd, st } #endif =20 -int perf_event__synthesize_build_id(const struct perf_tool *tool, struct d= so *pos, u16 misc, - perf_event__handler_t process, struct machine *machine) +int perf_event__synthesize_build_id(const struct perf_tool *tool, + struct perf_sample *sample, + struct machine *machine, + perf_event__handler_t process, + const struct evsel *evsel, + __u16 misc, + const struct build_id *bid, + const char *filename) { union perf_event ev; size_t len; =20 - if (!dso__hit(pos)) - return 0; + len =3D sizeof(ev.build_id) + strlen(filename) + 1; + len =3D PERF_ALIGN(len, sizeof(u64)); =20 - memset(&ev, 0, sizeof(ev)); + memset(&ev, 0, len); =20 - len =3D dso__long_name_len(pos) + 1; - len =3D PERF_ALIGN(len, NAME_ALIGN); - ev.build_id.size =3D min(dso__bid(pos)->size, sizeof(dso__bid(pos)->data)= ); - memcpy(&ev.build_id.build_id, dso__bid(pos)->data, ev.build_id.size); + ev.build_id.size =3D min(bid->size, sizeof(ev.build_id.build_id)); + memcpy(ev.build_id.build_id, bid->data, ev.build_id.size); ev.build_id.header.type =3D PERF_RECORD_HEADER_BUILD_ID; ev.build_id.header.misc =3D misc | PERF_RECORD_MISC_BUILD_ID_SIZE; ev.build_id.pid =3D machine->pid; - ev.build_id.header.size =3D sizeof(ev.build_id) + len; - memcpy(&ev.build_id.filename, dso__long_name(pos), dso__long_name_len(pos= )); + ev.build_id.header.size =3D len; + strcpy(ev.build_id.filename, filename); + + if (evsel) { + void *array =3D &ev; + int ret; =20 - return process(tool, &ev, NULL, machine); + array +=3D ev.header.size; + ret =3D perf_event__synthesize_id_sample(array, evsel->core.attr.sample_= type, sample); + if (ret < 0) + return ret; + + if (ret & 7) { + pr_err("Bad id sample size %d\n", ret); + return -EINVAL; + } + + ev.header.size +=3D ret; + } + return process(tool, &ev, sample, machine); } =20 int perf_event__synthesize_stat_events(struct perf_stat_config *config, co= nst struct perf_tool *tool, diff --git a/tools/perf/util/synthetic-events.h b/tools/perf/util/synthetic= -events.h index 31df7653677f..795bf3e18396 100644 --- a/tools/perf/util/synthetic-events.h +++ b/tools/perf/util/synthetic-events.h @@ -9,6 +9,7 @@ #include =20 struct auxtrace_record; +struct build_id; struct dso; struct evlist; struct evsel; @@ -45,7 +46,14 @@ typedef int (*perf_event__handler_t)(const struct perf_t= ool *tool, union perf_ev =20 int perf_event__synthesize_attrs(const struct perf_tool *tool, struct evli= st *evlist, perf_event__handler_t process); int perf_event__synthesize_attr(const struct perf_tool *tool, struct perf_= event_attr *attr, u32 ids, u64 *id, perf_event__handler_t process); -int perf_event__synthesize_build_id(const struct perf_tool *tool, struct d= so *pos, u16 misc, perf_event__handler_t process, struct machine *machine); +int perf_event__synthesize_build_id(const struct perf_tool *tool, + struct perf_sample *sample, + struct machine *machine, + perf_event__handler_t process, + const struct evsel *evsel, + __u16 misc, + const struct build_id *bid, + const char *filename); int perf_event__synthesize_cpu_map(const struct perf_tool *tool, const str= uct perf_cpu_map *cpus, perf_event__handler_t process, struct machine *mach= ine); int perf_event__synthesize_event_update_cpus(const struct perf_tool *tool,= struct evsel *evsel, perf_event__handler_t process); int perf_event__synthesize_event_update_name(const struct perf_tool *tool,= struct evsel *evsel, perf_event__handler_t process); --=20 2.46.0.184.g6999bdac58-goog From nobody Sat Feb 7 12:29:48 2026 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 C3E171482F3 for ; Sat, 17 Aug 2024 06:45:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723877129; cv=none; b=R08yeXXOfCldY6qW+CSmwFaa4ln6r5N8UYYmzC9dx7Mnd21QEWmqh6nyvpwrGiq8zJdbxV3prFD8Js4TLR0/hHyBCJtp99YnznI3+uUvg94ICZBlrwXiWzwfXeMSHqji/yutvk5z2DxXLrbRtAfHgvc0c2rmaAe3goP17WMo8sw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723877129; c=relaxed/simple; bh=QpBMD0kpQEm4CD5YL7HRhIq6xDSHfb8hYh4/L55BjQc=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=eCbdkDND/7RtMyJu211wxKxR8nAgCb/tMr6O0D3VehCccQEq3OZRqu9r/35LFgu1bZHhtYsn0V82vxgDoPB9ErY9WEbb2WhyXThdvnfazmpPrVHsBlaJJWwRdBQMyhx/9ut7M1mXr3jakPtykAbOU/pMUZxxKdGbGzaP0CSgLpA= 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=Fi1vJOJd; arc=none smtp.client-ip=209.85.128.202 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="Fi1vJOJd" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6b43e6b9c82so14950897b3.0 for ; Fri, 16 Aug 2024 23:45:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1723877127; x=1724481927; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=TXAXn6xK+PoC88ZvEgDZdmJIFm+dzHlxN2g70itgLKc=; b=Fi1vJOJdQyo9LwmqEgOhUeK8mHIm0f/ugIhWjlZBS61KhFf5e9+e95W1qH5ku0eLSR /xVIIeAIKjPb/wPfYfJB1b78n92ZhDGuKcfU2nf0mo7ztA0siEfJ7SM6T77nBk2iuJvg k8uyrwUH5Rsru7HPI5gzCT1AMkJBaDM7CPmY8RhN+SFcRctYS4pGMlIOcUrB+LAs6a/4 S262DYnga7bNJ+f3vFEuv//kNGCcc0+iKySEVAbHRXsknNKpSmZJd48Ko8oVjr4Ei83F HgZ9aR1BS/3v9xV4WpJSF7zUOZqJ2wO6e2lu+UIJ0DPpd1JieLe9bZmQLSpQa2YattER M9iQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723877127; x=1724481927; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=TXAXn6xK+PoC88ZvEgDZdmJIFm+dzHlxN2g70itgLKc=; b=iOdhNLkITkB0OjoMyYBnnPn9NnjBl8Z8OLD9Mu/eym97RYlNGmTUkQSzWq3Vj8j86d AKA24Qd+Qq3g2WLkyp7r4OSkpz9Xj7Z5bXuPIB2j3mE5Zql8x6eLLOfAQiZ+odTjdK6V u1BJGzUjChwyxTbicrPV/ekhV5F9dj0nlHWE1e4u2/Bt3Utyq4n/Yg+0zz+MDId2Lq8h DfwdGfGECouklJrzKsoX2sd4AvSppGekmEUBZGlTm88xI5HkU51/BbIzIb2OQH4VvsJP sw8yWdJi/8YPlC89f49zO8rgXoJukrWPrOHfyJe3WAmH35zq4V9ACn+GvjOZbcN10w0W TXzg== X-Forwarded-Encrypted: i=1; AJvYcCV7OTMRvdq0leFkYqQW06Wi45THUZnCBYD5oSNGvaD0NCgNhFWgcnoo5zGg7RR3SIN0rl2BudtmyNCZ3UBELAFCLimlSQ2g4jBM/JCx X-Gm-Message-State: AOJu0YzX74CS2OXVII8PDqadqPwoJTWlzdBC6JtGmalTpHCi3q8Lmnsz j+Oft4xzo6o8lM7kMXlVyBMHm8owWPRGfwC5N69InWwgGyPNfwKkS/UJ9mu5lpcNpN1/hRy5vzb PBC/6YA== X-Google-Smtp-Source: AGHT+IHFxN3N3woVEej46v2pH2bwTVupl8ivX7TTlOLLLegLEBpZrn01gXlXNRoWkgjVqXDLt123ujpFj/uJ X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:78c9:5e58:734f:c59f]) (user=irogers job=sendgmr) by 2002:a05:690c:460b:b0:6b0:d571:3533 with SMTP id 00721157ae682-6b1bbb4af15mr1175187b3.7.1723877127009; Fri, 16 Aug 2024 23:45:27 -0700 (PDT) Date: Fri, 16 Aug 2024 23:44:40 -0700 In-Reply-To: <20240817064442.2152089-1-irogers@google.com> Message-Id: <20240817064442.2152089-12-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240817064442.2152089-1-irogers@google.com> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog Subject: [PATCH v1 11/13] perf inject: Add new mmap2-buildid-all option 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 , Masahiro Yamada , Arnd Bergmann , Jann Horn , Colin Ian King , Casey Chen , Athira Rajeev , Chaitanya S Prakash , James Clark , Ze Gao , Yang Jihong , Yunseong Kim , Weilin Wang , Dominique Martinet , Anne Macedo , Sun Haiyong , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add an option that allows all mmap or mmap2 events to be rewritten as mmap2 events with build IDs. This is similar to the existing -b/--build-ids and --buildid-all options except instead of adding a build_id event an existing mmap/mmap2 event is used as a template and a new mmap2 event synthesized from it. As mmap2 events are typical this avoids the insertion of build_id events. Add test coverage to the pipe test. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/builtin-inject.c | 88 ++++++++++++++++++++++++++++- tools/perf/tests/shell/pipe_test.sh | 1 + tools/perf/util/synthetic-events.c | 57 +++++++++++++++++++ tools/perf/util/synthetic-events.h | 11 ++++ 4 files changed, 154 insertions(+), 3 deletions(-) diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index 84a4bdb5cb0a..86425cade30e 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -107,6 +107,7 @@ enum build_id_rewrite_style { BID_RWS__NONE =3D 0, BID_RWS__INJECT_HEADER_LAZY, BID_RWS__INJECT_HEADER_ALL, + BID_RWS__MMAP2_BUILDID_ALL, }; =20 struct perf_inject { @@ -147,6 +148,16 @@ static int dso__inject_build_id(const struct perf_tool= *tool, __u16 misc, const char *filename, struct dso *dso, u32 flags); +static int dso__inject_mmap2_build_id(const struct perf_tool *tool, + struct perf_sample *sample, + struct machine *machine, + const struct evsel *evsel, + __u16 misc, + __u32 pid, __u32 tid, + __u64 start, __u64 len, __u64 pgoff, + struct dso *dso, + __u32 prot, __u32 flags, + const char *filename); =20 static int output_bytes(struct perf_inject *inject, void *buf, size_t sz) { @@ -162,6 +173,7 @@ static int output_bytes(struct perf_inject *inject, voi= d *buf, size_t sz) =20 static int perf_event__repipe_synth(const struct perf_tool *tool, union perf_event *event) + { struct perf_inject *inject =3D container_of(tool, struct perf_inject, tool); @@ -454,7 +466,9 @@ static int perf_event__repipe_common_mmap(const struct = perf_tool *tool, union perf_event *event, struct perf_sample *sample, struct machine *machine, - __u32 pid, __u32 tid, __u32 flags, + __u32 pid, __u32 tid, + __u64 start, __u64 len, __u64 pgoff, + __u32 flags, __u32 prot, const char *filename, const struct dso_id *dso_id, int (*perf_event_process)(const struct perf_tool *tool, @@ -525,6 +539,26 @@ static int perf_event__repipe_common_mmap(const struct= perf_tool *tool, return err; } } + if ((inject->build_id_style =3D=3D BID_RWS__MMAP2_BUILDID_ALL) && + !(event->header.misc & PERF_RECORD_MISC_MMAP_BUILD_ID)) { + struct evsel *evsel =3D evlist__event2evsel(inject->session->evlist, eve= nt); + + if (evsel && !dso_sought) { + dso =3D findnew_dso(pid, tid, filename, dso_id, machine); + dso_sought =3D true; + } + if (evsel && dso && + !dso__inject_mmap2_build_id(tool, sample, machine, evsel, + sample->cpumode | PERF_RECORD_MISC_MMAP_BUILD_ID, + pid, tid, start, len, pgoff, + dso, + prot, flags, + filename)) { + /* Injected mmap2 so no need to repipe. */ + dso__put(dso); + return 0; + } + } dso__put(dso); return perf_event__repipe(tool, event, sample, machine); } @@ -536,7 +570,9 @@ static int perf_event__repipe_mmap(const struct perf_to= ol *tool, { return perf_event__repipe_common_mmap( tool, event, sample, machine, - event->mmap.pid, event->mmap.tid, /*flags=3D*/0, + event->mmap.pid, event->mmap.tid, + event->mmap.start, event->mmap.len, event->mmap.pgoff, + /*flags=3D*/0, PROT_EXEC, event->mmap.filename, /*dso_id=3D*/NULL, perf_event__process_mmap); } @@ -559,7 +595,9 @@ static int perf_event__repipe_mmap2(const struct perf_t= ool *tool, =20 return perf_event__repipe_common_mmap( tool, event, sample, machine, - event->mmap2.pid, event->mmap2.tid, event->mmap2.flags, + event->mmap2.pid, event->mmap2.tid, + event->mmap2.start, event->mmap2.len, event->mmap2.pgoff, + event->mmap2.flags, event->mmap2.prot, event->mmap2.filename, dso_id, perf_event__process_mmap2); } @@ -748,6 +786,45 @@ static int dso__inject_build_id(const struct perf_tool= *tool, return 0; } =20 +static int dso__inject_mmap2_build_id(const struct perf_tool *tool, + struct perf_sample *sample, + struct machine *machine, + const struct evsel *evsel, + __u16 misc, + __u32 pid, __u32 tid, + __u64 start, __u64 len, __u64 pgoff, + struct dso *dso, + __u32 prot, __u32 flags, + const char *filename) +{ + int err; + + /* Return to repipe anonymous maps. */ + if (is_anon_memory(filename) || flags & MAP_HUGETLB) + return 1; + if (is_no_dso_memory(filename)) + return 1; + + if (dso__read_build_id(dso)) { + pr_debug("no build_id found for %s\n", filename); + return -1; + } + + err =3D perf_event__synthesize_mmap2_build_id(tool, sample, machine, + perf_event__repipe, + evsel, + misc, pid, tid, + start, len, pgoff, + dso__bid(dso), + prot, flags, + filename); + if (err) { + pr_err("Can't synthesize build_id event for %s\n", filename); + return -1; + } + return 0; +} + static int mark_dso_hit(const struct perf_tool *tool, struct perf_sample *sample, struct machine *machine, @@ -2257,12 +2334,15 @@ int cmd_inject(int argc, const char **argv) const char *known_build_ids =3D NULL; bool build_ids; bool build_id_all; + bool mmap2_build_id_all; =20 struct option options[] =3D { OPT_BOOLEAN('b', "build-ids", &build_ids, "Inject build-ids into the output stream"), OPT_BOOLEAN(0, "buildid-all", &build_id_all, "Inject build-ids of all DSOs into the output stream"), + OPT_BOOLEAN(0, "mmap2-buildid-all", &mmap2_build_id_all, + "Rewrite all mmap events as mmap2 events with build IDs"), OPT_STRING(0, "known-build-ids", &known_build_ids, "buildid path [,buildid path...]", "build-ids to use for given paths"), @@ -2359,6 +2439,8 @@ int cmd_inject(int argc, const char **argv) return -1; } } + if (mmap2_build_id_all) + inject.build_id_style =3D BID_RWS__MMAP2_BUILDID_ALL; if (build_ids) inject.build_id_style =3D BID_RWS__INJECT_HEADER_LAZY; if (build_id_all) diff --git a/tools/perf/tests/shell/pipe_test.sh b/tools/perf/tests/shell/p= ipe_test.sh index ad10012fdc29..1cacd6f15bcb 100755 --- a/tools/perf/tests/shell/pipe_test.sh +++ b/tools/perf/tests/shell/pipe_test.sh @@ -92,6 +92,7 @@ test_inject_bids() { test_record_report test_inject_bids -b test_inject_bids --buildid-all +test_inject_bids --mmap2-buildid-all =20 cleanup exit $err diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic= -events.c index 6bb62e4e2d5d..a58444c4aed1 100644 --- a/tools/perf/util/synthetic-events.c +++ b/tools/perf/util/synthetic-events.c @@ -2266,6 +2266,63 @@ int perf_event__synthesize_build_id(const struct per= f_tool *tool, =20 ev.header.size +=3D ret; } + + return process(tool, &ev, sample, machine); +} + +int perf_event__synthesize_mmap2_build_id(const struct perf_tool *tool, + struct perf_sample *sample, + struct machine *machine, + perf_event__handler_t process, + const struct evsel *evsel, + __u16 misc, + __u32 pid, __u32 tid, + __u64 start, __u64 len, __u64 pgoff, + const struct build_id *bid, + __u32 prot, __u32 flags, + const char *filename) +{ + union perf_event ev; + size_t ev_len; + void *array; + int ret; + + ev_len =3D sizeof(ev.mmap2) - sizeof(ev.mmap2.filename) + strlen(filename= ) + 1; + ev_len =3D PERF_ALIGN(ev_len, sizeof(u64)); + + memset(&ev, 0, ev_len); + + ev.mmap2.header.type =3D PERF_RECORD_MMAP2; + ev.mmap2.header.misc =3D misc | PERF_RECORD_MISC_MMAP_BUILD_ID; + ev.mmap2.header.size =3D ev_len; + + ev.mmap2.pid =3D pid; + ev.mmap2.tid =3D tid; + ev.mmap2.start =3D start; + ev.mmap2.len =3D len; + ev.mmap2.pgoff =3D pgoff; + + ev.mmap2.build_id_size =3D min(bid->size, sizeof(ev.mmap2.build_id)); + memcpy(ev.mmap2.build_id, bid->data, ev.mmap2.build_id_size); + + ev.mmap2.prot =3D prot; + ev.mmap2.flags =3D flags; + + memcpy(ev.mmap2.filename, filename, min(strlen(filename), sizeof(ev.mmap.= filename))); + + array =3D &ev; + array +=3D ev.header.size; + ret =3D perf_event__synthesize_id_sample(array, evsel->core.attr.sample_t= ype, sample); + if (ret < 0) + return ret; + + if (ret & 7) { + pr_err("Bad id sample size %d\n", ret); + return -EINVAL; + } + + ev.header.size +=3D ret; + return process(tool, &ev, sample, machine); } =20 diff --git a/tools/perf/util/synthetic-events.h b/tools/perf/util/synthetic= -events.h index 795bf3e18396..b9c936b5cfeb 100644 --- a/tools/perf/util/synthetic-events.h +++ b/tools/perf/util/synthetic-events.h @@ -54,6 +54,17 @@ int perf_event__synthesize_build_id(const struct perf_to= ol *tool, __u16 misc, const struct build_id *bid, const char *filename); +int perf_event__synthesize_mmap2_build_id(const struct perf_tool *tool, + struct perf_sample *sample, + struct machine *machine, + perf_event__handler_t process, + const struct evsel *evsel, + __u16 misc, + __u32 pid, __u32 tid, + __u64 start, __u64 len, __u64 pgoff, + const struct build_id *bid, + __u32 prot, __u32 flags, + const char *filename); int perf_event__synthesize_cpu_map(const struct perf_tool *tool, const str= uct perf_cpu_map *cpus, perf_event__handler_t process, struct machine *mach= ine); int perf_event__synthesize_event_update_cpus(const struct perf_tool *tool,= struct evsel *evsel, perf_event__handler_t process); int perf_event__synthesize_event_update_name(const struct perf_tool *tool,= struct evsel *evsel, perf_event__handler_t process); --=20 2.46.0.184.g6999bdac58-goog From nobody Sat Feb 7 12:29:48 2026 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.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 44A6913FD86 for ; Sat, 17 Aug 2024 06:45:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723877131; cv=none; b=m6ixvM7bwkdonjAShQi1owMPLzx1WKLbd/mQIgq5gJpnbMER9OehAu1oBEqq/SQTedI/ecNBX+csR2S/KmJxPYGWYrVBXWlPy+OoTiR9J3oc2Hue8YVJxgwLgwCOHUg0PaX4joXZoomoJbq8qHW64itUsTCDz6pcbbK0WavQtXo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723877131; c=relaxed/simple; bh=VnhhslHkaD4cCwbYqZhzz2/fkKI4DNPiJVg+COtL2pQ=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=hldunjPiwy9q7nKz4Pqg//uv9ekfuHvOdjK/0kl/8U+pcl6RGOAoM/E3UurES9Q6cWWCWNCLCzL6JN2Aj8+oN4iPBJwyGwluydDqeNMnPmipPktY8RCG5hK6zRJNPEcMmiiMSg9PgOYyUfTocjSTAlpc2Pti13iG8+FZNUpjVYQ= 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=3dS96kLB; arc=none smtp.client-ip=209.85.128.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="3dS96kLB" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6506bfeaf64so40592187b3.1 for ; Fri, 16 Aug 2024 23:45:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1723877129; x=1724481929; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=His0pYvOMvESQ2So15V1L43VruSGtFsE9vF3maA0zqQ=; b=3dS96kLB2UNjl+ObvXcfCfFsDYuMLjazieXszB+eIzvsy43Fxi821lhntfkEZvsxS2 1fg0JFHIe4iSSe2McwOEVDgnLeHfsSLQr9Tlidby1/LymSutrJVJ2p9DXMMI5/WjvpQS Vv8D9V+4r3VzpKJmON+HoCEPHcSiCvtn04tEcwn48yvx88BAVjolf3hUIY6haU2/nFwi akWmVGcCXK/1d20VsxyscImslgXk6AlmI/gXgllPAzYHEqUjOnxJBv7sB+aNNYEGd3BR mNpXeXiltY8aNPf+MqLfelIhLlAbHwutA4h1N2s5QEgiksMw+00Wvjz/MI1crryut5kH Qrdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723877129; x=1724481929; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=His0pYvOMvESQ2So15V1L43VruSGtFsE9vF3maA0zqQ=; b=HEzzpRRTC+WMpjC/9ZWPRDRHJA2VQ4GxxJvc3QjQlKmajrK3F4Dor7EFB/mUvUejLt KJmQRaDePI+puELeVJZfzQoWiAa8EehNVU42xAusBjWKPZ0wi1taA23VmsL8xGXaDGBC hDKYp49YlcIfn8hG7Y+qZOCkXFeUa+vUQwUb03CwzhGzY1NGASTP3t3ZZp+wjomIzo+W slf/KrkmouXUqnsT1e9kAqzyTE36xKpJ3kNsQqc5Lgq35DevZylZ1sbnUtOXmCl625HV yb+uVn1kNzIUJd4t4t8V/QVv2LhjX7fb61DzDyMIpSax0vPMYS/AeSlNZm4rB6jDtW8X MDVw== X-Forwarded-Encrypted: i=1; AJvYcCX7EK6/7jtPgc9G2hUq4WD24W9l6yRr+5TeGSSXfsGxkNw7DM8v7inW2+XiCisfZ9QoCSDi+kPG2sx9P4fLrk5ZomSQd/Gn0Qh0KmKR X-Gm-Message-State: AOJu0YzGWBg0+lZZ+5e0lcw60u0ivvlqn1wRZEmBPPrI0Y+c90Gk0q16 MBlUPFy7eVebvNKbBsbFfJENwZssHLTcXt7MV+LUorqRD8/0EKS0jAYMm51plFDw9AxL0jsDZYy E+eMcCQ== X-Google-Smtp-Source: AGHT+IFQKhgp0W3SvzFWr5GF42xG1sD5n1dv9Y/pMZdZM6IiAqUpv0hBnIIr0MQsm0E4/fBlO+PuC9Um3l2z X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:78c9:5e58:734f:c59f]) (user=irogers job=sendgmr) by 2002:a05:690c:4084:b0:667:8a45:d0f9 with SMTP id 00721157ae682-6b1b1e5d0dcmr1703327b3.0.1723877129211; Fri, 16 Aug 2024 23:45:29 -0700 (PDT) Date: Fri, 16 Aug 2024 23:44:41 -0700 In-Reply-To: <20240817064442.2152089-1-irogers@google.com> Message-Id: <20240817064442.2152089-13-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240817064442.2152089-1-irogers@google.com> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog Subject: [PATCH v1 12/13] perf inject: Lazy build-id mmap2 event insertion 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 , Masahiro Yamada , Arnd Bergmann , Jann Horn , Colin Ian King , Casey Chen , Athira Rajeev , Chaitanya S Prakash , James Clark , Ze Gao , Yang Jihong , Yunseong Kim , Weilin Wang , Dominique Martinet , Anne Macedo , Sun Haiyong , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add -B option that lazily inserts mmap2 events thereby dropping all mmap events without samples. This is similar to the behavior of -b where only build_id events are inserted when a dso is accessed in a sample. File size savings can be significant in system-wide mode, consider: ``` $ perf record -g -a -o perf.data sleep 1 $ perf inject -B -i perf.data -o perf.new.data $ ls -al perf.data perf.new.data 5147049 perf.data 2248493 perf.new.data ``` Give test coverage of the new option in pipe test. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/builtin-inject.c | 62 +++++++++++++++++++++++------ tools/perf/tests/shell/pipe_test.sh | 1 + tools/perf/util/map.c | 1 + tools/perf/util/map.h | 11 +++++ 4 files changed, 63 insertions(+), 12 deletions(-) diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index 86425cade30e..2ff246f56a44 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -108,6 +108,7 @@ enum build_id_rewrite_style { BID_RWS__INJECT_HEADER_LAZY, BID_RWS__INJECT_HEADER_ALL, BID_RWS__MMAP2_BUILDID_ALL, + BID_RWS__MMAP2_BUILDID_LAZY, }; =20 struct perf_inject { @@ -527,7 +528,8 @@ static int perf_event__repipe_common_mmap(const struct = perf_tool *tool, * Remember the evsel for lazy build id generation. It is used * for the sample id header type. */ - if (inject->build_id_style =3D=3D BID_RWS__INJECT_HEADER_LAZY && + if ((inject->build_id_style =3D=3D BID_RWS__INJECT_HEADER_LAZY || + inject->build_id_style =3D=3D BID_RWS__MMAP2_BUILDID_LAZY) && !inject->mmap_evsel) inject->mmap_evsel =3D evlist__event2evsel(inject->session->evlist, eve= nt); =20 @@ -560,6 +562,9 @@ static int perf_event__repipe_common_mmap(const struct = perf_tool *tool, } } dso__put(dso); + if (inject->build_id_style =3D=3D BID_RWS__MMAP2_BUILDID_LAZY) + return 0; + return perf_event__repipe(tool, event, sample, machine); } =20 @@ -825,7 +830,8 @@ static int dso__inject_mmap2_build_id(const struct perf= _tool *tool, return 0; } =20 -static int mark_dso_hit(const struct perf_tool *tool, +static int mark_dso_hit(const struct perf_inject *inject, + const struct perf_tool *tool, struct perf_sample *sample, struct machine *machine, const struct evsel *mmap_evsel, @@ -854,16 +860,39 @@ static int mark_dso_hit(const struct perf_tool *tool, } } dso =3D map__dso(map); - if (dso && !dso__hit(dso)) { - dso__set_hit(dso); - dso__inject_build_id(tool, sample, machine, - mmap_evsel, misc, dso__long_name(dso), dso, - map__flags(map)); + if (inject->build_id_style =3D=3D BID_RWS__INJECT_HEADER_LAZY) { + if (dso && !dso__hit(dso)) { + dso__set_hit(dso); + dso__inject_build_id(tool, sample, machine, + mmap_evsel, misc, dso__long_name(dso), dso, + map__flags(map)); + } + } else if (inject->build_id_style =3D=3D BID_RWS__MMAP2_BUILDID_LAZY) { + if (!map__hit(map)) { + const struct build_id null_bid =3D { .size =3D 0 }; + const struct build_id *bid =3D dso ? dso__bid(dso) : &null_bid; + const char *filename =3D dso ? dso__long_name(dso) : ""; + + map__set_hit(map); + perf_event__synthesize_mmap2_build_id(tool, sample, machine, + perf_event__repipe, + mmap_evsel, + misc, + sample->pid, sample->tid, + map__start(map), + map__end(map) - map__start(map), + map__pgoff(map), + bid, + map__prot(map), + map__flags(map), + filename); + } } return 0; } =20 struct mark_dso_hit_args { + const struct perf_inject *inject; const struct perf_tool *tool; struct perf_sample *sample; struct machine *machine; @@ -875,7 +904,7 @@ static int mark_dso_hit_callback(struct callchain_curso= r_node *node, void *data) struct mark_dso_hit_args *args =3D data; struct map *map =3D node->ms.map; =20 - return mark_dso_hit(args->tool, args->sample, args->machine, + return mark_dso_hit(args->inject, args->tool, args->sample, args->machine, args->mmap_evsel, map, /*sample_in_dso=3D*/false); } =20 @@ -888,6 +917,7 @@ int perf_event__inject_buildid(const struct perf_tool *= tool, union perf_event *e struct thread *thread; struct perf_inject *inject =3D container_of(tool, struct perf_inject, too= l); struct mark_dso_hit_args args =3D { + .inject =3D inject, .tool =3D tool, /* * Use the parsed sample data of the sample event, which will @@ -907,7 +937,7 @@ int perf_event__inject_buildid(const struct perf_tool *= tool, union perf_event *e } =20 if (thread__find_map(thread, sample->cpumode, sample->ip, &al)) { - mark_dso_hit(tool, sample, machine, args.mmap_evsel, al.map, + mark_dso_hit(inject, tool, sample, machine, args.mmap_evsel, al.map, /*sample_in_dso=3D*/true); } =20 @@ -2151,7 +2181,8 @@ static int __cmd_inject(struct perf_inject *inject) =20 output_data_offset =3D perf_session__data_offset(session->evlist); =20 - if (inject->build_id_style =3D=3D BID_RWS__INJECT_HEADER_LAZY) { + if (inject->build_id_style =3D=3D BID_RWS__INJECT_HEADER_LAZY || + inject->build_id_style =3D=3D BID_RWS__MMAP2_BUILDID_LAZY) { inject->tool.sample =3D perf_event__inject_buildid; } else if (inject->sched_stat) { struct evsel *evsel; @@ -2334,6 +2365,7 @@ int cmd_inject(int argc, const char **argv) const char *known_build_ids =3D NULL; bool build_ids; bool build_id_all; + bool mmap2_build_ids; bool mmap2_build_id_all; =20 struct option options[] =3D { @@ -2341,6 +2373,8 @@ int cmd_inject(int argc, const char **argv) "Inject build-ids into the output stream"), OPT_BOOLEAN(0, "buildid-all", &build_id_all, "Inject build-ids of all DSOs into the output stream"), + OPT_BOOLEAN('B', "mmap2-buildids", &mmap2_build_ids, + "Drop unused mmap events, make others mmap2 with build IDs"), OPT_BOOLEAN(0, "mmap2-buildid-all", &mmap2_build_id_all, "Rewrite all mmap events as mmap2 events with build IDs"), OPT_STRING(0, "known-build-ids", &known_build_ids, @@ -2439,6 +2473,8 @@ int cmd_inject(int argc, const char **argv) return -1; } } + if (mmap2_build_ids) + inject.build_id_style =3D BID_RWS__MMAP2_BUILDID_LAZY; if (mmap2_build_id_all) inject.build_id_style =3D BID_RWS__MMAP2_BUILDID_ALL; if (build_ids) @@ -2458,7 +2494,8 @@ int cmd_inject(int argc, const char **argv) repipe =3D false; } ordered_events =3D inject.jit_mode || inject.sched_stat || - (inject.build_id_style =3D=3D BID_RWS__INJECT_HEADER_LAZY); + inject.build_id_style =3D=3D BID_RWS__INJECT_HEADER_LAZY || + inject.build_id_style =3D=3D BID_RWS__MMAP2_BUILDID_LAZY; perf_tool__init(&inject.tool, ordered_events); inject.tool.sample =3D perf_event__repipe_sample; inject.tool.read =3D perf_event__repipe_sample; @@ -2530,7 +2567,8 @@ int cmd_inject(int argc, const char **argv) goto out_delete; } =20 - if (inject.build_id_style =3D=3D BID_RWS__INJECT_HEADER_LAZY) { + if (inject.build_id_style =3D=3D BID_RWS__INJECT_HEADER_LAZY || + inject.build_id_style =3D=3D BID_RWS__MMAP2_BUILDID_LAZY) { /* * to make sure the mmap records are ordered correctly * and so that the correct especially due to jitted code diff --git a/tools/perf/tests/shell/pipe_test.sh b/tools/perf/tests/shell/p= ipe_test.sh index 1cacd6f15bcb..9b1fcbfeb837 100755 --- a/tools/perf/tests/shell/pipe_test.sh +++ b/tools/perf/tests/shell/pipe_test.sh @@ -90,6 +90,7 @@ test_inject_bids() { } =20 test_record_report +test_inject_bids -B test_inject_bids -b test_inject_bids --buildid-all test_inject_bids --mmap2-buildid-all diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c index e781c8d56a9a..d729438b7d65 100644 --- a/tools/perf/util/map.c +++ b/tools/perf/util/map.c @@ -116,6 +116,7 @@ static void map__init(struct map *map, u64 start, u64 e= nd, u64 pgoff, map__set_mapping_type(map, MAPPING_TYPE__DSO); assert(map__erange_warned(map) =3D=3D false); assert(map__priv(map) =3D=3D false); + assert(map__hit(map) =3D=3D false); } =20 struct map *map__new(struct machine *machine, u64 start, u64 len, diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h index 6c43f31a9fe0..4262f5a143be 100644 --- a/tools/perf/util/map.h +++ b/tools/perf/util/map.h @@ -35,6 +35,7 @@ DECLARE_RC_STRUCT(map) { enum mapping_type mapping_type:8; bool erange_warned; bool priv; + bool hit; }; =20 struct kmap; @@ -83,6 +84,11 @@ static inline bool map__priv(const struct map *map) return RC_CHK_ACCESS(map)->priv; } =20 +static inline bool map__hit(const struct map *map) +{ + return RC_CHK_ACCESS(map)->hit; +} + static inline refcount_t *map__refcnt(struct map *map) { return &RC_CHK_ACCESS(map)->refcnt; @@ -287,6 +293,11 @@ static inline void map__set_priv(struct map *map) RC_CHK_ACCESS(map)->priv =3D true; } =20 +static inline void map__set_hit(struct map *map) +{ + RC_CHK_ACCESS(map)->hit =3D true; +} + static inline void map__set_erange_warned(struct map *map) { RC_CHK_ACCESS(map)->erange_warned =3D true; --=20 2.46.0.184.g6999bdac58-goog From nobody Sat Feb 7 12:29:48 2026 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 30B40148826 for ; Sat, 17 Aug 2024 06:45:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723877134; cv=none; b=dqIo+hyWjU1m+Y/C1SfXquVJObsn7407bo01x5ERIEiM1ZHqWTRxJq9MnFqB7tFEU5dGEC0xq/XFixsfFpXunx9aHlxRrUh5CCX7JHSfcfht1G5F7C4SoPWK6NfCoRFQI8rPSAS+zpVCBrojjBmGZYvKGvZfZgB43yPs41aqcBw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723877134; c=relaxed/simple; bh=T+vkABo8pfjGvY2NJBEP+BbLwKM2texesBTDSZzCQeo=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=rbXx5jGJTRVhaHbxUEr5l4prEq966m9IYvIwfvz9DGCF0jTklNZbHBL4zrYcSMRvYNpg1wnvCOdM+2WhWDJHd/RN8QB0vrJLpuWIKGtHA6YmJH8QwpGIEu6Kf3PA4E3Ia/HqEj85VFyznnYxoVst2jU44wJPNBnqVwthOrnsDlY= 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=MBcRtOvB; arc=none smtp.client-ip=209.85.128.202 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="MBcRtOvB" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6addeef41a2so50614767b3.2 for ; Fri, 16 Aug 2024 23:45:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1723877131; x=1724481931; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=9vs/ATUqSidqRIzdN2QwVwb6M41EgV7LbTTqskLbY2Q=; b=MBcRtOvBjHuzQ81K2qj/bR1qRjX/NBiNaFaw8RHW9Kb/H34rxMdtSXAaga6Ocs6OzL RIlk/Q+n7ZsU+S0/VllmWb7gD+hSYHXd7CBqKynxtbe11HPAZTKQPESXgkBBpltznt7A MVC5h2ScQxTm5Oo5bq4BCPrnZzf7VAZP81FQPbabtcnBV0lrRxiUU9GacnIeNgvXYAWh qOOrX8vhTsOQ1r6OQPgVD1JVv5jQ0zmoNBiNkwvvuLneU3u4uim/Yl/MQQ3tCeYZUs90 181me0DbLojvaB8UQegRPoTT9ui1OesIZjGPo3RN0F2rCrsAoujwVcb0fF2vZAOVxszY MC0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723877131; x=1724481931; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=9vs/ATUqSidqRIzdN2QwVwb6M41EgV7LbTTqskLbY2Q=; b=IbxZJdLZwmuo46rzk/UHtABspSFYJ02WyMbffedsnApUpLQx5rj6++Q++fay9gYkk0 NwSrL344IXJbrthkzxHZM/88TSLMGny2TbcT7u9I59Z4ppLHEnCGelSyf60TB+ScE3OB jK4hGJVSaWw3aplZmluBoTVf7cwjCrSvRfmfOUS+HIuD2hUZz83aYGsGAFw3eDdwuTte WMPSdw21dUtcDsDFsBlJ0OQWsa7+w0rSSGSBc8qwcnBKL8C4b/MSuZ2Jldsh3ctP1exQ PeFM39ckQSK5k4c9R/u44zpCwVnJujEEbo9PzOqfGIyixV+bYS6W/TqtvWgLtcdqL/e8 M+Wg== X-Forwarded-Encrypted: i=1; AJvYcCWhzz8orelgwbeB1ZhXrjhQ998Eo0LlBwK1Lyk5WvCyTJItwUjn+a/xC5L03gR6+s0V1DXSs5pZFtny0XgJD5oQ/BsNadH/7p/1NLG3 X-Gm-Message-State: AOJu0YzrqXznFrFuLF992xBLqV8osRvn6KALESnwVfh6qCZj1BsGn0rf Znqe85jwlL53+qPULYNKvv0MnsQb3vppuFi89kwaEtIJ+acRETisnZynBJeNBzMRZ02Hm5Z6IfJ wh/Q5OQ== X-Google-Smtp-Source: AGHT+IF6f83tDj9w+yBgzQZgrB/tfugQj/LzXEEgJgaYJ+HcUK3RgmIsHTTvviaw6SxOuRaRQXJampnNms/V X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:78c9:5e58:734f:c59f]) (user=irogers job=sendgmr) by 2002:a05:690c:2a87:b0:62c:f976:a763 with SMTP id 00721157ae682-6b1b7595cd4mr1426637b3.1.1723877131385; Fri, 16 Aug 2024 23:45:31 -0700 (PDT) Date: Fri, 16 Aug 2024 23:44:42 -0700 In-Reply-To: <20240817064442.2152089-1-irogers@google.com> Message-Id: <20240817064442.2152089-14-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240817064442.2152089-1-irogers@google.com> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog Subject: [PATCH v1 13/13] perf callchain: Allow symbols to be optional when resolving a callchain 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 , Masahiro Yamada , Arnd Bergmann , Jann Horn , Colin Ian King , Casey Chen , Athira Rajeev , Chaitanya S Prakash , James Clark , Ze Gao , Yang Jihong , Yunseong Kim , Weilin Wang , Dominique Martinet , Anne Macedo , Sun Haiyong , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In uses like perf inject it is not necessary to gather the symbol for each call chain location, the map for the sample IP is wanted so that build IDs and the like can be injected. Make gathering the symbol in the callchain_cursor optional. For a perf inject -B command this lowers the peak RSS from 54.1MB to 29.6MB by avoiding loading symbols. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/builtin-inject.c | 2 +- tools/perf/util/callchain.c | 8 ++-- tools/perf/util/callchain.h | 2 +- tools/perf/util/machine.c | 92 +++++++++++++++++++++---------------- tools/perf/util/machine.h | 33 ++++++++++--- 5 files changed, 85 insertions(+), 52 deletions(-) diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index 2ff246f56a44..8ad7cc5f0c63 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -942,7 +942,7 @@ int perf_event__inject_buildid(const struct perf_tool *= tool, union perf_event *e } =20 sample__for_each_callchain_node(thread, evsel, sample, PERF_MAX_STACK_DEP= TH, - mark_dso_hit_callback, &args); + /*symbols=3D*/false, mark_dso_hit_callback, &args); =20 thread__put(thread); repipe: diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c index 0d608e875fe9..0c7564747a14 100644 --- a/tools/perf/util/callchain.c +++ b/tools/perf/util/callchain.c @@ -1800,7 +1800,7 @@ s64 callchain_avg_cycles(struct callchain_node *cnode) =20 int sample__for_each_callchain_node(struct thread *thread, struct evsel *e= vsel, struct perf_sample *sample, int max_stack, - callchain_iter_fn cb, void *data) + bool symbols, callchain_iter_fn cb, void *data) { struct callchain_cursor *cursor =3D get_tls_callchain_cursor(); int ret; @@ -1809,9 +1809,9 @@ int sample__for_each_callchain_node(struct thread *th= read, struct evsel *evsel, return -ENOMEM; =20 /* Fill in the callchain. */ - ret =3D thread__resolve_callchain(thread, cursor, evsel, sample, - /*parent=3D*/NULL, /*root_al=3D*/NULL, - max_stack); + ret =3D __thread__resolve_callchain(thread, cursor, evsel, sample, + /*parent=3D*/NULL, /*root_al=3D*/NULL, + max_stack, symbols); if (ret) return ret; =20 diff --git a/tools/perf/util/callchain.h b/tools/perf/util/callchain.h index 76891f8e2373..86ed9e4d04f9 100644 --- a/tools/perf/util/callchain.h +++ b/tools/perf/util/callchain.h @@ -315,6 +315,6 @@ typedef int (*callchain_iter_fn)(struct callchain_curso= r_node *node, void *data) =20 int sample__for_each_callchain_node(struct thread *thread, struct evsel *e= vsel, struct perf_sample *sample, int max_stack, - callchain_iter_fn cb, void *data); + bool symbols, callchain_iter_fn cb, void *data); =20 #endif /* __PERF_CALLCHAIN_H */ diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index cd79a830abae..6cffee6f9891 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -2059,7 +2059,8 @@ static int add_callchain_ip(struct thread *thread, bool branch, struct branch_flags *flags, struct iterations *iter, - u64 branch_from) + u64 branch_from, + bool symbols) { struct map_symbol ms =3D {}; struct addr_location al; @@ -2098,7 +2099,8 @@ static int add_callchain_ip(struct thread *thread, } goto out; } - thread__find_symbol(thread, *cpumode, ip, &al); + if (symbols) + thread__find_symbol(thread, *cpumode, ip, &al); } =20 if (al.sym !=3D NULL) { @@ -2227,7 +2229,8 @@ static int lbr_callchain_add_kernel_ip(struct thread = *thread, struct symbol **parent, struct addr_location *root_al, u64 branch_from, - bool callee, int end) + bool callee, int end, + bool symbols) { struct ip_callchain *chain =3D sample->callchain; u8 cpumode =3D PERF_RECORD_MISC_USER; @@ -2237,7 +2240,8 @@ static int lbr_callchain_add_kernel_ip(struct thread = *thread, for (i =3D 0; i < end + 1; i++) { err =3D add_callchain_ip(thread, cursor, parent, root_al, &cpumode, chain->ips[i], - false, NULL, NULL, branch_from); + false, NULL, NULL, branch_from, + symbols); if (err) return err; } @@ -2247,7 +2251,8 @@ static int lbr_callchain_add_kernel_ip(struct thread = *thread, for (i =3D end; i >=3D 0; i--) { err =3D add_callchain_ip(thread, cursor, parent, root_al, &cpumode, chain->ips[i], - false, NULL, NULL, branch_from); + false, NULL, NULL, branch_from, + symbols); if (err) return err; } @@ -2290,7 +2295,8 @@ static int lbr_callchain_add_lbr_ip(struct thread *th= read, struct symbol **parent, struct addr_location *root_al, u64 *branch_from, - bool callee) + bool callee, + bool symbols) { struct branch_stack *lbr_stack =3D sample->branch_stack; struct branch_entry *entries =3D perf_sample__branch_entries(sample); @@ -2323,7 +2329,7 @@ static int lbr_callchain_add_lbr_ip(struct thread *th= read, err =3D add_callchain_ip(thread, cursor, parent, root_al, &cpumode, ip, true, flags, NULL, - *branch_from); + *branch_from, symbols); if (err) return err; =20 @@ -2348,7 +2354,7 @@ static int lbr_callchain_add_lbr_ip(struct thread *th= read, err =3D add_callchain_ip(thread, cursor, parent, root_al, &cpumode, ip, true, flags, NULL, - *branch_from); + *branch_from, symbols); if (err) return err; save_lbr_cursor_node(thread, cursor, i); @@ -2363,7 +2369,7 @@ static int lbr_callchain_add_lbr_ip(struct thread *th= read, err =3D add_callchain_ip(thread, cursor, parent, root_al, &cpumode, ip, true, flags, NULL, - *branch_from); + *branch_from, symbols); if (err) return err; save_lbr_cursor_node(thread, cursor, i); @@ -2377,7 +2383,7 @@ static int lbr_callchain_add_lbr_ip(struct thread *th= read, err =3D add_callchain_ip(thread, cursor, parent, root_al, &cpumode, ip, true, flags, NULL, - *branch_from); + *branch_from, symbols); if (err) return err; } @@ -2544,7 +2550,8 @@ static int resolve_lbr_callchain_sample(struct thread= *thread, struct symbol **parent, struct addr_location *root_al, int max_stack, - unsigned int max_lbr) + unsigned int max_lbr, + bool symbols) { bool callee =3D (callchain_param.order =3D=3D ORDER_CALLEE); struct ip_callchain *chain =3D sample->callchain; @@ -2586,12 +2593,12 @@ static int resolve_lbr_callchain_sample(struct thre= ad *thread, /* Add kernel ip */ err =3D lbr_callchain_add_kernel_ip(thread, cursor, sample, parent, root_al, branch_from, - true, i); + true, i, symbols); if (err) goto error; =20 err =3D lbr_callchain_add_lbr_ip(thread, cursor, sample, parent, - root_al, &branch_from, true); + root_al, &branch_from, true, symbols); if (err) goto error; =20 @@ -2608,14 +2615,14 @@ static int resolve_lbr_callchain_sample(struct thre= ad *thread, goto error; } err =3D lbr_callchain_add_lbr_ip(thread, cursor, sample, parent, - root_al, &branch_from, false); + root_al, &branch_from, false, symbols); if (err) goto error; =20 /* Add kernel ip */ err =3D lbr_callchain_add_kernel_ip(thread, cursor, sample, parent, root_al, branch_from, - false, i); + false, i, symbols); if (err) goto error; } @@ -2629,7 +2636,7 @@ static int find_prev_cpumode(struct ip_callchain *cha= in, struct thread *thread, struct callchain_cursor *cursor, struct symbol **parent, struct addr_location *root_al, - u8 *cpumode, int ent) + u8 *cpumode, int ent, bool symbols) { int err =3D 0; =20 @@ -2639,7 +2646,7 @@ static int find_prev_cpumode(struct ip_callchain *cha= in, struct thread *thread, if (ip >=3D PERF_CONTEXT_MAX) { err =3D add_callchain_ip(thread, cursor, parent, root_al, cpumode, ip, - false, NULL, NULL, 0); + false, NULL, NULL, 0, symbols); break; } } @@ -2661,7 +2668,8 @@ static int thread__resolve_callchain_sample(struct th= read *thread, struct perf_sample *sample, struct symbol **parent, struct addr_location *root_al, - int max_stack) + int max_stack, + bool symbols) { struct branch_stack *branch =3D sample->branch_stack; struct branch_entry *entries =3D perf_sample__branch_entries(sample); @@ -2681,7 +2689,8 @@ static int thread__resolve_callchain_sample(struct th= read *thread, =20 err =3D resolve_lbr_callchain_sample(thread, cursor, sample, parent, root_al, max_stack, - !env ? 0 : env->max_branches); + !env ? 0 : env->max_branches, + symbols); if (err) return (err < 0) ? err : 0; } @@ -2746,13 +2755,14 @@ static int thread__resolve_callchain_sample(struct = thread *thread, root_al, NULL, be[i].to, true, &be[i].flags, - NULL, be[i].from); + NULL, be[i].from, symbols); =20 - if (!err) + if (!err) { err =3D add_callchain_ip(thread, cursor, parent, root_al, NULL, be[i].from, true, &be[i].flags, - &iter[i], 0); + &iter[i], 0, symbols); + } if (err =3D=3D -EINVAL) break; if (err) @@ -2768,7 +2778,7 @@ static int thread__resolve_callchain_sample(struct th= read *thread, check_calls: if (chain && callchain_param.order !=3D ORDER_CALLEE) { err =3D find_prev_cpumode(chain, thread, cursor, parent, root_al, - &cpumode, chain->nr - first_call); + &cpumode, chain->nr - first_call, symbols); if (err) return (err < 0) ? err : 0; } @@ -2790,7 +2800,7 @@ static int thread__resolve_callchain_sample(struct th= read *thread, ++nr_entries; else if (callchain_param.order !=3D ORDER_CALLEE) { err =3D find_prev_cpumode(chain, thread, cursor, parent, - root_al, &cpumode, j); + root_al, &cpumode, j, symbols); if (err) return (err < 0) ? err : 0; continue; @@ -2817,8 +2827,8 @@ static int thread__resolve_callchain_sample(struct th= read *thread, if (leaf_frame_caller && leaf_frame_caller !=3D ip) { =20 err =3D add_callchain_ip(thread, cursor, parent, - root_al, &cpumode, leaf_frame_caller, - false, NULL, NULL, 0); + root_al, &cpumode, leaf_frame_caller, + false, NULL, NULL, 0, symbols); if (err) return (err < 0) ? err : 0; } @@ -2826,7 +2836,7 @@ static int thread__resolve_callchain_sample(struct th= read *thread, =20 err =3D add_callchain_ip(thread, cursor, parent, root_al, &cpumode, ip, - false, NULL, NULL, 0); + false, NULL, NULL, 0, symbols); =20 if (err) return (err < 0) ? err : 0; @@ -2906,7 +2916,7 @@ static int thread__resolve_callchain_unwind(struct th= read *thread, struct callchain_cursor *cursor, struct evsel *evsel, struct perf_sample *sample, - int max_stack) + int max_stack, bool symbols) { /* Can we do dwarf post unwind? */ if (!((evsel->core.attr.sample_type & PERF_SAMPLE_REGS_USER) && @@ -2918,17 +2928,21 @@ static int thread__resolve_callchain_unwind(struct = thread *thread, (!sample->user_stack.size)) return 0; =20 + if (!symbols) + pr_debug("Not resolving symbols with an unwinder isn't currently support= ed\n"); + return unwind__get_entries(unwind_entry, cursor, thread, sample, max_stack, false); } =20 -int thread__resolve_callchain(struct thread *thread, - struct callchain_cursor *cursor, - struct evsel *evsel, - struct perf_sample *sample, - struct symbol **parent, - struct addr_location *root_al, - int max_stack) +int __thread__resolve_callchain(struct thread *thread, + struct callchain_cursor *cursor, + struct evsel *evsel, + struct perf_sample *sample, + struct symbol **parent, + struct addr_location *root_al, + int max_stack, + bool symbols) { int ret =3D 0; =20 @@ -2941,22 +2955,22 @@ int thread__resolve_callchain(struct thread *thread, ret =3D thread__resolve_callchain_sample(thread, cursor, evsel, sample, parent, root_al, - max_stack); + max_stack, symbols); if (ret) return ret; ret =3D thread__resolve_callchain_unwind(thread, cursor, evsel, sample, - max_stack); + max_stack, symbols); } else { ret =3D thread__resolve_callchain_unwind(thread, cursor, evsel, sample, - max_stack); + max_stack, symbols); if (ret) return ret; ret =3D thread__resolve_callchain_sample(thread, cursor, evsel, sample, parent, root_al, - max_stack); + max_stack, symbols); } =20 return ret; diff --git a/tools/perf/util/machine.h b/tools/perf/util/machine.h index a687876e3453..2e5a4cb342d8 100644 --- a/tools/perf/util/machine.h +++ b/tools/perf/util/machine.h @@ -178,13 +178,32 @@ struct mem_info *sample__resolve_mem(struct perf_samp= le *sample, =20 struct callchain_cursor; =20 -int thread__resolve_callchain(struct thread *thread, - struct callchain_cursor *cursor, - struct evsel *evsel, - struct perf_sample *sample, - struct symbol **parent, - struct addr_location *root_al, - int max_stack); +int __thread__resolve_callchain(struct thread *thread, + struct callchain_cursor *cursor, + struct evsel *evsel, + struct perf_sample *sample, + struct symbol **parent, + struct addr_location *root_al, + int max_stack, + bool symbols); + +static inline int thread__resolve_callchain(struct thread *thread, + struct callchain_cursor *cursor, + struct evsel *evsel, + struct perf_sample *sample, + struct symbol **parent, + struct addr_location *root_al, + int max_stack) +{ + return __thread__resolve_callchain(thread, + cursor, + evsel, + sample, + parent, + root_al, + max_stack, + /*symbols=3D*/true); +} =20 /* * Default guest kernel is defined by parameter --guestkallsyms --=20 2.46.0.184.g6999bdac58-goog