resource.h revision 194766
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: head/sys/sys/resource.h 194766 2009-06-23 20:45:22Z kib $
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
591541Srgrimes
6083045Sobrienstruct rusage {
61170174Sjeff	struct timeval ru_utime;	/* user time used */
62170174Sjeff	struct timeval ru_stime;	/* system time used */
63170174Sjeff	long	ru_maxrss;		/* max resident set size */
641541Srgrimes#define	ru_first	ru_ixrss
65170174Sjeff	long	ru_ixrss;		/* integral shared memory size */
66170174Sjeff	long	ru_idrss;		/* integral unshared data " */
67170174Sjeff	long	ru_isrss;		/* integral unshared stack " */
68170174Sjeff	long	ru_minflt;		/* page reclaims */
69170174Sjeff	long	ru_majflt;		/* page faults */
70170174Sjeff	long	ru_nswap;		/* swaps */
71170174Sjeff	long	ru_inblock;		/* block input operations */
72170174Sjeff	long	ru_oublock;		/* block output operations */
73170174Sjeff	long	ru_msgsnd;		/* messages sent */
74170174Sjeff	long	ru_msgrcv;		/* messages received */
75170174Sjeff	long	ru_nsignals;		/* signals received */
76170174Sjeff	long	ru_nvcsw;		/* voluntary context switches */
77170174Sjeff	long	ru_nivcsw;		/* involuntary " */
781541Srgrimes#define	ru_last		ru_nivcsw
791541Srgrimes};
801541Srgrimes
811541Srgrimes/*
821541Srgrimes * Resource limits
831541Srgrimes */
84152527Sjhb#define	RLIMIT_CPU	0		/* maximum cpu time in seconds */
851541Srgrimes#define	RLIMIT_FSIZE	1		/* maximum file size */
861541Srgrimes#define	RLIMIT_DATA	2		/* data size */
871541Srgrimes#define	RLIMIT_STACK	3		/* stack size */
881541Srgrimes#define	RLIMIT_CORE	4		/* core file size */
891541Srgrimes#define	RLIMIT_RSS	5		/* resident set size */
901541Srgrimes#define	RLIMIT_MEMLOCK	6		/* locked-in-memory address space */
911541Srgrimes#define	RLIMIT_NPROC	7		/* number of processes */
921541Srgrimes#define	RLIMIT_NOFILE	8		/* number of open files */
9352070Sgreen#define	RLIMIT_SBSIZE	9		/* maximum size of all socket buffers */
9498833Sdillon#define RLIMIT_VMEM	10		/* virtual process size (inclusive of mmap) */
95130435Sdas#define	RLIMIT_AS	RLIMIT_VMEM	/* standard name for RLIMIT_VMEM */
96181905Sed#define	RLIMIT_NPTS	11		/* pseudo-terminals */
97194766Skib#define	RLIMIT_SWAP	12		/* swap used */
981541Srgrimes
99194766Skib#define	RLIM_NLIMITS	13		/* number of resource limits */
1001541Srgrimes
101137423Sdes#define	RLIM_INFINITY	((rlim_t)(((uint64_t)1 << 63) - 1))
102130435Sdas/* XXX Missing: RLIM_SAVED_MAX, RLIM_SAVED_CUR */
1035767Sbde
10446201Sphk
10546201Sphk/*
10646201Sphk * Resource limit string identifiers
10746201Sphk */
10846201Sphk
10946201Sphk#ifdef _RLIMIT_IDENT
110185940Sedstatic char *rlimit_ident[RLIM_NLIMITS] = {
11146201Sphk	"cpu",
11246201Sphk	"fsize",
11346201Sphk	"data",
11446201Sphk	"stack",
11546201Sphk	"core",
11646201Sphk	"rss",
11746201Sphk	"memlock",
11846201Sphk	"nproc",
11946201Sphk	"nofile",
12052070Sgreen	"sbsize",
12198833Sdillon	"vmem",
122185940Sed	"npts",
123194766Skib	"swap",
12446201Sphk};
12546201Sphk#endif
12646201Sphk
127130435Sdas#ifndef _RLIM_T_DECLARED
128130435Sdastypedef	__rlim_t	rlim_t;
129130435Sdas#define	_RLIM_T_DECLARED
130130435Sdas#endif
1311541Srgrimes
1321541Srgrimesstruct rlimit {
13321381Sache	rlim_t	rlim_cur;		/* current (soft) limit */
13421381Sache	rlim_t	rlim_max;		/* maximum value for rlim_cur */
1351541Srgrimes};
1361541Srgrimes
137130435Sdas#if __BSD_VISIBLE
138130435Sdas
139130435Sdasstruct orlimit {
140130435Sdas	__int32_t	rlim_cur;	/* current (soft) limit */
141130435Sdas	__int32_t	rlim_max;	/* maximum value for rlim_cur */
142130435Sdas};
143130435Sdas
1441541Srgrimesstruct loadavg {
145130435Sdas	__fixpt_t	ldavg[3];
146130435Sdas	long		fscale;
1471541Srgrimes};
1481541Srgrimes
149110999Sphk#define	CP_USER		0
150110999Sphk#define	CP_NICE		1
151110999Sphk#define	CP_SYS		2
152110999Sphk#define	CP_INTR		3
153110999Sphk#define	CP_IDLE		4
154110999Sphk#define	CPUSTATES	5
155110999Sphk
156130435Sdas#endif	/* __BSD_VISIBLE */
157130435Sdas
15855205Speter#ifdef _KERNEL
159139739Sjhb
1601541Srgrimesextern struct loadavg averunnable;
161174070Spetervoid	read_cpu_time(long *cp_time);	/* Writes array of CPUSTATES */
1621541Srgrimes
1631541Srgrimes#else
1641541Srgrimes
1651541Srgrimes__BEGIN_DECLS
166130435Sdas/* XXX 2nd arg to [gs]etpriority() should be an id_t */
16792719Salfredint	getpriority(int, int);
16892719Salfredint	getrlimit(int, struct rlimit *);
16992719Salfredint	getrusage(int, struct rusage *);
17092719Salfredint	setpriority(int, int, int);
17192719Salfredint	setrlimit(int, const struct rlimit *);
1721541Srgrimes__END_DECLS
1731541Srgrimes
17455205Speter#endif	/* _KERNEL */
1751541Srgrimes#endif	/* !_SYS_RESOURCE_H_ */
176