From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 75AB4606A322 for ; Wed, 2 Dec 2026 07:01:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=LSk3mEzY Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 9C2393E7477 for ; Wed, 2 Dec 2026 08:01:38 +0100 (CET) Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [IPv6:2001:4b78:1:20::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 145773E72A8 for ; Wed, 2 Dec 2026 08:01:19 +0100 (CET) Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (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-3.smtp.seeweb.it (Postfix) with ESMTPS id 820CC1A0107D for ; Wed, 2 Dec 2026 08:01:17 +0100 (CET) Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6B234ZK83568783 for ; Wed, 2 Dec 2026 07:01:15 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:message-id:mime-version :subject:to; s=pp1; bh=hM7Le0ykpz2cu75wot6MYUhGK9M8R6wwAv70nsjE4 Dc=; b=LSk3mEzY0Zk4aOcNkYDwYZVndix3AnPhl0sUt6eSMVihCK6iwnCGWQa3B hsAuXt9WtoWWVNctY4D8OeG/f3E/CRq5h4rLuGcz9UXpeBXQTc4ttUKRAbaTLgca 0VWF2IoFFSRM+tQWTdeA7Dg6DyDqpokLW7rK2q45yQHqc6jLi/lBK2VKDxBBW7Jy UrKBHqWVM+jUDrAkVwCOQzhfm51Q8vkwuwOBr/tw9H7MiKALoT5UoBDY428LpwLv LymXAicWFgV86A0wPOgcSyQQnA46lrIH07O+t4q1gE3Vu31Yz0Pk/P2KeLf8I7s8 SibrTbCC2ux4N2SOJ0M0l+yq2vE3A== Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4j7pp60g58-1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT) for ; Wed, 02 Dec 2026 07:01:15 +0000 (GMT) Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.18.1.11/8.18.1.11) with ESMTP id 6B26nElq4173534 for ; Wed, 2 Dec 2026 07:01:14 GMT Received: from smtprelay07.dal12v.mail.ibm.com ([172.16.1.9]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4j9u5fv52n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 02 Dec 2026 07:01:14 +0000 (GMT) Received: from smtpav06.wdc07v.mail.ibm.com (smtpav06.wdc07v.mail.ibm.com [10.39.53.233]) by smtprelay07.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6B271Daf29557362 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 2 Dec 2026 07:01:13 GMT Received: from smtpav06.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2EF8A58060; Wed, 2 Dec 2026 07:01:13 +0000 (GMT) Received: from smtpav06.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B5FD158071; Wed, 2 Dec 2026 07:01:11 +0000 (GMT) Received: from dhcp-9-123-12-110.bl1-in.ibm.com (unknown [9.123.12.110]) by smtpav06.wdc07v.mail.ibm.com (Postfix) with ESMTP; Wed, 2 Dec 2026 07:01:11 +0000 (GMT) From: ujwal300@linux.ibm.com To: ltp@lists.linux.it Date: Wed, 2 Dec 2026 12:31:07 +0530 Message-ID: <20261202070106.35620-2-ujwal300@linux.ibm.com> X-Mailer: git-send-email 2.50.1 X-Archived-By: MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: rYVZQ5inw_jN43FhOqZsdlNDvxGA45bs X-Proofpoint-Spam-Info: AW1haW4tMjYxMjAyMDAyNiBTYWx0ZWRfX5yGrpYoG3EBa tlSS4cgqSJaYTNI3lWeoVlCAu1FBiPDQIVGTJpzIPp3YS2iVl1CqSFue9dkLknCyQETjk9exQh6 jeN1IqGi01LEA9qshj5kWbICNl1Bv0I= X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMjAyMDAyNiBTYWx0ZWRfX8hOx46i2hWE5 euimSN5v3NnxUO1GMvRrD+HDciS7aRXJ0yDI5xjI2IkrNIPxdRtUMu/TEtbENLqKxigKhTI2qks tdbrCXDHyErkxfYgy0vwgJXsokoPIJ3HN6zJLnS47IqkLPfXuyMAaQK0PJe5mBxOTObh1a4rd00 /m4PFVNYBeK6kp8EUKNJaeYBpvdhY3gb+ocURxsu4xQH9/51gnwi95EgdiXAnUrc01xAMW5f/y4 OIM23ECDwo1AjfTBxVtBhZbPoZKtbvhgSdYjNidXSCVfpzT1InDKGGYR3DFotBu59l9Oxb5F+zG J3dYsM/4XfSDeMPFcSvESg7EB7BqR0CsqIGacoWp8OyBjUFy3s+DU5ToIe3zNyvk4zFqC1jE7t3 PYr/ltOVzDmVRKfy9kbWWtR+yEsRAt3JmszxMpF+6n9rWSUlCHUIPd9vVLsLdb6q2FzkNlL6pEK fGmFBJQt9JtyzvRvwoA== X-Authority-Analysis: v=2.4 cv=Ae8kjHXG c=1 sm=1 tr=0 ts=6b0fc23b cx=c_pps a=GFwsV6G8L6GxiO2Y/PsHdQ==:117 a=GFwsV6G8L6GxiO2Y/PsHdQ==:17 a=pUM-KoujPXoA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=U7nrCbtTmkRpXpFmAIza:22 a=VnNF1IyMAAAA:8 a=5y--eyNyNitgPs9XmMsA:9 X-Proofpoint-ORIG-GUID: rYVZQ5inw_jN43FhOqZsdlNDvxGA45bs X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-12-02_01,2026-12-01_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 adultscore=0 spamscore=0 malwarescore=0 phishscore=0 lowpriorityscore=0 bulkscore=0 priorityscore=1501 impostorscore=0 clxscore=1011 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2612020026 X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Virus-Scanned: clamav-milter 1.0.9 at in-3.smtp.seeweb.it X-Virus-Status: Clean Subject: [LTP] [PATCH] sched/psi: Add psi_trigger_interface01 test X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "ltp" From: Ujwal Kumar Add new LTP test case to verify PSI (Pressure Stall Information) trigger interface. Signed-off-by: Ujwal Kumar --- testcases/kernel/sched/psi/Makefile | 6 + .../sched/psi/psi_trigger_interface01.c | 324 ++++++++++++++++++ 2 files changed, 330 insertions(+) create mode 100644 testcases/kernel/sched/psi/Makefile create mode 100644 testcases/kernel/sched/psi/psi_trigger_interface01.c diff --git a/testcases/kernel/sched/psi/Makefile b/testcases/kernel/sched/psi/Makefile new file mode 100644 index 000000000..5ea7d67db --- /dev/null +++ b/testcases/kernel/sched/psi/Makefile @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk +include $(top_srcdir)/include/mk/generic_leaf_target.mk diff --git a/testcases/kernel/sched/psi/psi_trigger_interface01.c b/testcases/kernel/sched/psi/psi_trigger_interface01.c new file mode 100644 index 000000000..94d824d30 --- /dev/null +++ b/testcases/kernel/sched/psi/psi_trigger_interface01.c @@ -0,0 +1,324 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2024 Linux Test Project + */ + +/*\ + * Verify the PSI trigger interface of the pressure files. + * + * A trigger is registered by writing " " + * to an open pressure file and is monitored with poll(2) and POLLPRI. It + * lives as long as the file descriptor it was registered on. The test uses + * the pressure files of a cgroup of its own and the ones in /proc/pressure/ + * and does not generate any load, so only the interface is checked: + * + * - valid triggers are accepted, including the smallest and the largest + * allowed threshold and window. + * - malformed triggers, a window of zero or above 10s and a threshold of zero + * or above the window are rejected with EINVAL. + * - a second trigger written to a file descriptor that has one already is + * rejected with EBUSY. + * - several file descriptors of the same file can hold different triggers + * at the same time. + * - the trigger is released when its file descriptor is closed, so a new one + * can be registered afterwards. + * - poll(2) on a file descriptor without a trigger reports POLLERR, while on + * one with a trigger it does not report any event as long as there is no + * stall in the idle cgroup. + * + * The accounting of the stall time is checked by psi_accounting01. + * + * [Kernel config] + * CONFIG_PSI=y + * + * [References] + * - kernel/sched/psi.c + * - Documentation/accounting/psi.rst + */ + +#define _GNU_SOURCE + +#include +#include + +#include "tst_test.h" +#include "tst_safe_file_at.h" + +#define PSI_PROBE "/proc/pressure/cpu" +#define PSI_CPU "/proc/pressure/cpu" +#define PSI_MEMORY "/proc/pressure/memory" +#define PSI_IO "/proc/pressure/io" + +/* The kernel checks the trigger for a whole window, so wait at least for one */ +#define IDLE_TIMEOUT_MS 1500 + +#define TRIGGER_OK "some 100000 500000" +#define TRIGGER_OK_FULL "full 100000 500000" + +static struct tst_cg_group *cg_psi; +static int cg_fd = -1; + +static const struct trigger_case { + const char *file; + const char *trigger; + /* 0 if the trigger has to be accepted, otherwise the expected errno */ + int err; + const char *desc; +} trigger_cases[] = { + {"cpu.pressure", TRIGGER_OK, 0, "cgroup cpu some"}, + {"memory.pressure", TRIGGER_OK, 0, "cgroup memory some"}, + {"memory.pressure", TRIGGER_OK_FULL, 0, "cgroup memory full"}, + {"io.pressure", TRIGGER_OK, 0, "cgroup io some"}, + {"io.pressure", TRIGGER_OK_FULL, 0, "cgroup io full"}, + /* openat() ignores the directory fd for an absolute path */ + {PSI_CPU, TRIGGER_OK, 0, "system cpu some"}, + {PSI_MEMORY, TRIGGER_OK, 0, "system memory some"}, + {PSI_MEMORY, TRIGGER_OK_FULL, 0, "system memory full"}, + {PSI_IO, TRIGGER_OK, 0, "system io some"}, + {PSI_IO, TRIGGER_OK_FULL, 0, "system io full"}, + + {"memory.pressure", "some 1 500000", 0, "minimal threshold and window"}, + {"memory.pressure", "some 500000 500000", 0, "threshold equal to window"}, + {"memory.pressure", "some 1 10000000", 0, "maximal window"}, + + {"memory.pressure", "bogus 100000 500000", EINVAL, "unknown type"}, + {"memory.pressure", "aaa bbb ccc ddd eee", EINVAL, "garbage"}, + {"memory.pressure", "some 1 0", EINVAL, "zero window"}, + {"memory.pressure", "some 100000 10000001", EINVAL, "window above 10s"}, + {"memory.pressure", "some 500001 500000", EINVAL, "threshold above window"}, + {"memory.pressure", "some 0 500000", EINVAL, "zero threshold"}, +}; + +/* + * The terminating NUL is written as well, the handlers of the files in + * /proc/pressure/ replace the last byte of the data with it. + */ +static size_t trigger_len(const char *trigger) +{ + return strlen(trigger) + 1; +} + +static ssize_t write_trigger(int fd, const char *trigger) +{ + return write(fd, trigger, trigger_len(trigger)); +} + +/* + * Check the result of writing a trigger, err is 0 if it has to be accepted + * and the expected errno otherwise. + */ +static void check_write(ssize_t ret, const char *trigger, int err, + const char *desc) +{ + if (!err && ret == (ssize_t)trigger_len(trigger)) { + tst_res(TPASS, "%s: '%s' accepted", desc, trigger); + } else if (!err) { + tst_res(TFAIL | TERRNO, "%s: '%s' not accepted, ret=%zd", + desc, trigger, ret); + } else if (ret >= 0) { + tst_res(TFAIL, "%s: '%s' accepted, expected %s", + desc, trigger, tst_strerrno(err)); + } else if (errno != err) { + tst_res(TFAIL | TERRNO, "%s: '%s' expected %s", + desc, trigger, tst_strerrno(err)); + } else { + tst_res(TPASS | TERRNO, "%s: '%s' rejected", desc, trigger); + } +} + +static int open_pressure(const char *file) +{ + return SAFE_OPENAT(cg_fd, file, O_RDWR | O_NONBLOCK); +} + +static int register_trigger(const char *file, const char *trigger) +{ + int fd = open_pressure(file); + + if (write_trigger(fd, trigger) != (ssize_t)trigger_len(trigger)) + tst_brk(TBROK | TERRNO, "write('%s') to %s failed", trigger, file); + + return fd; +} + +static short poll_events(int fd, const char *file, int timeout_ms, int *ret) +{ + struct pollfd pfd = {.fd = fd, .events = POLLPRI}; + + *ret = poll(&pfd, 1, timeout_ms); + if (*ret < 0) + tst_brk(TBROK | TERRNO, "poll(%s) failed", file); + + return pfd.revents; +} + +static void verify_trigger_write(void) +{ + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(trigger_cases); i++) { + const struct trigger_case *tc = &trigger_cases[i]; + int fd = open_pressure(tc->file); + + check_write(write_trigger(fd, tc->trigger), tc->trigger, + tc->err, tc->desc); + SAFE_CLOSE(fd); + } +} + +static void verify_second_write(void) +{ + int fd = register_trigger("memory.pressure", TRIGGER_OK); + + check_write(write_trigger(fd, TRIGGER_OK_FULL), TRIGGER_OK_FULL, EBUSY, + "second trigger on the same fd"); + SAFE_CLOSE(fd); +} + +static void verify_multiple_fds(void) +{ + static const char *const triggers[] = { + "some 50000 500000", + "some 100000 500000", + "full 200000 1000000", + }; + int fds[ARRAY_SIZE(triggers)]; + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(triggers); i++) { + fds[i] = open_pressure("memory.pressure"); + check_write(write_trigger(fds[i], triggers[i]), triggers[i], 0, + "independent fd of memory.pressure"); + } + + for (i = 0; i < ARRAY_SIZE(triggers); i++) + SAFE_CLOSE(fds[i]); +} + +static void verify_reopen(void) +{ + int fd = register_trigger("io.pressure", TRIGGER_OK); + + SAFE_CLOSE(fd); + + fd = open_pressure("io.pressure"); + check_write(write_trigger(fd, TRIGGER_OK), TRIGGER_OK, 0, + "trigger after the previous fd was closed"); + SAFE_CLOSE(fd); +} + +static void verify_poll_no_trigger(void) +{ + int fd = open_pressure("memory.pressure"); + int ret; + short revents = poll_events(fd, "memory.pressure", 0, &ret); + + if (revents & POLLERR) + tst_res(TPASS, "poll() on an fd without trigger reports POLLERR"); + else + tst_res(TFAIL, "poll() on an fd without trigger, revents=0x%x", + revents); + + SAFE_CLOSE(fd); +} + +static void verify_poll_idle(void) +{ + static const char *const files[] = { + "cpu.pressure", "memory.pressure", "io.pressure", + }; + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(files); i++) { + int fd = register_trigger(files[i], TRIGGER_OK); + int ret; + short revents = poll_events(fd, files[i], IDLE_TIMEOUT_MS, &ret); + + if (revents & POLLERR) + tst_res(TFAIL, "poll(%s) returned POLLERR", files[i]); + else if (ret == 0) + tst_res(TPASS, "%s: no event in the idle cgroup", files[i]); + else + tst_res(TFAIL, "%s: event in the idle cgroup, revents=0x%x", + files[i], revents); + + SAFE_CLOSE(fd); + } +} + +static void (*const tests[])(void) = { + verify_trigger_write, + verify_second_write, + verify_multiple_fds, + verify_reopen, + verify_poll_no_trigger, + verify_poll_idle, +}; + +static void run(unsigned int n) +{ + tests[n](); +} + +static void check_pressure_file(const char *file) +{ + if (faccessat(cg_fd, file, R_OK, 0)) + tst_brk(TCONF | TERRNO, "%s is not available in the cgroup", file); +} + +static void setup(void) +{ + char buf[64]; + int fd = open(PSI_PROBE, O_RDONLY); + + /* Some distributions build PSI but keep it disabled unless psi=1 is set */ + if (fd < 0) { + if (errno == ENOENT) + tst_brk(TCONF, "PSI is not enabled in GRUB, %s does not exist " + "(add psi=1 to the kernel command line)", PSI_PROBE); + + tst_brk(TBROK | TERRNO, "open(%s) failed", PSI_PROBE); + } + + /* psi=0 on the kernel command line makes the interface return EOPNOTSUPP */ + if (read(fd, buf, sizeof(buf)) < 0) { + if (errno == EOPNOTSUPP) + tst_brk(TCONF, "PSI is not enabled in GRUB, it is disabled by " + "psi=0 (use psi=1 on the kernel command line)"); + + tst_brk(TBROK | TERRNO, "read(%s) failed", PSI_PROBE); + } + + SAFE_CLOSE(fd); + + cg_psi = tst_cg_group_mk(tst_cg, "psi"); + cg_fd = tst_cg_group_unified_dir_fd(cg_psi); + + if (cg_fd < 0) + tst_brk(TBROK, "Cannot get the directory of the cgroup"); + + check_pressure_file("cpu.pressure"); + check_pressure_file("memory.pressure"); + check_pressure_file("io.pressure"); +} + +static void cleanup(void) +{ + if (cg_psi) + cg_psi = tst_cg_group_rm(cg_psi); +} + +static struct tst_test test = { + .tcnt = ARRAY_SIZE(tests), + .test = run, + .setup = setup, + .cleanup = cleanup, + .needs_root = 1, + .min_kver = "5.2", + .needs_cgroup_ver = TST_CG_V2, + .needs_cgroup_ctrls = (const char *const[]) {"memory", NULL}, + .needs_kconfigs = (const char *const[]) { + "CONFIG_PSI=y", + NULL + }, +}; -- 2.50.1 (Apple Git-155) -- Mailing list info: https://lists.linux.it/listinfo/ltp