From patchwork Mon Dec 19 16:44:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Cervesato X-Patchwork-Id: 1717480 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=susede1 header.b=eD+VcjSJ; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NbQbH12l6z1ydb for ; Tue, 20 Dec 2022 03:46:48 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 7B9103CBAFF for ; Mon, 19 Dec 2022 17:46:44 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-5.smtp.seeweb.it (in-5.smtp.seeweb.it [217.194.8.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 889433CBACC for ; Mon, 19 Dec 2022 17:46:42 +0100 (CET) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) (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 in-5.smtp.seeweb.it (Postfix) with ESMTPS id BF456600768 for ; Mon, 19 Dec 2022 17:46:41 +0100 (CET) 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 E43C9611D9; Mon, 19 Dec 2022 16:46:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1671468400; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=qZIupsi+sywN7aP48SoBJxA17GbOxbW7LtgvkN1chkw=; b=eD+VcjSJm4oWu9gNv/GF1mAiMBju1L3k8FGbftzeiXaI2YDGnhvcs1St9L0vyQm2SGLvIJ 1TJCz/BDpHN+E497o51nAPxwoJFmmiRGSpZDpL1COYDduD4BLq77LcDSjA2macy1B2NSn9 at6tW3GQXPPU2c73ACZ8h+jF54DltCE= 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 B239213498; Mon, 19 Dec 2022 16:46:40 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id XNjnKHCVoGPVdQAAMHmgww (envelope-from ); Mon, 19 Dec 2022 16:46:40 +0000 To: ltp@lists.linux.it Date: Mon, 19 Dec 2022 17:44:59 +0100 Message-Id: <20221219164459.3614-1-andrea.cervesato@suse.com> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-5.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-5.smtp.seeweb.it Subject: [LTP] [PATCH v1] Fix aio-stress stucking with multiple threads X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrea Cervesato via ltp From: Andrea Cervesato Reply-To: Andrea Cervesato Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" CPUs that increment threads_starting and threads_ending might have not flushed the operation into cache. This causes the test to stuck when variables have not been increased correctly. To avoid this issue we use pthread_barrier instead of flags. Removed also no_stonewall flag that is useless for our testing. Signed-off-by: Andrea Cervesato --- testcases/kernel/io/ltp-aiodio/aio-stress.c | 47 ++++----------------- 1 file changed, 8 insertions(+), 39 deletions(-) diff --git a/testcases/kernel/io/ltp-aiodio/aio-stress.c b/testcases/kernel/io/ltp-aiodio/aio-stress.c index 39db14d65..2fdbb84e8 100644 --- a/testcases/kernel/io/ltp-aiodio/aio-stress.c +++ b/testcases/kernel/io/ltp-aiodio/aio-stress.c @@ -88,7 +88,6 @@ static int shm_id; static char *unaligned_buffer; static char *aligned_buffer; static int padded_reclen; -static char *no_stonewall; static char *verify; static char *verify_buf; static char *unlink_files; @@ -227,10 +226,7 @@ struct thread_info { }; /* pthread mutexes and other globals for keeping the threads in sync */ -static pthread_cond_t stage_cond = PTHREAD_COND_INITIALIZER; -static pthread_mutex_t stage_mutex = PTHREAD_MUTEX_INITIALIZER; -static int threads_ending; -static int threads_starting; +static pthread_barrier_t worker_barrier; static struct timeval global_stage_start_time; static struct thread_info *global_thread_info; @@ -1025,9 +1021,6 @@ static void global_thread_throughput(struct thread_info *t, char *this_stage) if (total_mb) { tst_res(TINFO, "%s throughput (%.2f MB/s)", this_stage, total_mb / runtime); tst_res(TINFO, "%.2f MB in %.2fs", total_mb, runtime); - - if (no_stonewall) - tst_res(TINFO, "min transfer %.2fMB", min_trans); } } @@ -1053,18 +1046,8 @@ static int *worker(struct thread_info *t) restart: if (num_threads > 1) { - pthread_mutex_lock(&stage_mutex); - threads_starting++; - - if (threads_starting == num_threads) { - threads_ending = 0; + if (pthread_barrier_wait(&worker_barrier)) gettimeofday(&global_stage_start_time, NULL); - pthread_cond_broadcast(&stage_cond); - } - - while (threads_starting != num_threads) - pthread_cond_wait(&stage_cond, &stage_mutex); - pthread_mutex_unlock(&stage_mutex); } if (t->active_opers) { @@ -1077,14 +1060,7 @@ restart: /* first we send everything through aio */ while (t->active_opers && cnt < iterations) { - if (!no_stonewall && threads_ending) { - oper = t->active_opers; - oper->stonewalled = 1; - oper_list_del(oper, &t->active_opers); - oper_list_add(oper, &t->finished_opers); - } else { - run_active_list(t, io_iter, max_io_submit); - } + run_active_list(t, io_iter, max_io_submit); cnt++; } @@ -1135,18 +1111,8 @@ restart: } if (num_threads > 1) { - pthread_mutex_lock(&stage_mutex); - threads_ending++; - - if (threads_ending == num_threads) { - threads_starting = 0; - pthread_cond_broadcast(&stage_cond); + if (pthread_barrier_wait(&worker_barrier)) global_thread_throughput(t, this_stage); - } - - while (threads_ending != num_threads) - pthread_cond_wait(&stage_cond, &stage_mutex); - pthread_mutex_unlock(&stage_mutex); } /* someone got restarted, go back to the beginning */ @@ -1177,6 +1143,8 @@ static int run_workers(struct thread_info *t, int num_threads) int ret = 0; int i; + pthread_barrier_init(&worker_barrier, NULL, num_threads); + for (i = 0; i < num_threads; i++) SAFE_PTHREAD_CREATE(&t[i].tid, NULL, (start_routine)worker, t + i); @@ -1185,6 +1153,8 @@ static int run_workers(struct thread_info *t, int num_threads) ret |= (intptr_t)retval; } + pthread_barrier_destroy(&worker_barrier); + return ret; } @@ -1397,7 +1367,6 @@ static struct tst_test test = { { "t:", &str_num_threads, "Number of threads to run" }, { "u", &unlink_files, "Unlink files after completion" }, { "v", &verify, "Verification of bytes written" }, - { "x", &no_stonewall, "Turn off thread stonewalling" }, {}, }, };