xref: /titanic_41/usr/src/uts/common/sys/task.h (revision 2850d85b7b93f31e578520dc3b3feb24db609c62)
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
5532877c4Srd117015  * Common Development and Distribution License (the "License").
6532877c4Srd117015  * 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*2850d85bSmv143129  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef	_SYS_TASK_H
277c478bd9Sstevel@tonic-gate #define	_SYS_TASK_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
327c478bd9Sstevel@tonic-gate extern "C" {
337c478bd9Sstevel@tonic-gate #endif
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #include <sys/param.h>
367c478bd9Sstevel@tonic-gate #include <sys/types.h>
377c478bd9Sstevel@tonic-gate #include <sys/rctl.h>
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #define	TASK_NORMAL	0x0	/* task may create tasks via settaskid() */
407c478bd9Sstevel@tonic-gate #define	TASK_FINAL	0x1	/* task finalized, settaskid() will fail */
41532877c4Srd117015 #define	TASK_MASK	0x1	/* task flags mask */
42532877c4Srd117015 
43532877c4Srd117015 #define	TASK_PROJ_PURGE	0x100000	/* purge project.* rctl entities */
44532877c4Srd117015 #define	TASK_PROJ_MASK	0x100000
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate #ifdef _KERNEL
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate #include <sys/id_space.h>
497c478bd9Sstevel@tonic-gate #include <sys/exacct_impl.h>
507c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate struct proc;
537c478bd9Sstevel@tonic-gate struct zone;
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate typedef struct task {
567c478bd9Sstevel@tonic-gate 	taskid_t	tk_tkid;	/* task id			*/
577c478bd9Sstevel@tonic-gate 	uint_t		tk_flags;	/* task properties		*/
587c478bd9Sstevel@tonic-gate 	struct kproject	*tk_proj;	/* project membership		*/
597c478bd9Sstevel@tonic-gate 	uint_t		tk_hold_count;	/* number of members/observers	*/
607c478bd9Sstevel@tonic-gate 	struct proc	*tk_memb_list;	/* pointer to the first process */
617c478bd9Sstevel@tonic-gate 					/* in a doubly linked list of	*/
627c478bd9Sstevel@tonic-gate 					/* task members			*/
637c478bd9Sstevel@tonic-gate 	kmutex_t	tk_usage_lock;	/* lock to protect tk_*usage	*/
647c478bd9Sstevel@tonic-gate 	task_usage_t	*tk_usage;	/* total task resource usage	*/
657c478bd9Sstevel@tonic-gate 	task_usage_t	*tk_prevusage;	/* previous interval usage	*/
667c478bd9Sstevel@tonic-gate 	task_usage_t	*tk_zoneusage;	/* previous interval usage in zone */
677c478bd9Sstevel@tonic-gate 	rctl_set_t	*tk_rctls;	/* task's resource controls	*/
687c478bd9Sstevel@tonic-gate 	rctl_qty_t	tk_nlwps;	/* protected by			*/
697c478bd9Sstevel@tonic-gate 					/* tk_zone->zone_nlwps_lock	*/
707c478bd9Sstevel@tonic-gate 	rctl_qty_t	tk_nlwps_ctl;	/* protected by tk_rctls->rcs_lock */
717c478bd9Sstevel@tonic-gate 	rctl_qty_t	tk_cpu_time;	/* accumulated CPU seconds	*/
727c478bd9Sstevel@tonic-gate 	struct zone	*tk_zone;	/* zone task belongs to		*/
737eceb558Srh87107 	task_usage_t	*tk_inherited;	/* task resource usage		*/
747eceb558Srh87107 					/* inherited with the first	*/
757eceb558Srh87107 					/* member process		*/
76*2850d85bSmv143129 	rctl_qty_t	tk_cpu_ticks;	/* accumulated CPU ticks	*/
77*2850d85bSmv143129 	kmutex_t	tk_cpu_time_lock; /* accumulated CPU seconds lock */
787c478bd9Sstevel@tonic-gate } task_t;
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate extern task_t *task0p;
817c478bd9Sstevel@tonic-gate extern rctl_hndl_t rc_task_lwps;
827c478bd9Sstevel@tonic-gate extern rctl_hndl_t rc_task_cpu_time;
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate extern void task_init(void);
857c478bd9Sstevel@tonic-gate extern task_t *task_create(projid_t, struct zone *);
867c478bd9Sstevel@tonic-gate extern void task_begin(task_t *, struct proc *);
877c478bd9Sstevel@tonic-gate extern void task_attach(task_t *, struct proc *);
887c478bd9Sstevel@tonic-gate extern void task_change(task_t *, struct proc *);
897c478bd9Sstevel@tonic-gate extern void task_detach(struct proc *);
907c478bd9Sstevel@tonic-gate extern task_t *task_join(task_t *, uint_t);
917c478bd9Sstevel@tonic-gate extern task_t *task_hold_by_id(taskid_t);
927c478bd9Sstevel@tonic-gate extern task_t *task_hold_by_id_zone(taskid_t, zoneid_t);
937c478bd9Sstevel@tonic-gate extern void task_rele(task_t *);
947c478bd9Sstevel@tonic-gate extern void task_hold(task_t *);
957c478bd9Sstevel@tonic-gate extern void task_end(task_t *);
96*2850d85bSmv143129 extern rctl_qty_t task_cpu_time_incr(task_t *, rctl_qty_t);
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate #else /* _KERNEL */
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate struct task;
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate extern taskid_t settaskid(projid_t, uint_t);
1037c478bd9Sstevel@tonic-gate extern taskid_t gettaskid(void);
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate #endif /* _KERNEL */
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1087c478bd9Sstevel@tonic-gate }
1097c478bd9Sstevel@tonic-gate #endif
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate #endif	/* _SYS_TASK_H */
112