]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/kern/thread_call.c
xnu-2782.10.72.tar.gz
[apple/xnu.git] / osfmk / kern / thread_call.c
index 610b94991d023b51c459a48b40574cf435a61860..99ffcc9b5cb21d5633ac7c48bbb6ce05a3c1bde4 100644 (file)
@@ -154,10 +154,10 @@ disable_ints_and_lock(void)
 }
 
 static inline void 
-enable_ints_and_unlock(void)
+enable_ints_and_unlock(spl_t s)
 {
        thread_call_unlock();
-       (void)spllo();
+       splx(s);
 }
 
 
@@ -307,6 +307,7 @@ thread_call_initialize(void)
        kern_return_t                   result;
        thread_t                        thread;
        int                             i;
+       spl_t                   s;
 
        i = sizeof (thread_call_data_t);
        thread_call_zone = zinit(i, 4096 * i, 16 * i, "thread_call");
@@ -332,7 +333,7 @@ thread_call_initialize(void)
        thread_call_group_setup(&thread_call_groups[THREAD_CALL_PRIORITY_KERNEL], THREAD_CALL_PRIORITY_KERNEL, 1, TRUE);
        thread_call_group_setup(&thread_call_groups[THREAD_CALL_PRIORITY_HIGH], THREAD_CALL_PRIORITY_HIGH, THREAD_CALL_THREAD_MIN, FALSE);
 
-       disable_ints_and_lock();
+       s = disable_ints_and_lock();
 
        queue_init(&thread_call_internal_queue);
        for (
@@ -346,7 +347,7 @@ thread_call_initialize(void)
 
        thread_call_daemon_awake = TRUE;
 
-       enable_ints_and_unlock();
+       enable_ints_and_unlock(s);
 
        result = kernel_thread_start_priority((thread_continue_t)thread_call_daemon, NULL, BASEPRI_PREEMPT + 1, &thread);
        if (result != KERN_SUCCESS)
@@ -522,7 +523,7 @@ _set_delayed_call_timer(
        timer_call_enter_with_leeway(&group->delayed_timer, NULL,
            call->tc_soft_deadline, leeway,
            TIMER_CALL_SYS_CRITICAL|TIMER_CALL_LEEWAY,
-           ((call->tc_soft_deadline & 0x1) == 0x1));
+           ((call->tc_flags & THREAD_CALL_RATELIMITED) == THREAD_CALL_RATELIMITED));
 }
 
 /*
@@ -925,17 +926,13 @@ thread_call_enter_delayed_internal(
        else
                deadline += slop;
 
-       /* Bit 0 of the "soft" deadline indicates that
-        * this particular callout requires rate-limiting
-        * behaviour. Maintain the invariant deadline >= soft_deadline
-        */
-       deadline |= 1;
        if (ratelimited) {
-               call->tc_soft_deadline |= 0x1ULL;
+               call->tc_flags |= TIMER_CALL_RATELIMITED;
        } else {
-               call->tc_soft_deadline &= ~0x1ULL;
+               call->tc_flags &= ~TIMER_CALL_RATELIMITED;
        }
 
+
        call->tc_call.param1 = param1;
        call->ttd = (sdeadline > abstime) ? (sdeadline - abstime) : 0;
 
@@ -1112,7 +1109,7 @@ sched_call_thread(
  * if the client has so requested.
  */
 static void
-thread_call_finish(thread_call_t call)
+thread_call_finish(thread_call_t call, spl_t *s)
 {
        boolean_t dowake = FALSE;
 
@@ -1138,11 +1135,11 @@ thread_call_finish(thread_call_t call)
                        panic("Someone waiting on a thread call that is scheduled for free: %p\n", call->tc_call.func);
                }
 
-               enable_ints_and_unlock();
+               enable_ints_and_unlock(*s);
 
                zfree(thread_call_zone, call);
 
-               (void)disable_ints_and_lock();
+               *s = disable_ints_and_lock();
        }
 
 }
@@ -1157,6 +1154,7 @@ thread_call_thread(
 {
        thread_t        self = current_thread();
        boolean_t       canwait;
+       spl_t           s;
 
        if ((thread_get_tag_internal(self) & THREAD_TAG_CALLOUT) == 0)
                (void)thread_set_tag_internal(self, THREAD_TAG_CALLOUT);
@@ -1172,7 +1170,7 @@ thread_call_thread(
                panic("thread_terminate() returned?");
        }
 
-       (void)disable_ints_and_lock();
+       s = disable_ints_and_lock();
 
        thread_sched_call(self, group->sched_call);
 
@@ -1202,7 +1200,7 @@ thread_call_thread(
                } else
                        canwait = FALSE;
 
-               enable_ints_and_unlock();
+               enable_ints_and_unlock(s);
 
                KERNEL_DEBUG_CONSTANT(
                                MACHDBG_CODE(DBG_MACH_SCHED,MACH_CALLOUT) | DBG_FUNC_NONE,
@@ -1224,13 +1222,11 @@ thread_call_thread(
                                        pl, (void *)VM_KERNEL_UNSLIDE(func), param0, param1);
                }
 
-               (void)thread_funnel_set(self->funnel_lock, FALSE);              /* XXX */
-
-               (void) disable_ints_and_lock();
+               s = disable_ints_and_lock();
                
                if (canwait) {
                        /* Frees if so desired */
-                       thread_call_finish(call);
+                       thread_call_finish(call, &s);
                }
        }
 
@@ -1273,7 +1269,7 @@ thread_call_thread(
                        panic("kcall worker unable to assert wait?");
                }   
 
-               enable_ints_and_unlock();
+               enable_ints_and_unlock(s);
 
                thread_block_parameter((thread_continue_t)thread_call_thread, group);
        } else {
@@ -1282,14 +1278,14 @@ thread_call_thread(
 
                        wait_queue_assert_wait(&group->idle_wqueue, NO_EVENT, THREAD_UNINT, 0); /* Interrupted means to exit */
 
-                       enable_ints_and_unlock();
+                       enable_ints_and_unlock(s);
 
                        thread_block_parameter((thread_continue_t)thread_call_thread, group);
                        /* NOTREACHED */
                }
        }
 
-       enable_ints_and_unlock();
+       enable_ints_and_unlock(s);
 
        thread_terminate(self);
        /* NOTREACHED */
@@ -1306,8 +1302,9 @@ thread_call_daemon_continue(__unused void *arg)
        int             i;
        kern_return_t   kr;
        thread_call_group_t group;
+       spl_t   s;
 
-       (void)disable_ints_and_lock();
+       s = disable_ints_and_lock();
 
        /* Starting at zero happens to be high-priority first. */
        for (i = 0; i < THREAD_CALL_GROUP_COUNT; i++) {
@@ -1315,7 +1312,7 @@ thread_call_daemon_continue(__unused void *arg)
                while (thread_call_group_should_add_thread(group)) {
                        group->active_count++;
 
-                       enable_ints_and_unlock();
+                       enable_ints_and_unlock(s);
 
                        kr = thread_call_thread_create(group);
                        if (kr != KERN_SUCCESS) {
@@ -1324,11 +1321,11 @@ thread_call_daemon_continue(__unused void *arg)
                                 * We can try again later.
                                 */
                                delay(10000); /* 10 ms */
-                               (void)disable_ints_and_lock();
+                               s = disable_ints_and_lock();
                                goto out;
                        }
 
-                       (void)disable_ints_and_lock();
+                       s = disable_ints_and_lock();
                }
        }
 
@@ -1336,7 +1333,7 @@ out:
        thread_call_daemon_awake = FALSE;
        wait_queue_assert_wait(&daemon_wqueue, NO_EVENT, THREAD_UNINT, 0);
 
-       enable_ints_and_unlock();
+       enable_ints_and_unlock(s);
 
        thread_block_parameter((thread_continue_t)thread_call_daemon_continue, NULL);
        /* NOTREACHED */
@@ -1396,13 +1393,7 @@ thread_call_delayed_timer(
 
        while (!queue_end(&group->delayed_queue, qe(call))) {
                if (call->tc_soft_deadline <= timestamp) {
-                       /* Bit 0 of the "soft" deadline indicates that
-                        * this particular callout is rate-limited
-                        * and hence shouldn't be processed before its
-                        * hard deadline. Rate limited timers aren't
-                        * skipped when a forcible reevaluation is in progress.
-                        */
-                       if ((call->tc_soft_deadline & 0x1) &&
+                       if ((call->tc_flags & THREAD_CALL_RATELIMITED) &&
                            (CE(call)->deadline > timestamp) &&
                            (ml_timer_forced_evaluation() == FALSE)) {
                                break;
@@ -1567,10 +1558,11 @@ boolean_t
 thread_call_isactive(thread_call_t call) 
 {
        boolean_t active;
+       spl_t   s;
 
-       disable_ints_and_lock();
+       s = disable_ints_and_lock();
        active = (call->tc_submit_count > call->tc_finish_count);
-       enable_ints_and_unlock();
+       enable_ints_and_unlock(s);
 
        return active;
 }