From patchwork Thu Dec 7 01:16:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 174844 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp4488077vqy; Wed, 6 Dec 2023 17:19:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IEyT1el+ObQfjCRjuZsP3WKmTj12CHzZ1VwL9nXqvki5cqIARNbZ9AwEBIBlDkDIjm3x5Wj X-Received: by 2002:a05:6830:104f:b0:6d9:6afe:53e with SMTP id b15-20020a056830104f00b006d96afe053emr1866050otp.30.1701911981448; Wed, 06 Dec 2023 17:19:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701911981; cv=none; d=google.com; s=arc-20160816; b=iOlhvXHdz8k58SB/dNZi66HgMPJS6DTD6Ay7ndh0vFttrl6lkdWb6DtG6JtA2l/bzr D+0M+U+0RByQeTmfGxdz12Ogx0EdQRlklmhG+3ln8uLQH1hcFnuTPN5RCfkk6iy+YFjF cENwK4Rsnk24W2orD2KuDs+rGzR+qcE5w3SRJDtQKxmJlz3qcT9YAZ5FCqEvd2R3t5uG uCIzJmb4nlafwiY3HS4SADxRNME2XY3bw72oLUlU04Gp+zdi8zCGbShIMwkZG31pzPVR Of+v3FLvxYtqbHbrIS3izKO/2cPskWjWzRqnFU6JeQjcPseIdcWdmNz6mOCDxcXwTYnH 3Qyw== 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=zhWv5XH2QIvBBYa/R05A/SafwPCuOWvAm4FZ/Ek/rFM=; fh=Io7x3OacpefNRRNKoYAzVE0aWTDwD7FRzyCdD1e3AN4=; b=j/NgC5nbWIaIShXU3Iymf2HPZtF3fXMr7ZYztAY3erX9KDixVq5q76cjj+t6gjgttG TIKBMIdSajpiF1sIqm3mWUv0DEklZ4exGTyvnCf4rB7Vc6QEK6GuuyR9FEy7smomJFeb ID+LIw8sNoCSF+QbBcUuJHbWqMo2MLFHR1+SULr5HE3QJNiqylrAN7af5Lj6VmsdTYGE 02IDtlj9tqmxqfZ+GU/p3yFTJAXfnZYMtxhtf+XTRH9RoDRHz4vo/mDmXALaHMDmYEie XpSt/LqFCHGeygpXss4e7HjmfWzTOtpCvFzWQ8P2dScsWxHBc35dDXexP0aafhaodG2F CrAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=aKrqV2LL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id m5-20020a056a00080500b006ce7afb03absi265551pfk.131.2023.12.06.17.19.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 17:19:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=aKrqV2LL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (Postfix) with ESMTP id 04E9081F3213; Wed, 6 Dec 2023 17:19:29 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1443017AbjLGBTI (ORCPT + 99 others); Wed, 6 Dec 2023 20:19:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1443001AbjLGBSi (ORCPT ); Wed, 6 Dec 2023 20:18:38 -0500 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 5FBB91FC3 for ; Wed, 6 Dec 2023 17:18:12 -0800 (PST) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5d9c036769cso1842547b3.2 for ; Wed, 06 Dec 2023 17:18:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701911891; x=1702516691; 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=zhWv5XH2QIvBBYa/R05A/SafwPCuOWvAm4FZ/Ek/rFM=; b=aKrqV2LLaveEeNRG0k5c6Fa2OyEtZKKkinL9NWdjtQ7YQLJxH9WnGGvfKZkZR1nKbV AXU6HylhZeuOeDI6fTq5bNOSs4XQRk84D8coYKv5jbRo3shOuq8VUvTLW16YP9RKvDft OHApy0W9NqJjcthFbVLptVN7dMeRW7sl6vvJ5FYRiMxTb1gIfKYi9nyjWn9sW3eHVBuQ 8mtZjMM081V9zYHnYbsvKNc6mRoENbV2EB4sxsFEQ9USJrGqW9+tSmaG2v9AOXao1m19 IJraUtqlPvbJwmIpP7R4yTUvngdG3eN+LdNKqjANPh0akZklpUFxc1L8kjUGd8lR9IOy ptfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701911891; x=1702516691; 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=zhWv5XH2QIvBBYa/R05A/SafwPCuOWvAm4FZ/Ek/rFM=; b=bomDGuEb/MkpCe6NDbzI8n27dDCeMR8viVNDlYvtaOvwSxg2Q3NKTeueKJzgBYybHG cES8yaVnifyydi5IGdm0E/Tu/kITcdAI9NSn54hAg5nP1WKBqDG6kJpW5bOVkyBr8K8q 6A/1cf38m0pMWwnOPD36QEFax1AFPAh+6pNWAradqmRqjw86mvR94H5fHOFQSAw7xD0a BmUL3GsYgRBLn/RhsmVB9a3OiLAvT9fsLq/dA8gMKuSNCs1SX22QEwZ/gM8GA9zcVORu xSu5P+gPE0RFQVF/Egbye8EbmQO5RzBiM2giIzIi84B6QViUQEp05n5/ZK8ZCVIV9mP4 aFTQ== X-Gm-Message-State: AOJu0Yye5ne8/upYslULFMu4wtcfNwHtPK9GVo78GGrlV8epBcTs5clM tnZhgHQ5QrlxvMbESz0I8PFvI+iwwfqG X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:35bf:293e:7696:34e9]) (user=irogers job=sendgmr) by 2002:a81:be14:0:b0:5d1:7706:b886 with SMTP id i20-20020a81be14000000b005d17706b886mr31238ywn.0.1701911891461; Wed, 06 Dec 2023 17:18:11 -0800 (PST) Date: Wed, 6 Dec 2023 17:16:53 -0800 In-Reply-To: <20231207011722.1220634-1-irogers@google.com> Message-Id: <20231207011722.1220634-20-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 19/47] 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 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 pete.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 (pete.vger.email [0.0.0.0]); Wed, 06 Dec 2023 17:19:29 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784584057890875734 X-GMAIL-MSGID: 1784584057890875734 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 f1716c089c99..31ff19afc20c 100644 --- a/tools/perf/util/bpf_lock_contention.c +++ b/tools/perf/util/bpf_lock_contention.c @@ -318,7 +318,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 986daa1b0497..024a6c9f72c4 100644 --- a/tools/perf/util/maps.c +++ b/tools/perf/util/maps.c @@ -793,3 +793,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