]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/sys/resource.h
xnu-2422.90.20.tar.gz
[apple/xnu.git] / bsd / sys / resource.h
index 622ad92c50f5ec4f511a372327f9ea82877c53de..d4739507306e7b3c36c70d0f9f48ea5e4d9e1899 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2008 Apple Inc. All rights reserved.
  *
  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  * 
 #include <sys/cdefs.h>
 #include <sys/_types.h>
 
+#if __DARWIN_C_LEVEL >= __DARWIN_C_FULL
+#include <stdint.h>
+#endif /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL */
+
+#ifndef KERNEL
+#include <Availability.h>
+#endif
 
 /* [XSI] The timeval structure shall be defined as described in
  * <sys/time.h>
- *
- * NB: We use __darwin_time_t and __darwin_suseconds_t here to avoid
- * improperly exposing time_t and suseconds_t into the namespace.
  */
-#ifndef _TIMEVAL
-#define _TIMEVAL
-struct timeval {
-       __darwin_time_t         tv_sec;         /* seconds */
-       __darwin_suseconds_t    tv_usec;        /* and microseconds */
-};
+#include <sys/_types/_timeval.h>
+#ifdef KERNEL
+#include <sys/_types/_user32_timeval.h>
+#include <sys/_types/_user64_timeval.h>
 #endif
 
 /* The id_t type shall be defined as described in <sys/types.h> */
-#ifndef _ID_T
-#define _ID_T
-typedef __darwin_id_t  id_t;           /* can hold pid_t, gid_t, or uid_t */
-#endif
+#include <sys/_types/_id_t.h>
 
 
 /*
  * Resource limit type (low 63 bits, excluding the sign bit)
  */
-typedef __int64_t      rlim_t;
+typedef __uint64_t     rlim_t;
 
 
 /*****
@@ -108,13 +107,30 @@ typedef __int64_t rlim_t;
 #define        PRIO_PGRP       1               /* Second argument is a GID */
 #define        PRIO_USER       2               /* Second argument is a UID */
 
-#ifndef _POSIX_C_SOURCE
+#if __DARWIN_C_LEVEL >= __DARWIN_C_FULL
+#define        PRIO_DARWIN_THREAD      3               /* Second argument is always 0 (current thread) */
+#define        PRIO_DARWIN_PROCESS     4               /* Second argument is a PID */
+
 /*
  * Range limitations for the value of the third parameter to setpriority().
  */
 #define        PRIO_MIN        -20
 #define        PRIO_MAX        20
-#endif /* !_POSIX_C_SOURCE */
+
+/* 
+ * use PRIO_DARWIN_BG to set the current thread into "background" state
+ * which lowers CPU, disk IO, and networking priorites until thread terminates
+ * or "background" state is revoked
+ */
+#define PRIO_DARWIN_BG 0x1000
+
+/*
+ * use PRIO_DARWIN_NONUI to restrict a process's ability to make calls to
+ * the GPU.
+ */
+#define PRIO_DARWIN_NONUI 0x1001
+
+#endif /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL */
 
 
 
@@ -139,70 +155,164 @@ typedef __int64_t        rlim_t;
  *       is discouraged for standards compliant programs.
  */
 struct rusage {
-       struct timeval ru_utime;        /* user time used */
-       struct timeval ru_stime;        /* system time used */
-#ifdef _POSIX_C_SOURCE
+       struct timeval ru_utime;        /* user time used (PL) */
+       struct timeval ru_stime;        /* system time used (PL) */
+#if __DARWIN_C_LEVEL < __DARWIN_C_FULL
        long    ru_opaque[14];          /* implementation defined */
-#else  /* !_POSIX_C_SOURCE */
+#else
        /*
         * Informational aliases for source compatibility with programs
         * that need more information than that provided by standards,
         * and which do not mind being OS-dependent.
         */
-       long    ru_maxrss;              /* max resident set size */
+       long    ru_maxrss;              /* max resident set size (PL) */
 #define        ru_first        ru_ixrss        /* internal: ruadd() range start */
-       long    ru_ixrss;               /* integral shared memory size */
-       long    ru_idrss;               /* integral unshared data " */
-       long    ru_isrss;               /* integral unshared stack " */
-       long    ru_minflt;              /* page reclaims */
-       long    ru_majflt;              /* page faults */
-       long    ru_nswap;               /* swaps */
-       long    ru_inblock;             /* block input operations */
-       long    ru_oublock;             /* block output operations */
-       long    ru_msgsnd;              /* messages sent */
-       long    ru_msgrcv;              /* messages received */
-       long    ru_nsignals;            /* signals received */
-       long    ru_nvcsw;               /* voluntary context switches */
+       long    ru_ixrss;               /* integral shared memory size (NU) */
+       long    ru_idrss;               /* integral unshared data (NU)  */
+       long    ru_isrss;               /* integral unshared stack (NU) */
+       long    ru_minflt;              /* page reclaims (NU) */
+       long    ru_majflt;              /* page faults (NU) */
+       long    ru_nswap;               /* swaps (NU) */
+       long    ru_inblock;             /* block input operations (atomic) */
+       long    ru_oublock;             /* block output operations (atomic) */
+       long    ru_msgsnd;              /* messages sent (atomic) */
+       long    ru_msgrcv;              /* messages received (atomic) */
+       long    ru_nsignals;            /* signals received (atomic) */
+       long    ru_nvcsw;               /* voluntary context switches (atomic) */
        long    ru_nivcsw;              /* involuntary " */
 #define        ru_last         ru_nivcsw       /* internal: ruadd() range end */
-#endif /* !_POSIX_C_SOURCE */
+#endif /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL */
+};
+
+#if __DARWIN_C_LEVEL >= __DARWIN_C_FULL
+/*
+ * Flavors for proc_pid_rusage().
+ */
+#define RUSAGE_INFO_V0 0
+#define RUSAGE_INFO_V1 1
+#define RUSAGE_INFO_V2 2
+#define        RUSAGE_INFO_CURRENT RUSAGE_INFO_V2
+
+typedef void *rusage_info_t;
+
+struct rusage_info_v0 {
+       uint8_t  ri_uuid[16];
+       uint64_t ri_user_time;
+       uint64_t ri_system_time;
+       uint64_t ri_pkg_idle_wkups;
+       uint64_t ri_interrupt_wkups;
+       uint64_t ri_pageins;
+       uint64_t ri_wired_size;
+       uint64_t ri_resident_size;      
+       uint64_t ri_phys_footprint;
+       uint64_t ri_proc_start_abstime;
+       uint64_t ri_proc_exit_abstime;
+};
+
+struct rusage_info_v1 {
+       uint8_t  ri_uuid[16];
+       uint64_t ri_user_time;
+       uint64_t ri_system_time;
+       uint64_t ri_pkg_idle_wkups;
+       uint64_t ri_interrupt_wkups;
+       uint64_t ri_pageins;
+       uint64_t ri_wired_size;
+       uint64_t ri_resident_size;      
+       uint64_t ri_phys_footprint;
+       uint64_t ri_proc_start_abstime;
+       uint64_t ri_proc_exit_abstime;
+       uint64_t ri_child_user_time;
+       uint64_t ri_child_system_time;
+       uint64_t ri_child_pkg_idle_wkups;
+       uint64_t ri_child_interrupt_wkups;
+       uint64_t ri_child_pageins;
+       uint64_t ri_child_elapsed_abstime;
 };
 
+struct rusage_info_v2 {
+       uint8_t  ri_uuid[16];
+       uint64_t ri_user_time;
+       uint64_t ri_system_time;
+       uint64_t ri_pkg_idle_wkups;
+       uint64_t ri_interrupt_wkups;
+       uint64_t ri_pageins;
+       uint64_t ri_wired_size;
+       uint64_t ri_resident_size;      
+       uint64_t ri_phys_footprint;
+       uint64_t ri_proc_start_abstime;
+       uint64_t ri_proc_exit_abstime;
+       uint64_t ri_child_user_time;
+       uint64_t ri_child_system_time;
+       uint64_t ri_child_pkg_idle_wkups;
+       uint64_t ri_child_interrupt_wkups;
+       uint64_t ri_child_pageins;
+       uint64_t ri_child_elapsed_abstime;
+       uint64_t ri_diskio_bytesread;
+       uint64_t ri_diskio_byteswritten;
+};
 
+#endif /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL */
 
-// LP64todo - should this move?
 #ifdef KERNEL
-#include <machine/types.h>     /* user_time_t */
 
-/* LP64 version of struct timeval.  time_t is a long and must grow when 
- * we're dealing with a 64-bit process.
- * WARNING - keep in sync with struct timeval
- */
+struct rusage_superset {
+       struct rusage                   ru;
+       struct rusage_info_v2   ri;
+};
+
+struct rusage_info_child {
+       uint64_t ri_child_user_time;
+       uint64_t ri_child_system_time;
+       uint64_t ri_child_pkg_idle_wkups;
+       uint64_t ri_child_interrupt_wkups;
+       uint64_t ri_child_pageins;
+       uint64_t ri_child_elapsed_abstime;
+};
 
-struct user_rusage_timeval {
-       user_time_t             tv_sec;         /* seconds */
-       __darwin_suseconds_t    tv_usec __attribute((aligned(8)));      /* and microseconds */
-};     
-struct user_rusage {
-       struct user_rusage_timeval ru_utime;    /* user time used */
-       struct user_rusage_timeval ru_stime;    /* system time used */
-       user_long_t     ru_maxrss;              /* max resident set size */
-       user_long_t     ru_ixrss;               /* integral shared memory size */
-       user_long_t     ru_idrss;               /* integral unshared data " */
-       user_long_t     ru_isrss;               /* integral unshared stack " */
-       user_long_t     ru_minflt;              /* page reclaims */
-       user_long_t     ru_majflt;              /* page faults */
-       user_long_t     ru_nswap;               /* swaps */
-       user_long_t     ru_inblock;             /* block input operations */
-       user_long_t     ru_oublock;             /* block output operations */
-       user_long_t     ru_msgsnd;              /* messages sent */
-       user_long_t     ru_msgrcv;              /* messages received */
-       user_long_t     ru_nsignals;    /* signals received */
-       user_long_t     ru_nvcsw;               /* voluntary context switches */
-       user_long_t     ru_nivcsw;              /* involuntary " */
+struct rusage_info_diskiobytes {
+       volatile uint64_t ri_bytesread __attribute__((aligned(8)));
+       volatile uint64_t ri_byteswritten __attribute__((aligned(8)));
 };
 
-#endif // KERNEL
+struct user64_rusage {
+       struct user64_timeval ru_utime; /* user time used */
+       struct user64_timeval ru_stime; /* system time used */
+       user64_long_t   ru_maxrss;              /* max resident set size */
+       user64_long_t   ru_ixrss;               /* integral shared memory size */
+       user64_long_t   ru_idrss;               /* integral unshared data " */
+       user64_long_t   ru_isrss;               /* integral unshared stack " */
+       user64_long_t   ru_minflt;              /* page reclaims */
+       user64_long_t   ru_majflt;              /* page faults */
+       user64_long_t   ru_nswap;               /* swaps */
+       user64_long_t   ru_inblock;             /* block input operations */
+       user64_long_t   ru_oublock;             /* block output operations */
+       user64_long_t   ru_msgsnd;              /* messages sent */
+       user64_long_t   ru_msgrcv;              /* messages received */
+       user64_long_t   ru_nsignals;    /* signals received */
+       user64_long_t   ru_nvcsw;               /* voluntary context switches */
+       user64_long_t   ru_nivcsw;              /* involuntary " */
+};
+
+struct user32_rusage {
+       struct user32_timeval ru_utime; /* user time used */
+       struct user32_timeval ru_stime; /* system time used */
+       user32_long_t   ru_maxrss;              /* max resident set size */
+       user32_long_t   ru_ixrss;               /* integral shared memory size */
+       user32_long_t   ru_idrss;               /* integral unshared data " */
+       user32_long_t   ru_isrss;               /* integral unshared stack " */
+       user32_long_t   ru_minflt;              /* page reclaims */
+       user32_long_t   ru_majflt;              /* page faults */
+       user32_long_t   ru_nswap;               /* swaps */
+       user32_long_t   ru_inblock;             /* block input operations */
+       user32_long_t   ru_oublock;             /* block output operations */
+       user32_long_t   ru_msgsnd;              /* messages sent */
+       user32_long_t   ru_msgrcv;              /* messages received */
+       user32_long_t   ru_nsignals;    /* signals received */
+       user32_long_t   ru_nvcsw;               /* voluntary context switches */
+       user32_long_t   ru_nivcsw;              /* involuntary " */
+};
+
+#endif /* KERNEL */
 
 
 /*****
@@ -222,21 +332,22 @@ struct    user_rusage {
  * Possible values of the first parameter to getrlimit()/setrlimit(), to
  * indicate for which resource the operation is being performed.
  */
-#define        RLIMIT_CPU      0               /* cpu time per process, in ms */
+#define        RLIMIT_CPU      0               /* cpu time per process */
 #define        RLIMIT_FSIZE    1               /* file size */
 #define        RLIMIT_DATA     2               /* data segment size */
 #define        RLIMIT_STACK    3               /* stack size */
 #define        RLIMIT_CORE     4               /* core file size */
 #define        RLIMIT_AS       5               /* address space (resident set size) */
-#ifndef _POSIX_C_SOURCE
+#if __DARWIN_C_LEVEL >= __DARWIN_C_FULL
 #define        RLIMIT_RSS      RLIMIT_AS       /* source compatibility alias */
 #define        RLIMIT_MEMLOCK  6               /* locked-in-memory address space */
 #define        RLIMIT_NPROC    7               /* number of processes */
-#endif /* !_POSIX_C_SOURCE */
+#endif /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL */
 #define        RLIMIT_NOFILE   8               /* number of open files */
-#ifndef _POSIX_C_SOURCE
+#if __DARWIN_C_LEVEL >= __DARWIN_C_FULL
 #define        RLIM_NLIMITS    9               /* total number of resource limits */
-#endif /* !_POSIX_C_SOURCE */
+#endif /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL */
+#define _RLIMIT_POSIX_FLAG     0x1000  /* Set bit for strict POSIX */
 
 /*
  * A structure representing a resource limit.  The address of an instance
@@ -247,15 +358,99 @@ struct rlimit {
        rlim_t  rlim_max;               /* maximum value for rlim_cur */
 };
 
+#if __DARWIN_C_LEVEL >= __DARWIN_C_FULL
+/*
+ * proc_rlimit_control()
+ *
+ * Resource limit flavors
+ */
+#define RLIMIT_WAKEUPS_MONITOR         0x1 /* Configure the wakeups monitor. */
+#define        RLIMIT_CPU_USAGE_MONITOR        0x2 /* Configure the CPU usage monitor. */
+
+/*
+ * Flags for wakeups monitor control.
+ */
+#define WAKEMON_ENABLE                 0x01
+#define WAKEMON_DISABLE                        0x02
+#define WAKEMON_GET_PARAMS             0x04
+#define WAKEMON_SET_DEFAULTS           0x08
+#define        WAKEMON_MAKE_FATAL              0x10 /* Configure the task so that violations are fatal. */
+/*
+ * Flags for CPU usage monitor control.
+ */
+#define        CPUMON_MAKE_FATAL               0x1000
+
+struct proc_rlimit_control_wakeupmon {
+       uint32_t wm_flags;
+       int32_t wm_rate;
+};
+
+/* I/O type */
+#define IOPOL_TYPE_DISK        0
+#if PRIVATE
+#define IOPOL_TYPE_VFS_HFS_CASE_SENSITIVITY 1
+#endif
+
+/* scope */
+#define IOPOL_SCOPE_PROCESS   0
+#define IOPOL_SCOPE_THREAD    1
+#define IOPOL_SCOPE_DARWIN_BG 2
+
+/* I/O Priority */
+#define IOPOL_DEFAULT          0
+#define IOPOL_IMPORTANT                1
+#define IOPOL_PASSIVE          2
+#define IOPOL_THROTTLE         3
+#define IOPOL_UTILITY          4
+#define IOPOL_STANDARD         5
+
+/* compatibility with older names */
+#define IOPOL_APPLICATION       IOPOL_STANDARD
+#define IOPOL_NORMAL            IOPOL_IMPORTANT
+
+#if PRIVATE
+#define IOPOL_VFS_HFS_CASE_SENSITIVITY_DEFAULT 0
+#define IOPOL_VFS_HFS_CASE_SENSITIVITY_FORCE_CASE_SENSITIVE    1
+#endif
+
+#ifdef PRIVATE
+/*
+ * Structures for use in communicating via iopolicysys() between Libc and the
+ * kernel.  Not to be used by user programs directly.
+ */
+
+/*
+ * the command to iopolicysys()
+ */
+#define        IOPOL_CMD_GET           0x00000001      /* Get I/O policy */
+#define        IOPOL_CMD_SET           0x00000002      /* Set I/O policy */
+
+/*
+ * Second parameter to iopolicysys()
+ */
+struct _iopol_param_t {
+       int iop_scope;  /* current process or a thread */
+       int iop_iotype;
+       int iop_policy;
+};
+
+#endif /* PRIVATE */
+#endif /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL */
 
 #ifndef KERNEL
 
 __BEGIN_DECLS
 int    getpriority(int, id_t);
-int    getrlimit(int, struct rlimit *);
+#if __DARWIN_C_LEVEL >= __DARWIN_C_FULL
+int    getiopolicy_np(int, int) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);
+#endif /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL */
+int    getrlimit(int, struct rlimit *) __DARWIN_ALIAS(getrlimit);
 int    getrusage(int, struct rusage *);
 int    setpriority(int, id_t, int);
-int    setrlimit(int, const struct rlimit *);
+#if __DARWIN_C_LEVEL >= __DARWIN_C_FULL
+int    setiopolicy_np(int, int, int) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);
+#endif /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL */
+int    setrlimit(int, const struct rlimit *) __DARWIN_ALIAS(setrlimit);
 __END_DECLS
 
 #endif /* !KERNEL */