Skip to content

Commit 2456e85

Browse files
committed
ktime: Get rid of the union
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]>
1 parent a5a1d1c commit 2456e85

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+200
-227
lines changed

drivers/base/power/wakeup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,7 @@ static int print_wakeup_source_stats(struct seq_file *m,
998998

999999
active_time = ktime_sub(now, ws->last_time);
10001000
total_time = ktime_add(total_time, active_time);
1001-
if (active_time.tv64 > max_time.tv64)
1001+
if (active_time > max_time)
10021002
max_time = active_time;
10031003

10041004
if (ws->autosleep_enabled)

drivers/media/rc/ir-rx51.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ static enum hrtimer_restart lirc_rx51_timer_cb(struct hrtimer *timer)
109109

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

112-
} while (hrtimer_get_expires_tv64(timer) < now.tv64);
112+
} while (hrtimer_get_expires_tv64(timer) < now);
113113

114114
return HRTIMER_RESTART;
115115
end:

drivers/rtc/interface.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,8 @@ int rtc_initialize_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
394394
rtc->aie_timer.period = ktime_set(0, 0);
395395

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

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

767767
/* Skip over expired timers */
768768
while (next) {
769-
if (next->expires.tv64 >= now.tv64)
769+
if (next->expires >= now)
770770
break;
771771
next = timerqueue_iterate_next(next);
772772
}
@@ -858,7 +858,7 @@ void rtc_timer_do_work(struct work_struct *work)
858858
__rtc_read_time(rtc, &tm);
859859
now = rtc_tm_to_ktime(tm);
860860
while ((next = timerqueue_getnext(&rtc->timerqueue))) {
861-
if (next->expires.tv64 > now.tv64)
861+
if (next->expires > now)
862862
break;
863863

864864
/* expire timer */

drivers/usb/chipidea/otg_fsm.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ static void ci_otg_add_timer(struct ci_hdrc *ci, enum otg_fsm_timer t)
234234
ktime_set(timer_sec, timer_nsec));
235235
ci->enabled_otg_timer_bits |= (1 << t);
236236
if ((ci->next_otg_timer == NUM_OTG_FSM_TIMERS) ||
237-
(ci->hr_timeouts[ci->next_otg_timer].tv64 >
238-
ci->hr_timeouts[t].tv64)) {
237+
(ci->hr_timeouts[ci->next_otg_timer] >
238+
ci->hr_timeouts[t])) {
239239
ci->next_otg_timer = t;
240240
hrtimer_start_range_ns(&ci->otg_fsm_hrtimer,
241241
ci->hr_timeouts[t], NSEC_PER_MSEC,
@@ -269,8 +269,8 @@ static void ci_otg_del_timer(struct ci_hdrc *ci, enum otg_fsm_timer t)
269269
for_each_set_bit(cur_timer, &enabled_timer_bits,
270270
NUM_OTG_FSM_TIMERS) {
271271
if ((next_timer == NUM_OTG_FSM_TIMERS) ||
272-
(ci->hr_timeouts[next_timer].tv64 <
273-
ci->hr_timeouts[cur_timer].tv64))
272+
(ci->hr_timeouts[next_timer] <
273+
ci->hr_timeouts[cur_timer]))
274274
next_timer = cur_timer;
275275
}
276276
}
@@ -397,14 +397,14 @@ static enum hrtimer_restart ci_otg_hrtimer_func(struct hrtimer *t)
397397

398398
now = ktime_get();
399399
for_each_set_bit(cur_timer, &enabled_timer_bits, NUM_OTG_FSM_TIMERS) {
400-
if (now.tv64 >= ci->hr_timeouts[cur_timer].tv64) {
400+
if (now >= ci->hr_timeouts[cur_timer]) {
401401
ci->enabled_otg_timer_bits &= ~(1 << cur_timer);
402402
if (otg_timer_handlers[cur_timer])
403403
ret = otg_timer_handlers[cur_timer](ci);
404404
} else {
405405
if ((next_timer == NUM_OTG_FSM_TIMERS) ||
406-
(ci->hr_timeouts[cur_timer].tv64 <
407-
ci->hr_timeouts[next_timer].tv64))
406+
(ci->hr_timeouts[cur_timer] <
407+
ci->hr_timeouts[next_timer]))
408408
next_timer = cur_timer;
409409
}
410410
}

drivers/usb/host/ehci-timer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ static enum hrtimer_restart ehci_hrtimer_func(struct hrtimer *t)
425425
*/
426426
now = ktime_get();
427427
for_each_set_bit(e, &events, EHCI_HRTIMER_NUM_EVENTS) {
428-
if (now.tv64 >= ehci->hr_timeouts[e].tv64)
428+
if (now >= ehci->hr_timeouts[e])
429429
event_handlers[e](ehci);
430430
else
431431
ehci_enable_event(ehci, e, false);

drivers/usb/host/fotg210-hcd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1381,7 +1381,7 @@ static enum hrtimer_restart fotg210_hrtimer_func(struct hrtimer *t)
13811381
*/
13821382
now = ktime_get();
13831383
for_each_set_bit(e, &events, FOTG210_HRTIMER_NUM_EVENTS) {
1384-
if (now.tv64 >= fotg210->hr_timeouts[e].tv64)
1384+
if (now >= fotg210->hr_timeouts[e])
13851385
event_handlers[e](fotg210);
13861386
else
13871387
fotg210_enable_event(fotg210, e, false);

fs/aio.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,7 +1285,7 @@ static long read_events(struct kioctx *ctx, long min_nr, long nr,
12851285
struct io_event __user *event,
12861286
struct timespec __user *timeout)
12871287
{
1288-
ktime_t until = { .tv64 = KTIME_MAX };
1288+
ktime_t until = KTIME_MAX;
12891289
long ret = 0;
12901290

12911291
if (timeout) {
@@ -1311,7 +1311,7 @@ static long read_events(struct kioctx *ctx, long min_nr, long nr,
13111311
* the ringbuffer empty. So in practice we should be ok, but it's
13121312
* something to be aware of when touching this code.
13131313
*/
1314-
if (until.tv64 == 0)
1314+
if (until == 0)
13151315
aio_read_events(ctx, min_nr, nr, event, &ret);
13161316
else
13171317
wait_event_interruptible_hrtimeout(ctx->wait,

fs/nfs/flexfilelayout/flexfilelayout.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -619,12 +619,11 @@ nfs4_ff_layoutstat_start_io(struct nfs4_ff_layout_mirror *mirror,
619619
struct nfs4_ff_layoutstat *layoutstat,
620620
ktime_t now)
621621
{
622-
static const ktime_t notime = {0};
623622
s64 report_interval = FF_LAYOUTSTATS_REPORT_INTERVAL;
624623
struct nfs4_flexfile_layout *ffl = FF_LAYOUT_FROM_HDR(mirror->layout);
625624

626625
nfs4_ff_start_busy_timer(&layoutstat->busy_timer, now);
627-
if (ktime_equal(mirror->start_time, notime))
626+
if (ktime_equal(mirror->start_time, 0))
628627
mirror->start_time = now;
629628
if (mirror->report_interval != 0)
630629
report_interval = (s64)mirror->report_interval * 1000LL;

fs/ocfs2/cluster/heartbeat.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1250,7 +1250,7 @@ static int o2hb_thread(void *data)
12501250

12511251
mlog(ML_HEARTBEAT,
12521252
"start = %lld, end = %lld, msec = %u, ret = %d\n",
1253-
before_hb.tv64, after_hb.tv64, elapsed_msec, ret);
1253+
before_hb, after_hb, elapsed_msec, ret);
12541254

12551255
if (!kthread_should_stop() &&
12561256
elapsed_msec < reg->hr_timeout_ms) {

fs/timerfd.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ static inline bool isalarm(struct timerfd_ctx *ctx)
5555
/*
5656
* This gets called when the timer event triggers. We set the "expired"
5757
* flag, but we do not re-arm the timer (in case it's necessary,
58-
* tintv.tv64 != 0) until the timer is accessed.
58+
* tintv != 0) until the timer is accessed.
5959
*/
6060
static void timerfd_triggered(struct timerfd_ctx *ctx)
6161
{
@@ -93,7 +93,7 @@ static enum alarmtimer_restart timerfd_alarmproc(struct alarm *alarm,
9393
*/
9494
void timerfd_clock_was_set(void)
9595
{
96-
ktime_t moffs = ktime_mono_to_real((ktime_t){ .tv64 = 0 });
96+
ktime_t moffs = ktime_mono_to_real(0);
9797
struct timerfd_ctx *ctx;
9898
unsigned long flags;
9999

@@ -102,8 +102,8 @@ void timerfd_clock_was_set(void)
102102
if (!ctx->might_cancel)
103103
continue;
104104
spin_lock_irqsave(&ctx->wqh.lock, flags);
105-
if (ctx->moffs.tv64 != moffs.tv64) {
106-
ctx->moffs.tv64 = KTIME_MAX;
105+
if (ctx->moffs != moffs) {
106+
ctx->moffs = KTIME_MAX;
107107
ctx->ticks++;
108108
wake_up_locked(&ctx->wqh);
109109
}
@@ -124,9 +124,9 @@ static void timerfd_remove_cancel(struct timerfd_ctx *ctx)
124124

125125
static bool timerfd_canceled(struct timerfd_ctx *ctx)
126126
{
127-
if (!ctx->might_cancel || ctx->moffs.tv64 != KTIME_MAX)
127+
if (!ctx->might_cancel || ctx->moffs != KTIME_MAX)
128128
return false;
129-
ctx->moffs = ktime_mono_to_real((ktime_t){ .tv64 = 0 });
129+
ctx->moffs = ktime_mono_to_real(0);
130130
return true;
131131
}
132132

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

158-
return remaining.tv64 < 0 ? ktime_set(0, 0): remaining;
158+
return remaining < 0 ? ktime_set(0, 0): remaining;
159159
}
160160

161161
static int timerfd_setup(struct timerfd_ctx *ctx, int flags,
@@ -184,7 +184,7 @@ static int timerfd_setup(struct timerfd_ctx *ctx, int flags,
184184
ctx->t.tmr.function = timerfd_tmrproc;
185185
}
186186

187-
if (texp.tv64 != 0) {
187+
if (texp != 0) {
188188
if (isalarm(ctx)) {
189189
if (flags & TFD_TIMER_ABSTIME)
190190
alarm_start(&ctx->t.alarm, texp);
@@ -261,9 +261,9 @@ static ssize_t timerfd_read(struct file *file, char __user *buf, size_t count,
261261
if (ctx->ticks) {
262262
ticks = ctx->ticks;
263263

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

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

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

501501
spin_lock_irq(&ctx->wqh.lock);
502-
if (ctx->expired && ctx->tintv.tv64) {
502+
if (ctx->expired && ctx->tintv) {
503503
ctx->expired = 0;
504504

505505
if (isalarm(ctx)) {

0 commit comments

Comments
 (0)