[LTP] [PATCH v6 1/3] lapi/sched: add SAFE_SCHED_SETATTR()

Andrea Cervesato andrea.cervesato@suse.com
Thu Sep 3 09:38:45 CEST 2026


Hi Cyril,

> -static inline int sched_setattr(pid_t pid, const struct sched_attr *attr,
> +static inline int sched_setattr(pid_t pid, struct sched_attr *attr,
>                                  unsigned int flags)
>  {
>  	return syscall(__NR_sched_setattr, pid, attr, flags);
> @@ -169,4 +169,33 @@ static inline int getcpu(unsigned *cpu, unsigned *node)
>  # define CLONE_INTO_CGROUP 0x200000000ULL
>  #endif
>  
> +static inline int safe_sched_setattr(const char *file, const int lineno,
> +				     pid_t pid, struct sched_attr *attr,
> +				     unsigned int flags)
> +{
> +	int ret;
> +
> +	ret = sched_setattr(pid, attr, flags);
> +
> +	if (ret == -1) {
> +		tst_brk_(file, lineno, TBROK | TERRNO,
> +			"sched_setattr(%i) failed", pid);
> +	}
> +
> +	return ret;
> +}
> +
> +/**
> + * SAFE_SCHED_SETATTR() - Safe wrapper for sched_setattr().
> + * @pid: Target process or thread ID (0 for caller).
> + * @attr: Pointer to a sched_attr structure.
> + * @flags: Flags modifying the scheduling behavior.
> + *
> + * Calls sched_setattr() and breaks the test with TBROK | TERRNO on failure.
> + *
> + * Return: Zero on success.
> + */
> +#define SAFE_SCHED_SETATTR(pid, attr, flags)\
> +	safe_sched_setattr(__FILE__, __LINE__, (pid), (attr), (flags))
> +
>  #endif /* LAPI_SCHED_H__ */

the header is used by sched_setattr01, so I can't include the SAFE_*
definition in here, which is the right place, since we are trying to
move them into the related headers. It causes a build failure due to
the old vs. new API mix. I will send a new patch-set with the
sched_setattr01 rewrite.

--
Andrea Cervesato
SUSE QE Automation Engineer Linux
andrea.cervesato@suse.com


More information about the ltp mailing list