From patchwork Tue Jan 19 11:16:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 59981 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp2509178lbb; Tue, 19 Jan 2016 03:18:37 -0800 (PST) X-Received: by 10.98.69.209 with SMTP id n78mr42348423pfi.81.1453202317656; Tue, 19 Jan 2016 03:18:37 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id fd9si8200444pad.134.2016.01.19.03.18.37; Tue, 19 Jan 2016 03:18:37 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752861AbcASLSf (ORCPT + 29 others); Tue, 19 Jan 2016 06:18:35 -0500 Received: from szxga03-in.huawei.com ([119.145.14.66]:4644 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752001AbcASLSQ (ORCPT ); Tue, 19 Jan 2016 06:18:16 -0500 Received: from 172.24.1.49 (EHLO szxeml427-hub.china.huawei.com) ([172.24.1.49]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id BUW16801; Tue, 19 Jan 2016 19:17:13 +0800 (CST) Received: from linux-4hy3.site (10.107.193.248) by szxeml427-hub.china.huawei.com (10.82.67.182) with Microsoft SMTP Server id 14.3.235.1; Tue, 19 Jan 2016 19:17:02 +0800 From: Wang Nan To: , CC: , Wang Nan , He Kuang , Arnaldo Carvalho de Melo , "Brendan Gregg" , Jiri Olsa , "Masami Hiramatsu" , Namhyung Kim , Zefan Li , Subject: [PATCH 4/6] perf core: Add backwork attribute to perf event Date: Tue, 19 Jan 2016 11:16:48 +0000 Message-ID: <1453202210-134429-5-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1453202210-134429-1-git-send-email-wangnan0@huawei.com> References: <20160118120230.GP6357@twins.programming.kicks-ass.net> <1453202210-134429-1-git-send-email-wangnan0@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.107.193.248] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020202.569E1B3A.0171, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-05-26 15:14:31, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: afb4110672920cbd9fb137388ff77a0e Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In perf_event_attr a new bit 'write_backward' is appended to indicate this event should write ring buffer from its end to beginning. In perf_output_begin(), prepare ring buffer according this bit. This patch introduces small overhead into perf_output_begin(): an extra memory read and a conditional branch. Further patch can remove this overhead using custom output handler. Signed-off-by: Wang Nan Cc: He Kuang Cc: Alexei Starovoitov Cc: Arnaldo Carvalho de Melo Cc: Brendan Gregg Cc: Jiri Olsa Cc: Masami Hiramatsu Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Zefan Li Cc: pi3orama@163.com --- include/linux/perf_event.h | 5 +++++ include/uapi/linux/perf_event.h | 3 ++- kernel/events/core.c | 7 +++++++ kernel/events/ring_buffer.c | 2 ++ 4 files changed, 16 insertions(+), 1 deletion(-) -- 1.8.3.4 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index f9828a4..54c3fb2 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -1032,6 +1032,11 @@ static inline bool has_aux(struct perf_event *event) return event->pmu->setup_aux; } +static inline bool is_write_backward(struct perf_event *event) +{ + return !!event->attr.write_backward; +} + extern int perf_output_begin(struct perf_output_handle *handle, struct perf_event *event, unsigned int size); extern void perf_output_end(struct perf_output_handle *handle); diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h index 2c7f00c..598b9b0 100644 --- a/include/uapi/linux/perf_event.h +++ b/include/uapi/linux/perf_event.h @@ -340,7 +340,8 @@ struct perf_event_attr { comm_exec : 1, /* flag comm events that are due to an exec */ use_clockid : 1, /* use @clockid for time fields */ context_switch : 1, /* context switch data */ - __reserved_1 : 37; + write_backward : 1, /* Write ring buffer from end to beginning */ + __reserved_1 : 36; union { __u32 wakeup_events; /* wakeup every n events */ diff --git a/kernel/events/core.c b/kernel/events/core.c index f79c4be..8ad22a5 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -8107,6 +8107,13 @@ perf_event_set_output(struct perf_event *event, struct perf_event *output_event) goto out; /* + * Either writing ring buffer from beginning or from end. + * Mixing is not allowed. + */ + if (is_write_backward(output_event) != is_write_backward(event)) + goto out; + + /* * If both events generate aux data, they must be on the same PMU */ if (has_aux(event) && has_aux(output_event) && diff --git a/kernel/events/ring_buffer.c b/kernel/events/ring_buffer.c index bbc3bc6..1372427 100644 --- a/kernel/events/ring_buffer.c +++ b/kernel/events/ring_buffer.c @@ -228,6 +228,8 @@ out: int perf_output_begin(struct perf_output_handle *handle, struct perf_event *event, unsigned int size) { + if (unlikely(is_write_backward(event))) + return __perf_output_begin(handle, event, size, true); return __perf_output_begin(handle, event, size, false); }