Re: [PATCH memory-model scripts 01/31] tools/memory-model: Document locking corner cases

From: Paul E. McKenney
Date: Wed Mar 22 2023 - 15:14:28 EST


On Wed, Mar 22, 2023 at 09:59:38AM +0100, Andrea Parri wrote:
> > create mode 100644 Documentation/litmus-tests/locking/DCL-broken.litmus
> > create mode 100644 Documentation/litmus-tests/locking/DCL-fixed.litmus
> > create mode 100644 Documentation/litmus-tests/locking/RM-broken.litmus
> > create mode 100644 Documentation/litmus-tests/locking/RM-fixed.litmus
>
> Unfortunately none of them were liked by klitmus7/gcc, the diff below
> works for me but please double check.

Applied with attribution, thank you!

I was surprised by the need to change the "locations" clauses, but
applied that change anyway. Ah, I take it that klitmus prints that,
but doesn't know how to print out a spinlock_t?

Dropping "y" from the "filter" clause also gave me pause, but I eventually
convinced myself that it was OK. But it would be good for others to
also take a close look.

Thanx, Paul

> Andrea
>
>
> diff --git a/Documentation/litmus-tests/locking/DCL-broken.litmus b/Documentation/litmus-tests/locking/DCL-broken.litmus
> index cfaa25ff82b1e..bfb7ba4316d69 100644
> --- a/Documentation/litmus-tests/locking/DCL-broken.litmus
> +++ b/Documentation/litmus-tests/locking/DCL-broken.litmus
> @@ -10,10 +10,9 @@ C DCL-broken
> {
> int flag;
> int data;
> - int lck;
> }
>
> -P0(int *flag, int *data, int *lck)
> +P0(int *flag, int *data, spinlock_t *lck)
> {
> int r0;
> int r1;
> @@ -32,7 +31,7 @@ P0(int *flag, int *data, int *lck)
> r2 = READ_ONCE(*data);
> }
>
> -P1(int *flag, int *data, int *lck)
> +P1(int *flag, int *data, spinlock_t *lck)
> {
> int r0;
> int r1;
> @@ -51,5 +50,5 @@ P1(int *flag, int *data, int *lck)
> r2 = READ_ONCE(*data);
> }
>
> -locations [flag;data;lck;0:r0;0:r1;1:r0;1:r1]
> +locations [flag;data;0:r0;0:r1;1:r0;1:r1]
> exists (0:r2=0 \/ 1:r2=0)
> diff --git a/Documentation/litmus-tests/locking/DCL-fixed.litmus b/Documentation/litmus-tests/locking/DCL-fixed.litmus
> index 579d6c246f167..d1b60bcb0c8f3 100644
> --- a/Documentation/litmus-tests/locking/DCL-fixed.litmus
> +++ b/Documentation/litmus-tests/locking/DCL-fixed.litmus
> @@ -11,10 +11,9 @@ C DCL-fixed
> {
> int flag;
> int data;
> - int lck;
> }
>
> -P0(int *flag, int *data, int *lck)
> +P0(int *flag, int *data, spinlock_t *lck)
> {
> int r0;
> int r1;
> @@ -33,7 +32,7 @@ P0(int *flag, int *data, int *lck)
> r2 = READ_ONCE(*data);
> }
>
> -P1(int *flag, int *data, int *lck)
> +P1(int *flag, int *data, spinlock_t *lck)
> {
> int r0;
> int r1;
> @@ -52,5 +51,5 @@ P1(int *flag, int *data, int *lck)
> r2 = READ_ONCE(*data);
> }
>
> -locations [flag;data;lck;0:r0;0:r1;1:r0;1:r1]
> +locations [flag;data;0:r0;0:r1;1:r0;1:r1]
> exists (0:r2=0 \/ 1:r2=0)
> diff --git a/Documentation/litmus-tests/locking/RM-broken.litmus b/Documentation/litmus-tests/locking/RM-broken.litmus
> index c586ae4b547de..b7ef30cedfe51 100644
> --- a/Documentation/litmus-tests/locking/RM-broken.litmus
> +++ b/Documentation/litmus-tests/locking/RM-broken.litmus
> @@ -9,12 +9,11 @@ C RM-broken
> *)
>
> {
> - int lck;
> int x;
> - int y;
> + atomic_t y;
> }
>
> -P0(int *x, int *y, int *lck)
> +P0(int *x, atomic_t *y, spinlock_t *lck)
> {
> int r2;
>
> @@ -24,7 +23,7 @@ P0(int *x, int *y, int *lck)
> spin_unlock(lck);
> }
>
> -P1(int *x, int *y, int *lck)
> +P1(int *x, atomic_t *y, spinlock_t *lck)
> {
> int r0;
> int r1;
> @@ -37,6 +36,6 @@ P1(int *x, int *y, int *lck)
> spin_unlock(lck);
> }
>
> -locations [x;lck;0:r2;1:r0;1:r1;1:r2]
> -filter (y=2 /\ 1:r0=0 /\ 1:r1=1)
> +locations [x;0:r2;1:r0;1:r1;1:r2]
> +filter (1:r0=0 /\ 1:r1=1)
> exists (1:r2=1)
> diff --git a/Documentation/litmus-tests/locking/RM-fixed.litmus b/Documentation/litmus-tests/locking/RM-fixed.litmus
> index 672856736b42e..b628175596160 100644
> --- a/Documentation/litmus-tests/locking/RM-fixed.litmus
> +++ b/Documentation/litmus-tests/locking/RM-fixed.litmus
> @@ -9,12 +9,11 @@ C RM-fixed
> *)
>
> {
> - int lck;
> int x;
> - int y;
> + atomic_t y;
> }
>
> -P0(int *x, int *y, int *lck)
> +P0(int *x, atomic_t *y, spinlock_t *lck)
> {
> int r2;
>
> @@ -24,7 +23,7 @@ P0(int *x, int *y, int *lck)
> spin_unlock(lck);
> }
>
> -P1(int *x, int *y, int *lck)
> +P1(int *x, atomic_t *y, spinlock_t *lck)
> {
> int r0;
> int r1;
> @@ -37,6 +36,6 @@ P1(int *x, int *y, int *lck)
> spin_unlock(lck);
> }
>
> -locations [x;lck;0:r2;1:r0;1:r1;1:r2]
> -filter (y=2 /\ 1:r0=0 /\ 1:r1=1)
> +locations [x;0:r2;1:r0;1:r1;1:r2]
> +filter (1:r0=0 /\ 1:r1=1)
> exists (1:r2=1)