Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp1325566rdb; Fri, 9 Feb 2024 19:20:03 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWNX5ZAkXyWK6ymbUOQ+LLmq06tHCwIkFKFGQbI2r1vH8eh087UcIa9VwOnnMUenEgTuI3Z3qWuYwskO2ep3s+xLbPbsZr0ER4VyuuvIg== X-Google-Smtp-Source: AGHT+IFQcEuauLW6gMsXG3oVJglG2t/3Ihg9XLdvRbsncYTPPLiuhgxSZFA7by5M1lem8a09jDE3 X-Received: by 2002:a05:6214:4381:b0:68c:87cf:ada4 with SMTP id oh1-20020a056214438100b0068c87cfada4mr1326246qvb.41.1707535202900; Fri, 09 Feb 2024 19:20:02 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707535202; cv=pass; d=google.com; s=arc-20160816; b=Jd5CrMb7ojN/LEq3IwbJPjFdZRMrQSQdh8jqRoIBDIiZBhrU5tx+vWaQu6Caf21FQB KYx/tjsa8M9bt7YXo1Gb4cwVdIopEI4F/vIkZWaHwRadZ/nlrWymtGmR8R75bBEgo88Y +wKCO/t1gyt48zCA5DT5x6LiQZej3qmWy8yMdibTDkzV0lU5ytKVXxrK0Dj6rR3xWFGW 0pqzzjD8aPTtymbxPixoeVA5ota6yQWz33W4QJlb0AaGPsKteAwIM9dfD9yWLVbKjoP6 ZQgYnemBBOCwGyyKxgpoJSnoB49+zzY40ixJmoPvaalTcUtyzTAbUQEmELXsIRZp9BxE 1zTg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:from:subject:references:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:in-reply-to:date :dkim-signature; bh=ie89sB6IlXpvkiQnUaYF5PTvKc7dfqYdcE9ndiylfmM=; fh=ME9gPO9ZV3EvBZsTy1+OekjiVWR8LUneQ4MVbsMNAsI=; b=VcXYUdG3TGWNBbVUJEYyLPu7SYHDFzdFiXgGdTXwJ+bQSNXXpTQUWb3mfTjkgY4g2h TBWXPrbWcTLLlpmtkhbshzKaq0L9iaV7VlZH8RspF5x7fKcYHRRciS+gGzWJ2oSsGMlf P4tqCkZgZ5Cood84wJbj3jF2m4Jw0u+2UuU40qnY9ZMgqcp0hKCkg3q3GtLYkpDj0VYe ioxqT2081ZUsYm6fSZPePvuc+iC/j4KEMcTLbioLT6hOSdOc7gVttUoDi2Mf5PlPEY8A hIwlidVBjd/3JbdcVvR47x0bTHV5PblxLUA7LFuG8ihuDW8AuPB1zdHk+QqRU9GB8fj/ 0fgA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ueZrGJ0I; arc=pass (i=1 spf=pass spfdomain=flex--irogers.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-60269-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60269-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=2; AJvYcCXWqJetSMldkPYcVR3ZgHgAbie8H0Se14opPjySXzS5rLQCye8ht/4z9qoBxz4jXPEagOQUQXJ0mVLXrQDOKL6i3Q3bPo8tDhYePhyTpQ== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id jq15-20020ad45fcf000000b0068c8b401467si3562509qvb.597.2024.02.09.19.20.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 19:20:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-60269-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ueZrGJ0I; arc=pass (i=1 spf=pass spfdomain=flex--irogers.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-60269-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60269-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 970AA1C2490C for ; Sat, 10 Feb 2024 03:20:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 19DD936AEF; Sat, 10 Feb 2024 03:18:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ueZrGJ0I" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9FA5F171D0 for ; Sat, 10 Feb 2024 03:18:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707535093; cv=none; b=aGVMbUQeAe44xO2Vrdjh5iQttEb+osLq12RFBpJfcL9q26J/jayPrU0rtWVmtMJO/OrbGUpKMLiVdSGS+1ineXu3emo3UigpQr3ZTWxhNh85tO9o/foKZLJX/AqjoX605VOvIbFS0gqzI6W4lQtZ98I0V53aVC5omS736bjQZnQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707535093; c=relaxed/simple; bh=fmY7OGiQyoafs0dUqE06bQrvTXGFG0wOIGJr3qrBCDk=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=b3dzlblQ8CCEmmcIstBhZTLoL7ms8kFVZs8lrD6Sx6sYkL2fh64OP2O4W5BFHvw8sgcFxs2vDM1h61NZ/TshgBcRLEpSrm4FDr9ng1+7XVjyIY2lrdtFnBjNvCS490UMJowsJjTcEl7iUTFVCbdo++qaQGRSBR+NfKXE/KZ0pYY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ueZrGJ0I; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-603c0e020a6so25565527b3.0 for ; Fri, 09 Feb 2024 19:18:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707535090; x=1708139890; 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=ie89sB6IlXpvkiQnUaYF5PTvKc7dfqYdcE9ndiylfmM=; b=ueZrGJ0IuPfGlwXCKjovy5gGGS30jkNrGtsNC8pnicR1KIk7lhl7dwkZUTTREAOoJn NztsMiVXbJgsmEcNLj4vd4HNyYmGU6iDVlGEsEDePPLWhfY0MrnR1rsXNVEXNnrUx7Xq Ya6tpJEpWKjWuLP/CZ7d5tmfZU0ulM+GHc7NbiuEBH9vpd/pt/jYMMkvWMnni+Zhlab1 x7qQZ8ux3//bPdqmSGd+SC2MqMA0k3M7nDu8yY6UgHEBm/SlbSS5PKGXZnL/lP0dawbD gMm2dlCbtU9N4Rx+SXav2XKoBtqnExXgy4hn2CCnLJNAsuhuna7RTGWqy4QthZpYDbwg Iv2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707535090; x=1708139890; 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=ie89sB6IlXpvkiQnUaYF5PTvKc7dfqYdcE9ndiylfmM=; b=SjyNw+J43iABMvDT8pQMuhRHfnJ+PvKUt/TisUECtemCZfCPZICLYlnJD0H1RGgFF9 i1iacZLmxMvjQ2csHvxvvkiNtAhLDeoKsUMmtjndmTA8VBiLDLP8j7kaCg0vzgdo2NYw ge068lMmeO2pyKu2EuToifnwu5bpK4Vesgxqw610rB4RlJ988OoVozhnOXRam4A3Kf49 A2N78j5clyVGbbuQ9XShvpEY/ckedXxyDbaw3Ci9aSCAtys5tzLoPc7I70h4dNr/cBrS HqYZRUE7dhOQ6+2/7zUTJbxacE0B2tN0NxJYUqnm1/+53T8E/Kvp7qmUmlT1vqYaoEKq M30Q== X-Forwarded-Encrypted: i=1; AJvYcCUwfHG71i0+M/VtGzEx/bMHc2ug+IxCyvK2JEoOXICnCt4ZnNNxnI0fZJTUqLNHvbSZ8h6qcnIQYVPgqvSCqtWKmgFaC+FzBSFIfTJD X-Gm-Message-State: AOJu0Yz6RVAZ5Uj0+puMaDHjlO+6DKMGjtReHREK5JFGKVKOTEOQUGCc /vdocJ8ME/p861d46x1y2jWupIf5a/KcZQKNP+aGcO5JYI1dwxYhYYRozBMuw9v5jzKzrW0M0rW YpWvqcQ== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:877:241d:8c35:1c5b]) (user=irogers job=sendgmr) by 2002:a0d:d549:0:b0:604:499:fee1 with SMTP id x70-20020a0dd549000000b006040499fee1mr191533ywd.6.1707535090579; Fri, 09 Feb 2024 19:18:10 -0800 (PST) Date: Fri, 9 Feb 2024 19:17:46 -0800 In-Reply-To: <20240210031746.4057262-1-irogers@google.com> Message-Id: <20240210031746.4057262-7-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240210031746.4057262-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.687.g38aa6559b0-goog Subject: [PATCH v3 6/6] perf maps: Locking tidy up of nr_maps From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Song Liu , Colin Ian King , Liam Howlett , K Prateek Nayak , Artem Savkov , Changbin Du , Masami Hiramatsu , Athira Rajeev , Alexey Dobriyan , James Clark , Vincent Whitchurch , Leo Yan , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org Content-Type: text/plain; charset="UTF-8" After this change maps__nr_maps is only used by tests, existing users are migrated to maps__empty. Compute maps__empty under the read lock. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/util/machine.c | 2 +- tools/perf/util/maps.c | 10 ++++++++-- tools/perf/util/maps.h | 4 ++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index 4911734411b5..3da92f18814a 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -440,7 +440,7 @@ static struct thread *findnew_guest_code(struct machine *machine, return NULL; /* Assume maps are set up if there are any */ - if (maps__nr_maps(thread__maps(thread))) + if (!maps__empty(thread__maps(thread))) return thread; host_thread = machine__find_thread(host_machine, -1, pid); diff --git a/tools/perf/util/maps.c b/tools/perf/util/maps.c index 439cefab112a..53aea6d2ef93 100644 --- a/tools/perf/util/maps.c +++ b/tools/perf/util/maps.c @@ -541,7 +541,13 @@ void maps__remove(struct maps *maps, struct map *map) bool maps__empty(struct maps *maps) { - return maps__nr_maps(maps) == 0; + bool res; + + down_read(maps__lock(maps)); + res = maps__nr_maps(maps) == 0; + up_read(maps__lock(maps)); + + return res; } bool maps__equal(struct maps *a, struct maps *b) @@ -871,7 +877,7 @@ int maps__copy_from(struct maps *dest, struct maps *parent) parent_maps_by_address = maps__maps_by_address(parent); n = maps__nr_maps(parent); - if (maps__empty(dest)) { + if (maps__nr_maps(dest) == 0) { /* No existing mappings so just copy from parent to avoid reallocs in insert. */ unsigned int nr_maps_allocated = RC_CHK_ACCESS(parent)->nr_maps_allocated; struct map **dest_maps_by_address = diff --git a/tools/perf/util/maps.h b/tools/perf/util/maps.h index 4bcba136ffe5..d9aa62ed968a 100644 --- a/tools/perf/util/maps.h +++ b/tools/perf/util/maps.h @@ -43,8 +43,8 @@ int maps__for_each_map(struct maps *maps, int (*cb)(struct map *map, void *data) void maps__remove_maps(struct maps *maps, bool (*cb)(struct map *map, void *data), void *data); struct machine *maps__machine(const struct maps *maps); -unsigned int maps__nr_maps(const struct maps *maps); -refcount_t *maps__refcnt(struct maps *maps); +unsigned int maps__nr_maps(const struct maps *maps); /* Test only. */ +refcount_t *maps__refcnt(struct maps *maps); /* Test only. */ #ifdef HAVE_LIBUNWIND_SUPPORT void *maps__addr_space(const struct maps *maps); -- 2.43.0.687.g38aa6559b0-goog