xref: /illumos-gate/usr/src/uts/common/sys/task.h (revision ff19e029)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5532877c4Srd  * Common Development and Distribution License (the "License").
6532877c4Srd  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*ff19e029SMenno Lageman  * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
237c478bd9Sstevel@tonic-gate  */
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate #ifndef	_SYS_TASK_H
267c478bd9Sstevel@tonic-gate #define	_SYS_TASK_H
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
297c478bd9Sstevel@tonic-gate extern "C" {
307c478bd9Sstevel@tonic-gate #endif
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include <sys/param.h>
337c478bd9Sstevel@tonic-gate #include <sys/types.h>
347c478bd9Sstevel@tonic-gate #include <sys/rctl.h>
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #define	TASK_NORMAL	0x0	/* task may create tasks via settaskid() */
377c478bd9Sstevel@tonic-gate #define	TASK_FINAL	0x1	/* task finalized, settaskid() will fail */
38532877c4Srd #define	TASK_MASK	0x1	/* task flags mask */
39532877c4Srd 
40532877c4Srd #define	TASK_PROJ_PURGE	0x100000	/* purge project.* rctl entities */
41532877c4Srd #define	TASK_PROJ_MASK	0x100000
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate #ifdef _KERNEL
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate #include <sys/id_space.h>
467c478bd9Sstevel@tonic-gate #include <sys/exacct_impl.h>
477c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate struct proc;
507c478bd9Sstevel@tonic-gate struct zone;
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate typedef struct task {
537c478bd9Sstevel@tonic-gate 	taskid_t	tk_tkid;	/* task id			*/
547c478bd9Sstevel@tonic-gate 	uint_t		tk_flags;	/* task properties		*/
557c478bd9Sstevel@tonic-gate 	struct kproject	*tk_proj;	/* project membership		*/
567c478bd9Sstevel@tonic-gate 	uint_t		tk_hold_count;	/* number of members/observers	*/
577c478bd9Sstevel@tonic-gate 	struct proc	*tk_memb_list;	/* pointer to the first process */
587c478bd9Sstevel@tonic-gate 					/* in a doubly linked list of	*/
597c478bd9Sstevel@tonic-gate 					/* task members			*/
607c478bd9Sstevel@tonic-gate 	kmutex_t	tk_usage_lock;	/* lock to protect tk_*usage	*/
617c478bd9Sstevel@tonic-gate 	task_usage_t	*tk_usage;	/* total task resource usage	*/
627c478bd9Sstevel@tonic-gate 	task_usage_t	*tk_prevusage;	/* previous interval usage	*/
637c478bd9Sstevel@tonic-gate 	task_usage_t	*tk_zoneusage;	/* previous interval usage in zone */
647c478bd9Sstevel@tonic-gate 	rctl_set_t	*tk_rctls;	/* task's resource controls	*/
657c478bd9Sstevel@tonic-gate 	rctl_qty_t	tk_nlwps;	/* protected by			*/
667c478bd9Sstevel@tonic-gate 					/* tk_zone->zone_nlwps_lock	*/
677c478bd9Sstevel@tonic-gate 	rctl_qty_t	tk_nlwps_ctl;	/* protected by tk_rctls->rcs_lock */
687c478bd9Sstevel@tonic-gate 	rctl_qty_t	tk_cpu_time;	/* accumulated CPU seconds	*/
697c478bd9Sstevel@tonic-gate 	struct zone	*tk_zone;	/* zone task belongs to		*/
707eceb558Srh 	task_usage_t	*tk_inherited;	/* task resource usage		*/
717eceb558Srh 					/* inherited with the first	*/
727eceb558Srh 					/* member process		*/
732850d85bSmv 	rctl_qty_t	tk_cpu_ticks;	/* accumulated CPU ticks	*/
742850d85bSmv 	kmutex_t	tk_cpu_time_lock; /* accumulated CPU seconds lock */
75*ff19e029SMenno Lageman 	rctl_qty_t	tk_nprocs;	/* protected by			*/
76*ff19e029SMenno Lageman 					/* tk_zone->zone_nlwps_lock	*/
77*ff19e029SMenno Lageman 	rctl_qty_t	tk_nprocs_ctl;	/* protected by tk_rctls->rcs_lock */
78*ff19e029SMenno Lageman 	kstat_t		*tk_nprocs_kstat; /* max-processes rctl kstat   */
79*ff19e029SMenno Lageman 	struct task	*tk_commit_next;  /* next task on task commit list */
807c478bd9Sstevel@tonic-gate } task_t;
817c478bd9Sstevel@tonic-gate 
82*ff19e029SMenno Lageman typedef struct task_kstat {
83*ff19e029SMenno Lageman 	kstat_named_t	ktk_zonename;
84*ff19e029SMenno Lageman 	kstat_named_t	ktk_usage;
85*ff19e029SMenno Lageman 	kstat_named_t	ktk_value;
86*ff19e029SMenno Lageman } task_kstat_t;
87*ff19e029SMenno Lageman 
887c478bd9Sstevel@tonic-gate extern task_t *task0p;
897c478bd9Sstevel@tonic-gate extern rctl_hndl_t rc_task_lwps;
90*ff19e029SMenno Lageman extern rctl_hndl_t rc_task_nprocs;
917c478bd9Sstevel@tonic-gate extern rctl_hndl_t rc_task_cpu_time;
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate extern void task_init(void);
947c478bd9Sstevel@tonic-gate extern task_t *task_create(projid_t, struct zone *);
957c478bd9Sstevel@tonic-gate extern void task_begin(task_t *, struct proc *);
967c478bd9Sstevel@tonic-gate extern void task_attach(task_t *, struct proc *);
977c478bd9Sstevel@tonic-gate extern void task_change(task_t *, struct proc *);
987c478bd9Sstevel@tonic-gate extern void task_detach(struct proc *);
997c478bd9Sstevel@tonic-gate extern task_t *task_join(task_t *, uint_t);
1007c478bd9Sstevel@tonic-gate extern task_t *task_hold_by_id(taskid_t);
1017c478bd9Sstevel@tonic-gate extern task_t *task_hold_by_id_zone(taskid_t, zoneid_t);
1027c478bd9Sstevel@tonic-gate extern void task_rele(task_t *);
1037c478bd9Sstevel@tonic-gate extern void task_hold(task_t *);
1047c478bd9Sstevel@tonic-gate extern void task_end(task_t *);
1052850d85bSmv extern rctl_qty_t task_cpu_time_incr(task_t *, rctl_qty_t);
106*ff19e029SMenno Lageman extern void task_commit_thread_init(void);
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate #else /* _KERNEL */
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate struct task;
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate extern taskid_t settaskid(projid_t, uint_t);
1137c478bd9Sstevel@tonic-gate extern taskid_t gettaskid(void);
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate #endif /* _KERNEL */
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1187c478bd9Sstevel@tonic-gate }
1197c478bd9Sstevel@tonic-gate #endif
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate #endif	/* _SYS_TASK_H */
122