xref: /onnv-gate/usr/src/uts/common/sys/task.h (revision 12725:334fd88ae67c)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
53684Srd117015  * Common Development and Distribution License (the "License").
63684Srd117015  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*12725SMenno.Lageman@Sun.COM  * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
230Sstevel@tonic-gate  */
240Sstevel@tonic-gate 
250Sstevel@tonic-gate #ifndef	_SYS_TASK_H
260Sstevel@tonic-gate #define	_SYS_TASK_H
270Sstevel@tonic-gate 
280Sstevel@tonic-gate #ifdef	__cplusplus
290Sstevel@tonic-gate extern "C" {
300Sstevel@tonic-gate #endif
310Sstevel@tonic-gate 
320Sstevel@tonic-gate #include <sys/param.h>
330Sstevel@tonic-gate #include <sys/types.h>
340Sstevel@tonic-gate #include <sys/rctl.h>
350Sstevel@tonic-gate 
360Sstevel@tonic-gate #define	TASK_NORMAL	0x0	/* task may create tasks via settaskid() */
370Sstevel@tonic-gate #define	TASK_FINAL	0x1	/* task finalized, settaskid() will fail */
383684Srd117015 #define	TASK_MASK	0x1	/* task flags mask */
393684Srd117015 
403684Srd117015 #define	TASK_PROJ_PURGE	0x100000	/* purge project.* rctl entities */
413684Srd117015 #define	TASK_PROJ_MASK	0x100000
420Sstevel@tonic-gate 
430Sstevel@tonic-gate #ifdef _KERNEL
440Sstevel@tonic-gate 
450Sstevel@tonic-gate #include <sys/id_space.h>
460Sstevel@tonic-gate #include <sys/exacct_impl.h>
470Sstevel@tonic-gate #include <sys/kmem.h>
480Sstevel@tonic-gate 
490Sstevel@tonic-gate struct proc;
500Sstevel@tonic-gate struct zone;
510Sstevel@tonic-gate 
520Sstevel@tonic-gate typedef struct task {
530Sstevel@tonic-gate 	taskid_t	tk_tkid;	/* task id			*/
540Sstevel@tonic-gate 	uint_t		tk_flags;	/* task properties		*/
550Sstevel@tonic-gate 	struct kproject	*tk_proj;	/* project membership		*/
560Sstevel@tonic-gate 	uint_t		tk_hold_count;	/* number of members/observers	*/
570Sstevel@tonic-gate 	struct proc	*tk_memb_list;	/* pointer to the first process */
580Sstevel@tonic-gate 					/* in a doubly linked list of	*/
590Sstevel@tonic-gate 					/* task members			*/
600Sstevel@tonic-gate 	kmutex_t	tk_usage_lock;	/* lock to protect tk_*usage	*/
610Sstevel@tonic-gate 	task_usage_t	*tk_usage;	/* total task resource usage	*/
620Sstevel@tonic-gate 	task_usage_t	*tk_prevusage;	/* previous interval usage	*/
630Sstevel@tonic-gate 	task_usage_t	*tk_zoneusage;	/* previous interval usage in zone */
640Sstevel@tonic-gate 	rctl_set_t	*tk_rctls;	/* task's resource controls	*/
650Sstevel@tonic-gate 	rctl_qty_t	tk_nlwps;	/* protected by			*/
660Sstevel@tonic-gate 					/* tk_zone->zone_nlwps_lock	*/
670Sstevel@tonic-gate 	rctl_qty_t	tk_nlwps_ctl;	/* protected by tk_rctls->rcs_lock */
680Sstevel@tonic-gate 	rctl_qty_t	tk_cpu_time;	/* accumulated CPU seconds	*/
690Sstevel@tonic-gate 	struct zone	*tk_zone;	/* zone task belongs to		*/
704584Srh87107 	task_usage_t	*tk_inherited;	/* task resource usage		*/
714584Srh87107 					/* inherited with the first	*/
724584Srh87107 					/* member process		*/
735788Smv143129 	rctl_qty_t	tk_cpu_ticks;	/* accumulated CPU ticks	*/
745788Smv143129 	kmutex_t	tk_cpu_time_lock; /* accumulated CPU seconds lock */
75*12725SMenno.Lageman@Sun.COM 	rctl_qty_t	tk_nprocs;	/* protected by			*/
76*12725SMenno.Lageman@Sun.COM 					/* tk_zone->zone_nlwps_lock	*/
77*12725SMenno.Lageman@Sun.COM 	rctl_qty_t	tk_nprocs_ctl;	/* protected by tk_rctls->rcs_lock */
78*12725SMenno.Lageman@Sun.COM 	kstat_t		*tk_nprocs_kstat; /* max-processes rctl kstat   */
79*12725SMenno.Lageman@Sun.COM 	struct task	*tk_commit_next;  /* next task on task commit list */
800Sstevel@tonic-gate } task_t;
810Sstevel@tonic-gate 
82*12725SMenno.Lageman@Sun.COM typedef struct task_kstat {
83*12725SMenno.Lageman@Sun.COM 	kstat_named_t	ktk_zonename;
84*12725SMenno.Lageman@Sun.COM 	kstat_named_t	ktk_usage;
85*12725SMenno.Lageman@Sun.COM 	kstat_named_t	ktk_value;
86*12725SMenno.Lageman@Sun.COM } task_kstat_t;
87*12725SMenno.Lageman@Sun.COM 
880Sstevel@tonic-gate extern task_t *task0p;
890Sstevel@tonic-gate extern rctl_hndl_t rc_task_lwps;
90*12725SMenno.Lageman@Sun.COM extern rctl_hndl_t rc_task_nprocs;
910Sstevel@tonic-gate extern rctl_hndl_t rc_task_cpu_time;
920Sstevel@tonic-gate 
930Sstevel@tonic-gate extern void task_init(void);
940Sstevel@tonic-gate extern task_t *task_create(projid_t, struct zone *);
950Sstevel@tonic-gate extern void task_begin(task_t *, struct proc *);
960Sstevel@tonic-gate extern void task_attach(task_t *, struct proc *);
970Sstevel@tonic-gate extern void task_change(task_t *, struct proc *);
980Sstevel@tonic-gate extern void task_detach(struct proc *);
990Sstevel@tonic-gate extern task_t *task_join(task_t *, uint_t);
1000Sstevel@tonic-gate extern task_t *task_hold_by_id(taskid_t);
1010Sstevel@tonic-gate extern task_t *task_hold_by_id_zone(taskid_t, zoneid_t);
1020Sstevel@tonic-gate extern void task_rele(task_t *);
1030Sstevel@tonic-gate extern void task_hold(task_t *);
1040Sstevel@tonic-gate extern void task_end(task_t *);
1055788Smv143129 extern rctl_qty_t task_cpu_time_incr(task_t *, rctl_qty_t);
106*12725SMenno.Lageman@Sun.COM extern void task_commit_thread_init(void);
1070Sstevel@tonic-gate 
1080Sstevel@tonic-gate #else /* _KERNEL */
1090Sstevel@tonic-gate 
1100Sstevel@tonic-gate struct task;
1110Sstevel@tonic-gate 
1120Sstevel@tonic-gate extern taskid_t settaskid(projid_t, uint_t);
1130Sstevel@tonic-gate extern taskid_t gettaskid(void);
1140Sstevel@tonic-gate 
1150Sstevel@tonic-gate #endif /* _KERNEL */
1160Sstevel@tonic-gate 
1170Sstevel@tonic-gate #ifdef	__cplusplus
1180Sstevel@tonic-gate }
1190Sstevel@tonic-gate #endif
1200Sstevel@tonic-gate 
1210Sstevel@tonic-gate #endif	/* _SYS_TASK_H */
122