Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp3122197pxy; Sun, 25 Apr 2021 14:45:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyBUgnX4JZJXZrb36/lxGEDvP4V4HjQJwhmeiTfEVx/IHA2KAtHpkLDbrKCBhZS7TJujxRh X-Received: by 2002:a17:902:a415:b029:e7:137b:ef9c with SMTP id p21-20020a170902a415b02900e7137bef9cmr15046065plq.28.1619387119408; Sun, 25 Apr 2021 14:45:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619387119; cv=none; d=google.com; s=arc-20160816; b=iN2SFp4UhwNpHz3T+nDdaq/8a4QTpBX0oof4VxMS+Ui6XmrJCYeNNa9p6mW+Iv3zCm 9dY47a15pmFIp/A3TZUcIDnD00sVtqv895fTjGl7HspC95IadQX7PdwrX+9q+Kx3JZox gDxWBxTMue7L+ND8J9WXpOdJlQPonZVFk5Y28Q+T5xuyFijapnPZHhIjcEZObFgEAH7e Z4G6+/yjivcEkeNOQWnAB+qp0ScO9HQjPCw2z/CanY0N2YeUa7W+OsJ5Zt7lZ42gJA6M TZD5jiVBX4zZaDsydrBU/bspGXxhQghMhCJq9lYxNtK6Mq0MVa1K6rfRad08OsP3keW2 tsBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=5y2h8ALayMUUnYnwAfDv2TqFA1ykq1fcSYastgomcxw=; b=ATcVEXRml6Rzwt9eI1Mu8hZ13SXxrvUV0jOznz96b4b1JQtjAyjX3ny8ERyIfhFCIs kz7YW7cCkXddMCUkR5kHZh5vOQ0prB1tp1sB3sYCFynK3RQrkcplBxmaCfg45s/IpBd3 mBxsttpRqJFwVjvcHlgkTUuKdWnpsWuijqhjmSNE6VsB1/ksSXlFHUwrS5c/dT++b8AV XmLvo8IR9wU2rUJ3n3xkNHaOWljzGxr3/C6/sUaBJkwUXVmb8f5Hgz5hUtAYBCwz0fIL TV2zNOT9lwgfBK+Woec5koa3KDZwrinRaouEIWy5EzkepjZJZko5ImQiBHkG40ddU5Tj 1euQ== 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 q6si16098937plx.285.2021.04.25.14.45.07; Sun, 25 Apr 2021 14:45:19 -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 S231418AbhDYVof convert rfc822-to-8bit (ORCPT + 99 others); Sun, 25 Apr 2021 17:44:35 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:5718 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231416AbhDYVod (ORCPT ); Sun, 25 Apr 2021 17:44:33 -0400 Received: from pps.filterd (m0001303.ppops.net [127.0.0.1]) by m0001303.ppops.net (8.16.0.43/8.16.0.43) with SMTP id 13PLZbtJ014413 for ; Sun, 25 Apr 2021 14:43:53 -0700 Received: from mail.thefacebook.com ([163.114.132.120]) by m0001303.ppops.net with ESMTP id 384f10ntvj-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Sun, 25 Apr 2021 14:43:53 -0700 Received: from intmgw001.25.frc3.facebook.com (2620:10d:c085:208::f) by mail.thefacebook.com (2620:10d:c085:21d::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Sun, 25 Apr 2021 14:43:51 -0700 Received: by devbig006.ftw2.facebook.com (Postfix, from userid 4523) id 5EF1662E2330; Sun, 25 Apr 2021 14:43:46 -0700 (PDT) From: Song Liu To: CC: , , , , , , Song Liu Subject: [PATCH v5 4/5] perf-stat: introduce ':b' modifier Date: Sun, 25 Apr 2021 14:43:32 -0700 Message-ID: <20210425214333.1090950-5-song@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210425214333.1090950-1-song@kernel.org> References: <20210425214333.1090950-1-song@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8BIT X-FB-Internal: Safe Content-Type: text/plain X-Proofpoint-GUID: 82yAvUV2uwNlTZw6rQC-n-luRkaron7U X-Proofpoint-ORIG-GUID: 82yAvUV2uwNlTZw6rQC-n-luRkaron7U X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.761 definitions=2021-04-25_09:2021-04-23,2021-04-25 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 adultscore=0 malwarescore=0 lowpriorityscore=0 suspectscore=0 phishscore=0 clxscore=1015 mlxlogscore=999 impostorscore=0 priorityscore=1501 mlxscore=0 bulkscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104250162 X-FB-Internal: deliver Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Introduce 'b' modifier to event parser, which means use BPF program to manage this event. This is the same as --bpf-counters option, but only applies to this event. For example, perf stat -e cycles:b,cs # use bpf for cycles, but not cs perf stat -e cycles,cs --bpf-counters # use bpf for both cycles and cs Suggested-by: Jiri Olsa Signed-off-by: Song Liu --- tools/perf/util/bpf_counter.c | 2 +- tools/perf/util/evsel.h | 1 + tools/perf/util/parse-events.c | 8 +++++++- tools/perf/util/parse-events.l | 2 +- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/bpf_counter.c b/tools/perf/util/bpf_counter.c index 33b1888103dfa..f179f57430253 100644 --- a/tools/perf/util/bpf_counter.c +++ b/tools/perf/util/bpf_counter.c @@ -790,7 +790,7 @@ int bpf_counter__load(struct evsel *evsel, struct target *target) { if (target->bpf_str) evsel->bpf_counter_ops = &bpf_program_profiler_ops; - else if (target->use_bpf || + else if (target->use_bpf || evsel->bpf_counter || evsel__match_bpf_counter_events(evsel->name)) evsel->bpf_counter_ops = &bperf_ops; diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index ce4b629d659c2..8f66cdcb338d0 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -82,6 +82,7 @@ struct evsel { bool auto_merge_stats; bool collect_stat; bool weak_group; + bool bpf_counter; int bpf_fd; struct bpf_object *bpf_obj; }; diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 8123d218ad17c..46ebd269a98d1 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1804,6 +1804,7 @@ struct event_modifier { int pinned; int weak; int exclusive; + int bpf_counter; }; static int get_event_modifier(struct event_modifier *mod, char *str, @@ -1824,6 +1825,7 @@ static int get_event_modifier(struct event_modifier *mod, char *str, int exclude = eu | ek | eh; int exclude_GH = evsel ? evsel->exclude_GH : 0; int weak = 0; + int bpf_counter = 0; memset(mod, 0, sizeof(*mod)); @@ -1867,6 +1869,8 @@ static int get_event_modifier(struct event_modifier *mod, char *str, exclusive = 1; } else if (*str == 'W') { weak = 1; + } else if (*str == 'b') { + bpf_counter = 1; } else break; @@ -1898,6 +1902,7 @@ static int get_event_modifier(struct event_modifier *mod, char *str, mod->sample_read = sample_read; mod->pinned = pinned; mod->weak = weak; + mod->bpf_counter = bpf_counter; mod->exclusive = exclusive; return 0; @@ -1912,7 +1917,7 @@ static int check_modifier(char *str) char *p = str; /* The sizeof includes 0 byte as well. */ - if (strlen(str) > (sizeof("ukhGHpppPSDIWe") - 1)) + if (strlen(str) > (sizeof("ukhGHpppPSDIWeb") - 1)) return -1; while (*p) { @@ -1953,6 +1958,7 @@ int parse_events__modifier_event(struct list_head *list, char *str, bool add) evsel->sample_read = mod.sample_read; evsel->precise_max = mod.precise_max; evsel->weak_group = mod.weak; + evsel->bpf_counter = mod.bpf_counter; if (evsel__is_group_leader(evsel)) { evsel->core.attr.pinned = mod.pinned; diff --git a/tools/perf/util/parse-events.l b/tools/perf/util/parse-events.l index 0b36285a9435d..fb8646cc3e834 100644 --- a/tools/perf/util/parse-events.l +++ b/tools/perf/util/parse-events.l @@ -210,7 +210,7 @@ name_tag [\'][a-zA-Z_*?\[\]][a-zA-Z0-9_*?\-,\.\[\]:=]*[\'] name_minus [a-zA-Z_*?][a-zA-Z0-9\-_*?.:]* drv_cfg_term [a-zA-Z0-9_\.]+(=[a-zA-Z0-9_*?\.:]+)? /* If you add a modifier you need to update check_modifier() */ -modifier_event [ukhpPGHSDIWe]+ +modifier_event [ukhpPGHSDIWeb]+ modifier_bp [rwx]{1,3} %% -- 2.30.2