mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@elte.hu>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Peter Zijlstra <peterz@infradead.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	prasad@linux.vnet.ibm.com,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Mathieu Desnoyers <compudj@krystal.dyndns.org>,
	"Frank Ch. Eigler" <fche@redhat.com>,
	David Wilder <dwilder@us.ibm.com>,
	hch@lst.de, Martin Bligh <mbligh@google.com>,
	Christoph Hellwig <hch@infradead.org>,
	Masami Hiramatsu <mhiramat@redhat.com>,
	Steven Rostedt <srostedt@redhat.com>,
	Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Subject: Re: [PATCH v9] Unified trace buffer
Date: Sat, 27 Sep 2008 20:39:12 +0200	[thread overview]
Message-ID: <20080927183912.GA13685@elte.hu> (raw)
In-Reply-To: <alpine.DEB.1.10.0809270203270.1628@gandalf.stny.rr.com>


small nitpicking review, nothing structural yet:

* Steven Rostedt <rostedt@goodmis.org> wrote:

> Index: linux-trace.git/include/linux/ring_buffer.h
> +enum {
> +	RB_TYPE_PADDING,	/* Left over page padding

RB_ clashes with red-black tree namespace. (on the thought level)

> +#define RB_ALIGNMENT_SHIFT	2
> +#define RB_ALIGNMENT		(1 << RB_ALIGNMENT_SHIFT)
> +#define RB_MAX_SMALL_DATA	(28)

no need to put numeric literals into parenthesis.

> +static inline unsigned
> +ring_buffer_event_length(struct ring_buffer_event *event)
> +{
> +	unsigned length;
> +
> +	switch (event->type) {
> +	case RB_TYPE_PADDING:
> +		/* undefined */
> +		return -1;
> +
> +	case RB_TYPE_TIME_EXTENT:
> +		return RB_LEN_TIME_EXTENT;
> +
> +	case RB_TYPE_TIME_STAMP:
> +		return RB_LEN_TIME_STAMP;
> +
> +	case RB_TYPE_DATA:
> +		if (event->len)
> +			length = event->len << RB_ALIGNMENT_SHIFT;
> +		else
> +			length = event->array[0];
> +		return length + RB_EVNT_HDR_SIZE;
> +	default:
> +		BUG();
> +	}
> +	/* not hit */
> +	return 0;

too large, please uninline.

> +static inline void *
> +ring_buffer_event_data(struct ring_buffer_event *event)
> +{
> +	BUG_ON(event->type != RB_TYPE_DATA);
> +	/* If length is in len field, then array[0] has the data */
> +	if (event->len)
> +		return (void *)&event->array[0];
> +	/* Otherwise length is in array[0] and array[1] has the data */
> +	return (void *)&event->array[1];
> +}

ditto.

> +/* FIXME!!! */
> +u64 ring_buffer_time_stamp(int cpu)
> +{
> +	/* shift to debug/test normalization and TIME_EXTENTS */
> +	return sched_clock() << DEBUG_SHIFT;

[ duly noted ;-) ]

> +}
> +void ring_buffer_normalize_time_stamp(int cpu, u64 *ts)

needs extra newline above.

> +/*
> + * head_page == tail_page && head == tail then buffer is empty.
> + */
> +struct ring_buffer_per_cpu {
> +	int			cpu;
> +	struct ring_buffer	*buffer;
> +	raw_spinlock_t		lock;

hm, should not be raw, at least initially. I am 95% sure we'll see 
lockups, we always did when we iterated ftrace's buffer implementation 
;-)

> +struct ring_buffer {
> +	unsigned long		size;
> +	unsigned		pages;
> +	unsigned		flags;
> +	int			cpus;
> +	cpumask_t		cpumask;
> +	atomic_t		record_disabled;
> +
> +	struct mutex		mutex;
> +
> +	struct ring_buffer_per_cpu **buffers;
> +};
> +
> +struct ring_buffer_iter {
> +	struct ring_buffer_per_cpu	*cpu_buffer;
> +	unsigned long			head;
> +	struct buffer_page		*head_page;
> +	u64				read_stamp;

please use consistent vertical whitespaces.  Above, in the struct 
ring_buffer definition, you can add another tab to most of the vars - 
that will also make the '**buffers' line look nice.

same for all structs across this file. In my experience, a 50% vertical 
break works best - the one you used here in 'struct ring_buffer_iter'.

> +};
> +
> +#define CHECK_COND(buffer, cond)			\
> +	if (unlikely(cond)) {				\
> +		atomic_inc(&buffer->record_disabled);	\
> +		WARN_ON(1);				\
> +		return -1;				\
> +	}

please name it RINGBUFFER_BUG_ON() / RINGBUFFER_WARN_ON(), so that we 
dont have to memorize another set of debug names. [ See 
DEBUG_LOCKS_WARN_ON() in include/linux/debug_locks.h ]

you can change it to:

> +static int
> +rb_allocate_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned nr_pages)
> +{
> +	struct list_head *head = &cpu_buffer->pages;
> +	LIST_HEAD(pages);
> +	struct buffer_page *page, *tmp;
> +	unsigned long addr;
> +	unsigned i;

please apply ftrace's standard reverse christmas tree style and move the 
'pages' line down two lines.

> +int ring_buffer_resize(struct ring_buffer *buffer, unsigned long size)
> +{
> +	struct ring_buffer_per_cpu *cpu_buffer;
> +	unsigned long buffer_size;
> +	LIST_HEAD(pages);
> +	unsigned long addr;
> +	unsigned nr_pages, rm_pages, new_pages;
> +	struct buffer_page *page, *tmp;
> +	int i, cpu;

ditto.

> +static inline void *rb_page_index(struct buffer_page *page, unsigned index)
> +{
> +	void *addr;
> +
> +	addr = page_address(&page->page);

'addr' initialization can move to the definition line - you save two 
lines.

> +	return addr + index;
> +}
> +
> +static inline struct ring_buffer_event *
> +rb_head_event(struct ring_buffer_per_cpu *cpu_buffer)
> +{
> +	return rb_page_index(cpu_buffer->head_page,
> +			     cpu_buffer->head);

can all move to the same return line.

> +}
> +
> +static inline struct ring_buffer_event *
> +rb_iter_head_event(struct ring_buffer_iter *iter)
> +{
> +	return rb_page_index(iter->head_page,
> +			     iter->head);

ditto.

> +	for (head = 0; head < rb_head_size(cpu_buffer);
> +	     head += ring_buffer_event_length(event)) {
> +		event = rb_page_index(cpu_buffer->head_page, head);
> +		BUG_ON(rb_null_event(event));

( optional:when there's a multi-line loop then i generally try to insert 
  an extra newline when starting the body - to make sure the iterator 
  and the body stands apart visually. Matter of taste. )

> +static struct ring_buffer_event *
> +rb_reserve_next_event(struct ring_buffer_per_cpu *cpu_buffer,
> +		      unsigned type, unsigned long length)
> +{
> +	u64 ts, delta;
> +	struct ring_buffer_event *event;
> +	static int once;
> +
> +	ts = ring_buffer_time_stamp(cpu_buffer->cpu);
> +
> +	if (cpu_buffer->tail) {
> +		delta = ts - cpu_buffer->write_stamp;
> +
> +		if (test_time_stamp(delta)) {
> +			if (unlikely(delta > (1ULL << 59) && !once++)) {
> +				printk(KERN_WARNING "Delta way too big! %llu"
> +				       " ts=%llu write stamp = %llu\n",
> +				       delta, ts, cpu_buffer->write_stamp);
> +				WARN_ON(1);
> +			}
> +			/*
> +			 * The delta is too big, we to add a
> +			 * new timestamp.
> +			 */
> +			event = __rb_reserve_next(cpu_buffer,
> +						  RB_TYPE_TIME_EXTENT,
> +						  RB_LEN_TIME_EXTENT,
> +						  &ts);
> +			if (!event)
> +				return NULL;
> +
> +			/* check to see if we went to the next page */
> +			if (cpu_buffer->tail) {
> +				/* Still on same page, update timestamp */
> +				event->time_delta = delta & TS_MASK;
> +				event->array[0] = delta >> TS_SHIFT;
> +				/* commit the time event */
> +				cpu_buffer->tail +=
> +					ring_buffer_event_length(event);
> +				cpu_buffer->write_stamp = ts;
> +				delta = 0;
> +			}
> +		}
> +	} else {
> +		rb_add_stamp(cpu_buffer, &ts);
> +		delta = 0;
> +	}
> +
> +	event = __rb_reserve_next(cpu_buffer, type, length, &ts);
> +	if (!event)
> +		return NULL;
> +
> +	/* If the reserve went to the next page, our delta is zero */
> +	if (!cpu_buffer->tail)
> +		delta = 0;
> +
> +	event->time_delta = delta;
> +
> +	return event;
> +}

this function is too long, please split it up. The first condition's 
body could go into a separate function i guess.

> +	RB_TYPE_TIME_EXTENT,	/* Extent the time delta
> +				 * array[0] = time delta (28 .. 59)
> +				 * size = 8 bytes
> +				 */

please use standard comment style:

 /*
  * Comment
  */

	Ingo

  reply	other threads:[~2008-09-27 18:40 UTC|newest]

Thread overview: 102+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-25 18:51 [RFC PATCH 0/2 v3] " Steven Rostedt
2008-09-25 18:51 ` [RFC PATCH 1/2 " Steven Rostedt
2008-09-26  1:02   ` [RFC PATCH v4] " Steven Rostedt
2008-09-26  1:52     ` Masami Hiramatsu
2008-09-26  2:11       ` Steven Rostedt
2008-09-26  2:47         ` Masami Hiramatsu
2008-09-26  3:20         ` Mathieu Desnoyers
2008-09-26  7:18           ` Peter Zijlstra
2008-09-26 10:45             ` Steven Rostedt
2008-09-26 11:00               ` Peter Zijlstra
2008-09-26 16:57                 ` Masami Hiramatsu
2008-09-26 17:14                   ` Steven Rostedt
2008-09-26 10:47             ` Steven Rostedt
2008-09-26 16:04             ` Mathieu Desnoyers
2008-09-26 17:11       ` [PATCH v5] " Steven Rostedt
2008-09-26 17:31         ` Arnaldo Carvalho de Melo
2008-09-26 17:37           ` Linus Torvalds
2008-09-26 17:46             ` Steven Rostedt
2008-09-27 17:02               ` Ingo Molnar
2008-09-27 17:18                 ` Steven Rostedt
2008-09-26 18:05         ` [PATCH v6] " Steven Rostedt
2008-09-26 18:30           ` Richard Holden
2008-09-26 18:39             ` Steven Rostedt
2008-09-26 18:59           ` Peter Zijlstra
2008-09-26 19:46             ` Martin Bligh
2008-09-26 19:52               ` Steven Rostedt
2008-09-26 21:37               ` Steven Rostedt
2008-09-26 19:14           ` Peter Zijlstra
2008-09-26 22:28             ` Mike Travis
2008-09-26 23:56               ` Steven Rostedt
2008-09-27  0:05                 ` Mike Travis
2008-09-27  0:18                   ` Steven Rostedt
2008-09-27  0:46                     ` Mike Travis
2008-09-27  0:52                       ` Steven Rostedt
2008-09-26 19:17           ` Peter Zijlstra
2008-09-26 23:16             ` Arjan van de Ven
2008-09-26 20:08           ` Peter Zijlstra
2008-09-26 21:14             ` Masami Hiramatsu
2008-09-26 21:26               ` Steven Rostedt
2008-09-26 21:13           ` [PATCH v7] " Steven Rostedt
2008-09-27  2:02             ` [PATCH v8] " Steven Rostedt
2008-09-27  6:06               ` [PATCH v9] " Steven Rostedt
2008-09-27 18:39                 ` Ingo Molnar [this message]
2008-09-27 19:24                   ` Steven Rostedt
2008-09-27 19:41                     ` Ingo Molnar
2008-09-27 19:54                       ` Steven Rostedt
2008-09-27 20:00                         ` Ingo Molnar
2008-09-29 15:05                           ` Steven Rostedt
2008-09-27 20:07                         ` Martin Bligh
2008-09-27 20:34                           ` Ingo Molnar
2008-09-29 16:10                 ` [PATCH v10 Golden] " Steven Rostedt
2008-09-29 16:11                   ` Steven Rostedt
2008-09-29 23:35                   ` Mathieu Desnoyers
2008-09-30  0:01                     ` Steven Rostedt
2008-09-30  0:03                       ` Mathieu Desnoyers
2008-09-30  0:12                         ` Steven Rostedt
2008-09-30  3:46                           ` Mathieu Desnoyers
2008-09-30  4:00                             ` Steven Rostedt
2008-09-30 15:20                               ` Jonathan Corbet
2008-09-30 15:54                                 ` Peter Zijlstra
2008-09-30 16:38                                   ` Linus Torvalds
2008-09-30 16:48                                     ` Steven Rostedt
2008-09-30 17:00                                       ` Peter Zijlstra
2008-09-30 17:41                                         ` Steven Rostedt
2008-09-30 17:49                                           ` Peter Zijlstra
2008-09-30 17:56                                             ` Steven Rostedt
2008-09-30 18:02                                               ` Steven Rostedt
2008-09-30 17:01                                       ` Linus Torvalds
2008-10-01 15:14                                         ` [PATCH] ring_buffer: allocate buffer page pointer Steven Rostedt
2008-10-01 17:36                                           ` Mathieu Desnoyers
2008-10-01 17:49                                             ` Steven Rostedt
2008-10-01 18:21                                           ` Mathieu Desnoyers
2008-10-02  8:50                                           ` Ingo Molnar
2008-10-02  8:51                                             ` Ingo Molnar
2008-10-02  9:05                                               ` [PATCH] ring-buffer: fix build error Ingo Molnar
2008-10-02  9:38                                                 ` [boot crash] " Ingo Molnar
2008-10-02 13:16                                                   ` Steven Rostedt
2008-10-02 13:17                                                   ` Steven Rostedt
2008-10-02 15:50                                                     ` Ingo Molnar
2008-10-02 18:27                                                       ` Steven Rostedt
2008-10-02 18:55                                                         ` Ingo Molnar
2008-10-02 23:18                                                   ` [PATCH] ring_buffer: map to cpu not page Steven Rostedt
2008-10-02 23:36                                                     ` Steven Rostedt
2008-10-03  4:56                                                     ` [PATCH] x86 Topology cpu_to_node parameter check Mathieu Desnoyers
2008-10-03  5:20                                                       ` Steven Rostedt
2008-10-03 15:56                                                         ` Mathieu Desnoyers
2008-10-03 16:26                                                           ` Steven Rostedt
2008-10-03 17:21                                                             ` Mathieu Desnoyers
2008-10-03 17:54                                                               ` Steven Rostedt
2008-10-03 18:53                                                                 ` [PATCH] topology.h define mess fix Mathieu Desnoyers
2008-10-03 20:14                                                                   ` Luck, Tony
2008-10-03 22:47                                                                     ` [PATCH] topology.h define mess fix v2 Mathieu Desnoyers
2008-10-03  7:27                                                     ` [PATCH] ring_buffer: map to cpu not page Ingo Molnar
2008-10-02  9:06                                             ` [PATCH] ring_buffer: allocate buffer page pointer Andrew Morton
2008-10-02  9:41                                               ` Ingo Molnar
2008-10-02 13:06                                               ` Steven Rostedt
2008-09-26 22:31           ` [PATCH v6] Unified trace buffer Arnaldo Carvalho de Melo
2008-09-26 23:58             ` Steven Rostedt
2008-09-27  0:13               ` Linus Torvalds
2008-09-27  0:23                 ` Steven Rostedt
2008-09-27  0:28                   ` Steven Rostedt
2008-09-25 18:51 ` [RFC PATCH 2/2 v3] ftrace: make work with new ring buffer Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080927183912.GA13685@elte.hu \
    --to=mingo@elte.hu \
    --cc=acme@ghostprotocols.net \
    --cc=akpm@linux-foundation.org \
    --cc=compudj@krystal.dyndns.org \
    --cc=dwilder@us.ibm.com \
    --cc=fche@redhat.com \
    --cc=hch@infradead.org \
    --cc=hch@lst.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mbligh@google.com \
    --cc=mhiramat@redhat.com \
    --cc=peterz@infradead.org \
    --cc=prasad@linux.vnet.ibm.com \
    --cc=rostedt@goodmis.org \
    --cc=srostedt@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome