From patchwork Sat Sep 12 02:56:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 261005 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=-12.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable 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 27E62C43461 for ; Sat, 12 Sep 2020 02:57:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E031C221EB for ; Sat, 12 Sep 2020 02:57:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="cEuaKFtv" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725889AbgILC5t (ORCPT ); Fri, 11 Sep 2020 22:57:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725808AbgILC5B (ORCPT ); Fri, 11 Sep 2020 22:57:01 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CBF9BC061796 for ; Fri, 11 Sep 2020 19:56:59 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id y6so15592ybi.11 for ; Fri, 11 Sep 2020 19:56:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=JjLhvyF9iMwelIcaw0DBsu//Y1+/ZRLd9VReK2mwSGs=; b=cEuaKFtvziVsuhVvQm/MR9FV9+QVZlR9FW5IU+nia4FDj/qXfvp6uzCu734+nn4QQW nzF3mMWnA9wzXvXef021Ejg1zSdN+eXgjWdpqR/0hXCy9p+k28u0yiIMa75YaOkqlD84 ZETk+umBq/6+72xE21jwKbBMDK3GbO4Pt5g0oD0NGp/bX512d2oJlTSfHp59Ffzm6Z4f 3J1qFgWluIsOtMbusuaXSBgUjQ2dIuF859kOnyZzAYfiFwuYbxwjcYHNTy5iu2j9YCpk ZFQbbCNARJlNVVsnesgFR29Ioho5jW4Op21MZTxVxAhvESXqEqWRxVZOcYAkNL1Hv7B/ I6LA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=JjLhvyF9iMwelIcaw0DBsu//Y1+/ZRLd9VReK2mwSGs=; b=tGL0zNZQ9GF/T2MX+syF+YRZGu3BvREn5kJRSuqTTTw4ESObAbSUDyF8GSojDrKtws BIOZkaBTB6JDg1aw6As6XbAzCzjBV3jyciUvJ10cT9VnOxx9y7UOdbrXDnncGNSTL5AZ oIADNSXiVhuczn9xg/qGJz5Qw9+Ad4yorvCEWHzy8wySbMZl++OwthsZMN/dJc1ELo0x Frk2v9z4oLNKyEGynpA1FQrMmuI4aNC5KGk/yluA3vkJInu9VKVFS95kFeh7Km5ePu40 vPzYOyoTn00n1mVpEbs4L7JRZlfGkRSL54SO1UCh9FHGPshqvCtHTg8c0wkh+1wbiLMi tsvg== X-Gm-Message-State: AOAM533pRUj8f4lkyUBmM7BT3+vddDs9FfOf6W19t6ok/cbvh2P868Zi zLiwE/LRQBpuUgFoRKb7OGaCOUiNQfku X-Google-Smtp-Source: ABdhPJz3ff6ZAhAaEVz80+FABBEVLhzUutcRr/Uhs+2mnjS21WRcmYL5tmOf4eZWJ+py9c5W+hUwdj339FiU X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:2:f693:9fff:fef4:4583]) (user=irogers job=sendgmr) by 2002:a25:dcc6:: with SMTP id y189mr7066582ybe.178.1599879418975; Fri, 11 Sep 2020 19:56:58 -0700 (PDT) Date: Fri, 11 Sep 2020 19:56:52 -0700 In-Reply-To: <20200912025655.1337192-1-irogers@google.com> Message-Id: <20200912025655.1337192-2-irogers@google.com> Mime-Version: 1.0 References: <20200912025655.1337192-1-irogers@google.com> X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog Subject: [PATCH v3 1/4] perf record: Set PERF_RECORD_PERIOD if attr->freq is set. From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , Andrii Nakryiko , John Fastabend , KP Singh , Adrian Hunter , Andi Kleen , Athira Rajeev , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org Cc: Stephane Eranian , David Sharp , Ian Rogers Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: David Sharp evsel__config() would only set PERF_RECORD_PERIOD if it set attr->freq from perf record options. When it is set by libpfm events, it would not get set. This changes evsel__config to see if attr->freq is set outside of whether or not it changes attr->freq itself. Signed-off-by: David Sharp Signed-off-by: Ian Rogers --- tools/perf/util/evsel.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index fd865002cbbd..3e985016da7e 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -979,13 +979,18 @@ void evsel__config(struct evsel *evsel, struct record_opts *opts, if (!attr->sample_period || (opts->user_freq != UINT_MAX || opts->user_interval != ULLONG_MAX)) { if (opts->freq) { - evsel__set_sample_bit(evsel, PERIOD); attr->freq = 1; attr->sample_freq = opts->freq; } else { attr->sample_period = opts->default_interval; } } + /* + * If attr->freq was set (here or earlier), ask for period + * to be sampled. + */ + if (attr->freq) + evsel__set_sample_bit(evsel, PERIOD); if (opts->no_samples) attr->sample_freq = 0; From patchwork Sat Sep 12 02:56:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 261006 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=-12.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable 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 80DB3C43461 for ; Sat, 12 Sep 2020 02:57:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 40ECB221EB for ; Sat, 12 Sep 2020 02:57:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="pbPv6LoT" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725857AbgILC5S (ORCPT ); Fri, 11 Sep 2020 22:57:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725830AbgILC5D (ORCPT ); Fri, 11 Sep 2020 22:57:03 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC9E0C0613ED for ; Fri, 11 Sep 2020 19:57:03 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 125so10865914ybg.12 for ; Fri, 11 Sep 2020 19:57:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=S4BaSChoStuXn9hUjRtFrVEEliba+K91i8IvE/c8cWU=; b=pbPv6LoTFW9c9cgb1mIWL4TXAnmXnBP3zMCzGQT4KcZ4LkRTO9zyobxhuDAdLt0TLE Nf1zhQ2urZmVZga/imCGWFsImzFGhh6+S+JaXaQcSGRYYrxkWL1AqCEbSl7KKx30WL3x yhOQc/Qie9pC/KVnW+0U0CiC77suqzpyNuyTROVWMr7I977yEQiJsRYTlZ/w/t4GRHKM ctc2pp4bDM95NZAQnaMu/6SrTSGPpk6sEFIZi27286exnQw3qHUd4zxS4cK0dP8K4PCe ylkq0AvTJRbEV6nXKPYGWOv358H0PRerHbQOAuA7vrcfOAFxqf3ebJ4BYlcUpRSKSHyh 6NXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=S4BaSChoStuXn9hUjRtFrVEEliba+K91i8IvE/c8cWU=; b=LotmtDWxlX8X365pfQDGeNx7vd1WLHpnaQXAZBcvq4Vtrji5WZhFHWuB2yLcQC8ZJ5 +g1q9HKZQqOyckG5LN1Kqk5wc6sV8WMcc46W3oAWaKUZ1pOoiucPUE1smKeun7mZS+xO /VMnCAbfQDnsbXd+52I2nUZgmLBwhGBcAlSgMK+arRXkODSQUl7hxCTk6s2Bb3wkt2w4 skquiw8UdCPurkqXu035fvQB9Y51xBsn62TZ2/7cXhk/lv2U+2rjoHGTQjRVeAkk17RK QFnxElLrH+V/WaTk9BmUX9lEYuqWuNwnLbuh8+nd3Dta6syPhh6M4Hn5YcnL1GmYBm5E dqTg== X-Gm-Message-State: AOAM530ETcv4P0O7EsaVrbejY1qWQ0JoFFyRUS7InMjQ+HZwXAYg2E5B CLrqyk6ddH0jFN19fVw0oXyzPwWHI01v X-Google-Smtp-Source: ABdhPJydvl5bZ5owq66oiX1WfPkpW16l0ovIc+lZVj9SuIGZawWsXOZx4KTvhzIJFWyCEUS5CSvNOxz6miJL X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:2:f693:9fff:fef4:4583]) (user=irogers job=sendgmr) by 2002:a25:5096:: with SMTP id e144mr5872381ybb.32.1599879422845; Fri, 11 Sep 2020 19:57:02 -0700 (PDT) Date: Fri, 11 Sep 2020 19:56:54 -0700 In-Reply-To: <20200912025655.1337192-1-irogers@google.com> Message-Id: <20200912025655.1337192-4-irogers@google.com> Mime-Version: 1.0 References: <20200912025655.1337192-1-irogers@google.com> X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog Subject: [PATCH v3 3/4] perf record: Don't clear event's period if set by a term From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , Andrii Nakryiko , John Fastabend , KP Singh , Adrian Hunter , Andi Kleen , Athira Rajeev , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org Cc: Stephane Eranian , Ian Rogers Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org If events in a group explicitly set a frequency or period with leader sampling, don't disable the samples on those events. Prior to 5.8: perf record -e '{cycles/period=12345000/,instructions/period=6789000/}:S' would clear the attributes then apply the config terms. In commit 5f34278867b7 leader sampling configuration was moved to after applying the config terms, in the example, making the instructions' event have its period cleared. This change makes it so that sampling is only disabled if configuration terms aren't present. Fixes: 5f34278867b7 ("perf evlist: Move leader-sampling configuration") Signed-off-by: Ian Rogers Acked-by: Adrian Hunter --- tools/perf/util/record.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/tools/perf/util/record.c b/tools/perf/util/record.c index a4cc11592f6b..ea9aa1d7cf50 100644 --- a/tools/perf/util/record.c +++ b/tools/perf/util/record.c @@ -2,6 +2,7 @@ #include "debug.h" #include "evlist.h" #include "evsel.h" +#include "evsel_config.h" #include "parse-events.h" #include #include @@ -33,11 +34,24 @@ static struct evsel *evsel__read_sampler(struct evsel *evsel, struct evlist *evl return leader; } +static u64 evsel__config_term_mask(struct evsel *evsel) +{ + struct evsel_config_term *term; + struct list_head *config_terms = &evsel->config_terms; + u64 term_types = 0; + + list_for_each_entry(term, config_terms, list) { + term_types |= 1 << term->type; + } + return term_types; +} + static void evsel__config_leader_sampling(struct evsel *evsel, struct evlist *evlist) { struct perf_event_attr *attr = &evsel->core.attr; struct evsel *leader = evsel->leader; struct evsel *read_sampler; + u64 term_types, freq_mask; if (!leader->sample_read) return; @@ -47,16 +61,20 @@ static void evsel__config_leader_sampling(struct evsel *evsel, struct evlist *ev if (evsel == read_sampler) return; + term_types = evsel__config_term_mask(evsel); /* - * Disable sampling for all group members other than the leader in - * case the leader 'leads' the sampling, except when the leader is an - * AUX area event, in which case the 2nd event in the group is the one - * that 'leads' the sampling. + * Disable sampling for all group members except those with explicit + * config terms or the leader. In the case of an AUX area event, the 2nd + * event in the group is the one that 'leads' the sampling. */ - attr->freq = 0; - attr->sample_freq = 0; - attr->sample_period = 0; - attr->write_backward = 0; + freq_mask = (1 << EVSEL__CONFIG_TERM_FREQ) | (1 << EVSEL__CONFIG_TERM_PERIOD); + if ((term_types & freq_mask) == 0) { + attr->freq = 0; + attr->sample_freq = 0; + attr->sample_period = 0; + } + if ((term_types & (1 << EVSEL__CONFIG_TERM_OVERWRITE)) == 0) + attr->write_backward = 0; /* * We don't get a sample for slave events, we make them when delivering