1 /*	$OpenBSD: resourcevar.h,v 1.7 2003/06/02 23:28:21 millert Exp $	*/
2 /*	$NetBSD: resourcevar.h,v 1.12 1995/11/22 23:01:53 cgd Exp $	*/
3 
4 /*
5  * Copyright (c) 1991, 1993
6  *	The Regents of the University of California.  All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. Neither the name of the University nor the names of its contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  *
32  *	@(#)resourcevar.h	8.3 (Berkeley) 2/22/94
33  */
34 
35 #ifndef	_SYS_RESOURCEVAR_H_
36 #define	_SYS_RESOURCEVAR_H_
37 
38 /*
39  * Kernel per-process accounting / statistics
40  * (not necessarily resident except when running).
41  */
42 struct pstats {
43 #define	pstat_startzero	p_ru
44 	struct	rusage p_ru;		/* stats for this proc */
45 	struct	rusage p_cru;		/* sum of stats for reaped children */
46 #define	pstat_endzero	pstat_startcopy
47 
48 #define	pstat_startcopy	p_timer
49 	struct	itimerval p_timer[3];	/* virtual-time timers */
50 
51 	struct uprof {			/* profile arguments */
52 		caddr_t	pr_base;	/* buffer base */
53 		size_t  pr_size;	/* buffer size */
54 		u_long	pr_off;		/* pc offset */
55 		u_int   pr_scale;	/* pc scaling */
56 		u_long	pr_addr;	/* temp storage for addr until AST */
57 	} p_prof;
58 #define	pstat_endcopy	p_start
59 	struct	timeval p_start;	/* starting time */
60 };
61 
62 /*
63  * Kernel shareable process resource limits.  Because this structure
64  * is moderately large but changes infrequently, it is normally
65  * shared copy-on-write after forks.  If a group of processes
66  * ("threads") share modifications, the PL_SHAREMOD flag is set,
67  * and a copy must be made for the child of a new fork that isn't
68  * sharing modifications to the limits.
69  */
70 struct plimit {
71 	struct	rlimit pl_rlimit[RLIM_NLIMITS];
72 #define	PL_SHAREMOD	0x01		/* modifications are shared */
73 	int	p_lflags;
74 	int	p_refcnt;		/* number of references */
75 };
76 
77 /* add user profiling from AST */
78 #define	ADDUPROF(p) addupc_task((p), (p)->p_stats->p_prof.pr_addr, 1)
79 
80 #ifdef _KERNEL
81 void	 addupc_intr(struct proc *p, u_long pc);
82 void	 addupc_task(struct proc *p, u_long pc, u_int ticks);
83 void	 calcru(struct proc *p, struct timeval *up, struct timeval *sp,
84 	    struct timeval *ip);
85 struct plimit *limcopy(struct plimit *lim);
86 void	limfree(struct plimit *);
87 
88 void	 ruadd(struct rusage *ru, struct rusage *ru2);
89 #endif
90 #endif	/* !_SYS_RESOURCEVAR_H_ */
91