Add some functions to jiffies.h.
Also add some checks for overflow to existing functions. Reviewed by: hselasky MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D11533
This commit is contained in:
parent
d03ae351ed
commit
8d92040b75
@ -68,11 +68,14 @@ timespec_to_jiffies(const struct timespec *ts)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
msecs_to_jiffies(const u64 msec)
|
msecs_to_jiffies(uint64_t msec)
|
||||||
{
|
{
|
||||||
u64 result;
|
uint64_t msec_max, result;
|
||||||
|
|
||||||
result = howmany(msec * (u64)hz, 1000ULL);
|
msec_max = -1ULL / (uint64_t)hz;
|
||||||
|
if (msec > msec_max)
|
||||||
|
msec = msec_max;
|
||||||
|
result = howmany(msec * (uint64_t)hz, 1000ULL);
|
||||||
if (result > MAX_JIFFY_OFFSET)
|
if (result > MAX_JIFFY_OFFSET)
|
||||||
result = MAX_JIFFY_OFFSET;
|
result = MAX_JIFFY_OFFSET;
|
||||||
|
|
||||||
@ -80,27 +83,61 @@ msecs_to_jiffies(const u64 msec)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
usecs_to_jiffies(const u64 u)
|
usecs_to_jiffies(uint64_t usec)
|
||||||
{
|
{
|
||||||
u64 result;
|
uint64_t usec_max, result;
|
||||||
|
|
||||||
result = howmany(u * (u64)hz, 1000000ULL);
|
usec_max = -1ULL / (uint64_t)hz;
|
||||||
|
if (usec > usec_max)
|
||||||
|
usec = usec_max;
|
||||||
|
result = howmany(usec * (uint64_t)hz, 1000000ULL);
|
||||||
if (result > MAX_JIFFY_OFFSET)
|
if (result > MAX_JIFFY_OFFSET)
|
||||||
result = MAX_JIFFY_OFFSET;
|
result = MAX_JIFFY_OFFSET;
|
||||||
|
|
||||||
return ((int)result);
|
return ((int)result);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline u64
|
static inline uint64_t
|
||||||
nsecs_to_jiffies(const u64 n)
|
nsecs_to_jiffies64(uint64_t nsec)
|
||||||
{
|
{
|
||||||
|
uint64_t nsec_max, result;
|
||||||
|
|
||||||
|
nsec_max = -1ULL / (uint64_t)hz;
|
||||||
|
if (nsec > nsec_max)
|
||||||
|
nsec = nsec_max;
|
||||||
|
result = howmany(nsec * (uint64_t)hz, 1000000000ULL);
|
||||||
|
if (result > MAX_JIFFY_OFFSET)
|
||||||
|
result = MAX_JIFFY_OFFSET;
|
||||||
|
|
||||||
|
return (result);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline uint64_t
|
||||||
|
nsecs_to_jiffies(uint64_t n)
|
||||||
|
{
|
||||||
|
|
||||||
return (usecs_to_jiffies(howmany(n, 1000ULL)));
|
return (usecs_to_jiffies(howmany(n, 1000ULL)));
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline u64
|
static inline uint64_t
|
||||||
|
jiffies_to_nsecs(int j)
|
||||||
|
{
|
||||||
|
|
||||||
|
return ((1000000000ULL / hz) * (uint64_t)(unsigned int)j);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline uint64_t
|
||||||
|
jiffies_to_usecs(int j)
|
||||||
|
{
|
||||||
|
|
||||||
|
return ((1000000ULL / hz) * (uint64_t)(unsigned int)j);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline uint64_t
|
||||||
get_jiffies_64(void)
|
get_jiffies_64(void)
|
||||||
{
|
{
|
||||||
return ((u64)(unsigned)ticks);
|
|
||||||
|
return ((uint64_t)(unsigned int)ticks);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
|
Loading…
x
Reference in New Issue
Block a user