xref: /titanic_41/usr/src/uts/common/sys/task.h (revision 40cb5e5daa7b80bb70fcf8dadfb20f9281566331)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_TASK_H
28 #define	_SYS_TASK_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #include <sys/param.h>
37 #include <sys/types.h>
38 #include <sys/rctl.h>
39 
40 #define	TASK_NORMAL	0x0	/* task may create tasks via settaskid() */
41 #define	TASK_FINAL	0x1	/* task finalized, settaskid() will fail */
42 
43 #ifdef _KERNEL
44 
45 #include <sys/id_space.h>
46 #include <sys/exacct_impl.h>
47 #include <sys/kmem.h>
48 
49 struct proc;
50 struct zone;
51 
52 typedef struct task {
53 	taskid_t	tk_tkid;	/* task id			*/
54 	uint_t		tk_flags;	/* task properties		*/
55 	struct kproject	*tk_proj;	/* project membership		*/
56 	uint_t		tk_hold_count;	/* number of members/observers	*/
57 	struct proc	*tk_memb_list;	/* pointer to the first process */
58 					/* in a doubly linked list of	*/
59 					/* task members			*/
60 	kmutex_t	tk_usage_lock;	/* lock to protect tk_*usage	*/
61 	task_usage_t	*tk_usage;	/* total task resource usage	*/
62 	task_usage_t	*tk_prevusage;	/* previous interval usage	*/
63 	task_usage_t	*tk_zoneusage;	/* previous interval usage in zone */
64 	rctl_set_t	*tk_rctls;	/* task's resource controls	*/
65 	rctl_qty_t	tk_nlwps;	/* protected by			*/
66 					/* tk_zone->zone_nlwps_lock	*/
67 	rctl_qty_t	tk_nlwps_ctl;	/* protected by tk_rctls->rcs_lock */
68 	rctl_qty_t	tk_cpu_time;	/* accumulated CPU seconds	*/
69 	struct zone	*tk_zone;	/* zone task belongs to		*/
70 } task_t;
71 
72 extern task_t *task0p;
73 extern rctl_hndl_t rc_task_lwps;
74 extern rctl_hndl_t rc_task_cpu_time;
75 
76 extern void task_init(void);
77 extern task_t *task_create(projid_t, struct zone *);
78 extern void task_begin(task_t *, struct proc *);
79 extern void task_attach(task_t *, struct proc *);
80 extern void task_change(task_t *, struct proc *);
81 extern void task_detach(struct proc *);
82 extern task_t *task_join(task_t *, uint_t);
83 extern task_t *task_hold_by_id(taskid_t);
84 extern task_t *task_hold_by_id_zone(taskid_t, zoneid_t);
85 extern void task_rele(task_t *);
86 extern void task_hold(task_t *);
87 extern void task_end(task_t *);
88 
89 #else /* _KERNEL */
90 
91 struct task;
92 
93 extern taskid_t settaskid(projid_t, uint_t);
94 extern taskid_t gettaskid(void);
95 
96 #endif /* _KERNEL */
97 
98 #ifdef	__cplusplus
99 }
100 #endif
101 
102 #endif	/* _SYS_TASK_H */
103