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 X-Spam-Level: X-Spam-Status: No, score=-8.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8CF9EC2D0A8 for ; Wed, 23 Sep 2020 20:20:36 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 17FBC206D9 for ; Wed, 23 Sep 2020 20:20:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="xx+V1oPz"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="DgXO4YwW" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 17FBC206D9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject: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=a7ivzV1MISU/NpflWo25U3VvIsmIgzFTox9wHGSmmVs=; b=xx+V1oPziUQMl1nsmed73Yzxs bBe2NlqhYHlhFvE6GTNzkko/4QjPVQ9ZzC2dOmnw2btD54x0QosnRYNaXzC8ZgHh6x7elRiSOEZU6 dkyOkUQz92J1pgW09l2d2VGNGhoZ/7M47qqphpGzUTmJ3Q/g9KJyVGL0IGyzbJPXFZ66lMVzpZKfS 4n0tsQdPZVzy/JcBgcfSUn8SY6GN9ho5htfpdiwNP107YynxWVTp1RZZqx0duMJDVtpY/nF+hGtgo Vzagm07WiXg9zmzf4GDX8RuuH4UdFxgzF7rRlDcgw5SEsr5uW2I3BuzoCN1zcqNNLBjC/E41Nu/jq CDnmlXCSA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kLBES-0003Z4-2F; Wed, 23 Sep 2020 20:19:16 +0000 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kLBEP-0003YD-Pq for linux-arm-kernel@lists.infradead.org; Wed, 23 Sep 2020 20:19:14 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600892353; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=DHTSvTADLG6e+v7rV8YcXc8m4s3QJCzEI+irlAKTENE=; b=DgXO4YwWtcqEn0RraqKagFWA1oIBRsf4V2Gn5j154I4xvE5ylHOnJxoVCDZMZ5bhsuOMak evYEKJQgW+uPcbKji21fYOAvI4IAFs1V4G4+VWpXqjWofDFwhxyeTK+/hwGn4Bf9hiMn6K UFo5aPErpTKPnP+/8+xP2E/rlLsf2/A= 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-538-HFmRnXl8No-YwcZFXE-1Mw-1; Wed, 23 Sep 2020 16:19:08 -0400 X-MC-Unique: HFmRnXl8No-YwcZFXE-1Mw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A0F061007B1D; Wed, 23 Sep 2020 20:19:06 +0000 (UTC) Received: from krava (ovpn-112-117.ams2.redhat.com [10.36.112.117]) by smtp.corp.redhat.com (Postfix) with SMTP id 8A79960BF1; Wed, 23 Sep 2020 20:19:01 +0000 (UTC) Date: Wed, 23 Sep 2020 22:19:00 +0200 From: Jiri Olsa To: Namhyung Kim Subject: Re: [PATCH 1/2] perf stat: Fix segfault when counting armv8_pmu events Message-ID: <20200923201900.GQ2893484@krava> References: <20200922031346.15051-1-liwei391@huawei.com> <20200922031346.15051-2-liwei391@huawei.com> <20200923054426.GG2893484@krava> <20200923140747.GN2893484@krava> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200923_161913_874275_5F5AABAC X-CRM114-Status: GOOD ( 30.48 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Andi Kleen , Alexander Shishkin , Alexey Budankov , Adrian Hunter , Arnaldo Carvalho de Melo , linux-kernel , Peter Zijlstra , Andi Kleen , Li Bin , Wei Li , Ingo Molnar , linux-arm-kernel@lists.infradead.org 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 On Wed, Sep 23, 2020 at 11:15:06PM +0900, Namhyung Kim wrote: > On Wed, Sep 23, 2020 at 11:08 PM Jiri Olsa wrote: > > > > On Wed, Sep 23, 2020 at 10:49:52PM +0900, Namhyung Kim wrote: > > > On Wed, Sep 23, 2020 at 2:44 PM Jiri Olsa wrote: > > > > > > > > On Tue, Sep 22, 2020 at 11:13:45AM +0800, Wei Li wrote: > > > > > When executing perf stat with armv8_pmu events with a workload, it will > > > > > report a segfault as result. > > > > > > > > please share the perf stat command line you see that segfault for > > > > > > It seems the description in the patch 0/2 already has it: > > > > > > [root@localhost hulk]# tools/perf/perf stat -e > > > armv8_pmuv3_0/ll_cache_rd/,armv8_pmuv3_0/ll_cache_miss_rd/ ls > > > > /dev/null > > > Segmentation fault > > > > yea I found it, but can't reproduce it.. I see the issue from > > patch 2, but not sure what's the problem so far > > I think the problem is that armv8_pmu has a cpumask, > and the user requested per-task events. > > The code tried to open the event with a dummy cpu map > since it's not a cpu event, but the pmu has cpu map and > it's passed to evsel. So there's confusion somewhere > whether it should use evsel->cpus or a dummy map. you're right, I have following cpus file in pmu: # cat /sys/devices/armv8_pmuv3_0/cpus 0-3 covering all the cpus.. and once you have cpumask/cpus file, you're system wide by default in current code, but we should not crash ;-) I tried to cover this case in patch below and I probably broke some other use cases, but perhaps we could allow to open counters per cpus for given workload I'll try to look at this more tomorrow jirka --- diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 7f8d756d9408..0c7f16a673c2 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -379,12 +379,7 @@ static int read_affinity_counters(struct timespec *rs) if (affinity__setup(&affinity) < 0) return -1; - ncpus = perf_cpu_map__nr(evsel_list->core.all_cpus); - if (!target__has_cpu(&target) || target__has_per_thread(&target)) - ncpus = 1; evlist__for_each_cpu(evsel_list, i, cpu) { - if (i >= ncpus) - break; affinity__set(&affinity, cpu); evlist__for_each_entry(evsel_list, counter) { diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index fd865002cbbd..ef525eb2f619 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1861,6 +1861,16 @@ void evsel__close(struct evsel *evsel) perf_evsel__free_id(&evsel->core); } +int evsel__open_threads_per_cpu(struct evsel *evsel, struct perf_thread_map *threads, + struct perf_cpu_map *cpus, int cpu) +{ + if (cpu == -1) + return evsel__open_cpu(evsel, cpus, threads, 0, + cpus ? cpus->nr : 1); + + return evsel__open_cpu(evsel, cpus, threads, cpu, cpu + 1); +} + int evsel__open_per_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, int cpu) { if (cpu == -1) diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 35e3f6d66085..1d055699bd1f 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -231,6 +231,8 @@ int evsel__enable(struct evsel *evsel); int evsel__disable(struct evsel *evsel); int evsel__disable_cpu(struct evsel *evsel, int cpu); +int evsel__open_threads_per_cpu(struct evsel *evsel, struct perf_thread_map *threads, + struct perf_cpu_map *cpus, int cpu); int evsel__open_per_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, int cpu); int evsel__open_per_thread(struct evsel *evsel, struct perf_thread_map *threads); int evsel__open(struct evsel *evsel, struct perf_cpu_map *cpus, diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index cdb154381a87..2b17f1315cfb 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c @@ -560,6 +560,11 @@ int create_perf_stat_counter(struct evsel *evsel, attr->enable_on_exec = 1; } + if (evsel->core.own_cpus && evsel->core.threads) { + return evsel__open_threads_per_cpu(evsel, evsel->core.threads, + evsel__cpus(evsel), cpu); + } + if (target__has_cpu(target) && !target__has_per_thread(target)) return evsel__open_per_cpu(evsel, evsel__cpus(evsel), cpu); _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel