On 2024-04-17 13:39:32+0000, Thijs Raymakers wrote: > Co-authored-by: Phil Auld <pauld@xxxxxxxxxx> > Signed-off-by: Phil Auld <pauld@xxxxxxxxxx> > Signed-off-by: Thijs Raymakers <thijs@xxxxxxxxxxxx> > --- > > Hi Karel, > > Thanks for taking a look at it! Here is the version that addresses the > man page comments that Phil made. > > Thijs [..] > diff --git a/schedutils/coresched.c b/schedutils/coresched.c > new file mode 100644 > index 000000000..bb97cc020 > --- /dev/null > +++ b/schedutils/coresched.c > @@ -0,0 +1,358 @@ > +/** > + * SPDX-License-Identifier: EUPL-1.2 > + * > + * coresched.c - manage core scheduling cookies for tasks > + * > + * Copyright (C) 2024 Thijs Raymakers, Phil Auld > + * Licensed under the EUPL v1.2 > + */ > + > +#include <getopt.h> > +#include <stdbool.h> > +#include <stdio.h> > +#include <sys/prctl.h> > +#include <unistd.h> > + > +#include "c.h" > +#include "closestream.h" > +#include "nls.h" > +#include "strutils.h" > + > +// These definitions might not be defined in the header files, even if the > +// prctl interface in the kernel accepts them as valid. > +#ifndef PR_SCHED_CORE > + #define PR_SCHED_CORE 62 > +#endif > +#ifndef PR_SCHED_CORE_GET > + #define PR_SCHED_CORE_GET 0 > +#endif > +#ifndef PR_SCHED_CORE_CREATE > + #define PR_SCHED_CORE_CREATE 1 > +#endif > +#ifndef PR_SCHED_CORE_SHARE_TO > + #define PR_SCHED_CORE_SHARE_TO 2 > +#endif > +#ifndef PR_SCHED_CORE_SHARE_FROM > + #define PR_SCHED_CORE_SHARE_FROM 3 > +#endif > +#ifndef PR_SCHED_CORE_SCOPE_THREAD > + #define PR_SCHED_CORE_SCOPE_THREAD 0 > +#endif > +#ifndef PR_SCHED_CORE_SCOPE_THREAD_GROUP > + #define PR_SCHED_CORE_SCOPE_THREAD_GROUP 1 > +#endif > +#ifndef PR_SCHED_CORE_SCOPE_PROCESS_GROUP > + #define PR_SCHED_CORE_SCOPE_PROCESS_GROUP 2 > +#endif > + > +typedef int sched_core_scope; > +typedef unsigned long sched_core_cookie; This should be uint64_t, as the kernel will always copy 64 bytes. Otherwise it will smash the stack on 32bit: https://download.copr.fedorainfracloud.org/results/packit/util-linux-util-linux-2990/fedora-rawhide-i386/07339240-util-linux/builder-live.log.gz > +typedef enum { > + SCHED_CORE_CMD_GET, > + SCHED_CORE_CMD_NEW, > + SCHED_CORE_CMD_COPY, > +} sched_core_cmd; > + > +struct args { > + pid_t src; > + pid_t dest; > + sched_core_scope type; > + sched_core_cmd cmd; > + int exec_argv_offset; > +}; > + [..]