Lines Matching refs:tfd

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