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 81831C77B7C for ; Sat, 27 May 2023 01:32:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238127AbjE0BcU (ORCPT ); Fri, 26 May 2023 21:32:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231216AbjE0BcS (ORCPT ); Fri, 26 May 2023 21:32:18 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B299DC3; Fri, 26 May 2023 18:32:16 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 3C8FB654DB; Sat, 27 May 2023 01:32:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 103B1C433D2; Sat, 27 May 2023 01:32:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685151135; bh=UWaVRWh97QkaKEW+3Y55uies+J/z/xLzCy793JnQzLs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ayFWnoKZQfFcHXHqX2xr3q6x1Kk9cRXYQN468s3bNVp/yn5Ytmx1rGfKv2ZoFHrdo 7XasElUlyzsv7vLbnax0sJ4srG2cTei178XGz1d1/RC0RqQuU/6nLnVIcICV6SLjoA NSNMnf1Ue522UoF1RVlDYdkDGPNRG28nsCuzfP+vob3ZA6XqvwuvZLeS3u6/Cfgdsg KtVhmSt3Yx6X9yjH7xmuxk7l2v76dEFINH+PQ1VduQW8DSpLdZZlh2/Ihpiq2GJIbM SMSbENaedwJ7YzAn2qJNHQb0jLoUUjUSS2fp0a7OJRQTCogP/BAbXjCTnDbntejMFO hEw1lWYNaurYA== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 99129403B5; Fri, 26 May 2023 22:32:12 -0300 (-03) Date: Fri, 26 May 2023 22:32:12 -0300 From: Arnaldo Carvalho de Melo To: Ian Rogers Cc: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Subject: Re: [PATCH v4 03/35] perf cpumap: Add equal function Message-ID: References: <20230526215410.2435674-1-irogers@google.com> <20230526215410.2435674-4-irogers@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230526215410.2435674-4-irogers@google.com> X-Url: http://acmel.wordpress.com Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Fri, May 26, 2023 at 02:53:38PM -0700, Ian Rogers escreveu: > Equality is a useful property to compare after merging and > intersecting maps. > > Signed-off-by: Ian Rogers > Reviewed-by: Kan Liang > --- > tools/lib/perf/cpumap.c | 21 ++++++++++++++++ > tools/lib/perf/include/perf/cpumap.h | 2 ++ > tools/perf/tests/cpumap.c | 37 ++++++++++++++++++++++++++++ > 3 files changed, 60 insertions(+) > > diff --git a/tools/lib/perf/cpumap.c b/tools/lib/perf/cpumap.c > index d4f3a1a12522..48595a3ad69c 100644 > --- a/tools/lib/perf/cpumap.c > +++ b/tools/lib/perf/cpumap.c > @@ -321,6 +321,27 @@ bool perf_cpu_map__has(const struct perf_cpu_map *cpus, struct perf_cpu cpu) > return perf_cpu_map__idx(cpus, cpu) != -1; > } > > +bool perf_cpu_map__equal(const struct perf_cpu_map *lhs, const struct perf_cpu_map *rhs) > +{ > + int nr; > + > + if (lhs == rhs) > + return true; > + > + if (!lhs || !rhs) > + return false; > + > + nr = perf_cpu_map__nr(lhs); > + if (nr != perf_cpu_map__nr(rhs)) > + return false; > + > + for (int idx = 0; idx < nr; idx++) { > + if (RC_CHK_ACCESS(lhs)->map[idx].cpu != RC_CHK_ACCESS(rhs)->map[idx].cpu) > + return false; Don't we have an accessor to avoid this RC_CHK_ACCESS()-> access? > + } > + return true; > +} > + > 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 0466c4216fbb..d0ae9552f8e2 100644 > --- a/tools/lib/perf/include/perf/cpumap.h > +++ b/tools/lib/perf/include/perf/cpumap.h > @@ -28,6 +28,8 @@ LIBPERF_API int perf_cpu_map__nr(const struct perf_cpu_map *cpus); > LIBPERF_API bool perf_cpu_map__empty(const struct perf_cpu_map *map); > 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, > + const struct perf_cpu_map *rhs); > > #define perf_cpu_map__for_each_cpu(cpu, idx, cpus) \ > for ((idx) = 0, (cpu) = perf_cpu_map__cpu(cpus, idx); \ > diff --git a/tools/perf/tests/cpumap.c b/tools/perf/tests/cpumap.c > index 83805690c209..7730fc2ab40b 100644 > --- a/tools/perf/tests/cpumap.c > +++ b/tools/perf/tests/cpumap.c > @@ -211,11 +211,48 @@ static int test__cpu_map_intersect(struct test_suite *test __maybe_unused, > return ret; > } > > +static int test__cpu_map_equal(struct test_suite *test __maybe_unused, int subtest __maybe_unused) > +{ > + struct perf_cpu_map *any = perf_cpu_map__dummy_new(); > + struct perf_cpu_map *one = perf_cpu_map__new("1"); > + struct perf_cpu_map *two = perf_cpu_map__new("2"); > + struct perf_cpu_map *empty = perf_cpu_map__intersect(one, two); > + struct perf_cpu_map *pair = perf_cpu_map__new("1-2"); > + struct perf_cpu_map *tmp; > + struct perf_cpu_map *maps[] = {empty, any, one, two, pair}; > + > + for (size_t i = 0; i < ARRAY_SIZE(maps); i++) { > + /* Maps equal themself. */ > + TEST_ASSERT_VAL("equal", perf_cpu_map__equal(maps[i], maps[i])); > + for (size_t j = 0; j < ARRAY_SIZE(maps); j++) { > + /* Maps dont't equal each other. */ > + if (i == j) > + continue; > + TEST_ASSERT_VAL("not equal", !perf_cpu_map__equal(maps[i], maps[j])); > + } > + } > + > + /* Maps equal made maps. */ > + tmp = perf_cpu_map__merge(perf_cpu_map__get(one), two); > + TEST_ASSERT_VAL("pair", perf_cpu_map__equal(pair, tmp)); > + perf_cpu_map__put(tmp); > + > + tmp = perf_cpu_map__intersect(pair, one); > + TEST_ASSERT_VAL("one", perf_cpu_map__equal(one, tmp)); > + perf_cpu_map__put(tmp); > + > + for (size_t i = 0; i < ARRAY_SIZE(maps); i++) > + perf_cpu_map__put(maps[i]); > + > + return TEST_OK; > +} > + > static struct test_case tests__cpu_map[] = { > TEST_CASE("Synthesize cpu map", cpu_map_synthesize), > TEST_CASE("Print cpu map", cpu_map_print), > TEST_CASE("Merge cpu map", cpu_map_merge), > TEST_CASE("Intersect cpu map", cpu_map_intersect), > + TEST_CASE("Equal cpu map", cpu_map_equal), > { .name = NULL, } > }; > > -- > 2.41.0.rc0.172.g3f132b7071-goog > -- - Arnaldo 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DAD67C77B7C for ; Sat, 27 May 2023 01:32:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=cDMm3QNgXi3cakx4aRgyVRdQG5eLdOnRNWfm4mmpdKM=; b=cELeZ9sQrAZun/ K8SVQdhoDYBEh7zwuKqsHkBcht6L5jMU03p7k/uc3/c8yXkW129/psU18Q3r+N5W22Ht79PQPKRUr TfjCKhYGnpWmoyglo0VMc6AerEST0inWMwdqzg1WkMKwHZR/W8eWTr9fTL7XaF41mngg578/O1oOr gg8pftlktoUyBBGQLswMFR8ryUI6HFv8oCAejqR6urQoz+m0BGs3iDro8MOZSYgRSgb1UxTPCvCqz mWUP5taeZQqczdFGiB57pN2UDGqv/WMry38sF9Pt3C5aBKyfCUgaSGXoXmMPwMqN4LZ4g0QkyWB45 gUuq8QJAXvgNOTty+zRw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q2inB-004YOJ-0B; Sat, 27 May 2023 01:32:25 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q2in9-004YNy-2K for linux-arm-kernel@bombadil.infradead.org; Sat, 27 May 2023 01:32:23 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=IoLXMLdUtW3pacTmk7j1h7FgqfxQvrfYJ47lUJ23woA=; b=Kv40WNImm5YIosvBo138Q3PE68 DT4GGtbZVj00Pjh36tO0gsse+Q5bOIHE38xzrMkG0Jj/QW67ek0+5/LgMPQTJdzTKYUkyYKC+Qs9+ 3k2ChXdSdGloFBeQAJoeHyrjVICpsTUo7C+zHdwSgNAQX8rVfkKRhj63xTJOhvVonUPGOyj1NAC2W 4tXOG+mTh3B0lke9ILiZtaYs+bcL2t2u22q6lLysXagXHhZGe7PMOb8g5TFvk7gsFFCuFua6pY3kb r78iXTy7O3aku+iT3QU9K69XqDSKV88jGVzNP1fw0bNYZvXC6F2KyfG/qSuBzYB+SFmVl2Ayst0vB 4K/GhOgw==; Received: from [179.97.37.151] (helo=quaco.ghostprotocols.net) by desiato.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1q2in3-007lx8-1X; Sat, 27 May 2023 01:32:20 +0000 Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 99129403B5; Fri, 26 May 2023 22:32:12 -0300 (-03) Date: Fri, 26 May 2023 22:32:12 -0300 From: Arnaldo Carvalho de Melo To: Ian Rogers Cc: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Subject: Re: [PATCH v4 03/35] perf cpumap: Add equal function Message-ID: References: <20230526215410.2435674-1-irogers@google.com> <20230526215410.2435674-4-irogers@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20230526215410.2435674-4-irogers@google.com> X-Url: http://acmel.wordpress.com X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Em Fri, May 26, 2023 at 02:53:38PM -0700, Ian Rogers escreveu: > Equality is a useful property to compare after merging and > intersecting maps. > > Signed-off-by: Ian Rogers > Reviewed-by: Kan Liang > --- > tools/lib/perf/cpumap.c | 21 ++++++++++++++++ > tools/lib/perf/include/perf/cpumap.h | 2 ++ > tools/perf/tests/cpumap.c | 37 ++++++++++++++++++++++++++++ > 3 files changed, 60 insertions(+) > > diff --git a/tools/lib/perf/cpumap.c b/tools/lib/perf/cpumap.c > index d4f3a1a12522..48595a3ad69c 100644 > --- a/tools/lib/perf/cpumap.c > +++ b/tools/lib/perf/cpumap.c > @@ -321,6 +321,27 @@ bool perf_cpu_map__has(const struct perf_cpu_map *cpus, struct perf_cpu cpu) > return perf_cpu_map__idx(cpus, cpu) != -1; > } > > +bool perf_cpu_map__equal(const struct perf_cpu_map *lhs, const struct perf_cpu_map *rhs) > +{ > + int nr; > + > + if (lhs == rhs) > + return true; > + > + if (!lhs || !rhs) > + return false; > + > + nr = perf_cpu_map__nr(lhs); > + if (nr != perf_cpu_map__nr(rhs)) > + return false; > + > + for (int idx = 0; idx < nr; idx++) { > + if (RC_CHK_ACCESS(lhs)->map[idx].cpu != RC_CHK_ACCESS(rhs)->map[idx].cpu) > + return false; Don't we have an accessor to avoid this RC_CHK_ACCESS()-> access? > + } > + return true; > +} > + > 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 0466c4216fbb..d0ae9552f8e2 100644 > --- a/tools/lib/perf/include/perf/cpumap.h > +++ b/tools/lib/perf/include/perf/cpumap.h > @@ -28,6 +28,8 @@ LIBPERF_API int perf_cpu_map__nr(const struct perf_cpu_map *cpus); > LIBPERF_API bool perf_cpu_map__empty(const struct perf_cpu_map *map); > 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, > + const struct perf_cpu_map *rhs); > > #define perf_cpu_map__for_each_cpu(cpu, idx, cpus) \ > for ((idx) = 0, (cpu) = perf_cpu_map__cpu(cpus, idx); \ > diff --git a/tools/perf/tests/cpumap.c b/tools/perf/tests/cpumap.c > index 83805690c209..7730fc2ab40b 100644 > --- a/tools/perf/tests/cpumap.c > +++ b/tools/perf/tests/cpumap.c > @@ -211,11 +211,48 @@ static int test__cpu_map_intersect(struct test_suite *test __maybe_unused, > return ret; > } > > +static int test__cpu_map_equal(struct test_suite *test __maybe_unused, int subtest __maybe_unused) > +{ > + struct perf_cpu_map *any = perf_cpu_map__dummy_new(); > + struct perf_cpu_map *one = perf_cpu_map__new("1"); > + struct perf_cpu_map *two = perf_cpu_map__new("2"); > + struct perf_cpu_map *empty = perf_cpu_map__intersect(one, two); > + struct perf_cpu_map *pair = perf_cpu_map__new("1-2"); > + struct perf_cpu_map *tmp; > + struct perf_cpu_map *maps[] = {empty, any, one, two, pair}; > + > + for (size_t i = 0; i < ARRAY_SIZE(maps); i++) { > + /* Maps equal themself. */ > + TEST_ASSERT_VAL("equal", perf_cpu_map__equal(maps[i], maps[i])); > + for (size_t j = 0; j < ARRAY_SIZE(maps); j++) { > + /* Maps dont't equal each other. */ > + if (i == j) > + continue; > + TEST_ASSERT_VAL("not equal", !perf_cpu_map__equal(maps[i], maps[j])); > + } > + } > + > + /* Maps equal made maps. */ > + tmp = perf_cpu_map__merge(perf_cpu_map__get(one), two); > + TEST_ASSERT_VAL("pair", perf_cpu_map__equal(pair, tmp)); > + perf_cpu_map__put(tmp); > + > + tmp = perf_cpu_map__intersect(pair, one); > + TEST_ASSERT_VAL("one", perf_cpu_map__equal(one, tmp)); > + perf_cpu_map__put(tmp); > + > + for (size_t i = 0; i < ARRAY_SIZE(maps); i++) > + perf_cpu_map__put(maps[i]); > + > + return TEST_OK; > +} > + > static struct test_case tests__cpu_map[] = { > TEST_CASE("Synthesize cpu map", cpu_map_synthesize), > TEST_CASE("Print cpu map", cpu_map_print), > TEST_CASE("Merge cpu map", cpu_map_merge), > TEST_CASE("Intersect cpu map", cpu_map_intersect), > + TEST_CASE("Equal cpu map", cpu_map_equal), > { .name = NULL, } > }; > > -- > 2.41.0.rc0.172.g3f132b7071-goog > -- - Arnaldo _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel