kth: Remove irq_okay from sems and CVs
authorBarret Rhoden <brho@cs.berkeley.edu>
Fri, 14 Dec 2018 22:46:11 +0000 (17:46 -0500)
committerBarret Rhoden <brho@cs.berkeley.edu>
Tue, 18 Dec 2018 20:30:28 +0000 (15:30 -0500)
It wasn't necessary.  The only use for it was one assertion.  If that
assert would have failed, then the spinlock code will also fail
(assuming SPINLOCK_DEBUG is on).

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
kern/include/kthread.h
kern/src/kthread.c

index d9c8a74..3a4bdb5 100644 (file)
@@ -73,7 +73,6 @@ struct semaphore {
        struct kthread_tailq            waiters;
        int                                             nr_signals;
        spinlock_t                                      lock;
-       bool                                            irq_okay;
 };
 
 #ifdef CONFIG_SEMAPHORE_DEBUG
@@ -87,7 +86,6 @@ struct semaphore {
     .waiters    = TAILQ_HEAD_INITIALIZER((name).waiters),                      \
        .nr_signals = (n),                                                         \
     .lock       = SPINLOCK_INITIALIZER,                                        \
-    .irq_okay   = FALSE,                                                       \
        KTH_DB_INIT                                                                \
 }
 
@@ -96,7 +94,6 @@ struct semaphore {
     .waiters    = TAILQ_HEAD_INITIALIZER((name).waiters),                      \
        .nr_signals = (n),                                                         \
     .lock       = SPINLOCK_INITIALIZER_IRQSAVE,                                \
-    .irq_okay   = TRUE,                                                        \
        KTH_DB_INIT                                                                \
 }
 
@@ -108,7 +105,6 @@ struct cond_var {
        spinlock_t                                      *lock;          /* usually points to internal_ */
        spinlock_t                                      internal_lock;
        unsigned long                           nr_waiters;
-       bool                                            irq_okay;
 };
 
 struct cv_lookup_elm {
index dbe6ae7..f407f1d 100644 (file)
@@ -307,14 +307,12 @@ void sem_init(struct semaphore *sem, int signals)
 {
        sem_init_common(sem, signals);
        spinlock_init(&sem->lock);
-       sem->irq_okay = FALSE;
 }
 
 void sem_init_irqsave(struct semaphore *sem, int signals)
 {
        sem_init_common(sem, signals);
        spinlock_init_irqsave(&sem->lock);
-       sem->irq_okay = TRUE;
 }
 
 bool sem_trydown_bulk(struct semaphore *sem, int nr_signals)
@@ -721,7 +719,6 @@ void cv_init(struct cond_var *cv)
 
        cv->lock = &cv->internal_lock;
        spinlock_init(cv->lock);
-       cv->irq_okay = FALSE;
 }
 
 void cv_init_irqsave(struct cond_var *cv)
@@ -730,7 +727,6 @@ void cv_init_irqsave(struct cond_var *cv)
 
        cv->lock = &cv->internal_lock;
        spinlock_init_irqsave(cv->lock);
-       cv->irq_okay = TRUE;
 }
 
 void cv_init_with_lock(struct cond_var *cv, spinlock_t *lock)
@@ -738,15 +734,11 @@ void cv_init_with_lock(struct cond_var *cv, spinlock_t *lock)
        __cv_raw_init(cv);
 
        cv->lock = lock;
-       cv->irq_okay = FALSE;
 }
 
 void cv_init_irqsave_with_lock(struct cond_var *cv, spinlock_t *lock)
 {
-       __cv_raw_init(cv);
-
-       cv->lock = lock;
-       cv->irq_okay = TRUE;
+       cv_init_with_lock(cv, lock);
 }
 
 void cv_lock(struct cond_var *cv)
@@ -779,8 +771,9 @@ static void __attribute__((noreturn)) __cv_unlock_and_idle(void *arg)
        smp_idle();
 }
 
-/* Comes in locked.  The initial cv_lock would have disabled irqs (if
- * applicable). */
+/* Comes in locked.  Regarding IRQs, the initial cv_lock_irqsave would have
+ * disabled irqs.  When this returns, IRQs would still be disabled.  If it was a
+ * regular cv_lock(), IRQs will be enabled when we return. */
 void cv_wait_and_unlock(struct cond_var *cv)
 {
        bool irqs_were_on = irq_is_enabled();
@@ -806,12 +799,11 @@ void cv_wait_and_unlock(struct cond_var *cv)
 }
 
 /* Comes in locked.  Note cv_lock does not disable irqs.   They should still be
- * disabled from the initial cv_lock_irqsave(). */
+ * disabled from the initial cv_lock_irqsave(), which cv_wait_and_unlock()
+ * maintained. */
 void cv_wait(struct cond_var *cv)
 {
        cv_wait_and_unlock(cv);
-       if (cv->irq_okay)
-               assert(!irq_is_enabled());
        cv_lock(cv);
 }