locking/pvqspinlock: Convert fields of 'enum vcpu_state' to uppercase

Convert the fields of 'enum vcpu_state' to uppercase for better
readability. No functional changes intended.

Acked-by: Waiman Long <longman@redhat.com>
Signed-off-by: Qiuxu Zhuo <qiuxu.zhuo@intel.com>
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Link: https://lore.kernel.org/r/20240809014802.15320-1-qiuxu.zhuo@intel.com
This commit is contained in:
Qiuxu Zhuo 2024-08-09 09:48:02 +08:00 committed by Boqun Feng
parent 560af5dc83
commit 2628cbd039

View File

@ -38,13 +38,13 @@
#define PV_PREV_CHECK_MASK 0xff #define PV_PREV_CHECK_MASK 0xff
/* /*
* Queue node uses: vcpu_running & vcpu_halted. * Queue node uses: VCPU_RUNNING & VCPU_HALTED.
* Queue head uses: vcpu_running & vcpu_hashed. * Queue head uses: VCPU_RUNNING & VCPU_HASHED.
*/ */
enum vcpu_state { enum vcpu_state {
vcpu_running = 0, VCPU_RUNNING = 0,
vcpu_halted, /* Used only in pv_wait_node */ VCPU_HALTED, /* Used only in pv_wait_node */
vcpu_hashed, /* = pv_hash'ed + vcpu_halted */ VCPU_HASHED, /* = pv_hash'ed + VCPU_HALTED */
}; };
struct pv_node { struct pv_node {
@ -266,7 +266,7 @@ pv_wait_early(struct pv_node *prev, int loop)
if ((loop & PV_PREV_CHECK_MASK) != 0) if ((loop & PV_PREV_CHECK_MASK) != 0)
return false; return false;
return READ_ONCE(prev->state) != vcpu_running; return READ_ONCE(prev->state) != VCPU_RUNNING;
} }
/* /*
@ -279,7 +279,7 @@ static void pv_init_node(struct mcs_spinlock *node)
BUILD_BUG_ON(sizeof(struct pv_node) > sizeof(struct qnode)); BUILD_BUG_ON(sizeof(struct pv_node) > sizeof(struct qnode));
pn->cpu = smp_processor_id(); pn->cpu = smp_processor_id();
pn->state = vcpu_running; pn->state = VCPU_RUNNING;
} }
/* /*
@ -308,26 +308,26 @@ static void pv_wait_node(struct mcs_spinlock *node, struct mcs_spinlock *prev)
/* /*
* Order pn->state vs pn->locked thusly: * Order pn->state vs pn->locked thusly:
* *
* [S] pn->state = vcpu_halted [S] next->locked = 1 * [S] pn->state = VCPU_HALTED [S] next->locked = 1
* MB MB * MB MB
* [L] pn->locked [RmW] pn->state = vcpu_hashed * [L] pn->locked [RmW] pn->state = VCPU_HASHED
* *
* Matches the cmpxchg() from pv_kick_node(). * Matches the cmpxchg() from pv_kick_node().
*/ */
smp_store_mb(pn->state, vcpu_halted); smp_store_mb(pn->state, VCPU_HALTED);
if (!READ_ONCE(node->locked)) { if (!READ_ONCE(node->locked)) {
lockevent_inc(pv_wait_node); lockevent_inc(pv_wait_node);
lockevent_cond_inc(pv_wait_early, wait_early); lockevent_cond_inc(pv_wait_early, wait_early);
pv_wait(&pn->state, vcpu_halted); pv_wait(&pn->state, VCPU_HALTED);
} }
/* /*
* If pv_kick_node() changed us to vcpu_hashed, retain that * If pv_kick_node() changed us to VCPU_HASHED, retain that
* value so that pv_wait_head_or_lock() knows to not also try * value so that pv_wait_head_or_lock() knows to not also try
* to hash this lock. * to hash this lock.
*/ */
cmpxchg(&pn->state, vcpu_halted, vcpu_running); cmpxchg(&pn->state, VCPU_HALTED, VCPU_RUNNING);
/* /*
* If the locked flag is still not set after wakeup, it is a * If the locked flag is still not set after wakeup, it is a
@ -357,7 +357,7 @@ static void pv_wait_node(struct mcs_spinlock *node, struct mcs_spinlock *prev)
static void pv_kick_node(struct qspinlock *lock, struct mcs_spinlock *node) static void pv_kick_node(struct qspinlock *lock, struct mcs_spinlock *node)
{ {
struct pv_node *pn = (struct pv_node *)node; struct pv_node *pn = (struct pv_node *)node;
u8 old = vcpu_halted; u8 old = VCPU_HALTED;
/* /*
* If the vCPU is indeed halted, advance its state to match that of * If the vCPU is indeed halted, advance its state to match that of
* pv_wait_node(). If OTOH this fails, the vCPU was running and will * pv_wait_node(). If OTOH this fails, the vCPU was running and will
@ -374,7 +374,7 @@ static void pv_kick_node(struct qspinlock *lock, struct mcs_spinlock *node)
* subsequent writes. * subsequent writes.
*/ */
smp_mb__before_atomic(); smp_mb__before_atomic();
if (!try_cmpxchg_relaxed(&pn->state, &old, vcpu_hashed)) if (!try_cmpxchg_relaxed(&pn->state, &old, VCPU_HASHED))
return; return;
/* /*
@ -407,7 +407,7 @@ pv_wait_head_or_lock(struct qspinlock *lock, struct mcs_spinlock *node)
* If pv_kick_node() already advanced our state, we don't need to * If pv_kick_node() already advanced our state, we don't need to
* insert ourselves into the hash table anymore. * insert ourselves into the hash table anymore.
*/ */
if (READ_ONCE(pn->state) == vcpu_hashed) if (READ_ONCE(pn->state) == VCPU_HASHED)
lp = (struct qspinlock **)1; lp = (struct qspinlock **)1;
/* /*
@ -420,7 +420,7 @@ pv_wait_head_or_lock(struct qspinlock *lock, struct mcs_spinlock *node)
* Set correct vCPU state to be used by queue node wait-early * Set correct vCPU state to be used by queue node wait-early
* mechanism. * mechanism.
*/ */
WRITE_ONCE(pn->state, vcpu_running); WRITE_ONCE(pn->state, VCPU_RUNNING);
/* /*
* Set the pending bit in the active lock spinning loop to * Set the pending bit in the active lock spinning loop to
@ -460,7 +460,7 @@ pv_wait_head_or_lock(struct qspinlock *lock, struct mcs_spinlock *node)
goto gotlock; goto gotlock;
} }
} }
WRITE_ONCE(pn->state, vcpu_hashed); WRITE_ONCE(pn->state, VCPU_HASHED);
lockevent_inc(pv_wait_head); lockevent_inc(pv_wait_head);
lockevent_cond_inc(pv_wait_again, waitcnt); lockevent_cond_inc(pv_wait_again, waitcnt);
pv_wait(&lock->locked, _Q_SLOW_VAL); pv_wait(&lock->locked, _Q_SLOW_VAL);