From nobody Sun Dec 28 17:30:29 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C55ECC4167B for ; Thu, 7 Dec 2023 01:18:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442953AbjLGBSN (ORCPT ); Wed, 6 Dec 2023 20:18:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1442994AbjLGBR7 (ORCPT ); Wed, 6 Dec 2023 20:17:59 -0500 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 712E910C0 for ; Wed, 6 Dec 2023 17:17:52 -0800 (PST) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5d67fc68a82so1628127b3.2 for ; Wed, 06 Dec 2023 17:17:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701911871; x=1702516671; 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=YLs18EUwcJ7v2oX/7NfyA6HjR14FLN4dfhaM88TGxMk=; b=kRAoV4bY/0iOfctTnaq+ytVR7KqTy05l2D/bibubFYQkj8uH7P3Deo2TPEbXHXKy2a Ludsm3nNLohmk6f+4232F4mRVjnwX4YGh3LuKVDT1+HZJi4zC3Nn/WINZpyyw21lgI/D Sy+M6UV3Hu7GyaL5HfkQrmKOruf8M+SYATjax+JEkUQE91sMd0oFjF7mQTlOzFbYueU5 TUyXCFOAFK4L89RiXOy7RFO99pqB24DI3Lzmj59qklAYLucsHDPUOXifbjlwfFs0jYdr b3q6oUzkdZYqjSAaBLIe1D45nwwmPde5h/n9E2enM1duFaYCgnerZ+9B9oRnl5qQ3TIp Ocjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701911871; x=1702516671; 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=YLs18EUwcJ7v2oX/7NfyA6HjR14FLN4dfhaM88TGxMk=; b=aM3ZSFOoiDodyVHcGrgPKN8n0AibjKJg5fHBvLLGyY4KP0LxtHuqd5mPI12LXOQ2Ub S/PdkxAjBvE0BOhjk8yXi1K1Fcg762fc3Mas54R8OBByVF4RLD4uXzHs6bXo9rbFDFUU z753jLHqiVcGfyvK0NxaqDbGw4W1pLcAF3kK6eaB7P3sBAtMpwveZ2c/ZiYob3ghv7SU VgLDzWfRW3NmuYkRIb5fWEo1lI/pmDXnuoc7H1WOpXTZts0V4JNSgLAWtSJ8OPjfFzTA UHC5cbxwj6srE6c0q7vFwvZnHl9uOvdr3/tPApzjd6RfNy1W6vdtuMREc15X7XQyVzSj Fn2Q== X-Gm-Message-State: AOJu0YzK6YEo/Som/6QjVO2H4p4L+deriz1c2UTyNUnE1JoIeUWibh1v QPt4EBkb3Pc6YFecNg3xhxIxudFh6zow X-Google-Smtp-Source: AGHT+IFPtjgGW+/HVbXi/s6styOGACrpE+wgUPXjW2RbA5UaZ5b03h7MXJLv7jWvZreh5E1/ayyPbBclxVlu X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:35bf:293e:7696:34e9]) (user=irogers job=sendgmr) by 2002:a05:690c:300e:b0:5d6:e473:bf60 with SMTP id ey14-20020a05690c300e00b005d6e473bf60mr24337ywb.8.1701911871171; Wed, 06 Dec 2023 17:17:51 -0800 (PST) Date: Wed, 6 Dec 2023 17:16:44 -0800 In-Reply-To: <20231207011722.1220634-1-irogers@google.com> Message-Id: <20231207011722.1220634-11-irogers@google.com> Mime-Version: 1.0 References: <20231207011722.1220634-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.rc2.451.g8631bc7472-goog Subject: [PATCH v6 10/47] perf thread: Use function to add missing maps lock From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Nick Terrell , Kan Liang , Andi Kleen , Kajol Jain , Athira Rajeev , Huacai Chen , Masami Hiramatsu , Vincent Whitchurch , "Steinar H. Gunderson" , Liam Howlett , Miguel Ojeda , Colin Ian King , Dmitrii Dolgov <9erthalion6@gmail.com>, Yang Jihong , Ming Wang , James Clark , K Prateek Nayak , Sean Christopherson , Leo Yan , Ravi Bangoria , German Gomez , Changbin Du , Paolo Bonzini , Li Dong , Sandipan Das , liuwenyu , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Guilherme Amadio Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Switch thread__prepare_access from loop macro maps__for_each_entry to maps__for_each_map function that takes a callback. The function holds the maps lock, which should be held during iteration. Signed-off-by: Ian Rogers --- tools/perf/util/thread.c | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c index b9c2039c4230..b6986a81aa6d 100644 --- a/tools/perf/util/thread.c +++ b/tools/perf/util/thread.c @@ -349,34 +349,33 @@ int thread__insert_map(struct thread *thread, struct = map *map) return maps__insert(thread__maps(thread), map); } =20 -static int __thread__prepare_access(struct thread *thread) +struct thread__prepare_access_maps_cb_args { + int err; + struct maps *maps; +}; + +static int thread__prepare_access_maps_cb(struct map *map, void *data) { bool initialized =3D false; - int err =3D 0; - struct maps *maps =3D thread__maps(thread); - struct map_rb_node *rb_node; - - down_read(maps__lock(maps)); - - maps__for_each_entry(maps, rb_node) { - err =3D unwind__prepare_access(thread__maps(thread), rb_node->map, &init= ialized); - if (err || initialized) - break; - } + struct thread__prepare_access_maps_cb_args *args =3D data; =20 - up_read(maps__lock(maps)); + args->err =3D unwind__prepare_access(args->maps, map, &initialized); =20 - return err; + return (args->err || initialized) ? 1 : 0; } =20 static int thread__prepare_access(struct thread *thread) { - int err =3D 0; + struct thread__prepare_access_maps_cb_args args =3D { + .err =3D 0, + }; =20 - if (dwarf_callchain_users) - err =3D __thread__prepare_access(thread); + if (dwarf_callchain_users) { + args.maps =3D thread__maps(thread); + maps__for_each_map(thread__maps(thread), thread__prepare_access_maps_cb,= &args); + } =20 - return err; + return args.err; } =20 static int thread__clone_maps(struct thread *thread, struct thread *parent= , bool do_maps_clone) --=20 2.43.0.rc2.451.g8631bc7472-goog