From patchwork Tue Mar 21 11:03:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Gao X-Patchwork-Id: 1759387 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=XP48SY+v; 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 4Pgpd539vFz247d for ; Tue, 21 Mar 2023 22:03:52 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id B28E53CCBF8 for ; Tue, 21 Mar 2023 12:03:49 +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 EF60E3CA72B for ; Tue, 21 Mar 2023 12:03:47 +0100 (CET) Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) (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 2B719600812 for ; Tue, 21 Mar 2023 12:03:46 +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 E11E31FEF0; Tue, 21 Mar 2023 11:03:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1679396624; 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=2ElQ4Ou7ZezQvO6U5Sy7kiTeFeHmpr5hxBJgeFv6Lp0=; b=XP48SY+voa3x/Q7ju5CiEvdQwAgAZPSwPV7v3pnE+FQkAD0LQrKdSEPbaN1h7OpsecesE4 rRD+hvZIwvdcJaQKSBQJoX3YHjzvd/Vh8z2G9NcymJpyEXXRGAWI7oHl4EpK2jUzhN9lk0 fzji/sdeunQ5we3x+wKKyVsRWrkxlPg= 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 0842113440; Tue, 21 Mar 2023 11:03:43 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id PZTeMg+PGWTKRQAAMHmgww (envelope-from ); Tue, 21 Mar 2023 11:03:43 +0000 To: ltp@lists.linux.it Date: Tue, 21 Mar 2023 07:03:37 -0400 Message-Id: <20230321110337.22970-1-wegao@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] starvation.c: New case for sched starvation 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: Wei Gao via ltp From: Wei Gao Reply-To: Wei Gao Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Wei Gao Add scheduller thread starvation test case base following link: https://lwn.net/ml/linux-kernel/9fd2c37a05713c206dcbd5866f67ce779f315e9e.camel@gmx.de/ --- runtest/sched | 1 + .../kernel/sched/cfs-scheduler/.gitignore | 1 + .../kernel/sched/cfs-scheduler/starvation.c | 97 +++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 testcases/kernel/sched/cfs-scheduler/starvation.c diff --git a/runtest/sched b/runtest/sched index 592898723..172fe4174 100644 --- a/runtest/sched +++ b/runtest/sched @@ -9,6 +9,7 @@ trace_sched01 trace_sched -c 1 cfs_bandwidth01 cfs_bandwidth01 -i 5 hackbench01 hackbench 50 process 1000 hackbench02 hackbench 20 thread 1000 +starvation starvation sched_cli_serv run_sched_cliserv.sh # Run this stress test for 2 minutes diff --git a/testcases/kernel/sched/cfs-scheduler/.gitignore b/testcases/kernel/sched/cfs-scheduler/.gitignore index c5dacd6ef..e86178f80 100644 --- a/testcases/kernel/sched/cfs-scheduler/.gitignore +++ b/testcases/kernel/sched/cfs-scheduler/.gitignore @@ -1,2 +1,3 @@ /hackbench cfs_bandwidth01 +/starvation diff --git a/testcases/kernel/sched/cfs-scheduler/starvation.c b/testcases/kernel/sched/cfs-scheduler/starvation.c new file mode 100644 index 000000000..74bffd741 --- /dev/null +++ b/testcases/kernel/sched/cfs-scheduler/starvation.c @@ -0,0 +1,97 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* Copyright 2023 Mike Galbraith */ +/*\ + * + * [Description] + * + * Thread starvation test. + * This case copy from following link: + * https://lwn.net/ml/linux-kernel/9fd2c37a05713c206dcbd5866f67ce779f315e9e.camel@gmx.de/ + * + */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include + +#include "tst_test.h" + +static unsigned long loop = 10000000; + +static int wait_for_pid(pid_t pid) +{ + int status, ret; + +again: + ret = waitpid(pid, &status, 0); + if (ret == -1) { + if (errno == EINTR) + goto again; + + return -1; + } + + if (WIFSIGNALED(status)) + return 0; + + return -1; +} + +static void setup(void) +{ + cpu_set_t mask; + + CPU_ZERO(&mask); + + CPU_SET(0, &mask); + + TST_EXP_POSITIVE(sched_setaffinity(0, sizeof(mask), &mask)); +} + +static void handler(void) +{ + if (loop > 0) + --loop; +} + +static int child(void) +{ + pid_t ppid = getppid(); + + TST_CHECKPOINT_WAIT(0); + + while (1) + kill(ppid, SIGUSR1); +} + +static void do_test(void) +{ + pid_t child_pid; + + child_pid = SAFE_FORK(); + + if (!child_pid) + child(); + + SAFE_SIGNAL(SIGUSR1, handler); + TST_CHECKPOINT_WAKE(0); + + while (loop) + sleep(1); + + kill(child_pid, SIGTERM); + TST_EXP_PASS(wait_for_pid(child_pid)); +} + +static struct tst_test test = { + .test_all = do_test, + .setup = setup, + .forks_child = 1, + .needs_checkpoints = 1, + .max_runtime = 120, +};