From patchwork Tue Feb 6 03:33:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 197158 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1299767dyb; Mon, 5 Feb 2024 19:35:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IFqkWMedIe6DStQgrYxWdG4AFdnKw0n+nI+jYmsptcrWabWRvIXmSNazM0coJZtEGYMqhHE X-Received: by 2002:a50:955a:0:b0:55f:ccb4:ec84 with SMTP id v26-20020a50955a000000b0055fccb4ec84mr8420389eda.1.1707190554539; Mon, 05 Feb 2024 19:35:54 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707190554; cv=pass; d=google.com; s=arc-20160816; b=j7GPS3CyOdVRaEGVGXOVwMgobXvHqo58V/K/slLT37H+E438pfAEky8NCmeyU3ehtW cnv2eaJJYvbSe7kLpX2GbwEWY1ixr/JVaGxMqJ+cGw+IVRtMI0h9sTbud3sKVogAsSeK N7z1R8FoxlBs/oWNGrcRbRqgTFCKf06fafQMqyWc5Gj9VKyyDmOmnwvwvVRZ9cgzVXIY 3rdRsMP2PiSYlktTkbW7wyPSrtUeFKu4fYZkutd6HdmNgtBX17hrdww4Q4hBGfTiR6+U GRvkh9bPt3hHtWxR+dgO4/yo8aCRBtuGGhAEVkSXAxBOnXBvSWzGJTZYhUsn9rcOg4Gd Aicw== 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=YvrBtULQX4ISVmqY8ZE+9LzFj2ATZO5GZsBrD+xYvls=; b=rHAKuvlyPVTSgPxLCv7o5Fv22XFFPOa/RyGwemRzrnv/iHUtpaYT9IMCirs7dSTaiW EA+MJncTuxGmqczgGOtrlwkfSKAvzteD8Hw7C9KzwQCZNaYMlvzw7y6sAylpDHLITg7u jAt0pfFA4a99I0RfcWIANqU9EZboQhjJZpNxyQYVPaz4XLcyocHjWF+bNH/Rvf3FL2kc n6GDAWA+IjZEgr7K1h2qtyyNfAlg8RuRbUlydNf47Dgc4bHyl8UuuiglXTXLcYQtuwNV uJHqaUmIxPgfOqiIoHXBaWraX64LdYcZ02TPOlKcL4Sjj8Jh6MaKkmPUR7mX1FfKk4TD CMGQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="ixVwS9m/"; 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-54264-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54264-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=1; AJvYcCV7RB3HV6AEA4k5YdHc2uzbVG7dMq3NC/2tczuNb3g8ZtWFqPOQQvVD2Yv4d0R9Z+vnjQSrFplKWvWSmnOxgUBC4vW09A== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id n19-20020a5099d3000000b005600463837bsi614270edb.543.2024.02.05.19.35.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 19:35:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54264-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="ixVwS9m/"; 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-54264-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54264-ouuuleilei=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 B6E041F23F56 for ; Tue, 6 Feb 2024 03:35:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B75897C09D; Tue, 6 Feb 2024 03:33:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ixVwS9m/" 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 CCF9177F2B for ; Tue, 6 Feb 2024 03:33:39 +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=1707190421; cv=none; b=jhU5HpxZB33vjXFrxFqLzQgO2SV/f14ziGFeWZ9Nb9BSvUXhQSALEWgVr8rTQiIVoRJTrNoj/hnJ2a2zCfYpXGrGvkxfaIQjFs9NCL2UOHBqGeKdRxRL/urDm8GFFouvySbioE4bXQPnnEQT+j//Oo/8yKVJCGpVPI2AdeZ5u0U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707190421; c=relaxed/simple; bh=QOZ3AXSow+69/jSpTKwTzsRv+NqoTfrDzrJ1ZUXaoRk=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=BFl6aMPf3HzFtjHJMSE7ERtDXU5d1y9laws0+mrUGUvAAoQyXk9NO8EJkDOYTen7SezCpxv09VDYVxXKV4glTIBUYgkQRvPaoWQ0cO417bY/3EsBuoW5tJSKs6rVaatPXEtDcheg4N8YWW90oDSUq5R/vxc+fgmFnSJi8LWvt94= 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=ixVwS9m/; 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-60402c8d651so82838307b3.3 for ; Mon, 05 Feb 2024 19:33:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707190419; x=1707795219; 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=ixVwS9m/0znAw4QZkK+GbKmrknuOyRgxRPKAwxgz4Pzfd5JnseVblOETA7o0GsOPWJ n8Z+kXzC7suudMIuWBKVva54xQ2z2Q1hvaKh+pv1Q6/V5lZizFVEiHVOdB3lT4G3SuXR NaJSvfD+2NcfveM1/4UUC44quCuVgFpNlGirB1EknN5317334GM1SJ0At0TJmYSh3+SD oNcRHywDuoTW3Fz3vhLwkSTBcgytvJ9Mpfd89YlEsYYvGrRmYx9oMoHi5JhouDHYRJiy hoTGDJ8h5LfmHk+4EeyoUnkEV5rF4MQacUR3g80gObvzRJGmgHTf1+RrX8tbeLp1JBNK kiqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707190419; x=1707795219; 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=C07rfP9YYIuIjXiABIzKDgaeTxrMoFFS+/ccFJJL6Gl0YDFTciVcqqh37TXSbLivC7 Aa7hM0wBBrd+MH1S0wDb3Saqngzu7eUYRQUECJ91dw+Qeo/f6FwqzMNESnCzcGyU2oDH vDVSSQwWmeBqlKkWd14a4nnmDgBv66mx/sk6i6hv8o05aT5qWUoSCl3KxW6B8qyBHGo6 Yz/vtFXUovRLRrCzthMpLHzJnYVQfw30/VUVDaIuG6drZlB5vIG016EvtAXa7QaiL/QA bW9ixkDwmeSCSVsOEAzHPkyjm5fwGecNHAOpzrrkffk89slbzs+zw0uN8qk+prXaxwfW d2bg== X-Gm-Message-State: AOJu0YyeCwgOukd3PUxAxDahOMm2qkMMIccqUywUp1E5L2vc8ZNBszcD ms97YLICN1PbqU8eI4cE3XubA4g8xga4cqXo02/HH+qzH8EeDC26t+hr9I3SmFKc+Ub8FDG6KxT FIM+TQQ== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:326b:71bb:e465:6f39]) (user=irogers job=sendgmr) by 2002:a81:9ac1:0:b0:5f9:4fa1:1a0b with SMTP id r184-20020a819ac1000000b005f94fa11a0bmr62908ywg.0.1707190418775; Mon, 05 Feb 2024 19:33:38 -0800 (PST) Date: Mon, 5 Feb 2024 19:33:20 -0800 In-Reply-To: <20240206033320.2657716-1-irogers@google.com> Message-Id: <20240206033320.2657716-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: <20240206033320.2657716-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog Subject: [PATCH v1 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 , liuwenyu , Leo Yan , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790119042959490280 X-GMAIL-MSGID: 1790119042959490280 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);