summaryrefslogtreecommitdiff
path: root/usr/src/uts/common/sys/project.h
blob: 308c05044e30337f72b5507168d0073b18eb9d3d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
 */

#ifndef	_SYS_PROJECT_H
#define	_SYS_PROJECT_H

#ifdef	__cplusplus
extern "C" {
#endif


#include <sys/kstat.h>
#include <sys/types.h>
#include <sys/mutex.h>
#include <sys/rctl.h>
#include <sys/ipc_rctl.h>
#include <sys/zone.h>

typedef struct kproject_kstat {
	kstat_named_t kpk_zonename;
	kstat_named_t kpk_usage;
	kstat_named_t kpk_value;
} kproject_kstat_t;

typedef struct kproject_data {		/* Datum protected by: */
	rctl_qty_t	kpd_shmmax;	/* shm's ipcs_lock */
	ipc_rqty_t	kpd_ipc;	/* shm|sem|msg's ipcs lock */
	rctl_qty_t	kpd_locked_mem;	 /* zone_rctl_lock */
	rctl_qty_t	kpd_locked_mem_ctl; /* kpj_rctls->rcs_lock */
	rctl_qty_t	kpd_contract;	/* contract_lock */
	kmutex_t	kpd_crypto_lock;
	rctl_qty_t	kpd_crypto_mem;	/* kpd_crypto_lock above */
	rctl_qty_t	kpd_crypto_mem_ctl; /* kpj_rctls->rcs_lock */
	kstat_t		*kpd_lockedmem_kstat; /* locked memory kstat */
	kstat_t		*kpd_nprocs_kstat;
} kproject_data_t;

struct cpucap;

/*
 * The first two fields of this structure must not be reordered.
 */
typedef struct kproject {
	projid_t 	kpj_id;		/* project ID		*/
	zoneid_t	kpj_zoneid;	/* zone ID		*/
	struct zone	*kpj_zone;	/* zone pointer		*/
	uint_t		kpj_count;	/* reference counter	*/
	uint32_t	kpj_shares;	/* number of shares	*/
	rctl_set_t	*kpj_rctls;	/* resource control set */
	struct kproject	*kpj_prev;	/* previous project	*/
	struct kproject	*kpj_next;	/* next project		*/
	kproject_data_t	kpj_data;	/* subsystem-specfic data */
	kmutex_t	kpj_poolbind;	/* synchronization with pools	*/
	rctl_qty_t	kpj_nlwps;	/* protected by project's zone's */
					/* zone_nlwps_lock */
	rctl_qty_t	kpj_nlwps_ctl;	/* protected by kpj_rctls->rcs_lock */
	rctl_qty_t	kpj_ntasks;	/* protected by project's zone's */
					/* zone_nlwps_lock */
	rctl_qty_t	kpj_ntasks_ctl;	/* protected by kpj_rctls->rcs_lock */
	struct cpucap	*kpj_cpucap;	/* CPU cap data			*/
	struct klpd_reg	*kpj_klpd;	/* our extended policy */
					/* protected by klpd_mutex */
	rctl_qty_t	kpj_nprocs;	/* protected by project's zone's */
					/* zone_nlwps_lock */
	rctl_qty_t	kpj_nprocs_ctl;	/* protected by kpj_rctls->rcs_lock */
} kproject_t;

#ifdef _KERNEL

/*
 * Flags for project_hold_by_id()
 */
#define	PROJECT_HOLD_FIND	1
#define	PROJECT_HOLD_INSERT	2

void project_init(void);
kproject_t *project_hold(kproject_t *);
kproject_t *project_hold_by_id(projid_t, struct zone *, int);
void project_rele(kproject_t *);
int project_walk_all(zoneid_t, int (*)(kproject_t *, void *), void *);
projid_t curprojid(void);

extern kproject_t *proj0p;
extern rctl_hndl_t rc_project_nlwps;
extern rctl_hndl_t rc_project_nprocs;
extern rctl_hndl_t rc_project_ntasks;
extern rctl_hndl_t rc_project_locked_mem;
extern rctl_hndl_t rc_project_crypto_mem;
#endif /* _KERNEL */

#ifdef	__cplusplus
}
#endif

#endif	/* _SYS_PROJECT_H */