Skip to content

Commit

Permalink
ktime: Get rid of the union
Browse files Browse the repository at this point in the history
ktime is a union because the initial implementation stored the time in
scalar nanoseconds on 64 bit machine and in a endianess optimized timespec
variant for 32bit machines. The Y2038 cleanup removed the timespec variant
and switched everything to scalar nanoseconds. The union remained, but
become completely pointless.

Get rid of the union and just keep ktime_t as simple typedef of type s64.

The conversion was done with coccinelle and some manual mopping up.

Signed-off-by: Thomas Gleixner <[email protected]>
Cc: Peter Zijlstra <[email protected]>
  • Loading branch information
KAGA-KOKO committed Dec 25, 2016
1 parent a5a1d1c commit 2456e85
Show file tree
Hide file tree
Showing 48 changed files with 200 additions and 227 deletions.
2 changes: 1 addition & 1 deletion drivers/base/power/wakeup.c
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@ static int print_wakeup_source_stats(struct seq_file *m,

active_time = ktime_sub(now, ws->last_time);
total_time = ktime_add(total_time, active_time);
if (active_time.tv64 > max_time.tv64)
if (active_time > max_time)
max_time = active_time;

if (ws->autosleep_enabled)
Expand Down
2 changes: 1 addition & 1 deletion drivers/media/rc/ir-rx51.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ static enum hrtimer_restart lirc_rx51_timer_cb(struct hrtimer *timer)

now = timer->base->get_time();

} while (hrtimer_get_expires_tv64(timer) < now.tv64);
} while (hrtimer_get_expires_tv64(timer) < now);

return HRTIMER_RESTART;
end:
Expand Down
8 changes: 4 additions & 4 deletions drivers/rtc/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,8 @@ int rtc_initialize_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
rtc->aie_timer.period = ktime_set(0, 0);

/* Alarm has to be enabled & in the future for us to enqueue it */
if (alarm->enabled && (rtc_tm_to_ktime(now).tv64 <
rtc->aie_timer.node.expires.tv64)) {
if (alarm->enabled && (rtc_tm_to_ktime(now) <
rtc->aie_timer.node.expires)) {

rtc->aie_timer.enabled = 1;
timerqueue_add(&rtc->timerqueue, &rtc->aie_timer.node);
Expand Down Expand Up @@ -766,7 +766,7 @@ static int rtc_timer_enqueue(struct rtc_device *rtc, struct rtc_timer *timer)

/* Skip over expired timers */
while (next) {
if (next->expires.tv64 >= now.tv64)
if (next->expires >= now)
break;
next = timerqueue_iterate_next(next);
}
Expand Down Expand Up @@ -858,7 +858,7 @@ void rtc_timer_do_work(struct work_struct *work)
__rtc_read_time(rtc, &tm);
now = rtc_tm_to_ktime(tm);
while ((next = timerqueue_getnext(&rtc->timerqueue))) {
if (next->expires.tv64 > now.tv64)
if (next->expires > now)
break;

/* expire timer */
Expand Down
14 changes: 7 additions & 7 deletions drivers/usb/chipidea/otg_fsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ static void ci_otg_add_timer(struct ci_hdrc *ci, enum otg_fsm_timer t)
ktime_set(timer_sec, timer_nsec));
ci->enabled_otg_timer_bits |= (1 << t);
if ((ci->next_otg_timer == NUM_OTG_FSM_TIMERS) ||
(ci->hr_timeouts[ci->next_otg_timer].tv64 >
ci->hr_timeouts[t].tv64)) {
(ci->hr_timeouts[ci->next_otg_timer] >
ci->hr_timeouts[t])) {
ci->next_otg_timer = t;
hrtimer_start_range_ns(&ci->otg_fsm_hrtimer,
ci->hr_timeouts[t], NSEC_PER_MSEC,
Expand Down Expand Up @@ -269,8 +269,8 @@ static void ci_otg_del_timer(struct ci_hdrc *ci, enum otg_fsm_timer t)
for_each_set_bit(cur_timer, &enabled_timer_bits,
NUM_OTG_FSM_TIMERS) {
if ((next_timer == NUM_OTG_FSM_TIMERS) ||
(ci->hr_timeouts[next_timer].tv64 <
ci->hr_timeouts[cur_timer].tv64))
(ci->hr_timeouts[next_timer] <
ci->hr_timeouts[cur_timer]))
next_timer = cur_timer;
}
}
Expand Down Expand Up @@ -397,14 +397,14 @@ static enum hrtimer_restart ci_otg_hrtimer_func(struct hrtimer *t)

now = ktime_get();
for_each_set_bit(cur_timer, &enabled_timer_bits, NUM_OTG_FSM_TIMERS) {
if (now.tv64 >= ci->hr_timeouts[cur_timer].tv64) {
if (now >= ci->hr_timeouts[cur_timer]) {
ci->enabled_otg_timer_bits &= ~(1 << cur_timer);
if (otg_timer_handlers[cur_timer])
ret = otg_timer_handlers[cur_timer](ci);
} else {
if ((next_timer == NUM_OTG_FSM_TIMERS) ||
(ci->hr_timeouts[cur_timer].tv64 <
ci->hr_timeouts[next_timer].tv64))
(ci->hr_timeouts[cur_timer] <
ci->hr_timeouts[next_timer]))
next_timer = cur_timer;
}
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/usb/host/ehci-timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ static enum hrtimer_restart ehci_hrtimer_func(struct hrtimer *t)
*/
now = ktime_get();
for_each_set_bit(e, &events, EHCI_HRTIMER_NUM_EVENTS) {
if (now.tv64 >= ehci->hr_timeouts[e].tv64)
if (now >= ehci->hr_timeouts[e])
event_handlers[e](ehci);
else
ehci_enable_event(ehci, e, false);
Expand Down
2 changes: 1 addition & 1 deletion drivers/usb/host/fotg210-hcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1381,7 +1381,7 @@ static enum hrtimer_restart fotg210_hrtimer_func(struct hrtimer *t)
*/
now = ktime_get();
for_each_set_bit(e, &events, FOTG210_HRTIMER_NUM_EVENTS) {
if (now.tv64 >= fotg210->hr_timeouts[e].tv64)
if (now >= fotg210->hr_timeouts[e])
event_handlers[e](fotg210);
else
fotg210_enable_event(fotg210, e, false);
Expand Down
4 changes: 2 additions & 2 deletions fs/aio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1285,7 +1285,7 @@ static long read_events(struct kioctx *ctx, long min_nr, long nr,
struct io_event __user *event,
struct timespec __user *timeout)
{
ktime_t until = { .tv64 = KTIME_MAX };
ktime_t until = KTIME_MAX;
long ret = 0;

if (timeout) {
Expand All @@ -1311,7 +1311,7 @@ static long read_events(struct kioctx *ctx, long min_nr, long nr,
* the ringbuffer empty. So in practice we should be ok, but it's
* something to be aware of when touching this code.
*/
if (until.tv64 == 0)
if (until == 0)
aio_read_events(ctx, min_nr, nr, event, &ret);
else
wait_event_interruptible_hrtimeout(ctx->wait,
Expand Down
3 changes: 1 addition & 2 deletions fs/nfs/flexfilelayout/flexfilelayout.c
Original file line number Diff line number Diff line change
Expand Up @@ -619,12 +619,11 @@ nfs4_ff_layoutstat_start_io(struct nfs4_ff_layout_mirror *mirror,
struct nfs4_ff_layoutstat *layoutstat,
ktime_t now)
{
static const ktime_t notime = {0};
s64 report_interval = FF_LAYOUTSTATS_REPORT_INTERVAL;
struct nfs4_flexfile_layout *ffl = FF_LAYOUT_FROM_HDR(mirror->layout);

nfs4_ff_start_busy_timer(&layoutstat->busy_timer, now);
if (ktime_equal(mirror->start_time, notime))
if (ktime_equal(mirror->start_time, 0))
mirror->start_time = now;
if (mirror->report_interval != 0)
report_interval = (s64)mirror->report_interval * 1000LL;
Expand Down
2 changes: 1 addition & 1 deletion fs/ocfs2/cluster/heartbeat.c
Original file line number Diff line number Diff line change
Expand Up @@ -1250,7 +1250,7 @@ static int o2hb_thread(void *data)

mlog(ML_HEARTBEAT,
"start = %lld, end = %lld, msec = %u, ret = %d\n",
before_hb.tv64, after_hb.tv64, elapsed_msec, ret);
before_hb, after_hb, elapsed_msec, ret);

if (!kthread_should_stop() &&
elapsed_msec < reg->hr_timeout_ms) {
Expand Down
26 changes: 13 additions & 13 deletions fs/timerfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static inline bool isalarm(struct timerfd_ctx *ctx)
/*
* This gets called when the timer event triggers. We set the "expired"
* flag, but we do not re-arm the timer (in case it's necessary,
* tintv.tv64 != 0) until the timer is accessed.
* tintv != 0) until the timer is accessed.
*/
static void timerfd_triggered(struct timerfd_ctx *ctx)
{
Expand Down Expand Up @@ -93,7 +93,7 @@ static enum alarmtimer_restart timerfd_alarmproc(struct alarm *alarm,
*/
void timerfd_clock_was_set(void)
{
ktime_t moffs = ktime_mono_to_real((ktime_t){ .tv64 = 0 });
ktime_t moffs = ktime_mono_to_real(0);
struct timerfd_ctx *ctx;
unsigned long flags;

Expand All @@ -102,8 +102,8 @@ void timerfd_clock_was_set(void)
if (!ctx->might_cancel)
continue;
spin_lock_irqsave(&ctx->wqh.lock, flags);
if (ctx->moffs.tv64 != moffs.tv64) {
ctx->moffs.tv64 = KTIME_MAX;
if (ctx->moffs != moffs) {
ctx->moffs = KTIME_MAX;
ctx->ticks++;
wake_up_locked(&ctx->wqh);
}
Expand All @@ -124,9 +124,9 @@ static void timerfd_remove_cancel(struct timerfd_ctx *ctx)

static bool timerfd_canceled(struct timerfd_ctx *ctx)
{
if (!ctx->might_cancel || ctx->moffs.tv64 != KTIME_MAX)
if (!ctx->might_cancel || ctx->moffs != KTIME_MAX)
return false;
ctx->moffs = ktime_mono_to_real((ktime_t){ .tv64 = 0 });
ctx->moffs = ktime_mono_to_real(0);
return true;
}

Expand Down Expand Up @@ -155,7 +155,7 @@ static ktime_t timerfd_get_remaining(struct timerfd_ctx *ctx)
else
remaining = hrtimer_expires_remaining_adjusted(&ctx->t.tmr);

return remaining.tv64 < 0 ? ktime_set(0, 0): remaining;
return remaining < 0 ? ktime_set(0, 0): remaining;
}

static int timerfd_setup(struct timerfd_ctx *ctx, int flags,
Expand Down Expand Up @@ -184,7 +184,7 @@ static int timerfd_setup(struct timerfd_ctx *ctx, int flags,
ctx->t.tmr.function = timerfd_tmrproc;
}

if (texp.tv64 != 0) {
if (texp != 0) {
if (isalarm(ctx)) {
if (flags & TFD_TIMER_ABSTIME)
alarm_start(&ctx->t.alarm, texp);
Expand Down Expand Up @@ -261,9 +261,9 @@ static ssize_t timerfd_read(struct file *file, char __user *buf, size_t count,
if (ctx->ticks) {
ticks = ctx->ticks;

if (ctx->expired && ctx->tintv.tv64) {
if (ctx->expired && ctx->tintv) {
/*
* If tintv.tv64 != 0, this is a periodic timer that
* If tintv != 0, this is a periodic timer that
* needs to be re-armed. We avoid doing it in the timer
* callback to avoid DoS attacks specifying a very
* short timer period.
Expand Down Expand Up @@ -410,7 +410,7 @@ SYSCALL_DEFINE2(timerfd_create, int, clockid, int, flags)
else
hrtimer_init(&ctx->t.tmr, clockid, HRTIMER_MODE_ABS);

ctx->moffs = ktime_mono_to_real((ktime_t){ .tv64 = 0 });
ctx->moffs = ktime_mono_to_real(0);

ufd = anon_inode_getfd("[timerfd]", &timerfd_fops, ctx,
O_RDWR | (flags & TFD_SHARED_FCNTL_FLAGS));
Expand Down Expand Up @@ -469,7 +469,7 @@ static int do_timerfd_settime(int ufd, int flags,
* We do not update "ticks" and "expired" since the timer will be
* re-programmed again in the following timerfd_setup() call.
*/
if (ctx->expired && ctx->tintv.tv64) {
if (ctx->expired && ctx->tintv) {
if (isalarm(ctx))
alarm_forward_now(&ctx->t.alarm, ctx->tintv);
else
Expand Down Expand Up @@ -499,7 +499,7 @@ static int do_timerfd_gettime(int ufd, struct itimerspec *t)
ctx = f.file->private_data;

spin_lock_irq(&ctx->wqh.lock);
if (ctx->expired && ctx->tintv.tv64) {
if (ctx->expired && ctx->tintv) {
ctx->expired = 0;

if (isalarm(ctx)) {
Expand Down
4 changes: 2 additions & 2 deletions include/linux/futex.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#ifndef _LINUX_FUTEX_H
#define _LINUX_FUTEX_H

#include <linux/ktime.h>
#include <uapi/linux/futex.h>

struct inode;
struct mm_struct;
struct task_struct;
union ktime;

long do_futex(u32 __user *uaddr, int op, u32 val, union ktime *timeout,
long do_futex(u32 __user *uaddr, int op, u32 val, ktime_t *timeout,
u32 __user *uaddr2, u32 val2, u32 val3);

extern int
Expand Down
12 changes: 6 additions & 6 deletions include/linux/hrtimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ static inline void hrtimer_set_expires_range_ns(struct hrtimer *timer, ktime_t t

static inline void hrtimer_set_expires_tv64(struct hrtimer *timer, s64 tv64)
{
timer->node.expires.tv64 = tv64;
timer->_softexpires.tv64 = tv64;
timer->node.expires = tv64;
timer->_softexpires = tv64;
}

static inline void hrtimer_add_expires(struct hrtimer *timer, ktime_t time)
Expand All @@ -256,11 +256,11 @@ static inline ktime_t hrtimer_get_softexpires(const struct hrtimer *timer)

static inline s64 hrtimer_get_expires_tv64(const struct hrtimer *timer)
{
return timer->node.expires.tv64;
return timer->node.expires;
}
static inline s64 hrtimer_get_softexpires_tv64(const struct hrtimer *timer)
{
return timer->_softexpires.tv64;
return timer->_softexpires;
}

static inline s64 hrtimer_get_expires_ns(const struct hrtimer *timer)
Expand Down Expand Up @@ -297,7 +297,7 @@ extern void hrtimer_peek_ahead_timers(void);
* this resolution values.
*/
# define HIGH_RES_NSEC 1
# define KTIME_HIGH_RES (ktime_t) { .tv64 = HIGH_RES_NSEC }
# define KTIME_HIGH_RES (HIGH_RES_NSEC)
# define MONOTONIC_RES_NSEC HIGH_RES_NSEC
# define KTIME_MONOTONIC_RES KTIME_HIGH_RES

Expand Down Expand Up @@ -333,7 +333,7 @@ __hrtimer_expires_remaining_adjusted(const struct hrtimer *timer, ktime_t now)
* hrtimer_start_range_ns() to prevent short timeouts.
*/
if (IS_ENABLED(CONFIG_TIME_LOW_RES) && timer->is_rel)
rem.tv64 -= hrtimer_resolution;
rem -= hrtimer_resolution;
return rem;
}

Expand Down
Loading

0 comments on commit 2456e85

Please sign in to comment.