Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp3428249rdh; Mon, 27 Nov 2023 14:11:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IG7x6thyzXXN2GIrKIz68/WpbxQAZi9i/3NI/0J3K907rZX99h75lNEcWlSIiJoHBRrKhQK X-Received: by 2002:a17:90b:4c4d:b0:274:616e:3fc4 with SMTP id np13-20020a17090b4c4d00b00274616e3fc4mr12254028pjb.34.1701123111048; Mon, 27 Nov 2023 14:11:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701123111; cv=none; d=google.com; s=arc-20160816; b=UojgBQFW16l5QkTfyJV39BSV8mgEW5VeInkcyfWagy9+oNxLglUs6xvzns6qJ0gSaH oV3SIUqSOCrbRR2lRmbEx0j3xvWPAKfQWAVRukh2ysTCOWW4iQINlgyYJo5PPHidXqV5 yhanW9cnLzvufOK0pltKMkEPR8oM4MDuo8EU/UKwVBSbXgBNlHZPC6+MsWZjx83pAkmi wc2yYcHoYAB5wV1ky734wVKtqUh9nVoooXyYzlat0wem7oHSVo6UFhet7RHi8vMIDjiN J7JQRt1twjrbDrPhVwB2sY1LCvlvIWHijIGn/5EM/24lJDzImKV5b9VnxM2kcE6vimXs bA7Q== 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=cjlQMs1hNHRgSuoywd2CjIiILfAJuheeO1q52M2CHpo=; fh=Io7x3OacpefNRRNKoYAzVE0aWTDwD7FRzyCdD1e3AN4=; b=ZR3wjVTqL79VjBSrF93DW/5pYbth6iDnXtA+/AtW9hUBWI6OO1CrijAf7YnXX60nO0 5w2aV2F9uxWzVobGV/D4nLM3/T007BRvmV49fEwMgvEUvoRR2jIyizLSv6Zo5AOcbOaF G8wGVlfNlPtex2CcPx1z0K9hBsgnScGfpsSD8Yp751kNLN4UDvFkMUlYbdHQVtvFPmKc kwynPHavMAAJRyDWaTq7ydQmNzWo2LIUwPmSoW7DZ1GPb+iikwQVfMkd2j2MwNdwDPsb 0Mm9Gwrc0WnXFf5gIK4+/4ruz5Quy+ImhwWh5sXJX3Hw67VwWqYc01twSmifGfIohFkA WM/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=PKhP33GG; 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 bb5-20020a17090b008500b0028571ddddfasi10027025pjb.146.2023.11.27.14.11.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 14:11:51 -0800 (PST) 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=PKhP33GG; 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 35082810DEC9; Mon, 27 Nov 2023 14:11:48 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233780AbjK0WLU (ORCPT + 99 others); Mon, 27 Nov 2023 17:11:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233803AbjK0WKi (ORCPT ); Mon, 27 Nov 2023 17:10:38 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 537F52122 for ; Mon, 27 Nov 2023 14:10:13 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d9a541b720aso5315804276.0 for ; Mon, 27 Nov 2023 14:10:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701123012; x=1701727812; 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=cjlQMs1hNHRgSuoywd2CjIiILfAJuheeO1q52M2CHpo=; b=PKhP33GGrallGD2URPK+wiamwQuNjJR/ojvWyWq03PWiYMXXdzxtU03jWHCfLGoaxF ggq9YKQ8fVu0JSski08WTZyh4b5qemd5P+aA9Awq3s3GodbPCYqly6un6LKB+cwelIpg 9JLMbsmyzMZYPYDxouu6/vP75x71x0fuGYtuqjwsG3NHRmNns30C9Gaefk3HyG+NHoaV lh3zkq7aDTsBK/PhpLl6AzEInp4ViyrvsqJtyYdUEF4x+KV20CFA3ZLerCyR5Bn0NBOk x/pVPBchPa8l2C5w4lJAiA02kTP7oTfU1VdZUl/FTJS8Fh9K6ZyOwuzgaZnxB0nQbF6b VxYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701123012; x=1701727812; 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=cjlQMs1hNHRgSuoywd2CjIiILfAJuheeO1q52M2CHpo=; b=upaIzg54nIPU2HkM6lMuf6AT6kSdQ/zFapQ5g5LxNGq+vBmMQdvEUE8sK4Z0theUcP L6+KfCujcAakodgtfNwJaHB9TzgxKmjt28IoSyiLB1djnB53aNyI/eIWbCeKVpb1ezOM KdEoNAqlgndNBlD1Yu0Z+hLvJ/aG9Ce611FYYAvVkkP0dtiO57YzDEZwfq87ph7JSson pz8rnNS63QO2Z/6AYC4N8mrAShd+w27eZnDdkhzJmhnfO80WpqwwOBC3uPIPWappX89b IZv2wjsPxj8sGLibjpo44cgfuwcnQP05zlRrMx46mWN/1/259UbIHs74tVlPUbBeBoFR hIag== X-Gm-Message-State: AOJu0YzfBdQSH6O+gPoqF5YcN/SBNj802LewLBXbZ534NkBOuYdkb5uf TGq+zzT87RVo0hi5NmsBEKDJR3AqcYn5 X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:829:6e77:9093:f39b]) (user=irogers job=sendgmr) by 2002:a25:fb07:0:b0:db4:5d35:c5a3 with SMTP id j7-20020a25fb07000000b00db45d35c5a3mr432690ybe.0.1701123012376; Mon, 27 Nov 2023 14:10:12 -0800 (PST) Date: Mon, 27 Nov 2023 14:08:33 -0800 In-Reply-To: <20231127220902.1315692-1-irogers@google.com> Message-Id: <20231127220902.1315692-22-irogers@google.com> Mime-Version: 1.0 References: <20231127220902.1315692-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.rc1.413.gea7ed67945-goog Subject: [PATCH v5 21/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 , 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 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 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]); Mon, 27 Nov 2023 14:11:48 -0800 (PST) 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.43.0.rc1.413.gea7ed67945-goog