From nobody Fri Dec 26 21:28:07 2025 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 B6AAA18640 for ; Wed, 3 Jan 2024 05:07:01 +0000 (UTC) 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="eC6YhVvT" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dbdac466edcso9615201276.2 for ; Tue, 02 Jan 2024 21:07:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1704258421; x=1704863221; 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=IWXABpo7gjjLxsIx2h9glSNIaYYqxVQN6KNcO9FjYOs=; b=eC6YhVvTJzAyr8HNa2Fo6+8vq/i6Waq1kJjJCcsEQ4ipmaJLt2D3KYiq2cYMk4VYVX +4y5stFTyWYSWhqoAQov2afrMqmmTEC3NCk/aXV9Dvazsd2qE/Gb6khAwpOzh26Q2I56 kwWxQ/GMCmMLfi1k+Igqb5JSSL/jZMP3gGm1AYiTtsBit6sYj9+HWUdy/SsrBxsYXN76 HxS3/L0S/b+zNZZydORmep5UhJUYKRzoYVYUtH8kXKb2Mghi2P1B3qNdn8nnokYYHSv9 9maIX8NiqbrmJ4TqBwg9jwbm7kzmt0YeZrp1G4S+pQMufClZ4cpx4cAS60KtI2F37+NY Ccyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704258421; x=1704863221; 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=IWXABpo7gjjLxsIx2h9glSNIaYYqxVQN6KNcO9FjYOs=; b=r3w8BYWQ1wqFEz1KrzKgZ+hYDeq2ldBFefm76rQ9hdFRsuj5C54SKhC+MwQctecsR3 oFIfwC6BI12/UTiN7xh01woyGcE/Aba6YLQLjQQNRP/X6tcKfmhM0GQg/PumSPjHQHX7 TZeUoZfoOu1I3O2aglK49O7ODXB3LBa1CqzfHq0hE2oZgaqGmn15C6bRpRczhLiFCluR n/rl77BIG48uu9A0DJo6ebqk/8KCdFMKHfMb4t7Vbejovrx6dq2qYjPA0xklYJOq1Jzn yWiXx3i/GrOQndLzqrkZeT9VnLHoX90ZE4huYOpY6BWqO8RjmNyWZIXxvB43LMirKYt1 3NnQ== X-Gm-Message-State: AOJu0YytKkyJ8FWIHEiIKlyT7c1mL/QHhSx3MUiaqktr/XjGK3zqpYO3 oAwpi6pywa+cvD9Ks3mmqTpXGfpn1GF1vyIo2Gc= X-Google-Smtp-Source: AGHT+IHUMwHDLuJECA72sU70kX8hzfGaNYfMEJ5he0cP/LCgKp+lHrx9icG52dkE6kWJ4fYLgrnkatpZ9UhP X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:e2bd:f1f6:8ea6:8d6c]) (user=irogers job=sendgmr) by 2002:a25:418b:0:b0:dbe:9dcc:8ba8 with SMTP id o133-20020a25418b000000b00dbe9dcc8ba8mr7419yba.6.1704258420783; Tue, 02 Jan 2024 21:07:00 -0800 (PST) Date: Tue, 2 Jan 2024 21:06:16 -0800 In-Reply-To: <20240103050635.391888-1-irogers@google.com> Message-Id: <20240103050635.391888-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: <20240103050635.391888-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog Subject: [PATCH v7 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 , 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-Transfer-Encoding: quoted-printable 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; =20 /* Assume maps are set up if there are any */ - if (maps__nr_maps(thread__maps(thread))) + if (!maps__empty(thread__maps(thread))) return thread; =20 host_thread =3D machine__find_thread(host_machine, -1, pid); diff --git a/tools/perf/util/maps.c b/tools/perf/util/maps.c index c08e412a4313..cb52de9d6c2a 100644 --- a/tools/perf/util/maps.c +++ b/tools/perf/util/maps.c @@ -528,7 +528,13 @@ void maps__remove(struct maps *maps, struct map *map) =20 bool maps__empty(struct maps *maps) { - return maps__nr_maps(maps) =3D=3D 0; + bool res; + + down_read(maps__lock(maps)); + res =3D maps__nr_maps(maps) =3D=3D 0; + up_read(maps__lock(maps)); + + return res; } =20 bool maps__equal(struct maps *a, struct maps *b) @@ -852,7 +858,7 @@ int maps__copy_from(struct maps *dest, struct maps *par= ent) =20 parent_maps_by_address =3D maps__maps_by_address(parent); n =3D maps__nr_maps(parent); - if (maps__empty(dest)) { + if (maps__nr_maps(dest) =3D=3D 0) { /* No existing mappings so just copy from parent to avoid reallocs in in= sert. */ unsigned int nr_maps_allocated =3D RC_CHK_ACCESS(parent)->nr_maps_alloca= ted; struct map **dest_maps_by_address =3D 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)(struc= t map *map, void *data) void maps__remove_maps(struct maps *maps, bool (*cb)(struct map *map, void= *data), void *data); =20 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. */ =20 #ifdef HAVE_LIBUNWIND_SUPPORT void *maps__addr_space(const struct maps *maps); --=20 2.43.0.472.g3155946c3a-goog