xref: /illumos-gate/usr/src/uts/common/sys/project.h (revision ff19e029)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
23  */
24 
25 #ifndef	_SYS_PROJECT_H
26 #define	_SYS_PROJECT_H
27 
28 #ifdef	__cplusplus
29 extern "C" {
30 #endif
31 
32 
33 #include <sys/kstat.h>
34 #include <sys/types.h>
35 #include <sys/mutex.h>
36 #include <sys/rctl.h>
37 #include <sys/ipc_rctl.h>
38 #include <sys/zone.h>
39 
40 typedef struct kproject_kstat {
41 	kstat_named_t kpk_zonename;
42 	kstat_named_t kpk_usage;
43 	kstat_named_t kpk_value;
44 } kproject_kstat_t;
45 
46 typedef struct kproject_data {		/* Datum protected by: */
47 	rctl_qty_t	kpd_shmmax;	/* shm's ipcs_lock */
48 	ipc_rqty_t	kpd_ipc;	/* shm|sem|msg's ipcs lock */
49 	rctl_qty_t	kpd_locked_mem;	 /* zone_rctl_lock */
50 	rctl_qty_t	kpd_locked_mem_ctl; /* kpj_rctls->rcs_lock */
51 	rctl_qty_t	kpd_contract;	/* contract_lock */
52 	kmutex_t	kpd_crypto_lock;
53 	rctl_qty_t	kpd_crypto_mem;	/* kpd_crypto_lock above */
54 	rctl_qty_t	kpd_crypto_mem_ctl; /* kpj_rctls->rcs_lock */
55 	kstat_t		*kpd_lockedmem_kstat; /* locked memory kstat */
56 	kstat_t		*kpd_nprocs_kstat;
57 } kproject_data_t;
58 
59 struct cpucap;
60 
61 /*
62  * The first two fields of this structure must not be reordered.
63  */
64 typedef struct kproject {
65 	projid_t 	kpj_id;		/* project ID		*/
66 	zoneid_t	kpj_zoneid;	/* zone ID		*/
67 	struct zone	*kpj_zone;	/* zone pointer		*/
68 	uint_t		kpj_count;	/* reference counter	*/
69 	uint32_t	kpj_shares;	/* number of shares	*/
70 	rctl_set_t	*kpj_rctls;	/* resource control set */
71 	struct kproject	*kpj_prev;	/* previous project	*/
72 	struct kproject	*kpj_next;	/* next project		*/
73 	kproject_data_t	kpj_data;	/* subsystem-specfic data */
74 	kmutex_t	kpj_poolbind;	/* synchronization with pools	*/
75 	rctl_qty_t	kpj_nlwps;	/* protected by project's zone's */
76 					/* zone_nlwps_lock */
77 	rctl_qty_t	kpj_nlwps_ctl;	/* protected by kpj_rctls->rcs_lock */
78 	rctl_qty_t	kpj_ntasks;	/* protected by project's zone's */
79 					/* zone_nlwps_lock */
80 	rctl_qty_t	kpj_ntasks_ctl;	/* protected by kpj_rctls->rcs_lock */
81 	struct cpucap	*kpj_cpucap;	/* CPU cap data			*/
82 	struct klpd_reg	*kpj_klpd;	/* our extended policy */
83 					/* protected by klpd_mutex */
84 	rctl_qty_t	kpj_nprocs;	/* protected by project's zone's */
85 					/* zone_nlwps_lock */
86 	rctl_qty_t	kpj_nprocs_ctl;	/* protected by kpj_rctls->rcs_lock */
87 } kproject_t;
88 
89 #ifdef _KERNEL
90 
91 /*
92  * Flags for project_hold_by_id()
93  */
94 #define	PROJECT_HOLD_FIND	1
95 #define	PROJECT_HOLD_INSERT	2
96 
97 void project_init(void);
98 kproject_t *project_hold(kproject_t *);
99 kproject_t *project_hold_by_id(projid_t, struct zone *, int);
100 void project_rele(kproject_t *);
101 int project_walk_all(zoneid_t, int (*)(kproject_t *, void *), void *);
102 projid_t curprojid(void);
103 
104 extern kproject_t *proj0p;
105 extern rctl_hndl_t rc_project_nlwps;
106 extern rctl_hndl_t rc_project_nprocs;
107 extern rctl_hndl_t rc_project_ntasks;
108 extern rctl_hndl_t rc_project_locked_mem;
109 extern rctl_hndl_t rc_project_crypto_mem;
110 #endif /* _KERNEL */
111 
112 #ifdef	__cplusplus
113 }
114 #endif
115 
116 #endif	/* _SYS_PROJECT_H */
117