Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp645747rdb; Thu, 1 Feb 2024 22:17:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IG3gFFKHTFO97E1yHFPd9x3k1AKT61FxZy3g594VUfU2COKvSoy5VS2PzpK8nGD50eAxli9 X-Received: by 2002:a2e:a712:0:b0:2d0:862e:a873 with SMTP id s18-20020a2ea712000000b002d0862ea873mr387488lje.4.1706854639098; Thu, 01 Feb 2024 22:17:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706854639; cv=pass; d=google.com; s=arc-20160816; b=b4FBja/nWHiYy1ZN4DtLmM2+aQvan6vc3Io7PCgeTcijtvomTWRixFiuu4cwvUlxY7 fZr3pSkuWXO12a/np5mcz7tr0363INMgDG2jA/hkE5VpciojT6fhI8HGOTfFAiIr8iZ2 FL7pWMM5zSmtrXHqS9xjeaCo1qz2MRsj3nIPn5ddTkYXyHl/CYo9PT3h2wAC06GHh/fH 9A+dxREStxrOl4+1RsuKNuq2wP/QjOiNNmGqUA83PscVR6PH3TTrgrZ5InbjAfIddts8 9su1D+ul590yHUw1EhOqmefEw3fkuVj9TqGaU9+oKbsPy3ltEYCKRyE0dj9k+Mpu9U/X SSsA== 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=GtgvpFVCeAxfBLC1ay05GLymu1fr0pRRLiLlSBt0YmA=; fh=BNl69TeZCTzi/9iXCMxEHxcyEOS3JOiRulP4TfSoYQc=; b=NOe8sjx0lIu/NyyWOJ3eAgerorvp+xRBTUXEXlYuZrSkXJGlNv3Gwhl7bN+BDzPPbi gmc1ZFvvvN7ljUwqzI4+jBvanc3/VuW4j4xD9pUHgFxbkdZGKpI8bZfynuvWBZZ2a/UQ hdD1EPb/v0JF1E5GFlS8pg2Hpjn9+oYJdmZgnli2muXLFo6aJ/flMzUVKvLCKz7MPvYK MxQxT8hH3n/nuDqMzXp3d2RIagBuDZlL9Kp2dun11sUNUhi103El8/EucYuLUUJRX5Pg xUX6wzoQ8OFHnMHHVUsfrB2apqayx2zfTwE+dZaTnQGFW6MlIz6xZ7Ba1fZLXmPnnOB6 dfEg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=SmQziLbY; 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-49245-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49245-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=1; AJvYcCWWh4p6Pr6DoJK5udp3JzL8bMgOyTEcwHhxhdRQ1K2MRwSren9CJixAF0KsOeoy1WtFx7vl8LLLfUIU3T8CU8ny4yDbuRVZcYy24NOLIA== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id r6-20020a50c006000000b0055d0a061200si521838edb.21.2024.02.01.22.17.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 22:17:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49245-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=SmQziLbY; 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-49245-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49245-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 am.mirrors.kernel.org (Postfix) with ESMTPS id A6F851F21BF1 for ; Fri, 2 Feb 2024 06:17:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AA6F71804E; Fri, 2 Feb 2024 06:16:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="SmQziLbY" Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (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 380C81755A for ; Fri, 2 Feb 2024 06:16:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706854562; cv=none; b=kRyxsgiaxfXyPkKrHBLzHj+y6WieYDA2lROi4vTcUToVH/rqBCWOn54G0tZPTmxBzTbfT+EoQbkcrbm+4JB4lIsnADCbT36JbakFe9cTHiIPgcDNnQG8+cQPZwGe7kfjkqvWEbEr0JOmAdWIB1DOpWVciHUfiN3nul7Y9DJwEhg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706854562; c=relaxed/simple; bh=8s9pvXR/dJ4oS1alnHLZ3B/RdRusn7pUE+bkSp22vOk=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=YwNtFzcR5EJgmUcIyEV6thWf4iz4ku7yiLHZ9o5t/cxAXBk4YW33cfWDtoytrwV1Dxi5zQk1VVu8PsiK57iXX3hjdrxLO+mimKuVxktNQODVvMVz+todphWRNHzy5krHuIisjO3jxz9+ze/yw06lCuoViOO52+2/M9sHxed15xU= 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=SmQziLbY; arc=none smtp.client-ip=209.85.219.201 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-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc6ade10cb8so1005120276.0 for ; Thu, 01 Feb 2024 22:16:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706854560; x=1707459360; 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=GtgvpFVCeAxfBLC1ay05GLymu1fr0pRRLiLlSBt0YmA=; b=SmQziLbYIXp3B16LvdMb/KufFnTDnU6wkgdxeaYTnlSpdH1hXEVaHzerxvqGhYspyV oo4stUf8s+SqXnRBKacAzX11GwcHYNHdO76K6Je+MjHEyJNFjs5c7fPn8a1mcmCsWSwK bobU5hnJuERN8LNTVMR0wwbZrUVQBeHSSh7ZR7qcwqB/9PBjNwwYGg8HRXYQmQBH1YT1 gSDxU8AxtkQF7mqzu18HyDfspkMsXrpCy2FiMzCmpozpqrC1gkOHgnyOuUp69jjLoqab 2QugJrXocAPCdctGM1RPcDPBz9C24N8R1AEnPGQVVjgvGu9J7hw4pvUMKQWo/jdw6B7G o/3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706854560; x=1707459360; 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=GtgvpFVCeAxfBLC1ay05GLymu1fr0pRRLiLlSBt0YmA=; b=aqer77izX3NdPQ/+iedy26nBhCxkbIzftNoPkN5rcUDUHHV/xr7CQFfbnE7h3ASF5A KqAVuI16bkPhJTFIXviajNM+vKowet7zwfLQgFvwMEJlbX6f9kqfVlIFf81KInW2xqK/ Z3u9NhtQASxOJZhIhZ23OreOz9ofPeN7kK0aOu4CRRGIxLlxJrg94Pz0wYPMl9SncsP0 H3WNFEid7p61Ep6jF1U5LUMcwBy3Zafs13yg/5n/rNhEEfW3s3nBaI/qNs5Fx6yFwdkq 32gwv5dZAvyFO5AYNOwh6mWbsz7Yqwj5/n5zRM0XRoOcgR26P2B34d3/Qh4154fdZIW7 P0Dg== X-Gm-Message-State: AOJu0Ywn83lFTkvz19hfTvSN5fUxukiTzXheKx/sjOaDCefbjLBKRiAW KZ/+CCyURldaOkFl4NrVjmBTrmt33o9vebZfZpecFYEQpi4+UKEI5QTBbuwUlpvB0b+2GHoiHpN M/9+0bQ== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:a85f:db1d:a66b:7f53]) (user=irogers job=sendgmr) by 2002:a25:b28c:0:b0:dc6:ddb9:14ad with SMTP id k12-20020a25b28c000000b00dc6ddb914admr242339ybj.0.1706854560075; Thu, 01 Feb 2024 22:16:00 -0800 (PST) Date: Thu, 1 Feb 2024 22:15:13 -0800 In-Reply-To: <20240202061532.1939474-1-irogers@google.com> Message-Id: <20240202061532.1939474-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: <20240202061532.1939474-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog Subject: [PATCH v8 06/25] perf maps: Locking tidy up of nr_maps 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 , "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 , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Guilherme Amadio 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 --- 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 c3d91e5e9cae..d5db1f284dad 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) @@ -865,7 +871,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.594.gd9cf4e227d-goog