public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/aoliva/heads/testme)] testsuite: pthread: call sched_yield for non-preemptive targets
@ 2022-06-27 9:33 Alexandre Oliva
0 siblings, 0 replies; 10+ messages in thread
From: Alexandre Oliva @ 2022-06-27 9:33 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:83aa1c59ad064491fa46ee99aa6ece612ea57539
commit 83aa1c59ad064491fa46ee99aa6ece612ea57539
Author: Alexandre Oliva <oliva@adacore.com>
Date: Mon Jun 27 05:30:52 2022 -0300
testsuite: pthread: call sched_yield for non-preemptive targets
Systems without preemptive multi-threading require sched_yield calls
to be placed at points in which a context switch might be needed to
enable the test to complete.
for gcc/testsuite/ChangeLog
* gcc.dg/atomic/c11-atomic-exec-4.c: Call sched_yield.
* gcc.dg/atomic/c11-atomic-exec-5.c: Likewise.
* gcc.dg/atomic/pr80640-2.c: Likewise.
* gcc.dg/atomic/pr80640.c: Likewise.
* gcc.dg/atomic/pr81316.c: Likewise.
* gcc.dg/di-sync-multithread.c: Likewise.
Diff:
---
gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-4.c | 12 +++++++++---
gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-5.c | 6 +++++-
gcc/testsuite/gcc.dg/atomic/pr80640-2.c | 6 ++++--
gcc/testsuite/gcc.dg/atomic/pr80640.c | 6 ++++--
gcc/testsuite/gcc.dg/atomic/pr81316.c | 9 +++++++--
gcc/testsuite/gcc.dg/di-sync-multithread.c | 8 ++++++++
6 files changed, 37 insertions(+), 10 deletions(-)
diff --git a/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-4.c b/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-4.c
index d6bb629f59f..669e7c058c3 100644
--- a/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-4.c
+++ b/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-4.c
@@ -32,7 +32,10 @@ test_thread_##NAME (void *arg) \
{ \
thread_ready = true; \
for (int i = 0; i < ITER_COUNT; i++) \
- PRE var_##NAME POST; \
+ { \
+ sched_yield (); \
+ PRE var_##NAME POST; \
+ } \
return NULL; \
} \
\
@@ -49,9 +52,12 @@ test_main_##NAME (void) \
return 1; \
} \
while (!thread_ready) \
- ; \
+ sched_yield (); \
for (int i = 0; i < ITER_COUNT; i++) \
- PRE var_##NAME POST; \
+ { \
+ PRE var_##NAME POST; \
+ sched_yield (); \
+ } \
pthread_join (thread_id, NULL); \
if (var_##NAME != (FINAL)) \
{ \
diff --git a/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-5.c b/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-5.c
index 692c64ad207..f8bfa63b4cc 100644
--- a/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-5.c
+++ b/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-5.c
@@ -53,8 +53,11 @@ test_thread_##NAME (void *arg) \
thread_ready = true; \
while (!thread_stop) \
{ \
+ sched_yield (); \
var_##NAME = (INIT1); \
+ sched_yield (); \
var_##NAME = (INIT2); \
+ sched_yield (); \
} \
return NULL; \
} \
@@ -75,13 +78,14 @@ test_main_##NAME (void) \
} \
int num_1_pass = 0, num_1_fail = 0, num_2_pass = 0, num_2_fail = 0; \
while (!thread_ready) \
- ; \
+ sched_yield (); \
for (int i = 0; i < ITER_COUNT; i++) \
{ \
feclearexcept (FE_ALL_EXCEPT); \
feraiseexcept (BEXC); \
LHSTYPE r = (PRE var_##NAME POST); \
int rexc = fetestexcept (TEST_ALL_EXCEPT); \
+ sched_yield (); \
if (VALTEST1 (r)) \
{ \
if (rexc == ((BEXC) | (EXC1))) \
diff --git a/gcc/testsuite/gcc.dg/atomic/pr80640-2.c b/gcc/testsuite/gcc.dg/atomic/pr80640-2.c
index a735054090d..e33dcc386ab 100644
--- a/gcc/testsuite/gcc.dg/atomic/pr80640-2.c
+++ b/gcc/testsuite/gcc.dg/atomic/pr80640-2.c
@@ -12,7 +12,8 @@ static void *f(void *va)
void **p = va;
if (*p) return *p;
sem1 = 1;
- while (!__atomic_load_n(&sem2, __ATOMIC_ACQUIRE));
+ while (!__atomic_load_n(&sem2, __ATOMIC_ACQUIRE))
+ sched_yield ();
// GCC used to RTL-CSE this and the first load, causing 0 to be returned
return *p;
}
@@ -23,7 +24,8 @@ int main()
pthread_t thr;
if (pthread_create(&thr, 0, f, &p))
return 2;
- while (!sem1);
+ while (!sem1)
+ sched_yield ();
__atomic_thread_fence(__ATOMIC_ACQUIRE);
p = &p;
__atomic_store_n(&sem2, 1, __ATOMIC_RELEASE);
diff --git a/gcc/testsuite/gcc.dg/atomic/pr80640.c b/gcc/testsuite/gcc.dg/atomic/pr80640.c
index fd17978a482..2577e0ddf4f 100644
--- a/gcc/testsuite/gcc.dg/atomic/pr80640.c
+++ b/gcc/testsuite/gcc.dg/atomic/pr80640.c
@@ -12,7 +12,8 @@ static void *f(void *va)
void **p = va;
if (*p) return *p;
sem1 = 1;
- while (!sem2);
+ while (!sem2)
+ sched_yield ();
__atomic_thread_fence(__ATOMIC_ACQUIRE);
// GCC used to RTL-CSE this and the first load, causing 0 to be returned
return *p;
@@ -24,7 +25,8 @@ int main()
pthread_t thr;
if (pthread_create(&thr, 0, f, &p))
return 2;
- while (!sem1);
+ while (!sem1)
+ sched_yield ();
__atomic_thread_fence(__ATOMIC_ACQUIRE);
p = &p;
__atomic_thread_fence(__ATOMIC_RELEASE);
diff --git a/gcc/testsuite/gcc.dg/atomic/pr81316.c b/gcc/testsuite/gcc.dg/atomic/pr81316.c
index ef10095718e..dc6569a7253 100644
--- a/gcc/testsuite/gcc.dg/atomic/pr81316.c
+++ b/gcc/testsuite/gcc.dg/atomic/pr81316.c
@@ -10,7 +10,8 @@ static _Atomic int sem1;
static void *f(void *va)
{
void **p = va;
- while (!__atomic_load_n(&sem1, __ATOMIC_ACQUIRE));
+ while (!__atomic_load_n(&sem1, __ATOMIC_ACQUIRE))
+ sched_yield ();
exit(!*p);
}
@@ -24,6 +25,10 @@ int main(int argc)
p = &p;
__atomic_store_n(&sem1, 1, __ATOMIC_RELEASE);
int r = -1;
- while (r < 0) asm("":"+r"(r));
+ while (r < 0)
+ {
+ sched_yield ();
+ asm("":"+r"(r));
+ }
return r;
}
diff --git a/gcc/testsuite/gcc.dg/di-sync-multithread.c b/gcc/testsuite/gcc.dg/di-sync-multithread.c
index 493f1e27201..1a97df7a9e6 100644
--- a/gcc/testsuite/gcc.dg/di-sync-multithread.c
+++ b/gcc/testsuite/gcc.dg/di-sync-multithread.c
@@ -70,6 +70,8 @@ worker (void* data)
case this to carry across the 32bit boundary. */
for (tmp2 = 0; tmp2 < 64; tmp2++)
{
+ sched_yield ();
+
/* Add 2 using the two different adds. */
tmp1 = __sync_add_and_fetch (&workspace, add1bit);
tmp3 = __sync_fetch_and_add (&workspace, add1bit);
@@ -103,6 +105,8 @@ worker (void* data)
for (tmp2 = 0; tmp2 < 64; tmp2++)
{
+ sched_yield ();
+
/* Subtract 2 using the two different subs. */
tmp1=__sync_sub_and_fetch (&workspace, add1bit);
tmp3=__sync_fetch_and_sub (&workspace, add1bit);
@@ -178,6 +182,8 @@ main ()
t, err);
};
+ sched_yield ();
+
#ifdef _WIN32
Sleep (5000);
#else
@@ -187,6 +193,8 @@ main ()
/* Stop please. */
__sync_lock_test_and_set (&doquit, 1ll);
+ sched_yield ();
+
for (t = 0; t < 3; t++)
{
err=pthread_join (threads[t], NULL);
^ permalink raw reply [flat|nested] 10+ messages in thread
* [gcc(refs/users/aoliva/heads/testme)] testsuite: pthread: call sched_yield for non-preemptive targets
@ 2022-06-27 10:50 Alexandre Oliva
0 siblings, 0 replies; 10+ messages in thread
From: Alexandre Oliva @ 2022-06-27 10:50 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:56882369a015ea7596880e5c3ab07a9fa8915391
commit 56882369a015ea7596880e5c3ab07a9fa8915391
Author: Alexandre Oliva <oliva@adacore.com>
Date: Mon Jun 27 05:30:52 2022 -0300
testsuite: pthread: call sched_yield for non-preemptive targets
Systems without preemptive multi-threading require sched_yield calls
to be placed at points in which a context switch might be needed to
enable the test to complete.
for gcc/testsuite/ChangeLog
* gcc.dg/atomic/c11-atomic-exec-4.c: Call sched_yield.
* gcc.dg/atomic/c11-atomic-exec-5.c: Likewise.
* gcc.dg/atomic/pr80640-2.c: Likewise.
* gcc.dg/atomic/pr80640.c: Likewise.
* gcc.dg/atomic/pr81316.c: Likewise.
* gcc.dg/di-sync-multithread.c: Likewise.
Diff:
---
gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-4.c | 12 +++++++++---
gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-5.c | 6 +++++-
gcc/testsuite/gcc.dg/atomic/pr80640-2.c | 6 ++++--
gcc/testsuite/gcc.dg/atomic/pr80640.c | 6 ++++--
gcc/testsuite/gcc.dg/atomic/pr81316.c | 9 +++++++--
gcc/testsuite/gcc.dg/di-sync-multithread.c | 8 ++++++++
6 files changed, 37 insertions(+), 10 deletions(-)
diff --git a/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-4.c b/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-4.c
index d6bb629f59f..669e7c058c3 100644
--- a/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-4.c
+++ b/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-4.c
@@ -32,7 +32,10 @@ test_thread_##NAME (void *arg) \
{ \
thread_ready = true; \
for (int i = 0; i < ITER_COUNT; i++) \
- PRE var_##NAME POST; \
+ { \
+ sched_yield (); \
+ PRE var_##NAME POST; \
+ } \
return NULL; \
} \
\
@@ -49,9 +52,12 @@ test_main_##NAME (void) \
return 1; \
} \
while (!thread_ready) \
- ; \
+ sched_yield (); \
for (int i = 0; i < ITER_COUNT; i++) \
- PRE var_##NAME POST; \
+ { \
+ PRE var_##NAME POST; \
+ sched_yield (); \
+ } \
pthread_join (thread_id, NULL); \
if (var_##NAME != (FINAL)) \
{ \
diff --git a/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-5.c b/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-5.c
index 692c64ad207..f8bfa63b4cc 100644
--- a/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-5.c
+++ b/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-5.c
@@ -53,8 +53,11 @@ test_thread_##NAME (void *arg) \
thread_ready = true; \
while (!thread_stop) \
{ \
+ sched_yield (); \
var_##NAME = (INIT1); \
+ sched_yield (); \
var_##NAME = (INIT2); \
+ sched_yield (); \
} \
return NULL; \
} \
@@ -75,13 +78,14 @@ test_main_##NAME (void) \
} \
int num_1_pass = 0, num_1_fail = 0, num_2_pass = 0, num_2_fail = 0; \
while (!thread_ready) \
- ; \
+ sched_yield (); \
for (int i = 0; i < ITER_COUNT; i++) \
{ \
feclearexcept (FE_ALL_EXCEPT); \
feraiseexcept (BEXC); \
LHSTYPE r = (PRE var_##NAME POST); \
int rexc = fetestexcept (TEST_ALL_EXCEPT); \
+ sched_yield (); \
if (VALTEST1 (r)) \
{ \
if (rexc == ((BEXC) | (EXC1))) \
diff --git a/gcc/testsuite/gcc.dg/atomic/pr80640-2.c b/gcc/testsuite/gcc.dg/atomic/pr80640-2.c
index a735054090d..e33dcc386ab 100644
--- a/gcc/testsuite/gcc.dg/atomic/pr80640-2.c
+++ b/gcc/testsuite/gcc.dg/atomic/pr80640-2.c
@@ -12,7 +12,8 @@ static void *f(void *va)
void **p = va;
if (*p) return *p;
sem1 = 1;
- while (!__atomic_load_n(&sem2, __ATOMIC_ACQUIRE));
+ while (!__atomic_load_n(&sem2, __ATOMIC_ACQUIRE))
+ sched_yield ();
// GCC used to RTL-CSE this and the first load, causing 0 to be returned
return *p;
}
@@ -23,7 +24,8 @@ int main()
pthread_t thr;
if (pthread_create(&thr, 0, f, &p))
return 2;
- while (!sem1);
+ while (!sem1)
+ sched_yield ();
__atomic_thread_fence(__ATOMIC_ACQUIRE);
p = &p;
__atomic_store_n(&sem2, 1, __ATOMIC_RELEASE);
diff --git a/gcc/testsuite/gcc.dg/atomic/pr80640.c b/gcc/testsuite/gcc.dg/atomic/pr80640.c
index fd17978a482..2577e0ddf4f 100644
--- a/gcc/testsuite/gcc.dg/atomic/pr80640.c
+++ b/gcc/testsuite/gcc.dg/atomic/pr80640.c
@@ -12,7 +12,8 @@ static void *f(void *va)
void **p = va;
if (*p) return *p;
sem1 = 1;
- while (!sem2);
+ while (!sem2)
+ sched_yield ();
__atomic_thread_fence(__ATOMIC_ACQUIRE);
// GCC used to RTL-CSE this and the first load, causing 0 to be returned
return *p;
@@ -24,7 +25,8 @@ int main()
pthread_t thr;
if (pthread_create(&thr, 0, f, &p))
return 2;
- while (!sem1);
+ while (!sem1)
+ sched_yield ();
__atomic_thread_fence(__ATOMIC_ACQUIRE);
p = &p;
__atomic_thread_fence(__ATOMIC_RELEASE);
diff --git a/gcc/testsuite/gcc.dg/atomic/pr81316.c b/gcc/testsuite/gcc.dg/atomic/pr81316.c
index ef10095718e..dc6569a7253 100644
--- a/gcc/testsuite/gcc.dg/atomic/pr81316.c
+++ b/gcc/testsuite/gcc.dg/atomic/pr81316.c
@@ -10,7 +10,8 @@ static _Atomic int sem1;
static void *f(void *va)
{
void **p = va;
- while (!__atomic_load_n(&sem1, __ATOMIC_ACQUIRE));
+ while (!__atomic_load_n(&sem1, __ATOMIC_ACQUIRE))
+ sched_yield ();
exit(!*p);
}
@@ -24,6 +25,10 @@ int main(int argc)
p = &p;
__atomic_store_n(&sem1, 1, __ATOMIC_RELEASE);
int r = -1;
- while (r < 0) asm("":"+r"(r));
+ while (r < 0)
+ {
+ sched_yield ();
+ asm("":"+r"(r));
+ }
return r;
}
diff --git a/gcc/testsuite/gcc.dg/di-sync-multithread.c b/gcc/testsuite/gcc.dg/di-sync-multithread.c
index 493f1e27201..1a97df7a9e6 100644
--- a/gcc/testsuite/gcc.dg/di-sync-multithread.c
+++ b/gcc/testsuite/gcc.dg/di-sync-multithread.c
@@ -70,6 +70,8 @@ worker (void* data)
case this to carry across the 32bit boundary. */
for (tmp2 = 0; tmp2 < 64; tmp2++)
{
+ sched_yield ();
+
/* Add 2 using the two different adds. */
tmp1 = __sync_add_and_fetch (&workspace, add1bit);
tmp3 = __sync_fetch_and_add (&workspace, add1bit);
@@ -103,6 +105,8 @@ worker (void* data)
for (tmp2 = 0; tmp2 < 64; tmp2++)
{
+ sched_yield ();
+
/* Subtract 2 using the two different subs. */
tmp1=__sync_sub_and_fetch (&workspace, add1bit);
tmp3=__sync_fetch_and_sub (&workspace, add1bit);
@@ -178,6 +182,8 @@ main ()
t, err);
};
+ sched_yield ();
+
#ifdef _WIN32
Sleep (5000);
#else
@@ -187,6 +193,8 @@ main ()
/* Stop please. */
__sync_lock_test_and_set (&doquit, 1ll);
+ sched_yield ();
+
for (t = 0; t < 3; t++)
{
err=pthread_join (threads[t], NULL);
^ permalink raw reply [flat|nested] 10+ messages in thread
* [gcc(refs/users/aoliva/heads/testme)] testsuite: pthread: call sched_yield for non-preemptive targets
@ 2022-06-23 12:44 Alexandre Oliva
0 siblings, 0 replies; 10+ messages in thread
From: Alexandre Oliva @ 2022-06-23 12:44 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:4f266f831ae76c05d0379126cb34690e19200623
commit 4f266f831ae76c05d0379126cb34690e19200623
Author: Alexandre Oliva <oliva@adacore.com>
Date: Mon Jun 20 19:43:47 2022 -0300
testsuite: pthread: call sched_yield for non-preemptive targets
Systems without preemptive multi-threading require sched_yield calls
to be placed at points in which a context switch might be needed to
enable the test to complete.
for gcc/testsuite/ChangeLog
* gcc.dg/atomic/c11-atomic-exec-4.c: Call sched_yield.
* gcc.dg/atomic/c11-atomic-exec-5.c: Likewise.
* gcc.dg/atomic/pr80640-2.c: Likewise.
* gcc.dg/atomic/pr80640.c: Likewise.
* gcc.dg/atomic/pr81316.c: Likewise.
* gcc.dg/di-sync-multithread.c: Likewise.
Diff:
---
gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-4.c | 12 +++++++++---
gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-5.c | 6 +++++-
gcc/testsuite/gcc.dg/atomic/pr80640-2.c | 6 ++++--
gcc/testsuite/gcc.dg/atomic/pr80640.c | 6 ++++--
gcc/testsuite/gcc.dg/atomic/pr81316.c | 9 +++++++--
gcc/testsuite/gcc.dg/di-sync-multithread.c | 8 ++++++++
6 files changed, 37 insertions(+), 10 deletions(-)
diff --git a/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-4.c b/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-4.c
index d6bb629f59f..669e7c058c3 100644
--- a/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-4.c
+++ b/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-4.c
@@ -32,7 +32,10 @@ test_thread_##NAME (void *arg) \
{ \
thread_ready = true; \
for (int i = 0; i < ITER_COUNT; i++) \
- PRE var_##NAME POST; \
+ { \
+ sched_yield (); \
+ PRE var_##NAME POST; \
+ } \
return NULL; \
} \
\
@@ -49,9 +52,12 @@ test_main_##NAME (void) \
return 1; \
} \
while (!thread_ready) \
- ; \
+ sched_yield (); \
for (int i = 0; i < ITER_COUNT; i++) \
- PRE var_##NAME POST; \
+ { \
+ PRE var_##NAME POST; \
+ sched_yield (); \
+ } \
pthread_join (thread_id, NULL); \
if (var_##NAME != (FINAL)) \
{ \
diff --git a/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-5.c b/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-5.c
index 692c64ad207..f8bfa63b4cc 100644
--- a/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-5.c
+++ b/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-5.c
@@ -53,8 +53,11 @@ test_thread_##NAME (void *arg) \
thread_ready = true; \
while (!thread_stop) \
{ \
+ sched_yield (); \
var_##NAME = (INIT1); \
+ sched_yield (); \
var_##NAME = (INIT2); \
+ sched_yield (); \
} \
return NULL; \
} \
@@ -75,13 +78,14 @@ test_main_##NAME (void) \
} \
int num_1_pass = 0, num_1_fail = 0, num_2_pass = 0, num_2_fail = 0; \
while (!thread_ready) \
- ; \
+ sched_yield (); \
for (int i = 0; i < ITER_COUNT; i++) \
{ \
feclearexcept (FE_ALL_EXCEPT); \
feraiseexcept (BEXC); \
LHSTYPE r = (PRE var_##NAME POST); \
int rexc = fetestexcept (TEST_ALL_EXCEPT); \
+ sched_yield (); \
if (VALTEST1 (r)) \
{ \
if (rexc == ((BEXC) | (EXC1))) \
diff --git a/gcc/testsuite/gcc.dg/atomic/pr80640-2.c b/gcc/testsuite/gcc.dg/atomic/pr80640-2.c
index a735054090d..e33dcc386ab 100644
--- a/gcc/testsuite/gcc.dg/atomic/pr80640-2.c
+++ b/gcc/testsuite/gcc.dg/atomic/pr80640-2.c
@@ -12,7 +12,8 @@ static void *f(void *va)
void **p = va;
if (*p) return *p;
sem1 = 1;
- while (!__atomic_load_n(&sem2, __ATOMIC_ACQUIRE));
+ while (!__atomic_load_n(&sem2, __ATOMIC_ACQUIRE))
+ sched_yield ();
// GCC used to RTL-CSE this and the first load, causing 0 to be returned
return *p;
}
@@ -23,7 +24,8 @@ int main()
pthread_t thr;
if (pthread_create(&thr, 0, f, &p))
return 2;
- while (!sem1);
+ while (!sem1)
+ sched_yield ();
__atomic_thread_fence(__ATOMIC_ACQUIRE);
p = &p;
__atomic_store_n(&sem2, 1, __ATOMIC_RELEASE);
diff --git a/gcc/testsuite/gcc.dg/atomic/pr80640.c b/gcc/testsuite/gcc.dg/atomic/pr80640.c
index fd17978a482..2577e0ddf4f 100644
--- a/gcc/testsuite/gcc.dg/atomic/pr80640.c
+++ b/gcc/testsuite/gcc.dg/atomic/pr80640.c
@@ -12,7 +12,8 @@ static void *f(void *va)
void **p = va;
if (*p) return *p;
sem1 = 1;
- while (!sem2);
+ while (!sem2)
+ sched_yield ();
__atomic_thread_fence(__ATOMIC_ACQUIRE);
// GCC used to RTL-CSE this and the first load, causing 0 to be returned
return *p;
@@ -24,7 +25,8 @@ int main()
pthread_t thr;
if (pthread_create(&thr, 0, f, &p))
return 2;
- while (!sem1);
+ while (!sem1)
+ sched_yield ();
__atomic_thread_fence(__ATOMIC_ACQUIRE);
p = &p;
__atomic_thread_fence(__ATOMIC_RELEASE);
diff --git a/gcc/testsuite/gcc.dg/atomic/pr81316.c b/gcc/testsuite/gcc.dg/atomic/pr81316.c
index ef10095718e..dc6569a7253 100644
--- a/gcc/testsuite/gcc.dg/atomic/pr81316.c
+++ b/gcc/testsuite/gcc.dg/atomic/pr81316.c
@@ -10,7 +10,8 @@ static _Atomic int sem1;
static void *f(void *va)
{
void **p = va;
- while (!__atomic_load_n(&sem1, __ATOMIC_ACQUIRE));
+ while (!__atomic_load_n(&sem1, __ATOMIC_ACQUIRE))
+ sched_yield ();
exit(!*p);
}
@@ -24,6 +25,10 @@ int main(int argc)
p = &p;
__atomic_store_n(&sem1, 1, __ATOMIC_RELEASE);
int r = -1;
- while (r < 0) asm("":"+r"(r));
+ while (r < 0)
+ {
+ sched_yield ();
+ asm("":"+r"(r));
+ }
return r;
}
diff --git a/gcc/testsuite/gcc.dg/di-sync-multithread.c b/gcc/testsuite/gcc.dg/di-sync-multithread.c
index 493f1e27201..1a97df7a9e6 100644
--- a/gcc/testsuite/gcc.dg/di-sync-multithread.c
+++ b/gcc/testsuite/gcc.dg/di-sync-multithread.c
@@ -70,6 +70,8 @@ worker (void* data)
case this to carry across the 32bit boundary. */
for (tmp2 = 0; tmp2 < 64; tmp2++)
{
+ sched_yield ();
+
/* Add 2 using the two different adds. */
tmp1 = __sync_add_and_fetch (&workspace, add1bit);
tmp3 = __sync_fetch_and_add (&workspace, add1bit);
@@ -103,6 +105,8 @@ worker (void* data)
for (tmp2 = 0; tmp2 < 64; tmp2++)
{
+ sched_yield ();
+
/* Subtract 2 using the two different subs. */
tmp1=__sync_sub_and_fetch (&workspace, add1bit);
tmp3=__sync_fetch_and_sub (&workspace, add1bit);
@@ -178,6 +182,8 @@ main ()
t, err);
};
+ sched_yield ();
+
#ifdef _WIN32
Sleep (5000);
#else
@@ -187,6 +193,8 @@ main ()
/* Stop please. */
__sync_lock_test_and_set (&doquit, 1ll);
+ sched_yield ();
+
for (t = 0; t < 3; t++)
{
err=pthread_join (threads[t], NULL);
^ permalink raw reply [flat|nested] 10+ messages in thread
* [gcc(refs/users/aoliva/heads/testme)] testsuite: pthread: call sched_yield for non-preemptive targets
@ 2022-06-23 12:30 Alexandre Oliva
0 siblings, 0 replies; 10+ messages in thread
From: Alexandre Oliva @ 2022-06-23 12:30 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:0d9b43974fd16d41c7174d98fe108d240cddbf72
commit 0d9b43974fd16d41c7174d98fe108d240cddbf72
Author: Alexandre Oliva <oliva@adacore.com>
Date: Mon Jun 20 19:43:47 2022 -0300
testsuite: pthread: call sched_yield for non-preemptive targets
Systems without preemptive multi-threading require sched_yield calls
to be placed at points in which a context switch might be needed to
enable the test to complete.
for gcc/testsuite/ChangeLog
* gcc.dg/atomic/c11-atomic-exec-4.c: Call sched_yield.
* gcc.dg/atomic/c11-atomic-exec-5.c: Likewise.
* gcc.dg/atomic/pr80640-2.c: Likewise.
* gcc.dg/atomic/pr80640.c: Likewise.
* gcc.dg/atomic/pr81316.c: Likewise.
* gcc.dg/di-sync-multithread.c: Likewise.
Diff:
---
gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-4.c | 12 +++++++++---
gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-5.c | 6 +++++-
gcc/testsuite/gcc.dg/atomic/pr80640-2.c | 6 ++++--
gcc/testsuite/gcc.dg/atomic/pr80640.c | 6 ++++--
gcc/testsuite/gcc.dg/atomic/pr81316.c | 9 +++++++--
gcc/testsuite/gcc.dg/di-sync-multithread.c | 8 ++++++++
6 files changed, 37 insertions(+), 10 deletions(-)
diff --git a/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-4.c b/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-4.c
index d6bb629f59f..669e7c058c3 100644
--- a/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-4.c
+++ b/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-4.c
@@ -32,7 +32,10 @@ test_thread_##NAME (void *arg) \
{ \
thread_ready = true; \
for (int i = 0; i < ITER_COUNT; i++) \
- PRE var_##NAME POST; \
+ { \
+ sched_yield (); \
+ PRE var_##NAME POST; \
+ } \
return NULL; \
} \
\
@@ -49,9 +52,12 @@ test_main_##NAME (void) \
return 1; \
} \
while (!thread_ready) \
- ; \
+ sched_yield (); \
for (int i = 0; i < ITER_COUNT; i++) \
- PRE var_##NAME POST; \
+ { \
+ PRE var_##NAME POST; \
+ sched_yield (); \
+ } \
pthread_join (thread_id, NULL); \
if (var_##NAME != (FINAL)) \
{ \
diff --git a/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-5.c b/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-5.c
index 692c64ad207..f8bfa63b4cc 100644
--- a/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-5.c
+++ b/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-5.c
@@ -53,8 +53,11 @@ test_thread_##NAME (void *arg) \
thread_ready = true; \
while (!thread_stop) \
{ \
+ sched_yield (); \
var_##NAME = (INIT1); \
+ sched_yield (); \
var_##NAME = (INIT2); \
+ sched_yield (); \
} \
return NULL; \
} \
@@ -75,13 +78,14 @@ test_main_##NAME (void) \
} \
int num_1_pass = 0, num_1_fail = 0, num_2_pass = 0, num_2_fail = 0; \
while (!thread_ready) \
- ; \
+ sched_yield (); \
for (int i = 0; i < ITER_COUNT; i++) \
{ \
feclearexcept (FE_ALL_EXCEPT); \
feraiseexcept (BEXC); \
LHSTYPE r = (PRE var_##NAME POST); \
int rexc = fetestexcept (TEST_ALL_EXCEPT); \
+ sched_yield (); \
if (VALTEST1 (r)) \
{ \
if (rexc == ((BEXC) | (EXC1))) \
diff --git a/gcc/testsuite/gcc.dg/atomic/pr80640-2.c b/gcc/testsuite/gcc.dg/atomic/pr80640-2.c
index a735054090d..e33dcc386ab 100644
--- a/gcc/testsuite/gcc.dg/atomic/pr80640-2.c
+++ b/gcc/testsuite/gcc.dg/atomic/pr80640-2.c
@@ -12,7 +12,8 @@ static void *f(void *va)
void **p = va;
if (*p) return *p;
sem1 = 1;
- while (!__atomic_load_n(&sem2, __ATOMIC_ACQUIRE));
+ while (!__atomic_load_n(&sem2, __ATOMIC_ACQUIRE))
+ sched_yield ();
// GCC used to RTL-CSE this and the first load, causing 0 to be returned
return *p;
}
@@ -23,7 +24,8 @@ int main()
pthread_t thr;
if (pthread_create(&thr, 0, f, &p))
return 2;
- while (!sem1);
+ while (!sem1)
+ sched_yield ();
__atomic_thread_fence(__ATOMIC_ACQUIRE);
p = &p;
__atomic_store_n(&sem2, 1, __ATOMIC_RELEASE);
diff --git a/gcc/testsuite/gcc.dg/atomic/pr80640.c b/gcc/testsuite/gcc.dg/atomic/pr80640.c
index fd17978a482..2577e0ddf4f 100644
--- a/gcc/testsuite/gcc.dg/atomic/pr80640.c
+++ b/gcc/testsuite/gcc.dg/atomic/pr80640.c
@@ -12,7 +12,8 @@ static void *f(void *va)
void **p = va;
if (*p) return *p;
sem1 = 1;
- while (!sem2);
+ while (!sem2)
+ sched_yield ();
__atomic_thread_fence(__ATOMIC_ACQUIRE);
// GCC used to RTL-CSE this and the first load, causing 0 to be returned
return *p;
@@ -24,7 +25,8 @@ int main()
pthread_t thr;
if (pthread_create(&thr, 0, f, &p))
return 2;
- while (!sem1);
+ while (!sem1)
+ sched_yield ();
__atomic_thread_fence(__ATOMIC_ACQUIRE);
p = &p;
__atomic_thread_fence(__ATOMIC_RELEASE);
diff --git a/gcc/testsuite/gcc.dg/atomic/pr81316.c b/gcc/testsuite/gcc.dg/atomic/pr81316.c
index ef10095718e..dc6569a7253 100644
--- a/gcc/testsuite/gcc.dg/atomic/pr81316.c
+++ b/gcc/testsuite/gcc.dg/atomic/pr81316.c
@@ -10,7 +10,8 @@ static _Atomic int sem1;
static void *f(void *va)
{
void **p = va;
- while (!__atomic_load_n(&sem1, __ATOMIC_ACQUIRE));
+ while (!__atomic_load_n(&sem1, __ATOMIC_ACQUIRE))
+ sched_yield ();
exit(!*p);
}
@@ -24,6 +25,10 @@ int main(int argc)
p = &p;
__atomic_store_n(&sem1, 1, __ATOMIC_RELEASE);
int r = -1;
- while (r < 0) asm("":"+r"(r));
+ while (r < 0)
+ {
+ sched_yield ();
+ asm("":"+r"(r));
+ }
return r;
}
diff --git a/gcc/testsuite/gcc.dg/di-sync-multithread.c b/gcc/testsuite/gcc.dg/di-sync-multithread.c
index 493f1e27201..1a97df7a9e6 100644
--- a/gcc/testsuite/gcc.dg/di-sync-multithread.c
+++ b/gcc/testsuite/gcc.dg/di-sync-multithread.c
@@ -70,6 +70,8 @@ worker (void* data)
case this to carry across the 32bit boundary. */
for (tmp2 = 0; tmp2 < 64; tmp2++)
{
+ sched_yield ();
+
/* Add 2 using the two different adds. */
tmp1 = __sync_add_and_fetch (&workspace, add1bit);
tmp3 = __sync_fetch_and_add (&workspace, add1bit);
@@ -103,6 +105,8 @@ worker (void* data)
for (tmp2 = 0; tmp2 < 64; tmp2++)
{
+ sched_yield ();
+
/* Subtract 2 using the two different subs. */
tmp1=__sync_sub_and_fetch (&workspace, add1bit);
tmp3=__sync_fetch_and_sub (&workspace, add1bit);
@@ -178,6 +182,8 @@ main ()
t, err);
};
+ sched_yield ();
+
#ifdef _WIN32
Sleep (5000);
#else
@@ -187,6 +193,8 @@ main ()
/* Stop please. */
__sync_lock_test_and_set (&doquit, 1ll);
+ sched_yield ();
+
for (t = 0; t < 3; t++)
{
err=pthread_join (threads[t], NULL);
^ permalink raw reply [flat|nested] 10+ messages in thread
* [gcc(refs/users/aoliva/heads/testme)] testsuite: pthread: call sched_yield for non-preemptive targets
@ 2022-06-23 12:22 Alexandre Oliva
0 siblings, 0 replies; 10+ messages in thread
From: Alexandre Oliva @ 2022-06-23 12:22 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:638ea9dce0bb1153d9aa669316097c56afa7fc78
commit 638ea9dce0bb1153d9aa669316097c56afa7fc78
Author: Alexandre Oliva <oliva@adacore.com>
Date: Mon Jun 20 19:43:47 2022 -0300
testsuite: pthread: call sched_yield for non-preemptive targets
Systems without preemptive multi-threading require sched_yield calls
to be placed at points in which a context switch might be needed to
enable the test to complete.
for gcc/testsuite/ChangeLog
* gcc.dg/atomic/c11-atomic-exec-4.c: Call sched_yield.
* gcc.dg/atomic/c11-atomic-exec-5.c: Likewise.
* gcc.dg/atomic/pr80640-2.c: Likewise.
* gcc.dg/atomic/pr80640.c: Likewise.
* gcc.dg/atomic/pr81316.c: Likewise.
* gcc.dg/di-sync-multithread.c: Likewise.
Diff:
---
gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-4.c | 12 +++++++++---
gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-5.c | 6 +++++-
gcc/testsuite/gcc.dg/atomic/pr80640-2.c | 6 ++++--
gcc/testsuite/gcc.dg/atomic/pr80640.c | 6 ++++--
gcc/testsuite/gcc.dg/atomic/pr81316.c | 9 +++++++--
gcc/testsuite/gcc.dg/di-sync-multithread.c | 8 ++++++++
6 files changed, 37 insertions(+), 10 deletions(-)
diff --git a/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-4.c b/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-4.c
index d6bb629f59f..669e7c058c3 100644
--- a/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-4.c
+++ b/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-4.c
@@ -32,7 +32,10 @@ test_thread_##NAME (void *arg) \
{ \
thread_ready = true; \
for (int i = 0; i < ITER_COUNT; i++) \
- PRE var_##NAME POST; \
+ { \
+ sched_yield (); \
+ PRE var_##NAME POST; \
+ } \
return NULL; \
} \
\
@@ -49,9 +52,12 @@ test_main_##NAME (void) \
return 1; \
} \
while (!thread_ready) \
- ; \
+ sched_yield (); \
for (int i = 0; i < ITER_COUNT; i++) \
- PRE var_##NAME POST; \
+ { \
+ PRE var_##NAME POST; \
+ sched_yield (); \
+ } \
pthread_join (thread_id, NULL); \
if (var_##NAME != (FINAL)) \
{ \
diff --git a/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-5.c b/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-5.c
index 692c64ad207..f8bfa63b4cc 100644
--- a/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-5.c
+++ b/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-5.c
@@ -53,8 +53,11 @@ test_thread_##NAME (void *arg) \
thread_ready = true; \
while (!thread_stop) \
{ \
+ sched_yield (); \
var_##NAME = (INIT1); \
+ sched_yield (); \
var_##NAME = (INIT2); \
+ sched_yield (); \
} \
return NULL; \
} \
@@ -75,13 +78,14 @@ test_main_##NAME (void) \
} \
int num_1_pass = 0, num_1_fail = 0, num_2_pass = 0, num_2_fail = 0; \
while (!thread_ready) \
- ; \
+ sched_yield (); \
for (int i = 0; i < ITER_COUNT; i++) \
{ \
feclearexcept (FE_ALL_EXCEPT); \
feraiseexcept (BEXC); \
LHSTYPE r = (PRE var_##NAME POST); \
int rexc = fetestexcept (TEST_ALL_EXCEPT); \
+ sched_yield (); \
if (VALTEST1 (r)) \
{ \
if (rexc == ((BEXC) | (EXC1))) \
diff --git a/gcc/testsuite/gcc.dg/atomic/pr80640-2.c b/gcc/testsuite/gcc.dg/atomic/pr80640-2.c
index a735054090d..e33dcc386ab 100644
--- a/gcc/testsuite/gcc.dg/atomic/pr80640-2.c
+++ b/gcc/testsuite/gcc.dg/atomic/pr80640-2.c
@@ -12,7 +12,8 @@ static void *f(void *va)
void **p = va;
if (*p) return *p;
sem1 = 1;
- while (!__atomic_load_n(&sem2, __ATOMIC_ACQUIRE));
+ while (!__atomic_load_n(&sem2, __ATOMIC_ACQUIRE))
+ sched_yield ();
// GCC used to RTL-CSE this and the first load, causing 0 to be returned
return *p;
}
@@ -23,7 +24,8 @@ int main()
pthread_t thr;
if (pthread_create(&thr, 0, f, &p))
return 2;
- while (!sem1);
+ while (!sem1)
+ sched_yield ();
__atomic_thread_fence(__ATOMIC_ACQUIRE);
p = &p;
__atomic_store_n(&sem2, 1, __ATOMIC_RELEASE);
diff --git a/gcc/testsuite/gcc.dg/atomic/pr80640.c b/gcc/testsuite/gcc.dg/atomic/pr80640.c
index fd17978a482..2577e0ddf4f 100644
--- a/gcc/testsuite/gcc.dg/atomic/pr80640.c
+++ b/gcc/testsuite/gcc.dg/atomic/pr80640.c
@@ -12,7 +12,8 @@ static void *f(void *va)
void **p = va;
if (*p) return *p;
sem1 = 1;
- while (!sem2);
+ while (!sem2)
+ sched_yield ();
__atomic_thread_fence(__ATOMIC_ACQUIRE);
// GCC used to RTL-CSE this and the first load, causing 0 to be returned
return *p;
@@ -24,7 +25,8 @@ int main()
pthread_t thr;
if (pthread_create(&thr, 0, f, &p))
return 2;
- while (!sem1);
+ while (!sem1)
+ sched_yield ();
__atomic_thread_fence(__ATOMIC_ACQUIRE);
p = &p;
__atomic_thread_fence(__ATOMIC_RELEASE);
diff --git a/gcc/testsuite/gcc.dg/atomic/pr81316.c b/gcc/testsuite/gcc.dg/atomic/pr81316.c
index ef10095718e..dc6569a7253 100644
--- a/gcc/testsuite/gcc.dg/atomic/pr81316.c
+++ b/gcc/testsuite/gcc.dg/atomic/pr81316.c
@@ -10,7 +10,8 @@ static _Atomic int sem1;
static void *f(void *va)
{
void **p = va;
- while (!__atomic_load_n(&sem1, __ATOMIC_ACQUIRE));
+ while (!__atomic_load_n(&sem1, __ATOMIC_ACQUIRE))
+ sched_yield ();
exit(!*p);
}
@@ -24,6 +25,10 @@ int main(int argc)
p = &p;
__atomic_store_n(&sem1, 1, __ATOMIC_RELEASE);
int r = -1;
- while (r < 0) asm("":"+r"(r));
+ while (r < 0)
+ {
+ sched_yield ();
+ asm("":"+r"(r));
+ }
return r;
}
diff --git a/gcc/testsuite/gcc.dg/di-sync-multithread.c b/gcc/testsuite/gcc.dg/di-sync-multithread.c
index 493f1e27201..1a97df7a9e6 100644
--- a/gcc/testsuite/gcc.dg/di-sync-multithread.c
+++ b/gcc/testsuite/gcc.dg/di-sync-multithread.c
@@ -70,6 +70,8 @@ worker (void* data)
case this to carry across the 32bit boundary. */
for (tmp2 = 0; tmp2 < 64; tmp2++)
{
+ sched_yield ();
+
/* Add 2 using the two different adds. */
tmp1 = __sync_add_and_fetch (&workspace, add1bit);
tmp3 = __sync_fetch_and_add (&workspace, add1bit);
@@ -103,6 +105,8 @@ worker (void* data)
for (tmp2 = 0; tmp2 < 64; tmp2++)
{
+ sched_yield ();
+
/* Subtract 2 using the two different subs. */
tmp1=__sync_sub_and_fetch (&workspace, add1bit);
tmp3=__sync_fetch_and_sub (&workspace, add1bit);
@@ -178,6 +182,8 @@ main ()
t, err);
};
+ sched_yield ();
+
#ifdef _WIN32
Sleep (5000);
#else
@@ -187,6 +193,8 @@ main ()
/* Stop please. */
__sync_lock_test_and_set (&doquit, 1ll);
+ sched_yield ();
+
for (t = 0; t < 3; t++)
{
err=pthread_join (threads[t], NULL);
^ permalink raw reply [flat|nested] 10+ messages in thread
* [gcc(refs/users/aoliva/heads/testme)] testsuite: pthread: call sched_yield for non-preemptive targets
@ 2022-06-23 10:05 Alexandre Oliva
0 siblings, 0 replies; 10+ messages in thread
From: Alexandre Oliva @ 2022-06-23 10:05 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:843de4bf7ab385ecf8886f9e76e03fa7e7ee1651
commit 843de4bf7ab385ecf8886f9e76e03fa7e7ee1651
Author: Alexandre Oliva <oliva@adacore.com>
Date: Mon Jun 20 19:43:47 2022 -0300
testsuite: pthread: call sched_yield for non-preemptive targets
Systems without preemptive multi-threading require sched_yield calls
to be placed at points in which a context switch might be needed to
enable the test to complete.
for gcc/testsuite/ChangeLog
* gcc.dg/atomic/c11-atomic-exec-4.c: Call sched_yield.
* gcc.dg/atomic/c11-atomic-exec-5.c: Likewise.
* gcc.dg/atomic/pr80640-2.c: Likewise.
* gcc.dg/atomic/pr80640.c: Likewise.
* gcc.dg/atomic/pr81316.c: Likewise.
* gcc.dg/di-sync-multithread.c: Likewise.
Diff:
---
gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-4.c | 12 +++++++++---
gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-5.c | 6 +++++-
gcc/testsuite/gcc.dg/atomic/pr80640-2.c | 6 ++++--
gcc/testsuite/gcc.dg/atomic/pr80640.c | 6 ++++--
gcc/testsuite/gcc.dg/atomic/pr81316.c | 9 +++++++--
gcc/testsuite/gcc.dg/di-sync-multithread.c | 8 ++++++++
6 files changed, 37 insertions(+), 10 deletions(-)
diff --git a/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-4.c b/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-4.c
index d6bb629f59f..669e7c058c3 100644
--- a/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-4.c
+++ b/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-4.c
@@ -32,7 +32,10 @@ test_thread_##NAME (void *arg) \
{ \
thread_ready = true; \
for (int i = 0; i < ITER_COUNT; i++) \
- PRE var_##NAME POST; \
+ { \
+ sched_yield (); \
+ PRE var_##NAME POST; \
+ } \
return NULL; \
} \
\
@@ -49,9 +52,12 @@ test_main_##NAME (void) \
return 1; \
} \
while (!thread_ready) \
- ; \
+ sched_yield (); \
for (int i = 0; i < ITER_COUNT; i++) \
- PRE var_##NAME POST; \
+ { \
+ PRE var_##NAME POST; \
+ sched_yield (); \
+ } \
pthread_join (thread_id, NULL); \
if (var_##NAME != (FINAL)) \
{ \
diff --git a/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-5.c b/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-5.c
index 692c64ad207..f8bfa63b4cc 100644
--- a/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-5.c
+++ b/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-5.c
@@ -53,8 +53,11 @@ test_thread_##NAME (void *arg) \
thread_ready = true; \
while (!thread_stop) \
{ \
+ sched_yield (); \
var_##NAME = (INIT1); \
+ sched_yield (); \
var_##NAME = (INIT2); \
+ sched_yield (); \
} \
return NULL; \
} \
@@ -75,13 +78,14 @@ test_main_##NAME (void) \
} \
int num_1_pass = 0, num_1_fail = 0, num_2_pass = 0, num_2_fail = 0; \
while (!thread_ready) \
- ; \
+ sched_yield (); \
for (int i = 0; i < ITER_COUNT; i++) \
{ \
feclearexcept (FE_ALL_EXCEPT); \
feraiseexcept (BEXC); \
LHSTYPE r = (PRE var_##NAME POST); \
int rexc = fetestexcept (TEST_ALL_EXCEPT); \
+ sched_yield (); \
if (VALTEST1 (r)) \
{ \
if (rexc == ((BEXC) | (EXC1))) \
diff --git a/gcc/testsuite/gcc.dg/atomic/pr80640-2.c b/gcc/testsuite/gcc.dg/atomic/pr80640-2.c
index a735054090d..e33dcc386ab 100644
--- a/gcc/testsuite/gcc.dg/atomic/pr80640-2.c
+++ b/gcc/testsuite/gcc.dg/atomic/pr80640-2.c
@@ -12,7 +12,8 @@ static void *f(void *va)
void **p = va;
if (*p) return *p;
sem1 = 1;
- while (!__atomic_load_n(&sem2, __ATOMIC_ACQUIRE));
+ while (!__atomic_load_n(&sem2, __ATOMIC_ACQUIRE))
+ sched_yield ();
// GCC used to RTL-CSE this and the first load, causing 0 to be returned
return *p;
}
@@ -23,7 +24,8 @@ int main()
pthread_t thr;
if (pthread_create(&thr, 0, f, &p))
return 2;
- while (!sem1);
+ while (!sem1)
+ sched_yield ();
__atomic_thread_fence(__ATOMIC_ACQUIRE);
p = &p;
__atomic_store_n(&sem2, 1, __ATOMIC_RELEASE);
diff --git a/gcc/testsuite/gcc.dg/atomic/pr80640.c b/gcc/testsuite/gcc.dg/atomic/pr80640.c
index fd17978a482..2577e0ddf4f 100644
--- a/gcc/testsuite/gcc.dg/atomic/pr80640.c
+++ b/gcc/testsuite/gcc.dg/atomic/pr80640.c
@@ -12,7 +12,8 @@ static void *f(void *va)
void **p = va;
if (*p) return *p;
sem1 = 1;
- while (!sem2);
+ while (!sem2)
+ sched_yield ();
__atomic_thread_fence(__ATOMIC_ACQUIRE);
// GCC used to RTL-CSE this and the first load, causing 0 to be returned
return *p;
@@ -24,7 +25,8 @@ int main()
pthread_t thr;
if (pthread_create(&thr, 0, f, &p))
return 2;
- while (!sem1);
+ while (!sem1)
+ sched_yield ();
__atomic_thread_fence(__ATOMIC_ACQUIRE);
p = &p;
__atomic_thread_fence(__ATOMIC_RELEASE);
diff --git a/gcc/testsuite/gcc.dg/atomic/pr81316.c b/gcc/testsuite/gcc.dg/atomic/pr81316.c
index ef10095718e..dc6569a7253 100644
--- a/gcc/testsuite/gcc.dg/atomic/pr81316.c
+++ b/gcc/testsuite/gcc.dg/atomic/pr81316.c
@@ -10,7 +10,8 @@ static _Atomic int sem1;
static void *f(void *va)
{
void **p = va;
- while (!__atomic_load_n(&sem1, __ATOMIC_ACQUIRE));
+ while (!__atomic_load_n(&sem1, __ATOMIC_ACQUIRE))
+ sched_yield ();
exit(!*p);
}
@@ -24,6 +25,10 @@ int main(int argc)
p = &p;
__atomic_store_n(&sem1, 1, __ATOMIC_RELEASE);
int r = -1;
- while (r < 0) asm("":"+r"(r));
+ while (r < 0)
+ {
+ sched_yield ();
+ asm("":"+r"(r));
+ }
return r;
}
diff --git a/gcc/testsuite/gcc.dg/di-sync-multithread.c b/gcc/testsuite/gcc.dg/di-sync-multithread.c
index 493f1e27201..1a97df7a9e6 100644
--- a/gcc/testsuite/gcc.dg/di-sync-multithread.c
+++ b/gcc/testsuite/gcc.dg/di-sync-multithread.c
@@ -70,6 +70,8 @@ worker (void* data)
case this to carry across the 32bit boundary. */
for (tmp2 = 0; tmp2 < 64; tmp2++)
{
+ sched_yield ();
+
/* Add 2 using the two different adds. */
tmp1 = __sync_add_and_fetch (&workspace, add1bit);
tmp3 = __sync_fetch_and_add (&workspace, add1bit);
@@ -103,6 +105,8 @@ worker (void* data)
for (tmp2 = 0; tmp2 < 64; tmp2++)
{
+ sched_yield ();
+
/* Subtract 2 using the two different subs. */
tmp1=__sync_sub_and_fetch (&workspace, add1bit);
tmp3=__sync_fetch_and_sub (&workspace, add1bit);
@@ -178,6 +182,8 @@ main ()
t, err);
};
+ sched_yield ();
+
#ifdef _WIN32
Sleep (5000);
#else
@@ -187,6 +193,8 @@ main ()
/* Stop please. */
__sync_lock_test_and_set (&doquit, 1ll);
+ sched_yield ();
+
for (t = 0; t < 3; t++)
{
err=pthread_join (threads[t], NULL);
^ permalink raw reply [flat|nested] 10+ messages in thread
* [gcc(refs/users/aoliva/heads/testme)] testsuite: pthread: call sched_yield for non-preemptive targets
@ 2022-06-23 7:15 Alexandre Oliva
0 siblings, 0 replies; 10+ messages in thread
From: Alexandre Oliva @ 2022-06-23 7:15 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:ba8cfb0770665015bfc22385d6c6e6ee777b930b
commit ba8cfb0770665015bfc22385d6c6e6ee777b930b
Author: Alexandre Oliva <oliva@adacore.com>
Date: Mon Jun 20 19:43:47 2022 -0300
testsuite: pthread: call sched_yield for non-preemptive targets
Systems without preemptive multi-threading require sched_yield calls
to be placed at points in which a context switch might be needed to
enable the test to complete.
for gcc/testsuite/ChangeLog
* gcc.dg/atomic/c11-atomic-exec-4.c: Call sched_yield.
* gcc.dg/atomic/c11-atomic-exec-5.c: Likewise.
* gcc.dg/atomic/pr80640-2.c: Likewise.
* gcc.dg/atomic/pr80640.c: Likewise.
* gcc.dg/atomic/pr81316.c: Likewise.
* gcc.dg/di-sync-multithread.c: Likewise.
Diff:
---
gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-4.c | 12 +++++++++---
gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-5.c | 6 +++++-
gcc/testsuite/gcc.dg/atomic/pr80640-2.c | 6 ++++--
gcc/testsuite/gcc.dg/atomic/pr80640.c | 6 ++++--
gcc/testsuite/gcc.dg/atomic/pr81316.c | 9 +++++++--
gcc/testsuite/gcc.dg/di-sync-multithread.c | 8 ++++++++
6 files changed, 37 insertions(+), 10 deletions(-)
diff --git a/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-4.c b/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-4.c
index d6bb629f59f..669e7c058c3 100644
--- a/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-4.c
+++ b/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-4.c
@@ -32,7 +32,10 @@ test_thread_##NAME (void *arg) \
{ \
thread_ready = true; \
for (int i = 0; i < ITER_COUNT; i++) \
- PRE var_##NAME POST; \
+ { \
+ sched_yield (); \
+ PRE var_##NAME POST; \
+ } \
return NULL; \
} \
\
@@ -49,9 +52,12 @@ test_main_##NAME (void) \
return 1; \
} \
while (!thread_ready) \
- ; \
+ sched_yield (); \
for (int i = 0; i < ITER_COUNT; i++) \
- PRE var_##NAME POST; \
+ { \
+ PRE var_##NAME POST; \
+ sched_yield (); \
+ } \
pthread_join (thread_id, NULL); \
if (var_##NAME != (FINAL)) \
{ \
diff --git a/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-5.c b/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-5.c
index 692c64ad207..f8bfa63b4cc 100644
--- a/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-5.c
+++ b/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-5.c
@@ -53,8 +53,11 @@ test_thread_##NAME (void *arg) \
thread_ready = true; \
while (!thread_stop) \
{ \
+ sched_yield (); \
var_##NAME = (INIT1); \
+ sched_yield (); \
var_##NAME = (INIT2); \
+ sched_yield (); \
} \
return NULL; \
} \
@@ -75,13 +78,14 @@ test_main_##NAME (void) \
} \
int num_1_pass = 0, num_1_fail = 0, num_2_pass = 0, num_2_fail = 0; \
while (!thread_ready) \
- ; \
+ sched_yield (); \
for (int i = 0; i < ITER_COUNT; i++) \
{ \
feclearexcept (FE_ALL_EXCEPT); \
feraiseexcept (BEXC); \
LHSTYPE r = (PRE var_##NAME POST); \
int rexc = fetestexcept (TEST_ALL_EXCEPT); \
+ sched_yield (); \
if (VALTEST1 (r)) \
{ \
if (rexc == ((BEXC) | (EXC1))) \
diff --git a/gcc/testsuite/gcc.dg/atomic/pr80640-2.c b/gcc/testsuite/gcc.dg/atomic/pr80640-2.c
index a735054090d..e33dcc386ab 100644
--- a/gcc/testsuite/gcc.dg/atomic/pr80640-2.c
+++ b/gcc/testsuite/gcc.dg/atomic/pr80640-2.c
@@ -12,7 +12,8 @@ static void *f(void *va)
void **p = va;
if (*p) return *p;
sem1 = 1;
- while (!__atomic_load_n(&sem2, __ATOMIC_ACQUIRE));
+ while (!__atomic_load_n(&sem2, __ATOMIC_ACQUIRE))
+ sched_yield ();
// GCC used to RTL-CSE this and the first load, causing 0 to be returned
return *p;
}
@@ -23,7 +24,8 @@ int main()
pthread_t thr;
if (pthread_create(&thr, 0, f, &p))
return 2;
- while (!sem1);
+ while (!sem1)
+ sched_yield ();
__atomic_thread_fence(__ATOMIC_ACQUIRE);
p = &p;
__atomic_store_n(&sem2, 1, __ATOMIC_RELEASE);
diff --git a/gcc/testsuite/gcc.dg/atomic/pr80640.c b/gcc/testsuite/gcc.dg/atomic/pr80640.c
index fd17978a482..2577e0ddf4f 100644
--- a/gcc/testsuite/gcc.dg/atomic/pr80640.c
+++ b/gcc/testsuite/gcc.dg/atomic/pr80640.c
@@ -12,7 +12,8 @@ static void *f(void *va)
void **p = va;
if (*p) return *p;
sem1 = 1;
- while (!sem2);
+ while (!sem2)
+ sched_yield ();
__atomic_thread_fence(__ATOMIC_ACQUIRE);
// GCC used to RTL-CSE this and the first load, causing 0 to be returned
return *p;
@@ -24,7 +25,8 @@ int main()
pthread_t thr;
if (pthread_create(&thr, 0, f, &p))
return 2;
- while (!sem1);
+ while (!sem1)
+ sched_yield ();
__atomic_thread_fence(__ATOMIC_ACQUIRE);
p = &p;
__atomic_thread_fence(__ATOMIC_RELEASE);
diff --git a/gcc/testsuite/gcc.dg/atomic/pr81316.c b/gcc/testsuite/gcc.dg/atomic/pr81316.c
index ef10095718e..dc6569a7253 100644
--- a/gcc/testsuite/gcc.dg/atomic/pr81316.c
+++ b/gcc/testsuite/gcc.dg/atomic/pr81316.c
@@ -10,7 +10,8 @@ static _Atomic int sem1;
static void *f(void *va)
{
void **p = va;
- while (!__atomic_load_n(&sem1, __ATOMIC_ACQUIRE));
+ while (!__atomic_load_n(&sem1, __ATOMIC_ACQUIRE))
+ sched_yield ();
exit(!*p);
}
@@ -24,6 +25,10 @@ int main(int argc)
p = &p;
__atomic_store_n(&sem1, 1, __ATOMIC_RELEASE);
int r = -1;
- while (r < 0) asm("":"+r"(r));
+ while (r < 0)
+ {
+ sched_yield ();
+ asm("":"+r"(r));
+ }
return r;
}
diff --git a/gcc/testsuite/gcc.dg/di-sync-multithread.c b/gcc/testsuite/gcc.dg/di-sync-multithread.c
index 493f1e27201..1a97df7a9e6 100644
--- a/gcc/testsuite/gcc.dg/di-sync-multithread.c
+++ b/gcc/testsuite/gcc.dg/di-sync-multithread.c
@@ -70,6 +70,8 @@ worker (void* data)
case this to carry across the 32bit boundary. */
for (tmp2 = 0; tmp2 < 64; tmp2++)
{
+ sched_yield ();
+
/* Add 2 using the two different adds. */
tmp1 = __sync_add_and_fetch (&workspace, add1bit);
tmp3 = __sync_fetch_and_add (&workspace, add1bit);
@@ -103,6 +105,8 @@ worker (void* data)
for (tmp2 = 0; tmp2 < 64; tmp2++)
{
+ sched_yield ();
+
/* Subtract 2 using the two different subs. */
tmp1=__sync_sub_and_fetch (&workspace, add1bit);
tmp3=__sync_fetch_and_sub (&workspace, add1bit);
@@ -178,6 +182,8 @@ main ()
t, err);
};
+ sched_yield ();
+
#ifdef _WIN32
Sleep (5000);
#else
@@ -187,6 +193,8 @@ main ()
/* Stop please. */
__sync_lock_test_and_set (&doquit, 1ll);
+ sched_yield ();
+
for (t = 0; t < 3; t++)
{
err=pthread_join (threads[t], NULL);
^ permalink raw reply [flat|nested] 10+ messages in thread
* [gcc(refs/users/aoliva/heads/testme)] testsuite: pthread: call sched_yield for non-preemptive targets
@ 2022-06-22 5:22 Alexandre Oliva
0 siblings, 0 replies; 10+ messages in thread
From: Alexandre Oliva @ 2022-06-22 5:22 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:ccb50093fa082ae5551c60f18cb74da277292322
commit ccb50093fa082ae5551c60f18cb74da277292322
Author: Alexandre Oliva <oliva@adacore.com>
Date: Mon Jun 20 19:43:47 2022 -0300
testsuite: pthread: call sched_yield for non-preemptive targets
Systems without preemptive multi-threading require sched_yield calls
to be placed at points in which a context switch might be needed to
enable the test to complete.
for gcc/testsuite/ChangeLog
* gcc.dg/atomic/c11-atomic-exec-4.c: Call sched_yield.
* gcc.dg/atomic/c11-atomic-exec-5.c: Likewise.
* gcc.dg/atomic/pr80640-2.c: Likewise.
* gcc.dg/atomic/pr80640.c: Likewise.
* gcc.dg/atomic/pr81316.c: Likewise.
* gcc.dg/di-sync-multithread.c: Likewise.
Diff:
---
gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-4.c | 12 +++++++++---
gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-5.c | 6 +++++-
gcc/testsuite/gcc.dg/atomic/pr80640-2.c | 6 ++++--
gcc/testsuite/gcc.dg/atomic/pr80640.c | 6 ++++--
gcc/testsuite/gcc.dg/atomic/pr81316.c | 9 +++++++--
gcc/testsuite/gcc.dg/di-sync-multithread.c | 8 ++++++++
6 files changed, 37 insertions(+), 10 deletions(-)
diff --git a/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-4.c b/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-4.c
index d6bb629f59f..669e7c058c3 100644
--- a/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-4.c
+++ b/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-4.c
@@ -32,7 +32,10 @@ test_thread_##NAME (void *arg) \
{ \
thread_ready = true; \
for (int i = 0; i < ITER_COUNT; i++) \
- PRE var_##NAME POST; \
+ { \
+ sched_yield (); \
+ PRE var_##NAME POST; \
+ } \
return NULL; \
} \
\
@@ -49,9 +52,12 @@ test_main_##NAME (void) \
return 1; \
} \
while (!thread_ready) \
- ; \
+ sched_yield (); \
for (int i = 0; i < ITER_COUNT; i++) \
- PRE var_##NAME POST; \
+ { \
+ PRE var_##NAME POST; \
+ sched_yield (); \
+ } \
pthread_join (thread_id, NULL); \
if (var_##NAME != (FINAL)) \
{ \
diff --git a/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-5.c b/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-5.c
index 692c64ad207..f8bfa63b4cc 100644
--- a/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-5.c
+++ b/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-5.c
@@ -53,8 +53,11 @@ test_thread_##NAME (void *arg) \
thread_ready = true; \
while (!thread_stop) \
{ \
+ sched_yield (); \
var_##NAME = (INIT1); \
+ sched_yield (); \
var_##NAME = (INIT2); \
+ sched_yield (); \
} \
return NULL; \
} \
@@ -75,13 +78,14 @@ test_main_##NAME (void) \
} \
int num_1_pass = 0, num_1_fail = 0, num_2_pass = 0, num_2_fail = 0; \
while (!thread_ready) \
- ; \
+ sched_yield (); \
for (int i = 0; i < ITER_COUNT; i++) \
{ \
feclearexcept (FE_ALL_EXCEPT); \
feraiseexcept (BEXC); \
LHSTYPE r = (PRE var_##NAME POST); \
int rexc = fetestexcept (TEST_ALL_EXCEPT); \
+ sched_yield (); \
if (VALTEST1 (r)) \
{ \
if (rexc == ((BEXC) | (EXC1))) \
diff --git a/gcc/testsuite/gcc.dg/atomic/pr80640-2.c b/gcc/testsuite/gcc.dg/atomic/pr80640-2.c
index a735054090d..e33dcc386ab 100644
--- a/gcc/testsuite/gcc.dg/atomic/pr80640-2.c
+++ b/gcc/testsuite/gcc.dg/atomic/pr80640-2.c
@@ -12,7 +12,8 @@ static void *f(void *va)
void **p = va;
if (*p) return *p;
sem1 = 1;
- while (!__atomic_load_n(&sem2, __ATOMIC_ACQUIRE));
+ while (!__atomic_load_n(&sem2, __ATOMIC_ACQUIRE))
+ sched_yield ();
// GCC used to RTL-CSE this and the first load, causing 0 to be returned
return *p;
}
@@ -23,7 +24,8 @@ int main()
pthread_t thr;
if (pthread_create(&thr, 0, f, &p))
return 2;
- while (!sem1);
+ while (!sem1)
+ sched_yield ();
__atomic_thread_fence(__ATOMIC_ACQUIRE);
p = &p;
__atomic_store_n(&sem2, 1, __ATOMIC_RELEASE);
diff --git a/gcc/testsuite/gcc.dg/atomic/pr80640.c b/gcc/testsuite/gcc.dg/atomic/pr80640.c
index fd17978a482..2577e0ddf4f 100644
--- a/gcc/testsuite/gcc.dg/atomic/pr80640.c
+++ b/gcc/testsuite/gcc.dg/atomic/pr80640.c
@@ -12,7 +12,8 @@ static void *f(void *va)
void **p = va;
if (*p) return *p;
sem1 = 1;
- while (!sem2);
+ while (!sem2)
+ sched_yield ();
__atomic_thread_fence(__ATOMIC_ACQUIRE);
// GCC used to RTL-CSE this and the first load, causing 0 to be returned
return *p;
@@ -24,7 +25,8 @@ int main()
pthread_t thr;
if (pthread_create(&thr, 0, f, &p))
return 2;
- while (!sem1);
+ while (!sem1)
+ sched_yield ();
__atomic_thread_fence(__ATOMIC_ACQUIRE);
p = &p;
__atomic_thread_fence(__ATOMIC_RELEASE);
diff --git a/gcc/testsuite/gcc.dg/atomic/pr81316.c b/gcc/testsuite/gcc.dg/atomic/pr81316.c
index ef10095718e..dc6569a7253 100644
--- a/gcc/testsuite/gcc.dg/atomic/pr81316.c
+++ b/gcc/testsuite/gcc.dg/atomic/pr81316.c
@@ -10,7 +10,8 @@ static _Atomic int sem1;
static void *f(void *va)
{
void **p = va;
- while (!__atomic_load_n(&sem1, __ATOMIC_ACQUIRE));
+ while (!__atomic_load_n(&sem1, __ATOMIC_ACQUIRE))
+ sched_yield ();
exit(!*p);
}
@@ -24,6 +25,10 @@ int main(int argc)
p = &p;
__atomic_store_n(&sem1, 1, __ATOMIC_RELEASE);
int r = -1;
- while (r < 0) asm("":"+r"(r));
+ while (r < 0)
+ {
+ sched_yield ();
+ asm("":"+r"(r));
+ }
return r;
}
diff --git a/gcc/testsuite/gcc.dg/di-sync-multithread.c b/gcc/testsuite/gcc.dg/di-sync-multithread.c
index 493f1e27201..1a97df7a9e6 100644
--- a/gcc/testsuite/gcc.dg/di-sync-multithread.c
+++ b/gcc/testsuite/gcc.dg/di-sync-multithread.c
@@ -70,6 +70,8 @@ worker (void* data)
case this to carry across the 32bit boundary. */
for (tmp2 = 0; tmp2 < 64; tmp2++)
{
+ sched_yield ();
+
/* Add 2 using the two different adds. */
tmp1 = __sync_add_and_fetch (&workspace, add1bit);
tmp3 = __sync_fetch_and_add (&workspace, add1bit);
@@ -103,6 +105,8 @@ worker (void* data)
for (tmp2 = 0; tmp2 < 64; tmp2++)
{
+ sched_yield ();
+
/* Subtract 2 using the two different subs. */
tmp1=__sync_sub_and_fetch (&workspace, add1bit);
tmp3=__sync_fetch_and_sub (&workspace, add1bit);
@@ -178,6 +182,8 @@ main ()
t, err);
};
+ sched_yield ();
+
#ifdef _WIN32
Sleep (5000);
#else
@@ -187,6 +193,8 @@ main ()
/* Stop please. */
__sync_lock_test_and_set (&doquit, 1ll);
+ sched_yield ();
+
for (t = 0; t < 3; t++)
{
err=pthread_join (threads[t], NULL);
^ permalink raw reply [flat|nested] 10+ messages in thread
* [gcc(refs/users/aoliva/heads/testme)] testsuite: pthread: call sched_yield for non-preemptive targets
@ 2022-06-21 0:16 Alexandre Oliva
0 siblings, 0 replies; 10+ messages in thread
From: Alexandre Oliva @ 2022-06-21 0:16 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:e6f1daa833212e1d1c36d6d0b26e4593d91b564b
commit e6f1daa833212e1d1c36d6d0b26e4593d91b564b
Author: Alexandre Oliva <oliva@adacore.com>
Date: Mon Jun 20 19:43:47 2022 -0300
testsuite: pthread: call sched_yield for non-preemptive targets
Systems without preemptive multi-threading require sched_yield calls
to be placed at points in which a context switch might be needed to
enable the test to complete.
for gcc/testsuite/ChangeLog
* gcc.dg/atomic/c11-atomic-exec-4.c: Call sched_yield.
* gcc.dg/atomic/c11-atomic-exec-5.c: Likewise.
* gcc.dg/atomic/pr80640-2.c: Likewise.
* gcc.dg/atomic/pr80640.c: Likewise.
* gcc.dg/atomic/pr81316.c: Likewise.
* gcc.dg/di-sync-multithread.c: Likewise.
Diff:
---
gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-4.c | 12 +++++++++---
gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-5.c | 6 +++++-
gcc/testsuite/gcc.dg/atomic/pr80640-2.c | 6 ++++--
gcc/testsuite/gcc.dg/atomic/pr80640.c | 6 ++++--
gcc/testsuite/gcc.dg/atomic/pr81316.c | 9 +++++++--
gcc/testsuite/gcc.dg/di-sync-multithread.c | 8 ++++++++
6 files changed, 37 insertions(+), 10 deletions(-)
diff --git a/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-4.c b/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-4.c
index d6bb629f59f..669e7c058c3 100644
--- a/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-4.c
+++ b/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-4.c
@@ -32,7 +32,10 @@ test_thread_##NAME (void *arg) \
{ \
thread_ready = true; \
for (int i = 0; i < ITER_COUNT; i++) \
- PRE var_##NAME POST; \
+ { \
+ sched_yield (); \
+ PRE var_##NAME POST; \
+ } \
return NULL; \
} \
\
@@ -49,9 +52,12 @@ test_main_##NAME (void) \
return 1; \
} \
while (!thread_ready) \
- ; \
+ sched_yield (); \
for (int i = 0; i < ITER_COUNT; i++) \
- PRE var_##NAME POST; \
+ { \
+ PRE var_##NAME POST; \
+ sched_yield (); \
+ } \
pthread_join (thread_id, NULL); \
if (var_##NAME != (FINAL)) \
{ \
diff --git a/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-5.c b/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-5.c
index 692c64ad207..f8bfa63b4cc 100644
--- a/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-5.c
+++ b/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-5.c
@@ -53,8 +53,11 @@ test_thread_##NAME (void *arg) \
thread_ready = true; \
while (!thread_stop) \
{ \
+ sched_yield (); \
var_##NAME = (INIT1); \
+ sched_yield (); \
var_##NAME = (INIT2); \
+ sched_yield (); \
} \
return NULL; \
} \
@@ -75,13 +78,14 @@ test_main_##NAME (void) \
} \
int num_1_pass = 0, num_1_fail = 0, num_2_pass = 0, num_2_fail = 0; \
while (!thread_ready) \
- ; \
+ sched_yield (); \
for (int i = 0; i < ITER_COUNT; i++) \
{ \
feclearexcept (FE_ALL_EXCEPT); \
feraiseexcept (BEXC); \
LHSTYPE r = (PRE var_##NAME POST); \
int rexc = fetestexcept (TEST_ALL_EXCEPT); \
+ sched_yield (); \
if (VALTEST1 (r)) \
{ \
if (rexc == ((BEXC) | (EXC1))) \
diff --git a/gcc/testsuite/gcc.dg/atomic/pr80640-2.c b/gcc/testsuite/gcc.dg/atomic/pr80640-2.c
index a735054090d..e33dcc386ab 100644
--- a/gcc/testsuite/gcc.dg/atomic/pr80640-2.c
+++ b/gcc/testsuite/gcc.dg/atomic/pr80640-2.c
@@ -12,7 +12,8 @@ static void *f(void *va)
void **p = va;
if (*p) return *p;
sem1 = 1;
- while (!__atomic_load_n(&sem2, __ATOMIC_ACQUIRE));
+ while (!__atomic_load_n(&sem2, __ATOMIC_ACQUIRE))
+ sched_yield ();
// GCC used to RTL-CSE this and the first load, causing 0 to be returned
return *p;
}
@@ -23,7 +24,8 @@ int main()
pthread_t thr;
if (pthread_create(&thr, 0, f, &p))
return 2;
- while (!sem1);
+ while (!sem1)
+ sched_yield ();
__atomic_thread_fence(__ATOMIC_ACQUIRE);
p = &p;
__atomic_store_n(&sem2, 1, __ATOMIC_RELEASE);
diff --git a/gcc/testsuite/gcc.dg/atomic/pr80640.c b/gcc/testsuite/gcc.dg/atomic/pr80640.c
index fd17978a482..2577e0ddf4f 100644
--- a/gcc/testsuite/gcc.dg/atomic/pr80640.c
+++ b/gcc/testsuite/gcc.dg/atomic/pr80640.c
@@ -12,7 +12,8 @@ static void *f(void *va)
void **p = va;
if (*p) return *p;
sem1 = 1;
- while (!sem2);
+ while (!sem2)
+ sched_yield ();
__atomic_thread_fence(__ATOMIC_ACQUIRE);
// GCC used to RTL-CSE this and the first load, causing 0 to be returned
return *p;
@@ -24,7 +25,8 @@ int main()
pthread_t thr;
if (pthread_create(&thr, 0, f, &p))
return 2;
- while (!sem1);
+ while (!sem1)
+ sched_yield ();
__atomic_thread_fence(__ATOMIC_ACQUIRE);
p = &p;
__atomic_thread_fence(__ATOMIC_RELEASE);
diff --git a/gcc/testsuite/gcc.dg/atomic/pr81316.c b/gcc/testsuite/gcc.dg/atomic/pr81316.c
index ef10095718e..dc6569a7253 100644
--- a/gcc/testsuite/gcc.dg/atomic/pr81316.c
+++ b/gcc/testsuite/gcc.dg/atomic/pr81316.c
@@ -10,7 +10,8 @@ static _Atomic int sem1;
static void *f(void *va)
{
void **p = va;
- while (!__atomic_load_n(&sem1, __ATOMIC_ACQUIRE));
+ while (!__atomic_load_n(&sem1, __ATOMIC_ACQUIRE))
+ sched_yield ();
exit(!*p);
}
@@ -24,6 +25,10 @@ int main(int argc)
p = &p;
__atomic_store_n(&sem1, 1, __ATOMIC_RELEASE);
int r = -1;
- while (r < 0) asm("":"+r"(r));
+ while (r < 0)
+ {
+ sched_yield ();
+ asm("":"+r"(r));
+ }
return r;
}
diff --git a/gcc/testsuite/gcc.dg/di-sync-multithread.c b/gcc/testsuite/gcc.dg/di-sync-multithread.c
index 493f1e27201..1a97df7a9e6 100644
--- a/gcc/testsuite/gcc.dg/di-sync-multithread.c
+++ b/gcc/testsuite/gcc.dg/di-sync-multithread.c
@@ -70,6 +70,8 @@ worker (void* data)
case this to carry across the 32bit boundary. */
for (tmp2 = 0; tmp2 < 64; tmp2++)
{
+ sched_yield ();
+
/* Add 2 using the two different adds. */
tmp1 = __sync_add_and_fetch (&workspace, add1bit);
tmp3 = __sync_fetch_and_add (&workspace, add1bit);
@@ -103,6 +105,8 @@ worker (void* data)
for (tmp2 = 0; tmp2 < 64; tmp2++)
{
+ sched_yield ();
+
/* Subtract 2 using the two different subs. */
tmp1=__sync_sub_and_fetch (&workspace, add1bit);
tmp3=__sync_fetch_and_sub (&workspace, add1bit);
@@ -178,6 +182,8 @@ main ()
t, err);
};
+ sched_yield ();
+
#ifdef _WIN32
Sleep (5000);
#else
@@ -187,6 +193,8 @@ main ()
/* Stop please. */
__sync_lock_test_and_set (&doquit, 1ll);
+ sched_yield ();
+
for (t = 0; t < 3; t++)
{
err=pthread_join (threads[t], NULL);
^ permalink raw reply [flat|nested] 10+ messages in thread
* [gcc(refs/users/aoliva/heads/testme)] testsuite: pthread: call sched_yield for non-preemptive targets
@ 2022-06-21 0:08 Alexandre Oliva
0 siblings, 0 replies; 10+ messages in thread
From: Alexandre Oliva @ 2022-06-21 0:08 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:7794f2d268622912271adca098e9fed93cf1c87a
commit 7794f2d268622912271adca098e9fed93cf1c87a
Author: Alexandre Oliva <oliva@adacore.com>
Date: Mon Jun 20 19:43:47 2022 -0300
testsuite: pthread: call sched_yield for non-preemptive targets
Systems without preemptive multi-threading require sched_yield calls
to be placed at points in which a context switch might be needed to
enable the test to complete.
for gcc/testsuite/ChangeLog
* gcc.dg/atomic/c11-atomic-exec-4.c: Call sched_yield.
* gcc.dg/atomic/c11-atomic-exec-5.c: Likewise.
* gcc.dg/atomic/pr80640-2.c: Likewise.
* gcc.dg/atomic/pr80640.c: Likewise.
* gcc.dg/atomic/pr81316.c: Likewise.
* gcc.dg/di-sync-multithread.c: Likewise.
TN: V527-017
Diff:
---
gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-4.c | 12 +++++++++---
gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-5.c | 6 +++++-
gcc/testsuite/gcc.dg/atomic/pr80640-2.c | 6 ++++--
gcc/testsuite/gcc.dg/atomic/pr80640.c | 6 ++++--
gcc/testsuite/gcc.dg/atomic/pr81316.c | 9 +++++++--
gcc/testsuite/gcc.dg/di-sync-multithread.c | 8 ++++++++
6 files changed, 37 insertions(+), 10 deletions(-)
diff --git a/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-4.c b/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-4.c
index d6bb629f59f..669e7c058c3 100644
--- a/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-4.c
+++ b/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-4.c
@@ -32,7 +32,10 @@ test_thread_##NAME (void *arg) \
{ \
thread_ready = true; \
for (int i = 0; i < ITER_COUNT; i++) \
- PRE var_##NAME POST; \
+ { \
+ sched_yield (); \
+ PRE var_##NAME POST; \
+ } \
return NULL; \
} \
\
@@ -49,9 +52,12 @@ test_main_##NAME (void) \
return 1; \
} \
while (!thread_ready) \
- ; \
+ sched_yield (); \
for (int i = 0; i < ITER_COUNT; i++) \
- PRE var_##NAME POST; \
+ { \
+ PRE var_##NAME POST; \
+ sched_yield (); \
+ } \
pthread_join (thread_id, NULL); \
if (var_##NAME != (FINAL)) \
{ \
diff --git a/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-5.c b/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-5.c
index 692c64ad207..f8bfa63b4cc 100644
--- a/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-5.c
+++ b/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-5.c
@@ -53,8 +53,11 @@ test_thread_##NAME (void *arg) \
thread_ready = true; \
while (!thread_stop) \
{ \
+ sched_yield (); \
var_##NAME = (INIT1); \
+ sched_yield (); \
var_##NAME = (INIT2); \
+ sched_yield (); \
} \
return NULL; \
} \
@@ -75,13 +78,14 @@ test_main_##NAME (void) \
} \
int num_1_pass = 0, num_1_fail = 0, num_2_pass = 0, num_2_fail = 0; \
while (!thread_ready) \
- ; \
+ sched_yield (); \
for (int i = 0; i < ITER_COUNT; i++) \
{ \
feclearexcept (FE_ALL_EXCEPT); \
feraiseexcept (BEXC); \
LHSTYPE r = (PRE var_##NAME POST); \
int rexc = fetestexcept (TEST_ALL_EXCEPT); \
+ sched_yield (); \
if (VALTEST1 (r)) \
{ \
if (rexc == ((BEXC) | (EXC1))) \
diff --git a/gcc/testsuite/gcc.dg/atomic/pr80640-2.c b/gcc/testsuite/gcc.dg/atomic/pr80640-2.c
index a735054090d..e33dcc386ab 100644
--- a/gcc/testsuite/gcc.dg/atomic/pr80640-2.c
+++ b/gcc/testsuite/gcc.dg/atomic/pr80640-2.c
@@ -12,7 +12,8 @@ static void *f(void *va)
void **p = va;
if (*p) return *p;
sem1 = 1;
- while (!__atomic_load_n(&sem2, __ATOMIC_ACQUIRE));
+ while (!__atomic_load_n(&sem2, __ATOMIC_ACQUIRE))
+ sched_yield ();
// GCC used to RTL-CSE this and the first load, causing 0 to be returned
return *p;
}
@@ -23,7 +24,8 @@ int main()
pthread_t thr;
if (pthread_create(&thr, 0, f, &p))
return 2;
- while (!sem1);
+ while (!sem1)
+ sched_yield ();
__atomic_thread_fence(__ATOMIC_ACQUIRE);
p = &p;
__atomic_store_n(&sem2, 1, __ATOMIC_RELEASE);
diff --git a/gcc/testsuite/gcc.dg/atomic/pr80640.c b/gcc/testsuite/gcc.dg/atomic/pr80640.c
index fd17978a482..2577e0ddf4f 100644
--- a/gcc/testsuite/gcc.dg/atomic/pr80640.c
+++ b/gcc/testsuite/gcc.dg/atomic/pr80640.c
@@ -12,7 +12,8 @@ static void *f(void *va)
void **p = va;
if (*p) return *p;
sem1 = 1;
- while (!sem2);
+ while (!sem2)
+ sched_yield ();
__atomic_thread_fence(__ATOMIC_ACQUIRE);
// GCC used to RTL-CSE this and the first load, causing 0 to be returned
return *p;
@@ -24,7 +25,8 @@ int main()
pthread_t thr;
if (pthread_create(&thr, 0, f, &p))
return 2;
- while (!sem1);
+ while (!sem1)
+ sched_yield ();
__atomic_thread_fence(__ATOMIC_ACQUIRE);
p = &p;
__atomic_thread_fence(__ATOMIC_RELEASE);
diff --git a/gcc/testsuite/gcc.dg/atomic/pr81316.c b/gcc/testsuite/gcc.dg/atomic/pr81316.c
index ef10095718e..dc6569a7253 100644
--- a/gcc/testsuite/gcc.dg/atomic/pr81316.c
+++ b/gcc/testsuite/gcc.dg/atomic/pr81316.c
@@ -10,7 +10,8 @@ static _Atomic int sem1;
static void *f(void *va)
{
void **p = va;
- while (!__atomic_load_n(&sem1, __ATOMIC_ACQUIRE));
+ while (!__atomic_load_n(&sem1, __ATOMIC_ACQUIRE))
+ sched_yield ();
exit(!*p);
}
@@ -24,6 +25,10 @@ int main(int argc)
p = &p;
__atomic_store_n(&sem1, 1, __ATOMIC_RELEASE);
int r = -1;
- while (r < 0) asm("":"+r"(r));
+ while (r < 0)
+ {
+ sched_yield ();
+ asm("":"+r"(r));
+ }
return r;
}
diff --git a/gcc/testsuite/gcc.dg/di-sync-multithread.c b/gcc/testsuite/gcc.dg/di-sync-multithread.c
index 493f1e27201..1a97df7a9e6 100644
--- a/gcc/testsuite/gcc.dg/di-sync-multithread.c
+++ b/gcc/testsuite/gcc.dg/di-sync-multithread.c
@@ -70,6 +70,8 @@ worker (void* data)
case this to carry across the 32bit boundary. */
for (tmp2 = 0; tmp2 < 64; tmp2++)
{
+ sched_yield ();
+
/* Add 2 using the two different adds. */
tmp1 = __sync_add_and_fetch (&workspace, add1bit);
tmp3 = __sync_fetch_and_add (&workspace, add1bit);
@@ -103,6 +105,8 @@ worker (void* data)
for (tmp2 = 0; tmp2 < 64; tmp2++)
{
+ sched_yield ();
+
/* Subtract 2 using the two different subs. */
tmp1=__sync_sub_and_fetch (&workspace, add1bit);
tmp3=__sync_fetch_and_sub (&workspace, add1bit);
@@ -178,6 +182,8 @@ main ()
t, err);
};
+ sched_yield ();
+
#ifdef _WIN32
Sleep (5000);
#else
@@ -187,6 +193,8 @@ main ()
/* Stop please. */
__sync_lock_test_and_set (&doquit, 1ll);
+ sched_yield ();
+
for (t = 0; t < 3; t++)
{
err=pthread_join (threads[t], NULL);
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2022-06-27 10:50 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-27 9:33 [gcc(refs/users/aoliva/heads/testme)] testsuite: pthread: call sched_yield for non-preemptive targets Alexandre Oliva
-- strict thread matches above, loose matches on Subject: below --
2022-06-27 10:50 Alexandre Oliva
2022-06-23 12:44 Alexandre Oliva
2022-06-23 12:30 Alexandre Oliva
2022-06-23 12:22 Alexandre Oliva
2022-06-23 10:05 Alexandre Oliva
2022-06-23 7:15 Alexandre Oliva
2022-06-22 5:22 Alexandre Oliva
2022-06-21 0:16 Alexandre Oliva
2022-06-21 0:08 Alexandre Oliva
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).