Re: [PATCH 1/1] kernel/locking: Add mutual exclusion self-test

From: Haakon Bugge

Date: Mon Sep 14 2026 - 13:48:52 EST




> On 14 Sep 2026, at 14:32, Haakon Bugge <haakon.bugge@xxxxxxxxxx> wrote:
>
> On 14 Sep 2026, at 11:35, David Laight <david.laight.linux@xxxxxxxxx> wrote:

[snip]

>> If you use change the MX_ATOMIC_ADD to use the atomic_long functions
>> (I've forgotten the exact name) then all the counter are the same type
>> and can be removed from the union.
>> The default 'just use +=' code can then be moved to the bottom of mx_add().
>
> That is a good idea, but we then misses test coverage for atomic_t. But,
> what about:

[snip]

I ended up with:

struct mx_elem {
/* This union contains locks and lock-free data types */
union {
spinlock_t spinlock;
rwlock_t rwlock;
struct mutex mutex;
atomic_t atomic_lock;
atomic_t atomic_counter;
atomic64_t atomic64_counter;
long cmpxchg_counter;
unsigned long bits;
struct ww_mutex ww_mutex;
struct optimistic_spin_queue osq_lock;
};
/* A counter protected by one of the locks above */
long counter;
};

This became quite simpler. I'll test somewhat more, and send out
a v2 tomorrow.


Thxs, Håkon