resourcevar.h revision 65495
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 65495 2000-09-05 22:11:13Z truckman $
351541Srgrimes */
361541Srgrimes
371541Srgrimes#ifndef	_SYS_RESOURCEVAR_H_
381541Srgrimes#define	_SYS_RESOURCEVAR_H_
391541Srgrimes
4034924Sbde#include <sys/resource.h>
4165495Struckman#include <sys/queue.h>
4234924Sbde
431541Srgrimes/*
441541Srgrimes * Kernel per-process accounting / statistics
451541Srgrimes * (not necessarily resident except when running).
461541Srgrimes */
471541Srgrimesstruct pstats {
481541Srgrimes#define	pstat_startzero	p_ru
491541Srgrimes	struct	rusage p_ru;		/* stats for this proc */
501541Srgrimes	struct	rusage p_cru;		/* sum of stats for reaped children */
511541Srgrimes#define	pstat_endzero	pstat_startcopy
521541Srgrimes
531541Srgrimes#define	pstat_startcopy	p_timer
541541Srgrimes	struct	itimerval p_timer[3];	/* virtual-time timers */
551541Srgrimes
561541Srgrimes	struct uprof {			/* profile arguments */
571541Srgrimes		caddr_t	pr_base;	/* buffer base */
581541Srgrimes		u_long	pr_size;	/* buffer size */
591541Srgrimes		u_long	pr_off;		/* pc offset */
601541Srgrimes		u_long	pr_scale;	/* pc scaling */
611541Srgrimes		u_long	pr_addr;	/* temp storage for addr until AST */
621541Srgrimes		u_long	pr_ticks;	/* temp storage for ticks until AST */
631541Srgrimes	} p_prof;
641541Srgrimes#define	pstat_endcopy	p_start
651541Srgrimes	struct	timeval p_start;	/* starting time */
661541Srgrimes};
671541Srgrimes
681541Srgrimes/*
691541Srgrimes * Kernel shareable process resource limits.  Because this structure
701541Srgrimes * is moderately large but changes infrequently, it is normally
711541Srgrimes * shared copy-on-write after forks.  If a group of processes
721541Srgrimes * ("threads") share modifications, the PL_SHAREMOD flag is set,
731541Srgrimes * and a copy must be made for the child of a new fork that isn't
741541Srgrimes * sharing modifications to the limits.
751541Srgrimes */
761541Srgrimesstruct plimit {
771541Srgrimes	struct	rlimit pl_rlimit[RLIM_NLIMITS];
781541Srgrimes#define	PL_SHAREMOD	0x01		/* modifications are shared */
791541Srgrimes	int	p_lflags;
801541Srgrimes	int	p_refcnt;		/* number of references */
8136441Sphk	rlim_t	p_cpulimit;		/* current cpu limit in usec */
821541Srgrimes};
831541Srgrimes
8465495Struckman/*
8565495Struckman * Per uid resource consumption
8665495Struckman */
8765495Struckmanstruct uidinfo {
8865495Struckman	LIST_ENTRY(uidinfo) ui_hash;
8965495Struckman	rlim_t	ui_sbsize;		/* socket buffer space consumed */
9065495Struckman	long	ui_proccnt;		/* number of processes */
9165495Struckman	uid_t	ui_uid;			/* uid */
9265495Struckman	u_short	ui_ref;			/* reference count */
9365495Struckman};
9465495Struckman
9555205Speter#ifdef _KERNEL
9665495Struckman#define uihold(uip)	(uip)->ui_ref++
9734924Sbdestruct proc;
9834924Sbde
991541Srgrimesvoid	 addupc_intr __P((struct proc *p, u_long pc, u_int ticks));
1001541Srgrimesvoid	 addupc_task __P((struct proc *p, u_long pc, u_int ticks));
1014470Sbdevoid	 calcru __P((struct proc *p, struct timeval *up, struct timeval *sp,
10214501Shsu	    struct timeval *ip));
10365495Struckmanint	 chgproccnt __P((struct uidinfo *uip, int diff, int max));
10465495Struckmanint	 chgsbsize __P((struct uidinfo *uip, u_long *hiwat, u_long to,
10565495Struckman	    rlim_t max));
1064470Sbdeint	 fuswintr __P((void *base));
1071541Srgrimesstruct plimit
1081541Srgrimes	*limcopy __P((struct plimit *lim));
1094470Sbdevoid	 ruadd __P((struct rusage *ru, struct rusage *ru2));
1104470Sbdeint	 suswintr __P((void *base, int word));
11165495Struckmanstruct uidinfo
11265495Struckman	*uifind __P((uid_t uid));
11365495Struckmanint	 uifree __P((struct uidinfo *uip));
11465495Struckmanvoid	uihashinit __P((void));
1151541Srgrimes#endif
1164470Sbde
1171541Srgrimes#endif	/* !_SYS_RESOURCEVAR_H_ */
118