[PATCH 1/3] virprocess: define sched_attr and sched_setattr

Michal Prívozník mprivozn at redhat.com
Wed Aug 10 08:44:26 UTC 2022


On 8/1/22 19:11, Sasha Algisi wrote:
> In order to use SCHED_DEADLINE we need sched_setattr(), as
> sched_setscheduler() does not support all the necessary parameters.
> 
> Signed-off-by: Sasha Algisi <sasha.algisi at edu.unito.it>
> Signed-off-by: Dario Faggioli <dfaggioli at suse.com>
> ---
>  src/util/virprocess.c | 39 +++++++++++++++++++++++++++++++++++++++
>  1 file changed, 39 insertions(+)
> 
> diff --git a/src/util/virprocess.c b/src/util/virprocess.c
> index 013afd91b4..a8f86784e1 100644
> --- a/src/util/virprocess.c
> +++ b/src/util/virprocess.c
> @@ -51,6 +51,10 @@
>  # include <sys/cpuset.h>
>  #endif
>  
> +#if WITH_SYS_SYSCALL_H
> +# include <sys/syscall.h>
> +#endif
> +
>  #ifdef WIN32
>  # define WIN32_LEAN_AND_MEAN
>  # include <windows.h>
> @@ -67,6 +71,10 @@
>  
>  #define VIR_FROM_THIS VIR_FROM_NONE
>  
> +#if defined(__linux__) && !defined(SCHED_FLAG_RESET_ON_FORK)
> +# define SCHED_FLAG_RESET_ON_FORK 0x01
> +#endif
> +
>  VIR_LOG_INIT("util.process");
>  
>  VIR_ENUM_IMPL(virProcessSchedPolicy,
> @@ -79,6 +87,37 @@ VIR_ENUM_IMPL(virProcessSchedPolicy,
>  );
>  
>  
> +#if defined(__linux__) && defined(SCHED_DEADLINE)
> +
> +struct sched_attr {
> +    uint32_t size;
> +    uint32_t sched_policy;
> +    uint64_t sched_flags;
> +
> +    /*SCHED_OTHER, SCHED_BATCH*/
> +    int32_t sched_nice;
> +
> +    /*SCHED_FIFO, SCHED_RR*/
> +    uint32_t sched_priority;
> +
> +    /*SCHED_DEADLINE*/
> +    uint64_t sched_runtime;
> +    uint64_t sched_deadline;
> +    uint64_t sched_period;
> +};

Darn, I wish we could just include <linux/sched/types.h> but we can't.
Kernel headers (at least the version I'm using: 5.15) are broken as the
header file redefines sched_param struct.

> +
> +
> +static
> +int sched_setattr(pid_t pid,

We format it differently:

static int
function(int arg, ..)

> +                  struct sched_attr *attr,
> +                  unsigned int flags)
> +{
> +    return syscall(SYS_sched_setattr, pid, attr, flags);
> +}
> +
> +#endif

Now, this function is not used and is static which makes compiler sad.
Maybe it can be marked as G_GNUC_UNUSED for the time being, until is
used (in the following patch). Or just squash patches together.

Michal



More information about the libvir-list mailing list