Lines Matching refs:tfd

134 	struct timerfd *tfd;  in timerfd_jumped()  local
142 LIST_FOREACH(tfd, &timerfd_list, entry) { in timerfd_jumped()
143 mtx_lock(&tfd->tfd_lock); in timerfd_jumped()
144 if (tfd->tfd_clockid != CLOCK_REALTIME || in timerfd_jumped()
145 (tfd->tfd_timflags & TFD_TIMER_ABSTIME) == 0 || in timerfd_jumped()
146 timespeccmp(&boottime, &tfd->tfd_boottim, ==)) { in timerfd_jumped()
147 mtx_unlock(&tfd->tfd_lock); in timerfd_jumped()
151 if (callout_active(&tfd->tfd_callout)) { in timerfd_jumped()
152 if ((tfd->tfd_timflags & TFD_TIMER_CANCEL_ON_SET) != 0) in timerfd_jumped()
153 tfd->tfd_jumped = TFD_CANCELED; in timerfd_jumped()
154 else if (timespeccmp(&boottime, &tfd->tfd_boottim, <)) in timerfd_jumped()
155 tfd->tfd_jumped = TFD_ZREAD; in timerfd_jumped()
161 if (!tfd->tfd_expired) { in timerfd_jumped()
163 &tfd->tfd_boottim, &diff); in timerfd_jumped()
164 timespecsub(&tfd->tfd_time.it_value, in timerfd_jumped()
165 &diff, &tfd->tfd_time.it_value); in timerfd_jumped()
166 if (callout_stop(&tfd->tfd_callout) == 1) { in timerfd_jumped()
167 callout_schedule_sbt(&tfd->tfd_callout, in timerfd_jumped()
168 tstosbt(tfd->tfd_time.it_value), in timerfd_jumped()
174 tfd->tfd_boottim = boottime; in timerfd_jumped()
175 mtx_unlock(&tfd->tfd_lock); in timerfd_jumped()
184 struct timerfd *tfd = fp->f_data; in timerfd_read() local
191 mtx_lock(&tfd->tfd_lock); in timerfd_read()
193 getnanotime(&tfd->tfd_atim); in timerfd_read()
194 if ((tfd->tfd_jumped & TFD_JUMPED) != 0) { in timerfd_read()
195 if (tfd->tfd_jumped == TFD_CANCELED) in timerfd_read()
197 tfd->tfd_jumped = TFD_READ; in timerfd_read()
198 tfd->tfd_count = 0; in timerfd_read()
199 mtx_unlock(&tfd->tfd_lock); in timerfd_read()
202 tfd->tfd_jumped = TFD_NOJUMP; in timerfd_read()
204 if (tfd->tfd_count == 0) { in timerfd_read()
206 mtx_unlock(&tfd->tfd_lock); in timerfd_read()
210 error = mtx_sleep(&tfd->tfd_count, &tfd->tfd_lock, in timerfd_read()
215 mtx_unlock(&tfd->tfd_lock); in timerfd_read()
220 count = tfd->tfd_count; in timerfd_read()
221 tfd->tfd_count = 0; in timerfd_read()
222 mtx_unlock(&tfd->tfd_lock); in timerfd_read()
253 struct timerfd *tfd = fp->f_data; in timerfd_poll() local
256 mtx_lock(&tfd->tfd_lock); in timerfd_poll()
258 tfd->tfd_count > 0 && tfd->tfd_jumped != TFD_READ) in timerfd_poll()
261 selrecord(td, &tfd->tfd_sel); in timerfd_poll()
262 mtx_unlock(&tfd->tfd_lock); in timerfd_poll()
270 struct timerfd *tfd = kn->kn_hook; in filt_timerfddetach() local
272 mtx_lock(&tfd->tfd_lock); in filt_timerfddetach()
273 knlist_remove(&tfd->tfd_sel.si_note, kn, 1); in filt_timerfddetach()
274 mtx_unlock(&tfd->tfd_lock); in filt_timerfddetach()
280 struct timerfd *tfd = kn->kn_hook; in filt_timerfdread() local
282 mtx_assert(&tfd->tfd_lock, MA_OWNED); in filt_timerfdread()
283 kn->kn_data = (int64_t)tfd->tfd_count; in filt_timerfdread()
284 return (tfd->tfd_count > 0); in filt_timerfdread()
296 struct timerfd *tfd = fp->f_data; in timerfd_kqfilter() local
302 kn->kn_hook = tfd; in timerfd_kqfilter()
303 knlist_add(&tfd->tfd_sel.si_note, kn, 0); in timerfd_kqfilter()
311 struct timerfd *tfd = fp->f_data; in timerfd_stat() local
318 mtx_lock(&tfd->tfd_lock); in timerfd_stat()
319 sb->st_atim = tfd->tfd_atim; in timerfd_stat()
320 sb->st_mtim = tfd->tfd_mtim; in timerfd_stat()
321 mtx_unlock(&tfd->tfd_lock); in timerfd_stat()
323 sb->st_ino = tfd->tfd_ino; in timerfd_stat()
324 sb->st_birthtim = tfd->tfd_birthtim; in timerfd_stat()
332 struct timerfd *tfd = fp->f_data; in timerfd_close() local
335 LIST_REMOVE(tfd, entry); in timerfd_close()
338 callout_drain(&tfd->tfd_callout); in timerfd_close()
339 seldrain(&tfd->tfd_sel); in timerfd_close()
340 knlist_destroy(&tfd->tfd_sel.si_note); in timerfd_close()
341 mtx_destroy(&tfd->tfd_lock); in timerfd_close()
342 free(tfd, M_TIMERFD); in timerfd_close()
352 struct timerfd *tfd = fp->f_data; in timerfd_fill_kinfo() local
355 kif->kf_un.kf_timerfd.kf_timerfd_clockid = tfd->tfd_clockid; in timerfd_fill_kinfo()
356 kif->kf_un.kf_timerfd.kf_timerfd_flags = tfd->tfd_flags; in timerfd_fill_kinfo()
357 kif->kf_un.kf_timerfd.kf_timerfd_addr = (uintptr_t)tfd; in timerfd_fill_kinfo()
380 timerfd_curval(struct timerfd *tfd, struct itimerspec *old_value) in timerfd_curval() argument
384 mtx_assert(&tfd->tfd_lock, MA_OWNED); in timerfd_curval()
385 *old_value = tfd->tfd_time; in timerfd_curval()
386 if (timespecisset(&tfd->tfd_time.it_value)) { in timerfd_curval()
388 timespecsub(&tfd->tfd_time.it_value, &curr_value, in timerfd_curval()
396 struct timerfd *tfd = (struct timerfd *)arg; in timerfd_expire() local
399 ++tfd->tfd_count; in timerfd_expire()
400 tfd->tfd_expired = true; in timerfd_expire()
401 if (timespecisset(&tfd->tfd_time.it_interval)) { in timerfd_expire()
404 if (timespeccmp(&uptime, &tfd->tfd_time.it_value, >)) { in timerfd_expire()
405 timespecsub(&uptime, &tfd->tfd_time.it_value, &uptime); in timerfd_expire()
406 tfd->tfd_count += tstosbt(uptime) / in timerfd_expire()
407 tstosbt(tfd->tfd_time.it_interval); in timerfd_expire()
409 timespecadd(&tfd->tfd_time.it_value, in timerfd_expire()
410 &tfd->tfd_time.it_interval, &tfd->tfd_time.it_value); in timerfd_expire()
411 callout_schedule_sbt(&tfd->tfd_callout, in timerfd_expire()
412 tstosbt(tfd->tfd_time.it_value), in timerfd_expire()
416 callout_deactivate(&tfd->tfd_callout); in timerfd_expire()
417 timespecclear(&tfd->tfd_time.it_value); in timerfd_expire()
420 wakeup(&tfd->tfd_count); in timerfd_expire()
421 selwakeup(&tfd->tfd_sel); in timerfd_expire()
422 KNOTE_LOCKED(&tfd->tfd_sel.si_note, 0); in timerfd_expire()
429 struct timerfd *tfd; in kern_timerfd_create() local
462 tfd = malloc(sizeof(*tfd), M_TIMERFD, M_WAITOK | M_ZERO); in kern_timerfd_create()
463 tfd->tfd_clockid = (clockid_t)clockid; in kern_timerfd_create()
464 tfd->tfd_flags = flags; in kern_timerfd_create()
465 tfd->tfd_ino = alloc_unr64(&tfdino_unr); in kern_timerfd_create()
466 mtx_init(&tfd->tfd_lock, "timerfd", NULL, MTX_DEF); in kern_timerfd_create()
467 callout_init_mtx(&tfd->tfd_callout, &tfd->tfd_lock, 0); in kern_timerfd_create()
468 knlist_init_mtx(&tfd->tfd_sel.si_note, &tfd->tfd_lock); in kern_timerfd_create()
469 timerfd_getboottime(&tfd->tfd_boottim); in kern_timerfd_create()
470 getnanotime(&tfd->tfd_birthtim); in kern_timerfd_create()
472 LIST_INSERT_HEAD(&timerfd_list, tfd, entry); in kern_timerfd_create()
475 finit(fp, fflags, DTYPE_TIMERFD, tfd, &timerfdops); in kern_timerfd_create()
487 struct timerfd *tfd; in kern_timerfd_gettime() local
497 tfd = fp->f_data; in kern_timerfd_gettime()
499 mtx_lock(&tfd->tfd_lock); in kern_timerfd_gettime()
500 timerfd_curval(tfd, curr_value); in kern_timerfd_gettime()
501 mtx_unlock(&tfd->tfd_lock); in kern_timerfd_gettime()
512 struct timerfd *tfd; in kern_timerfd_settime() local
529 tfd = fp->f_data; in kern_timerfd_settime()
531 mtx_lock(&tfd->tfd_lock); in kern_timerfd_settime()
532 getnanotime(&tfd->tfd_mtim); in kern_timerfd_settime()
533 tfd->tfd_timflags = flags; in kern_timerfd_settime()
537 timerfd_curval(tfd, old_value); in kern_timerfd_settime()
540 tfd->tfd_time = *new_value; in kern_timerfd_settime()
541 if (timespecisset(&tfd->tfd_time.it_value)) { in kern_timerfd_settime()
544 timespecadd(&tfd->tfd_time.it_value, &ts, in kern_timerfd_settime()
545 &tfd->tfd_time.it_value); in kern_timerfd_settime()
546 } else if (tfd->tfd_clockid == CLOCK_REALTIME) { in kern_timerfd_settime()
548 if (tfd->tfd_jumped == TFD_CANCELED) in kern_timerfd_settime()
551 timespecsub(&tfd->tfd_time.it_value, &tfd->tfd_boottim, in kern_timerfd_settime()
552 &tfd->tfd_time.it_value); in kern_timerfd_settime()
554 callout_reset_sbt(&tfd->tfd_callout, in kern_timerfd_settime()
555 tstosbt(tfd->tfd_time.it_value), in kern_timerfd_settime()
556 0, timerfd_expire, tfd, C_ABSOLUTE); in kern_timerfd_settime()
558 callout_stop(&tfd->tfd_callout); in kern_timerfd_settime()
560 tfd->tfd_count = 0; in kern_timerfd_settime()
561 tfd->tfd_expired = false; in kern_timerfd_settime()
562 tfd->tfd_jumped = TFD_NOJUMP; in kern_timerfd_settime()
563 mtx_unlock(&tfd->tfd_lock); in kern_timerfd_settime()