Received: by 2002:a05:7412:2a8a:b0:fc:a2b0:25d7 with SMTP id u10csp609459rdh; Wed, 7 Feb 2024 14:38:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IEc9YdJFUx0QRQgwlEkR6uWf4LWry5+YeeAwCHXNyqYItoF53e/foP4CNUKxcK51U+sJuh6 X-Received: by 2002:ac8:5b89:0:b0:42a:7169:4359 with SMTP id a9-20020ac85b89000000b0042a71694359mr9343025qta.66.1707345537161; Wed, 07 Feb 2024 14:38:57 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707345537; cv=pass; d=google.com; s=arc-20160816; b=WJh/fcM4cxAJiAUCeaR9eXO297z7mQkBX6IMF3kq/8KFtxRxbiTzGTPUtlrQTUM0C8 HNZxWF2NTQ+JUD5O0GXoF0O1qVLTT8DCxIFWEvb/vx2QgNRcuhpNusJiUAHypPvxtMgY hPfW7il18ANP5xq6UGOHjmqqiUHZjVnPLMNrBNGTjbmcQkNqV2kzfO/xp5m/n38M4bMd oeFSphEX/1oOuuuxX2Ih38EYWgdglsOfDcKO3xrWhXKtzOZrkyfXXJLxMwbb84/R6isU DbwTuikKhumhPDDIrAZCaj+YFUoOZcYFu+Ek29q6YOR02vCG6FYUAhMWxoTeSEV0k0x/ GhAQ== 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=dvZ5WUWTj8QrlPAJDzYrQkQZ6y0b1KQREpo25gbb83I=; fh=zgOcAdSJFj8q6xbUi/NwQQqmd4AbvdZgaQAu+1dVNj0=; b=jriTWT75spDbb0hzAjHF1zjID/tYCOXnUTATHjx25g+pcbxAeYRO/iZ+pd6c4MufmD /4pNYyeOSP/lgE2f1lxNI0jPize9c1ehqfhcOC8Gf5bH0CyWNA4L4dlkGQlRHYu40dcA oFUBP854vuLv3ibJHUsORUnSv5oc1dIa/4YPuZu2r0R6xuXhJ3rdg3nF0gZClwLHGJ8F HBBTtCV3fsRdeAtjv7wt6pAprXkRcSDybNseBJFnj+jyGuDGthiKnTq/FYnrWAxgZ6r1 CaOvkuLWx5dc59dXrU+7cTpe0CjKFVk6Bz4qlbT986W/tYgTfGQMXqQPRYU+hBEzPEco pkUw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=cRNiyyzd; 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-57265-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57265-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; AJvYcCWyJ6ca1QsKjbOdiHCSs10fclVjuxiUMxkfQET+bi6NyNnOucKotXLpcBGavrbney7Wtjcc4wAlIBTy9dhdAcnsUpBSKWavnLpGBW1EDA== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id b2-20020ac85bc2000000b0042bee82eeb1si2133951qtb.633.2024.02.07.14.38.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 14:38:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-57265-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=cRNiyyzd; 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-57265-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57265-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 D784B1C22709 for ; Wed, 7 Feb 2024 22:38:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B076B6931C; Wed, 7 Feb 2024 22:37:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="cRNiyyzd" 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 EDA11692E8 for ; Wed, 7 Feb 2024 22:37:20 +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=1707345442; cv=none; b=JXk+lz8xMBC2KQVPDy2oyLTB06g8lwSwXMuM/uHpP3dMOs4IDECB+fI29Gtf15FFSIOefrFRRBjK0EiuMjivYDvlA8tCVC0CwKflfoo+dcW5/NnOGlbQEJ+8rKAk4sFKwHQVtO9OikbioMLTWGUm0GsdAUSXAwW+jwPO9olCwBY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707345442; c=relaxed/simple; bh=QOZ3AXSow+69/jSpTKwTzsRv+NqoTfrDzrJ1ZUXaoRk=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=ZyQ/sB75gYYCk32apOjtgUpIYI35k8PpE1FODRtKQa1c25hVGbCktkMCJZ+9kum6ZMeuR11Dr0koq9W3cWoRIAloAGGDvK6BWwe+wzweF3I5qQSQvLsSQOjs63k1q5wfLddC3hVwzuH8On3Tsyh5CwOTJ9KhqLBjdmHIG+n7ThE= 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=cRNiyyzd; 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-5ee22efe5eeso21753647b3.3 for ; Wed, 07 Feb 2024 14:37:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707345440; x=1707950240; 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=dvZ5WUWTj8QrlPAJDzYrQkQZ6y0b1KQREpo25gbb83I=; b=cRNiyyzdmB+oZrqLdqiwlC3u8oyDF1StzYlMviQhJ8GkD7AN7/N24xJaOu5e6hub27 sl/agywiSWb8moNlaIw9Dr1gnpMFkjRs/KkiGQS54kSvR6ec2lrRuQhwr8aX9AjAIKq/ 2KGgIFb4ZNxpM2fjPZf5SYyyPvrBZ1JKI+YEbuxRRZ2krwZPJcmZqnTMaopR6e0z/g0p ttZbDsGSUivaFGi5ZrqubdvmiC1H5Wkz0SZNGCFMExJnMe2Fbfw/7Qxz/sVVpAtIxdrO /2pfR+1jEGFar1SY3BMbkVj9S5guYQpYjDx8YTV9bUn+hpyvkr2JzhPKXLyYxXEg8eUX GeZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707345440; x=1707950240; 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=dvZ5WUWTj8QrlPAJDzYrQkQZ6y0b1KQREpo25gbb83I=; b=pvMQNRkFqiGoOJ3AJezX5RIxyha2IOsphLfZ0CFmuRB43lB+6+HnDMtXJh4sPeomhh 8oMIcAdSxEWbZ1dOch0Kt00BDxJDQXR3WHaTJ5y/lARZPGOgcydjTcdhhdqQbJffbZS0 NzQsmYKI5UMWnuNKd/Bw2Q9U4YnzYHKsXZ6d0lTxlXPdf/73LVnTcAhxid+OAMfMeJ4I Xz9OL2dpSRwtt1nmnNVTJEr0jE5RFBdTZOqPzXNXhvsRoBN5qp9cXxnifSBpeucmEWUw 6RXCSMVmr2uL5KYD8xjTG3cmpzMG7NgyRj6x/KfRClgWEPOtWhoS9S7W7gjElu/X/1mi P0yQ== X-Gm-Message-State: AOJu0YzRb0jPiazkfRJdQ4JKAc/pUNwVL+rVsL5YpvvQvAPpwg/Hm3FM nLbXSEwExQzq1SeTzDcbaHmoDNOGdlfS1ULmdMivCd1EyWFxCmXtTih5JF4O86F+qXSW1gGuJy1 Hcm0Hmw== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:b420:757c:5706:d53b]) (user=irogers job=sendgmr) by 2002:a05:6902:1a46:b0:dc6:b813:5813 with SMTP id cy6-20020a0569021a4600b00dc6b8135813mr230558ybb.9.1707345440025; Wed, 07 Feb 2024 14:37:20 -0800 (PST) Date: Wed, 7 Feb 2024 14:36:39 -0800 In-Reply-To: <20240207223639.3139601-1-irogers@google.com> Message-Id: <20240207223639.3139601-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: <20240207223639.3139601-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog Subject: [PATCH v2 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 , Miguel Ojeda , Liam Howlett , Colin Ian King , K Prateek Nayak , Artem Savkov , Changbin Du , Masami Hiramatsu , Athira Rajeev , Yang Jihong , Tiezhu Yang , James Clark , 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 0ab19e1de190..e59118648524 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