From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 12839C433F5 for ; Wed, 30 Mar 2022 20:34:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351012AbiC3UgE (ORCPT ); Wed, 30 Mar 2022 16:36:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351073AbiC3Uf6 (ORCPT ); Wed, 30 Mar 2022 16:35:58 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 149112DCD; Wed, 30 Mar 2022 13:34:08 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id B6C38B81E45; Wed, 30 Mar 2022 20:34:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2BCB6C340EE; Wed, 30 Mar 2022 20:34:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1648672445; bh=hcdqaYSmSK2xXJZLV14LMkx9on5I7W9ImHA2gJ/i8S0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=JWOPoKGznYgqYwkfYqPe8bAxr3mfP5Kly/Cxz8mbCMKB8G7nyc4UVSw5OYo2m4ZyH vO9UTy7wOXOCvzMzw4Am3snOkNnbFurqfvD4Vj+1jAb2vQp9HyvQWOd8Zo93GYAePC d6Qw6HfxG1q9G+4iAv8GSYY/R7AqEVIK/QXG5SNwLNVl37nsgLoaJl9W0mprbj1B6N h6sZYvLqqVL4sXbmOwo4uhTJmQgBT1UzlIz3q6TRwgBRGd1bXri0ZGtoHaXT9lk4yg 6IyhQ5yDgD426wEDldEUkfLoIPoj7z85DrBNhxHvUVEbAxXEdi7dFDdlvLv8v2Y+1Y tLK1VsJdqlwkw== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 7FF5440407; Wed, 30 Mar 2022 17:34:02 -0300 (-03) Date: Wed, 30 Mar 2022 17:34:02 -0300 From: Arnaldo Carvalho de Melo To: Ian Rogers Cc: Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Mathieu Poirier , Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Kajol Jain , James Clark , German Gomez , Adrian Hunter , Riccardo Mancini , Andi Kleen , Alexey Bayduraev , Alexander Antonov , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org, bpf@vger.kernel.org, Stephane Eranian Subject: Re: [PATCH v2 3/6] perf cpumap: Add is_subset function Message-ID: References: <20220328232648.2127340-1-irogers@google.com> <20220328232648.2127340-4-irogers@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220328232648.2127340-4-irogers@google.com> X-Url: http://acmel.wordpress.com Precedence: bulk List-ID: X-Mailing-List: linux-perf-users@vger.kernel.org Em Mon, Mar 28, 2022 at 04:26:45PM -0700, Ian Rogers escreveu: > Returns true if the second argument is a subset of the first. Thanks, applied. - Arnaldo > Signed-off-by: Ian Rogers > --- > tools/lib/perf/cpumap.c | 20 ++++++++++++++++++++ > tools/lib/perf/include/internal/cpumap.h | 1 + > 2 files changed, 21 insertions(+) > > diff --git a/tools/lib/perf/cpumap.c b/tools/lib/perf/cpumap.c > index ee66760f1e63..23701024e0c0 100644 > --- a/tools/lib/perf/cpumap.c > +++ b/tools/lib/perf/cpumap.c > @@ -319,6 +319,26 @@ struct perf_cpu perf_cpu_map__max(struct perf_cpu_map *map) > return map->nr > 0 ? map->map[map->nr - 1] : result; > } > > +/** Is 'b' a subset of 'a'. */ > +bool perf_cpu_map__is_subset(const struct perf_cpu_map *a, const struct perf_cpu_map *b) > +{ > + if (a == b || !b) > + return true; > + if (!a || b->nr > a->nr) > + return false; > + > + for (int i = 0, j = 0; i < a->nr; i++) { > + if (a->map[i].cpu > b->map[j].cpu) > + return false; > + if (a->map[i].cpu == b->map[j].cpu) { > + j++; > + if (j == b->nr) > + return true; > + } > + } > + return false; > +} > + > /* > * Merge two cpumaps > * > diff --git a/tools/lib/perf/include/internal/cpumap.h b/tools/lib/perf/include/internal/cpumap.h > index 1973a18c096b..35dd29642296 100644 > --- a/tools/lib/perf/include/internal/cpumap.h > +++ b/tools/lib/perf/include/internal/cpumap.h > @@ -25,5 +25,6 @@ struct perf_cpu_map { > #endif > > int perf_cpu_map__idx(const struct perf_cpu_map *cpus, struct perf_cpu cpu); > +bool perf_cpu_map__is_subset(const struct perf_cpu_map *a, const struct perf_cpu_map *b); > > #endif /* __LIBPERF_INTERNAL_CPUMAP_H */ > -- > 2.35.1.1021.g381101b075-goog -- - Arnaldo