Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1312136

[PATCH 3/6] perf core: Prepare writing into ring buffer from end

Path csiph.com!news.mixmin.net!aioe.org!bofh.it!news.nic.it!robomod
From Wang Nan <wangnan0@huawei.com>
Newsgroups linux.kernel
Subject [PATCH 3/6] perf core: Prepare writing into ring buffer from end
Date Tue, 19 Jan 2016 12:30:02 +0100
Message-ID <qSCE2-730-15@gated-at.bofh.it> (permalink)
References <qSgNb-rq-19@gated-at.bofh.it> <qSCum-6ZJ-9@gated-at.bofh.it>
X-Original-To <peterz@infradead.org>, <ast@kernel.org>
X-Mailer git-send-email 1.8.3.4
MIME-Version 1.0
Content-Type text/plain
X-Originating-IP [10.107.193.248]
X-Cfilter-Loop Reflected
X-Mirapoint-Virus-Rapid-Raw score=unknown(0), refid=str=0001.0A020205.569E1B37.005E,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32
X-Mirapoint-Loop-ID 1c99639fb6e32fdb0eb515602314af70
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 93
Organization linux.* mail to news gateway
X-Original-Cc <linux-kernel@vger.kernel.org>, Wang Nan <wangnan0@huawei.com>, He Kuang <hekuang@huawei.com>, Arnaldo Carvalho de Melo <acme@redhat.com>, "Brendan Gregg" <brendan.d.gregg@gmail.com>, Jiri Olsa <jolsa@kernel.org>, "Masami Hiramatsu" <masami.hiramatsu.pt@hitachi.com>, Namhyung Kim <namhyung@kernel.org>, Zefan Li <lizefan@huawei.com>, <pi3orama@163.com>
X-Original-Date Tue, 19 Jan 2016 11:16:47 +0000
X-Original-Message-ID <1453202210-134429-4-git-send-email-wangnan0@huawei.com>
X-Original-References <20160118120230.GP6357@twins.programming.kicks-ass.net> <1453202210-134429-1-git-send-email-wangnan0@huawei.com>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1312136

Show key headers only | View raw


Convert perf_output_begin to __perf_output_begin and make the later
function able to write records from the end of the ring buffer.
Following commits will utilize the 'backward' flag.

This patch doesn't introduce any extra performance overhead since we
use always_inline.

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Cc: He Kuang <hekuang@huawei.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
---
 kernel/events/ring_buffer.c | 37 +++++++++++++++++++++++++++++++------
 1 file changed, 31 insertions(+), 6 deletions(-)

diff --git a/kernel/events/ring_buffer.c b/kernel/events/ring_buffer.c
index 9f1a93f..bbc3bc6 100644
--- a/kernel/events/ring_buffer.c
+++ b/kernel/events/ring_buffer.c
@@ -102,8 +102,21 @@ out:
 	preempt_enable();
 }
 
-int perf_output_begin(struct perf_output_handle *handle,
-		      struct perf_event *event, unsigned int size)
+static bool __always_inline
+ring_buffer_has_space(unsigned long head, unsigned long tail,
+		      unsigned long data_size, unsigned int size,
+		      bool backward)
+{
+	if (!backward)
+		return CIRC_SPACE(head, tail, data_size) < size;
+	else
+		return CIRC_SPACE(tail, head, data_size) < size;
+}
+
+static int __always_inline
+__perf_output_begin(struct perf_output_handle *handle,
+		    struct perf_event *event, unsigned int size,
+		    bool backward)
 {
 	struct ring_buffer *rb;
 	unsigned long tail, offset, head;
@@ -146,9 +159,12 @@ int perf_output_begin(struct perf_output_handle *handle,
 	do {
 		tail = READ_ONCE(rb->user_page->data_tail);
 		offset = head = local_read(&rb->head);
-		if (!rb->overwrite &&
-		    unlikely(CIRC_SPACE(head, tail, perf_data_size(rb)) < size))
-			goto fail;
+		if (!rb->overwrite) {
+			if (unlikely(!ring_buffer_has_space(head, tail,
+							    perf_data_size(rb),
+							    size, backward)))
+				goto fail;
+		}
 
 		/*
 		 * The above forms a control dependency barrier separating the
@@ -162,7 +178,10 @@ int perf_output_begin(struct perf_output_handle *handle,
 		 * See perf_output_put_handle().
 		 */
 
-		head += size;
+		if (!backward)
+			head += size;
+		else
+			head -= size;
 	} while (local_cmpxchg(&rb->head, offset, head) != offset);
 
 	/*
@@ -206,6 +225,12 @@ out:
 	return -ENOSPC;
 }
 
+int perf_output_begin(struct perf_output_handle *handle,
+		      struct perf_event *event, unsigned int size)
+{
+	return __perf_output_begin(handle, event, size, false);
+}
+
 unsigned int perf_output_copy(struct perf_output_handle *handle,
 		      const void *buf, unsigned int len)
 {
-- 
1.8.3.4

Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH] perf core: Introduce new ioctl options to pause and resume ring buffer Wang Nan <wangnan0@huawei.com> - 2016-01-18 13:00 +0100
  Re: [PATCH] perf core: Introduce new ioctl options to pause and  resume ring buffer Peter Zijlstra <peterz@infradead.org> - 2016-01-18 13:10 +0100
    Re: [PATCH] perf core: Introduce new ioctl options to pause and resume  ring buffer "Wangnan (F)" <wangnan0@huawei.com> - 2016-01-19 04:00 +0100
    [PATCH 0/6] perf core: Read from overwrite ring buffer Wang Nan <wangnan0@huawei.com> - 2016-01-19 12:20 +0100
      [PATCH 1/6] perf core: Introduce new ioctl options to pause and resume ring buffer Wang Nan <wangnan0@huawei.com> - 2016-01-19 12:20 +0100
      [PATCH 6/6] perf/core: Put size of a sample at the end of it by PERF_SAMPLE_TAILSIZE Wang Nan <wangnan0@huawei.com> - 2016-01-19 12:20 +0100
      [PATCH 2/6] perf core: Set event's default overflow_handler Wang Nan <wangnan0@huawei.com> - 2016-01-19 12:20 +0100
      [PATCH 5/6] perf core: Reduce perf event output overhead by setting overwrite handler Wang Nan <wangnan0@huawei.com> - 2016-01-19 12:20 +0100
      [PATCH 4/6] perf core: Add backwork attribute to perf event Wang Nan <wangnan0@huawei.com> - 2016-01-19 12:20 +0100
      [PATCH 3/6] perf core: Prepare writing into ring buffer from end Wang Nan <wangnan0@huawei.com> - 2016-01-19 12:30 +0100
      Re: [PATCH 0/6] perf core: Read from overwrite ring buffer Namhyung Kim <namhyung@kernel.org> - 2016-01-19 15:10 +0100
        Re: [PATCH 0/6] perf core: Read from overwrite ring buffer pi3orama <pi3orama@163.com> - 2016-01-19 15:20 +0100
      Re: [PATCH 0/6] perf core: Read from overwrite ring buffer Alexei Starovoitov <alexei.starovoitov@gmail.com> - 2016-01-19 18:50 +0100
        Re: [PATCH 0/6] perf core: Read from overwrite ring buffer "Wangnan (F)" <wangnan0@huawei.com> - 2016-01-20 02:40 +0100
          Re: [PATCH 0/6] perf core: Read from overwrite ring buffer Alexei Starovoitov <alexei.starovoitov@gmail.com> - 2016-01-20 03:30 +0100
            Re: [PATCH 0/6] perf core: Read from overwrite ring buffer "Wangnan (F)" <wangnan0@huawei.com> - 2016-01-21 08:00 +0100
              Re: [PATCH 0/6] perf core: Read from overwrite ring buffer "Wangnan (F)" <wangnan0@huawei.com> - 2016-01-22 03:30 +0100
                Re: [PATCH 0/6] perf core: Read from overwrite ring buffer Alexei Starovoitov <alexei.starovoitov@gmail.com> - 2016-01-22 04:30 +0100
                Re: [PATCH 0/6] perf core: Read from overwrite ring buffer "Wangnan (F)" <wangnan0@huawei.com> - 2016-01-22 05:50 +0100

csiph-web