resourcevar.h revision 210226
1139825Simp/*- 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 * 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 * 2914501Shsu * @(#)resourcevar.h 8.4 (Berkeley) 1/9/95 3050477Speter * $FreeBSD: head/sys/sys/resourcevar.h 210226 2010-07-18 20:57:53Z trasz $ 311541Srgrimes */ 321541Srgrimes 331541Srgrimes#ifndef _SYS_RESOURCEVAR_H_ 341541Srgrimes#define _SYS_RESOURCEVAR_H_ 351541Srgrimes 3634924Sbde#include <sys/resource.h> 3765495Struckman#include <sys/queue.h> 3876166Smarkm#ifdef _KERNEL 3976166Smarkm#include <sys/_lock.h> 4076166Smarkm#include <sys/_mutex.h> 4176166Smarkm#endif 4234924Sbde 431541Srgrimes/* 441541Srgrimes * Kernel per-process accounting / statistics 451541Srgrimes * (not necessarily resident except when running). 46131437Sjhb * 47131437Sjhb * Locking key: 48131437Sjhb * b - created at fork, never changes 49131437Sjhb * c - locked by proc mtx 50170305Sjeff * j - locked by proc slock 51131437Sjhb * k - only accessed by curthread 521541Srgrimes */ 531541Srgrimesstruct pstats { 54170174Sjeff#define pstat_startzero p_cru 55131437Sjhb struct rusage p_cru; /* Stats for reaped children. */ 56131437Sjhb struct itimerval p_timer[3]; /* (j) Virtual-time timers. */ 571541Srgrimes#define pstat_endzero pstat_startcopy 581541Srgrimes 59121636Sjhb#define pstat_startcopy p_prof 60131437Sjhb struct uprof { /* Profile arguments. */ 61131437Sjhb caddr_t pr_base; /* (c + j) Buffer base. */ 62131437Sjhb u_long pr_size; /* (c + j) Buffer size. */ 63131437Sjhb u_long pr_off; /* (c + j) PC offset. */ 64131437Sjhb u_long pr_scale; /* (c + j) PC scaling. */ 651541Srgrimes } p_prof; 661541Srgrimes#define pstat_endcopy p_start 67131437Sjhb struct timeval p_start; /* (b) Starting time. */ 681541Srgrimes}; 691541Srgrimes 70125525Sjhb#ifdef _KERNEL 71125525Sjhb 721541Srgrimes/* 731541Srgrimes * Kernel shareable process resource limits. Because this structure 741541Srgrimes * is moderately large but changes infrequently, it is normally 75111163Stjr * shared copy-on-write after forks. 761541Srgrimes */ 771541Srgrimesstruct plimit { 781541Srgrimes struct rlimit pl_rlimit[RLIM_NLIMITS]; 79125454Sjhb int pl_refcnt; /* number of references */ 801541Srgrimes}; 811541Srgrimes 82210226Strasz/*- 83210224Strasz * Per uid resource consumption. This structure is used to track 84210224Strasz * the total resource consumption (process count, socket buffer size, 85210224Strasz * etc) for the uid and impose limits. 86133125Srwatson * 87133125Srwatson * Locking guide: 88133125Srwatson * (a) Constant from inception 89177277Spjd * (b) Lockless, updated using atomics 90133125Srwatson * (c) Locked by global uihashtbl_mtx 91194766Skib * (d) Locked by the ui_vmsize_mtx 9265495Struckman */ 9365495Struckmanstruct uidinfo { 94133125Srwatson LIST_ENTRY(uidinfo) ui_hash; /* (c) hash chain of uidinfos */ 95194766Skib struct mtx ui_vmsize_mtx; 96194766Skib vm_ooffset_t ui_vmsize; /* (d) swap reservation by uid */ 97177277Spjd long ui_sbsize; /* (b) socket buffer space consumed */ 98133125Srwatson long ui_proccnt; /* (b) number of processes */ 99181905Sed long ui_ptscnt; /* (b) number of pseudo-terminals */ 100133125Srwatson uid_t ui_uid; /* (a) uid */ 101133125Srwatson u_int ui_ref; /* (b) reference count */ 10265495Struckman}; 10365495Struckman 104194766Skib#define UIDINFO_VMSIZE_LOCK(ui) mtx_lock(&((ui)->ui_vmsize_mtx)) 105194766Skib#define UIDINFO_VMSIZE_UNLOCK(ui) mtx_unlock(&((ui)->ui_vmsize_mtx)) 106194766Skib 107125523Sjhbstruct proc; 108136152Sjhbstruct rusage_ext; 10983366Sjulianstruct thread; 11034924Sbde 111153489Sjhbvoid addupc_intr(struct thread *td, uintfptr_t pc, u_int ticks); 112153489Sjhbvoid addupc_task(struct thread *td, uintfptr_t pc, u_int ticks); 113136152Sjhbvoid calccru(struct proc *p, struct timeval *up, struct timeval *sp); 114136152Sjhbvoid calcru(struct proc *p, struct timeval *up, struct timeval *sp); 115177277Spjdint chgproccnt(struct uidinfo *uip, int diff, rlim_t maxval); 116100591Sjdpint chgsbsize(struct uidinfo *uip, u_int *hiwat, u_int to, 117132319Salfred rlim_t maxval); 118181905Sedint chgptscnt(struct uidinfo *uip, int diff, rlim_t maxval); 11992719Salfredint fuswintr(void *base); 120125495Sjhbstruct plimit 121125495Sjhb *lim_alloc(void); 122125495Sjhbvoid lim_copy(struct plimit *dst, struct plimit *src); 123125454Sjhbrlim_t lim_cur(struct proc *p, int which); 124170174Sjeffvoid lim_fork(struct proc *p1, struct proc *p2); 125125454Sjhbvoid lim_free(struct plimit *limp); 1261541Srgrimesstruct plimit 127125454Sjhb *lim_hold(struct plimit *limp); 128125495Sjhbrlim_t lim_max(struct proc *p, int which); 129125495Sjhbvoid lim_rlimit(struct proc *p, int which, struct rlimit *rlp); 130136152Sjhbvoid ruadd(struct rusage *ru, struct rusage_ext *rux, struct rusage *ru2, 131136152Sjhb struct rusage_ext *rux2); 132170472Sattiliovoid rucollect(struct rusage *ru, struct rusage *ru2); 133170174Sjeffvoid rufetch(struct proc *p, struct rusage *ru); 134170472Sattiliovoid rufetchcalc(struct proc *p, struct rusage *ru, struct timeval *up, 135170472Sattilio struct timeval *sp); 136208488Skibvoid ruxagg(struct proc *p, struct thread *td); 13792719Salfredint suswintr(void *base, int word); 13865495Struckmanstruct uidinfo 13992719Salfred *uifind(uid_t uid); 140125495Sjhbvoid uifree(struct uidinfo *uip); 141125495Sjhbvoid uihashinit(void); 14292719Salfredvoid uihold(struct uidinfo *uip); 1434470Sbde 144125495Sjhb#endif /* _KERNEL */ 145125495Sjhb#endif /* !_SYS_RESOURCEVAR_H_ */ 146