From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id C6EF2385828E for ; Fri, 17 Feb 2023 22:42:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C6EF2385828E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id D0D815BF56 for ; Fri, 17 Feb 2023 22:42:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1676673738; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=48G+uEdc2Q6fqbWFyIjxbCYPABu24yRE4vpWznZANJA=; b=Fy8MOBed1Q+HFh7WL4lC0C0EDS9MlNPlOAC3R8idIaGUYhE2AoQrGqAkerXDH0CB8fJ4p7 Xb0dcNnWgqpLE7mS35WqT3bEln6P3mqQrPVRusj+YgvEUbW9wvzKvQmxr9KOQNqJpDpdyk A+yrg21p+tS3fY0rufft6LH10Mgn2RA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1676673738; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=48G+uEdc2Q6fqbWFyIjxbCYPABu24yRE4vpWznZANJA=; b=QLmb9mT60EYUAdqsp0ubXLkAcmlgeM839ov1ZS+2gAsf0VCdMccfxNU5klZxP7VSyjR1HK QDe4WW7W9vIuybCg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id C02FB13274 for ; Fri, 17 Feb 2023 22:42:18 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id Xwm4LcoC8GO8TAAAMHmgww (envelope-from ) for ; Fri, 17 Feb 2023 22:42:18 +0000 Message-ID: <1fa42134-e1bf-c10d-971e-d750a49cd244@suse.de> Date: Fri, 17 Feb 2023 23:42:20 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 Subject: Re: [pushed] [gdb/testsuite] Fix gdb.threads/schedlock.exp on fast cpu To: gdb-patches@sourceware.org References: <20230206115401.16137-1-tdevries@suse.de> Content-Language: en-US From: Tom de Vries In-Reply-To: <20230206115401.16137-1-tdevries@suse.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 2/6/23 12:54, Tom de Vries via Gdb-patches wrote: > Occasionally, I run into: > ... > (gdb) PASS: gdb.threads/schedlock.exp: schedlock=on: cmd=continue: \ > set scheduler-locking on > continue^M > Continuing.^M > PASS: gdb.threads/schedlock.exp: schedlock=on: cmd=continue: \ > continue (with lock) > [Thread 0x7ffff746e700 (LWP 1339) exited]^M > No unwaited-for children left.^M > (gdb) Quit^M > (gdb) FAIL: gdb.threads/schedlock.exp: schedlock=on: cmd=continue: \ > stop all threads (with lock) (timeout) > ... > > What happens is that this loop which is supposed to run "just short of forever": > ... > /* Don't run forever. Run just short of it :) */ > while (*myp > 0) > { > /* schedlock.exp: main loop. */ > MAYBE_CALL_SOME_FUNCTION(); (*myp) ++; > } > ... > finishes after 0x7fffffff iterations (when a signed wrap occurs), which on my > system takes only about 1.5 seconds. > > Fix this by: > - changing the pointed-at type of myp from signed to unsigned, which makes the > wrap defined behaviour (and which also make the loop run twice as long, > which is already enough to make it impossible for me to reproduce the FAIL. > But let's try to solve this more structurally). > - changing the pointed-at type of myp from int to long long, making the wrap > unlikely. > - making sure the loop runs forever, by setting the loop condition to 1. > - making sure the loop still contains different lines (as far as debug info is > concerned) by incrementing a volatile counter in the loop. > - making sure the program doesn't run forever in case of trouble, by adding an > "alarm (30)". > > Tested on x86_64-linux. > Hmm, I just found out that this regresses the test-case with older compilers like 4.8 and 5, I'll need to fix that. Thanks, - Tom > PR testsuite/30074 > Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30074 > --- > gdb/testsuite/gdb.threads/schedlock.c | 11 +++++++---- > 1 file changed, 7 insertions(+), 4 deletions(-) > > diff --git a/gdb/testsuite/gdb.threads/schedlock.c b/gdb/testsuite/gdb.threads/schedlock.c > index 5422c64fd99..c4e77948ad4 100644 > --- a/gdb/testsuite/gdb.threads/schedlock.c > +++ b/gdb/testsuite/gdb.threads/schedlock.c > @@ -24,7 +24,7 @@ void *thread_function(void *arg); /* Pointer to function executed by each thread > > #define NUM 1 > > -unsigned int args[NUM+1]; > +unsigned long long int args[NUM+1]; > > int main() { > int res; > @@ -32,6 +32,8 @@ int main() { > void *thread_result; > long i; > > + alarm (30); > + > for (i = 1; i <= NUM; i++) > { > args[i] = 1; > @@ -72,13 +74,14 @@ volatile int call_function = 0; > > void *thread_function(void *arg) { > int my_number = (long) arg; > - int *myp = (int *) &args[my_number]; > + unsigned long long int *myp = (unsigned long long int *) &args[my_number]; > + volatile unsigned int cnt = 0; > > - /* Don't run forever. Run just short of it :) */ > - while (*myp > 0) > + while (1) > { > /* schedlock.exp: main loop. */ > MAYBE_CALL_SOME_FUNCTION(); (*myp) ++; > + cnt++; > } > > pthread_exit(NULL); > > base-commit: 023b960d59c25994da233ea371deb26105fbacc8