Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp2127673ybm; Sun, 31 May 2020 09:25:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyML373K1k1mfDEl6vKVu35BHrUhqA1haHHGbqaK+WqWz1XmX4fvGq5awv8rpBHzb7zJ4nv X-Received: by 2002:a17:906:7c82:: with SMTP id w2mr15343839ejo.296.1590942358997; Sun, 31 May 2020 09:25:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590942358; cv=none; d=google.com; s=arc-20160816; b=tfvHUl916DGu6f9d7HdDiFSHIIJjVtwcuN4K5xKtvz93+fSHQDm9nKbdK2AKBCLuN3 cLO61FrHu2CWgV1VF//kAIbglRz2kiWG3zNwejBW2Ky4RdLZfQa/TdWdFv4rjtR7eI5K xucZ88uVp8DdY2gL5LHfqos98NY6gVCb/5czvrKkcnn4TS2JItjs45wP7g6wrL6g8ERt ZCwSlwBS5Q2I6s/1pE7ukoEPB2mT2k9JNtHXGDV8a1/DQBMNf5JsQ3N7lMWt7wBxaG/q 3wmxY1w4oUkRErkSPI+97hwQCDleVEf5jsaEm4pvKu9X5uhvhsH0AGJdR3gzmbHD9t+y I6KA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=dGDSf1qt9d38mw00XfuhAMQVrUFQgzYTRivF5aK8ujg=; b=OYyYtX0eYwhG+/gE/gRMWrtGP39WWZ3irwWsf8l1TNB+TSfUk59RwnMDdVsmrhufn3 rb0arPEdtxkX0vJ7Pc+g1YxVixHMbbOwqxxA+gA+TkucLdnCxDorPB9asoODIVgLaIxD w5lLQk3vOMwrudw6MJqwIK2Btka0y4+iAzotf+yXgstuO8nvITIWWrCEvvZDwEAtnapA Q5WSCvKrS8T5rmsdJVjpPbakcuNcPrX1neDqS8FOPdfBid4CTM9/++DnZ6hp14Pm5Umn aWrh7R1llBYFAvdciwxVp4iQhsTq7klOaJyIOvN/G36CVdtmgXYR/HuWT0j5GmiSOEq0 lSIQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i5si9090119edq.575.2020.05.31.09.25.35; Sun, 31 May 2020 09:25:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728197AbgEaQWS convert rfc822-to-8bit (ORCPT + 99 others); Sun, 31 May 2020 12:22:18 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:33002 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725912AbgEaQWS (ORCPT ); Sun, 31 May 2020 12:22:18 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-470-o2qZ29xAMOC3rPJ6htNU7Q-1; Sun, 31 May 2020 12:22:11 -0400 X-MC-Unique: o2qZ29xAMOC3rPJ6htNU7Q-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9A94A1800D42; Sun, 31 May 2020 16:22:09 +0000 (UTC) Received: from krava.redhat.com (unknown [10.40.192.36]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0CD54768DE; Sun, 31 May 2020 16:22:06 +0000 (UTC) From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: Jin Yao , lkml , Ingo Molnar , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Michael Petlan , Ian Rogers , Stephane Eranian , Andi Kleen Subject: [PATCH] perf stat: Ensure group is defined on top of the same cpu mask Date: Sun, 31 May 2020 18:22:06 +0200 Message-Id: <20200531162206.911168-1-jolsa@kernel.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kernel.org Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Jin Yao reported the issue (and posted first versions of this change) with groups being defined over events with different cpu mask. This causes assert aborts in get_group_fd, like: # perf stat -M "C2_Pkg_Residency" -a -- sleep 1 perf: util/evsel.c:1464: get_group_fd: Assertion `!(fd == -1)' failed. Aborted All the events in the group have to be defined over the same cpus so the group_fd can be found for every leader/member pair. Adding check to ensure this condition is met and removing the group (with warning) if we detect mixed cpus, like: $ sudo perf stat -e '{power/energy-cores/,cycles},{instructions,power/energy-cores/}' WARNING: event cpu maps do not match, disabling group: anon group { power/energy-cores/, cycles } anon group { instructions, power/energy-cores/ } Fixes: 6a4bb04caacc8 ("perf tools: Enable grouping logic for parsed events") Co-developed-by: Jin Yao Signed-off-by: Jin Yao Signed-off-by: Jiri Olsa --- tools/perf/builtin-stat.c | 51 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index b2b79aa161dd..512a41363d07 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -190,6 +190,55 @@ static struct perf_stat_config stat_config = { .big_num = true, }; +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 (a->core.cpus->nr != b->core.cpus->nr) + return false; + + for (int i = 0; i < a->core.cpus->nr; i++) { + if (a->core.cpus->map[i] != b->core.cpus->map[i]) + return false; + } + + return true; +} + +static void evlist__check_cpu_maps(struct evlist *evlist) +{ + struct evsel *evsel, *pos, *leader; + char buf[1024]; + + evlist__for_each_entry(evlist, evsel) { + leader = evsel->leader; + + /* Check that leader matches cpus with each member. */ + if (leader == evsel) + continue; + if (cpus_map_matched(leader, evsel)) + continue; + + /* + * If there's mismatch display dismantle the + * group and warn user. + */ + WARN_ONCE(1, "WARNING: group events cpu maps do not match, disabling group:\n"); + evsel__group_desc(leader, buf, sizeof(buf)); + pr_warning(" %s\n", buf); + + for_each_group_evsel(pos, leader) { + pos->leader = pos; + pos->core.nr_members = 0; + } + evsel->leader->core.nr_members = 0; + } +} + static inline void diff_timespec(struct timespec *r, struct timespec *a, struct timespec *b) { @@ -1962,6 +2011,8 @@ int cmd_stat(int argc, const char **argv) } else if (argc && !strncmp(argv[0], "rep", 3)) return __cmd_report(argc, argv); + evlist__check_cpu_maps(evsel_list); + interval = stat_config.interval; timeout = stat_config.timeout; -- 2.25.4