On Sun, Apr 25, 2021 at 04:06:37PM -0400, Waiman Long wrote:That works for me too. It is equivalent anyway.
void queued_write_lock_slowpath(struct qrwlock *lock)Would not something like:
{
- int cnts;
+ int cnts = 0;
/* Put the writer into the wait queue */
arch_spin_lock(&lock->wait_lock);
/* Try to acquire the lock directly if no reader is present */
if (!atomic_read(&lock->cnts) &&
- (atomic_cmpxchg_acquire(&lock->cnts, 0, _QW_LOCKED) == 0))
+ atomic_try_cmpxchg_acquire(&lock->cnts, &cnts, _QW_LOCKED))
goto unlock;
if (!(cnts = atomic_read(&lock->cnts)) &&
atomic_try_cmpxchg_acquire(&lock->cnts, &cnts, _QW_LOCKED)
goto unlock;
Be clearer?
I was not sure as I didn't look at other archs that hadn't used qrwlock yet. Given what you said, I will remove the comment.
- /* Set the waiting flag to notify readers that a writer is pending */That might be a little overboard on the comment, but sure :-) I don't
- atomic_add(_QW_WAITING, &lock->cnts);
+ /*
+ * Set the waiting flag to notify readers that a writer is pending
+ *
+ * As only one writer who is the wait_lock owner can set the waiting
+ * flag which will be cleared later on when acquiring the write lock,
+ * we can easily replace atomic_or() by an atomic_add() if there is
+ * an architecture where an atomic_add() performs better than an
+ * atomic_or().
think there's any arch that doesn't have atomic_or(), like I wrote
elsewhere, the one that's often an issue is atomic_fetch_or().