Back to index

glibc  2.9
sched.h
Go to the documentation of this file.
00001 /* Definitions of constants and data structure for POSIX 1003.1b-1993
00002    scheduling interface.
00003    Copyright (C) 1996-1999,2001-2003,2005,2006,2007,2008
00004    Free Software Foundation, Inc.
00005    This file is part of the GNU C Library.
00006 
00007    The GNU C Library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Lesser General Public
00009    License as published by the Free Software Foundation; either
00010    version 2.1 of the License, or (at your option) any later version.
00011 
00012    The GNU C Library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Lesser General Public License for more details.
00016 
00017    You should have received a copy of the GNU Lesser General Public
00018    License along with the GNU C Library; if not, write to the Free
00019    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00020    02111-1307 USA.  */
00021 
00022 #ifndef __need_schedparam
00023 
00024 #ifndef _SCHED_H
00025 # error "Never include <bits/sched.h> directly; use <sched.h> instead."
00026 #endif
00027 
00028 
00029 /* Scheduling algorithms.  */
00030 #define SCHED_OTHER  0
00031 #define SCHED_FIFO   1
00032 #define SCHED_RR     2
00033 #ifdef __USE_GNU
00034 # define SCHED_BATCH 3
00035 #endif
00036 
00037 #ifdef __USE_MISC
00038 /* Cloning flags.  */
00039 # define CSIGNAL       0x000000ff /* Signal mask to be sent at exit.  */
00040 # define CLONE_VM      0x00000100 /* Set if VM shared between processes.  */
00041 # define CLONE_FS      0x00000200 /* Set if fs info shared between processes.  */
00042 # define CLONE_FILES   0x00000400 /* Set if open files shared between processes.  */
00043 # define CLONE_SIGHAND 0x00000800 /* Set if signal handlers shared.  */
00044 # define CLONE_PTRACE  0x00002000 /* Set if tracing continues on the child.  */
00045 # define CLONE_VFORK   0x00004000 /* Set if the parent wants the child to
00046                                  wake it up on mm_release.  */
00047 # define CLONE_PARENT  0x00008000 /* Set if we want to have the same
00048                                  parent as the cloner.  */
00049 # define CLONE_THREAD  0x00010000 /* Set to add to same thread group.  */
00050 # define CLONE_NEWNS   0x00020000 /* Set to create new namespace.  */
00051 # define CLONE_SYSVSEM 0x00040000 /* Set to shared SVID SEM_UNDO semantics.  */
00052 # define CLONE_SETTLS  0x00080000 /* Set TLS info.  */
00053 # define CLONE_PARENT_SETTID 0x00100000 /* Store TID in userlevel buffer
00054                                       before MM copy.  */
00055 # define CLONE_CHILD_CLEARTID 0x00200000 /* Register exit futex and memory
00056                                        location to clear.  */
00057 # define CLONE_DETACHED 0x00400000 /* Create clone detached.  */
00058 # define CLONE_UNTRACED 0x00800000 /* Set if the tracing process can't
00059                                   force CLONE_PTRACE on this clone.  */
00060 # define CLONE_CHILD_SETTID 0x01000000 /* Store TID in userlevel buffer in
00061                                      the child.  */
00062 # define CLONE_NEWUTS       0x04000000    /* New utsname group.  */
00063 # define CLONE_NEWIPC       0x08000000    /* New ipcs.  */
00064 # define CLONE_NEWUSER      0x10000000    /* New user namespace.  */
00065 # define CLONE_NEWPID       0x20000000    /* New pid namespace.  */
00066 # define CLONE_NEWNET       0x40000000    /* New network namespace.  */
00067 # define CLONE_IO    0x80000000    /* Clone I/O context.  */
00068 #endif
00069 
00070 /* The official definition.  */
00071 struct sched_param
00072   {
00073     int __sched_priority;
00074   };
00075 
00076 __BEGIN_DECLS
00077 
00078 #ifdef __USE_MISC
00079 /* Clone current process.  */
00080 extern int clone (int (*__fn) (void *__arg), void *__child_stack,
00081                 int __flags, void *__arg, ...) __THROW;
00082 
00083 /* Unshare the specified resources.  */
00084 extern int unshare (int __flags) __THROW;
00085 
00086 /* Get index of currently used CPU.  */
00087 extern int sched_getcpu (void) __THROW;
00088 #endif
00089 
00090 __END_DECLS
00091 
00092 #endif /* need schedparam */
00093 
00094 #if !defined __defined_schedparam \
00095     && (defined __need_schedparam || defined _SCHED_H)
00096 # define __defined_schedparam      1
00097 /* Data structure to describe a process' schedulability.  */
00098 struct __sched_param
00099   {
00100     int __sched_priority;
00101   };
00102 # undef __need_schedparam
00103 #endif
00104 
00105 
00106 #if defined _SCHED_H && !defined __cpu_set_t_defined
00107 # define __cpu_set_t_defined
00108 /* Size definition for CPU sets.  */
00109 # define __CPU_SETSIZE      1024
00110 # define __NCPUBITS  (8 * sizeof (__cpu_mask))
00111 
00112 /* Type for array elements in 'cpu_set_t'.  */
00113 typedef unsigned long int __cpu_mask;
00114 
00115 /* Basic access functions.  */
00116 # define __CPUELT(cpu)      ((cpu) / __NCPUBITS)
00117 # define __CPUMASK(cpu)     ((__cpu_mask) 1 << ((cpu) % __NCPUBITS))
00118 
00119 /* Data structure to describe CPU mask.  */
00120 typedef struct
00121 {
00122   __cpu_mask __bits[__CPU_SETSIZE / __NCPUBITS];
00123 } cpu_set_t;
00124 
00125 /* Access functions for CPU masks.  */
00126 # if __GNUC_PREREQ (2, 91)
00127 #  define __CPU_ZERO_S(setsize, cpusetp) \
00128   do __builtin_memset (cpusetp, '\0', setsize); while (0)
00129 # else
00130 #  define __CPU_ZERO_S(setsize, cpusetp) \
00131   do {                                                               \
00132     size_t __i;                                                             \
00133     size_t __imax = (setsize) / sizeof (__cpu_mask);                        \
00134     cpu_set_t *__arr = (cpusetp);                                    \
00135     for (__i = 0; __i < __imax; ++__i)                                      \
00136       __arr->__bits[__i] = 0;                                               \
00137   } while (0)
00138 # endif
00139 # define __CPU_SET_S(cpu, setsize, cpusetp) \
00140   (__extension__                                                     \
00141    ({ size_t __cpu = (cpu);                                          \
00142       __cpu < 8 * (setsize)                                          \
00143       ? ((cpusetp)->__bits[__CPUELT (__cpu)] |= __CPUMASK (__cpu)) : 0; }))
00144 # define __CPU_CLR_S(cpu, setsize, cpusetp) \
00145   (__extension__                                                     \
00146    ({ size_t __cpu = (cpu);                                          \
00147       __cpu < 8 * (setsize)                                          \
00148       ? ((cpusetp)->__bits[__CPUELT (__cpu)] &= ~__CPUMASK (__cpu)) : 0; }))
00149 # define __CPU_ISSET_S(cpu, setsize, cpusetp) \
00150   (__extension__                                                     \
00151    ({ size_t __cpu = (cpu);                                          \
00152       __cpu < 8 * (setsize)                                          \
00153       ? (((cpusetp)->__bits[__CPUELT (__cpu)] & __CPUMASK (__cpu))) != 0      \
00154       : 0; }))
00155 
00156 # define __CPU_COUNT_S(setsize, cpusetp) \
00157   __sched_cpucount (setsize, cpusetp)
00158 
00159 # if __GNUC_PREREQ (2, 91)
00160 #  define __CPU_EQUAL_S(setsize, cpusetp1, cpusetp2) \
00161   (__builtin_memcmp (cpusetp1, cpusetp2, setsize) == 0)
00162 # else
00163 #  define __CPU_EQUAL_S(setsize, cpusetp1, cpusetp2) \
00164   (__extension__                                                     \
00165    ({ cpu_set_t *__arr1 = (cpusetp1);                                       \
00166       cpu_set_t *__arr2 = (cpusetp2);                                       \
00167       size_t __imax = (setsize) / sizeof (__cpu_mask);                      \
00168       size_t __i;                                                    \
00169       for (__i = 0; __i < __imax; ++__i)                             \
00170        if (__arr1->__bits[__i] != __arr2->__bits[__i])                      \
00171          break;                                                      \
00172       __i == __imax; }))
00173 # endif
00174 
00175 # define __CPU_OP_S(setsize, destset, srcset1, srcset2, op) \
00176   (__extension__                                                     \
00177    ({ cpu_set_t *__dest = (destset);                                        \
00178       cpu_set_t *__arr1 = (srcset1);                                        \
00179       cpu_set_t *__arr2 = (srcset2);                                        \
00180       size_t __imax = (setsize) / sizeof (__cpu_mask);                      \
00181       size_t __i;                                                    \
00182       for (__i = 0; __i < __imax; ++__i)                             \
00183        __dest->__bits[__i] = __arr1->__bits[__i] op __arr2->__bits[__i];     \
00184       __dest; }))
00185 
00186 # define __CPU_ALLOC_SIZE(count) \
00187   ((((count) + __NCPUBITS - 1) / __NCPUBITS) * sizeof (__cpu_mask))
00188 # define __CPU_ALLOC(count) __sched_cpualloc (count)
00189 # define __CPU_FREE(cpuset) __sched_cpufree (cpuset)
00190 
00191 __BEGIN_DECLS
00192 
00193 extern int __sched_cpucount (size_t __setsize, const cpu_set_t *__setp)
00194   __THROW;
00195 extern cpu_set_t *__sched_cpualloc (size_t __count) __THROW __wur;
00196 extern void __sched_cpufree (cpu_set_t *__set) __THROW;
00197 
00198 __END_DECLS
00199 
00200 #endif