Received: by 2002:a05:7412:b795:b0:e2:908c:2ebd with SMTP id iv21csp554722rdb; Thu, 2 Nov 2023 11:00:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEHwBjJWVeJZfMAfWkeW1gk0nB6fVqhaV18gpYWe077qfaWow9CSFGmGj3QgRpRiNxIfJWu X-Received: by 2002:a05:6a21:7185:b0:180:e2b8:3b0e with SMTP id wq5-20020a056a21718500b00180e2b83b0emr10715747pzb.50.1698948057880; Thu, 02 Nov 2023 11:00:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698948057; cv=none; d=google.com; s=arc-20160816; b=kQr6WEwOxGyko/uC3KgJAIPmmGhCZb2F8Z8uySKBh1RdZzbZYTR7FgetzUT4SPAWev L3p80YPXbGIPTIIHf/1r+1vxi2PiC/gYxW8iXaMxkbkwJj4x2VIhJmi7jckMEUnym5DR mXR5reSRHyKt8eyOJJ9fBipjvH9u7dC6C4n1o7YNjNDQuq3lAC7yV8OyA5QbHTd3n18v 76yylgcuUfsdDxC8P93us601Xa8GKTye98OyAyB+jfL2riedNsGUvaR5sj1YhaVMNjKT JJ1U6XUP3h2HA/j9s0KZzAQJxdhm1CgVQH2KvKnvH/Zket0K0er9IH2FTPJbGN/w/g99 sGCQ== 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=UjGLpULVRUxYABNs8KK8hib6JmANLHcuQm1tIO1QTLc=; fh=z1KcSqUpYQ9oC4uLSeIkhAYTnJ2bvP0QbNW2xqV5NqA=; b=LFADvSpELag674Y1ctzOmrAvuH6KB20W9SBk2OOWpfLmoe7EdgRjHG4UcU/uY7nSv7 SBBRuLotRKtJIK248OkGLG7Rdo5rNzlQAEaKvKXHY3NOE8eN/QDPZzIKaILP9i9EgOLs +G3h5Q84oxsOYDg+4TxH55pZ5+KTMFWBJe56VjVX1KbIxvnTlbgn6NxKymYkq4AqMl2Z zgeKLBqV6ZREkPIChurN1bLqs3K53bxl1D4nEb1EdzXxjKviJhQy34wSbsSSqUPuVB5c uzMZFEgWamjBSN9cR0lx6TkiNMsMtqlUtMEDlV7WJD3LdPD1wXMiaj4mmYECeYXK84eI YP1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ER89x3QB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id i62-20020a636d41000000b005b98cb7b465si54844pgc.637.2023.11.02.11.00.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 11:00:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ER89x3QB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (Postfix) with ESMTP id CA9408211410; Thu, 2 Nov 2023 11:00:49 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234445AbjKBSAS (ORCPT + 99 others); Thu, 2 Nov 2023 14:00:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377259AbjKBR72 (ORCPT ); Thu, 2 Nov 2023 13:59:28 -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 4940E10F3 for ; Thu, 2 Nov 2023 10:58:52 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5b3715f3b41so16864837b3.2 for ; Thu, 02 Nov 2023 10:58:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698947931; x=1699552731; 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=UjGLpULVRUxYABNs8KK8hib6JmANLHcuQm1tIO1QTLc=; b=ER89x3QBSjW75W4RiQdRTVKtAxJHVgvda9Wayj8xyj7MRXcx4tLWCOeoLY4QQ/S6oH F/+U79jPBKgdjYjmmTi4JZMnc04mDRMvXrIWEo7LW/pfBNqdetmIfEK0zhHEWI8drs9D RHi6LGkMDc6JqV0h1MAgeAfscLsnwmQaQ+fEj+/6dIDa2MQEDrIQ//6/mFNQ8Y8jxdoV wzVde1G5nZ8o32XkKO41x6CZe/CDlVukhGIsY5m3fSctSrh1xEsSR9YO2l0smLMPNimI ZqlHuLtC37bxumhr2GPvKs9YogLsOTGYArBXhmBEkc6500EJSLVv/BGIq3qFFiHwnNCE /3ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698947931; x=1699552731; 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=UjGLpULVRUxYABNs8KK8hib6JmANLHcuQm1tIO1QTLc=; b=G7S8AztorjzL8ZHXiNh/qyO2XcT/6mQEUTUNK+Mqlo0Uvt46uAzBR7Pd5Cpf3oDA+c Fh8M6E7x5T2ChhYgLI4/6eYDkvceR305DTEvIe3ezj6bAyc3XTbJf5M2JcIdS9uNlJLi iY9G6E5Omb+JXakziGA30ObpK/4v/R0hYFAVoqI65Ow8D3bcAAzxCH62Gs8DNSXpQZku Yd/Gm55DwlG+f9XqSfR2qI0cHEkHUyd8tW9R5Wi1GQT1Ohjpuv//Fn2dkVzsa4JQ5AA9 Lt047gTRbMAlKES41lLdG4ZWIjZAlOZsmutSw+JnjxOJpfHL51uJ6zaE1i+AZeheGQOB 0Lrw== X-Gm-Message-State: AOJu0Yx8vgIG+DzNRs+VSpKWsydQAmG9Eeu/bakDdzzc1K/PUuG+bEuE IaF8YviUiHwVOQ2sCm8gAHrmTYoG5pxy X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:bb34:df9c:836c:afca]) (user=irogers job=sendgmr) by 2002:a81:5249:0:b0:5a1:d329:829c with SMTP id g70-20020a815249000000b005a1d329829cmr9123ywb.0.1698947931428; Thu, 02 Nov 2023 10:58:51 -0700 (PDT) Date: Thu, 2 Nov 2023 10:57:06 -0700 In-Reply-To: <20231102175735.2272696-1-irogers@google.com> Message-Id: <20231102175735.2272696-25-irogers@google.com> Mime-Version: 1.0 References: <20231102175735.2272696-1-irogers@google.com> X-Mailer: git-send-email 2.42.0.869.gea05f2083d-goog Subject: [PATCH v4 24/53] 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 , 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 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,T_SCC_BODY_TEXT_LINE, 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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Thu, 02 Nov 2023 11:00:50 -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.869.gea05f2083d-goog