mirror of
https://sourceware.org/git/glibc.git
synced 2025-10-12 19:04:54 +03:00
Linux: Add the sched_setattr and sched_getattr functions
And struct sched_attr. In sysdeps/unix/sysv/linux/bits/sched.h, the hack that defines sched_param around the inclusion of <linux/sched/types.h> is quite ugly, but the definition of struct sched_param has already been dropped by the kernel, so there is nothing else we can do and maintain compatibility of <sched.h> with a wide range of kernel header versions. (An alternative would involve introducing a separate header for this functionality, but this seems unnecessary.) The existing sched_* functions that change scheduler parameters are already incompatible with PTHREAD_PRIO_PROTECT mutexes, so there is no harm in adding more functionality in this area. The documentation mostly defers to the Linux manual pages. Reviewed-by: Carlos O'Donell <carlos@redhat.com>
This commit is contained in:
@@ -34,10 +34,39 @@
|
||||
# define SCHED_IDLE 5
|
||||
# define SCHED_DEADLINE 6
|
||||
|
||||
/* Flags that can be used in policy values. */
|
||||
# define SCHED_RESET_ON_FORK 0x40000000
|
||||
#endif
|
||||
|
||||
#ifdef __USE_GNU
|
||||
/* Use "" to work around incorrect macro expansion of the
|
||||
__has_include argument (GCC PR 80005). */
|
||||
# ifdef __has_include
|
||||
# if __has_include ("linux/sched/types.h")
|
||||
/* Some older Linux versions defined sched_param in <linux/sched/types.h>. */
|
||||
# define sched_param __glibc_mask_sched_param
|
||||
# include <linux/sched/types.h>
|
||||
# undef sched_param
|
||||
# endif
|
||||
# endif
|
||||
# ifndef SCHED_ATTR_SIZE_VER0
|
||||
# include <linux/types.h>
|
||||
# define SCHED_ATTR_SIZE_VER0 48
|
||||
# define SCHED_ATTR_SIZE_VER1 56
|
||||
struct sched_attr
|
||||
{
|
||||
__u32 size;
|
||||
__u32 sched_policy;
|
||||
__u64 sched_flags;
|
||||
__s32 sched_nice;
|
||||
__u32 sched_priority;
|
||||
__u64 sched_runtime;
|
||||
__u64 sched_deadline;
|
||||
__u64 sched_period;
|
||||
__u32 sched_util_min;
|
||||
__u32 sched_util_max;
|
||||
/* Additional fields may be added at the end. */
|
||||
};
|
||||
# endif /* !SCHED_ATTR_SIZE_VER0 */
|
||||
|
||||
/* Cloning flags. */
|
||||
# define CSIGNAL 0x000000ff /* Signal mask to be sent at exit. */
|
||||
# define CLONE_VM 0x00000100 /* Set if VM shared between processes. */
|
||||
@@ -97,6 +126,17 @@ extern int getcpu (unsigned int *, unsigned int *) __THROW;
|
||||
|
||||
/* Switch process to namespace of type NSTYPE indicated by FD. */
|
||||
extern int setns (int __fd, int __nstype) __THROW;
|
||||
|
||||
/* Apply the scheduling attributes from *ATTR to the process or thread TID. */
|
||||
int sched_setattr (pid_t tid, struct sched_attr *attr, unsigned int flags)
|
||||
__THROW __nonnull ((2));
|
||||
|
||||
/* Obtain the scheduling attributes of the process or thread TID and
|
||||
store it in *ATTR. */
|
||||
int sched_getattr (pid_t tid, struct sched_attr *attr, unsigned int size,
|
||||
unsigned int flags)
|
||||
__THROW __nonnull ((2)) __attr_access ((__write_only__, 2, 3));
|
||||
|
||||
#endif
|
||||
|
||||
__END_DECLS
|
||||
|
Reference in New Issue
Block a user