1139825Simp/*- 21541Srgrimes * Copyright (c) 1982, 1986, 1993 31541Srgrimes * The Regents of the University of California. All rights reserved. 41541Srgrimes * 51541Srgrimes * Redistribution and use in source and binary forms, with or without 61541Srgrimes * modification, are permitted provided that the following conditions 71541Srgrimes * are met: 81541Srgrimes * 1. Redistributions of source code must retain the above copyright 91541Srgrimes * notice, this list of conditions and the following disclaimer. 101541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111541Srgrimes * notice, this list of conditions and the following disclaimer in the 121541Srgrimes * documentation and/or other materials provided with the distribution. 131541Srgrimes * 4. Neither the name of the University nor the names of its contributors 141541Srgrimes * may be used to endorse or promote products derived from this software 151541Srgrimes * without specific prior written permission. 161541Srgrimes * 171541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 181541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 191541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 201541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 211541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 221541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 231541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 241541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 251541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 261541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 271541Srgrimes * SUCH DAMAGE. 281541Srgrimes * 2914485Shsu * @(#)resource.h 8.4 (Berkeley) 1/9/95 3050477Speter * $FreeBSD$ 311541Srgrimes */ 321541Srgrimes 331541Srgrimes#ifndef _SYS_RESOURCE_H_ 341541Srgrimes#define _SYS_RESOURCE_H_ 351541Srgrimes 36130435Sdas#include <sys/cdefs.h> 37130435Sdas#include <sys/_timeval.h> 38130435Sdas#include <sys/_types.h> 39130435Sdas 401541Srgrimes/* 411541Srgrimes * Process priority specifications to get/setpriority. 421541Srgrimes */ 431541Srgrimes#define PRIO_MIN -20 441541Srgrimes#define PRIO_MAX 20 451541Srgrimes 461541Srgrimes#define PRIO_PROCESS 0 471541Srgrimes#define PRIO_PGRP 1 481541Srgrimes#define PRIO_USER 2 491541Srgrimes 501541Srgrimes/* 511541Srgrimes * Resource utilization information. 52135637Sjhb * 53170174Sjeff * All fields are only modified by curthread and 54170174Sjeff * no locks are required to read. 551541Srgrimes */ 561541Srgrimes 571541Srgrimes#define RUSAGE_SELF 0 581541Srgrimes#define RUSAGE_CHILDREN -1 59207602Skib#define RUSAGE_THREAD 1 601541Srgrimes 6183045Sobrienstruct rusage { 62170174Sjeff struct timeval ru_utime; /* user time used */ 63170174Sjeff struct timeval ru_stime; /* system time used */ 64170174Sjeff long ru_maxrss; /* max resident set size */ 651541Srgrimes#define ru_first ru_ixrss 66170174Sjeff long ru_ixrss; /* integral shared memory size */ 67170174Sjeff long ru_idrss; /* integral unshared data " */ 68170174Sjeff long ru_isrss; /* integral unshared stack " */ 69170174Sjeff long ru_minflt; /* page reclaims */ 70170174Sjeff long ru_majflt; /* page faults */ 71170174Sjeff long ru_nswap; /* swaps */ 72170174Sjeff long ru_inblock; /* block input operations */ 73170174Sjeff long ru_oublock; /* block output operations */ 74170174Sjeff long ru_msgsnd; /* messages sent */ 75170174Sjeff long ru_msgrcv; /* messages received */ 76170174Sjeff long ru_nsignals; /* signals received */ 77170174Sjeff long ru_nvcsw; /* voluntary context switches */ 78170174Sjeff long ru_nivcsw; /* involuntary " */ 791541Srgrimes#define ru_last ru_nivcsw 801541Srgrimes}; 811541Srgrimes 82242958Skib#if __BSD_VISIBLE 83242958Skibstruct __wrusage { 84242958Skib struct rusage wru_self; 85242958Skib struct rusage wru_children; 86242958Skib}; 87242958Skib#endif 88242958Skib 891541Srgrimes/* 901541Srgrimes * Resource limits 911541Srgrimes */ 92152527Sjhb#define RLIMIT_CPU 0 /* maximum cpu time in seconds */ 931541Srgrimes#define RLIMIT_FSIZE 1 /* maximum file size */ 941541Srgrimes#define RLIMIT_DATA 2 /* data size */ 951541Srgrimes#define RLIMIT_STACK 3 /* stack size */ 961541Srgrimes#define RLIMIT_CORE 4 /* core file size */ 971541Srgrimes#define RLIMIT_RSS 5 /* resident set size */ 981541Srgrimes#define RLIMIT_MEMLOCK 6 /* locked-in-memory address space */ 991541Srgrimes#define RLIMIT_NPROC 7 /* number of processes */ 1001541Srgrimes#define RLIMIT_NOFILE 8 /* number of open files */ 10152070Sgreen#define RLIMIT_SBSIZE 9 /* maximum size of all socket buffers */ 102210220Strasz#define RLIMIT_VMEM 10 /* virtual process size (incl. mmap) */ 103130435Sdas#define RLIMIT_AS RLIMIT_VMEM /* standard name for RLIMIT_VMEM */ 104181905Sed#define RLIMIT_NPTS 11 /* pseudo-terminals */ 105194766Skib#define RLIMIT_SWAP 12 /* swap used */ 1061541Srgrimes 107194766Skib#define RLIM_NLIMITS 13 /* number of resource limits */ 1081541Srgrimes 109137423Sdes#define RLIM_INFINITY ((rlim_t)(((uint64_t)1 << 63) - 1)) 110130435Sdas/* XXX Missing: RLIM_SAVED_MAX, RLIM_SAVED_CUR */ 1115767Sbde 11246201Sphk 11346201Sphk/* 11446201Sphk * Resource limit string identifiers 11546201Sphk */ 11646201Sphk 11746201Sphk#ifdef _RLIMIT_IDENT 118227954Strocinystatic const char *rlimit_ident[RLIM_NLIMITS] = { 11946201Sphk "cpu", 12046201Sphk "fsize", 12146201Sphk "data", 12246201Sphk "stack", 12346201Sphk "core", 12446201Sphk "rss", 12546201Sphk "memlock", 12646201Sphk "nproc", 12746201Sphk "nofile", 12852070Sgreen "sbsize", 12998833Sdillon "vmem", 130185940Sed "npts", 131194766Skib "swap", 13246201Sphk}; 13346201Sphk#endif 13446201Sphk 135130435Sdas#ifndef _RLIM_T_DECLARED 136130435Sdastypedef __rlim_t rlim_t; 137130435Sdas#define _RLIM_T_DECLARED 138130435Sdas#endif 1391541Srgrimes 1401541Srgrimesstruct rlimit { 14121381Sache rlim_t rlim_cur; /* current (soft) limit */ 14221381Sache rlim_t rlim_max; /* maximum value for rlim_cur */ 1431541Srgrimes}; 1441541Srgrimes 145130435Sdas#if __BSD_VISIBLE 146130435Sdas 147130435Sdasstruct orlimit { 148130435Sdas __int32_t rlim_cur; /* current (soft) limit */ 149130435Sdas __int32_t rlim_max; /* maximum value for rlim_cur */ 150130435Sdas}; 151130435Sdas 1521541Srgrimesstruct loadavg { 153130435Sdas __fixpt_t ldavg[3]; 154130435Sdas long fscale; 1551541Srgrimes}; 1561541Srgrimes 157110999Sphk#define CP_USER 0 158110999Sphk#define CP_NICE 1 159110999Sphk#define CP_SYS 2 160110999Sphk#define CP_INTR 3 161110999Sphk#define CP_IDLE 4 162110999Sphk#define CPUSTATES 5 163110999Sphk 164130435Sdas#endif /* __BSD_VISIBLE */ 165130435Sdas 16655205Speter#ifdef _KERNEL 167139739Sjhb 1681541Srgrimesextern struct loadavg averunnable; 169174070Spetervoid read_cpu_time(long *cp_time); /* Writes array of CPUSTATES */ 1701541Srgrimes 1711541Srgrimes#else 1721541Srgrimes 1731541Srgrimes__BEGIN_DECLS 174130435Sdas/* XXX 2nd arg to [gs]etpriority() should be an id_t */ 17592719Salfredint getpriority(int, int); 17692719Salfredint getrlimit(int, struct rlimit *); 17792719Salfredint getrusage(int, struct rusage *); 17892719Salfredint setpriority(int, int, int); 17992719Salfredint setrlimit(int, const struct rlimit *); 1801541Srgrimes__END_DECLS 1811541Srgrimes 18255205Speter#endif /* _KERNEL */ 1831541Srgrimes#endif /* !_SYS_RESOURCE_H_ */ 184