* [PATCH 0/2] [GIT PULL] ring-buffer: fixes suggested by Andrew
@ 2009-05-08 16:20 Steven Rostedt
2009-05-08 16:20 ` [PATCH 1/2] ring-buffer: replace constants with time macros in ring-buffer-benchmark Steven Rostedt
2009-05-08 16:20 ` [PATCH 2/2] ring-buffer: check for divide by zero " Steven Rostedt
0 siblings, 2 replies; 3+ messages in thread
From: Steven Rostedt @ 2009-05-08 16:20 UTC (permalink / raw)
To: linux-kernel; +Cc: Ingo Molnar, Andrew Morton
Ingo,
Please pull the latest tip/tracing/ftrace tree, which can be found at:
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-2.6-trace.git
tip/tracing/ftrace
Steven Rostedt (2):
ring-buffer: replace constants with time macros in ring-buffer-benchmark
ring-buffer: check for divide by zero in ring-buffer-benchmark
----
kernel/trace/ring_buffer_benchmark.c | 18 +++++++++++++-----
1 files changed, 13 insertions(+), 5 deletions(-)
--
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 1/2] ring-buffer: replace constants with time macros in ring-buffer-benchmark
2009-05-08 16:20 [PATCH 0/2] [GIT PULL] ring-buffer: fixes suggested by Andrew Steven Rostedt
@ 2009-05-08 16:20 ` Steven Rostedt
2009-05-08 16:20 ` [PATCH 2/2] ring-buffer: check for divide by zero " Steven Rostedt
1 sibling, 0 replies; 3+ messages in thread
From: Steven Rostedt @ 2009-05-08 16:20 UTC (permalink / raw)
To: linux-kernel; +Cc: Ingo Molnar, Andrew Morton
[-- Attachment #1: 0001-ring-buffer-replace-constants-with-time-macros-in-r.patch --]
[-- Type: text/plain, Size: 1805 bytes --]
From: Steven Rostedt <srostedt@redhat.com>
The use of numeric constants is discouraged. It is cleaner and more
descriptive to use macros for constant time conversions.
This patch also removes an extra new line.
[ Impact: more descriptive time conversions ]
Reported-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
kernel/trace/ring_buffer_benchmark.c | 12 +++++++-----
1 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/kernel/trace/ring_buffer_benchmark.c b/kernel/trace/ring_buffer_benchmark.c
index a21aa7b..7d3aef9 100644
--- a/kernel/trace/ring_buffer_benchmark.c
+++ b/kernel/trace/ring_buffer_benchmark.c
@@ -253,7 +253,7 @@ static void ring_buffer_producer(void)
}
time = end_tv.tv_sec - start_tv.tv_sec;
- time *= 1000000;
+ time *= USEC_PER_SEC;
time += (long long)((long)end_tv.tv_usec - (long)start_tv.tv_usec);
entries = ring_buffer_entries(buffer);
@@ -273,7 +273,8 @@ static void ring_buffer_producer(void)
pr_info("Missed: %ld\n", missed);
pr_info("Hit: %ld\n", hit);
- do_div(time, 1000);
+ /* Convert time from usecs to millisecs */
+ do_div(time, USEC_PER_MSEC);
if (time)
hit /= (long)time;
else
@@ -282,18 +283,19 @@ static void ring_buffer_producer(void)
pr_info("Entries per millisec: %ld\n", hit);
if (hit) {
- avg = 1000000 / hit;
+ /* Calculate the average time in nanosecs */
+ avg = NSEC_PER_MSEC / hit;
pr_info("%ld ns per entry\n", avg);
}
-
if (missed) {
if (time)
missed /= (long)time;
pr_info("Total iterations per millisec: %ld\n", hit + missed);
- avg = 1000000 / (hit + missed);
+ /* Caculate the average time in nanosecs */
+ avg = NSEC_PER_MSEC / (hit + missed);
pr_info("%ld ns per entry\n", avg);
}
}
--
1.6.2.4
--
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] ring-buffer: check for divide by zero in ring-buffer-benchmark
2009-05-08 16:20 [PATCH 0/2] [GIT PULL] ring-buffer: fixes suggested by Andrew Steven Rostedt
2009-05-08 16:20 ` [PATCH 1/2] ring-buffer: replace constants with time macros in ring-buffer-benchmark Steven Rostedt
@ 2009-05-08 16:20 ` Steven Rostedt
1 sibling, 0 replies; 3+ messages in thread
From: Steven Rostedt @ 2009-05-08 16:20 UTC (permalink / raw)
To: linux-kernel; +Cc: Ingo Molnar, Andrew Morton
[-- Attachment #1: 0002-ring-buffer-check-for-divide-by-zero-in-ring-buffer.patch --]
[-- Type: text/plain, Size: 1266 bytes --]
From: Steven Rostedt <srostedt@redhat.com>
Although we check if "missed" is not zero, we divide by hit + missed,
and the addition can possible overflow and become a divide by zero.
This patch checks for this case, and will report it when it happens
then modify "hit" to make the calculation be non zero.
[ Impact: prevent possible divide by zero in ring-buffer-benchmark ]
Reported-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
kernel/trace/ring_buffer_benchmark.c | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/kernel/trace/ring_buffer_benchmark.c b/kernel/trace/ring_buffer_benchmark.c
index 7d3aef9..8d68e14 100644
--- a/kernel/trace/ring_buffer_benchmark.c
+++ b/kernel/trace/ring_buffer_benchmark.c
@@ -294,6 +294,12 @@ static void ring_buffer_producer(void)
pr_info("Total iterations per millisec: %ld\n", hit + missed);
+ /* it is possible that hit + missed will overflow and be zero */
+ if (!(hit + missed)) {
+ pr_info("hit + missed overflowed and totalled zero!\n");
+ hit--; /* make it non zero */
+ }
+
/* Caculate the average time in nanosecs */
avg = NSEC_PER_MSEC / (hit + missed);
pr_info("%ld ns per entry\n", avg);
--
1.6.2.4
--
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-05-08 16:22 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-05-08 16:20 [PATCH 0/2] [GIT PULL] ring-buffer: fixes suggested by Andrew Steven Rostedt
2009-05-08 16:20 ` [PATCH 1/2] ring-buffer: replace constants with time macros in ring-buffer-benchmark Steven Rostedt
2009-05-08 16:20 ` [PATCH 2/2] ring-buffer: check for divide by zero " Steven Rostedt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox