Remove the NO_CAS version of spin_pdr locks
authorBarret Rhoden <brho@cs.berkeley.edu>
Thu, 8 Sep 2016 16:38:16 +0000 (12:38 -0400)
committerBarret Rhoden <brho@cs.berkeley.edu>
Fri, 16 Sep 2016 18:35:09 +0000 (14:35 -0400)
If we ever update the RISC-V port, we can either build CAS out of their
LL/SC or do something else.

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
user/parlib/include/parlib/spinlock.h
user/parlib/spinlock.c

index 67bd58b..b03e745 100644 (file)
@@ -25,17 +25,6 @@ void spinlock_lock(spinlock_t *lock);
 void spinlock_unlock(spinlock_t *lock);
 bool spinlock_locked(spinlock_t *lock);
 
-/* RISCV doesn't support CAS, so til it does, we use the NO_CAS, even if they
- * didn't ask for it in their config. */
-#ifdef __riscv__
-# ifndef CONFIG_SPINPDR_NO_CAS
-#  define CONFIG_SPINPDR_NO_CAS 1
-# endif
-#endif
-
-/* Two different versions, with and without CAS.  Default is with CAS. */
-#ifndef CONFIG_SPINPDR_NO_CAS
-
 # define SPINPDR_UNLOCKED ((uint32_t)-1)
 
 struct spin_pdr_lock {
@@ -43,19 +32,6 @@ struct spin_pdr_lock {
 };
 # define SPINPDR_INITIALIZER {SPINPDR_UNLOCKED}
 
-#else /* NO_CAS */
-
-# define SPINPDR_VCOREID_UNKNOWN ((uint32_t)-1)
-
-struct spin_pdr_lock {
-       /* consider putting these on separate cache lines, if we ever use them */
-       spinlock_t spinlock;
-       uint32_t lockholder;
-};
-# define SPINPDR_INITIALIZER {SPINLOCK_INITIALIZER, SPINPDR_VCOREID_UNKNOWN}
-
-#endif /* CONFIG_SPINPDR_NO_CAS */
-
 typedef struct spin_pdr_lock spinpdrlock_t;
 
 void spin_pdr_init(struct spin_pdr_lock *pdr_lock);
index 8146a76..9ca395d 100644 (file)
@@ -40,9 +40,6 @@ bool spinlock_locked(spinlock_t *lock)
        return lock->lock != 0;
 }
 
-/* Two different versions, with and without CAS.  Default is with CAS. */
-#ifndef CONFIG_SPINPDR_NO_CAS /* CAS version */
-
 /* Spin-PRD locks (preemption detection/recovery).  Idea is to CAS and put the
  * lockholder's vcoreid in the lock, and all spinners ensure that vcore runs. */
 void spin_pdr_init(struct spin_pdr_lock *pdr_lock)
@@ -77,46 +74,6 @@ bool spin_pdr_locked(struct spin_pdr_lock *pdr_lock)
        return pdr_lock->lock != SPINPDR_UNLOCKED;
 }
 
-#else /* NON-CAS version */
-
-/* Using regular spinlocks, with SPINPDR_VCOREID_UNKNOWN (-1) meaning 'no
- * lockholder advertised yet'.  There are two spots where the lockholder still
- * holds the lock but hasn't advertised its vcoreid, and in those cases we
- * ensure all vcores aren't preempted (linear scan). */
-void spin_pdr_init(struct spin_pdr_lock *pdr_lock)
-{
-       spinlock_init(&pdr_lock->spinlock);
-       pdr_lock->lockholder = SPINPDR_VCOREID_UNKNOWN;
-}
-
-void __spin_pdr_lock(struct spin_pdr_lock *pdr_lock)
-{
-       uint32_t vcoreid = vcore_id();
-       uint32_t ensure_tgt;
-       while (spinlock_trylock(&pdr_lock->spinlock)) {
-               ensure_tgt = pdr_lock->lockholder;
-               /* ensure will make sure *every* vcore runs if you pass it your self. */
-               if (ensure_tgt == SPINPDR_VCOREID_UNKNOWN)
-                       ensure_tgt = vcoreid;
-               ensure_vcore_runs(ensure_tgt);
-               cpu_relax();
-       }
-       pdr_lock->lockholder = vcoreid;
-}
-
-void __spin_pdr_unlock(struct spin_pdr_lock *pdr_lock)
-{
-       pdr_lock->lockholder = SPINPDR_VCOREID_UNKNOWN;
-       spinlock_unlock(&pdr_lock->spinlock);
-}
-
-bool spin_pdr_locked(struct spin_pdr_lock *pdr_lock)
-{
-       return spinlock_locked(&pdr_lock->spinlock);
-}
-
-#endif /* CONFIG_SPINPDR_NO_CAS */
-
 void spin_pdr_lock(struct spin_pdr_lock *pdr_lock)
 {
        /* Disable notifs, if we're an _M uthread */