From patchwork Fri Feb 2 23:40:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 196083 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp759121dyc; Fri, 2 Feb 2024 15:41:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IF/RHkUjBHUXxhTxqhH3icl5Nlx2upsblStAIr0NKysIjRFkFZuE0xOApTediM7YzgOR68y X-Received: by 2002:a05:6214:2a87:b0:68c:8e44:13ae with SMTP id jr7-20020a0562142a8700b0068c8e4413aemr1147115qvb.55.1706917311854; Fri, 02 Feb 2024 15:41:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706917311; cv=pass; d=google.com; s=arc-20160816; b=AE9K8fRmzcz5XpZ7a0RFewB9DvIfcZCBKRN05P9Ha/yw/xLc8Wwhv+TDRCZHUgr+lS CKMO8t3f7YmkR37QzAgvfBAeXZvcX+azJWS9HVR2R1PgwqpgkPKjBW8yZz4CPJGJ3qO3 3c+pk4qrmXXImDL6Z+jjpaaBFLRiYPOpCRo5MsGCdHbIAD61GOz1VrbvA6Epl34kRQO9 vIYwsh7EoPW0oo/05KFyI3zLI3hW20j0orLk9UUjqWYUaj+ID8/RYsW5odOLsqI0Djzu CheXzxwS1XbarE6nkpNG36SZvbW799zMK0IpM27g/ncfxSJfKUlxnIfht8JGD407cZqe B3QQ== 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=wSD742trI5qRJtx2AyB70ygbW0HL0IXuRRmpkhMUb0U=; fh=0rGcHQ5Q8vWkTML8m3BE6EwZl90EduiaXgIRpF0cPQw=; b=VRgfgg+cCnmXHjI4S5xrujhrcE1ixK7Uoz6xa/mXDBfPjkSGH4msTkLAbUkMA/uyNa /TTKjDEUZgSS8JaoB1diOBMSbvgjLaUx0RkSlOpX1VEDv8gLlXrdQgc3TGUTN1xjvIsq nfD4egDXhEn+zNl8j4JxLBWLurgFgQ1uVaFwXH1yCfaZU0UAYytHSLShv81wEV4ROo4p g4WbOMWZuNgHLgKQ6xMDAkO4Qap+uvJwZ0nxEoTP/JUUMt9dcE+cqCZlIG7xOmSwNw2Y 0nWq5rW49LRKH0FhRxN0jP1Va87ZnKla/8V9R/ar8iQnJBVJx6dPXz+h9XuIO4tHAaN9 De1Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=1RE9Oql0; 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-50719-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50719-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=1; AJvYcCV72667j5uw7ZELjLbXRmFlbOrfELfcsMRaxEAEU+I0JoDvxGqtEY/my7kRdRZXdzy1HushpzUYZY0dd3yTtv2P7Ia1KQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id w10-20020a056214012a00b006894f48199asi3184300qvs.359.2024.02.02.15.41.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 15:41:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50719-ouuuleilei=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=1RE9Oql0; 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-50719-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50719-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 94D511C21441 for ; Fri, 2 Feb 2024 23:41:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 01AFD12F397; Fri, 2 Feb 2024 23:41:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="1RE9Oql0" 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 CB0FA12D742 for ; Fri, 2 Feb 2024 23:41:12 +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=1706917274; cv=none; b=Q4GSlunXzKIEV77Cf8Jq3wIv3937/3xjrcpdsF9ZMaJI07AD0K47EP+OaELltPgl2wjWNnJMGezUa2zQqgq5PfO64YrD8z/3ameViIpOkMrtM0/6Zsi3jdZ1Edyh/OfF67C5lnPJ/G1mg5xj6XtJ+rJq2mTZ3iurZHWQiftj7Ck= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706917274; c=relaxed/simple; bh=5nIG5LyKHW7GTVpxwdG8LHaYQ9yDY/AHj79BA34oOvg=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=l3bHyxCrUW63iQgj8w9tihCz0tzPZx5hiHz4eHb65bVqpcwvY9Lql5zVQtAlmOA1+Zm9FcVqOyJC8BYsAAvr/km3dy8eFjs4yrwBZCcKBfUhcF55Ud23/whyRptG0UE3N6q9YHBGEzqnfqJ6Ka/vfm0Lt6NRn/VwbWdUZh19jSM= 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=1RE9Oql0; 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-5ee22efe5eeso45172277b3.3 for ; Fri, 02 Feb 2024 15:41:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706917272; x=1707522072; 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=wSD742trI5qRJtx2AyB70ygbW0HL0IXuRRmpkhMUb0U=; b=1RE9Oql00b8bPBF3nUtfAXNGCQbTSxEVTWp1T12bs3BJpQiGm6DBZglgALGxC+P0nV ztrQK/V728stfHu8CfWoxgnRrIZIOjeVFjLFz3KWZk1suK5Uyw38d2wbATnGz1apj88W chYS/yULOLkaiHhgtNMLCy1StLX6ljs3/opYsz72tpFvW3hSs7votYj/WpgH6OkHfVWI lrSQEayy05D/htOuLZ8FDbLRcUspZTM28F6GGs/xwESLapxH5F7MUpkPhCgdAOZCNAO/ ASNFwH7I2Y6O17+85IxqbjPSKD3VjmQGYigjUdblyMKZ/NSIZ3QigkvpGhVc30y1MiIB NTlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706917272; x=1707522072; 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=wSD742trI5qRJtx2AyB70ygbW0HL0IXuRRmpkhMUb0U=; b=SWBz/T8AHhgP4O6VaAwTwKhLabcR81q/kj0dUNFxSCEmMRbGrxR/fpZoNiTBgydmro lpKM66cKAASs5M5Zm3omFB1UTyUuMweQRR/lF/Uw9N6c31y746DZCmi8NRLfFdWamuTH Nmfwt8u0z1OYRi0408EeHY40keT9qF1L0u5KVUHQxefnOuKWylJ3TwSwTgbn22Rk3laG oChJjEhZVfKCvBB2J8QcJomp4KGygR1gdAI9acaxGGvRz3Q2jb1s2lta6sNUSEPWIWe3 Ij9bE9GoXB+r1OAdbAldbQARO2ucrI0DsJDTK3nqXu1d2Hl9FbYCE9VCompCi7Pxy7pC Vn2A== X-Gm-Message-State: AOJu0YziWGDvJbtGGavsGR1Pf+owURLnJAox46x69Wxa75WcW0T6wBmT WuVanPC7ddyDhcOH/UM1X3hKufgaHAWiODUEPvcX0uut9RcFsRiSDmEAejB+ZfCB9AFHBlDwV5F puCuNiA== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:7732:d863:503:f53d]) (user=irogers job=sendgmr) by 2002:a05:690c:19:b0:600:2492:f962 with SMTP id bc25-20020a05690c001900b006002492f962mr1161790ywb.8.1706917271761; Fri, 02 Feb 2024 15:41:11 -0800 (PST) Date: Fri, 2 Feb 2024 15:40:50 -0800 In-Reply-To: <20240202234057.2085863-1-irogers@google.com> Message-Id: <20240202234057.2085863-2-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240202234057.2085863-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog Subject: [PATCH v3 1/8] libperf cpumap: Add any, empty and min helpers From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Suzuki K Poulose , Mike Leach , James Clark , Leo Yan , John Garry , Will Deacon , Thomas Gleixner , Darren Hart , Davidlohr Bueso , " =?utf-8?q?Andr=C3=A9_Almeida?= " , Kan Liang , K Prateek Nayak , Sean Christopherson , Paolo Bonzini , Kajol Jain , Athira Rajeev , Andrew Jones , Alexandre Ghiti , Atish Patra , "Steinar H. Gunderson" , Yang Jihong , Yang Li , Changbin Du , Sandipan Das , Ravi Bangoria , Paran Lee , Nick Desaulniers , Huacai Chen , Yanteng Si , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, bpf@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789832527279072921 X-GMAIL-MSGID: 1789832527279072921 Additional helpers to better replace perf_cpu_map__has_any_cpu_or_is_empty. Signed-off-by: Ian Rogers --- tools/lib/perf/cpumap.c | 27 +++++++++++++++++++++++++++ tools/lib/perf/include/perf/cpumap.h | 16 ++++++++++++++++ tools/lib/perf/libperf.map | 4 ++++ 3 files changed, 47 insertions(+) diff --git a/tools/lib/perf/cpumap.c b/tools/lib/perf/cpumap.c index 4adcd7920d03..ba49552952c5 100644 --- a/tools/lib/perf/cpumap.c +++ b/tools/lib/perf/cpumap.c @@ -316,6 +316,19 @@ bool perf_cpu_map__has_any_cpu_or_is_empty(const struct perf_cpu_map *map) return map ? __perf_cpu_map__cpu(map, 0).cpu == -1 : true; } +bool perf_cpu_map__is_any_cpu_or_is_empty(const struct perf_cpu_map *map) +{ + if (!map) + return true; + + return __perf_cpu_map__nr(map) == 1 && __perf_cpu_map__cpu(map, 0).cpu == -1; +} + +bool perf_cpu_map__is_empty(const struct perf_cpu_map *map) +{ + return map == NULL; +} + int perf_cpu_map__idx(const struct perf_cpu_map *cpus, struct perf_cpu cpu) { int low, high; @@ -372,6 +385,20 @@ bool perf_cpu_map__has_any_cpu(const struct perf_cpu_map *map) return map && __perf_cpu_map__cpu(map, 0).cpu == -1; } +struct perf_cpu perf_cpu_map__min(const struct perf_cpu_map *map) +{ + struct perf_cpu cpu, result = { + .cpu = -1 + }; + int idx; + + perf_cpu_map__for_each_cpu_skip_any(cpu, idx, map) { + result = cpu; + break; + } + return result; +} + struct perf_cpu perf_cpu_map__max(const struct perf_cpu_map *map) { struct perf_cpu result = { diff --git a/tools/lib/perf/include/perf/cpumap.h b/tools/lib/perf/include/perf/cpumap.h index 228c6c629b0c..90457d17fb2f 100644 --- a/tools/lib/perf/include/perf/cpumap.h +++ b/tools/lib/perf/include/perf/cpumap.h @@ -61,6 +61,22 @@ LIBPERF_API int perf_cpu_map__nr(const struct perf_cpu_map *cpus); * perf_cpu_map__has_any_cpu_or_is_empty - is map either empty or has the "any CPU"/dummy value. */ LIBPERF_API bool perf_cpu_map__has_any_cpu_or_is_empty(const struct perf_cpu_map *map); +/** + * perf_cpu_map__is_any_cpu_or_is_empty - is map either empty or the "any CPU"/dummy value. + */ +LIBPERF_API bool perf_cpu_map__is_any_cpu_or_is_empty(const struct perf_cpu_map *map); +/** + * perf_cpu_map__is_empty - does the map contain no values and it doesn't + * contain the special "any CPU"/dummy value. + */ +LIBPERF_API bool perf_cpu_map__is_empty(const struct perf_cpu_map *map); +/** + * perf_cpu_map__min - the minimum CPU value or -1 if empty or just the "any CPU"/dummy value. + */ +LIBPERF_API struct perf_cpu perf_cpu_map__min(const struct perf_cpu_map *map); +/** + * perf_cpu_map__max - the maximum CPU value or -1 if empty or just the "any CPU"/dummy value. + */ LIBPERF_API struct perf_cpu perf_cpu_map__max(const struct perf_cpu_map *map); LIBPERF_API bool perf_cpu_map__has(const struct perf_cpu_map *map, struct perf_cpu cpu); LIBPERF_API bool perf_cpu_map__equal(const struct perf_cpu_map *lhs, diff --git a/tools/lib/perf/libperf.map b/tools/lib/perf/libperf.map index 10b3f3722642..2aa79b696032 100644 --- a/tools/lib/perf/libperf.map +++ b/tools/lib/perf/libperf.map @@ -10,6 +10,10 @@ LIBPERF_0.0.1 { perf_cpu_map__nr; perf_cpu_map__cpu; perf_cpu_map__has_any_cpu_or_is_empty; + perf_cpu_map__is_any_cpu_or_is_empty; + perf_cpu_map__is_empty; + perf_cpu_map__has_any_cpu; + perf_cpu_map__min; perf_cpu_map__max; perf_cpu_map__has; perf_thread_map__new_array; From patchwork Fri Feb 2 23:40:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 196084 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp759225dyc; Fri, 2 Feb 2024 15:42:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IHaixNPbRPgM732MEq/6B9l8iR5HD/AnQvP0TtBZ685X/n/ebF9g/TnIF9w08BLXSEdRP5u X-Received: by 2002:a05:622a:593:b0:42b:f794:d46 with SMTP id c19-20020a05622a059300b0042bf7940d46mr6444540qtb.60.1706917327904; Fri, 02 Feb 2024 15:42:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706917327; cv=pass; d=google.com; s=arc-20160816; b=pZbDjV37+VIcZAgN7fIgja10VLlns1p3KhR7cEctdG0/VvGgl6WoFr4Q8ZBaCa7eGl nzFw/IXpgENfAqBV1QYQy6EgQgqA1u2wCVYWHxcJaFwt7NZLt1SsyJVqN3q6a9Km/y06 GLKPQsXOJIOXVFutbdwAaq4aAUDccsFiETOJD8OcbPDfoOeP7j8/3Mxgojq0o739dh8x NH3FuAxTqAdmw0uJ7/1WtsuI+1P185bYBUEKhxwTC2BXnJgpUmLIyHMAVE0v+FyurYVP knjJ1EbixMfusvQvg7kxeVYIHpq3HVC9oBT5BWTpdw6Vz84lc91aIZxpumWFOvF2tQuv 1G2A== 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=wOc7/ot5clrlqkd/XVVApb41eylij+dgoGLfSlWPOp0=; fh=Nlhf4X30j6heizD8GMG6198g4c7lxJN77yU2/5LPjsY=; b=ktUcMoyr8HVP5YLkDjQLZPwOWr797kiszJXfA3gi+dxx3AQq0IlVa6AjRrvQrQIvzD +1cW87DauHCtHL2GqCFlwZeVVt3FVdzTcB7DqSzGecdMF6X+wKTG43wLEeLWqNojFqR7 D0oYh0XuiEd4A1ALQB6hkhMnFCNgweLrlXzXBy6D2hR7vPqM6v0jYCtzq1OcixBAX9tG Agpfd4QoRQ+koh2Vq0iRTU+jFc4HDYnq+6jbFce0moJf2x/mycPds+rvCwQa7/ZMmqkD VhBSWP4rdTO43c+Y0gT+m1zJcwYG3w/Pilc1i21xMp4kAcxncjJq2hzl3GPGFDFthrcu Ohbw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=AyrvHKJj; 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-50720-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50720-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=1; AJvYcCUWpIWrlP2StCEaSjc0pQRI8/BzOI3E5e8VOvqqhiAMMSmxse8BH4Pt1kLDM86ZB6QuMj2g7P3Aog+ANYcaI3kicJeVcg== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id n9-20020a05622a040900b0042ab228f5dcsi3120156qtx.779.2024.02.02.15.42.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 15:42:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50720-ouuuleilei=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=AyrvHKJj; 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-50720-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50720-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id B04DD1C20CB4 for ; Fri, 2 Feb 2024 23:42:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 97DC812C7E5; Fri, 2 Feb 2024 23:41:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="AyrvHKJj" Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.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 3CA9212D779 for ; Fri, 2 Feb 2024 23:41:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706917277; cv=none; b=q8i2BwUoUuwPQdVM4q+GQygAFM+SPdcudjqE/70YYDPd/Dg5nRKaqLSwf91Xmfu/5G2rSkHYfupsIHc/0woUyx8qbUG6ViNVUaU3BW4/cGB6rz4cPgGaXsNdGxhWH+fsNzfKJw0b+UpxeEIIWsQiPFaz03bZdxlaMtBLclZPCLQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706917277; c=relaxed/simple; bh=R7HDLt+WXCKcw0UAraBcZnWD54QthkXyaQu13uOf35M=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=JH+fbjxihsSQWLtf2SaB2TxVc/f1s4Ezf/vcNnocDD+ojPf/md3AXWjAl4ThngaKwdLOyuiNDy7GvS2+P/wGvsCr8bNF4pagm48Dm7vHaJ1SPe/afZrVkiRXwCeQWE7yPrAMZfz5+ee4Pn220g3/srRwHV9pgvWxsJL9yBbtRnA= 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=AyrvHKJj; arc=none smtp.client-ip=209.85.219.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-yb1-f202.google.com with SMTP id 3f1490d57ef6-dc6b9f4a513so4065541276.3 for ; Fri, 02 Feb 2024 15:41:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706917274; x=1707522074; 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=wOc7/ot5clrlqkd/XVVApb41eylij+dgoGLfSlWPOp0=; b=AyrvHKJjjXcpTnTw4Q1Oh72rOi5vJrbZ3NSKSgFRcmHrdQ9urAxqzaDeeAWfqmw1CL V2OIprdiY9MJ0htwTWHjbjukLdw7GmjOkyqarwZWfqn2/8Nov6Ocp/QbJOAyaHPZqEhv hziwunHjYpud1MfPnxCijqL4At/8TCLcXP3ITG/sHjJf5dLMZBDCWVnSsVuJpt8WizXl wZDeqrqXusMSV10naS2Ovb/WYhlAqQRr2Xtbkc0txIShOu29QlZQm42MK7Ezu4CBW1H2 OxpzDQzCpQwQLEealrpbXlNFI9Pleu4GOdpHUI3AnJSzmnPwCCL/ker674WkFBkQGxwz OW2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706917274; x=1707522074; 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=wOc7/ot5clrlqkd/XVVApb41eylij+dgoGLfSlWPOp0=; b=s0CHHmfWSUx/vLlekIpxwyw2nm3WhU1a0InuFyvicCZnvj0QCfxNoJ9Zmz/6HTFEbS q8cBTXxMK+uigQp6fohlY7xUVvDETdQ0OBGy9ZZIOmHdrY8fYnMh4jArljW0Xb36mVgA BbT/5ck7YKsHhEo8F6FzZrjk2XL/yvvnoQt2I7EbyNjX6m7O6BjNPCLGSNP2seTB7UpF s5PPNANemFd2qD3nHld0OM47BKaR9M/XOTJjlhlwWNjJBPlyq5Unx7m8wTBVxh9vm9sh XAyMAe9Ki4vnjqN0wkcWw83QmLQJ997BSIp8qXKtqxsNt4AHAaeSVddjWfAReX/wrwK/ hKYg== X-Gm-Message-State: AOJu0Yw1veCrCusjYhRQDA8GBA2mm66YBIHSRPXT+KcAEJz5IB9+CZSx uJnxMWkqqMV6hLMQOpGCvyhzsA/79kBOxlcpbsFZ8qS+K0vXsdRssycsuSnMyWaLux4UWGOKf/S R1hQlDA== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:7732:d863:503:f53d]) (user=irogers job=sendgmr) by 2002:a05:6902:1b08:b0:dc2:398d:a671 with SMTP id eh8-20020a0569021b0800b00dc2398da671mr1024554ybb.10.1706917274174; Fri, 02 Feb 2024 15:41:14 -0800 (PST) Date: Fri, 2 Feb 2024 15:40:51 -0800 In-Reply-To: <20240202234057.2085863-1-irogers@google.com> Message-Id: <20240202234057.2085863-3-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240202234057.2085863-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog Subject: [PATCH v3 2/8] libperf cpumap: Ensure empty cpumap is NULL from alloc From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Suzuki K Poulose , Mike Leach , James Clark , Leo Yan , John Garry , Will Deacon , Thomas Gleixner , Darren Hart , Davidlohr Bueso , " =?utf-8?q?Andr=C3=A9_Almeida?= " , Kan Liang , K Prateek Nayak , Sean Christopherson , Paolo Bonzini , Kajol Jain , Athira Rajeev , Andrew Jones , Alexandre Ghiti , Atish Patra , "Steinar H. Gunderson" , Yang Jihong , Yang Li , Changbin Du , Sandipan Das , Ravi Bangoria , Paran Lee , Nick Desaulniers , Huacai Chen , Yanteng Si , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, bpf@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789832544332552779 X-GMAIL-MSGID: 1789832544332552779 Potential corner cases could cause a cpumap to be allocated with size 0, but an empty cpumap should be represented as NULL. Add a path in perf_cpu_map__alloc to ensure this. Suggested-by: James Clark Closes: https://lore.kernel.org/lkml/2cd09e7c-eb88-6726-6169-647dcd0a8101@arm.com/ Signed-off-by: Ian Rogers --- tools/lib/perf/cpumap.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/lib/perf/cpumap.c b/tools/lib/perf/cpumap.c index ba49552952c5..cae799ad44e1 100644 --- a/tools/lib/perf/cpumap.c +++ b/tools/lib/perf/cpumap.c @@ -18,9 +18,13 @@ void perf_cpu_map__set_nr(struct perf_cpu_map *map, int nr_cpus) struct perf_cpu_map *perf_cpu_map__alloc(int nr_cpus) { - RC_STRUCT(perf_cpu_map) *cpus = malloc(sizeof(*cpus) + sizeof(struct perf_cpu) * nr_cpus); + RC_STRUCT(perf_cpu_map) *cpus; struct perf_cpu_map *result; + if (nr_cpus == 0) + return NULL; + + cpus = malloc(sizeof(*cpus) + sizeof(struct perf_cpu) * nr_cpus); if (ADD_RC_CHK(result, cpus)) { cpus->nr = nr_cpus; refcount_set(&cpus->refcnt, 1); From patchwork Fri Feb 2 23:40:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 196085 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp759355dyc; Fri, 2 Feb 2024 15:42:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IGM/J0V9wVcfciWNx4Qef1hAAPoxxjgsUdLWQUYcp1p5D/ytefEUVuQZREeLod2Bx87vj5i X-Received: by 2002:a0c:cd10:0:b0:68c:7b5b:a9df with SMTP id b16-20020a0ccd10000000b0068c7b5ba9dfmr5096224qvm.55.1706917357821; Fri, 02 Feb 2024 15:42:37 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706917357; cv=pass; d=google.com; s=arc-20160816; b=WqO/RBhyC907jMlbeM2wQGTo1qJNjcP/NljLm8LsvEyia4DDtdOd7jQwbYndxRL7Ae FjZ6Pi7ykmt3MCF5e5ueLc322HWqoZmDHcOTljzCqydaA8STe3kvzimpgSPB5OktdVNy 6keZeMrYaC0lEzeXgntIdTZmkp5uklNwTFI8OaNnHWQNzZ4nuJlIZetZBlMuocHle5S/ OK/aU6Sm2k7Akbpttrx0WKipS3xnW1cH90dKb0DrXF0esVogtNU10qeS9/B+j3efQZRx gP68/otXU2vXhzo4n9WOnhy1P7KDQXDRSj3nD29I6CLuVVNhg6mKrCRRTBcxsSJXmMn6 602g== 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=Xzvhj+a0qyhqfnlkJlD6nNip1T9+Dz0mvAMEktGGdDs=; fh=tLgeF88xgEgdZhde1RR4Df3NODfuqhxmTxRRE9WHUuo=; b=gJcTS13IzTItrEdG0iXRps9aRH0RnoxgKERdwIyNXlFwCVrZZl1f7gt4Xq73GGWa/4 2lV5PQNRSd2SomJRFPzy7oolBgL7tTla5m/MRH5CvdNAdpjYn5GB/ow+9nH8NGE+0L/u PAgOWMB7s7TMFmI3YtNyqbwQZSJ44UnigtFyTn3zfJXVi+EAo0V8t6QPYGRzdZCkrL55 5jz+L9fJVv5AFnmD0hD/hGlsvgn8WVB2HpQJstsCObSF7UMDlVE4ubcAR7w26y8WdlJ9 3IT3qPF+ctJvjB3qnw2kxKoQG7D+3Vu78SyAiQLIK/HTzu9YiaylQn1Jp3hQ9UAh33Dz awmA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Q2SurpQR; 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-50721-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50721-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=1; AJvYcCWBC8sPHPGYmgYcvU5g9VB5Ex4ZHUBJA9pimryiS2IYSoK7GQMsomdGtp4j38BOz2JH0eDpeVUUPNblhiSXDtre4xk/DA== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id l9-20020a05620a210900b00783f4af008esi3207888qkl.619.2024.02.02.15.42.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 15:42:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50721-ouuuleilei=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=Q2SurpQR; 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-50721-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50721-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 8D7551C2148C for ; Fri, 2 Feb 2024 23:42:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7E4C2132481; Fri, 2 Feb 2024 23:41:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Q2SurpQR" 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 3C46C12F38C for ; Fri, 2 Feb 2024 23:41:17 +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=1706917279; cv=none; b=pk3MTd45rgugQ9fhcGdXovx4sj0A6qFMJWjkrWaNNmDQQyW7jCJJejMR4r2YSeugPb7b6uezDBuUSzWoVaYw1X3Gg+S0hoQdT4VL8Q0t5Jd0K4Pw2mW6pW9O8ynokroqj5JOope+1oF0zQbpWzVEQYPoC4Yv+GqliZAHhOlzRXI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706917279; c=relaxed/simple; bh=2CEX69l8jHviwD08AVVrjec2O+3gxN5VKnRqORpifeQ=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=MchgCXk4d5rH746gdBKdg3fffxDUwGToXCKlX4dQTr5BNkv6N4gkNUsfF0xTAaDLjKze5BUAY7ZwaB4ceYErVbBBqEq2L/FQFhMQaR/FEqkiS9sVOPX9FZsbtuRCo2QDrmFSDudyY1WDZg940dgOQcCysszO0+KtrCxyFBUWwJM= 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=Q2SurpQR; 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-dc3645a6790so4709056276.0 for ; Fri, 02 Feb 2024 15:41:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706917276; x=1707522076; 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=Xzvhj+a0qyhqfnlkJlD6nNip1T9+Dz0mvAMEktGGdDs=; b=Q2SurpQRaQR+Y1ACtUW51Dydq5v+1OzPqkkPVLGHwTb717kWrZcZfvskPLtNK/MhLU n1o+FZ5aOx9PFmqJBzmUBKJBCU9L1XQtaZg7mkx+CWCD9R2uzO4Jx7Ck+xvCkq3na/EY h9eBZQtGcZjsCWJ7HF2HFeteZTucJ++HtL79fNMqU5JdcZnij8i/wUqB44at2bvUzJVx BQ5eptnmMoCBQmlC7XR+o+o1WcaGq2/6ppJh8Xg07JNteT0AA/wYWKwhfhnc1PEM+mG5 Z1l/L2AKBdjdg3r4Y52zKLvSeT43gSbNGqfB3LBmbKU2CCLWwEVjPjt+LS/M/+H2HMmF Igng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706917276; x=1707522076; 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=Xzvhj+a0qyhqfnlkJlD6nNip1T9+Dz0mvAMEktGGdDs=; b=xMJmc5Gg0MA55go3kSY5IzUgUcAuu3jMVzGSafP9WAUIcKivdYO4W5j57htncMe+ws 7CiK9zD98HpLbbCTsQ8FddLO7ooyTJSwqUxW1nONAz18U+bL/YRo2P/mrRc0zSx1Y4zG 3QpV+dL3VatdD1UJVeNvLKN/JnzqYMXOmW3GtdEQUkoWSWvMw4xjK7iwX3DnYI0lrA4P ex6++djptYlSL8pdOC/1ARb8WZsTWSYtu4AS5H8ylpWYH3hWryyYl8FAM5njlikjZPVE sEsNqlYkhBh9hWlzJTe70obquTGcb2kJy1qAmATFxGiyODnHAhpPwv9vXqDnF8fCZCAH JBEQ== X-Gm-Message-State: AOJu0Yw2wXozvnJ7/TOAOQ5tpXccCv09Q+pqxh1VaynXicg0R/r8e99E 8h/olUSFM/jlnU/TA38pWzRzPd20TwBvFA9mrd3HxONj5xt7oPWLXN97PxLRWV7JIOwSSiwEBTZ VMq4XFA== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:7732:d863:503:f53d]) (user=irogers job=sendgmr) by 2002:a05:6902:138e:b0:dc2:1cd6:346e with SMTP id x14-20020a056902138e00b00dc21cd6346emr2454938ybu.8.1706917276279; Fri, 02 Feb 2024 15:41:16 -0800 (PST) Date: Fri, 2 Feb 2024 15:40:52 -0800 In-Reply-To: <20240202234057.2085863-1-irogers@google.com> Message-Id: <20240202234057.2085863-4-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240202234057.2085863-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog Subject: [PATCH v3 3/8] perf arm-spe/cs-etm: Directly iterate CPU 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 , Suzuki K Poulose , Mike Leach , James Clark , Leo Yan , John Garry , Will Deacon , Thomas Gleixner , Darren Hart , Davidlohr Bueso , " =?utf-8?q?Andr=C3=A9_Almeida?= " , Kan Liang , K Prateek Nayak , Sean Christopherson , Paolo Bonzini , Kajol Jain , Athira Rajeev , Andrew Jones , Alexandre Ghiti , Atish Patra , "Steinar H. Gunderson" , Yang Jihong , Yang Li , Changbin Du , Sandipan Das , Ravi Bangoria , Paran Lee , Nick Desaulniers , Huacai Chen , Yanteng Si , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, bpf@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789832575200897259 X-GMAIL-MSGID: 1789832575200897259 Rather than iterate all CPUs and see if they are in CPU maps, directly iterate the CPU map. Similarly make use of the intersect function taking care for when "any" CPU is specified. Switch perf_cpu_map__has_any_cpu_or_is_empty to more appropriate alternatives. Signed-off-by: Ian Rogers Reviewed-by: James Clark --- tools/perf/arch/arm/util/cs-etm.c | 114 ++++++++++++--------------- tools/perf/arch/arm64/util/arm-spe.c | 4 +- 2 files changed, 51 insertions(+), 67 deletions(-) diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c index 77e6663c1703..07be32d99805 100644 --- a/tools/perf/arch/arm/util/cs-etm.c +++ b/tools/perf/arch/arm/util/cs-etm.c @@ -197,38 +197,37 @@ static int cs_etm_validate_timestamp(struct auxtrace_record *itr, static int cs_etm_validate_config(struct auxtrace_record *itr, struct evsel *evsel) { - int i, err = -EINVAL; + int idx, err = 0; struct perf_cpu_map *event_cpus = evsel->evlist->core.user_requested_cpus; - struct perf_cpu_map *online_cpus = perf_cpu_map__new_online_cpus(); - - /* Set option of each CPU we have */ - for (i = 0; i < cpu__max_cpu().cpu; i++) { - struct perf_cpu cpu = { .cpu = i, }; + struct perf_cpu_map *intersect_cpus; + struct perf_cpu cpu; - /* - * In per-cpu case, do the validation for CPUs to work with. - * In per-thread case, the CPU map is empty. Since the traced - * program can run on any CPUs in this case, thus don't skip - * validation. - */ - if (!perf_cpu_map__has_any_cpu_or_is_empty(event_cpus) && - !perf_cpu_map__has(event_cpus, cpu)) - continue; + /* + * Set option of each CPU we have. In per-cpu case, do the validation + * for CPUs to work with. In per-thread case, the CPU map has the "any" + * CPU value. Since the traced program can run on any CPUs in this case, + * thus don't skip validation. + */ + if (!perf_cpu_map__has_any_cpu(event_cpus)) { + struct perf_cpu_map *online_cpus = perf_cpu_map__new_online_cpus(); - if (!perf_cpu_map__has(online_cpus, cpu)) - continue; + intersect_cpus = perf_cpu_map__intersect(event_cpus, online_cpus); + perf_cpu_map__put(online_cpus); + } else { + intersect_cpus = perf_cpu_map__new_online_cpus(); + } - err = cs_etm_validate_context_id(itr, evsel, i); + perf_cpu_map__for_each_cpu_skip_any(cpu, idx, intersect_cpus) { + err = cs_etm_validate_context_id(itr, evsel, cpu.cpu); if (err) - goto out; - err = cs_etm_validate_timestamp(itr, evsel, i); + break; + + err = cs_etm_validate_timestamp(itr, evsel, cpu.cpu); if (err) - goto out; + break; } - err = 0; -out: - perf_cpu_map__put(online_cpus); + perf_cpu_map__put(intersect_cpus); return err; } @@ -435,7 +434,7 @@ static int cs_etm_recording_options(struct auxtrace_record *itr, * Also the case of per-cpu mmaps, need the contextID in order to be notified * when a context switch happened. */ - if (!perf_cpu_map__has_any_cpu_or_is_empty(cpus)) { + if (!perf_cpu_map__is_any_cpu_or_is_empty(cpus)) { evsel__set_config_if_unset(cs_etm_pmu, cs_etm_evsel, "timestamp", 1); evsel__set_config_if_unset(cs_etm_pmu, cs_etm_evsel, @@ -461,7 +460,7 @@ static int cs_etm_recording_options(struct auxtrace_record *itr, evsel->core.attr.sample_period = 1; /* In per-cpu case, always need the time of mmap events etc */ - if (!perf_cpu_map__has_any_cpu_or_is_empty(cpus)) + if (!perf_cpu_map__is_any_cpu_or_is_empty(cpus)) evsel__set_sample_bit(evsel, TIME); err = cs_etm_validate_config(itr, cs_etm_evsel); @@ -533,45 +532,31 @@ static size_t cs_etm_info_priv_size(struct auxtrace_record *itr __maybe_unused, struct evlist *evlist __maybe_unused) { - int i; + int idx; int etmv3 = 0, etmv4 = 0, ete = 0; struct perf_cpu_map *event_cpus = evlist->core.user_requested_cpus; - struct perf_cpu_map *online_cpus = perf_cpu_map__new_online_cpus(); - - /* cpu map is not empty, we have specific CPUs to work with */ - if (!perf_cpu_map__has_any_cpu_or_is_empty(event_cpus)) { - for (i = 0; i < cpu__max_cpu().cpu; i++) { - struct perf_cpu cpu = { .cpu = i, }; + struct perf_cpu_map *intersect_cpus; + struct perf_cpu cpu; - if (!perf_cpu_map__has(event_cpus, cpu) || - !perf_cpu_map__has(online_cpus, cpu)) - continue; + if (!perf_cpu_map__has_any_cpu(event_cpus)) { + /* cpu map is not "any" CPU , we have specific CPUs to work with */ + struct perf_cpu_map *online_cpus = perf_cpu_map__new_online_cpus(); - if (cs_etm_is_ete(itr, i)) - ete++; - else if (cs_etm_is_etmv4(itr, i)) - etmv4++; - else - etmv3++; - } + intersect_cpus = perf_cpu_map__intersect(event_cpus, online_cpus); + perf_cpu_map__put(online_cpus); } else { - /* get configuration for all CPUs in the system */ - for (i = 0; i < cpu__max_cpu().cpu; i++) { - struct perf_cpu cpu = { .cpu = i, }; - - if (!perf_cpu_map__has(online_cpus, cpu)) - continue; - - if (cs_etm_is_ete(itr, i)) - ete++; - else if (cs_etm_is_etmv4(itr, i)) - etmv4++; - else - etmv3++; - } + /* Event can be "any" CPU so count all online CPUs. */ + intersect_cpus = perf_cpu_map__new_online_cpus(); } - - perf_cpu_map__put(online_cpus); + perf_cpu_map__for_each_cpu_skip_any(cpu, idx, intersect_cpus) { + if (cs_etm_is_ete(itr, cpu.cpu)) + ete++; + else if (cs_etm_is_etmv4(itr, cpu.cpu)) + etmv4++; + else + etmv3++; + } + perf_cpu_map__put(intersect_cpus); return (CS_ETM_HEADER_SIZE + (ete * CS_ETE_PRIV_SIZE) + @@ -813,16 +798,15 @@ static int cs_etm_info_fill(struct auxtrace_record *itr, if (!session->evlist->core.nr_mmaps) return -EINVAL; - /* If the cpu_map is empty all online CPUs are involved */ - if (perf_cpu_map__has_any_cpu_or_is_empty(event_cpus)) { + /* If the cpu_map has the "any" CPU all online CPUs are involved */ + if (perf_cpu_map__has_any_cpu(event_cpus)) { cpu_map = online_cpus; } else { /* Make sure all specified CPUs are online */ - for (i = 0; i < perf_cpu_map__nr(event_cpus); i++) { - struct perf_cpu cpu = { .cpu = i, }; + struct perf_cpu cpu; - if (perf_cpu_map__has(event_cpus, cpu) && - !perf_cpu_map__has(online_cpus, cpu)) + perf_cpu_map__for_each_cpu(cpu, i, event_cpus) { + if (!perf_cpu_map__has(online_cpus, cpu)) return -EINVAL; } diff --git a/tools/perf/arch/arm64/util/arm-spe.c b/tools/perf/arch/arm64/util/arm-spe.c index 51ccbfd3d246..0b52e67edb3b 100644 --- a/tools/perf/arch/arm64/util/arm-spe.c +++ b/tools/perf/arch/arm64/util/arm-spe.c @@ -232,7 +232,7 @@ static int arm_spe_recording_options(struct auxtrace_record *itr, * In the case of per-cpu mmaps, sample CPU for AUX event; * also enable the timestamp tracing for samples correlation. */ - if (!perf_cpu_map__has_any_cpu_or_is_empty(cpus)) { + if (!perf_cpu_map__is_any_cpu_or_is_empty(cpus)) { evsel__set_sample_bit(arm_spe_evsel, CPU); evsel__set_config_if_unset(arm_spe_pmu, arm_spe_evsel, "ts_enable", 1); @@ -265,7 +265,7 @@ static int arm_spe_recording_options(struct auxtrace_record *itr, tracking_evsel->core.attr.sample_period = 1; /* In per-cpu case, always need the time of mmap events etc */ - if (!perf_cpu_map__has_any_cpu_or_is_empty(cpus)) { + if (!perf_cpu_map__is_any_cpu_or_is_empty(cpus)) { evsel__set_sample_bit(tracking_evsel, TIME); evsel__set_sample_bit(tracking_evsel, CPU); From patchwork Fri Feb 2 23:40:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 196086 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp759496dyc; Fri, 2 Feb 2024 15:43:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IHWefN09QJMj2LL0w3zcHsYNUi8gnSGeV5OPU1+EEof/MRIzj+0cMrf4SrQBQSyGcEJDty1 X-Received: by 2002:a17:902:a3c1:b0:1d9:2665:61c with SMTP id q1-20020a170902a3c100b001d92665061cmr3419770plb.8.1706917385417; Fri, 02 Feb 2024 15:43:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706917385; cv=pass; d=google.com; s=arc-20160816; b=OCiFModCP7GzaGKMsDyHfF9jsLpUVLMdjDU55Ft5UF+VYBRyDWuqQybdoTAS/wgLTM z16B7yT7UHGSZdG6nADP3UKVDLRR34PD9x+GYvWILlvt6XtgC0ymiFue7ULKZGvcjfqr G3y5mrKGefkkvTBCxljQpHPCSRWPWSiromLy+Igp2dCLXf5McBDjm3sBgC8x8+2bwCMi 870Czfh2s3xKitM6tTQADvnohKqxT0k7BAkVVWleQ2FTzANElBhMaTBmCOx9dUd/9bio 5/6xCY9QLOLSxEcyLQMOEKg6urGg2PixWRgkWMBbhKRtw2/A1wyu4Tz0Z6E0IW+rkWOm 2PMg== 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=wr65K6vWppDQ/+c7LXR1fsKtLh163OjTy8d5391wuIk=; fh=RfuJ5OAXEOuU6gTQIyBZCvkqElWvI+gK/AbX5+ft3vU=; b=st+CpcRzUxQKQNqfRMKsktTemgB8QhEal23SvLstIWUCoNtmVFqFHDNC5sM21jWtNY 5XbFnh7H8yhUve/Gr21E7VMBpe7nS65UXDDoI2P4u/+5cHZazDsDaa7y3hEspB4EIk+E FB6YYJ2Z0aud7+6b/0jMUitxvdtKTsp57ZJV+RPh/l6cRz9WXs/7OxEEcKvG62sR+YiI QFX7N1POPlpVAKZg3dRYfmJKqpFxTm3RJKse6cKoZhUn3QDPLsvtmUFIGaChRKzS3W9d 5I1BbRzMD/WlUvYuGWA8SUwEiR8jPXiuqLnfnQXzhojOes7rB1q5EeQPW+3POQPtmBat qYHg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=4w0kFDQh; 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-50722-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50722-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=1; AJvYcCXDLO7DAgcog4QDH4GHHVd1Uo/4onCAER4r0bP3T3aHus7BVvwKl/Zo0clCCW+PRSbmMXhzDTT35LKhdvyZzjKzFq/NVQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id m12-20020a65530c000000b005d54ef5dd07si2303058pgq.161.2024.02.02.15.43.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 15:43:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50722-ouuuleilei=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=4w0kFDQh; 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-50722-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50722-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 9CBCC283103 for ; Fri, 2 Feb 2024 23:42:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BEBBE13248C; Fri, 2 Feb 2024 23:41:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="4w0kFDQh" 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 800CF130AD0 for ; Fri, 2 Feb 2024 23:41:19 +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=1706917281; cv=none; b=ujS+kMvM66pKUbMRrdXLu1COCGa+2RQcSTG/z5rra5QwpitrQ159IZveX68zobm+FBH+4duR+3KsoxmPsp+VRRkuziMsIIrPfgRZ618IfSBZPhpmZQHLpnGWJKn2whjFNMIinau7UWzElbT9Is2BwWMkgIDgfhqcVY9UW0zQV9w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706917281; c=relaxed/simple; bh=vrKD5r788IsBMcWd7p/Y0rFlE9n9DwipYIJHOz74tOw=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=F39gbAn2DDa6VQGl7Ogphkov2BlVzW9Hznv8e0EgWvXjfpNDtW6iIEipmk5q3nunwBg9MjCnhYQYS3rQnOXSVkcSmDpwBdGPQIR+ELtsw0TLAAPh44XgpbPILZBvl90W5MmshmSXhNLQZ70GA1z199vCmAlZYN1ZdDZuMcCvtHg= 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=4w0kFDQh; 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-5ee22efe5eeso45173697b3.3 for ; Fri, 02 Feb 2024 15:41:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706917278; x=1707522078; 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=wr65K6vWppDQ/+c7LXR1fsKtLh163OjTy8d5391wuIk=; b=4w0kFDQhOhQz0WvuFPLIj+zyJzPgZ2QMlZ8lOM2cYWh6Z4Ij6FGdLBiXomLeP0p71c DA/VgJmxdEYjbM45a1wHLR1NS3uNSD1HcXFzNRby4Z5vUmGTVEwz3bkjCY3wUSEr8rQU w+UZk3cT0KO9U80IG7izxhul43cDXV94QRsCXmCZvr8cseO4t7p5445D+s2YJji64eWt cueuLaf1fo3+B/IlixcdhaF2bLIT88OWgL+1Y3HCIQHgPOGZBeO/sEo+ShO/n91sV0DQ EqCSpaIRpEloNRKb8nYA/9DdeiGhuv/gTENpBB+eKYcqnQ7+QmQSUAHTAm+B5zVmzasB MLUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706917278; x=1707522078; 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=wr65K6vWppDQ/+c7LXR1fsKtLh163OjTy8d5391wuIk=; b=Ks2U58cGoNxbM7CzV0tRV44pEeVYHIf9BcZeNOwXNAi1kXyCoqfWTg8K7NtEWxhmPH KQTKVgd3uq5nPk0cOW6aQRFaa2N65x6U/OJfuOo3G80cIxglrcDuN3+wTWG8ZUI6sk4m D/nlOyaWk7Wf5iLpYKtWsQXoh2ed2l4Indn4+Zcj47y4QOeIrzW97uL0nrXCBLjW+cjF lFJvgv9gbiBo/+ZUravHB8nc7e081ykBBbvWKop/7k0x20mBnrbbrvOZvRIcOCfqeZWI F9pnm6zo/HFw88QOzi41NVqVMTTiWie/Bih8+yQzSE500ZuMd+YOrPjKHRGkUbo6K67M kzzA== X-Gm-Message-State: AOJu0Yxy7tJ8R+VTo9PjPOB7jxl/Fj0YCm3aQ4kQQqBCCGPb40IGofzJ MhnrbJD9IH84ys2Y/6Lgy7VsYeo2MrVWAwbbAqQVr8wHiuczy93UYw2gPP/z0pvK9k8NwPV1mYZ tPG968A== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:7732:d863:503:f53d]) (user=irogers job=sendgmr) by 2002:a05:690c:f8d:b0:5ff:b07b:fb83 with SMTP id df13-20020a05690c0f8d00b005ffb07bfb83mr1162438ywb.4.1706917278493; Fri, 02 Feb 2024 15:41:18 -0800 (PST) Date: Fri, 2 Feb 2024 15:40:53 -0800 In-Reply-To: <20240202234057.2085863-1-irogers@google.com> Message-Id: <20240202234057.2085863-5-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240202234057.2085863-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog Subject: [PATCH v3 4/8] perf intel-pt/intel-bts: Switch perf_cpu_map__has_any_cpu_or_is_empty use From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Suzuki K Poulose , Mike Leach , James Clark , Leo Yan , John Garry , Will Deacon , Thomas Gleixner , Darren Hart , Davidlohr Bueso , " =?utf-8?q?Andr=C3=A9_Almeida?= " , Kan Liang , K Prateek Nayak , Sean Christopherson , Paolo Bonzini , Kajol Jain , Athira Rajeev , Andrew Jones , Alexandre Ghiti , Atish Patra , "Steinar H. Gunderson" , Yang Jihong , Yang Li , Changbin Du , Sandipan Das , Ravi Bangoria , Paran Lee , Nick Desaulniers , Huacai Chen , Yanteng Si , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, bpf@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789832604202194732 X-GMAIL-MSGID: 1789832604202194732 Switch perf_cpu_map__has_any_cpu_or_is_empty to perf_cpu_map__is_any_cpu_or_is_empty as a CPU map may contain CPUs as well as the dummy event and perf_cpu_map__is_any_cpu_or_is_empty is a more correct alternative. Signed-off-by: Ian Rogers --- tools/perf/arch/x86/util/intel-bts.c | 4 ++-- tools/perf/arch/x86/util/intel-pt.c | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/perf/arch/x86/util/intel-bts.c b/tools/perf/arch/x86/util/intel-bts.c index af8ae4647585..34696f3d3d5d 100644 --- a/tools/perf/arch/x86/util/intel-bts.c +++ b/tools/perf/arch/x86/util/intel-bts.c @@ -143,7 +143,7 @@ static int intel_bts_recording_options(struct auxtrace_record *itr, if (!opts->full_auxtrace) return 0; - if (opts->full_auxtrace && !perf_cpu_map__has_any_cpu_or_is_empty(cpus)) { + if (opts->full_auxtrace && !perf_cpu_map__is_any_cpu_or_is_empty(cpus)) { pr_err(INTEL_BTS_PMU_NAME " does not support per-cpu recording\n"); return -EINVAL; } @@ -224,7 +224,7 @@ static int intel_bts_recording_options(struct auxtrace_record *itr, * In the case of per-cpu mmaps, we need the CPU on the * AUX event. */ - if (!perf_cpu_map__has_any_cpu_or_is_empty(cpus)) + if (!perf_cpu_map__is_any_cpu_or_is_empty(cpus)) evsel__set_sample_bit(intel_bts_evsel, CPU); } diff --git a/tools/perf/arch/x86/util/intel-pt.c b/tools/perf/arch/x86/util/intel-pt.c index d199619df3ab..6de7e2d21075 100644 --- a/tools/perf/arch/x86/util/intel-pt.c +++ b/tools/perf/arch/x86/util/intel-pt.c @@ -369,7 +369,7 @@ static int intel_pt_info_fill(struct auxtrace_record *itr, ui__warning("Intel Processor Trace: TSC not available\n"); } - per_cpu_mmaps = !perf_cpu_map__has_any_cpu_or_is_empty(session->evlist->core.user_requested_cpus); + per_cpu_mmaps = !perf_cpu_map__is_any_cpu_or_is_empty(session->evlist->core.user_requested_cpus); auxtrace_info->type = PERF_AUXTRACE_INTEL_PT; auxtrace_info->priv[INTEL_PT_PMU_TYPE] = intel_pt_pmu->type; @@ -774,7 +774,7 @@ static int intel_pt_recording_options(struct auxtrace_record *itr, * Per-cpu recording needs sched_switch events to distinguish different * threads. */ - if (have_timing_info && !perf_cpu_map__has_any_cpu_or_is_empty(cpus) && + if (have_timing_info && !perf_cpu_map__is_any_cpu_or_is_empty(cpus) && !record_opts__no_switch_events(opts)) { if (perf_can_record_switch_events()) { bool cpu_wide = !target__none(&opts->target) && @@ -832,7 +832,7 @@ static int intel_pt_recording_options(struct auxtrace_record *itr, * In the case of per-cpu mmaps, we need the CPU on the * AUX event. */ - if (!perf_cpu_map__has_any_cpu_or_is_empty(cpus)) + if (!perf_cpu_map__is_any_cpu_or_is_empty(cpus)) evsel__set_sample_bit(intel_pt_evsel, CPU); } @@ -858,7 +858,7 @@ static int intel_pt_recording_options(struct auxtrace_record *itr, tracking_evsel->immediate = true; /* In per-cpu case, always need the time of mmap events etc */ - if (!perf_cpu_map__has_any_cpu_or_is_empty(cpus)) { + if (!perf_cpu_map__is_any_cpu_or_is_empty(cpus)) { evsel__set_sample_bit(tracking_evsel, TIME); /* And the CPU for switch events */ evsel__set_sample_bit(tracking_evsel, CPU); @@ -870,7 +870,7 @@ static int intel_pt_recording_options(struct auxtrace_record *itr, * Warn the user when we do not have enough information to decode i.e. * per-cpu with no sched_switch (except workload-only). */ - if (!ptr->have_sched_switch && !perf_cpu_map__has_any_cpu_or_is_empty(cpus) && + if (!ptr->have_sched_switch && !perf_cpu_map__is_any_cpu_or_is_empty(cpus) && !target__none(&opts->target) && !intel_pt_evsel->core.attr.exclude_user) ui__warning("Intel Processor Trace decoding will not be possible except for kernel tracing!\n"); From patchwork Fri Feb 2 23:40:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 196087 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp759625dyc; Fri, 2 Feb 2024 15:43:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IHka2HR8FVfK/JauYJekqJP5Wp9mlSdiv/kJbJKT0dsYyvHWcUB3Vem6I/irYyMUqVbDqpe X-Received: by 2002:a05:6a20:89a7:b0:19c:89f4:c2d7 with SMTP id h39-20020a056a2089a700b0019c89f4c2d7mr9839070pzg.34.1706917412564; Fri, 02 Feb 2024 15:43:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706917412; cv=pass; d=google.com; s=arc-20160816; b=l26QbFaiDbl9rSa8qwD9B/tYToqVn0nNOO6g6O8RBOTt0vwz1Xv/vW+Zr7yCMHLLW0 ORT+0+HCnU0Gr0c30zBlJYvs6556ClCBx8NucgiL/l3CzUkDnjCS4Ogo4v2plU65bIMt zJvE+j3f2RQBMh8i/LIZGsLwVWrVs+WNvR/gmIFDK5ZlXPysV7gFG9HFXkMpUkxpmvjl QaSBW2q3QOGvnJXeCCIatmNN+RXwr4cIYFTPMKoz69eAJra8vwJiCaZVZTGa6tY/8Pvi QvZ8vzSTio+L7CSU5S13XORBzD13MhgL6GcFTP0mSo5COqfOTZy9amgvr/v2nNadk1V6 ymBQ== 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=9PKn59qI/eEru2iRWjl8r3A2NQszSA8YlNSVgwlBz0k=; fh=Fv5LLiBa0HxijJiQiZ1z9pKm4SCSwRyirr49Xr/zQCc=; b=miYtR5i2XJbHcrMAGLwNEX74njBFxzN33SzYDNjSXxMsztQY+G+X1TWHuYcO4kraGB Zbmd8cFjUFjDqiow3YGMlTSaMwluqK+o48HDiD08ubq9M1fGh9h0RZbAeBPc1xpRWL+m ST07XTKY5GNeUAq86GEfTasqWQp0L4Sk2q6trvUlCMVHD5oN0YHe7FDL4e0LTnv0R16k 9HYcew3uP7q3O/VuHCVoflW3c6C1KV/JHSmGBP+5v5jaSm8dsPfCrc/CULRuG+a2L94f ciRHzN88pJCu3WauVB8WJCoNtQtB5kCCi3Q8qebhWEfeEXpKCiLTsiHVOpjnb6eqCUIV fbOg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="sMuuW/oA"; 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-50723-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50723-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=1; AJvYcCWct8836aTbmvqk5SRHEjN+Jeo/Uu62T/fX8vvSxilfEoCqQzl3+8WjHlslKCRMq9/Jlc99tSRpJHp7SoxYRfaB2QmDuQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id y18-20020a056a00191200b006db9c48e0bfsi2301510pfi.188.2024.02.02.15.43.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 15:43:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50723-ouuuleilei=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="sMuuW/oA"; 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-50723-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50723-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id A156028469F for ; Fri, 2 Feb 2024 23:43:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 854381332BF; Fri, 2 Feb 2024 23:41:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="sMuuW/oA" 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 C0E53130AF2 for ; Fri, 2 Feb 2024 23:41:21 +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=1706917283; cv=none; b=Drct7RqBXuicnBw7sBcKTNTeakDYm05wYBD8+k071ihzoUGheFMXCk9yZTt6yis6gFYZxN6/RyvGLABT8uHTiN7GlDMjZDt+YXFx6dtADoUGFexqOsMKUqjD3ar+2dyEumgVT8DzhbpZWpX5JedUR/VbWe5Qj9I8lNJygVCwtXM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706917283; c=relaxed/simple; bh=TXC4fY94F4QG3R5rAXB5MKDuVhvys01fhTTOf+9TuDM=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=MjNbVMywgfqJ9LSTHKtNUxeBm0VDZwjh4ocVqygFBJ/htOvHj7Haz8Ac0lPElod0mZsRaGftS8rsnh5uQlJPRUMbn8tYIIWPyNVZGoMFwTedbNxRTGd8+Ka8xWshsj8TMZOK6McG2BFgfjFKlZifjdnRhtD37+xbMdwgo3Vb/h0= 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=sMuuW/oA; 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-dc64f63d768so4754962276.2 for ; Fri, 02 Feb 2024 15:41:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706917281; x=1707522081; 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=9PKn59qI/eEru2iRWjl8r3A2NQszSA8YlNSVgwlBz0k=; b=sMuuW/oAwOEVa93y3Ljf4HwsW9FKQ/j+oHFKLOuY1zE1iGOnRqhmjnRRaE4Z8jwLR3 gEQcjNhVLPW1yyMJWUR9nnCwtNM1m8j9Q6zssgfYlyUWfiC7mEo2LyLETLlD/dU0kqhO ejm/n+48PbiQFl4x9qw9MB73KRCtRZJZ8A8q2kzTUwZr06x7IyiWJPjJAi9XbbssnAYz JmqupUkqXZy52FfPvWgUSeqAddd5T9PmV8fiH8wwTV1VyiQKNaK5hnkd+hEc2tovNRhO ifi4wFsNI43STWImWgqqeBtMCdXi2saFTZ4DT1sEVa4E2GhDd/VzKPWLOOv5bloQu7+o zo9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706917281; x=1707522081; 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=9PKn59qI/eEru2iRWjl8r3A2NQszSA8YlNSVgwlBz0k=; b=e1mTl/WwXSNiAuk5GfFs9CxyUEDciOhnLwcu4xSekOU6KDdyvZ362O4Oacas1NDxxD /+cPuFkGo2Op1+z0IJmjAz85X4vOu+GW1Vktyn/Ylzn/mdGJVjtd5/t7CrypmMT/How8 UqzE4NsQ3BCLr4zUuXHFqqopLr/UbkO/v23P3AzzHODfEFZAfqzkgDAqxMji8jc9NG+2 bNnjAc6Ti5WmcbKkRUv5OlHnVGs0xDntXYTHSIWewHJNlPMOV3JmqgEU7EHIR+0cUxKw NNUPgtALy9W6LJBiGPjSLh9SLLX9u5iICvEeSAVtyXNNQt+TS+215fPDcHi+Pt/VuoYY lVhg== X-Gm-Message-State: AOJu0YyV6SaGw6m9PIPsAJYVtQaOjk9Vhl20FBGUuQ9v48wDly3F5Pmv RFCYF/Ezj/Ax770KAqP8tKzmx9sHZR49MwbqUmnvkjEOIBPOJ3+5StljvlOmU2CSYWdieDrhsAa ROoqFCQ== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:7732:d863:503:f53d]) (user=irogers job=sendgmr) by 2002:a05:6902:2512:b0:dc2:1dd0:c517 with SMTP id dt18-20020a056902251200b00dc21dd0c517mr2454050ybb.7.1706917280766; Fri, 02 Feb 2024 15:41:20 -0800 (PST) Date: Fri, 2 Feb 2024 15:40:54 -0800 In-Reply-To: <20240202234057.2085863-1-irogers@google.com> Message-Id: <20240202234057.2085863-6-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240202234057.2085863-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog Subject: [PATCH v3 5/8] perf cpumap: Clean up use of perf_cpu_map__has_any_cpu_or_is_empty From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Suzuki K Poulose , Mike Leach , James Clark , Leo Yan , John Garry , Will Deacon , Thomas Gleixner , Darren Hart , Davidlohr Bueso , " =?utf-8?q?Andr=C3=A9_Almeida?= " , Kan Liang , K Prateek Nayak , Sean Christopherson , Paolo Bonzini , Kajol Jain , Athira Rajeev , Andrew Jones , Alexandre Ghiti , Atish Patra , "Steinar H. Gunderson" , Yang Jihong , Yang Li , Changbin Du , Sandipan Das , Ravi Bangoria , Paran Lee , Nick Desaulniers , Huacai Chen , Yanteng Si , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, bpf@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789832632641669852 X-GMAIL-MSGID: 1789832632641669852 Most uses of what was perf_cpu_map__empty but is now perf_cpu_map__has_any_cpu_or_is_empty want to do something with the CPU map if it contains CPUs. Replace uses of perf_cpu_map__has_any_cpu_or_is_empty with other helpers so that CPUs within the map can be handled. Signed-off-by: Ian Rogers Reviewed-by: James Clark --- tools/perf/builtin-c2c.c | 6 +----- tools/perf/builtin-stat.c | 9 ++++----- tools/perf/util/auxtrace.c | 4 ++-- tools/perf/util/record.c | 2 +- tools/perf/util/stat.c | 2 +- 5 files changed, 9 insertions(+), 14 deletions(-) diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c index 16b40f5d43db..24107062c43e 100644 --- a/tools/perf/builtin-c2c.c +++ b/tools/perf/builtin-c2c.c @@ -2319,11 +2319,7 @@ static int setup_nodes(struct perf_session *session) nodes[node] = set; - /* empty node, skip */ - if (perf_cpu_map__has_any_cpu_or_is_empty(map)) - continue; - - perf_cpu_map__for_each_cpu(cpu, idx, map) { + perf_cpu_map__for_each_cpu_skip_any(cpu, idx, map) { __set_bit(cpu.cpu, set); if (WARN_ONCE(cpu2node[cpu.cpu] != -1, "node/cpu topology bug")) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 5fe9abc6a524..280eb0c99d2b 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -1317,10 +1317,9 @@ static int cpu__get_cache_id_from_map(struct perf_cpu cpu, char *map) * be the first online CPU in the cache domain else use the * first online CPU of the cache domain as the ID. */ - if (perf_cpu_map__has_any_cpu_or_is_empty(cpu_map)) + id = perf_cpu_map__min(cpu_map).cpu; + if (id == -1) id = cpu.cpu; - else - id = perf_cpu_map__cpu(cpu_map, 0).cpu; /* Free the perf_cpu_map used to find the cache ID */ perf_cpu_map__put(cpu_map); @@ -1623,7 +1622,7 @@ static int perf_stat_init_aggr_mode(void) * taking the highest cpu number to be the size of * the aggregation translate cpumap. */ - if (!perf_cpu_map__has_any_cpu_or_is_empty(evsel_list->core.user_requested_cpus)) + if (!perf_cpu_map__is_any_cpu_or_is_empty(evsel_list->core.user_requested_cpus)) nr = perf_cpu_map__max(evsel_list->core.user_requested_cpus).cpu; else nr = 0; @@ -2290,7 +2289,7 @@ int process_stat_config_event(struct perf_session *session, perf_event__read_stat_config(&stat_config, &event->stat_config); - if (perf_cpu_map__has_any_cpu_or_is_empty(st->cpus)) { + if (perf_cpu_map__is_empty(st->cpus)) { if (st->aggr_mode != AGGR_UNSET) pr_warning("warning: processing task data, aggregation mode not set\n"); } else if (st->aggr_mode != AGGR_UNSET) { diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c index 3684e6009b63..6b1d4bafad59 100644 --- a/tools/perf/util/auxtrace.c +++ b/tools/perf/util/auxtrace.c @@ -174,7 +174,7 @@ void auxtrace_mmap_params__set_idx(struct auxtrace_mmap_params *mp, struct evlist *evlist, struct evsel *evsel, int idx) { - bool per_cpu = !perf_cpu_map__has_any_cpu_or_is_empty(evlist->core.user_requested_cpus); + bool per_cpu = !perf_cpu_map__has_any_cpu(evlist->core.user_requested_cpus); mp->mmap_needed = evsel->needs_auxtrace_mmap; @@ -648,7 +648,7 @@ int auxtrace_parse_snapshot_options(struct auxtrace_record *itr, static int evlist__enable_event_idx(struct evlist *evlist, struct evsel *evsel, int idx) { - bool per_cpu_mmaps = !perf_cpu_map__has_any_cpu_or_is_empty(evlist->core.user_requested_cpus); + bool per_cpu_mmaps = !perf_cpu_map__has_any_cpu(evlist->core.user_requested_cpus); if (per_cpu_mmaps) { struct perf_cpu evlist_cpu = perf_cpu_map__cpu(evlist->core.all_cpus, idx); diff --git a/tools/perf/util/record.c b/tools/perf/util/record.c index 87e817b3cf7e..e867de8ddaaa 100644 --- a/tools/perf/util/record.c +++ b/tools/perf/util/record.c @@ -237,7 +237,7 @@ bool evlist__can_select_event(struct evlist *evlist, const char *str) evsel = evlist__last(temp_evlist); - if (!evlist || perf_cpu_map__has_any_cpu_or_is_empty(evlist->core.user_requested_cpus)) { + if (!evlist || perf_cpu_map__is_any_cpu_or_is_empty(evlist->core.user_requested_cpus)) { struct perf_cpu_map *cpus = perf_cpu_map__new_online_cpus(); if (cpus) diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index b0bcf92f0f9c..0bd5467389e4 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c @@ -315,7 +315,7 @@ static int check_per_pkg(struct evsel *counter, struct perf_counts_values *vals, if (!counter->per_pkg) return 0; - if (perf_cpu_map__has_any_cpu_or_is_empty(cpus)) + if (perf_cpu_map__is_any_cpu_or_is_empty(cpus)) return 0; if (!mask) { From patchwork Fri Feb 2 23:40:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 196090 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp760251dyc; Fri, 2 Feb 2024 15:45:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IHatuezQz9IDsInPmMQl5uzBhPQMZemYQVyaJ2V7uuqT91OCMzISUXZi9dadPNwxuKDubfX X-Received: by 2002:a17:903:2346:b0:1d8:f06a:9d68 with SMTP id c6-20020a170903234600b001d8f06a9d68mr4227055plh.33.1706917545827; Fri, 02 Feb 2024 15:45:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706917545; cv=pass; d=google.com; s=arc-20160816; b=tWMl2ruBehz2wheTZdvDLtO9I2PdNPPneEcdyfvOfwlBhO7/DEhXF1+lD6E7yFmVQa yq37pbsqLb0WnYKOdfH9XOG02NitGgskhAGwIXJNwuGlXSUpgK3JGxUOXsp+R6F/wn62 lvyygijhyHA6vRy6pG9DE+UbTUNhXWxMlgpkBXMlQsviId3exBAlx3Ah835AKzITTytH 5NQydwgMf2osMBo74YueDhTlEbq6mWiXgGM9h+jZJzBD+OBbVWjWhK3iMU1SB/ekydDY smCTD4Vfi6nHb2vLjfeaUeqIfUrG/BO1caIE44imJEgZCUPsdxLXaErJE23KBwO38au4 +S9Q== 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=Jm6+rGnwaR5/dop0r40XD+HXuvjfQ9BLsYsO2f1XDQM=; fh=D+Zjww4qjLt+RAnYIl6Fw4jUDZa96yOrhRRT0tDOMC8=; b=qEUE/6MOt3HGz/j34b3npYgAsMimfebdoZ98ukqeT8LNfPX8BYbSrP2aJolYs52zK9 exDFrTWZW73TnejArg2SdE49tHIZmlAztjlI+FmIdlGyTkotfseT7srMpDBbg6eCKDH5 RPcEPzQayLSpCyfrMGfFtmcKSP5wpVLlrgs8L2qYK5Yao7RZmoGBhDWicdGDwI40p/N3 qYNwtzL476DaczFT9vIcc5zKZL3f/JfCKCggy5yLCvjD/p2F96MWrLUymi59WLlMd+VK aumGPBVnPxKl/vg4Di1T20q4zsmGkVem8NeewfDcL92pIrvHNGl0dYNvlw/+TV8N8woT V2Kw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=xcg4W7LX; 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-50725-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50725-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=1; AJvYcCULpKdXg55hnzSspAtP1Bvoo07xEtCHMYAieAd2085DWYDjmJuWFNdgas5RzZ/8A8Z/HYrXC8kazmGejqeiOtNg49z0bg== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id b18-20020a170903229200b001d4ede7ebf2si2486270plh.563.2024.02.02.15.45.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 15:45:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50725-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=xcg4W7LX; 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-50725-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50725-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 0A727B27A07 for ; Fri, 2 Feb 2024 23:43:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 951EE134CD5; Fri, 2 Feb 2024 23:41:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="xcg4W7LX" Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.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 06493132476 for ; Fri, 2 Feb 2024 23:41:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706917285; cv=none; b=Qn9cUdApkxvUi5OiqCJzivZhteXs2kz+O44AognBn0nw2mNuRAE3SZurFU0CPWzfE62RzxFp6DnWrLXGVc092jnsGOMOCzpq4B1wQLWiK2uWCuakox2ak/FK3l6h+LiQECT7Tzt83bfiUnXzJBZangI18jp5rBuHhcMDXCwZnN8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706917285; c=relaxed/simple; bh=0FiaP31PDhjVbhEu1bCl/SbTIvgKTkMX5fOyfQItO7k=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=cPdlq5ZfeuXRqUfHCzv8JfHd7EOfZ+lADlR10213G1ZLeGPdOOuVZDr7ujuQkcpnOkX10RMVE85sqMgxYd6ZKl4C9VxuCqXgM/LtM5rxaQxwZP7zauu0y9wsRh7IhJTVRo/ZH7aM4ldWDpvQRr/X5Dur/vQOgIhOWZtnLSrs7WM= 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=xcg4W7LX; arc=none smtp.client-ip=209.85.128.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-yw1-f201.google.com with SMTP id 00721157ae682-6041dbb7a78so40617437b3.0 for ; Fri, 02 Feb 2024 15:41:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706917283; x=1707522083; 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=Jm6+rGnwaR5/dop0r40XD+HXuvjfQ9BLsYsO2f1XDQM=; b=xcg4W7LXC/Lm4VGyXDbJWnjemFnNierLSmeKZwGDaq3FvGbLOZhjL6RBHwSmrdg4LN 4J/YBgwjz3bsuDcyhPgpfadd5FHgi9N4n5s/f2wq5JNeVjpZuA6HhlGVvNAmOHG4ss2v 2h6xH4iBi4gCpxIRixZVuXLwUGNIYdeDf9Q7hXNnlDlouj/WdZKoHZhgnuuG8BjnxU7l cASRrINfBVW5Yhob+Ry4VRjch4EP2OdQAI1+4ZrcY+ngfS1xjJXTIYJoAPbevkdWeAqp 1WF1sk3zSgoBMJfV7/jT/PSA4p8XTVayJ+EkOCCyPrY8MWn7L7+u3C9qQilaklEgpf6f g2pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706917283; x=1707522083; 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=Jm6+rGnwaR5/dop0r40XD+HXuvjfQ9BLsYsO2f1XDQM=; b=QgnbzoZwVmE3v63aLuXx07oQLYZI2FuDBPz80uD+FM1HSy9PYpEvM5ODvxpbW/Dvjz sbTG6bIr0WskZrZRNNN5LeyM5xvxQDjlYKOK5oiY598GfZPh1ik70zl0aWQAIU7eOXG9 MHhR5E/SH8N6sDSjD12lVh1ITYZfCtHeelKHnQLtZExYE/qOyhYAr5fQ786xCfau/VYI ejYDFH2NrtyyRvJd64kN6tNpqVy8sRVCTS4aLUsFX5148SmidA2GGrjQzuZ+yZxtmGy8 Y4E7ZpV0ugyhNmigfOpMdseo5SQTk4ecu0skAYSGWye24BTu4VD0DFF3ekSsGfwX9crf jGrA== X-Gm-Message-State: AOJu0YxHkgSDCPMbXHqCMzkHOcnJ42cg+Bay9N6wUjpGB3SwIHS3L0ex yknLSdq6jr9rwS0krHGXz7ME949Xlv+CavYCC4Txmeu8irhVREVokBNohWqylnNq1sEMNHpFjLm KkY4KMg== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:7732:d863:503:f53d]) (user=irogers job=sendgmr) by 2002:a81:994c:0:b0:5ff:dac0:6524 with SMTP id q73-20020a81994c000000b005ffdac06524mr2160038ywg.3.1706917283080; Fri, 02 Feb 2024 15:41:23 -0800 (PST) Date: Fri, 2 Feb 2024 15:40:55 -0800 In-Reply-To: <20240202234057.2085863-1-irogers@google.com> Message-Id: <20240202234057.2085863-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: <20240202234057.2085863-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog Subject: [PATCH v3 6/8] perf arm64 header: Remove unnecessary CPU map get and put From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Suzuki K Poulose , Mike Leach , James Clark , Leo Yan , John Garry , Will Deacon , Thomas Gleixner , Darren Hart , Davidlohr Bueso , " =?utf-8?q?Andr=C3=A9_Almeida?= " , Kan Liang , K Prateek Nayak , Sean Christopherson , Paolo Bonzini , Kajol Jain , Athira Rajeev , Andrew Jones , Alexandre Ghiti , Atish Patra , "Steinar H. Gunderson" , Yang Jihong , Yang Li , Changbin Du , Sandipan Das , Ravi Bangoria , Paran Lee , Nick Desaulniers , Huacai Chen , Yanteng Si , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, bpf@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789832772371686717 X-GMAIL-MSGID: 1789832772371686717 In both cases the CPU map is known owned by either the caller or a PMU. Signed-off-by: Ian Rogers Reviewed-by: James Clark --- tools/perf/arch/arm64/util/header.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/tools/perf/arch/arm64/util/header.c b/tools/perf/arch/arm64/util/header.c index 97037499152e..a9de0b5187dd 100644 --- a/tools/perf/arch/arm64/util/header.c +++ b/tools/perf/arch/arm64/util/header.c @@ -25,8 +25,6 @@ static int _get_cpuid(char *buf, size_t sz, struct perf_cpu_map *cpus) if (!sysfs || sz < MIDR_SIZE) return EINVAL; - cpus = perf_cpu_map__get(cpus); - for (cpu = 0; cpu < perf_cpu_map__nr(cpus); cpu++) { char path[PATH_MAX]; FILE *file; @@ -51,7 +49,6 @@ static int _get_cpuid(char *buf, size_t sz, struct perf_cpu_map *cpus) break; } - perf_cpu_map__put(cpus); return ret; } From patchwork Fri Feb 2 23:40:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 196088 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp759654dyc; Fri, 2 Feb 2024 15:43:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IFtREpzE+TYdSfzuZOM3iQo7nqo3R86ntqfganr4dvUKTMgtI+ieoC3kpOD56XnWpe8GnfN X-Received: by 2002:a05:620a:4d3:b0:784:5e49:e15 with SMTP id 19-20020a05620a04d300b007845e490e15mr8555936qks.19.1706917419623; Fri, 02 Feb 2024 15:43:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706917419; cv=pass; d=google.com; s=arc-20160816; b=OgQnNmnajrF8wda/qIOk5aM4sh3VV2U9SSj23AiEUt8hTzKrr5iXEAEsJYtyYHG1Pj s8WrDVYT/PGrm0rwRumzXg3HyDXtYSZM5TT4mtYfh1hrtOB8a2LE4G6XZGqpM7HiNPCk OfurabjzPA4tXvdB8W1sOH8CdoMQGwHWltMskFmB0zcf5Ti4AOL3euBoopM9FjCitOAg b1xh1iHEI7KXrera0hXCJ6gmJIK4tqHUl9ym7e2SBYhWwmiEgbXTx7NOZz7ngGLreYIO YyxsXapf/gqrKt/YTS4wDJaHxEq346SgLZ99MVIRgXvrGh0EOVMPv2X3niwSQZ1U00cf QMrg== 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=TiTDOvBVexFioWtZi7idM6N1b6RuopqNxCQfkxi6/RE=; fh=ND3/ZuXlr/OXajIRTTNZO38R8SvCsBDvQpmLLY6ycGE=; b=rXA0P47o6/zzhuXIoqiaZU1UkZW2uZva87RHXF0l6df+R2IDlcjoqyxMe7ruI4nVaH TMvPTKDsDynndC8caOblYCDF/F60dhT80xANY+3AfjsgWKSPXlE6sxLI7ACD56IRt/Zm Oy51745FZ5gSrSS/XODatx/GlWJ4phXaNDgUd66GpyCuDfpAoUmFgkfNRqlufO+CkFwc nlcvSq46nW2QPh/1CGVijN0zzdw0p2fAJ7p8H+XkmdSaEHq8pQhYT+070r+qwam73Url jwOAzByxlCT1XfZSu3W53nekbcznJZ7WfuQvJQj3+VRX1zuv/n10E7W11sbYRtz9b8cL V8MA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=rs1AoA1s; 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-50726-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50726-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=1; AJvYcCWDcpBcE5MRnkxFiPD9WGKkvMq856PZ+kuSzHYuDc0tm+dm8kfylehB24fpB8uahBOGMRHGGSHLb4TQ/csc5jnPReri0g== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id v13-20020ae9e30d000000b00783fee83570si3082653qkf.137.2024.02.02.15.43.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 15:43:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50726-ouuuleilei=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=rs1AoA1s; 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-50726-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50726-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 686A81C219E5 for ; Fri, 2 Feb 2024 23:43:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D3618134CEA; Fri, 2 Feb 2024 23:41:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="rs1AoA1s" 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 1FE4A13329F for ; Fri, 2 Feb 2024 23:41:26 +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=1706917287; cv=none; b=u1MK03Mp4v+Ht6Qo3BWw71NxM9RAOFVa5wHAEowuTm+RiFE+6RIshpYdYj9FD8W/tn7ERsvWZ+ueQayUe7jP4Upb2Lg9+AulM7Gn4ke/tgKv2s0dcLE+KJDeb1fqaY0bRr4kmg5jmKWoIHKnEPtGPgx+baY2J9jiqfV2Iavr7Ro= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706917287; c=relaxed/simple; bh=ML8a9VBGcxJuZQepK7vQffZ+xRnwx4f8S25ZVo2Pqug=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=g62YuHiUO8hVo1BUpCe+9fV2ZDyT4PLT7znVbKLtS19lvOTwfwuNRiOLTsojJx1iFjZSVVK5w5miAZ8UE0Wshad/1aqyw8V+0TPZFAWevgoNplnWUCmEoQvfpgbryHl37FjSddCy3Shbrq21rf9z4Idi+IgAyjLRxh7coV9xFYI= 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=rs1AoA1s; 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-603c0e020a6so39111077b3.0 for ; Fri, 02 Feb 2024 15:41:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706917285; x=1707522085; 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=TiTDOvBVexFioWtZi7idM6N1b6RuopqNxCQfkxi6/RE=; b=rs1AoA1sMgUgRfo019U4kngZCVdoq/iho4cU6+aGabvBnBWzaZCvru9y4Sg20/ISzP TnyyjgvBkfR5OdtjfFX4pyHoOJKdhORc9lK7iXe1lCr3YyXBEuGxGp3F4tbonGoN5cAA NVdq4J73jzcpbC9VzgYZ5sluqWEdZWO5HfVB8aDzjPiBd5uF2+nFYSaABd1ZgCyvFdVD 42b4EDJW3JKSDfPanU1ZjL6KbjC7hasxHnCKG3elkFUiOkRvhMW60N+Ta4iRJhO9y8fc 5aGTAlW2H5+469+wYepYDM4j+C+cI6mK3lM5bMH14TXqL4tDITzytRDODjcJFmjs2has M3Aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706917285; x=1707522085; 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=TiTDOvBVexFioWtZi7idM6N1b6RuopqNxCQfkxi6/RE=; b=kB14sIwASZuD5XeGbWBQKcWhHNkwmLT5Kx5GscNSkgdaQY77OOixr9STTt37YyFP1k UjH9jwqUNJKwA5jJNyH4lA/zOeTA+k7rh67tHDkmH5nhropfyAClncUyLHZDFRVI3GTH MjfSaz+4b5yP8TH/ufrM6NBr92sIvsHK91HtoUM5CyfX+fBGKEw5nhfuEUtP6mQYq6pa xfO0nKWivBkZo89zmh52jseDp09YlABI8lJAMGYcNWA22jGF9d8LD/esh17zPjzbar5S MfUqbjzZH+Ux676CO55x3WdEVV5YJwOgva6PVNH2pQVf/l5cO62Fa4inuOdxOMEXYCkC YvEg== X-Gm-Message-State: AOJu0Yzeh82uyLVxRRXAoglML0PTZxOzcESomX/uiQPSpekPz5nasuJ2 Is9WnzKjypHRkVUnGq9JtSRwGntFsOzbNI9QtyS2G4Z6CXOKjG7vEh66nhJJd6l7HxHSK+Z28V1 vFnTOzQ== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:7732:d863:503:f53d]) (user=irogers job=sendgmr) by 2002:a81:9b4b:0:b0:5ff:6041:c17d with SMTP id s72-20020a819b4b000000b005ff6041c17dmr1156128ywg.2.1706917285199; Fri, 02 Feb 2024 15:41:25 -0800 (PST) Date: Fri, 2 Feb 2024 15:40:56 -0800 In-Reply-To: <20240202234057.2085863-1-irogers@google.com> Message-Id: <20240202234057.2085863-8-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240202234057.2085863-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog Subject: [PATCH v3 7/8] perf stat: Remove duplicate cpus_map_matched function From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Suzuki K Poulose , Mike Leach , James Clark , Leo Yan , John Garry , Will Deacon , Thomas Gleixner , Darren Hart , Davidlohr Bueso , " =?utf-8?q?Andr=C3=A9_Almeida?= " , Kan Liang , K Prateek Nayak , Sean Christopherson , Paolo Bonzini , Kajol Jain , Athira Rajeev , Andrew Jones , Alexandre Ghiti , Atish Patra , "Steinar H. Gunderson" , Yang Jihong , Yang Li , Changbin Du , Sandipan Das , Ravi Bangoria , Paran Lee , Nick Desaulniers , Huacai Chen , Yanteng Si , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, bpf@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789832640122856635 X-GMAIL-MSGID: 1789832640122856635 Use libperf's perf_cpu_map__equal that performs the same function. Signed-off-by: Ian Rogers Reviewed-by: James Clark --- tools/perf/builtin-stat.c | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 280eb0c99d2b..d80bad7c73e4 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -164,26 +164,6 @@ static struct perf_stat_config stat_config = { .iostat_run = false, }; -static bool cpus_map_matched(struct evsel *a, struct evsel *b) -{ - if (!a->core.cpus && !b->core.cpus) - return true; - - if (!a->core.cpus || !b->core.cpus) - return false; - - if (perf_cpu_map__nr(a->core.cpus) != perf_cpu_map__nr(b->core.cpus)) - return false; - - for (int i = 0; i < perf_cpu_map__nr(a->core.cpus); i++) { - if (perf_cpu_map__cpu(a->core.cpus, i).cpu != - perf_cpu_map__cpu(b->core.cpus, i).cpu) - return false; - } - - return true; -} - static void evlist__check_cpu_maps(struct evlist *evlist) { struct evsel *evsel, *warned_leader = NULL; @@ -194,7 +174,7 @@ static void evlist__check_cpu_maps(struct evlist *evlist) /* Check that leader matches cpus with each member. */ if (leader == evsel) continue; - if (cpus_map_matched(leader, evsel)) + if (perf_cpu_map__equal(leader->core.cpus, evsel->core.cpus)) continue; /* If there's mismatch disable the group and warn user. */ From patchwork Fri Feb 2 23:40:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 196089 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp759770dyc; Fri, 2 Feb 2024 15:44:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IFGyM+/S2MTIlQ3qnz2/T+U2nqaGpiDIHJj2j6qClBBgTOX5sR17p1f4CsQMRlcskstI5q3 X-Received: by 2002:a05:6358:3426:b0:176:5c13:3cb9 with SMTP id h38-20020a056358342600b001765c133cb9mr3615164rwd.3.1706917444998; Fri, 02 Feb 2024 15:44:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706917444; cv=pass; d=google.com; s=arc-20160816; b=TKqBlushUe3qJhPEwir7LLqiMwhyVBV1LsK7e5x80YV3oaRzX0hN+nqnHiOI0Eq2lx kGFwNmvBbYFyJ0dKiGiiaQh6iHiHrAibM8t8LdfG/J0WGhcyLM/rrbrok5jib05PgyXm GtkYZjN9h1DfrSGw5P5iOXP+buUIf2Pddpv+K9MyKC+SfkbbsiOk8OxUR0axwEctvGb6 Jd/D1RNW/Lo3X1ff5mjyYvEc1u9h7XFRkReg69L8jeDfRZRrHXWPwVncRcj8l5YKdhEv +lLe1BZ+4LFYjY4uCe8XA/0pVKVuCLgSexvj4v4pbxjkzwxMWLYEklf51VJHeLPG2NoB WotQ== 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=oAZu4qV7GRrZlOn2fzXe1/O/dsnDVPHUY/jAFql6qE8=; fh=HB+Qna6ayEoRqMzlZrYvh5f6P6lGuAFnZSOoH9CauDk=; b=hfLehwsPgBsKQn+nq4TduODWSU1IF5Lhx808Q0Cqd2UmPmIPwTt7fv/3xxCUtiq/b9 dIMaikmO8bbF+x/NIbhBaaUKLLb0d7df8DOfWwJnlcangGI1RTvgVMwhXbeMuUSNCNCw XcrxywekByEvbrNx7SXiDw+StCCN0uhCfwijetpNAI9RKnZBdaBgP8Fjk2J4RoJeyZCD JH1LeedfZDriox15+JSPQMgTmDr7gmpd3VCNgQ4G/LTML6iA8YRFPu3i5BecqaKVzewN xtP0XjIvOwbiAu509sRtNLaR30P8/ip5pGx0meJeqjZa1sk67MMFmiXII19JcftyzPg9 YeIw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=DIuNlx0u; 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-50727-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50727-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=1; AJvYcCUYx//0QulJKViZmzpNm6UPEhwERJ+N6hlDO/2wHo9BuX2y0UHVhigftpfsLMF/LYBOAaaoxZRIIgznaKr31zs6Lb1lYA== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id u27-20020a63141b000000b005d8b5584dd8si2302887pgl.802.2024.02.02.15.44.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 15:44:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50727-ouuuleilei=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=DIuNlx0u; 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-50727-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50727-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 2C29628A858 for ; Fri, 2 Feb 2024 23:43:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0DDF312D77B; Fri, 2 Feb 2024 23:41:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="DIuNlx0u" Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.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 BC19312D75D for ; Fri, 2 Feb 2024 23:41:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706917290; cv=none; b=TLmLkCitR8Wro8AsVosm07Ogs7VOVU08XwaRs+ZbyaPxMk6QC7AqP0RXJc7WsQD1O/DLjiZnHhkPBae3OJhZZuKDi7JWue63lJdGs6oB8plY4V+99Va0m0WnUvNl5M2WgJ5uK+4Y4q+G6Lqicr4D0IJDQTpuecklr0kMEOSenxg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706917290; c=relaxed/simple; bh=Pj322BHyXG2gYzt70812aeyUBm7YX+GP878Iql8M7M0=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=SmT5BGC/BCSty2Q0X0xTv4saNPkPE5vh4TpYcBgt26I3BpMbcfX7qDQsipzu2RTWKa+Yd5SWjMJniyCD7oMsbLz/q8IygEvg7VeNI/ue43/Gzlh4Lvon8r5wS+w/oqtbT9JPdanszAKf35L/Qr+ndZW1bQDjje914Xb5z8UMbo8= 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=DIuNlx0u; arc=none smtp.client-ip=209.85.219.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-yb1-f202.google.com with SMTP id 3f1490d57ef6-dbf216080f5so4152676276.1 for ; Fri, 02 Feb 2024 15:41:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706917287; x=1707522087; 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=oAZu4qV7GRrZlOn2fzXe1/O/dsnDVPHUY/jAFql6qE8=; b=DIuNlx0u6wSWGys6ouJSMYxes9hEfYlyXok/OWotLRxVI35LFDYpfJH8coIYc0681B b9NXDeLR2MwM0bjymnAnENA9wDAJIPZ1pXNLfwC9jyhjYcpOXKEr7Zx8c/uXW0f5+yOR WOlNjjAKMX44JyyITWLYLd2jrMM6Cwe8DP/iJgOMPFCGUI4e0YOmmQPEHupBuc+JTlNW R4ltew9kBb8wstgn6E6eZXSGGmSmJyOoMxX9ab3V/XMLI0t4CQ9RziX+aAGsWZXnIJi7 69xRVNVv9to9TYv5c0GRE3SqaEO/jvrCEA3eM3o6gqv5lWvaVpbHXmIJPOMN8AFkgJuJ rVzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706917287; x=1707522087; 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=oAZu4qV7GRrZlOn2fzXe1/O/dsnDVPHUY/jAFql6qE8=; b=ZjXaJy6k8POyne3w1PagUBpMIUDSQO9Fsp3He10L1CZ3D12OmemOOEuozBnhy23Rsz c9K/dlygirWMqFT+8TIwTrmpHfLnyL+DxuJ51oMm99MiFfm0x3/QatPO10z+CMEEQbER /ODjH3nrFNDv8EEdFES0Sxed5ARCo3aLNMucOyLfmETpePqHXzeqnmK+iWDWWiejV7Gd oikHrWzLdie5BljzerowIpLyr6a7uldsgCW8ZuWQl8O64nVa3tbgh5WFMnY8rdSOsFpc u0xQer6LGJftEUybsr8ppN0sZWS85yRpnSy576E+hjOuZjcNm96kesFVMVjqitpiTSMH vaYw== X-Gm-Message-State: AOJu0YwFbQcQfTcNzdWaUIcXdMhxn08m2L0FrpZCg+44aS1Xe7aYOaUF K7AG9L/41ewLLK0a0pUUBhYkWk3tlP9IdGwmdbfTepKZRR6uK4+FHnAAW9wlJAgbo3kG4w7sSWT xTBumrg== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:7732:d863:503:f53d]) (user=irogers job=sendgmr) by 2002:a05:6902:1b90:b0:dc6:de8c:f4fb with SMTP id ei16-20020a0569021b9000b00dc6de8cf4fbmr1026637ybb.9.1706917287710; Fri, 02 Feb 2024 15:41:27 -0800 (PST) Date: Fri, 2 Feb 2024 15:40:57 -0800 In-Reply-To: <20240202234057.2085863-1-irogers@google.com> Message-Id: <20240202234057.2085863-9-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240202234057.2085863-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog Subject: [PATCH v3 8/8] perf cpumap: Use perf_cpu_map__for_each_cpu when possible From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Suzuki K Poulose , Mike Leach , James Clark , Leo Yan , John Garry , Will Deacon , Thomas Gleixner , Darren Hart , Davidlohr Bueso , " =?utf-8?q?Andr=C3=A9_Almeida?= " , Kan Liang , K Prateek Nayak , Sean Christopherson , Paolo Bonzini , Kajol Jain , Athira Rajeev , Andrew Jones , Alexandre Ghiti , Atish Patra , "Steinar H. Gunderson" , Yang Jihong , Yang Li , Changbin Du , Sandipan Das , Ravi Bangoria , Paran Lee , Nick Desaulniers , Huacai Chen , Yanteng Si , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, bpf@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789832666842807178 X-GMAIL-MSGID: 1789832666842807178 Rather than manually iterating the CPU map, use perf_cpu_map__for_each_cpu. When possible tidy local variables. Signed-off-by: Ian Rogers Reviewed-by: James Clark --- tools/perf/arch/arm64/util/header.c | 10 ++-- tools/perf/tests/bitmap.c | 13 +++--- tools/perf/tests/topology.c | 46 +++++++++---------- tools/perf/util/bpf_kwork.c | 16 ++++--- tools/perf/util/bpf_kwork_top.c | 12 ++--- tools/perf/util/cpumap.c | 12 ++--- .../scripting-engines/trace-event-python.c | 12 +++-- tools/perf/util/session.c | 5 +- tools/perf/util/svghelper.c | 20 ++++---- 9 files changed, 72 insertions(+), 74 deletions(-) diff --git a/tools/perf/arch/arm64/util/header.c b/tools/perf/arch/arm64/util/header.c index a9de0b5187dd..741df3614a09 100644 --- a/tools/perf/arch/arm64/util/header.c +++ b/tools/perf/arch/arm64/util/header.c @@ -4,8 +4,6 @@ #include #include #include -#include -#include #include #include #include "debug.h" @@ -19,18 +17,18 @@ static int _get_cpuid(char *buf, size_t sz, struct perf_cpu_map *cpus) { const char *sysfs = sysfs__mountpoint(); - int cpu; - int ret = EINVAL; + struct perf_cpu cpu; + int idx, ret = EINVAL; if (!sysfs || sz < MIDR_SIZE) return EINVAL; - for (cpu = 0; cpu < perf_cpu_map__nr(cpus); cpu++) { + perf_cpu_map__for_each_cpu(cpu, idx, cpus) { char path[PATH_MAX]; FILE *file; scnprintf(path, PATH_MAX, "%s/devices/system/cpu/cpu%d" MIDR, - sysfs, RC_CHK_ACCESS(cpus)->map[cpu].cpu); + sysfs, cpu.cpu); file = fopen(path, "r"); if (!file) { diff --git a/tools/perf/tests/bitmap.c b/tools/perf/tests/bitmap.c index 0173f5402a35..98956e0e0765 100644 --- a/tools/perf/tests/bitmap.c +++ b/tools/perf/tests/bitmap.c @@ -11,18 +11,19 @@ static unsigned long *get_bitmap(const char *str, int nbits) { struct perf_cpu_map *map = perf_cpu_map__new(str); - unsigned long *bm = NULL; - int i; + unsigned long *bm; bm = bitmap_zalloc(nbits); if (map && bm) { - for (i = 0; i < perf_cpu_map__nr(map); i++) - __set_bit(perf_cpu_map__cpu(map, i).cpu, bm); + int i; + struct perf_cpu cpu; + + perf_cpu_map__for_each_cpu(cpu, i, map) + __set_bit(cpu.cpu, bm); } - if (map) - perf_cpu_map__put(map); + perf_cpu_map__put(map); return bm; } diff --git a/tools/perf/tests/topology.c b/tools/perf/tests/topology.c index 2a842f53fbb5..a8cb5ba898ab 100644 --- a/tools/perf/tests/topology.c +++ b/tools/perf/tests/topology.c @@ -68,6 +68,7 @@ static int check_cpu_topology(char *path, struct perf_cpu_map *map) }; int i; struct aggr_cpu_id id; + struct perf_cpu cpu; session = perf_session__new(&data, NULL); TEST_ASSERT_VAL("can't get session", !IS_ERR(session)); @@ -113,8 +114,7 @@ static int check_cpu_topology(char *path, struct perf_cpu_map *map) TEST_ASSERT_VAL("Session header CPU map not set", session->header.env.cpu); for (i = 0; i < session->header.env.nr_cpus_avail; i++) { - struct perf_cpu cpu = { .cpu = i }; - + cpu.cpu = i; if (!perf_cpu_map__has(map, cpu)) continue; pr_debug("CPU %d, core %d, socket %d\n", i, @@ -123,48 +123,48 @@ static int check_cpu_topology(char *path, struct perf_cpu_map *map) } // Test that CPU ID contains socket, die, core and CPU - for (i = 0; i < perf_cpu_map__nr(map); i++) { - id = aggr_cpu_id__cpu(perf_cpu_map__cpu(map, i), NULL); + perf_cpu_map__for_each_cpu(cpu, i, map) { + id = aggr_cpu_id__cpu(cpu, NULL); TEST_ASSERT_VAL("Cpu map - CPU ID doesn't match", - perf_cpu_map__cpu(map, i).cpu == id.cpu.cpu); + cpu.cpu == id.cpu.cpu); TEST_ASSERT_VAL("Cpu map - Core ID doesn't match", - session->header.env.cpu[perf_cpu_map__cpu(map, i).cpu].core_id == id.core); + session->header.env.cpu[cpu.cpu].core_id == id.core); TEST_ASSERT_VAL("Cpu map - Socket ID doesn't match", - session->header.env.cpu[perf_cpu_map__cpu(map, i).cpu].socket_id == + session->header.env.cpu[cpu.cpu].socket_id == id.socket); TEST_ASSERT_VAL("Cpu map - Die ID doesn't match", - session->header.env.cpu[perf_cpu_map__cpu(map, i).cpu].die_id == id.die); + session->header.env.cpu[cpu.cpu].die_id == id.die); TEST_ASSERT_VAL("Cpu map - Node ID is set", id.node == -1); TEST_ASSERT_VAL("Cpu map - Thread IDX is set", id.thread_idx == -1); } // Test that core ID contains socket, die and core - for (i = 0; i < perf_cpu_map__nr(map); i++) { - id = aggr_cpu_id__core(perf_cpu_map__cpu(map, i), NULL); + perf_cpu_map__for_each_cpu(cpu, i, map) { + id = aggr_cpu_id__core(cpu, NULL); TEST_ASSERT_VAL("Core map - Core ID doesn't match", - session->header.env.cpu[perf_cpu_map__cpu(map, i).cpu].core_id == id.core); + session->header.env.cpu[cpu.cpu].core_id == id.core); TEST_ASSERT_VAL("Core map - Socket ID doesn't match", - session->header.env.cpu[perf_cpu_map__cpu(map, i).cpu].socket_id == + session->header.env.cpu[cpu.cpu].socket_id == id.socket); TEST_ASSERT_VAL("Core map - Die ID doesn't match", - session->header.env.cpu[perf_cpu_map__cpu(map, i).cpu].die_id == id.die); + session->header.env.cpu[cpu.cpu].die_id == id.die); TEST_ASSERT_VAL("Core map - Node ID is set", id.node == -1); TEST_ASSERT_VAL("Core map - Thread IDX is set", id.thread_idx == -1); } // Test that die ID contains socket and die - for (i = 0; i < perf_cpu_map__nr(map); i++) { - id = aggr_cpu_id__die(perf_cpu_map__cpu(map, i), NULL); + perf_cpu_map__for_each_cpu(cpu, i, map) { + id = aggr_cpu_id__die(cpu, NULL); TEST_ASSERT_VAL("Die map - Socket ID doesn't match", - session->header.env.cpu[perf_cpu_map__cpu(map, i).cpu].socket_id == + session->header.env.cpu[cpu.cpu].socket_id == id.socket); TEST_ASSERT_VAL("Die map - Die ID doesn't match", - session->header.env.cpu[perf_cpu_map__cpu(map, i).cpu].die_id == id.die); + session->header.env.cpu[cpu.cpu].die_id == id.die); TEST_ASSERT_VAL("Die map - Node ID is set", id.node == -1); TEST_ASSERT_VAL("Die map - Core is set", id.core == -1); @@ -173,10 +173,10 @@ static int check_cpu_topology(char *path, struct perf_cpu_map *map) } // Test that socket ID contains only socket - for (i = 0; i < perf_cpu_map__nr(map); i++) { - id = aggr_cpu_id__socket(perf_cpu_map__cpu(map, i), NULL); + perf_cpu_map__for_each_cpu(cpu, i, map) { + id = aggr_cpu_id__socket(cpu, NULL); TEST_ASSERT_VAL("Socket map - Socket ID doesn't match", - session->header.env.cpu[perf_cpu_map__cpu(map, i).cpu].socket_id == + session->header.env.cpu[cpu.cpu].socket_id == id.socket); TEST_ASSERT_VAL("Socket map - Node ID is set", id.node == -1); @@ -187,10 +187,10 @@ static int check_cpu_topology(char *path, struct perf_cpu_map *map) } // Test that node ID contains only node - for (i = 0; i < perf_cpu_map__nr(map); i++) { - id = aggr_cpu_id__node(perf_cpu_map__cpu(map, i), NULL); + perf_cpu_map__for_each_cpu(cpu, i, map) { + id = aggr_cpu_id__node(cpu, NULL); TEST_ASSERT_VAL("Node map - Node ID doesn't match", - cpu__get_node(perf_cpu_map__cpu(map, i)) == id.node); + cpu__get_node(cpu) == id.node); TEST_ASSERT_VAL("Node map - Socket is set", id.socket == -1); TEST_ASSERT_VAL("Node map - Die ID is set", id.die == -1); TEST_ASSERT_VAL("Node map - Core is set", id.core == -1); diff --git a/tools/perf/util/bpf_kwork.c b/tools/perf/util/bpf_kwork.c index 6eb2c78fd7f4..44f0f708a15d 100644 --- a/tools/perf/util/bpf_kwork.c +++ b/tools/perf/util/bpf_kwork.c @@ -147,12 +147,12 @@ static bool valid_kwork_class_type(enum kwork_class_type type) static int setup_filters(struct perf_kwork *kwork) { - u8 val = 1; - int i, nr_cpus, key, fd; - struct perf_cpu_map *map; - if (kwork->cpu_list != NULL) { - fd = bpf_map__fd(skel->maps.perf_kwork_cpu_filter); + int idx, nr_cpus; + struct perf_cpu_map *map; + struct perf_cpu cpu; + int fd = bpf_map__fd(skel->maps.perf_kwork_cpu_filter); + if (fd < 0) { pr_debug("Invalid cpu filter fd\n"); return -1; @@ -165,8 +165,8 @@ static int setup_filters(struct perf_kwork *kwork) } nr_cpus = libbpf_num_possible_cpus(); - for (i = 0; i < perf_cpu_map__nr(map); i++) { - struct perf_cpu cpu = perf_cpu_map__cpu(map, i); + perf_cpu_map__for_each_cpu(cpu, idx, map) { + u8 val = 1; if (cpu.cpu >= nr_cpus) { perf_cpu_map__put(map); @@ -181,6 +181,8 @@ static int setup_filters(struct perf_kwork *kwork) } if (kwork->profile_name != NULL) { + int key, fd; + if (strlen(kwork->profile_name) >= MAX_KWORKNAME) { pr_err("Requested name filter %s too large, limit to %d\n", kwork->profile_name, MAX_KWORKNAME - 1); diff --git a/tools/perf/util/bpf_kwork_top.c b/tools/perf/util/bpf_kwork_top.c index 035e02272790..22a3b00a1e23 100644 --- a/tools/perf/util/bpf_kwork_top.c +++ b/tools/perf/util/bpf_kwork_top.c @@ -122,11 +122,11 @@ static bool valid_kwork_class_type(enum kwork_class_type type) static int setup_filters(struct perf_kwork *kwork) { - u8 val = 1; - int i, nr_cpus, fd; - struct perf_cpu_map *map; - if (kwork->cpu_list) { + int idx, nr_cpus, fd; + struct perf_cpu_map *map; + struct perf_cpu cpu; + fd = bpf_map__fd(skel->maps.kwork_top_cpu_filter); if (fd < 0) { pr_debug("Invalid cpu filter fd\n"); @@ -140,8 +140,8 @@ static int setup_filters(struct perf_kwork *kwork) } nr_cpus = libbpf_num_possible_cpus(); - for (i = 0; i < perf_cpu_map__nr(map); i++) { - struct perf_cpu cpu = perf_cpu_map__cpu(map, i); + perf_cpu_map__for_each_cpu(cpu, idx, map) { + u8 val = 1; if (cpu.cpu >= nr_cpus) { perf_cpu_map__put(map); diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index 0581ee0fa5f2..e2287187babd 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c @@ -629,10 +629,10 @@ static char hex_char(unsigned char val) size_t cpu_map__snprint_mask(struct perf_cpu_map *map, char *buf, size_t size) { - int i, cpu; + int idx; char *ptr = buf; unsigned char *bitmap; - struct perf_cpu last_cpu = perf_cpu_map__cpu(map, perf_cpu_map__nr(map) - 1); + struct perf_cpu c, last_cpu = perf_cpu_map__max(map); if (buf == NULL) return 0; @@ -643,12 +643,10 @@ size_t cpu_map__snprint_mask(struct perf_cpu_map *map, char *buf, size_t size) return 0; } - for (i = 0; i < perf_cpu_map__nr(map); i++) { - cpu = perf_cpu_map__cpu(map, i).cpu; - bitmap[cpu / 8] |= 1 << (cpu % 8); - } + perf_cpu_map__for_each_cpu(c, idx, map) + bitmap[c.cpu / 8] |= 1 << (c.cpu % 8); - for (cpu = last_cpu.cpu / 4 * 4; cpu >= 0; cpu -= 4) { + for (int cpu = last_cpu.cpu / 4 * 4; cpu >= 0; cpu -= 4) { unsigned char bits = bitmap[cpu / 8]; if (cpu % 8) diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c index 860e1837ba96..8ef0e5ac03c2 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c @@ -1693,13 +1693,15 @@ static void python_process_stat(struct perf_stat_config *config, { struct perf_thread_map *threads = counter->core.threads; struct perf_cpu_map *cpus = counter->core.cpus; - int cpu, thread; - for (thread = 0; thread < perf_thread_map__nr(threads); thread++) { - for (cpu = 0; cpu < perf_cpu_map__nr(cpus); cpu++) { - process_stat(counter, perf_cpu_map__cpu(cpus, cpu), + for (int thread = 0; thread < perf_thread_map__nr(threads); thread++) { + int idx; + struct perf_cpu cpu; + + perf_cpu_map__for_each_cpu(cpu, idx, cpus) { + process_stat(counter, cpu, perf_thread_map__pid(threads, thread), tstamp, - perf_counts(counter->counts, cpu, thread)); + perf_counts(counter->counts, idx, thread)); } } } diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 199d3e8df315..d52b58344dbc 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -2738,6 +2738,7 @@ int perf_session__cpu_bitmap(struct perf_session *session, int i, err = -1; struct perf_cpu_map *map; int nr_cpus = min(session->header.env.nr_cpus_avail, MAX_NR_CPUS); + struct perf_cpu cpu; for (i = 0; i < PERF_TYPE_MAX; ++i) { struct evsel *evsel; @@ -2759,9 +2760,7 @@ int perf_session__cpu_bitmap(struct perf_session *session, return -1; } - for (i = 0; i < perf_cpu_map__nr(map); i++) { - struct perf_cpu cpu = perf_cpu_map__cpu(map, i); - + perf_cpu_map__for_each_cpu(cpu, i, map) { if (cpu.cpu >= nr_cpus) { pr_err("Requested CPU %d too large. " "Consider raising MAX_NR_CPUS\n", cpu.cpu); diff --git a/tools/perf/util/svghelper.c b/tools/perf/util/svghelper.c index 1892e9b6aa7f..2b04f47f4db0 100644 --- a/tools/perf/util/svghelper.c +++ b/tools/perf/util/svghelper.c @@ -725,26 +725,24 @@ static void scan_core_topology(int *map, struct topology *t, int nr_cpus) static int str_to_bitmap(char *s, cpumask_t *b, int nr_cpus) { - int i; - int ret = 0; - struct perf_cpu_map *m; - struct perf_cpu c; + int idx, ret = 0; + struct perf_cpu_map *map; + struct perf_cpu cpu; - m = perf_cpu_map__new(s); - if (!m) + map = perf_cpu_map__new(s); + if (!map) return -1; - for (i = 0; i < perf_cpu_map__nr(m); i++) { - c = perf_cpu_map__cpu(m, i); - if (c.cpu >= nr_cpus) { + perf_cpu_map__for_each_cpu(cpu, idx, map) { + if (cpu.cpu >= nr_cpus) { ret = -1; break; } - __set_bit(c.cpu, cpumask_bits(b)); + __set_bit(cpu.cpu, cpumask_bits(b)); } - perf_cpu_map__put(m); + perf_cpu_map__put(map); return ret; }