37#include "opt_ktrace.h"
41#include <sys/limits.h>
45#include <sys/sysproto.h>
46#include <sys/resourcevar.h>
47#include <sys/signalvar.h>
48#include <sys/kernel.h>
49#include <sys/sleepqueue.h>
50#include <sys/syscallsubr.h>
51#include <sys/sysctl.h>
52#include <sys/sysent.h>
55#include <sys/posix4.h>
57#include <sys/timers.h>
58#include <sys/timetc.h>
61#include <sys/ktrace.h>
65#include <vm/vm_extern.h>
67#define MAX_CLOCKS (CLOCK_MONOTONIC+1)
68#define CPUCLOCK_BIT 0x80000000
69#define CPUCLOCK_PROCESS_BIT 0x40000000
70#define CPUCLOCK_ID_MASK (~(CPUCLOCK_BIT|CPUCLOCK_PROCESS_BIT))
71#define MAKE_THREAD_CPUCLOCK(tid) (CPUCLOCK_BIT|(tid))
72#define MAKE_PROCESS_CPUCLOCK(pid) \
73 (CPUCLOCK_BIT|CPUCLOCK_PROCESS_BIT|(pid))
75#define NS_PER_SEC 1000000000
90static int settime(
struct thread *,
struct timeval *);
93 int flags,
const struct timespec *ua_rqtp,
94 struct timespec *ua_rmtp);
101static struct itimer *
itimer_find(
struct proc *,
int);
106 struct itimerspec *,
struct itimerspec *);
116#define CLOCK_CALL(clock, call, arglist) \
117 ((*posix_clocks[clock].call) arglist)
124 struct timeval delta, tv1, tv2;
125 static struct timeval maxtime, laststep;
144 if (delta.tv_sec < 0 || delta.tv_usec < 0) {
148 if (tv1.tv_sec > maxtime.tv_sec)
152 if (tv2.tv_sec < -1) {
153 tv->tv_sec = maxtime.tv_sec - 1;
154 printf(
"Time adjustment clamped to -1 second\n");
157 if (tv1.tv_sec == laststep.tv_sec)
159 if (delta.tv_sec > 1) {
160 tv->tv_sec = tv1.tv_sec + 1;
161 printf(
"Time adjustment clamped to +1 second\n");
167 ts.tv_sec = tv->tv_sec;
168 ts.tv_nsec = tv->tv_usec * 1000;
174#ifndef _SYS_SYSPROTO_H_
190 error = copyout(&clk_id, uap->
clock_id,
sizeof(clockid_t));
204 case CPUCLOCK_WHICH_PID:
206 error =
pget(
id, PGET_CANSEE | PGET_NOTID, &p);
212 pid = td->td_proc->p_pid;
216 case CPUCLOCK_WHICH_TID:
217 tid =
id == 0 ? td->td_tid : id;
225#ifndef _SYS_SYSPROTO_H_
240 error = copyout(&ats, uap->
tp,
sizeof(ats));
249 ats->tv_sec = runtime / 1000000;
250 ats->tv_nsec = runtime % 1000000 * 1000;
256 uint64_t runtime, curtime, switchtime;
258 if (targettd == NULL) {
260 switchtime = PCPU_GET(switchtime);
262 runtime = curthread->td_runtime;
264 runtime += curtime - switchtime;
266 PROC_LOCK_ASSERT(targettd->td_proc, MA_OWNED);
267 thread_lock(targettd);
268 runtime = targettd->td_runtime;
269 thread_unlock(targettd);
280 PROC_LOCK_ASSERT(targetp, MA_OWNED);
281 PROC_STATLOCK(targetp);
283 runtime = targetp->p_rux.rux_runtime;
284 if (curthread->td_proc == targetp)
285 runtime +=
cpu_ticks() - PCPU_GET(switchtime);
286 PROC_STATUNLOCK(targetp);
291get_cputime(
struct thread *td, clockid_t clock_id,
struct timespec *ats)
302 td2 =
tdfind(tid, p->p_pid);
306 PROC_UNLOCK(td2->td_proc);
309 error =
pget(pid, PGET_CANSEE, &p2);
321 struct timeval sys, user;
327 case CLOCK_REALTIME_PRECISE:
330 case CLOCK_REALTIME_FAST:
339 TIMEVAL_TO_TIMESPEC(&user, ats);
348 TIMEVAL_TO_TIMESPEC(&user, ats);
350 case CLOCK_MONOTONIC:
351 case CLOCK_MONOTONIC_PRECISE:
353 case CLOCK_UPTIME_PRECISE:
356 case CLOCK_UPTIME_FAST:
357 case CLOCK_MONOTONIC_FAST:
364 case CLOCK_THREAD_CPUTIME_ID:
367 case CLOCK_PROCESS_CPUTIME_ID:
373 if ((
int)clock_id >= 0)
380#ifndef _SYS_SYSPROTO_H_
383 const struct timespec *
tp;
393 if ((error = copyin(uap->
tp, &ats,
sizeof(ats))) != 0)
401 "do not perform possibly restrictive checks on settime(2) args");
409 if ((error =
priv_check(td, PRIV_CLOCK_SETTIME)) != 0)
411 if (clock_id != CLOCK_REALTIME)
413 if (ats->tv_nsec < 0 || ats->tv_nsec >=
NS_PER_SEC || ats->tv_sec < 0)
416 (ats->tv_sec > 8000ULL * 365 * 24 * 60 * 60 ||
420 TIMESPEC_TO_TIMEVAL(&atv, ats);
425#ifndef _SYS_SYSPROTO_H_
442 error = copyout(&
ts, uap->
tp,
sizeof(
ts));
453 case CLOCK_REALTIME_FAST:
454 case CLOCK_REALTIME_PRECISE:
455 case CLOCK_MONOTONIC:
456 case CLOCK_MONOTONIC_FAST:
457 case CLOCK_MONOTONIC_PRECISE:
459 case CLOCK_UPTIME_FAST:
460 case CLOCK_UPTIME_PRECISE:
477 case CLOCK_THREAD_CPUTIME_ID:
478 case CLOCK_PROCESS_CPUTIME_ID:
482 if (
ts->tv_nsec == 0)
486 if ((
int)clock_id < 0)
505 const struct timespec *rqt,
struct timespec *rmt)
507 struct timespec
ts, now;
508 sbintime_t sbt, sbtt, prec, tmp;
513 if (rqt->tv_nsec < 0 || rqt->tv_nsec >=
NS_PER_SEC)
515 if ((
flags & ~TIMER_ABSTIME) != 0)
519 case CLOCK_REALTIME_PRECISE:
520 case CLOCK_REALTIME_FAST:
522 is_abs_real = (
flags & TIMER_ABSTIME) != 0;
524 case CLOCK_MONOTONIC:
525 case CLOCK_MONOTONIC_PRECISE:
526 case CLOCK_MONOTONIC_FAST:
528 case CLOCK_UPTIME_PRECISE:
529 case CLOCK_UPTIME_FAST:
534 case CLOCK_PROCESS_CPUTIME_ID:
536 case CLOCK_THREAD_CPUTIME_ID:
542 if ((
flags & TIMER_ABSTIME) != 0) {
547 KASSERT(error == 0, (
"kern_clock_gettime: %d", error));
548 timespecsub(&
ts, &now, &
ts);
550 if (
ts.tv_sec < 0 || (
ts.tv_sec == 0 &&
ts.tv_nsec == 0)) {
554 if (
ts.tv_sec > INT32_MAX / 2) {
555 over =
ts.tv_sec - INT32_MAX / 2;
562 if (TIMESEL(&sbt, tmp))
565 error = tsleep_sbt(&
nanowait[curcpu], PWAIT | PCATCH,
"nanslp",
566 sbt, prec, C_ABSOLUTE);
567 }
while (error == 0 && is_abs_real && td->td_rtcgen == 0);
569 if (error != EWOULDBLOCK) {
570 if (TIMESEL(&sbtt, tmp))
574 if (error == ERESTART)
576 if ((
flags & TIMER_ABSTIME) == 0 && rmt != NULL) {
577 ts = sbttots(sbt - sbtt);
588#ifndef _SYS_SYSPROTO_H_
603#ifndef _SYS_SYSPROTO_H_
624 const struct timespec *ua_rqtp,
struct timespec *ua_rmtp)
626 struct timespec rmt, rqt;
629 error = copyin(ua_rqtp, &rqt,
sizeof(rqt));
633 if (error == EINTR && ua_rmtp != NULL && (
flags & TIMER_ABSTIME) == 0) {
634 error2 = copyout(&rmt, ua_rmtp,
sizeof(rmt));
641#ifndef _SYS_SYSPROTO_H_
657 error = copyout(&atv, uap->
tp, sizeof (atv));
659 if (error == 0 && uap->
tzp != NULL) {
660 rtz.tz_minuteswest = 0;
662 error = copyout(&rtz, uap->
tzp, sizeof (rtz));
667#ifndef _SYS_SYSPROTO_H_
677 struct timeval atv, *tvp;
678 struct timezone atz, *tzp;
682 error = copyin(uap->
tv, &atv,
sizeof(atv));
689 error = copyin(uap->
tzp, &atz,
sizeof(atz));
708 if (tv->tv_usec < 0 || tv->tv_usec >= 1000000 ||
737#ifndef _SYS_SYSPROTO_H_
746 struct itimerval aitv;
752 return (copyout(&aitv, uap->
itv, sizeof (
struct itimerval)));
758 struct proc *p = td->td_proc;
761 if (which > ITIMER_PROF)
764 if (which == ITIMER_REAL) {
772 *aitv = p->p_realtimer;
774 if (timevalisset(&aitv->it_value)) {
776 if (timevalcmp(&aitv->it_value, &ctv, <))
777 timevalclear(&aitv->it_value);
783 *aitv = p->p_stats->p_timer[which];
787 if (KTRPOINT(td, KTR_STRUCT))
793#ifndef _SYS_SYSPROTO_H_
802 struct itimerval aitv, oitv;
805 if (uap->
itv == NULL) {
810 if ((error = copyin(uap->
itv, &aitv,
sizeof(
struct itimerval))))
813 if (error != 0 || uap->
oitv == NULL)
815 return (copyout(&oitv, uap->
oitv,
sizeof(
struct itimerval)));
820 struct itimerval *oitv)
822 struct proc *p = td->td_proc;
829 if (which > ITIMER_PROF)
832 if (KTRPOINT(td, KTR_STRUCT))
836 aitv->it_value.tv_sec > INT32_MAX / 2)
838 if (!timevalisset(&aitv->it_value))
839 timevalclear(&aitv->it_interval);
840 else if (
itimerfix(&aitv->it_interval) ||
841 aitv->it_interval.tv_sec > INT32_MAX / 2)
844 if (which == ITIMER_REAL) {
846 if (timevalisset(&p->p_realtimer.it_value))
847 callout_stop(&p->p_itcallout);
849 if (timevalisset(&aitv->it_value)) {
852 sbt = tvtosbt(aitv->it_value);
853 callout_reset_sbt(&p->p_itcallout, sbt,
pr,
856 *oitv = p->p_realtimer;
857 p->p_realtimer = *aitv;
859 if (timevalisset(&oitv->it_value)) {
860 if (timevalcmp(&oitv->it_value, &ctv, <))
861 timevalclear(&oitv->it_value);
866 if (aitv->it_interval.tv_sec == 0 &&
867 aitv->it_interval.tv_usec != 0 &&
868 aitv->it_interval.tv_usec <
tick)
869 aitv->it_interval.tv_usec =
tick;
870 if (aitv->it_value.tv_sec == 0 &&
871 aitv->it_value.tv_usec != 0 &&
872 aitv->it_value.tv_usec <
tick)
873 aitv->it_value.tv_usec =
tick;
875 *oitv = p->p_stats->p_timer[which];
876 p->p_stats->p_timer[which] = *aitv;
880 if (KTRPOINT(td, KTR_STRUCT))
891 prec = isbtp == NULL ? tvtosbt(p->p_realtimer.it_interval) : *isbtp;
892 callout_reset_sbt(&p->p_itcallout, tvtosbt(p->p_realtimer.it_value),
903 PROC_LOCK_ASSERT(p, MA_OWNED);
905 if ((p->p_flag2 & P2_ITSTOPPED) != 0) {
906 p->p_flag2 &= ~P2_ITSTOPPED;
908 if (timevalcmp(&p->p_realtimer.it_value, &ctv, >=))
914 if (p->p_itimers != NULL) {
915 for (
id = 3;
id < TIMER_MAX;
id++) {
916 it = p->p_itimers->its_timers[id];
919 if ((it->it_flags & ITF_PSTOPPED) != 0) {
921 if ((it->it_flags & ITF_PSTOPPED) != 0) {
922 it->it_flags &= ~ITF_PSTOPPED;
923 if ((it->it_flags & ITF_DELETING) == 0)
951 p = (
struct proc *)arg;
953 if (!timevalisset(&p->p_realtimer.it_interval)) {
954 timevalclear(&p->p_realtimer.it_value);
955 if (p->p_flag & P_WEXIT)
960 isbt = tvtosbt(p->p_realtimer.it_interval);
967 &p->p_realtimer.it_interval);
968 }
while (timevalcmp(&p->p_realtimer.it_value, &ctv, <=));
970 if (P_SHOULDSTOP(p) || P_KILLED(p)) {
971 p->p_flag2 |= P2_ITSTOPPED;
975 p->p_flag2 &= ~P2_ITSTOPPED;
989 if (tv->tv_sec < 0 || tv->tv_usec < 0 || tv->tv_usec >= 1000000)
991 if (tv->tv_sec == 0 && tv->tv_usec != 0 &&
992 tv->tv_usec < (u_int)
tick / 16)
993 tv->tv_usec = (u_int)
tick / 16;
1011 if (itp->it_value.tv_usec < usec) {
1012 if (itp->it_value.tv_sec == 0) {
1014 usec -= itp->it_value.tv_usec;
1017 itp->it_value.tv_usec += 1000000;
1018 itp->it_value.tv_sec--;
1020 itp->it_value.tv_usec -= usec;
1022 if (timevalisset(&itp->it_value))
1026 if (timevalisset(&itp->it_interval)) {
1027 itp->it_value = itp->it_interval;
1028 itp->it_value.tv_usec -= usec;
1029 if (itp->it_value.tv_usec < 0) {
1030 itp->it_value.tv_usec += 1000000;
1031 itp->it_value.tv_sec--;
1034 itp->it_value.tv_usec = 0;
1049 t1->tv_sec += t2->tv_sec;
1050 t1->tv_usec += t2->tv_usec;
1058 t1->tv_sec -= t2->tv_sec;
1059 t1->tv_usec -= t2->tv_usec;
1067 if (t1->tv_usec < 0) {
1069 t1->tv_usec += 1000000;
1071 if (t1->tv_usec >= 1000000) {
1073 t1->tv_usec -= 1000000;
1081ratecheck(
struct timeval *lasttime,
const struct timeval *mininterval)
1083 struct timeval tv, delta;
1094 if (timevalcmp(&delta, mininterval, >=) ||
1095 (lasttime->tv_sec == 0 && lasttime->tv_usec == 0)) {
1128 if (lasttime->tv_sec == 0 || (u_int)(now - lasttime->tv_sec) >=
hz) {
1129 lasttime->tv_sec = now;
1131 return (maxpps != 0);
1134 return (maxpps < 0 || *curpps <= maxpps);
1141 static const struct kclock rt_clock = {
1148 itimer_zone = uma_zcreate(
"itimer",
sizeof(
struct itimer),
1153 p31b_setcfg(CTL_P1003_1B_DELAYTIMER_MAX, INT_MAX);
1161 printf(
"%s: invalid clockid\n", __func__);
1173 it = (
struct itimer *)mem;
1174 mtx_init(&it->it_mtx,
"itimer lock", NULL, MTX_DEF);
1183 it = (
struct itimer *)mem;
1184 mtx_destroy(&it->it_mtx);
1191 mtx_assert(&it->it_mtx, MA_OWNED);
1199 mtx_assert(&it->it_mtx, MA_OWNED);
1200 KASSERT(it->it_usecount > 0, (
"invalid it_usecount"));
1202 if (--it->it_usecount == 0 && (it->it_flags & ITF_WANTED) != 0)
1206#ifndef _SYS_SYSPROTO_H_
1216 struct sigevent *evp,
ev;
1220 if (uap->
evp == NULL) {
1223 error = copyin(uap->
evp, &
ev,
sizeof(
ev));
1230 error = copyout(&
id, uap->
timerid,
sizeof(
int));
1239 int *timerid,
int preset_id)
1241 struct proc *p = td->td_proc;
1253 if (evp->sigev_notify != SIGEV_NONE &&
1254 evp->sigev_notify != SIGEV_SIGNAL &&
1255 evp->sigev_notify != SIGEV_THREAD_ID)
1257 if ((evp->sigev_notify == SIGEV_SIGNAL ||
1258 evp->sigev_notify == SIGEV_THREAD_ID) &&
1259 !_SIG_VALID(evp->sigev_signo))
1263 if (p->p_itimers == NULL)
1268 it->it_usecount = 0;
1269 timespecclear(&it->it_time.it_value);
1270 timespecclear(&it->it_time.it_interval);
1272 it->it_overrun_last = 0;
1273 it->it_clockid = clock_id;
1275 ksiginfo_init(&it->it_ksi);
1276 it->it_ksi.ksi_flags |= KSI_INS | KSI_EXT;
1277 error =
CLOCK_CALL(clock_id, timer_create, (it));
1282 if (preset_id != -1) {
1283 KASSERT(preset_id >= 0 && preset_id < 3, (
"invalid preset_id"));
1285 if (p->p_itimers->its_timers[
id] != NULL) {
1295 for (
id = 3;
id < TIMER_MAX;
id++)
1296 if (p->p_itimers->its_timers[
id] == NULL)
1298 if (
id == TIMER_MAX) {
1304 p->p_itimers->its_timers[id] = it;
1306 it->it_sigev = *evp;
1308 it->it_sigev.sigev_notify = SIGEV_SIGNAL;
1311 case CLOCK_REALTIME:
1312 it->it_sigev.sigev_signo = SIGALRM;
1315 it->it_sigev.sigev_signo = SIGVTALRM;
1318 it->it_sigev.sigev_signo = SIGPROF;
1321 it->it_sigev.sigev_value.sival_int = id;
1324 if (it->it_sigev.sigev_notify == SIGEV_SIGNAL ||
1325 it->it_sigev.sigev_notify == SIGEV_THREAD_ID) {
1326 it->it_ksi.ksi_signo = it->it_sigev.sigev_signo;
1327 it->it_ksi.ksi_code = SI_TIMER;
1328 it->it_ksi.ksi_value = it->it_sigev.sigev_value;
1329 it->it_ksi.ksi_timerid = id;
1337 CLOCK_CALL(it->it_clockid, timer_delete, (it));
1343#ifndef _SYS_SYSPROTO_H_
1355static struct itimer *
1360 PROC_LOCK_ASSERT(p, MA_OWNED);
1361 if ((p->p_itimers == NULL) ||
1362 (timerid < 0) || (timerid >= TIMER_MAX) ||
1363 (it = p->p_itimers->its_timers[timerid]) == NULL) {
1367 if ((it->it_flags & ITF_DELETING) != 0) {
1377 struct proc *p = td->td_proc;
1388 it->it_flags |= ITF_DELETING;
1389 while (it->it_usecount > 0) {
1390 it->it_flags |= ITF_WANTED;
1391 msleep(it, &it->it_mtx, PPAUSE,
"itimer", 0);
1393 it->it_flags &= ~ITF_WANTED;
1394 CLOCK_CALL(it->it_clockid, timer_delete, (it));
1398 if (KSI_ONQ(&it->it_ksi))
1400 p->p_itimers->its_timers[timerid] = NULL;
1406#ifndef _SYS_SYSPROTO_H_
1417 struct itimerspec val, oval, *ovalp;
1420 error = copyin(uap->
value, &val,
sizeof(val));
1423 ovalp = uap->
ovalue != NULL ? &oval : NULL;
1425 if (error == 0 && uap->
ovalue != NULL)
1426 error = copyout(ovalp, uap->
ovalue,
sizeof(*ovalp));
1432 struct itimerspec *val,
struct itimerspec *oval)
1440 if (timer_id < 3 || (it =
itimer_find(p, timer_id)) == NULL) {
1446 error =
CLOCK_CALL(it->it_clockid, timer_settime, (it,
1454#ifndef _SYS_SYSPROTO_H_
1463 struct itimerspec val;
1468 error = copyout(&val, uap->
value,
sizeof(val));
1481 if (timer_id < 3 || (it =
itimer_find(p, timer_id)) == NULL) {
1487 error =
CLOCK_CALL(it->it_clockid, timer_gettime, (it, val));
1494#ifndef _SYS_SYSPROTO_H_
1509 struct proc *p = td->td_proc;
1519 td->td_retval[0] = it->it_overrun_last;
1530 callout_init_mtx(&it->it_callout, &it->it_mtx, 0);
1537 mtx_assert(&it->it_mtx, MA_OWNED);
1543 timespecclear(&it->it_time.it_value);
1544 timespecclear(&it->it_time.it_interval);
1546 callout_drain(&it->it_callout);
1554 struct timespec cts;
1556 mtx_assert(&it->it_mtx, MA_OWNED);
1559 *ovalue = it->it_time;
1560 if (ovalue->it_value.tv_sec != 0 || ovalue->it_value.tv_nsec != 0) {
1561 timespecsub(&ovalue->it_value, &cts, &ovalue->it_value);
1562 if (ovalue->it_value.tv_sec < 0 ||
1563 (ovalue->it_value.tv_sec == 0 &&
1564 ovalue->it_value.tv_nsec == 0)) {
1565 ovalue->it_value.tv_sec = 0;
1566 ovalue->it_value.tv_nsec = 1;
1574 struct itimerspec *ovalue)
1576 struct timespec cts,
ts;
1578 struct itimerspec val;
1580 mtx_assert(&it->it_mtx, MA_OWNED);
1586 if (timespecisset(&val.it_value)) {
1590 timespecclear(&val.it_interval);
1597 if (timespecisset(&val.it_value)) {
1600 if ((
flags & TIMER_ABSTIME) == 0) {
1602 timespecadd(&it->it_time.it_value, &cts,
1603 &it->it_time.it_value);
1605 timespecsub(&
ts, &cts, &
ts);
1611 TIMESPEC_TO_TIMEVAL(&tv, &
ts);
1615 callout_stop(&it->it_callout);
1624 if (
id == CLOCK_REALTIME)
1635 PROC_LOCK_ASSERT(p, MA_OWNED);
1638 ksi->ksi_overrun = it->it_overrun;
1639 it->it_overrun_last = it->it_overrun;
1653 if ((UINT64_MAX -
ts->tv_nsec) / NS_PER_SEC < ts->tv_sec)
1655 if (
ts->tv_sec == 0 &&
ts->tv_nsec != 0 &&
ts->tv_nsec <
tick * 1000)
1656 ts->tv_nsec =
tick * 1000;
1660#define timespectons(tsp) \
1661 ((uint64_t)(tsp)->tv_sec * NS_PER_SEC + (tsp)->tv_nsec)
1662#define timespecfromns(ns) (struct timespec){ \
1663 .tv_sec = (ns) / NS_PER_SEC, \
1664 .tv_nsec = (ns) % NS_PER_SEC \
1670 struct timespec cts,
ts;
1673 uint64_t interval, now, overruns,
value;
1677 if (timespeccmp(&cts, &it->it_time.it_value, >=)) {
1678 if (timespecisset(&it->it_time.it_interval)) {
1679 timespecadd(&it->it_time.it_value,
1680 &it->it_time.it_interval,
1681 &it->it_time.it_value);
1691 overruns = howmany(now -
value + 1, interval);
1692 if (it->it_overrun + overruns >=
1694 it->it_overrun + overruns <= INT_MAX) {
1695 it->it_overrun += (int)overruns;
1697 it->it_overrun = INT_MAX;
1698 it->it_ksi.ksi_errno = ERANGE;
1701 now + interval - (now -
value) % interval;
1706 timespecclear(&it->it_time.it_value);
1710 if (timespecisset(&it->it_time.it_value)) {
1711 if (P_SHOULDSTOP(p) || P_KILLED(p)) {
1712 it->it_flags |= ITF_PSTOPPED;
1714 timespecsub(&it->it_time.it_value, &cts, &
ts);
1715 TIMESPEC_TO_TIMEVAL(&tv, &
ts);
1716 callout_reset(&it->it_callout,
tvtohz(&tv),
1730 }
else if (timespecisset(&it->it_time.it_value)) {
1732 if (P_SHOULDSTOP(p) || P_KILLED(p)) {
1733 it->it_flags |= ITF_PSTOPPED;
1735 ts = it->it_time.it_value;
1736 timespecsub(&
ts, &cts, &
ts);
1737 TIMESPEC_TO_TIMEVAL(&tv, &
ts);
1738 callout_reset(&it->it_callout,
tvtohz(&tv),
1754 struct proc *p = it->it_proc;
1757 if (it->it_sigev.sigev_notify == SIGEV_SIGNAL ||
1758 it->it_sigev.sigev_notify == SIGEV_THREAD_ID) {
1761 timespecclear(&it->it_time.it_value);
1762 timespecclear(&it->it_time.it_interval);
1763 callout_stop(&it->it_callout);
1767 if (!KSI_ONQ(&it->it_ksi)) {
1768 it->it_ksi.ksi_errno = 0;
1769 ksiginfo_set_sigev(&it->it_ksi, &it->it_sigev);
1770 tdsendsignal(p, td, it->it_ksi.ksi_signo, &it->it_ksi);
1772 if (it->it_overrun < INT_MAX)
1775 it->it_ksi.ksi_errno = ERANGE;
1784 struct itimers *its;
1786 its =
malloc(
sizeof (
struct itimers), M_SUBPROC, M_WAITOK | M_ZERO);
1788 if (p->p_itimers == NULL) {
1794 free(its, M_SUBPROC);
1802 struct itimers *its;
1810 for (i = start_idx; i < TIMER_MAX; ++i) {
1811 if ((it = its->its_timers[i]) != NULL)
1814 if (its->its_timers[0] == NULL && its->its_timers[1] == NULL &&
1815 its->its_timers[2] == NULL) {
1818 p->p_itimers = NULL;
1820 free(its, M_SUBPROC);
int tvtohz(struct timeval *tv)
void *() malloc(size_t size, struct malloc_type *mtp, int flags)
void free(void *addr, struct malloc_type *mtp)
static struct pollrec pr[POLL_LIST_LEN]
int priv_check(struct thread *td, int priv)
int pget(pid_t pid, int flags, struct proc **pp)
int securelevel_gt(struct ucred *cr, int level)
void rufetch(struct proc *p, struct rusage *ru)
void calcru(struct proc *p, struct timeval *up, struct timeval *sp)
void sigqueue_take(ksiginfo_t *ksi)
void kern_psignal(struct proc *p, int sig)
int tdsendsignal(struct proc *p, struct thread *td, int sig, ksiginfo_t *ksi)
int sigev_findtd(struct proc *p, struct sigevent *sigev, struct thread **ttd)
void wakeup(const void *ident)
volatile int rtc_generation
void nanouptime(struct timespec *tsp)
uint64_t tc_getfrequency(void)
sbintime_t sbt_timethreshold
void getnanouptime(struct timespec *tsp)
void tc_setclock(struct timespec *ts)
volatile time_t time_second
void getmicrouptime(struct timeval *tvp)
void getnanotime(struct timespec *tsp)
void microtime(struct timeval *tvp)
void microuptime(struct timeval *tvp)
uint64_t cpu_tickrate(void)
void nanotime(struct timespec *tsp)
uint64_t cputick2usec(uint64_t tick)
struct thread * tdfind(lwpid_t tid, pid_t pid)
int sys_settimeofday(struct thread *td, struct settimeofday_args *uap)
static void itimer_start(void)
SYSINIT(posix_timer, SI_SUB_P1003_1B, SI_ORDER_FIRST+4, itimer_start, NULL)
#define CLOCK_CALL(clock, call, arglist)
int itimer_accept(struct proc *p, int timerid, ksiginfo_t *ksi)
void itimer_proc_continue(struct proc *p)
int kern_ktimer_gettime(struct thread *td, int timer_id, struct itimerspec *val)
int kern_settimeofday(struct thread *td, struct timeval *tv, struct timezone *tzp)
static int realtimer_create(struct itimer *)
static void itimers_event_exit_exec(int start_idx, struct proc *p)
int sys_setitimer(struct thread *td, struct setitimer_args *uap)
void itimers_exec(struct proc *p)
int sys_clock_settime(struct thread *td, struct clock_settime_args *uap)
static void itimer_enter(struct itimer *)
static int register_posix_clock(int, const struct kclock *)
static int settime(struct thread *, struct timeval *)
int ppsratecheck(struct timeval *lasttime, int *curpps, int maxpps)
int kern_ktimer_settime(struct thread *td, int timer_id, int flags, struct itimerspec *val, struct itimerspec *oval)
int sys_nanosleep(struct thread *td, struct nanosleep_args *uap)
int sys_clock_nanosleep(struct thread *td, struct clock_nanosleep_args *uap)
void timevaladd(struct timeval *t1, const struct timeval *t2)
static struct kclock posix_clocks[MAX_CLOCKS]
SYSCTL_INT(_debug, OID_AUTO, allow_insane_settime, CTLFLAG_RWTUN, &allow_insane_settime, 0, "do not perform possibly restrictive checks on settime(2) args")
void kern_thread_cputime(struct thread *targettd, struct timespec *ats)
int sys_clock_getres(struct thread *td, struct clock_getres_args *uap)
int kern_setitimer(struct thread *td, u_int which, struct itimerval *aitv, struct itimerval *oitv)
static void realtimer_expire(void *)
static int itimer_init(void *, int, int)
int itimerfix(struct timeval *tv)
int sys_ktimer_delete(struct thread *td, struct ktimer_delete_args *uap)
int sys_clock_gettime(struct thread *td, struct clock_gettime_args *uap)
int kern_clock_getres(struct thread *td, clockid_t clock_id, struct timespec *ts)
int kern_clock_gettime(struct thread *td, clockid_t clock_id, struct timespec *ats)
int sys_ktimer_create(struct thread *td, struct ktimer_create_args *uap)
int itimerdecr(struct itimerval *itp, int usec)
static int user_clock_nanosleep(struct thread *td, clockid_t clock_id, int flags, const struct timespec *ua_rqtp, struct timespec *ua_rmtp)
void timevalsub(struct timeval *t1, const struct timeval *t2)
void realitexpire(void *arg)
int sys_ktimer_gettime(struct thread *td, struct ktimer_gettime_args *uap)
#define MAKE_THREAD_CPUCLOCK(tid)
static struct itimer * itimer_find(struct proc *, int)
static void cputick2timespec(uint64_t runtime, struct timespec *ats)
int kern_ktimer_create(struct thread *td, clockid_t clock_id, struct sigevent *evp, int *timerid, int preset_id)
static int realtimer_delete(struct itimer *)
static void realtimer_clocktime(clockid_t, struct timespec *)
static int realtimer_gettime(struct itimer *, struct itimerspec *)
int kern_clock_getcpuclockid2(struct thread *td, id_t id, int which, clockid_t *clk_id)
int kern_clock_nanosleep(struct thread *td, clockid_t clock_id, int flags, const struct timespec *rqt, struct timespec *rmt)
static int allow_insane_settime
int sys_gettimeofday(struct thread *td, struct gettimeofday_args *uap)
static void itimer_fini(void *, int)
int kern_ktimer_delete(struct thread *td, int timerid)
static void itimer_fire(struct itimer *it)
#define timespecfromns(ns)
static int realtimer_settime(struct itimer *, int, struct itimerspec *, struct itimerspec *)
static void timevalfix(struct timeval *)
int kern_nanosleep(struct thread *td, struct timespec *rqt, struct timespec *rmt)
int kern_ktimer_getoverrun(struct thread *td, int timer_id)
#define timespectons(tsp)
int sys_ktimer_settime(struct thread *td, struct ktimer_settime_args *uap)
int kern_getitimer(struct thread *td, u_int which, struct itimerval *aitv)
int sys_clock_getcpuclockid2(struct thread *td, struct clock_getcpuclockid2_args *uap)
static int itimespecfix(struct timespec *ts)
void kern_process_cputime(struct proc *targetp, struct timespec *ats)
static uma_zone_t itimer_zone
#define CPUCLOCK_PROCESS_BIT
static void realtimer_expire_l(struct itimer *it, bool proc_locked)
int kern_clock_settime(struct thread *td, clockid_t clock_id, struct timespec *ats)
static void realitexpire_reset_callout(struct proc *p, sbintime_t *isbtp)
static int get_cputime(struct thread *td, clockid_t clock_id, struct timespec *ats)
int sys_ktimer_getoverrun(struct thread *td, struct ktimer_getoverrun_args *uap)
int ratecheck(struct timeval *lasttime, const struct timeval *mininterval)
int sys_getitimer(struct thread *td, struct getitimer_args *uap)
void itimers_exit(struct proc *p)
#define MAKE_PROCESS_CPUCLOCK(pid)
static uint8_t nanowait[MAXCPU]
static void itimer_leave(struct itimer *)
static void itimers_alloc(struct proc *)
void p31b_setcfg(int num, int value)
const struct timespec * tp
struct itimerspec * value
const struct itimerspec * value
struct itimerspec * ovalue
int printf(const char *fmt,...)
int kern_posix_error(struct thread *td, int error)