tracing: kill some magic numbers
Subsystems (2)
PATCH 1/1 tracing: kill some magic numbers
Impact: cleanup
Use USEC_PER_SEC and NSEC_PER_SEC instead of 1000000 and 1000000000.
--- kernel/trace/trace_boot.c | 5 +++-- kernel/trace/trace_mmiotrace.c | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-)
kernel/trace/trace_boot.c +3 -2
@@ -9,6 +9,7 @@#include <linux/debugfs.h> #include <linux/ftrace.h> #include <linux/kallsyms.h> +#include <linux/time.h> #include "trace.h" #include "trace_output.h"
@@ -67,7 +68,7 @@ initcall_call_print_line(struct trace_iterator *iter)trace_assign_type (field, entry); call = &field->boot_call; ts = iter->ts; - nsec_rem =do_div (ts,1000000000 ); + nsec_rem =do_div (ts,NSEC_PER_SEC ); ret =trace_seq_printf (s,"[%5ld.%09ld] calling %s @ %i\n" , (unsigned long )ts, nsec_rem, call->func, call->caller);
@@ -92,7 +93,7 @@ initcall_ret_print_line(struct trace_iterator *iter)trace_assign_type (field, entry); init_ret = &field->boot_ret; ts = iter->ts; - nsec_rem =do_div (ts,1000000000 ); + nsec_rem =do_div (ts,NSEC_PER_SEC ); ret = trace_seq_printf(s, "[%5ld.%09ld] initcall %s " "returned %d after %llu msecs\n",
kernel/trace/trace_mmiotrace.c +4 -2
@@ -9,6 +9,8 @@#include <linux/kernel.h> #include <linux/mmiotrace.h> #include <linux/pci.h> +#include <linux/time.h> +#include <asm/atomic.h> #include "trace.h"
@@ -174,7 +176,7 @@ static enum print_line_t mmio_print_rw(struct trace_iterator *iter)struct mmiotrace_rw *rw;struct trace_seq *s = &iter->seq;unsigned long long t =ns2usecs (iter->ts); -unsigned long usec_rem =do_div (t,1000000ULL ); +unsigned long usec_rem =do_div (t,USEC_PER_SEC );unsigned secs = (unsigned long )t;int ret =1 ;
@@ -221,7 +223,7 @@ static enum print_line_t mmio_print_map(struct trace_iterator *iter)struct mmiotrace_map *m;struct trace_seq *s = &iter->seq;unsigned long long t =ns2usecs (iter->ts); -unsigned long usec_rem =do_div (t,1000000ULL ); +unsigned long usec_rem =do_div (t,USEC_PER_SEC );unsigned secs = (unsigned long )t;int ret;
Signature · 1 line
1.5.4.rc3
Quoted 73 lines · Li Zefan
Impact: cleanup
Use
USEC_PER_SECandNSEC_PER_SECinstead of 1000000 and 1000000000.Signed-off-by Li Zefan <[email protected]>--- kernel/trace/trace_boot.c | 5 +++-- kernel/trace/trace_mmiotrace.c | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-)kernel/trace/trace_boot.c +3
-2@@ -9,6 +9,7 @@#include <linux/debugfs.h> #include <linux/ftrace.h> #include <linux/kallsyms.h> +#include <linux/time.h> #include "trace.h" #include "trace_output.h" @@ -67,7 +68,7 @@ initcall_call_print_line(struct trace_iterator *iter)trace_assign_type (field, entry); call = &field->boot_call; ts = iter->ts; - nsec_rem =do_div (ts,1000000000 ); + nsec_rem =do_div (ts,NSEC_PER_SEC ); ret =trace_seq_printf (s,"[%5ld.%09ld] calling %s @ %i\n" , (unsigned long )ts, nsec_rem, call->func, call->caller);@@ -92,7 +93,7 @@ initcall_ret_print_line(struct trace_iterator *iter)trace_assign_type (field, entry); init_ret = &field->boot_ret; ts = iter->ts; - nsec_rem =do_div (ts,1000000000 ); + nsec_rem =do_div (ts,NSEC_PER_SEC ); ret = trace_seq_printf(s, "[%5ld.%09ld] initcall %s " "returned %d after %llu msecs\n",kernel/trace/trace_mmiotrace.c +4
-2@@ -9,6 +9,8 @@#include <linux/kernel.h> #include <linux/mmiotrace.h> #include <linux/pci.h> +#include <linux/time.h> +#include <asm/atomic.h> #include "trace.h" @@ -174,7 +176,7 @@ static enum print_line_t mmio_print_rw(struct trace_iterator *iter)struct mmiotrace_rw *rw;struct trace_seq *s = &iter->seq;unsigned long long t =ns2usecs (iter->ts); -unsigned long usec_rem =do_div (t,1000000ULL ); +unsigned long usec_rem =do_div (t,USEC_PER_SEC );unsigned secs = (unsigned long )t;int ret =1 ;@@ -221,7 +223,7 @@ static enum print_line_t mmio_print_map(struct trace_iterator *iter)struct mmiotrace_map *m;struct trace_seq *s = &iter->seq;unsigned long long t =ns2usecs (iter->ts); -unsigned long usec_rem =do_div (t,1000000ULL ); +unsigned long usec_rem =do_div (t,USEC_PER_SEC );unsigned secs = (unsigned long )t;int ret;Signature · 1 line
1.5.4.rc3
Thanks!
Quoted 4 lines · Frederic Weisbecker
Quoted 3 lines · Li Zefan
Impact: cleanup
Use
USEC_PER_SECandNSEC_PER_SECinstead of 1000000 and 1000000000.
Nothing against the patch, but the subject is a bit misleading. I was expecting to see removals of "64" or some other "magic" numbers.
But 1000000 and 1000000000 are not magic numbers. They are known constants that represent usecs per second and nsecs per second.
I know this is just a nit, but the subject should have been
tracing: replace number constants with meaningful names
But for the patch itself...
-- Steve
Quoted 77 lines
Quoted 70 lines
Signed-off-by Li Zefan <[email protected]>--- kernel/trace/trace_boot.c | 5 +++-- kernel/trace/trace_mmiotrace.c | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-)kernel/trace/trace_boot.c +3
-2@@ -9,6 +9,7 @@#include <linux/debugfs.h> #include <linux/ftrace.h> #include <linux/kallsyms.h> +#include <linux/time.h> #include "trace.h" #include "trace_output.h" @@ -67,7 +68,7 @@ initcall_call_print_line(struct trace_iterator *iter)trace_assign_type (field, entry); call = &field->boot_call; ts = iter->ts; - nsec_rem =do_div (ts,1000000000 ); + nsec_rem =do_div (ts,NSEC_PER_SEC ); ret =trace_seq_printf (s,"[%5ld.%09ld] calling %s @ %i\n" , (unsigned long )ts, nsec_rem, call->func, call->caller);@@ -92,7 +93,7 @@ initcall_ret_print_line(struct trace_iterator *iter)trace_assign_type (field, entry); init_ret = &field->boot_ret; ts = iter->ts; - nsec_rem =do_div (ts,1000000000 ); + nsec_rem =do_div (ts,NSEC_PER_SEC ); ret = trace_seq_printf(s, "[%5ld.%09ld] initcall %s " "returned %d after %llu msecs\n",kernel/trace/trace_mmiotrace.c +4
-2@@ -9,6 +9,8 @@#include <linux/kernel.h> #include <linux/mmiotrace.h> #include <linux/pci.h> +#include <linux/time.h> +#include <asm/atomic.h> #include "trace.h" @@ -174,7 +176,7 @@ static enum print_line_t mmio_print_rw(struct trace_iterator *iter)struct mmiotrace_rw *rw;struct trace_seq *s = &iter->seq;unsigned long long t =ns2usecs (iter->ts); -unsigned long usec_rem =do_div (t,1000000ULL ); +unsigned long usec_rem =do_div (t,USEC_PER_SEC );unsigned secs = (unsigned long )t;int ret =1 ;@@ -221,7 +223,7 @@ static enum print_line_t mmio_print_map(struct trace_iterator *iter)struct mmiotrace_map *m;struct trace_seq *s = &iter->seq;unsigned long long t =ns2usecs (iter->ts); -unsigned long usec_rem =do_div (t,1000000ULL ); +unsigned long usec_rem =do_div (t,USEC_PER_SEC );unsigned secs = (unsigned long )t;int ret;Signature · 1 line
1.5.4.rc3Thanks!
Quoted 5 lines · Li Zefan
Impact: cleanup
Use
USEC_PER_SECandNSEC_PER_SECinstead of 1000000 and 1000000000.Signed-off-by Li Zefan <[email protected]>
Thanks, applied. I just changed the subject to say:
tracing: use macros to denote usec and nsec per second
This way it is a bit more descriptive in what it does.
-- Steve
[tip:tracing/core] tracing: use macros to denote usec and nsec per second
In reply to Li ZefanCommit-ID: a5dec5573f3c7e63f2f9b5852b9759ea342a5ff9 Gitweb: http://git.kernel.org/tip/a5dec5573f3c7e63f2f9b5852b9759ea342a5ff9 Author: Li Zefan <[email protected]> AuthorDate: Fri, 27 Mar 2009 14:55:44 +0800 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 7 Apr 2009 14:43:06 +0200
tracing: use macros to denote usec and nsec per second
Impact: cleanup
Use USEC_PER_SEC and NSEC_PER_SEC instead of 1000000 and 1000000000.
LKML-Reference: <[email protected]>
--- kernel/trace/trace_boot.c | 5 +++-- kernel/trace/trace_mmiotrace.c | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-)
kernel/trace/trace_boot.c +3 -2
@@ -9,6 +9,7 @@#include <linux/debugfs.h> #include <linux/ftrace.h> #include <linux/kallsyms.h> +#include <linux/time.h> #include "trace.h" #include "trace_output.h"
@@ -67,7 +68,7 @@ initcall_call_print_line(struct trace_iterator *iter)trace_assign_type (field, entry); call = &field->boot_call; ts = iter->ts; - nsec_rem =do_div (ts,1000000000 ); + nsec_rem =do_div (ts,NSEC_PER_SEC ); ret =trace_seq_printf (s,"[%5ld.%09ld] calling %s @ %i\n" , (unsigned long )ts, nsec_rem, call->func, call->caller);
@@ -92,7 +93,7 @@ initcall_ret_print_line(struct trace_iterator *iter)trace_assign_type (field, entry); init_ret = &field->boot_ret; ts = iter->ts; - nsec_rem =do_div (ts,1000000000 ); + nsec_rem =do_div (ts,NSEC_PER_SEC ); ret = trace_seq_printf(s, "[%5ld.%09ld] initcall %s " "returned %d after %llu msecs\n",
kernel/trace/trace_mmiotrace.c +4 -2
@@ -9,6 +9,8 @@#include <linux/kernel.h> #include <linux/mmiotrace.h> #include <linux/pci.h> +#include <linux/time.h> +#include <asm/atomic.h> #include "trace.h"
@@ -174,7 +176,7 @@ static enum print_line_t mmio_print_rw(struct trace_iterator *iter)struct mmiotrace_rw *rw;struct trace_seq *s = &iter->seq;unsigned long long t =ns2usecs (iter->ts); -unsigned long usec_rem =do_div (t,1000000ULL ); +unsigned long usec_rem =do_div (t,USEC_PER_SEC );unsigned secs = (unsigned long )t;int ret =1 ;
@@ -221,7 +223,7 @@ static enum print_line_t mmio_print_map(struct trace_iterator *iter)struct mmiotrace_map *m;struct trace_seq *s = &iter->seq;unsigned long long t =ns2usecs (iter->ts); -unsigned long usec_rem =do_div (t,1000000ULL ); +unsigned long usec_rem =do_div (t,USEC_PER_SEC );unsigned secs = (unsigned long )t;int ret;