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 2007 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #ifndef _SYS_FX_H 27 #define _SYS_FX_H 28 29 #include <sys/types.h> 30 #include <sys/thread.h> 31 #include <sys/ddi.h> 32 #include <sys/sunddi.h> 33 #include <sys/cpucaps.h> 34 35 #ifdef __cplusplus 36 extern "C" { 37 #endif 38 39 /* 40 * Fixed-priority dispatcher parameter table entry 41 */ 42 typedef struct fxdpent { 43 pri_t fx_globpri; /* global (class independent) priority */ 44 int fx_quantum; /* time quantum given to procs at this level */ 45 } fxdpent_t; 46 47 #ifdef _KERNEL 48 49 typedef uintptr_t fx_cookie_t; /* handle for callback supplied storage */ 50 51 /* 52 * callbacks supplied by custom scheduler. In general, a change to quantum 53 * and/or priority when returning from a callback has immediate effect. 54 * 55 * fx_exit - called when a thread exits. This also needs to free any storage 56 * for the fx_cookie_t. 57 * 58 * fx_callb_tick - called at every clock tick attributed to this thread 59 * 60 * fx_callb_preempt - called when a thread is being preempted or yielding 61 * 62 * fx_callb_stop/fx_callb_sleep - called when a thread stops running 63 * 64 * fx_callb_wakeup - called when a thread is again runnable 65 */ 66 typedef struct fx_callbacks { 67 int fx_callb_version; 68 void (*fx_callb_exit)(fx_cookie_t); 69 void (*fx_callb_tick)(fx_cookie_t, clock_t *, pri_t *); 70 void (*fx_callb_preempt)(fx_cookie_t, clock_t *, pri_t *); 71 void (*fx_callb_stop)(fx_cookie_t); 72 void (*fx_callb_sleep)(fx_cookie_t); 73 void (*fx_callb_wakeup)(fx_cookie_t, clock_t *, pri_t *); 74 75 } fx_callbacks_t; 76 77 78 #define FX_CALLB_VERSION_1 1 79 80 #define FX_CALLB_REV FX_CALLB_VERSION_1 81 82 #define FX_CB_VERSION(cb) cb->fx_callb_version 83 84 #define FX_CB_EXIT(cb, c) cb->fx_callb_exit(c) 85 86 #define FX_CB_TICK(cb, c, q, p) cb->fx_callb_tick(c, q, p) 87 88 #define FX_CB_PREEMPT(cb, c, q, p) cb->fx_callb_preempt(c, q, p) 89 90 #define FX_CB_STOP(cb, c) cb->fx_callb_stop(c) 91 92 #define FX_CB_SLEEP(cb, c) cb->fx_callb_sleep(c) 93 94 #define FX_CB_WAKEUP(cb, c, q, p) cb->fx_callb_wakeup(c, q, p) 95 96 /* priority setting */ 97 #define FX_CB_NOCHANGE -32768 98 99 100 /* 101 * Fixed-priority class specific thread structure 102 */ 103 typedef struct fxproc { 104 int fx_pquantum; /* time quantum given to this proc */ 105 int fx_timeleft; /* time remaining in procs quantum */ 106 107 pri_t fx_pri; /* relative priority within fx class */ 108 /* same as user priority */ 109 110 pri_t fx_uprilim; /* user priority limit */ 111 112 char fx_nice; /* nice value for compatibility */ 113 uchar_t fx_flags; /* flags defined below */ 114 kthread_t *fx_tp; /* pointer to thread */ 115 116 /* the following are used only when we have callbacks registered */ 117 kt_did_t fx_ktid; 118 struct fxproc *fx_cb_next; /* pointer to next fxproc that */ 119 /* has a callback */ 120 121 struct fxproc *fx_cb_prev; /* pointer to previous fxproc that */ 122 /* has a callback */ 123 fx_cookie_t fx_cookie; /* cookie with which callback */ 124 /* was registered */ 125 fx_callbacks_t *fx_callback; /* pointer to callback structure */ 126 caps_sc_t fx_caps; /* CPU caps specific data */ 127 } fxproc_t; 128 129 130 #define FX_CALLB(fxpp) fxpp->fx_callback 131 132 133 /* flags */ 134 #define FXBACKQ 0x02 /* thread goes to back of disp q when preempted */ 135 136 /* 137 * Kernel version of fixed-priority class specific parameter structure 138 */ 139 typedef struct fxkparms { 140 pri_t fx_upri; 141 pri_t fx_uprilim; 142 int fx_tqntm; 143 uint_t fx_cflags; 144 } fxkparms_t; 145 146 147 148 /* 149 * Interface for partner private code. This is not a public interface. 150 */ 151 extern int fx_register_callbacks(fx_callbacks_t *, fx_cookie_t, pri_t, clock_t); 152 extern int fx_unregister_callbacks(); 153 extern int fx_modify_priority(kt_did_t, clock_t, pri_t); 154 extern void *fx_get_mutex_cookie(); 155 extern pri_t fx_get_maxpri(); 156 157 #endif /* _KERNEL */ 158 159 #ifdef __cplusplus 160 } 161 #endif 162 163 #endif /* _SYS_FX_H */ 164