X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/8f6c56a50524aa785f7e596d52dddfb331e18961..d41d1dae2cd00cc08c7982087d1c445180cad9f5:/osfmk/kern/syscall_subr.c?ds=inline diff --git a/osfmk/kern/syscall_subr.c b/osfmk/kern/syscall_subr.c index c74f325ad..3daf1ec38 100644 --- a/osfmk/kern/syscall_subr.c +++ b/osfmk/kern/syscall_subr.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2009 Apple Inc. All rights reserved. * * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * @@ -74,6 +74,25 @@ #include #include + +#ifdef MACH_BSD +extern void workqueue_thread_yielded(void); +#endif /* MACH_BSD */ + + +/* Called from commpage to take a delayed preemption when exiting + * the "Preemption Free Zone" (PFZ). + */ +kern_return_t +pfz_exit( +__unused struct pfz_exit_args *args) +{ + /* For now, nothing special to do. We'll pick up the ASTs on kernel exit. */ + + return (KERN_SUCCESS); +} + + /* * swtch and swtch_pri both attempt to context switch (logic in * thread_block no-ops the context switch if nothing would happen). @@ -96,8 +115,7 @@ swtch_continue(void) disable_preemption(); myprocessor = current_processor(); - result = myprocessor->runq.count > 0 || - myprocessor->processor_set->runq.count > 0; + result = myprocessor->runq.count > 0 || rt_runq.count > 0; enable_preemption(); thread_syscall_return(result); @@ -113,8 +131,7 @@ swtch( disable_preemption(); myprocessor = current_processor(); - if ( myprocessor->runq.count == 0 && - myprocessor->processor_set->runq.count == 0 ) { + if (myprocessor->runq.count == 0 && rt_runq.count == 0) { mp_enable_preemption(); return (FALSE); @@ -127,8 +144,7 @@ swtch( disable_preemption(); myprocessor = current_processor(); - result = myprocessor->runq.count > 0 || - myprocessor->processor_set->runq.count > 0; + result = myprocessor->runq.count > 0 || rt_runq.count > 0; enable_preemption(); return (result); @@ -144,8 +160,7 @@ swtch_pri_continue(void) disable_preemption(); myprocessor = current_processor(); - result = myprocessor->runq.count > 0 || - myprocessor->processor_set->runq.count > 0; + result = myprocessor->runq.count > 0 || rt_runq.count > 0; mp_enable_preemption(); thread_syscall_return(result); @@ -161,8 +176,7 @@ __unused struct swtch_pri_args *args) disable_preemption(); myprocessor = current_processor(); - if ( myprocessor->runq.count == 0 && - myprocessor->processor_set->runq.count == 0 ) { + if (myprocessor->runq.count == 0 && rt_runq.count == 0) { mp_enable_preemption(); return (FALSE); @@ -179,8 +193,7 @@ __unused struct swtch_pri_args *args) disable_preemption(); myprocessor = current_processor(); - result = myprocessor->runq.count > 0 || - myprocessor->processor_set->runq.count > 0; + result = myprocessor->runq.count > 0 || rt_runq.count > 0; enable_preemption(); return (result); @@ -227,6 +240,8 @@ thread_switch( return (KERN_INVALID_ARGUMENT); } + workqueue_thread_yielded(); + /* * Translate the port name if supplied. */ @@ -242,7 +257,7 @@ thread_switch( ipc_port_release(port); if (thread == self) { - thread_deallocate_internal(thread); + (void)thread_deallocate_internal(thread); thread = THREAD_NULL; } } @@ -263,9 +278,9 @@ thread_switch( thread_lock(thread); /* - * Check if the thread is in the right pset, - * is not bound to a different processor, - * and that realtime is not involved. + * Check that the thread is not bound + * to a different processor, and that realtime + * is not involved. * * Next, pull it off its run queue. If it * doesn't come, it's not eligible. @@ -273,16 +288,15 @@ thread_switch( processor = current_processor(); if (processor->current_pri < BASEPRI_RTQUEUES && thread->sched_pri < BASEPRI_RTQUEUES && - thread->processor_set == processor->processor_set && (thread->bound_processor == PROCESSOR_NULL || thread->bound_processor == processor) && - run_queue_remove(thread) != RUN_QUEUE_NULL ) { + run_queue_remove(thread) ) { /* * Hah, got it!! */ thread_unlock(thread); - thread_deallocate_internal(thread); + (void)thread_deallocate_internal(thread); if (option == SWITCH_OPTION_WAIT) assert_wait_timeout((event_t)assert_wait_timeout, THREAD_ABORTSAFE, @@ -338,7 +352,6 @@ thread_depress_abstime( self->sched_pri = DEPRESSPRI; myprocessor->current_pri = self->sched_pri; - self->sched_mode &= ~TH_MODE_PREEMPT; self->sched_mode |= TH_MODE_DEPRESS; if (interval != 0) { @@ -434,7 +447,6 @@ thread_poll_yield( if (!(self->sched_mode & TH_MODE_ISDEPRESSED)) { self->sched_pri = DEPRESSPRI; myprocessor->current_pri = self->sched_pri; - self->sched_mode &= ~TH_MODE_PREEMPT; } self->computation_epoch = abstime; self->computation_metered = 0; @@ -445,9 +457,33 @@ thread_poll_yield( self->depress_timer_active++; thread_unlock(self); - if ((preempt = csw_check(self, myprocessor)) != AST_NONE) + if ((preempt = csw_check(myprocessor)) != AST_NONE) ast_on(preempt); } } splx(s); } + + +void +thread_yield_internal( + mach_msg_timeout_t ms) +{ + processor_t myprocessor; + + disable_preemption(); + myprocessor = current_processor(); + if (myprocessor->runq.count == 0 && rt_runq.count == 0) { + mp_enable_preemption(); + + return; + } + enable_preemption(); + + thread_depress_ms(ms); + + thread_block_reason(THREAD_CONTINUE_NULL, NULL, AST_YIELD); + + thread_depress_abort_internal(current_thread()); +} +