Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp2186278rda; Tue, 24 Oct 2023 15:28:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHKrYZxYSpGnUF2ejsjOtKbznhhccSOu31+REz94jaJ3sCN44wuaqUITaCX303Kx1/db8fg X-Received: by 2002:a17:90b:528e:b0:27c:fdc6:c52 with SMTP id si14-20020a17090b528e00b0027cfdc60c52mr9868785pjb.30.1698186486474; Tue, 24 Oct 2023 15:28:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698186486; cv=none; d=google.com; s=arc-20160816; b=z6SklFDsMlJuqPx8qetbQLvXOSsXW1fx9T3C8pbFaz0VqFIbfLRLyhjL87I3oj/dcD 94TtqoqEhyFU8Dfd63mL9TV/fn7gZvhTNgARH4cSTTSZaDBVafdZSaUjzpwOiSRAjAUG ppwgCJ5yzf7IMeHsyYgf6rpklJhKTHeSN60BqOyPsbNeWQxEUszddxjfeVz8XZo2GIaI l8K1UleKum6l5nMcOhIhlqgIaMj/7BNwBP4SCpuL1JqJp6TZ68eky6H28vBXaBp3fnp5 y8LKVKoFMrbWF1SYenrT8vni9BINSEYn7fMs3Zj9Xu2qa9mDWgY7eYuBuuUxqWNhmwml ot3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=g/BBcChnvHkmkYd/yKkYLm0W4V4ebv0lxjgGfrAGFAQ=; fh=NAro5oTsDEB2Or99ABwb774QJkwQSkr6EoLVqn/Yde0=; b=opuiOmuImKC0hDct5jlvPLFVZTbUaPT4TKq6SqditDFy+BlihsYMWHXXwoV/jj5dVa lr3YWl1QMoDTsBTa+S93a23c0YYwA4i7lDbE7IalwSAmy97sk7VNUOc1AsmcTujVNBPl wa/bOgoc3uWv4MSUs76FwxJPCOdnNluBB2r8C/mfyDi9/QjsSGRjGMp08PSKv3xqO/7Q FBXkNiju/xI5T+YALGL9tbC8JBUcW+wsA0WVWmyplkUM/r3yytgcQxZHDRfuILIodyMK OfL3J8z8jIPlGkX1+muGs/0B0o8UsDi+KPAv079VXf3wWZxpahXym6Ybl/e8JRs7qsM3 3bfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=IikWft0+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id h7-20020a17090adb8700b0027da14d1513si8606895pjv.124.2023.10.24.15.28.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 15:28:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=IikWft0+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 5E2C480219C7; Tue, 24 Oct 2023 15:28:02 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344627AbjJXW1c (ORCPT + 99 others); Tue, 24 Oct 2023 18:27:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344573AbjJXW1X (ORCPT ); Tue, 24 Oct 2023 18:27:23 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 791A42D53 for ; Tue, 24 Oct 2023 15:25:31 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5a7af53bde4so65534927b3.0 for ; Tue, 24 Oct 2023 15:25:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698186329; x=1698791129; 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=g/BBcChnvHkmkYd/yKkYLm0W4V4ebv0lxjgGfrAGFAQ=; b=IikWft0+Z2JZYapaYzZducsS8U/UZgqXninSEVB+zlH+i8i0EAC/IiJDMsOg/YwMgg 1vdiLwhQB8Yhct/2Aljp2ItEUU6WxI7oGstRkTzDu0PCYsvzZ/lTNDb6bXKKdoglzboL X5+Wwh7+RRHtobAaoZiTBg81555viJ7u6zG8StT0D05c4sO/ON7lvLvRbYQ/k+za7Khu dDSITUE9C9XWQy4dc9A/Iso3ALZ+17oHeiZbFLgdLzByROS+AFa4XNvHHzW/ZcNuGiO7 Of5VeO1ZiCeEo7UN4PM5PnpzWWDDlNUA0QdUtI1e9jovCqgY2Fxh1cn6PQuErjwH7OsW e10Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698186329; x=1698791129; 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=g/BBcChnvHkmkYd/yKkYLm0W4V4ebv0lxjgGfrAGFAQ=; b=fnVfqrizROxgGACRA9Wlf95tHqp/U7XIwXIVOL0LLeDrKLh5f9JYvawct5X9BQp3u1 gMlvkGdCTLTqOBgaODkV/IWJxuTqswCg9GP05giqkZJ6Q+FsxYh+YAIFFhQXWRBlwYuE tq88gHx09BzjRbmHqnPdXZJ/eAi8sYJosSpLwJmpWouFGAvR80jaQHZEAMat30FkwFhZ XJf3RW5g40pE9Zd5/gwJeAglK8a6Nt/oFe54/xWGJdNuW8BQgntVAWFEJF3sh9nbI6Of 8jN1JPZRYexziE3+Uipi21L07RwdxCr9SfEojNAcoAgOGwEI9D+rzYrC7cPnlqTvc87m RjTQ== X-Gm-Message-State: AOJu0Yyk6Q2TCSdzNuC2dr45A9fzXeh4tLC8jTBQEGLwDhDnL9a97F78 FntO4x3Vs4X9NZp+fWgI/KEJWktNqawo X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:93d2:18cc:4d63:45ba]) (user=irogers job=sendgmr) by 2002:a0d:d954:0:b0:595:5cf0:a9b0 with SMTP id b81-20020a0dd954000000b005955cf0a9b0mr293421ywe.9.1698186329522; Tue, 24 Oct 2023 15:25:29 -0700 (PDT) Date: Tue, 24 Oct 2023 15:23:37 -0700 In-Reply-To: <20231024222353.3024098-1-irogers@google.com> Message-Id: <20231024222353.3024098-35-irogers@google.com> Mime-Version: 1.0 References: <20231024222353.3024098-1-irogers@google.com> X-Mailer: git-send-email 2.42.0.758.gaed0368e0e-goog Subject: [PATCH v3 34/50] perf maps: Add maps__load_first 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 , Leo Yan , Song Liu , Sandipan Das , James Clark , Anshuman Khandual , Miguel Ojeda , Liam Howlett , Yang Jihong , Athira Rajeev , Kajol Jain , K Prateek Nayak , Sean Christopherson , Yanteng Si , Ravi Bangoria , German Gomez , Changbin Du , Paolo Bonzini , Masami Hiramatsu , liuwenyu , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Tue, 24 Oct 2023 15:28:02 -0700 (PDT) Avoid bpf_lock_contention_touching the internal maps data structure by adding a helper function. As access is done directly on the map in maps, hold the read lock to stop it being removed. Signed-off-by: Ian Rogers --- tools/perf/util/bpf_lock_contention.c | 2 +- tools/perf/util/maps.c | 13 +++++++++++++ tools/perf/util/maps.h | 2 ++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/bpf_lock_contention.c b/tools/perf/util/bpf_lock_contention.c index e105245eb905..d9720a910330 100644 --- a/tools/perf/util/bpf_lock_contention.c +++ b/tools/perf/util/bpf_lock_contention.c @@ -317,7 +317,7 @@ int lock_contention_read(struct lock_contention *con) } /* make sure it loads the kernel map */ - map__load(maps__first(machine->kmaps)->map); + maps__load_first(machine->kmaps); prev_key = NULL; while (!bpf_map_get_next_key(fd, prev_key, &key)) { diff --git a/tools/perf/util/maps.c b/tools/perf/util/maps.c index 85bea2a6dca9..9a84d26328a7 100644 --- a/tools/perf/util/maps.c +++ b/tools/perf/util/maps.c @@ -792,3 +792,16 @@ int maps__merge_in(struct maps *kmaps, struct map *new_map) } return err; } + +void maps__load_first(struct maps *maps) +{ + struct map_rb_node *first; + + down_read(maps__lock(maps)); + + first = maps__first(maps); + if (first) + map__load(first->map); + + up_read(maps__lock(maps)); +} diff --git a/tools/perf/util/maps.h b/tools/perf/util/maps.h index e4a49d6ff5cf..b7ab3ec61b7c 100644 --- a/tools/perf/util/maps.h +++ b/tools/perf/util/maps.h @@ -142,4 +142,6 @@ void __maps__sort_by_name(struct maps *maps); void maps__fixup_end(struct maps *maps); +void maps__load_first(struct maps *maps); + #endif // __PERF_MAPS_H -- 2.42.0.758.gaed0368e0e-goog