From patchwork Tue Jun 21 05:51:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Oliva X-Patchwork-Id: 1645849 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=Ve7mqF7s; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LRwdB2w0Tz9sGp for ; Tue, 21 Jun 2022 15:51:57 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A6792384146A for ; Tue, 21 Jun 2022 05:51:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A6792384146A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1655790714; bh=Q5/MZHxvnlYewLbhqlQhRx5bYy/ubJdiloEiyn2tkig=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Ve7mqF7sbj8yEYlft6zSieD98wIsOpev9j3I+r5H6JoVblswJZTiRKJccrcM9/Rme iDANhSFMFMZi424tizxIfntbCVw9RKxbSEcc1o4PEk7liVyVb5Q/SLspDEQAx8kdJV P/igirPBrHlriUh2xq9iaSOyMlFZ6EuzboikRL80= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from rock.gnat.com (rock.gnat.com [IPv6:2620:20:4000:0:a9e:1ff:fe9b:1d1]) by sourceware.org (Postfix) with ESMTPS id 63B3B384144C for ; Tue, 21 Jun 2022 05:51:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 63B3B384144C Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 311EF1160E0; Tue, 21 Jun 2022 01:51:34 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at gnat.com Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id uwwhps2qCqH8; Tue, 21 Jun 2022 01:51:34 -0400 (EDT) Received: from free.home (tron.gnat.com [IPv6:2620:20:4000:0:46a8:42ff:fe0e:e294]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPS id EC7FD1160DF; Tue, 21 Jun 2022 01:51:33 -0400 (EDT) Received: from livre (livre.home [172.31.160.2]) by free.home (8.15.2/8.15.2) with ESMTPS id 25L5pKhY693258 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 21 Jun 2022 02:51:20 -0300 To: gcc-patches@gcc.gnu.org Subject: [PATCH] testsuite: pthread: call sched_yield for non-preemptive targets Organization: Free thinker, does not speak for AdaCore Date: Tue, 21 Jun 2022 02:51:20 -0300 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Alexandre Oliva via Gcc-patches From: Alexandre Oliva Reply-To: Alexandre Oliva Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" 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. Regstrapped on x86_64-linux-gnu, also tested with a cross to aarch64-rtems6. Ok to install? 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. --- 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 d6bb629f59ffa..669e7c058c39e 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 692c64ad20737..f8bfa63b4cc8a 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 a735054090dc4..e33dcc386ab6f 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 fd17978a48225..2577e0ddf4f19 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 ef10095718ef8..dc6569a7253ac 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 493f1e272016f..1a97df7a9e637 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);