* [PATCH 1/1] ktime: Use macro NSEC_PER_USEC instead of a magic number
@ 2013-05-06 12:42 y
2013-05-07 8:15 ` Daniel Borkmann
0 siblings, 1 reply; 3+ messages in thread
From: y @ 2013-05-06 12:42 UTC (permalink / raw)
To: linux-kernel; +Cc: davem, dborkman, tglx, john.stultz, liu.y.victor, Liu Ying
From: Liu Ying <Ying.Liu@freescale.com>
We've got the macro NSEC_PER_USEC defined in header file
include/linux/time.h. To make the code decent, this patch
replaces the magic number 1000 to convert bewteen a time
value in microseconds and one in nanoseconds with the
macro NSEC_PER_USEC.
Signed-off-by: Liu Ying <Ying.Liu@freescale.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: Daniel Borkmann <dborkman@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: John Stultz <john.stultz@linaro.org>
---
include/linux/ktime.h | 7 ++++---
1 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/include/linux/ktime.h b/include/linux/ktime.h
index bbca128..5de963d 100644
--- a/include/linux/ktime.h
+++ b/include/linux/ktime.h
@@ -229,7 +229,8 @@ static inline ktime_t timespec_to_ktime(const struct timespec ts)
static inline ktime_t timeval_to_ktime(const struct timeval tv)
{
return (ktime_t) { .tv = { .sec = (s32)tv.tv_sec,
- .nsec = (s32)tv.tv_usec * 1000 } };
+ .nsec = (s32)tv.tv_usec *
+ (s32)NSEC_PER_USEC} };
}
/**
@@ -320,12 +321,12 @@ static inline s64 ktime_us_delta(const ktime_t later, const ktime_t earlier)
static inline ktime_t ktime_add_us(const ktime_t kt, const u64 usec)
{
- return ktime_add_ns(kt, usec * 1000);
+ return ktime_add_ns(kt, usec * NSEC_PER_USEC);
}
static inline ktime_t ktime_sub_us(const ktime_t kt, const u64 usec)
{
- return ktime_sub_ns(kt, usec * 1000);
+ return ktime_sub_ns(kt, usec * NSEC_PER_USEC);
}
extern ktime_t ktime_add_safe(const ktime_t lhs, const ktime_t rhs);
--
1.7.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 1/1] ktime: Use macro NSEC_PER_USEC instead of a magic number
2013-05-06 12:42 [PATCH 1/1] ktime: Use macro NSEC_PER_USEC instead of a magic number y
@ 2013-05-07 8:15 ` Daniel Borkmann
[not found] ` <CA+8Hj83_6Feq8KVSJh+E=R35wm2ZkF+uGWxcJV7XZsOxdze41A@mail.gmail.com>
0 siblings, 1 reply; 3+ messages in thread
From: Daniel Borkmann @ 2013-05-07 8:15 UTC (permalink / raw)
To: y; +Cc: linux-kernel, davem, tglx, john.stultz, liu.y.victor, Liu Ying
On 05/06/2013 02:42 PM, y@shlinux1.ap.freescale.net wrote:
> From: Liu Ying <Ying.Liu@freescale.com>
Nitpick:
If you only have 1 patch, then you don't need "1/1" in the subject.
The term magic number here might be a little exaggerated, not so
magic actually. :-)
But, in general I agree that we could do that also since it is used
elsewhere in the same header file. Thus, this might be more consistent.
> We've got the macro NSEC_PER_USEC defined in header file
> include/linux/time.h. To make the code decent, this patch
> replaces the magic number 1000 to convert bewteen a time
> value in microseconds and one in nanoseconds with the
> macro NSEC_PER_USEC.
>
> Signed-off-by: Liu Ying <Ying.Liu@freescale.com>
> Cc: David S. Miller <davem@davemloft.net>
> Cc: Daniel Borkmann <dborkman@redhat.com>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: John Stultz <john.stultz@linaro.org>
> ---
> include/linux/ktime.h | 7 ++++---
> 1 files changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/include/linux/ktime.h b/include/linux/ktime.h
> index bbca128..5de963d 100644
> --- a/include/linux/ktime.h
> +++ b/include/linux/ktime.h
> @@ -229,7 +229,8 @@ static inline ktime_t timespec_to_ktime(const struct timespec ts)
> static inline ktime_t timeval_to_ktime(const struct timeval tv)
> {
> return (ktime_t) { .tv = { .sec = (s32)tv.tv_sec,
> - .nsec = (s32)tv.tv_usec * 1000 } };
> + .nsec = (s32)tv.tv_usec *
> + (s32)NSEC_PER_USEC} };
Nitpick: Likely, this could be reduced to one cast only.
Otherwise looks good.
> }
>
> /**
> @@ -320,12 +321,12 @@ static inline s64 ktime_us_delta(const ktime_t later, const ktime_t earlier)
>
> static inline ktime_t ktime_add_us(const ktime_t kt, const u64 usec)
> {
> - return ktime_add_ns(kt, usec * 1000);
> + return ktime_add_ns(kt, usec * NSEC_PER_USEC);
> }
>
> static inline ktime_t ktime_sub_us(const ktime_t kt, const u64 usec)
> {
> - return ktime_sub_ns(kt, usec * 1000);
> + return ktime_sub_ns(kt, usec * NSEC_PER_USEC);
> }
>
> extern ktime_t ktime_add_safe(const ktime_t lhs, const ktime_t rhs);
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 1/1] ktime: Use macro NSEC_PER_USEC instead of a magic number
[not found] ` <CA+8Hj838CfaAKjdLtO2zdZ5DJP10a0QCzhYJbZ3GqQhmE5MZzw@mail.gmail.com>
@ 2013-05-07 9:12 ` Daniel Borkmann
0 siblings, 0 replies; 3+ messages in thread
From: Daniel Borkmann @ 2013-05-07 9:12 UTC (permalink / raw)
To: Liu Ying; +Cc: linux-kernel, davem, tglx, john.stultz, Liu Ying
On 05/07/2013 11:08 AM, Liu Ying wrote:
> 2013/5/7 Liu Ying <liu.y.victor@gmail.com>
>> 2013/5/7 Daniel Borkmann <dborkman@redhat.com>
>>> On 05/06/2013 02:42 PM, y@shlinux1.ap.freescale.net wrote:
>>>> From: Liu Ying <Ying.Liu@freescale.com>
>>> If you only have 1 patch, then you don't need "1/1" in the subject.
>>> The term magic number here might be a little exaggerated, not so
>>> magic actually. :-)
>>>
>> Thanks. I will update this. How about turning "magic number" to "immediate
>> number"?
Maybe like ``ktime: Use macro NSEC_PER_USEC where appropriate''.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-05-07 9:12 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-06 12:42 [PATCH 1/1] ktime: Use macro NSEC_PER_USEC instead of a magic number y
2013-05-07 8:15 ` Daniel Borkmann
[not found] ` <CA+8Hj83_6Feq8KVSJh+E=R35wm2ZkF+uGWxcJV7XZsOxdze41A@mail.gmail.com>
[not found] ` <CA+8Hj838CfaAKjdLtO2zdZ5DJP10a0QCzhYJbZ3GqQhmE5MZzw@mail.gmail.com>
2013-05-07 9:12 ` Daniel Borkmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox