From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754038AbdKNMhm (ORCPT ); Tue, 14 Nov 2017 07:37:42 -0500 Received: from mga05.intel.com ([192.55.52.43]:34776 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752791AbdKNMhc (ORCPT ); Tue, 14 Nov 2017 07:37:32 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,393,1505804400"; d="scan'208";a="1740796" From: Alexander Shishkin To: Peter Zijlstra , Arnaldo Carvalho de Melo Cc: Ingo Molnar , linux-kernel@vger.kernel.org, Will Deacon , Adrian Hunter , Alexander Shishkin , Markus Metzger Subject: [PATCH v1 1/4] perf: Allow suppressing AUX records Date: Tue, 14 Nov 2017 14:30:21 +0200 Message-Id: <20171114123024.11517-2-alexander.shishkin@linux.intel.com> X-Mailer: git-send-email 2.13.1 In-Reply-To: <20171114123024.11517-1-alexander.shishkin@linux.intel.com> References: <20171114123024.11517-1-alexander.shishkin@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It has been pointed out to me many times that it is useful to be able to switch off AUX records to save the bandwidth for records that actually matter, for example, in AUX overwrite mode. The usefulness of PERF_RECORD_AUX is in some of its flags, like the TRUNCATED flag that tells the decoder where exactly gaps in the trace are. The OVERWRITE flag, on the other hand will be set on every single record in overwrite mode. However, a PERF_RECORD_AUX[flags=OVERWRITE] is generated on every target task's sched_out, which over time adds up to a lot of useless information. This patch adds an attribute bit that enables suppressing such records. Signed-off-by: Alexander Shishkin Cc: Markus Metzger Cc: Adrian Hunter --- include/uapi/linux/perf_event.h | 3 ++- kernel/events/core.c | 5 +++++ kernel/events/ring_buffer.c | 12 ++++++++++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h index 362493a2f950..fa3821d9dc52 100644 --- a/include/uapi/linux/perf_event.h +++ b/include/uapi/linux/perf_event.h @@ -370,7 +370,8 @@ struct perf_event_attr { context_switch : 1, /* context switch data */ write_backward : 1, /* Write ring buffer from end to beginning */ namespaces : 1, /* include namespaces data */ - __reserved_1 : 35; + suppress_aux : 1, /* don't generate PERF_RECORD_AUX */ + __reserved_1 : 34; union { __u32 wakeup_events; /* wakeup every n events */ diff --git a/kernel/events/core.c b/kernel/events/core.c index 81dd57b9e5e3..483122c73936 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -10014,6 +10014,11 @@ SYSCALL_DEFINE5(perf_event_open, goto err_context; } + if (attr.suppress_aux && !pmu->setup_aux) { + err = -EINVAL; + goto err_context; + } + /* * Look up the group leader (we will attach this event to it): */ diff --git a/kernel/events/ring_buffer.c b/kernel/events/ring_buffer.c index f684d8e5fa2b..ecd8da78d387 100644 --- a/kernel/events/ring_buffer.c +++ b/kernel/events/ring_buffer.c @@ -425,6 +425,12 @@ static bool __always_inline rb_need_aux_wakeup(struct ring_buffer *rb) return false; } +/* + * These flags won't generate a PERF_RECORD_AUX on their own if + * attr::suppress_aux is set. + */ +#define SUPPRESSABLE_FLAGS PERF_AUX_FLAG_OVERWRITE + /* * Commit the data written by hardware into the ring buffer by adjusting * aux_head and posting a PERF_RECORD_AUX into the perf buffer. It is the @@ -459,8 +465,10 @@ void perf_aux_output_end(struct perf_output_handle *handle, unsigned long size) * Only send RECORD_AUX if we have something useful to communicate */ - perf_event_aux_event(handle->event, aux_head, size, - handle->aux_flags); + if (!handle->event->attr.suppress_aux || + (handle->aux_flags & ~(u64)SUPPRESSABLE_FLAGS)) + perf_event_aux_event(handle->event, aux_head, size, + handle->aux_flags); } rb->user_page->aux_head = rb->aux_head; -- 2.15.0