xref: /titanic_41/usr/src/uts/common/sys/task.h (revision f52e84dfce89ba2ea0ebb6a191b4466da3012efd)
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 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SYS_TASK_H
27 #define	_SYS_TASK_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #ifdef	__cplusplus
32 extern "C" {
33 #endif
34 
35 #include <sys/param.h>
36 #include <sys/types.h>
37 #include <sys/rctl.h>
38 
39 #define	TASK_NORMAL	0x0	/* task may create tasks via settaskid() */
40 #define	TASK_FINAL	0x1	/* task finalized, settaskid() will fail */
41 #define	TASK_MASK	0x1	/* task flags mask */
42 
43 #define	TASK_PROJ_PURGE	0x100000	/* purge project.* rctl entities */
44 #define	TASK_PROJ_MASK	0x100000
45 
46 #ifdef _KERNEL
47 
48 #include <sys/id_space.h>
49 #include <sys/exacct_impl.h>
50 #include <sys/kmem.h>
51 
52 struct proc;
53 struct zone;
54 
55 typedef struct task {
56 	taskid_t	tk_tkid;	/* task id			*/
57 	uint_t		tk_flags;	/* task properties		*/
58 	struct kproject	*tk_proj;	/* project membership		*/
59 	uint_t		tk_hold_count;	/* number of members/observers	*/
60 	struct proc	*tk_memb_list;	/* pointer to the first process */
61 					/* in a doubly linked list of	*/
62 					/* task members			*/
63 	kmutex_t	tk_usage_lock;	/* lock to protect tk_*usage	*/
64 	task_usage_t	*tk_usage;	/* total task resource usage	*/
65 	task_usage_t	*tk_prevusage;	/* previous interval usage	*/
66 	task_usage_t	*tk_zoneusage;	/* previous interval usage in zone */
67 	rctl_set_t	*tk_rctls;	/* task's resource controls	*/
68 	rctl_qty_t	tk_nlwps;	/* protected by			*/
69 					/* tk_zone->zone_nlwps_lock	*/
70 	rctl_qty_t	tk_nlwps_ctl;	/* protected by tk_rctls->rcs_lock */
71 	rctl_qty_t	tk_cpu_time;	/* accumulated CPU seconds	*/
72 	struct zone	*tk_zone;	/* zone task belongs to		*/
73 	task_usage_t	*tk_inherited;	/* task resource usage		*/
74 					/* inherited with the first	*/
75 					/* member process		*/
76 	rctl_qty_t	tk_cpu_ticks;	/* accumulated CPU ticks	*/
77 	kmutex_t	tk_cpu_time_lock; /* accumulated CPU seconds lock */
78 } task_t;
79 
80 extern task_t *task0p;
81 extern rctl_hndl_t rc_task_lwps;
82 extern rctl_hndl_t rc_task_cpu_time;
83 
84 extern void task_init(void);
85 extern task_t *task_create(projid_t, struct zone *);
86 extern void task_begin(task_t *, struct proc *);
87 extern void task_attach(task_t *, struct proc *);
88 extern void task_change(task_t *, struct proc *);
89 extern void task_detach(struct proc *);
90 extern task_t *task_join(task_t *, uint_t);
91 extern task_t *task_hold_by_id(taskid_t);
92 extern task_t *task_hold_by_id_zone(taskid_t, zoneid_t);
93 extern void task_rele(task_t *);
94 extern void task_hold(task_t *);
95 extern void task_end(task_t *);
96 extern rctl_qty_t task_cpu_time_incr(task_t *, rctl_qty_t);
97 
98 #else /* _KERNEL */
99 
100 struct task;
101 
102 extern taskid_t settaskid(projid_t, uint_t);
103 extern taskid_t gettaskid(void);
104 
105 #endif /* _KERNEL */
106 
107 #ifdef	__cplusplus
108 }
109 #endif
110 
111 #endif	/* _SYS_TASK_H */
112