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 B477AC433EF for ; Wed, 4 May 2022 12:54:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245656AbiEDM6L (ORCPT ); Wed, 4 May 2022 08:58:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236375AbiEDM6K (ORCPT ); Wed, 4 May 2022 08:58:10 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F404A366AE; Wed, 4 May 2022 05:54:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1651668874; x=1683204874; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=bQ57GLyAXmlEPnkviPyQ4B4ZK2mKn3I6U9V+wT1S18I=; b=h4P3ZnVYROlQqldqLLmiWgyL83UAE1dhV9fl4IssSqeCGRWuoBX0vviU symRqfYE1dRz8VOFi5c6/fpNQviQ9ZVhVjh2vm9/kXz5F3NLEvGnXe/zv pD3HZY8S9tbbuBP6/Ze7oGBQT/yaFkwyN0qUL6QZtEJYliEhQDS8J0RM6 GFRLFsJIOd5yIlhAcBm9Au4h4d9KkvTH/YyQyWJCqdQno7OeCzOFSWo4k FojcdtkS44xzR3kJedlqIzaAAJaCYzpJzl9hOxaprqr9wYgWa9Oaq7OG2 jK41VSdTbgxZusJTfZpVOYkrblvI4g5/P+BpiI8ZmPznvI1ulgmCARVtc g==; X-IronPort-AV: E=McAfee;i="6400,9594,10336"; a="354193849" X-IronPort-AV: E=Sophos;i="5.91,198,1647327600"; d="scan'208";a="354193849" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2022 05:54:31 -0700 X-IronPort-AV: E=Sophos;i="5.91,198,1647327600"; d="scan'208";a="584721396" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO [10.0.2.15]) ([10.252.32.90]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2022 05:54:22 -0700 Message-ID: <1e13c738-3460-ef7f-8b4b-5169e16b0b06@intel.com> Date: Wed, 4 May 2022 15:54:17 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Firefox/91.0 Thunderbird/91.8.1 Subject: Re: [PATCH v5 4/6] perf cpumap: Handle dummy maps as empty in subset Content-Language: en-US To: Ian Rogers Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , 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 , Riccardo Mancini , Andi Kleen , Alexey Bayduraev , Alexander Antonov , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Stephane Eranian References: <20220503041757.2365696-1-irogers@google.com> <20220503041757.2365696-5-irogers@google.com> From: Adrian Hunter Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-perf-users@vger.kernel.org On 3/05/22 17:03, Ian Rogers wrote: > On Tue, May 3, 2022 at 12:43 AM Adrian Hunter wrote: >> >> On 3/05/22 07:17, Ian Rogers wrote: >>> perf_cpu_map__empty is true for empty and dummy maps. Make is_subset >>> respect that. >> >> As I wrote before, I am not keen on this because it prevents -1, as a >> valid 3rd parameter to perf_event_open(), from being represented >> in merged evsel cpu maps. >> >> Why do you want this? > > Thanks Adrian, could you give me a test case (command line) where the > differing dummy and empty behavior matters? perf record --per-thread -e intel_pt// uname With patchset "perf intel-pt: Better support for perf record --cpu" the above will have (assuming 8-CPUs): user_requested_cpus = {-1} intel_pt evsel->cpus = {-1} text_poke dummy evsel->cpus = {0-7} which when merged would result in: before this patch: all_cpus = {-1-7} after this patch: all_cpus = {0-7} The absence of -1 will mean that the intel_pt event does not get mmapped. > Normally cpus/own_cpus are > set to null during parsing. They may get replaced with > user_requested_cpus: > https://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git/tree/tools/lib/perf/evlist.c?h=perf/core#n44 > https://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git/tree/tools/lib/perf/evlist.c?h=perf/core#n45 > (should it be on line 45 that !empty is expected?) > > During merge the null/empty all_cpus drops this value, which doesn't > matter as the behavior with empty is the same as dummy: > https://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git/tree/tools/lib/perf/evsel.c?h=perf/core#n119 > > What's concerning me is the definition of empty: > https://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git/tree/tools/lib/perf/cpumap.c?h=perf/core#n279 > ``` > return map ? map->map[0].cpu == -1 : true; > ``` > If the first entry can be -1 and there can be other CPUs merged after > then that cpu map will be empty by the definition above. Perhaps it > should be: > ``` > return map ? (map->nr == 1 && map->map[0].cpu == -1) : true; > ``` > but it seems you prefer: > ``` > return (map == NULL) ? true : false; > ``` > > You'd asked what the behavior with a dummy is and clearly it is > somewhat muddy. That is what this patch and unit test is trying to > clean up. > > Thanks, > Ian > >>> >>> Signed-off-by: Ian Rogers >>> --- >>> tools/lib/perf/cpumap.c | 4 ++-- >>> tools/perf/tests/cpumap.c | 10 +++++++++- >>> 2 files changed, 11 insertions(+), 3 deletions(-) >>> >>> diff --git a/tools/lib/perf/cpumap.c b/tools/lib/perf/cpumap.c >>> index 384d5e076ee4..9c83675788c2 100644 >>> --- a/tools/lib/perf/cpumap.c >>> +++ b/tools/lib/perf/cpumap.c >>> @@ -322,9 +322,9 @@ struct perf_cpu perf_cpu_map__max(struct perf_cpu_map *map) >>> /** 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) >>> + if (a == b || perf_cpu_map__empty(b)) >>> return true; >>> - if (!a || b->nr > a->nr) >>> + if (perf_cpu_map__empty(a) || b->nr > a->nr) >>> return false; >>> >>> for (int i = 0, j = 0; i < a->nr; i++) { >>> diff --git a/tools/perf/tests/cpumap.c b/tools/perf/tests/cpumap.c >>> index f94929ebb54b..d52b58395385 100644 >>> --- a/tools/perf/tests/cpumap.c >>> +++ b/tools/perf/tests/cpumap.c >>> @@ -128,13 +128,21 @@ static int test__cpu_map_merge(struct test_suite *test __maybe_unused, int subte >>> struct perf_cpu_map *a = perf_cpu_map__new("4,2,1"); >>> struct perf_cpu_map *b = perf_cpu_map__new("4,5,7"); >>> struct perf_cpu_map *c = perf_cpu_map__merge(a, b); >>> + struct perf_cpu_map *d = perf_cpu_map__dummy_new(); >>> + struct perf_cpu_map *e = perf_cpu_map__merge(b, d); >>> char buf[100]; >>> >>> TEST_ASSERT_VAL("failed to merge map: bad nr", perf_cpu_map__nr(c) == 5); >>> cpu_map__snprint(c, buf, sizeof(buf)); >>> TEST_ASSERT_VAL("failed to merge map: bad result", !strcmp(buf, "1-2,4-5,7")); >>> - perf_cpu_map__put(b); >>> + >>> + TEST_ASSERT_VAL("failed to merge map: bad nr", perf_cpu_map__nr(e) == 3); >>> + cpu_map__snprint(e, buf, sizeof(buf)); >>> + TEST_ASSERT_VAL("failed to merge map: bad result", !strcmp(buf, "4-5,7")); >>> + >>> perf_cpu_map__put(c); >>> + perf_cpu_map__put(d); >>> + perf_cpu_map__put(e); >>> return 0; >>> } >>> >>