• Home
  • Raw
  • Download

Lines Matching refs:ctx

54 static inline bool isalarm(struct timerfd_ctx *ctx)  in isalarm()  argument
56 return ctx->clockid == CLOCK_REALTIME_ALARM || in isalarm()
57 ctx->clockid == CLOCK_BOOTTIME_ALARM; in isalarm()
65 static void timerfd_triggered(struct timerfd_ctx *ctx) in timerfd_triggered() argument
69 spin_lock_irqsave(&ctx->wqh.lock, flags); in timerfd_triggered()
70 ctx->expired = 1; in timerfd_triggered()
71 ctx->ticks++; in timerfd_triggered()
72 wake_up_locked_poll(&ctx->wqh, EPOLLIN); in timerfd_triggered()
73 spin_unlock_irqrestore(&ctx->wqh.lock, flags); in timerfd_triggered()
78 struct timerfd_ctx *ctx = container_of(htmr, struct timerfd_ctx, in timerfd_tmrproc() local
80 timerfd_triggered(ctx); in timerfd_tmrproc()
87 struct timerfd_ctx *ctx = container_of(alarm, struct timerfd_ctx, in timerfd_alarmproc() local
89 timerfd_triggered(ctx); in timerfd_alarmproc()
102 struct timerfd_ctx *ctx; in timerfd_clock_was_set() local
106 list_for_each_entry_rcu(ctx, &cancel_list, clist) { in timerfd_clock_was_set()
107 if (!ctx->might_cancel) in timerfd_clock_was_set()
109 spin_lock_irqsave(&ctx->wqh.lock, flags); in timerfd_clock_was_set()
110 if (ctx->moffs != moffs) { in timerfd_clock_was_set()
111 ctx->moffs = KTIME_MAX; in timerfd_clock_was_set()
112 ctx->ticks++; in timerfd_clock_was_set()
113 wake_up_locked_poll(&ctx->wqh, EPOLLIN); in timerfd_clock_was_set()
115 spin_unlock_irqrestore(&ctx->wqh.lock, flags); in timerfd_clock_was_set()
136 static void __timerfd_remove_cancel(struct timerfd_ctx *ctx) in __timerfd_remove_cancel() argument
138 if (ctx->might_cancel) { in __timerfd_remove_cancel()
139 ctx->might_cancel = false; in __timerfd_remove_cancel()
141 list_del_rcu(&ctx->clist); in __timerfd_remove_cancel()
146 static void timerfd_remove_cancel(struct timerfd_ctx *ctx) in timerfd_remove_cancel() argument
148 spin_lock(&ctx->cancel_lock); in timerfd_remove_cancel()
149 __timerfd_remove_cancel(ctx); in timerfd_remove_cancel()
150 spin_unlock(&ctx->cancel_lock); in timerfd_remove_cancel()
153 static bool timerfd_canceled(struct timerfd_ctx *ctx) in timerfd_canceled() argument
155 if (!ctx->might_cancel || ctx->moffs != KTIME_MAX) in timerfd_canceled()
157 ctx->moffs = ktime_mono_to_real(0); in timerfd_canceled()
161 static void timerfd_setup_cancel(struct timerfd_ctx *ctx, int flags) in timerfd_setup_cancel() argument
163 spin_lock(&ctx->cancel_lock); in timerfd_setup_cancel()
164 if ((ctx->clockid == CLOCK_REALTIME || in timerfd_setup_cancel()
165 ctx->clockid == CLOCK_REALTIME_ALARM) && in timerfd_setup_cancel()
167 if (!ctx->might_cancel) { in timerfd_setup_cancel()
168 ctx->might_cancel = true; in timerfd_setup_cancel()
170 list_add_rcu(&ctx->clist, &cancel_list); in timerfd_setup_cancel()
174 __timerfd_remove_cancel(ctx); in timerfd_setup_cancel()
176 spin_unlock(&ctx->cancel_lock); in timerfd_setup_cancel()
179 static ktime_t timerfd_get_remaining(struct timerfd_ctx *ctx) in timerfd_get_remaining() argument
183 if (isalarm(ctx)) in timerfd_get_remaining()
184 remaining = alarm_expires_remaining(&ctx->t.alarm); in timerfd_get_remaining()
186 remaining = hrtimer_expires_remaining_adjusted(&ctx->t.tmr); in timerfd_get_remaining()
191 static int timerfd_setup(struct timerfd_ctx *ctx, int flags, in timerfd_setup() argument
196 int clockid = ctx->clockid; in timerfd_setup()
202 ctx->expired = 0; in timerfd_setup()
203 ctx->ticks = 0; in timerfd_setup()
204 ctx->tintv = timespec64_to_ktime(ktmr->it_interval); in timerfd_setup()
206 if (isalarm(ctx)) { in timerfd_setup()
207 alarm_init(&ctx->t.alarm, in timerfd_setup()
208 ctx->clockid == CLOCK_REALTIME_ALARM ? in timerfd_setup()
212 hrtimer_init(&ctx->t.tmr, clockid, htmode); in timerfd_setup()
213 hrtimer_set_expires(&ctx->t.tmr, texp); in timerfd_setup()
214 ctx->t.tmr.function = timerfd_tmrproc; in timerfd_setup()
220 if (isalarm(ctx)) { in timerfd_setup()
222 alarm_start(&ctx->t.alarm, texp); in timerfd_setup()
224 alarm_start_relative(&ctx->t.alarm, texp); in timerfd_setup()
226 hrtimer_start(&ctx->t.tmr, texp, htmode); in timerfd_setup()
229 if (timerfd_canceled(ctx)) in timerfd_setup()
233 ctx->settime_flags = flags & TFD_SETTIME_FLAGS; in timerfd_setup()
239 struct timerfd_ctx *ctx = file->private_data; in timerfd_release() local
241 timerfd_remove_cancel(ctx); in timerfd_release()
243 if (isalarm(ctx)) in timerfd_release()
244 alarm_cancel(&ctx->t.alarm); in timerfd_release()
246 hrtimer_cancel(&ctx->t.tmr); in timerfd_release()
247 kfree_rcu(ctx, rcu); in timerfd_release()
253 struct timerfd_ctx *ctx = file->private_data; in timerfd_poll() local
257 poll_wait(file, &ctx->wqh, wait); in timerfd_poll()
259 spin_lock_irqsave(&ctx->wqh.lock, flags); in timerfd_poll()
260 if (ctx->ticks) in timerfd_poll()
262 spin_unlock_irqrestore(&ctx->wqh.lock, flags); in timerfd_poll()
270 struct timerfd_ctx *ctx = file->private_data; in timerfd_read() local
276 spin_lock_irq(&ctx->wqh.lock); in timerfd_read()
280 res = wait_event_interruptible_locked_irq(ctx->wqh, ctx->ticks); in timerfd_read()
287 if (timerfd_canceled(ctx)) { in timerfd_read()
288 ctx->ticks = 0; in timerfd_read()
289 ctx->expired = 0; in timerfd_read()
293 if (ctx->ticks) { in timerfd_read()
294 ticks = ctx->ticks; in timerfd_read()
296 if (ctx->expired && ctx->tintv) { in timerfd_read()
303 if (isalarm(ctx)) { in timerfd_read()
305 &ctx->t.alarm, ctx->tintv) - 1; in timerfd_read()
306 alarm_restart(&ctx->t.alarm); in timerfd_read()
308 ticks += hrtimer_forward_now(&ctx->t.tmr, in timerfd_read()
309 ctx->tintv) - 1; in timerfd_read()
310 hrtimer_restart(&ctx->t.tmr); in timerfd_read()
313 ctx->expired = 0; in timerfd_read()
314 ctx->ticks = 0; in timerfd_read()
316 spin_unlock_irq(&ctx->wqh.lock); in timerfd_read()
325 struct timerfd_ctx *ctx = file->private_data; in timerfd_show() local
328 spin_lock_irq(&ctx->wqh.lock); in timerfd_show()
329 value = ktime_to_timespec64(timerfd_get_remaining(ctx)); in timerfd_show()
330 interval = ktime_to_timespec64(ctx->tintv); in timerfd_show()
331 spin_unlock_irq(&ctx->wqh.lock); in timerfd_show()
339 ctx->clockid, in timerfd_show()
340 (unsigned long long)ctx->ticks, in timerfd_show()
341 ctx->settime_flags, in timerfd_show()
354 struct timerfd_ctx *ctx = file->private_data; in timerfd_ioctl() local
366 spin_lock_irq(&ctx->wqh.lock); in timerfd_ioctl()
367 if (!timerfd_canceled(ctx)) { in timerfd_ioctl()
368 ctx->ticks = ticks; in timerfd_ioctl()
369 wake_up_locked_poll(&ctx->wqh, EPOLLIN); in timerfd_ioctl()
372 spin_unlock_irq(&ctx->wqh.lock); in timerfd_ioctl()
411 struct timerfd_ctx *ctx; in SYSCALL_DEFINE2() local
431 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); in SYSCALL_DEFINE2()
432 if (!ctx) in SYSCALL_DEFINE2()
435 init_waitqueue_head(&ctx->wqh); in SYSCALL_DEFINE2()
436 spin_lock_init(&ctx->cancel_lock); in SYSCALL_DEFINE2()
437 ctx->clockid = clockid; in SYSCALL_DEFINE2()
439 if (isalarm(ctx)) in SYSCALL_DEFINE2()
440 alarm_init(&ctx->t.alarm, in SYSCALL_DEFINE2()
441 ctx->clockid == CLOCK_REALTIME_ALARM ? in SYSCALL_DEFINE2()
445 hrtimer_init(&ctx->t.tmr, clockid, HRTIMER_MODE_ABS); in SYSCALL_DEFINE2()
447 ctx->moffs = ktime_mono_to_real(0); in SYSCALL_DEFINE2()
451 ufd = anon_inode_getfd(file_name_buf, &timerfd_fops, ctx, in SYSCALL_DEFINE2()
454 kfree(ctx); in SYSCALL_DEFINE2()
464 struct timerfd_ctx *ctx; in do_timerfd_settime() local
474 ctx = f.file->private_data; in do_timerfd_settime()
476 if (isalarm(ctx) && !capable(CAP_WAKE_ALARM)) { in do_timerfd_settime()
481 timerfd_setup_cancel(ctx, flags); in do_timerfd_settime()
488 spin_lock_irq(&ctx->wqh.lock); in do_timerfd_settime()
490 if (isalarm(ctx)) { in do_timerfd_settime()
491 if (alarm_try_to_cancel(&ctx->t.alarm) >= 0) in do_timerfd_settime()
494 if (hrtimer_try_to_cancel(&ctx->t.tmr) >= 0) in do_timerfd_settime()
497 spin_unlock_irq(&ctx->wqh.lock); in do_timerfd_settime()
499 if (isalarm(ctx)) in do_timerfd_settime()
500 hrtimer_cancel_wait_running(&ctx->t.alarm.timer); in do_timerfd_settime()
502 hrtimer_cancel_wait_running(&ctx->t.tmr); in do_timerfd_settime()
511 if (ctx->expired && ctx->tintv) { in do_timerfd_settime()
512 if (isalarm(ctx)) in do_timerfd_settime()
513 alarm_forward_now(&ctx->t.alarm, ctx->tintv); in do_timerfd_settime()
515 hrtimer_forward_now(&ctx->t.tmr, ctx->tintv); in do_timerfd_settime()
518 old->it_value = ktime_to_timespec64(timerfd_get_remaining(ctx)); in do_timerfd_settime()
519 old->it_interval = ktime_to_timespec64(ctx->tintv); in do_timerfd_settime()
524 ret = timerfd_setup(ctx, flags, new); in do_timerfd_settime()
526 spin_unlock_irq(&ctx->wqh.lock); in do_timerfd_settime()
534 struct timerfd_ctx *ctx; in do_timerfd_gettime() local
538 ctx = f.file->private_data; in do_timerfd_gettime()
540 spin_lock_irq(&ctx->wqh.lock); in do_timerfd_gettime()
541 if (ctx->expired && ctx->tintv) { in do_timerfd_gettime()
542 ctx->expired = 0; in do_timerfd_gettime()
544 if (isalarm(ctx)) { in do_timerfd_gettime()
545 ctx->ticks += in do_timerfd_gettime()
547 &ctx->t.alarm, ctx->tintv) - 1; in do_timerfd_gettime()
548 alarm_restart(&ctx->t.alarm); in do_timerfd_gettime()
550 ctx->ticks += in do_timerfd_gettime()
551 hrtimer_forward_now(&ctx->t.tmr, ctx->tintv) in do_timerfd_gettime()
553 hrtimer_restart(&ctx->t.tmr); in do_timerfd_gettime()
556 t->it_value = ktime_to_timespec64(timerfd_get_remaining(ctx)); in do_timerfd_gettime()
557 t->it_interval = ktime_to_timespec64(ctx->tintv); in do_timerfd_gettime()
558 spin_unlock_irq(&ctx->wqh.lock); in do_timerfd_gettime()