From cb5e3ca248435f19fce0254987ba894a25611974 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Wed, 15 Feb 2023 23:40:54 +0100 Subject: Document spl levels of locks taken during interrupts --- device/ds_routines.c | 3 ++- device/io_req.h | 2 ++ device/tty.h | 2 +- kern/mach_clock.c | 1 + kern/processor.h | 3 ++- kern/sched.h | 4 +++- kern/sched_prim.c | 15 ++++++++------- kern/thread.h | 1 + 8 files changed, 20 insertions(+), 11 deletions(-) diff --git a/device/ds_routines.c b/device/ds_routines.c index 07ab7b30..94e61592 100644 --- a/device/ds_routines.c +++ b/device/ds_routines.c @@ -1507,8 +1507,9 @@ ds_no_senders(mach_no_senders_notification_t *notification) notification->not_count); } +/* Shall be taken at splio only */ +def_simple_lock_data(static, io_done_list_lock) /* Lock for... */ queue_head_t io_done_list; -def_simple_lock_data(static, io_done_list_lock) #define splio splsched /* XXX must block ALL io devices */ diff --git a/device/io_req.h b/device/io_req.h index b80b3dde..e66e0800 100644 --- a/device/io_req.h +++ b/device/io_req.h @@ -95,6 +95,8 @@ struct io_req { * locking is needed in this sequence. Unfortunately, a synchronous wait * for a buffer requires a lock to avoid problems if the wait and interrupt * happen simultaneously on different processors. + * + * Shall be taken at splio only */ #define ior_lock(ior) simple_lock(&(ior)->io_req_lock) diff --git a/device/tty.h b/device/tty.h index 0bdb2db9..b0f99cf5 100644 --- a/device/tty.h +++ b/device/tty.h @@ -43,7 +43,7 @@ #include struct tty { - decl_simple_lock_data(,t_lock) + decl_simple_lock_data(,t_lock) /* Shall be taken at spltty only */ struct cirbuf t_inq; /* input buffer */ struct cirbuf t_outq; /* output buffer */ char * t_addr; /* device pointer */ diff --git a/kern/mach_clock.c b/kern/mach_clock.c index ed38c76b..a3656948 100644 --- a/kern/mach_clock.c +++ b/kern/mach_clock.c @@ -119,6 +119,7 @@ MACRO_BEGIN \ } while ((time)->seconds != mtime->check_seconds64); \ MACRO_END +/* Shall be taken at splsched only */ def_simple_lock_data(static, timer_lock) /* lock for ... */ timer_elt_data_t timer_head; /* ordered list of timeouts */ /* (doubles as end-of-list) */ diff --git a/kern/processor.h b/kern/processor.h index abc2e866..17b784a3 100644 --- a/kern/processor.h +++ b/kern/processor.h @@ -56,7 +56,7 @@ struct processor_set { struct run_queue runq; /* runq for this set */ queue_head_t idle_queue; /* idle processors */ int idle_count; /* how many ? */ - decl_simple_lock_data(, idle_lock) /* lock for above */ + decl_simple_lock_data(, idle_lock) /* lock for above, shall be taken at splsched only */ queue_head_t processors; /* all processors here */ int processor_count; /* how many ? */ boolean_t empty; /* true if no processors */ @@ -221,6 +221,7 @@ extern processor_t processor_ptr[NCPUS]; #define pset_ref_lock(pset) simple_lock(&(pset)->ref_lock) #define pset_ref_unlock(pset) simple_unlock(&(pset)->ref_lock) +/* Shall be taken at splsched only */ #define processor_lock(pr) simple_lock(&(pr)->lock) #define processor_unlock(pr) simple_unlock(&(pr)->lock) diff --git a/kern/sched.h b/kern/sched.h index 588e0aa6..07d27ff5 100644 --- a/kern/sched.h +++ b/kern/sched.h @@ -64,7 +64,9 @@ struct run_queue { queue_head_t runq[NRQS]; /* one for each priority */ - decl_simple_lock_data(, lock) /* one lock for all queues */ + decl_simple_lock_data(, lock) /* one lock for all queues, + shall be taken at splsched + only */ int low; /* low queue value */ int count; /* count of threads runable */ }; diff --git a/kern/sched_prim.c b/kern/sched_prim.c index 713d379e..dd0f492b 100644 --- a/kern/sched_prim.c +++ b/kern/sched_prim.c @@ -127,8 +127,9 @@ timer_elt_data_t recompute_priorities_timer; #define NUMQUEUES 1031 +/* Shall be taken at splsched only */ +decl_simple_lock_data(static, wait_lock[NUMQUEUES]) /* Lock for... */ queue_head_t wait_queue[NUMQUEUES]; -decl_simple_lock_data(static, wait_lock[NUMQUEUES]) /* NOTE: we want a small positive integer out of this */ #define wait_hash(event) \ @@ -1251,7 +1252,7 @@ void thread_setrun( */ processor = th->last_processor; if (processor->state == PROCESSOR_IDLE) { - simple_lock(&processor->lock); + processor_lock(processor); simple_lock(&pset->idle_lock); if ((processor->state == PROCESSOR_IDLE) #if MACH_HOST @@ -1264,11 +1265,11 @@ void thread_setrun( processor->next_thread = th; processor->state = PROCESSOR_DISPATCHING; simple_unlock(&pset->idle_lock); - simple_unlock(&processor->lock); + processor_unlock(processor); return; } simple_unlock(&pset->idle_lock); - simple_unlock(&processor->lock); + processor_unlock(processor); } #endif /* HW_FOOTPRINT */ @@ -1309,7 +1310,7 @@ void thread_setrun( * processor here because it may not be the current one. */ if (processor->state == PROCESSOR_IDLE) { - simple_lock(&processor->lock); + processor_lock(processor); pset = processor->processor_set; simple_lock(&pset->idle_lock); if (processor->state == PROCESSOR_IDLE) { @@ -1319,11 +1320,11 @@ void thread_setrun( processor->next_thread = th; processor->state = PROCESSOR_DISPATCHING; simple_unlock(&pset->idle_lock); - simple_unlock(&processor->lock); + processor_unlock(processor); return; } simple_unlock(&pset->idle_lock); - simple_unlock(&processor->lock); + processor_unlock(processor); } rq = &(processor->runq); run_queue_enqueue(rq,th); diff --git a/kern/thread.h b/kern/thread.h index 7252f410..a5abefcc 100644 --- a/kern/thread.h +++ b/kern/thread.h @@ -387,6 +387,7 @@ extern void thread_unfreeze( #define thread_pcb(th) ((th)->pcb) +/* Shall be taken at splsched only */ #define thread_lock(th) simple_lock(&(th)->lock) #define thread_unlock(th) simple_unlock(&(th)->lock) -- cgit v1.2.3