···422422extern unsigned long timespec64_to_jiffies(const struct timespec64 *value);423423extern void jiffies_to_timespec64(const unsigned long jiffies,424424 struct timespec64 *value);425425-static inline unsigned long timespec_to_jiffies(const struct timespec *value)426426-{427427- struct timespec64 ts = timespec_to_timespec64(*value);428428-429429- return timespec64_to_jiffies(&ts);430430-}431431-432432-static inline void jiffies_to_timespec(const unsigned long jiffies,433433- struct timespec *value)434434-{435435- struct timespec64 ts;436436-437437- jiffies_to_timespec64(jiffies, &ts);438438- *value = timespec64_to_timespec(ts);439439-}440440-441441-extern unsigned long timeval_to_jiffies(const struct timeval *value);442442-extern void jiffies_to_timeval(const unsigned long jiffies,443443- struct timeval *value);444444-445425extern clock_t jiffies_to_clock_t(unsigned long x);446426static inline clock_t jiffies_delta_to_clock_t(long delta)447427{
+5-53
kernel/time/time.c
···626626 * The >> (NSEC_JIFFIE_SC - SEC_JIFFIE_SC) converts the scaled nsec627627 * value to a scaled second value.628628 */629629-static unsigned long630630-__timespec64_to_jiffies(u64 sec, long nsec)629629+630630+unsigned long631631+timespec64_to_jiffies(const struct timespec64 *value)631632{632632- nsec = nsec + TICK_NSEC - 1;633633+ u64 sec = value->tv_sec;634634+ long nsec = value->tv_nsec + TICK_NSEC - 1;633635634636 if (sec >= MAX_SEC_IN_JIFFIES){635637 sec = MAX_SEC_IN_JIFFIES;···641639 (((u64)nsec * NSEC_CONVERSION) >>642640 (NSEC_JIFFIE_SC - SEC_JIFFIE_SC))) >> SEC_JIFFIE_SC;643641644644-}645645-646646-static unsigned long647647-__timespec_to_jiffies(unsigned long sec, long nsec)648648-{649649- return __timespec64_to_jiffies((u64)sec, nsec);650650-}651651-652652-unsigned long653653-timespec64_to_jiffies(const struct timespec64 *value)654654-{655655- return __timespec64_to_jiffies(value->tv_sec, value->tv_nsec);656642}657643EXPORT_SYMBOL(timespec64_to_jiffies);658644···657667 value->tv_nsec = rem;658668}659669EXPORT_SYMBOL(jiffies_to_timespec64);660660-661661-/*662662- * We could use a similar algorithm to timespec_to_jiffies (with a663663- * different multiplier for usec instead of nsec). But this has a664664- * problem with rounding: we can't exactly add TICK_NSEC - 1 to the665665- * usec value, since it's not necessarily integral.666666- *667667- * We could instead round in the intermediate scaled representation668668- * (i.e. in units of 1/2^(large scale) jiffies) but that's also669669- * perilous: the scaling introduces a small positive error, which670670- * combined with a division-rounding-upward (i.e. adding 2^(scale) - 1671671- * units to the intermediate before shifting) leads to accidental672672- * overflow and overestimates.673673- *674674- * At the cost of one additional multiplication by a constant, just675675- * use the timespec implementation.676676- */677677-unsigned long678678-timeval_to_jiffies(const struct timeval *value)679679-{680680- return __timespec_to_jiffies(value->tv_sec,681681- value->tv_usec * NSEC_PER_USEC);682682-}683683-EXPORT_SYMBOL(timeval_to_jiffies);684684-685685-void jiffies_to_timeval(const unsigned long jiffies, struct timeval *value)686686-{687687- /*688688- * Convert jiffies to nanoseconds and separate with689689- * one divide.690690- */691691- u32 rem;692692-693693- value->tv_sec = div_u64_rem((u64)jiffies * TICK_NSEC,694694- NSEC_PER_SEC, &rem);695695- value->tv_usec = rem / NSEC_PER_USEC;696696-}697697-EXPORT_SYMBOL(jiffies_to_timeval);698670699671/*700672 * Convert jiffies/jiffies_64 to clock_t and back.