Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3295548pxk; Mon, 21 Sep 2020 09:56:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzp0RF2y3A1r6kL7a0jZtl2F/iVz4CH+6N1W3DwCBurlpc20mLiYkh6P9FpUXu7vMfd+6MY X-Received: by 2002:a17:907:72c2:: with SMTP id du2mr385557ejc.512.1600707414586; Mon, 21 Sep 2020 09:56:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600707414; cv=none; d=google.com; s=arc-20160816; b=VN0VlkETqUjx83KvQyfm2g+P1Njq6wjTYUDIpoBnftR6sd+n7LF5501NWfjZzOobly f/m1NGeMkYnBEW698+HtEa6aLauqn4NAWkbtRz5dnggbuR/MYPTQrLGidi7jV418jxHj txOnoGfV5ya38HZ5QcNpjX1mVgT+IyKRldQc2EKydc5/1tpo9SkUygTPgKzSTqh3PiaW LT4Dy8BXXPeNRUPL3opatJS5RQbL74C5q8hvc3eVD0n/tSfXu04ns9qRHDA9BB/tDVpE ZokfFUl7YmzSOuo9lsIDbYNOVrfZxZb8T0P6uBFa4mOjJg1eImZGng6bII6YFxdRNeYk yx2Q== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=95yacsuJzZjKW1HRH+BqozrG0h5tSLPtumqvC7Pm2Ek=; b=wcbQI3+M/RwqHsXnkhSttx6UIgMuduv6gTlmNt1qpVa210/lqlUeQtMMUGrIZNJWYE DDhroijRGuInwYVHAOg3gWSQPlJ4ABFJZQtpU110f/4IpjNpCoqmPqY2jw5oZrPKcj5c QaojImDjy9Msf79qfAtRbMMy4IV2VFLtiD6XNY/9yFHQHAUiZFlaaMNCR9i4EqBqNFeU Cm5WzzXK6OOsDaLbdspTM4ePZV5zqVETKp1xj3EyKyLn62T9A1jjZlb/zvnhyN2K84g7 AjicnEWYPW8Nt9gtzwcIR2KV5xOi96dUlCUaTLxqLGEjWWC0ap9mKfKJBGva5hm/D0CB mYjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=iG+uGSbh; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h26si8550802eji.739.2020.09.21.09.56.30; Mon, 21 Sep 2020 09:56:54 -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=iG+uGSbh; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728778AbgIUQpq (ORCPT + 99 others); Mon, 21 Sep 2020 12:45:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:51704 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727786AbgIUQpj (ORCPT ); Mon, 21 Sep 2020 12:45:39 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 7B569206B2; Mon, 21 Sep 2020 16:45:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600706738; bh=3UZgajV0htduWcdwvwfX3e3YlbqtaHyNQ7QGawYJOT0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iG+uGSbh5CrmkwSQdS8SIheBZjqSKFqmqN8xZyAg6Foy2XOBBvq05iV3W231nOYcW FIdr8uJZVLRa+n+8OuiLEybZJJb2o8Blg3LWw4ZPAkXvWLYkwkwepLFjdkKewPzz0w SoYrK1+/WIq0Wy3JP+NhJABX0iEvhllk1LOSI/z8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ian Rogers , Adrian Hunter , Jiri Olsa , Arnaldo Carvalho de Melo , Alexander Shishkin , Alexei Starovoitov , Andi Kleen , Andrii Nakryiko , Athira Jajeev , Daniel Borkmann , John Fastabend , KP Singh , Mark Rutland , Martin KaFai Lau , Namhyung Kim , Peter Zijlstra , Song Liu , Stephane Eranian , Yonghong Song , Sasha Levin Subject: [PATCH 5.8 057/118] perf record: Dont clear events period if set by a term Date: Mon, 21 Sep 2020 18:27:49 +0200 Message-Id: <20200921162038.996947785@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200921162036.324813383@linuxfoundation.org> References: <20200921162036.324813383@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ian Rogers [ Upstream commit 3b0a18c1aa6cbfa7b0dd513b6be9893ef6e6ac30 ] 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. Committer testing: Before: # perf record -e '{cycles/period=1/,instructions/period=2/}:S' sleep 1 [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.051 MB perf.data (6 samples) ] # # perf evlist -v cycles/period=1/: size: 120, { sample_period, sample_freq }: 1, sample_type: IP|TID|TIME|READ|ID, read_format: ID|GROUP, disabled: 1, mmap: 1, comm: 1, enable_on_exec: 1, task: 1, sample_id_all: 1, exclude_guest: 1, mmap2: 1, comm_exec: 1, ksymbol: 1, bpf_event: 1 instructions/period=2/: size: 120, config: 0x1, sample_type: IP|TID|TIME|READ|ID, read_format: ID|GROUP, sample_id_all: 1, exclude_guest: 1 # After: # perf record -e '{cycles/period=1/,instructions/period=2/}:S' sleep 0.0001 [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.052 MB perf.data (4 samples) ] # perf evlist -v cycles/period=1/: size: 120, { sample_period, sample_freq }: 1, sample_type: IP|TID|TIME|READ|ID, read_format: ID|GROUP, disabled: 1, mmap: 1, comm: 1, enable_on_exec: 1, task: 1, sample_id_all: 1, exclude_guest: 1, mmap2: 1, comm_exec: 1, ksymbol: 1, bpf_event: 1 instructions/period=2/: size: 120, config: 0x1, { sample_period, sample_freq }: 2, sample_type: IP|TID|TIME|READ|ID, read_format: ID|GROUP, sample_id_all: 1, exclude_guest: 1 # Fixes: 5f34278867b7 ("perf evlist: Move leader-sampling configuration") Signed-off-by: Ian Rogers Acked-by: Adrian Hunter Acked-by: Jiri Olsa Tested-by: Arnaldo Carvalho de Melo Cc: Alexander Shishkin Cc: Alexei Starovoitov Cc: Andi Kleen Cc: Andrii Nakryiko Cc: Athira Jajeev Cc: Daniel Borkmann Cc: John Fastabend Cc: KP Singh Cc: Mark Rutland Cc: Martin KaFai Lau Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Song Liu Cc: Stephane Eranian Cc: Yonghong Song Link: http://lore.kernel.org/lkml/20200912025655.1337192-4-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- 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 a4cc11592f6b3..ea9aa1d7cf501 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 -- 2.25.1