resourcevar.h revision 69206
118099Spst/*
269626Sru * Copyright (c) 1991, 1993
369626Sru *	The Regents of the University of California.  All rights reserved.
469626Sru *
569626Sru * Redistribution and use in source and binary forms, with or without
669626Sru * modification, are permitted provided that the following conditions
769626Sru * are met:
818099Spst * 1. Redistributions of source code must retain the above copyright
918099Spst *    notice, this list of conditions and the following disclaimer.
1018099Spst * 2. Redistributions in binary form must reproduce the above copyright
1118099Spst *    notice, this list of conditions and the following disclaimer in the
12151497Sru *    documentation and/or other materials provided with the distribution.
1318099Spst * 3. All advertising materials mentioning features or use of this software
1418099Spst *    must display the following acknowledgement:
1518099Spst *	This product includes software developed by the University of
1618099Spst *	California, Berkeley and its contributors.
1718099Spst * 4. Neither the name of the University nor the names of its contributors
1818099Spst *    may be used to endorse or promote products derived from this software
1918099Spst *    without specific prior written permission.
2018099Spst *
2118099Spst * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2218099Spst * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2318099Spst * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2418099Spst * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2569626Sru * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2669626Sru * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27104862Sru * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 *	@(#)resourcevar.h	8.4 (Berkeley) 1/9/95
34 * $FreeBSD: head/sys/sys/resourcevar.h 69206 2000-11-26 12:08:17Z alfred $
35 */
36
37#ifndef	_SYS_RESOURCEVAR_H_
38#define	_SYS_RESOURCEVAR_H_
39
40#include <sys/resource.h>
41#include <sys/queue.h>
42#include <sys/mutex.h>	/* XXX */
43
44/*
45 * Kernel per-process accounting / statistics
46 * (not necessarily resident except when running).
47 */
48struct pstats {
49#define	pstat_startzero	p_ru
50	struct	rusage p_ru;		/* stats for this proc */
51	struct	rusage p_cru;		/* sum of stats for reaped children */
52#define	pstat_endzero	pstat_startcopy
53
54#define	pstat_startcopy	p_timer
55	struct	itimerval p_timer[3];	/* virtual-time timers */
56
57	struct uprof {			/* profile arguments */
58		caddr_t	pr_base;	/* buffer base */
59		u_long	pr_size;	/* buffer size */
60		u_long	pr_off;		/* pc offset */
61		u_long	pr_scale;	/* pc scaling */
62		u_long	pr_addr;	/* temp storage for addr until AST */
63		u_long	pr_ticks;	/* temp storage for ticks until AST */
64	} p_prof;
65#define	pstat_endcopy	p_start
66	struct	timeval p_start;	/* starting time */
67};
68
69/*
70 * Kernel shareable process resource limits.  Because this structure
71 * is moderately large but changes infrequently, it is normally
72 * shared copy-on-write after forks.  If a group of processes
73 * ("threads") share modifications, the PL_SHAREMOD flag is set,
74 * and a copy must be made for the child of a new fork that isn't
75 * sharing modifications to the limits.
76 */
77struct plimit {
78	struct	rlimit pl_rlimit[RLIM_NLIMITS];
79#define	PL_SHAREMOD	0x01		/* modifications are shared */
80	int	p_lflags;
81	int	p_refcnt;		/* number of references */
82	rlim_t	p_cpulimit;		/* current cpu limit in usec */
83};
84
85/*
86 * Per uid resource consumption
87 */
88struct uidinfo {
89	LIST_ENTRY(uidinfo) ui_hash;
90	rlim_t	ui_sbsize;		/* socket buffer space consumed */
91	long	ui_proccnt;		/* number of processes */
92	uid_t	ui_uid;			/* uid */
93	u_short	ui_ref;			/* reference count */
94	struct mtx	ui_mtx;		/* protect counts */
95};
96
97#ifdef _KERNEL
98#define uihold(uip)	\
99	do {						\
100		mtx_enter(&(uip)->ui_mtx, MTX_DEF);	\
101		(uip)->ui_ref++;			\
102		mtx_exit(&(uip)->ui_mtx, MTX_DEF);	\
103	} while(0)
104
105struct proc;
106
107void	 addupc_intr __P((struct proc *p, u_long pc, u_int ticks));
108void	 addupc_task __P((struct proc *p, u_long pc, u_int ticks));
109void	 calcru __P((struct proc *p, struct timeval *up, struct timeval *sp,
110	    struct timeval *ip));
111int	 chgproccnt __P((struct uidinfo *uip, int diff, int max));
112int	 chgsbsize __P((struct uidinfo *uip, u_long *hiwat, u_long to,
113	    rlim_t max));
114int	 fuswintr __P((void *base));
115struct plimit
116	*limcopy __P((struct plimit *lim));
117void	 ruadd __P((struct rusage *ru, struct rusage *ru2));
118int	 suswintr __P((void *base, int word));
119struct uidinfo
120	*uifind __P((uid_t uid));
121void	 uifree __P((struct uidinfo *uip));
122void	uihashinit __P((void));
123#endif
124
125#endif	/* !_SYS_RESOURCEVAR_H_ */
126