[LTP] sched/psi: Add psi_trigger_interface01 test
linuxtestproject.agent@gmail.com
linuxtestproject.agent@gmail.com
Wed Dec 2 23:12:07 CET 2026
Hi Ujwal,
On Wed Dec 2 12:31:07 2026 +0530, Ujwal Kumar <ujwal300@linux.ibm.com> wrote:
> sched/psi: Add psi_trigger_interface01 test
> diff --git a/testcases/kernel/sched/psi/Makefile b/testcases/kernel/sched/psi/Makefile
> new file mode 100644
> index 000000000..5ea7d67db
The new test binary needs a testcases/kernel/sched/psi/.gitignore entry
(/psi_trigger_interface01) and a runtest/sched entry.
> +/*\
> + * Verify the PSI trigger interface of the pressure files.
> + *
> + * A trigger is registered by writing "<some|full> <threshold_us> <window_us>"
> + * 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
> + */
Format poll(2) as :manpage:`poll(2)` and document why .needs_root = 1 is
required (CAP_SYS_RESOURCE is needed for trigger windows that are not
multiples of 2s). Also remove the reference to the non-existent
psi_accounting01 test and the redundant [Kernel config] section, and add a
blank line after [References] using :kernel_tree: and :kernel_doc: roles.
> +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);
> + }
> +}
Pass fd to check_write() and use TST_EXP_VAL(write(fd, trigger, len), len,
"%s: '%s'", desc, trigger) when !err and TST_EXP_FAIL2(write(fd, trigger,
len), err, "%s: '%s'", desc, trigger) otherwise, instead of calling write()
bare in write_trigger() and open-coding the result checks.
> +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;
> +}
Use SAFE_WRITE(SAFE_WRITE_ALL, fd, trigger, trigger_len(trigger)) in
register_trigger() and SAFE_POLL(&pfd, 1, timeout_ms) in poll_events().
> + /* 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)");
Do not split user-visible format strings across lines; checkpatch.pl flags
lines 278 and 287 with quoted string split warnings.
> + .needs_cgroup_ver = TST_CG_V2,
> + .needs_cgroup_ctrls = (const char *const[]) {"memory", NULL},
Use "base" instead of "memory" in .needs_cgroup_ctrls. The *.pressure files
are cgroup v2 core files enabled by CONFIG_PSI=y and do not require the
memory controller.
Verdict - Needs revision
---
Note:
The agent can sometimes produce false positives although often its
findings are genuine. If you find issues with the review, please
comment this email or ignore the suggestions.
Regards,
LTP AI Reviewer
More information about the ltp
mailing list