Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp1143199rdb; Fri, 2 Feb 2024 15:41:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IFhCduFWN61bxhUmMg4xyHJhFmktvKaaufHvfewbPpnJUdcSD/xRpaPSae4tB2WpY1e+VAx X-Received: by 2002:a05:6a20:c906:b0:19c:a465:a32e with SMTP id gx6-20020a056a20c90600b0019ca465a32emr8288611pzb.48.1706917296063; Fri, 02 Feb 2024 15:41:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706917296; cv=pass; d=google.com; s=arc-20160816; b=uKW8rg3q9aMKwysQeBISDgimwdXVDQe9HOIbf4LCeKxM9hsUXV6ccjHvqqWVxmx0K2 0oyc2aiZrqPNRyYP9ZQs88ucD/lB4sjOrcMiShCgo7Uqth0AUBAoPjZth6bVtIrbkqBB wxajrtxFUCTfaITYzpsIFa+XleXAuc2fIPiDsIZijQCW18GdSGB/9p/Oa17sG54pHstT VTftv+8uYZpiDgog8Mj4oUvXpN5fa/inaL9v/k6iKYZPBZ/puyxCDwiPPhJ+LAeZqxNZ VEIzCplJ3BfeizLgvclA1m5/DzHx/vISAdlorW9UStx6EPzgW9CQaQKcG2k2JpuKASfv FG+g== 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=6M1tEFgzLUItx5n2QZK1NBu0HQIVQrcdIcQwWus0QEo=; b=IcZjR2CmTdI739MEGDfp8a5DlIzHksLdxI6oO9+XlARoHrpYerj3stCe0xoNw4JS2/ Arvr9hSRm2fkB7RW0uSfTwvbrU+osQYv3+lo3cCrJmv4UcA2nyNurwE0/wyhL+SximS7 95TRJw5DXQvL1lK5/TB3VN/reSZr37Y76hVp/XyBEq0WnPfe/AK3BoK0tyIR8KGMUFVj 5n4H9S5XhuSkR4yOQHMdlkqj6/JBE7x+VtTGA23hTxJdJ/CiToyEUMTOpwavPfthGcuZ lc/K3KQHqYydJSsmHPc4ILgbyj+Lj9YZMlqPcZLPQfxQ6LkdPr/OmIzIe9WG/rCVH/KK TLpw==; 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-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50719-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=1; AJvYcCWEVc7Ri77U+vXmabDzpcr/jUei1HfOe4DDjpD9a+thEb2KM7TzkKiIQTmUshq2Xuip5FgfTBiCRR8g9DjtgDqAT+Bq1uTSeMkVLA+Atg== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id i1-20020a62c101000000b006dab362d29fsi2229407pfg.215.2024.02.02.15.41.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 15:41:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50719-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=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-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50719-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id B188528BD18 for ; Fri, 2 Feb 2024 23:41:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 77ABE12F364; Fri, 2 Feb 2024 23:41:15 +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=20Almeida?=" , 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 Content-Type: text/plain; charset="UTF-8" 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; -- 2.43.0.594.gd9cf4e227d-goog