Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp6935335rdb; Tue, 2 Jan 2024 21:08:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IFVdBQHMp6uPMQC12BC0IdhZhwiNPbIHvCOtvWKVhExAlfDIkwGa0CcaXaeFOsZvgs4m/sB X-Received: by 2002:a05:6a21:a5a3:b0:197:8e11:f55c with SMTP id gd35-20020a056a21a5a300b001978e11f55cmr34877pzc.52.1704258526097; Tue, 02 Jan 2024 21:08:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704258526; cv=none; d=google.com; s=arc-20160816; b=hogpHcl+VTfjzNAdEInj0riPVSHbjqYzddAspvNTMFFKZEptsUA5DExHqFS6Uw2Hqu n/HmdfhVkdT9ocx1+tVdXg8yI8ZBWNk3aVwMT9MLDKB1XP5ScNUp5RnR0TV0dgBoiKLT i8v8uvc+Ax5Ym5a5cdq2XxzJCQEEBsmwAajraLHYIesbfb3c2r9vx/m2EJ1Bx1FRQISx UQkDogTTd5BcdehPPtmJbfV5nM/J1GuQ2FY/cHQ1HlxF4ZAReiAJ3ASxnrviDdVGLVEr sq8zMDW5A4f8FltwnCVZ0/AxSzWtiM8ST3UsPeiznj1AV0r4Hp1FcvljONE84QQaexJZ LpYQ== ARC-Message-Signature: i=1; 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=IWXABpo7gjjLxsIx2h9glSNIaYYqxVQN6KNcO9FjYOs=; fh=Io7x3OacpefNRRNKoYAzVE0aWTDwD7FRzyCdD1e3AN4=; b=ZkOWH1nIr7TK51UxVvz+jbpgofnMMDeVBxvt5Hglv3D5d3RTQZgDe1ZpOu8wu3KmYo IjICyIom+AvjdReLAcKzTYvLe3zKTYK11vHtFylQb4LAZdRV2GXKzqVa8Y35cf25bNFa nk3CjOwsqGbj9yynGg2Nz5NsGqi+Y3igU3pjtVrgprGtkS1uHmY/vcGTkVdAl+y+Fthy aAkh5SHFCnFbanxbJUPHqZzCULDxdOp9Uz2Apk9OtQMutkar6g0mHFlc/T9y/oBez2aa O4Z+FWGoLPm9TbAo7JPBPZM0ctr7jUgnkePinNSpZvksQvCOlwkiFQFxcb4XJtf4P2op r8gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=eC6YhVvT; spf=pass (google.com: domain of linux-kernel+bounces-15165-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15165-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id w12-20020a056a0014cc00b006d9926b4c79si18177443pfu.76.2024.01.02.21.08.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 21:08:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-15165-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=eC6YhVvT; spf=pass (google.com: domain of linux-kernel+bounces-15165-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15165-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id BB6292847C5 for ; Wed, 3 Jan 2024 05:08:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C88221865B; Wed, 3 Jan 2024 05:07:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="eC6YhVvT" X-Original-To: linux-kernel@vger.kernel.org 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 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-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-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 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) 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) @@ -852,7 +858,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.472.g3155946c3a-goog