mirror of
https://github.com/systemd/systemd.git
synced 2024-11-30 22:03:41 +08:00
time-util: introduce jiffies_to_usec()
This commit is contained in:
parent
57894dc989
commit
77372afbe0
@ -1414,8 +1414,8 @@ struct tm *localtime_or_gmtime_r(const time_t *t, struct tm *tm, bool utc) {
|
||||
return utc ? gmtime_r(t, tm) : localtime_r(t, tm);
|
||||
}
|
||||
|
||||
unsigned long usec_to_jiffies(usec_t u) {
|
||||
static thread_local unsigned long hz = 0;
|
||||
static uint32_t sysconf_clock_ticks_cached(void) {
|
||||
static thread_local uint32_t hz = 0;
|
||||
long r;
|
||||
|
||||
if (hz == 0) {
|
||||
@ -1425,7 +1425,17 @@ unsigned long usec_to_jiffies(usec_t u) {
|
||||
hz = r;
|
||||
}
|
||||
|
||||
return DIV_ROUND_UP(u , USEC_PER_SEC / hz);
|
||||
return hz;
|
||||
}
|
||||
|
||||
uint32_t usec_to_jiffies(usec_t u) {
|
||||
uint32_t hz = sysconf_clock_ticks_cached();
|
||||
return DIV_ROUND_UP(u, USEC_PER_SEC / hz);
|
||||
}
|
||||
|
||||
usec_t jiffies_to_usec(uint32_t j) {
|
||||
uint32_t hz = sysconf_clock_ticks_cached();
|
||||
return DIV_ROUND_UP(j * USEC_PER_SEC, hz);
|
||||
}
|
||||
|
||||
usec_t usec_shift_clock(usec_t x, clockid_t from, clockid_t to) {
|
||||
|
@ -136,7 +136,8 @@ int get_timezone(char **timezone);
|
||||
time_t mktime_or_timegm(struct tm *tm, bool utc);
|
||||
struct tm *localtime_or_gmtime_r(const time_t *t, struct tm *tm, bool utc);
|
||||
|
||||
unsigned long usec_to_jiffies(usec_t usec);
|
||||
uint32_t usec_to_jiffies(usec_t usec);
|
||||
usec_t jiffies_to_usec(uint32_t jiffies);
|
||||
|
||||
bool in_utc_timezone(void);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user