Skip to contentSkip to conversation

tracing: couple of minor fixies

PATCH In review Jiri Olsa 2 participants 12 messages Oct 21, 2009 – Oct 22, 2009

Subsystems (4)
lore
Share & tools
lore

Jiri Olsa

author
#0 lore raw

cover tracing: couple of minor fixies

Hi,

sending few minor fixes.

1/4 - tracing: updating *ppos instead of filp->f_pos 2/4 - tracing: fix trace_seq_printf return value 3/4 - tracing: comment typo and documentation example fix 4/4 - tracing: removing cpu arg from rb_time_stamp function

wbr,
jirka

---
 Documentation/trace/ftrace.txt |    2 ++
 include/linux/trace_seq.h      |    2 +-
 kernel/trace/ftrace.c          |    2 +-
 kernel/trace/ring_buffer.c     |   12 ++++++------
 kernel/trace/trace.c           |    8 ++++----
 kernel/trace/trace_output.c    |    2 +-
 6 files changed, 15 insertions(+), 13 deletions(-)
author
#1 lore raw

PATCH 1/4 tracing: updating *ppos instead of filp->f_pos

Instead of direct updating filp->f_pos we should update *ppos argument. The filp->f_pos gets updated within the file_pos_write function called from sys_write.

wbr,
jirka

---
 kernel/trace/ftrace.c |    2 +-
 kernel/trace/trace.c  |    8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)
kernel/trace/ftrace.c +1 -1
index b10c0d9..1ed514f 100644
@@ -751,7 +751,7 @@ ftrace_profile_write(struct file *filp, const char __user *ubuf,
  out:
 	mutex_unlock(&ftrace_profile_lock);
 
-	filp->f_pos += cnt;
+	*ppos += cnt;
 
 	return cnt;
 }
kernel/trace/trace.c +4 -4
index 026e715..9d3067a 100644
@@ -2440,7 +2440,7 @@ tracing_trace_options_write(struct file *filp, const char __user *ubuf,
 			return ret;
 	}
 
-	filp->f_pos += cnt;
+	*ppos += cnt;
 
 	return cnt;
 }
@@ -2582,7 +2582,7 @@ tracing_ctrl_write(struct file *filp, const char __user *ubuf,
 	}
 	mutex_unlock(&trace_types_lock);
 
-	filp->f_pos += cnt;
+	*ppos += cnt;
 
 	return cnt;
 }
@@ -2764,7 +2764,7 @@ tracing_set_trace_write(struct file *filp, const char __user *ubuf,
 	if (err)
 		return err;
 
-	filp->f_pos += ret;
+	*ppos += ret;
 
 	return ret;
 }
@@ -3299,7 +3299,7 @@ tracing_entries_write(struct file *filp, const char __user *ubuf,
 		}
 	}
 
-	filp->f_pos += cnt;
+	*ppos += cnt;
 
 	/* If check pages failed, return ENOMEM */
 	if (tracing_disabled)
Signature · 1 line
1.6.2.5
author
#2 lore raw

PATCH 2/4 tracing: fix trace_seq_printf return value

In reply to Jiri Olsa

I believe we want to return the number of written characters, instead of the available buffer length.

wbr,
jirka

---
 kernel/trace/trace_output.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/trace/trace_output.c +1 -1
index ed17565..e871125 100644
@@ -95,7 +95,7 @@ trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
 
 	s->len += ret;
 
-	return len;
+	return ret;
 }
 EXPORT_SYMBOL_GPL(trace_seq_printf);
 
Signature · 1 line
1.6.2.5
maintainer
#3 lore raw

Re: [PATCH 2/4] tracing: fix trace_seq_printf return value

Quoted 16 lines · Jiri Olsa

I believe we want to return the number of written characters, instead of the available buffer length.

wbr,
jirka

---
 kernel/trace/trace_output.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/trace/trace_output.c +0 -0
index ed17565..e871125 100644

kernel/trace/trace_output.c trace_seq_printf(struct trace_seq *s, const char *fmt, ...) · line 98

Quoted 5 lines
kernel/trace/trace_output.c +1 -1
@@ -95,7 +95,7 @@ trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
 
 	s->len += ret;
 
-	return len;
+	return ret;

Actually the return value here is ambiguous. Returning len is actually safer. It probably should only return 0 (buffer not big enough to write to) or 1 (buffer is big enough).

Because this should actually return non zero:

  trace_seq_printf(s, "");

-- Steve

Quoted 3 lines
kernel/trace/trace_output.c +0 -0
 }
 EXPORT_SYMBOL_GPL(trace_seq_printf);
 
author
#4 lore raw

Re: [PATCH 2/4] tracing: fix trace_seq_printf return value

Quoted 27 lines · Steven Rostedt
Quoted 16 lines · Jiri Olsa

I believe we want to return the number of written characters, instead of the available buffer length.

wbr,
jirka

---
 kernel/trace/trace_output.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/trace/trace_output.c +0 -0
index ed17565..e871125 100644

kernel/trace/trace_output.c trace_seq_printf(struct trace_seq *s, const char *fmt, ...) · line 98

Quoted 5 lines
kernel/trace/trace_output.c +1 -1
@@ -95,7 +95,7 @@ trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
 
 	s->len += ret;
 
-	return len;
+	return ret;

Actually the return value here is ambiguous. Returning len is actually safer. It probably should only return 0 (buffer not big enough to write to) or 1 (buffer is big enough).

Quoted 10 lines

Because this should actually return non zero:

  trace_seq_printf(s, "");

-- Steve

Quoted 3 lines
kernel/trace/trace_output.c +0 -0
 }
 EXPORT_SYMBOL_GPL(trace_seq_printf);
 

I made the suggested fix, plus spot not used function.

---
Making trace_seq_printf return 0 if the trace oversizes the buffer's free space, 1 otherwise. Removing not used trace_seq_vprintf function.

wbr,
jirka

---
 include/linux/trace_seq.h   |    2 --
 kernel/trace/trace_output.c |   37 ++++---------------------------------
 2 files changed, 4 insertions(+), 35 deletions(-)
include/linux/trace_seq.h +0 -2
index c134dd1..6fc4651 100644
@@ -29,8 +29,6 @@ trace_seq_init(struct trace_seq *s)
 #ifdef CONFIG_TRACING
 extern int trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
 	__attribute__ ((format (printf, 2, 3)));
-extern int trace_seq_vprintf(struct trace_seq *s, const char *fmt, va_list args)
-	__attribute__ ((format (printf, 2, 0)));
 extern int
 trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary);
 extern void trace_print_seq(struct seq_file *m, struct trace_seq *s);
kernel/trace/trace_output.c +4 -33
index ed17565..11bd0e5 100644
@@ -69,6 +69,9 @@ enum print_line_t trace_print_printk_msg_only(struct trace_iterator *iter)
  * @s: trace sequence descriptor
  * @fmt: printf format string
  *
+ * It returns 0 if the trace oversizes the buffer's free
+ * space, 1 otherwise.
+ *
  * The tracer may use either sequence operations or its own
  * copy to user routines. To simplify formating of a trace
  * trace_seq_printf is used to store strings into a special
@@ -95,42 +98,10 @@ trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
 
 	s->len += ret;
 
-	return len;
+	return 1;
 }
 EXPORT_SYMBOL_GPL(trace_seq_printf);
 
-/**
- * trace_seq_vprintf - sequence printing of trace information
- * @s: trace sequence descriptor
- * @fmt: printf format string
- *
- * The tracer may use either sequence operations or its own
- * copy to user routines. To simplify formating of a trace
- * trace_seq_printf is used to store strings into a special
- * buffer (@s). Then the output may be either used by
- * the sequencer or pulled into another buffer.
- */
-int
-trace_seq_vprintf(struct trace_seq *s, const char *fmt, va_list args)
-{
-	int len = (PAGE_SIZE - 1) - s->len;
-	int ret;
-
-	if (!len)
-		return 0;
-
-	ret = vsnprintf(s->buffer + s->len, len, fmt, args);
-
-	/* If we can't write it all, don't bother writing anything */
-	if (ret >= len)
-		return 0;
-
-	s->len += ret;
-
-	return len;
-}
-EXPORT_SYMBOL_GPL(trace_seq_vprintf);
-
 int trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary)
 {
 	int len = (PAGE_SIZE - 1) - s->len;
maintainer
#5 lore raw

Re: [PATCH 2/4] tracing: fix trace_seq_printf return value

Quoted 39 lines · Jiri Olsa
Quoted 27 lines · Steven Rostedt
Quoted 16 lines · Jiri Olsa

I believe we want to return the number of written characters, instead of the available buffer length.

wbr,
jirka

---
 kernel/trace/trace_output.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/trace/trace_output.c +0 -0
index ed17565..e871125 100644

kernel/trace/trace_output.c trace_seq_printf(struct trace_seq *s, const char *fmt, ...) · line 98

Quoted 5 lines
kernel/trace/trace_output.c +1 -1
@@ -95,7 +95,7 @@ trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
 
 	s->len += ret;
 
-	return len;
+	return ret;

Actually the return value here is ambiguous. Returning len is actually safer. It probably should only return 0 (buffer not big enough to write to) or 1 (buffer is big enough).

Quoted 10 lines

Because this should actually return non zero:

  trace_seq_printf(s, "");

-- Steve

Quoted 3 lines
kernel/trace/trace_output.c +0 -0
 }
 EXPORT_SYMBOL_GPL(trace_seq_printf);
 
Quoted 5 lines

I made the suggested fix, plus spot not used function.

---
Making trace_seq_printf return 0 if the trace oversizes the buffer's free space, 1 otherwise. Removing not used trace_seq_vprintf function.

err, I hate to remove that function. This is a utility file that is exported for other parts of the kernel to use. At least make that a separate patch.

-- Steve

author
#6 lore raw

Re: [PATCH 2/4] tracing: fix trace_seq_printf return value

Quoted 42 lines · Steven Rostedt
Quoted 41 lines · Jiri Olsa
Quoted 27 lines · Steven Rostedt
Quoted 16 lines · Jiri Olsa

I believe we want to return the number of written characters, instead of the available buffer length.

wbr,
jirka

---
 kernel/trace/trace_output.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/trace/trace_output.c +0 -0
index ed17565..e871125 100644

kernel/trace/trace_output.c trace_seq_printf(struct trace_seq *s, const char *fmt, ...) · line 98

Quoted 5 lines
kernel/trace/trace_output.c +1 -1
@@ -95,7 +95,7 @@ trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
 
 	s->len += ret;
 
-	return len;
+	return ret;

Actually the return value here is ambiguous. Returning len is actually safer. It probably should only return 0 (buffer not big enough to write to) or 1 (buffer is big enough).

Quoted 10 lines

Because this should actually return non zero:

  trace_seq_printf(s, "");

-- Steve

Quoted 3 lines
kernel/trace/trace_output.c +0 -0
 }
 EXPORT_SYMBOL_GPL(trace_seq_printf);
 

I made the suggested fix, plus spot not used function.

Quoted 7 lines
Quoted 3 lines

---
Making trace_seq_printf return 0 if the trace oversizes the buffer's free space, 1 otherwise. Removing not used trace_seq_vprintf function.

err, I hate to remove that function. This is a utility file that is exported for other parts of the kernel to use. At least make that a separate patch.

np, sending out just the first part

jirka

---

Making trace_seq_printf return 0 if the trace oversizes the buffer's free space, 1 otherwise.

wbr,
jirka

---

kernel/trace/trace_output.c +4 -1
index ed17565..b6c12c6 100644
@@ -69,6 +69,9 @@ enum print_line_t trace_print_printk_msg_only(struct trace_iterator *iter)
  * @s: trace sequence descriptor
  * @fmt: printf format string
  *
+ * It returns 0 if the trace oversizes the buffer's free
+ * space, 1 otherwise.
+ *
  * The tracer may use either sequence operations or its own
  * copy to user routines. To simplify formating of a trace
  * trace_seq_printf is used to store strings into a special
@@ -95,7 +98,7 @@ trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
 
 	s->len += ret;
 
-	return len;
+	return 1;
 }
 EXPORT_SYMBOL_GPL(trace_seq_printf);
 
maintainer
#7 lore raw

Re: [PATCH 2/4] tracing: fix trace_seq_printf return value

Quoted 4 lines · Jiri Olsa
Quoted 3 lines

err, I hate to remove that function. This is a utility file that is exported for other parts of the kernel to use. At least make that a separate patch.

np, sending out just the first part

Thanks, I'll pull you patches in today and queue them up for 2.6.33.

-- Steve

author
#8 lore raw

PATCH 3/4 tracing: comment typo and documentation example fix

In reply to Jiri Olsa
---
 Documentation/trace/ftrace.txt |    2 ++
 kernel/trace/ring_buffer.c     |    2 +-
 2 files changed, 3 insertions(+), 1 deletions(-)
Documentation/trace/ftrace.txt +2 -0
index 957b22f..8179692 100644
@@ -1231,6 +1231,7 @@ something like this simple program:
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <unistd.h>
+#include <string.h>
 
 #define _STR(x) #x
 #define STR(x) _STR(x)
@@ -1265,6 +1266,7 @@ const char *find_debugfs(void)
                return NULL;
        }
 
+       strcat(debugfs, "/tracing/");
        debugfs_found = 1;
 
        return debugfs;
kernel/trace/ring_buffer.c +1 -1
index e43c928..d33e5ca 100644
@@ -2684,7 +2684,7 @@ unsigned long ring_buffer_entries(struct ring_buffer *buffer)
 EXPORT_SYMBOL_GPL(ring_buffer_entries);
 
 /**
- * ring_buffer_overrun_cpu - get the number of overruns in buffer
+ * ring_buffer_overruns - get the number of overruns in buffer
  * @buffer: The ring buffer
  *
  * Returns the total number of overruns in the ring buffer
Signature · 1 line
1.6.2.5
author
#9 lore raw

PATCH 4/4 tracing: removing cpu arg from rb_time_stamp function

In reply to Jiri Olsa

The cpu argument is not used inside rb_time_stamp function. Plus typo fix.

---
 include/linux/trace_seq.h  |    2 +-
 kernel/trace/ring_buffer.c |   10 +++++-----
 2 files changed, 6 insertions(+), 6 deletions(-)
include/linux/trace_seq.h +1 -1
index c134dd1..09077f6 100644
@@ -7,7 +7,7 @@
 
 /*
  * Trace sequences are used to allow a function to call several other functions
- * to create a string of data to use (up to a max of PAGE_SIZE.
+ * to create a string of data to use (up to a max of PAGE_SIZE).
  */
 
 struct trace_seq {
kernel/trace/ring_buffer.c +5 -5
index d33e5ca..63446f1 100644
@@ -486,7 +486,7 @@ struct ring_buffer_iter {
 /* Up this if you want to test the TIME_EXTENTS and normalization */
 #define DEBUG_SHIFT 0
 
-static inline u64 rb_time_stamp(struct ring_buffer *buffer, int cpu)
+static inline u64 rb_time_stamp(struct ring_buffer *buffer)
 {
 	/* shift to debug/test normalization and TIME_EXTENTS */
 	return buffer->clock() << DEBUG_SHIFT;
@@ -497,7 +497,7 @@ u64 ring_buffer_time_stamp(struct ring_buffer *buffer, int cpu)
 	u64 time;
 
 	preempt_disable_notrace();
-	time = rb_time_stamp(buffer, cpu);
+	time = rb_time_stamp(buffer);
 	preempt_enable_no_resched_notrace();
 
 	return time;
@@ -602,7 +602,7 @@ static struct list_head *rb_list_head(struct list_head *list)
 }
 
 /*
- * rb_is_head_page - test if the give page is the head page
+ * rb_is_head_page - test if the given page is the head page
  *
  * Because the reader may move the head_page pointer, we can
  * not trust what the head page is (it may be pointing to
@@ -1871,7 +1871,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
 		 * Nested commits always have zero deltas, so
 		 * just reread the time stamp
 		 */
-		*ts = rb_time_stamp(buffer, cpu_buffer->cpu);
+		*ts = rb_time_stamp(buffer);
 		next_page->page->time_stamp = *ts;
 	}
 
@@ -2114,7 +2114,7 @@ rb_reserve_next_event(struct ring_buffer *buffer,
 	if (RB_WARN_ON(cpu_buffer, ++nr_loops > 1000))
 		goto out_fail;
 
-	ts = rb_time_stamp(cpu_buffer->buffer, cpu_buffer->cpu);
+	ts = rb_time_stamp(cpu_buffer->buffer);
 
 	/*
 	 * Only the first commit can update the timestamp.
Signature · 1 line
1.6.2.5
maintainer
#10 lore raw

Re: [PATCH 4/4] tracing: removing cpu arg from rb_time_stamp function

Quoted 35 lines · Jiri Olsa

The cpu argument is not used inside rb_time_stamp function. Plus typo fix.

---
 include/linux/trace_seq.h  |    2 +-
 kernel/trace/ring_buffer.c |   10 +++++-----
 2 files changed, 6 insertions(+), 6 deletions(-)
include/linux/trace_seq.h +1 -1
index c134dd1..09077f6 100644
@@ -7,7 +7,7 @@
 
 /*
  * Trace sequences are used to allow a function to call several other functions
- * to create a string of data to use (up to a max of PAGE_SIZE.
+ * to create a string of data to use (up to a max of PAGE_SIZE).
  */
 
 struct trace_seq {
kernel/trace/ring_buffer.c +1 -1
index d33e5ca..63446f1 100644
@@ -486,7 +486,7 @@ struct ring_buffer_iter {
 /* Up this if you want to test the TIME_EXTENTS and normalization */
 #define DEBUG_SHIFT 0
 
-static inline u64 rb_time_stamp(struct ring_buffer *buffer, int cpu)
+static inline u64 rb_time_stamp(struct ring_buffer *buffer)
 {
 	/* shift to debug/test normalization and TIME_EXTENTS */
 	return buffer->clock() << DEBUG_SHIFT;

kernel/trace/ring_buffer.c u64 ring_buffer_time_stamp(struct ring_buffer *buffer, int cpu) · line 500

Quoted 5 lines
kernel/trace/ring_buffer.c +1 -1
@@ -497,7 +497,7 @@ u64 ring_buffer_time_stamp(struct ring_buffer *buffer, int cpu)
 	u64 time;
 
 	preempt_disable_notrace();
-	time = rb_time_stamp(buffer, cpu);
+	time = rb_time_stamp(buffer);

Yeah, originally this was to deal with cpu_clock() which takes cpu as its parameter. But we now just call "raw_smp_processor_id" instead directly when using cpu_clock.

Thanks,

-- Steve

Quoted 6 lines
kernel/trace/ring_buffer.c +0 -0
 	preempt_enable_no_resched_notrace();
 
 	return time;
@@ -602,7 +602,7 @@ static struct list_head *rb_list_head(struct list_head *list)
 }
 
maintainer
#11 lore raw
In reply to Jiri Olsa
Quoted 8 lines · Jiri Olsa

Hi,

sending few minor fixes.

1/4 - tracing: updating *ppos instead of filp->f_pos 2/4 - tracing: fix trace_seq_printf return value 3/4 - tracing: comment typo and documentation example fix 4/4 - tracing: removing cpu arg from rb_time_stamp function

Thanks,

I'll take 1,3 and 4. As 2 we should change it to return 0 or 1 and add a comment to the use of it.

-- Steve