xref: /illumos-gate/usr/src/uts/common/sys/fx.h (revision 2d6eb4a5)
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
5*c97ad5cdSakolb  * Common Development and Distribution License (the "License").
6*c97ad5cdSakolb  * 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*c97ad5cdSakolb  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23*c97ad5cdSakolb  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef _SYS_FX_H
277c478bd9Sstevel@tonic-gate #define	_SYS_FX_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #include <sys/types.h>
307c478bd9Sstevel@tonic-gate #include <sys/thread.h>
317c478bd9Sstevel@tonic-gate #include <sys/ddi.h>
327c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
33*c97ad5cdSakolb #include <sys/cpucaps.h>
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
367c478bd9Sstevel@tonic-gate extern "C" {
377c478bd9Sstevel@tonic-gate #endif
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate /*
407c478bd9Sstevel@tonic-gate  * Fixed-priority dispatcher parameter table entry
417c478bd9Sstevel@tonic-gate  */
427c478bd9Sstevel@tonic-gate typedef struct fxdpent {
437c478bd9Sstevel@tonic-gate 	pri_t	fx_globpri;	/* global (class independent) priority */
447c478bd9Sstevel@tonic-gate 	int	fx_quantum;	/* time quantum given to procs at this level */
457c478bd9Sstevel@tonic-gate } fxdpent_t;
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate #ifdef _KERNEL
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate typedef uintptr_t fx_cookie_t;	/* handle for callback supplied storage */
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate /*
527c478bd9Sstevel@tonic-gate  * callbacks supplied by custom scheduler. In general, a change to quantum
537c478bd9Sstevel@tonic-gate  * and/or priority when returning from a callback has immediate effect.
547c478bd9Sstevel@tonic-gate  *
557c478bd9Sstevel@tonic-gate  * fx_exit - called when a thread exits. This also needs to free any storage
567c478bd9Sstevel@tonic-gate  *	for the fx_cookie_t.
577c478bd9Sstevel@tonic-gate  *
587c478bd9Sstevel@tonic-gate  * fx_callb_tick - called at every clock tick attributed to this thread
597c478bd9Sstevel@tonic-gate  *
607c478bd9Sstevel@tonic-gate  * fx_callb_preempt - called when a thread is being preempted or yielding
617c478bd9Sstevel@tonic-gate  *
627c478bd9Sstevel@tonic-gate  * fx_callb_stop/fx_callb_sleep - called when a thread stops running
637c478bd9Sstevel@tonic-gate  *
647c478bd9Sstevel@tonic-gate  * fx_callb_wakeup - called when a thread is again runnable
657c478bd9Sstevel@tonic-gate  */
667c478bd9Sstevel@tonic-gate typedef struct fx_callbacks {
677c478bd9Sstevel@tonic-gate 	int fx_callb_version;
687c478bd9Sstevel@tonic-gate 	void (*fx_callb_exit)(fx_cookie_t);
697c478bd9Sstevel@tonic-gate 	void (*fx_callb_tick)(fx_cookie_t, clock_t *, pri_t *);
707c478bd9Sstevel@tonic-gate 	void (*fx_callb_preempt)(fx_cookie_t, clock_t *, pri_t *);
717c478bd9Sstevel@tonic-gate 	void (*fx_callb_stop)(fx_cookie_t);
727c478bd9Sstevel@tonic-gate 	void (*fx_callb_sleep)(fx_cookie_t);
737c478bd9Sstevel@tonic-gate 	void (*fx_callb_wakeup)(fx_cookie_t, clock_t *, pri_t *);
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate } fx_callbacks_t;
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate #define	FX_CALLB_VERSION_1	1
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate #define	FX_CALLB_REV	FX_CALLB_VERSION_1
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate #define	FX_CB_VERSION(cb)		cb->fx_callb_version
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate #define	FX_CB_EXIT(cb, c)		cb->fx_callb_exit(c)
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate #define	FX_CB_TICK(cb, c, q, p)		cb->fx_callb_tick(c, q, p)
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate #define	FX_CB_PREEMPT(cb, c, q, p)	cb->fx_callb_preempt(c, q, p)
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate #define	FX_CB_STOP(cb, c)		cb->fx_callb_stop(c)
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate #define	FX_CB_SLEEP(cb, c)		cb->fx_callb_sleep(c)
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate #define	FX_CB_WAKEUP(cb, c, q, p)	cb->fx_callb_wakeup(c, q, p)
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate /* priority setting */
977c478bd9Sstevel@tonic-gate #define	FX_CB_NOCHANGE	-32768
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate /*
1017c478bd9Sstevel@tonic-gate  * Fixed-priority class specific thread structure
1027c478bd9Sstevel@tonic-gate  */
1037c478bd9Sstevel@tonic-gate typedef struct fxproc {
1047c478bd9Sstevel@tonic-gate 	int		fx_pquantum;	/* time quantum given to this proc */
1057c478bd9Sstevel@tonic-gate 	int		fx_timeleft;	/* time remaining in procs quantum */
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate 	pri_t		fx_pri;		/* relative priority within fx class */
1087c478bd9Sstevel@tonic-gate 					/* same as user priority */
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate 	pri_t		fx_uprilim;	/* user priority limit */
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate 	char		fx_nice;	/* nice value for compatibility */
1137c478bd9Sstevel@tonic-gate 	uchar_t 	fx_flags;	/* flags defined below */
1147c478bd9Sstevel@tonic-gate 	kthread_t 	*fx_tp;		/* pointer to thread */
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate 	/* the following are used only when we have callbacks registered */
1177c478bd9Sstevel@tonic-gate 	kt_did_t	fx_ktid;
1187c478bd9Sstevel@tonic-gate 	struct fxproc 	*fx_cb_next;	/* pointer to next fxproc that */
1197c478bd9Sstevel@tonic-gate 					/* has a callback */
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate 	struct fxproc 	*fx_cb_prev;	/* pointer to previous fxproc that */
1227c478bd9Sstevel@tonic-gate 					/* has a callback */
1237c478bd9Sstevel@tonic-gate 	fx_cookie_t	fx_cookie;	/* cookie with which callback */
1247c478bd9Sstevel@tonic-gate 					/* was registered */
1257c478bd9Sstevel@tonic-gate 	fx_callbacks_t 	*fx_callback;	/* pointer to callback structure */
126*c97ad5cdSakolb 	caps_sc_t	fx_caps;	/* CPU caps specific data */
1277c478bd9Sstevel@tonic-gate } fxproc_t;
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate #define	FX_CALLB(fxpp)	fxpp->fx_callback
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate /* flags */
1347c478bd9Sstevel@tonic-gate #define	FXBACKQ	0x02	/* thread goes to back of disp q when preempted */
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate /*
1377c478bd9Sstevel@tonic-gate  * Kernel version of fixed-priority class specific parameter structure
1387c478bd9Sstevel@tonic-gate  */
1397c478bd9Sstevel@tonic-gate typedef struct	fxkparms {
1407c478bd9Sstevel@tonic-gate 	pri_t	fx_upri;
1417c478bd9Sstevel@tonic-gate 	pri_t	fx_uprilim;
1427c478bd9Sstevel@tonic-gate 	int	fx_tqntm;
1437c478bd9Sstevel@tonic-gate 	uint_t	fx_cflags;
1447c478bd9Sstevel@tonic-gate } fxkparms_t;
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate /*
1497c478bd9Sstevel@tonic-gate  * Interface for partner private code. This is not a public interface.
1507c478bd9Sstevel@tonic-gate  */
1517c478bd9Sstevel@tonic-gate extern int fx_register_callbacks(fx_callbacks_t *, fx_cookie_t, pri_t, clock_t);
1527c478bd9Sstevel@tonic-gate extern int fx_unregister_callbacks();
1537c478bd9Sstevel@tonic-gate extern int fx_modify_priority(kt_did_t, clock_t, pri_t);
1547c478bd9Sstevel@tonic-gate extern void *fx_get_mutex_cookie();
1557c478bd9Sstevel@tonic-gate extern pri_t fx_get_maxpri();
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1607c478bd9Sstevel@tonic-gate }
1617c478bd9Sstevel@tonic-gate #endif
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate #endif	/* _SYS_FX_H */
164