public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH] open_posix: Update pthread_rwlock_rdlock 2nd assertion
@ 2025-05-20 18:10 Ricardo B. Marlière via ltp
  2025-05-20 18:13 ` Ricardo B. Marlière via ltp
  2025-09-19 11:54 ` Cyril Hrubis
  0 siblings, 2 replies; 3+ messages in thread
From: Ricardo B. Marlière via ltp @ 2025-05-20 18:10 UTC (permalink / raw)
  To: Linux Test Project; +Cc: Ricardo B. Marlière

From: Ricardo B. Marlière <rbm@suse.com>

The pthread_rwlock_rdlock/2-*.c tests are broken because they rely on an
old version of the POSIX standard which says:

  If the Thread Execution Scheduling option is supported, and the threads
  involved in the lock are executing with the scheduling policies
  SCHED_FIFO or SCHED_RR, the calling thread shall not acquire the lock if
  a writer holds the lock or if writers of higher or equal priority are
  blocked on the lock; otherwise, the calling thread shall acquire the
  lock.

Whereas the new version says:

  If the Thread Execution Scheduling option is supported, and the threads
  that hold or are blocked on the lock are executing with the scheduling
  policies SCHED_FIFO or SCHED_RR, the calling thread shall not acquire the
  lock if a writer holds the lock or if the calling thread does not already
  hold a read lock and writers of higher or equal priority are blocked on
  the lock; otherwise, the calling thread shall acquire the lock.

This behaviour is not supported by default on GNU/Linux, so add a call to
Glibc pthread_rwlockattr_setkind_np() to set the correct lock kind as a
prerequisite to the 2-1.c and 2-2.c tests.

Link: https://austingroupbugs.net/view.php?id=1111
Link: https://sourceware.org/bugzilla/show_bug.cgi?id=13701
Signed-off-by: Ricardo B. Marlière <rbm@suse.com>
---
 .../interfaces/pthread_rwlock_rdlock/2-1.c          | 21 ++++++++++++++-------
 .../interfaces/pthread_rwlock_rdlock/2-2.c          | 21 ++++++++++++++-------
 .../interfaces/pthread_rwlock_rdlock/2-3.c          | 13 +++++++------
 .../interfaces/pthread_rwlock_rdlock/assertions.xml | 15 ++++++++-------
 4 files changed, 43 insertions(+), 27 deletions(-)

diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_rwlock_rdlock/2-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_rwlock_rdlock/2-1.c
index 288eb3e3566abf26100f999d02081b5ef02a6694..3b27a0bbbbdfaadf37fa94e129a937cdd9e986db 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_rwlock_rdlock/2-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_rwlock_rdlock/2-1.c
@@ -6,12 +6,13 @@
 
  * Test that pthread_rwlock_rdlock(pthread_rwlock_t *rwlock)
  *
- * 	If the Thread Execution Scheduling option is supported,
- *	and the threads involved in the lock are executing with the
- *	scheduling policies SCHED_FIFO or SCHED_RR, the calling thread shall not
- *	acquire the lock if a writer holds the lock or if writers of
- *	higher or equal priority are blocked on the lock;
- *	otherwise, the calling thread shall acquire the lock.
+ *	If the Thread Execution Scheduling option is supported,
+ *	and the threads that hold or are blocked on the lock are
+ *	executing with the scheduling policies SCHED_FIFO or SCHED_RR,
+ *	the calling thread shall not acquire the lock if a writer
+ *	holds the lock or if the calling thread does not already hold
+ *	a read lock and writers of higher or equal priority are blocked
+ *	on the lock; otherwise, the calling thread shall acquire the lock.
  *
  * In this case, we test "higher priority writer block"
  *
@@ -143,13 +144,19 @@ int main(void)
 	int cnt = 0;
 	pthread_t rd_thread, wr_thread;
 	int priority;
+	pthread_rwlockattr_t attr;
+
+	pthread_rwlockattr_init(&attr);
+#ifdef __GNUC__
+	pthread_rwlockattr_setkind_np(&attr, PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP);
+#endif
 
 	/* main thread needs to have the highest priority */
 	priority = sched_get_priority_min(TRD_POLICY) + 2;
 	set_priority(pthread_self(), TRD_POLICY, priority);
 	printf("main: has priority: %d\n", priority);
 
-	if (pthread_rwlock_init(&rwlock, NULL) != 0) {
+	if (pthread_rwlock_init(&rwlock, &attr) != 0) {
 		printf("main: Error at pthread_rwlock_init()\n");
 		return PTS_UNRESOLVED;
 	}
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_rwlock_rdlock/2-2.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_rwlock_rdlock/2-2.c
index 3593e4c7966bef183bc5979e296beff512196d47..4799b1e885caab509fd31173c34ae89beace68e6 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_rwlock_rdlock/2-2.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_rwlock_rdlock/2-2.c
@@ -6,12 +6,13 @@
 
  * Test that pthread_rwlock_rdlock(pthread_rwlock_t *rwlock)
  *
- * 	If the Thread Execution Scheduling option is supported,
- *	and the threads involved in the lock are executing with the
- *	scheduling policies SCHED_FIFO or SCHED_RR, the calling thread shall not
- *	acquire the lock if a writer holds the lock or if writers of
- *	higher or equal priority are blocked on the lock;
- *	otherwise, the calling thread shall acquire the lock.
+ *	If the Thread Execution Scheduling option is supported,
+ *	and the threads that hold or are blocked on the lock are
+ *	executing with the scheduling policies SCHED_FIFO or SCHED_RR,
+ *	the calling thread shall not acquire the lock if a writer
+ *	holds the lock or if the calling thread does not already hold
+ *	a read lock and writers of higher or equal priority are blocked
+ *	on the lock; otherwise, the calling thread shall acquire the lock.
  *
  * In this case, we test "equal priority writer block"
  *
@@ -143,12 +144,18 @@ int main(void)
 	int cnt = 0;
 	pthread_t rd_thread, wr_thread;
 	int priority;
+	pthread_rwlockattr_t attr;
+
+	pthread_rwlockattr_init(&attr);
+#ifdef __GNUC__
+	pthread_rwlockattr_setkind_np(&attr, PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP);
+#endif
 
 	/* main thread needs to have the highest priority */
 	priority = sched_get_priority_min(TRD_POLICY) + 2;
 	set_priority(pthread_self(), TRD_POLICY, priority);
 
-	if (pthread_rwlock_init(&rwlock, NULL) != 0) {
+	if (pthread_rwlock_init(&rwlock, &attr) != 0) {
 		printf("main: Error at pthread_rwlock_init()\n");
 		return PTS_UNRESOLVED;
 	}
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_rwlock_rdlock/2-3.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_rwlock_rdlock/2-3.c
index 40170dbb2d025ffda3693644c7d9aa4246f16bcf..aa1511bae3703efc92bc8569d7f4dc81f6219aa3 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_rwlock_rdlock/2-3.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_rwlock_rdlock/2-3.c
@@ -6,12 +6,13 @@
 
  * Test that pthread_rwlock_rdlock(pthread_rwlock_t *rwlock)
  *
- * 	If the Thread Execution Scheduling option is supported,
- *	and the threads involved in the lock are executing with the
- *	scheduling policies SCHED_FIFO or SCHED_RR, the calling thread shall not
- *	acquire the lock if a writer holds the lock or if writers of
- *	higher or equal priority are blocked on the lock;
- *	otherwise, the calling thread shall acquire the lock.
+ *	If the Thread Execution Scheduling option is supported,
+ *	and the threads that hold or are blocked on the lock are
+ *	executing with the scheduling policies SCHED_FIFO or SCHED_RR,
+ *	the calling thread shall not acquire the lock if a writer
+ *	holds the lock or if the calling thread does not already hold
+ *	a read lock and writers of higher or equal priority are blocked
+ *	on the lock; otherwise, the calling thread shall acquire the lock.
  *
  * In this case, reader has higher priority than the writer
  *
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_rwlock_rdlock/assertions.xml b/testcases/open_posix_testsuite/conformance/interfaces/pthread_rwlock_rdlock/assertions.xml
index 07263b3dedde488196037e7140fcaa367cc49f5c..deb318cb786a5299c20b846eabfbad1111cb24ed 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_rwlock_rdlock/assertions.xml
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_rwlock_rdlock/assertions.xml
@@ -6,13 +6,14 @@
 	no writers blocked on the lock.
   </assertion>
 
-  <assertion id="2" tag="ref:XSH6:34768:34771">
- 	If the Thread Execution Scheduling option is supported,
-	and the threads involved in the lock are executing with the
-	scheduling policies SCHED_FIFO or SCHED_RR, the calling thread shall not
-	acquire the lock if a writer holds the lock or if writers of
-	higher or equal priority are blocked on the lock;
-	otherwise, the calling thread shall acquire the lock.
+  <assertion id="2" tag="ref:XSH8:{System Interfaces:pthread_rwlock_rdlock:DESCRIPTION}">
+	If the Thread Execution Scheduling option is supported,
+	and the threads that hold or are blocked on the lock are
+	executing with the scheduling policies SCHED_FIFO or SCHED_RR,
+	the calling thread shall not acquire the lock if a writer
+	holds the lock or if the calling thread does not already hold
+	a read lock and writers of higher or equal priority are blocked
+	on the lock; otherwise, the calling thread shall acquire the lock.
   </assertion>
 
   <assertion id="3" tag="ref:XSH6:34772:34775">

---
base-commit: c9e5b1e50889adec8c2bb38ea5fd69cd48edb8b7
change-id: 20250520-fixes-pthread_rwlock_rdlock-b2b8e427160a

Best regards,
-- 
Ricardo B. Marlière <rbm@suse.com>


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [LTP] [PATCH] open_posix: Update pthread_rwlock_rdlock 2nd assertion
  2025-05-20 18:10 [LTP] [PATCH] open_posix: Update pthread_rwlock_rdlock 2nd assertion Ricardo B. Marlière via ltp
@ 2025-05-20 18:13 ` Ricardo B. Marlière via ltp
  2025-09-19 11:54 ` Cyril Hrubis
  1 sibling, 0 replies; 3+ messages in thread
From: Ricardo B. Marlière via ltp @ 2025-05-20 18:13 UTC (permalink / raw)
  To: Cyril Hrubis, Linux Test Project

On Tue May 20, 2025 at 3:10 PM -03, Ricardo B. Marlière wrote:
> From: Ricardo B. Marlière <rbm@suse.com>
>
> The pthread_rwlock_rdlock/2-*.c tests are broken because they rely on an
> old version of the POSIX standard which says:
>
>   If the Thread Execution Scheduling option is supported, and the threads
>   involved in the lock are executing with the scheduling policies
>   SCHED_FIFO or SCHED_RR, the calling thread shall not acquire the lock if
>   a writer holds the lock or if writers of higher or equal priority are
>   blocked on the lock; otherwise, the calling thread shall acquire the
>   lock.
>
> Whereas the new version says:
>
>   If the Thread Execution Scheduling option is supported, and the threads
>   that hold or are blocked on the lock are executing with the scheduling
>   policies SCHED_FIFO or SCHED_RR, the calling thread shall not acquire the
>   lock if a writer holds the lock or if the calling thread does not already
>   hold a read lock and writers of higher or equal priority are blocked on
>   the lock; otherwise, the calling thread shall acquire the lock.
>
> This behaviour is not supported by default on GNU/Linux, so add a call to
> Glibc pthread_rwlockattr_setkind_np() to set the correct lock kind as a
> prerequisite to the 2-1.c and 2-2.c tests.
>
> Link: https://austingroupbugs.net/view.php?id=1111
> Link: https://sourceware.org/bugzilla/show_bug.cgi?id=13701
> Signed-off-by: Ricardo B. Marlière <rbm@suse.com>
> ---
>  .../interfaces/pthread_rwlock_rdlock/2-1.c          | 21 ++++++++++++++-------
>  .../interfaces/pthread_rwlock_rdlock/2-2.c          | 21 ++++++++++++++-------
>  .../interfaces/pthread_rwlock_rdlock/2-3.c          | 13 +++++++------
>  .../interfaces/pthread_rwlock_rdlock/assertions.xml | 15 ++++++++-------
>  4 files changed, 43 insertions(+), 27 deletions(-)
>

Hi Cyril,

I think this one might be worth including in the new release!

Thanks,
-	Ricardo.



-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [LTP] [PATCH] open_posix: Update pthread_rwlock_rdlock 2nd assertion
  2025-05-20 18:10 [LTP] [PATCH] open_posix: Update pthread_rwlock_rdlock 2nd assertion Ricardo B. Marlière via ltp
  2025-05-20 18:13 ` Ricardo B. Marlière via ltp
@ 2025-09-19 11:54 ` Cyril Hrubis
  1 sibling, 0 replies; 3+ messages in thread
From: Cyril Hrubis @ 2025-09-19 11:54 UTC (permalink / raw)
  To: Ricardo B. Marlière; +Cc: Linux Test Project

Hi!
> The pthread_rwlock_rdlock/2-*.c tests are broken because they rely on an
> old version of the POSIX standard which says:
> 
>   If the Thread Execution Scheduling option is supported, and the threads
>   involved in the lock are executing with the scheduling policies
>   SCHED_FIFO or SCHED_RR, the calling thread shall not acquire the lock if
>   a writer holds the lock or if writers of higher or equal priority are
>   blocked on the lock; otherwise, the calling thread shall acquire the
>   lock.
> 
> Whereas the new version says:
> 
>   If the Thread Execution Scheduling option is supported, and the threads
>   that hold or are blocked on the lock are executing with the scheduling
>   policies SCHED_FIFO or SCHED_RR, the calling thread shall not acquire the
>   lock if a writer holds the lock or if the calling thread does not already
>   hold a read lock and writers of higher or equal priority are blocked on
>   the lock; otherwise, the calling thread shall acquire the lock.

I wouldn't say that these tests are broken because of the change in
POSIX. The change in POSIX only fixed the specs in the case of recursive
locking that is situation where we have a thread that has rdlock and
attempts to do rwlock while there is higher priority thread that
attempts rwlock. In that situation the previous definition would caused
deadlock.

But as far as I can see these tests do not attempt recursive locks, so
that part of POSIX wasn't really problem.

> This behaviour is not supported by default on GNU/Linux, so add a call to
> Glibc pthread_rwlockattr_setkind_np() to set the correct lock kind as a
> prerequisite to the 2-1.c and 2-2.c tests.

This is where the problem is, glibc decided to deviate from the POSIX
since they think that the standard is not well designed. That is a glibc
design choice. I'm not againts working around that with requesting POSIX
confirming variant on glibc, but the patch should clearly say this
instead.

Also we should split this into two patches, one that adjusts the specs
and one that adds glibc workaround.

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-09-19 11:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-20 18:10 [LTP] [PATCH] open_posix: Update pthread_rwlock_rdlock 2nd assertion Ricardo B. Marlière via ltp
2025-05-20 18:13 ` Ricardo B. Marlière via ltp
2025-09-19 11:54 ` Cyril Hrubis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox