ktime: Use macro NSEC_PER_USEC instead of a magic number
PATCH 1/1 ktime: Use macro NSEC_PER_USEC instead of a magic number
From: Liu Ying <[email protected]>
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.
--- include/linux/ktime.h | 7 ++++--- 1 files changed, 4 insertions(+), 3 deletions(-)
include/linux/ktime.h +4 -3
@@ -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);
Signature · 1 line
1.7.1
Quoted 1 line · On 05/06/2013 02:42 PM, [email protected] wrote:
From: Liu Ying <[email protected]>
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.
Quoted 20 lines
We've got the macro
NSEC_PER_USECdefined in header fileinclude/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 macroNSEC_PER_USEC.Signed-off-by Liu Ying <[email protected]>Cc David S. Miller <[email protected]>Cc Daniel Borkmann <[email protected]>Cc Thomas Gleixner <[email protected]>Cc John Stultz <[email protected]>--- include/linux/ktime.h | 7 ++++--- 1 files changed, 4 insertions(+), 3 deletions(-)include/linux/ktime.h +0
-0
include/linux/ktime.h static inline ktime_t timespec_to_ktime(const struct timespec ts) · line 233
Quoted 6 lines
include/linux/ktime.h +2
-1@@ -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.
Quoted 19 lines
include/linux/ktime.h +2
-2}/** @@ -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);
A message that is not in the archive (sent off-list or not yet received): CA+8Hj83_6Feq8KVSJh+E=R35wm2ZkF+uGWxcJV7XZsOxdze41A@mail.gmail.com
A message that is not in the archive (sent off-list or not yet received): CA+8Hj838CfaAKjdLtO2zdZ5DJP10a0QCzhYJbZ3GqQhmE5MZzw@mail.gmail.com
Quoted 11 lines · Liu Ying
2013/5/7 Liu Ying <[email protected]>
Quoted 10 lines
2013/5/7 Daniel Borkmann <[email protected]>
Quoted 7 lines · On 05/06/2013 02:42 PM, [email protected] wrote:
Quoted 1 line
From: Liu Ying <[email protected]>
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''.