]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/kern/kern_clock.c
xnu-4570.41.2.tar.gz
[apple/xnu.git] / bsd / kern / kern_clock.c
index 432a0f0e8b2e59a4884d860d972665e10bb805dd..08507cdc593e6c330f3b97ea0f95959cea5dbe97 100644 (file)
@@ -69,8 +69,6 @@
  * HISTORY
  */
 
-#include <machine/spl.h>
-
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/time.h>
@@ -140,8 +138,35 @@ timeout(
        thread_call_func_delayed((thread_call_func_t)fcn, param, deadline);
 }
 
+/*
+ *     Set a timeout with leeway.
+ *
+ *     fcn:            function to call
+ *     param:          parameter to pass to function
+ *     interval:       timeout interval, in hz.
+ *     leeway_interval:        leeway interval, in hz.
+ */
+void
+timeout_with_leeway(
+       timeout_fcn_t                   fcn,
+       void                                    *param,
+       int                                             interval,
+       int                                             leeway_interval)
+{
+       uint64_t                deadline;
+       uint64_t                leeway;
+
+       clock_interval_to_deadline(interval, NSEC_PER_SEC / hz, &deadline);
+
+       clock_interval_to_absolutetime_interval(leeway_interval, NSEC_PER_SEC / hz, &leeway);
+
+       thread_call_func_delayed_with_leeway((thread_call_func_t)fcn, param, deadline, leeway, THREAD_CALL_DELAY_LEEWAY);
+}
+
 /*
  * Cancel a timeout.
+ * Deprecated because it's very inefficient.
+ * Switch to an allocated thread call instead.
  */
 void
 untimeout(
@@ -176,6 +201,8 @@ bsd_timeout(
 
 /*
  * Cancel a timeout.
+ * Deprecated because it's very inefficient.
+ * Switch to an allocated thread call instead.
  */
 void
 bsd_untimeout(
@@ -228,20 +255,19 @@ static int
 sysctl_clockrate
 (__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, __unused struct sysctl_req *req)
 {
-       struct clockinfo clkinfo;
+       struct clockinfo clkinfo = {
+               .hz         = hz,
+               .tick       = tick,
+               .tickadj    = 0,
+               .stathz     = hz,
+               .profhz     = hz,
+       };
 
-       /*
-        * Construct clockinfo structure.
-        */
-       clkinfo.hz = hz;
-       clkinfo.tick = tick;
-       clkinfo.profhz = hz;
-       clkinfo.stathz = hz;
        return sysctl_io_opaque(req, &clkinfo, sizeof(clkinfo), NULL);
 }
 
 SYSCTL_PROC(_kern, KERN_CLOCKRATE, clockrate,
-               CTLTYPE_STRUCT | CTLFLAG_RD,
+               CTLTYPE_STRUCT | CTLFLAG_RD | CTLFLAG_LOCKED,
                0, 0, sysctl_clockrate, "S,clockinfo", "");
 
 
@@ -314,7 +340,7 @@ void
 startprofclock(struct proc *p)
 {
        if ((p->p_flag & P_PROFIL) == 0)
-               OSBitOrAtomic(P_PROFIL, (UInt32 *)&p->p_flag);
+               OSBitOrAtomic(P_PROFIL, &p->p_flag);
 }
 
 /*
@@ -324,7 +350,7 @@ void
 stopprofclock(struct proc *p)
 {
        if (p->p_flag & P_PROFIL)
-               OSBitAndAtomic(~((uint32_t)P_PROFIL), (UInt32 *)&p->p_flag);
+               OSBitAndAtomic(~((uint32_t)P_PROFIL), &p->p_flag);
 }
 
 /* TBD locking user profiling is not resolved yet */