resourcevar.h revision 100591
11541Srgrimes/*
21541Srgrimes * Copyright (c) 1991, 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 * 3. All advertising materials mentioning features or use of this software
141541Srgrimes *    must display the following acknowledgement:
151541Srgrimes *	This product includes software developed by the University of
161541Srgrimes *	California, Berkeley and its contributors.
171541Srgrimes * 4. Neither the name of the University nor the names of its contributors
181541Srgrimes *    may be used to endorse or promote products derived from this software
191541Srgrimes *    without specific prior written permission.
201541Srgrimes *
211541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
221541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
231541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
241541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
251541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
261541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
271541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
281541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
291541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
301541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
311541Srgrimes * SUCH DAMAGE.
321541Srgrimes *
3314501Shsu *	@(#)resourcevar.h	8.4 (Berkeley) 1/9/95
3450477Speter * $FreeBSD: head/sys/sys/resourcevar.h 100591 2002-07-24 03:02:43Z jdp $
351541Srgrimes */
361541Srgrimes
371541Srgrimes#ifndef	_SYS_RESOURCEVAR_H_
381541Srgrimes#define	_SYS_RESOURCEVAR_H_
391541Srgrimes
4034924Sbde#include <sys/resource.h>
4165495Struckman#include <sys/queue.h>
4276166Smarkm#ifdef _KERNEL
4376166Smarkm#include <sys/_lock.h>
4476166Smarkm#include <sys/_mutex.h>
4576166Smarkm#endif
4634924Sbde
471541Srgrimes/*
481541Srgrimes * Kernel per-process accounting / statistics
491541Srgrimes * (not necessarily resident except when running).
501541Srgrimes */
511541Srgrimesstruct pstats {
521541Srgrimes#define	pstat_startzero	p_ru
531541Srgrimes	struct	rusage p_ru;		/* stats for this proc */
541541Srgrimes	struct	rusage p_cru;		/* sum of stats for reaped children */
551541Srgrimes#define	pstat_endzero	pstat_startcopy
561541Srgrimes
571541Srgrimes#define	pstat_startcopy	p_timer
581541Srgrimes	struct	itimerval p_timer[3];	/* virtual-time timers */
591541Srgrimes
601541Srgrimes	struct uprof {			/* profile arguments */
611541Srgrimes		caddr_t	pr_base;	/* buffer base */
621541Srgrimes		u_long	pr_size;	/* buffer size */
631541Srgrimes		u_long	pr_off;		/* pc offset */
641541Srgrimes		u_long	pr_scale;	/* pc scaling */
651541Srgrimes		u_long	pr_addr;	/* temp storage for addr until AST */
6681493Sjhb		u_int	pr_ticks;	/* temp storage for ticks until AST */
671541Srgrimes	} p_prof;
681541Srgrimes#define	pstat_endcopy	p_start
691541Srgrimes	struct	timeval p_start;	/* starting time */
701541Srgrimes};
711541Srgrimes
721541Srgrimes/*
731541Srgrimes * Kernel shareable process resource limits.  Because this structure
741541Srgrimes * is moderately large but changes infrequently, it is normally
751541Srgrimes * shared copy-on-write after forks.  If a group of processes
761541Srgrimes * ("threads") share modifications, the PL_SHAREMOD flag is set,
771541Srgrimes * and a copy must be made for the child of a new fork that isn't
781541Srgrimes * sharing modifications to the limits.
791541Srgrimes */
801541Srgrimesstruct plimit {
811541Srgrimes	struct	rlimit pl_rlimit[RLIM_NLIMITS];
821541Srgrimes#define	PL_SHAREMOD	0x01		/* modifications are shared */
831541Srgrimes	int	p_lflags;
841541Srgrimes	int	p_refcnt;		/* number of references */
8536441Sphk	rlim_t	p_cpulimit;		/* current cpu limit in usec */
861541Srgrimes};
871541Srgrimes
8869403Salfred#ifdef _KERNEL
8969403Salfred
9065495Struckman/*
9165495Struckman * Per uid resource consumption
9265495Struckman */
9365495Struckmanstruct uidinfo {
9465495Struckman	LIST_ENTRY(uidinfo) ui_hash;
9565495Struckman	rlim_t	ui_sbsize;		/* socket buffer space consumed */
9665495Struckman	long	ui_proccnt;		/* number of processes */
9765495Struckman	uid_t	ui_uid;			/* uid */
9865495Struckman	u_short	ui_ref;			/* reference count */
9989594Salfred	struct mtx	*ui_mtxp;	/* protect all counts/limits */
10065495Struckman};
10165495Struckman
10291342Salfred#define	UIDINFO_LOCK(ui)	mtx_lock((ui)->ui_mtxp)
10391342Salfred#define	UIDINFO_UNLOCK(ui)	mtx_unlock((ui)->ui_mtxp)
10489594Salfred
10583366Sjulianstruct thread;
10683366Sjulianstruct kse;
10734924Sbdestruct proc;
10834924Sbde
10992719Salfredvoid	 addupc_intr(struct kse *ke, uintptr_t pc, u_int ticks);
11092719Salfredvoid	 addupc_task(struct kse *ke, uintptr_t pc, u_int ticks);
11192719Salfredvoid	 calcru(struct proc *p, struct timeval *up, struct timeval *sp,
11292719Salfred	    struct timeval *ip);
11392719Salfredint	 chgproccnt(struct uidinfo *uip, int diff, int max);
114100591Sjdpint	 chgsbsize(struct uidinfo *uip, u_int *hiwat, u_int to,
11592719Salfred	    rlim_t max);
11692719Salfredint	 fuswintr(void *base);
1171541Srgrimesstruct plimit
11892719Salfred	*limcopy(struct plimit *lim);
11992719Salfredvoid	 ruadd(struct rusage *ru, struct rusage *ru2);
12092719Salfredint	 suswintr(void *base, int word);
12165495Struckmanstruct uidinfo
12292719Salfred	*uifind(uid_t uid);
12392719Salfredvoid	 uihold(struct uidinfo *uip);
12492719Salfredvoid	 uifree(struct uidinfo *uip);
12592719Salfredvoid	uihashinit(void);
1261541Srgrimes#endif
1274470Sbde
1281541Srgrimes#endif	/* !_SYS_RESOURCEVAR_H_ */
129