|
@@ -287,26 +287,20 @@ EXPORT_SYMBOL(jiffies_to_usecs);
|
|
* @t: Timespec
|
|
* @t: Timespec
|
|
* @gran: Granularity in ns.
|
|
* @gran: Granularity in ns.
|
|
*
|
|
*
|
|
- * Truncate a timespec to a granularity. gran must be smaller than a second.
|
|
|
|
- * Always rounds down.
|
|
|
|
- *
|
|
|
|
- * This function should be only used for timestamps returned by
|
|
|
|
- * current_kernel_time() or CURRENT_TIME, not with do_gettimeofday() because
|
|
|
|
- * it doesn't handle the better resolution of the latter.
|
|
|
|
|
|
+ * Truncate a timespec to a granularity. Always rounds down. gran must
|
|
|
|
+ * not be 0 nor greater than a second (NSEC_PER_SEC, or 10^9 ns).
|
|
*/
|
|
*/
|
|
struct timespec timespec_trunc(struct timespec t, unsigned gran)
|
|
struct timespec timespec_trunc(struct timespec t, unsigned gran)
|
|
{
|
|
{
|
|
- /*
|
|
|
|
- * Division is pretty slow so avoid it for common cases.
|
|
|
|
- * Currently current_kernel_time() never returns better than
|
|
|
|
- * jiffies resolution. Exploit that.
|
|
|
|
- */
|
|
|
|
- if (gran <= jiffies_to_usecs(1) * 1000) {
|
|
|
|
|
|
+ /* Avoid division in the common cases 1 ns and 1 s. */
|
|
|
|
+ if (gran == 1) {
|
|
/* nothing */
|
|
/* nothing */
|
|
- } else if (gran == 1000000000) {
|
|
|
|
|
|
+ } else if (gran == NSEC_PER_SEC) {
|
|
t.tv_nsec = 0;
|
|
t.tv_nsec = 0;
|
|
- } else {
|
|
|
|
|
|
+ } else if (gran > 1 && gran < NSEC_PER_SEC) {
|
|
t.tv_nsec -= t.tv_nsec % gran;
|
|
t.tv_nsec -= t.tv_nsec % gran;
|
|
|
|
+ } else {
|
|
|
|
+ WARN(1, "illegal file time granularity: %u", gran);
|
|
}
|
|
}
|
|
return t;
|
|
return t;
|
|
}
|
|
}
|
|
@@ -546,7 +540,7 @@ EXPORT_SYMBOL(__usecs_to_jiffies);
|
|
* value to a scaled second value.
|
|
* value to a scaled second value.
|
|
*/
|
|
*/
|
|
static unsigned long
|
|
static unsigned long
|
|
-__timespec_to_jiffies(unsigned long sec, long nsec)
|
|
|
|
|
|
+__timespec64_to_jiffies(u64 sec, long nsec)
|
|
{
|
|
{
|
|
nsec = nsec + TICK_NSEC - 1;
|
|
nsec = nsec + TICK_NSEC - 1;
|
|
|
|
|
|
@@ -554,22 +548,27 @@ __timespec_to_jiffies(unsigned long sec, long nsec)
|
|
sec = MAX_SEC_IN_JIFFIES;
|
|
sec = MAX_SEC_IN_JIFFIES;
|
|
nsec = 0;
|
|
nsec = 0;
|
|
}
|
|
}
|
|
- return (((u64)sec * SEC_CONVERSION) +
|
|
|
|
|
|
+ return ((sec * SEC_CONVERSION) +
|
|
(((u64)nsec * NSEC_CONVERSION) >>
|
|
(((u64)nsec * NSEC_CONVERSION) >>
|
|
(NSEC_JIFFIE_SC - SEC_JIFFIE_SC))) >> SEC_JIFFIE_SC;
|
|
(NSEC_JIFFIE_SC - SEC_JIFFIE_SC))) >> SEC_JIFFIE_SC;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-unsigned long
|
|
|
|
-timespec_to_jiffies(const struct timespec *value)
|
|
|
|
|
|
+static unsigned long
|
|
|
|
+__timespec_to_jiffies(unsigned long sec, long nsec)
|
|
{
|
|
{
|
|
- return __timespec_to_jiffies(value->tv_sec, value->tv_nsec);
|
|
|
|
|
|
+ return __timespec64_to_jiffies((u64)sec, nsec);
|
|
}
|
|
}
|
|
|
|
|
|
-EXPORT_SYMBOL(timespec_to_jiffies);
|
|
|
|
|
|
+unsigned long
|
|
|
|
+timespec64_to_jiffies(const struct timespec64 *value)
|
|
|
|
+{
|
|
|
|
+ return __timespec64_to_jiffies(value->tv_sec, value->tv_nsec);
|
|
|
|
+}
|
|
|
|
+EXPORT_SYMBOL(timespec64_to_jiffies);
|
|
|
|
|
|
void
|
|
void
|
|
-jiffies_to_timespec(const unsigned long jiffies, struct timespec *value)
|
|
|
|
|
|
+jiffies_to_timespec64(const unsigned long jiffies, struct timespec64 *value)
|
|
{
|
|
{
|
|
/*
|
|
/*
|
|
* Convert jiffies to nanoseconds and separate with
|
|
* Convert jiffies to nanoseconds and separate with
|
|
@@ -580,7 +579,7 @@ jiffies_to_timespec(const unsigned long jiffies, struct timespec *value)
|
|
NSEC_PER_SEC, &rem);
|
|
NSEC_PER_SEC, &rem);
|
|
value->tv_nsec = rem;
|
|
value->tv_nsec = rem;
|
|
}
|
|
}
|
|
-EXPORT_SYMBOL(jiffies_to_timespec);
|
|
|
|
|
|
+EXPORT_SYMBOL(jiffies_to_timespec64);
|
|
|
|
|
|
/*
|
|
/*
|
|
* We could use a similar algorithm to timespec_to_jiffies (with a
|
|
* We could use a similar algorithm to timespec_to_jiffies (with a
|