Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3540551ybz; Mon, 20 Apr 2020 04:59:12 -0700 (PDT) X-Google-Smtp-Source: APiQypI6RLGsYLiUHB5hetCZUzEBx11y3Lq6TzO1Xm54CB+ElI215Vd5HJg83tOPaLXl53SLytOZ X-Received: by 2002:a50:c389:: with SMTP id h9mr14067941edf.1.1587383952647; Mon, 20 Apr 2020 04:59:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587383952; cv=none; d=google.com; s=arc-20160816; b=aw2d9q7IpvaLl1OcO+sI+oqDXyVJQTNqFP/dTKfAg0T7nMT1qM36vzRwNHR2AyPtu7 p48+RpSQWCa0OxznmUyOnWbi1skTQFCtdg9OHaGwy6AsyMK3FslXlKvsSu5Lvix1oYhZ ZLcx8nJ5jCw9H5LU4+g/wMX13QbdslEJGTrKyYKcrWIcELnetpcWNQAHtiauDhpfirEs ynXV0ZesNY5fvL8BWf0ZFi73FoSnCl/5G/aeVBkhwd5WPd7yI71ZvjuuFMEH+kkQWVIo Iz2NTYSg2t8NbC+5/tCPG/udtrjI/lUqYEsVsTsRx3jD/n1Qzj3H+7fMQeHVVWJ6qVmj lv3Q== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=faEZIp3qDDCKdBcChtTNlid+OccGXpahkmppNQLAOXQ=; b=HqldxZmjZcQBiRQco7p8Vieq7Jn/C8yFG7ImDpT00idhoapZXs/HPP/gguRKe47kSo o6QP1XNjjmGoXPH3xdj3HJ3aBOY74lAAjVGYMK+BGdenx2hjdq2fIkhjZzrSOfptybPP rlu/UPaP6Vj3CXLrYgEI7VMFK+2cy30nHMhnNgAlxSMHjN3VG8xyWaQHP7XQkdgbhLO1 Kk6RgqRZra4glPwnGQlch5t3sj8pEpTeF1MA8XqXO8Doki9Q1Xg+uZJeTkQQJqNkLESL RAa8iujSBZix+ZBVDE+7E0RoUT3uHmlYiiCKzNvHHxPB3Y3DSYJXQzXmRP4VpBmWKEIz znQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=q+x2Ul1e; 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 b5si209801edq.191.2020.04.20.04.58.49; Mon, 20 Apr 2020 04:59:12 -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; dkim=pass header.i=@kernel.org header.s=default header.b=q+x2Ul1e; 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 S1727768AbgDTL4z (ORCPT + 99 others); Mon, 20 Apr 2020 07:56:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:41310 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726661AbgDTL4t (ORCPT ); Mon, 20 Apr 2020 07:56:49 -0400 Received: from quaco.ghostprotocols.net (unknown [179.97.37.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 28317218AC; Mon, 20 Apr 2020 11:56:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587383808; bh=U4eJSc8TgHW9W+/DL/Cn7uZVr23BQIsJEfDEdoHZsHk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q+x2Ul1eZi7vB9Y5bUOHpzcXbCCLStAB8+8TD7Z8z7/hM7GcTr/GcDkgyn6vfewU5 beozZJ+tEB92F+4K2h/rd6a1aWnd/9ufOtYtZaS8yLyUV1t294wPUhavuIAmAAkOTx PXZn+dbbPizW+kZg8FJnVHbWAc56AaG7JZGR+jXM= From: Arnaldo Carvalho de Melo To: Ingo Molnar , Thomas Gleixner Cc: Jiri Olsa , Namhyung Kim , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Jiri Olsa , Thomas Richter , Arnaldo Carvalho de Melo , Alexander Shishkin , Michael Petlan , Peter Zijlstra , Sumanth Korikkar , Vasily Gorbik Subject: [PATCH 46/60] perf parser: Add support to specify rXXX event with pmu Date: Mon, 20 Apr 2020 08:53:02 -0300 Message-Id: <20200420115316.18781-47-acme@kernel.org> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200420115316.18781-1-acme@kernel.org> References: <20200420115316.18781-1-acme@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jiri Olsa The current rXXXX event specification creates event under PERF_TYPE_RAW pmu type. This change allows to use rXXXX within pmu syntax, so it's type is used via the following syntax: -e 'cpu/r3c/' -e 'cpum_cf/r0/' The XXXX number goes directly to perf_event_attr::config the same way as in '-e rXXXX' event. The perf_event_attr::type is filled with pmu type. Committer testing: So, lets see what goes in perf_event_attr::config for, say, the 'instructions' PERF_TYPE_HARDWARE (0) event, first we should look at how to encode this event as a PERF_TYPE_RAW event for this specific CPU, an AMD Ryzen 5: # cat /sys/devices/cpu/events/instructions event=0xc0 # Then try with it _and_ the instruction, just to see that they are close enough: # perf stat -e rc0,instructions sleep 1 Performance counter stats for 'sleep 1': 919,794 rc0 919,898 instructions 1.000754579 seconds time elapsed 0.000715000 seconds user 0.000000000 seconds sys # Now we should try, before this patch, the PMU event encoding: # perf stat -e cpu/rc0/ sleep 1 event syntax error: 'cpu/rc0/' \___ unknown term valid terms: event,edge,inv,umask,cmask,config,config1,config2,name,period,percore # Now with this patch, the three ways of specifying the 'instructions' CPU counter are accepted: # perf stat -e cpu/rc0/,rc0,instructions sleep 1 Performance counter stats for 'sleep 1': 892,948 cpu/rc0/ 893,052 rc0 893,156 instructions 1.000931819 seconds time elapsed 0.000916000 seconds user 0.000000000 seconds sys # Requested-by: Thomas Richter Signed-off-by: Jiri Olsa Tested-by: Arnaldo Carvalho de Melo Tested-by: Thomas Richter Cc: Alexander Shishkin Cc: Michael Petlan Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Sumanth Korikkar Cc: Vasily Gorbik Link: http://lore.kernel.org/lkml/20200416221405.437788-1-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/Documentation/perf-list.txt | 5 +++++ tools/perf/tests/parse-events.c | 17 ++++++++++++++++- tools/perf/util/parse-events.l | 1 + tools/perf/util/parse-events.y | 9 +++++++++ 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/tools/perf/Documentation/perf-list.txt b/tools/perf/Documentation/perf-list.txt index cb23667531ab..376a50b3452d 100644 --- a/tools/perf/Documentation/perf-list.txt +++ b/tools/perf/Documentation/perf-list.txt @@ -115,6 +115,11 @@ raw encoding of 0x1A8 can be used: perf stat -e r1a8 -a sleep 1 perf record -e r1a8 ... +It's also possible to use pmu syntax: + + perf record -e r1a8 -a sleep 1 + perf record -e cpu/r1a8/ ... + You should refer to the processor specific documentation for getting these details. Some of them are referenced in the SEE ALSO section below. diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-events.c index 091c3aeccc27..902bd9d591a0 100644 --- a/tools/perf/tests/parse-events.c +++ b/tools/perf/tests/parse-events.c @@ -1356,6 +1356,16 @@ static int test__checkevent_complex_name(struct evlist *evlist) return 0; } +static int test__checkevent_raw_pmu(struct evlist *evlist) +{ + struct evsel *evsel = evlist__first(evlist); + + TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries); + TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->core.attr.type); + TEST_ASSERT_VAL("wrong config", 0x1a == evsel->core.attr.config); + return 0; +} + static int test__sym_event_slash(struct evlist *evlist) { struct evsel *evsel = evlist__first(evlist); @@ -1750,7 +1760,12 @@ static struct evlist_test test__events_pmu[] = { .name = "cpu/name='COMPLEX_CYCLES_NAME:orig=cycles,desc=chip-clock-ticks',period=0x1,event=0x2/ukp", .check = test__checkevent_complex_name, .id = 3, - } + }, + { + .name = "software/r1a/", + .check = test__checkevent_raw_pmu, + .id = 4, + }, }; struct terms_test { diff --git a/tools/perf/util/parse-events.l b/tools/perf/util/parse-events.l index baa48f28d57d..c589fc42f058 100644 --- a/tools/perf/util/parse-events.l +++ b/tools/perf/util/parse-events.l @@ -286,6 +286,7 @@ no-overwrite { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_NOOVERWRITE); } percore { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_PERCORE); } aux-output { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_AUX_OUTPUT); } aux-sample-size { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_AUX_SAMPLE_SIZE); } +r{num_raw_hex} { return raw(yyscanner); } , { return ','; } "/" { BEGIN(INITIAL); return '/'; } {name_minus} { return str(yyscanner, PE_NAME); } diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y index 94f8bcd83582..e879eb257874 100644 --- a/tools/perf/util/parse-events.y +++ b/tools/perf/util/parse-events.y @@ -706,6 +706,15 @@ event_term } event_term: +PE_RAW +{ + struct parse_events_term *term; + + ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_CONFIG, + NULL, $1, false, &@1, NULL)); + $$ = term; +} +| PE_NAME '=' PE_NAME { struct parse_events_term *term; -- 2.21.1