1 | /* $Id: sched-os2.cpp 5653 2007-11-09 15:03:53Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * innotek Portable Runtime - Scheduling, OS/2
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2007 innotek GmbH
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License as published by the Free Software Foundation,
|
---|
13 | * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
14 | * distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
15 | * be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | /** @def OS2_SCHED_ENABLED
|
---|
19 | * Enables the priority scheme. */
|
---|
20 | #define OS2_SCHED_ENABLED
|
---|
21 |
|
---|
22 |
|
---|
23 | /*******************************************************************************
|
---|
24 | * Header Files *
|
---|
25 | *******************************************************************************/
|
---|
26 | #define LOG_GROUP RTLOGGROUP_THREAD
|
---|
27 | #define INCL_BASE
|
---|
28 | #define INCL_ERRORS
|
---|
29 | #include <os2.h>
|
---|
30 |
|
---|
31 | #include <iprt/thread.h>
|
---|
32 | #include <iprt/log.h>
|
---|
33 | #include <iprt/assert.h>
|
---|
34 | #include <iprt/err.h>
|
---|
35 | #include "internal/sched.h"
|
---|
36 | #include "internal/thread.h"
|
---|
37 |
|
---|
38 |
|
---|
39 | /*******************************************************************************
|
---|
40 | * Structures and Typedefs *
|
---|
41 | *******************************************************************************/
|
---|
42 | /**
|
---|
43 | * Configuration of one priority.
|
---|
44 | */
|
---|
45 | typedef struct
|
---|
46 | {
|
---|
47 | /** The priority. */
|
---|
48 | RTPROCPRIORITY enmPriority;
|
---|
49 | /** The name of this priority. */
|
---|
50 | const char *pszName;
|
---|
51 | /** Array scheduler attributes corresponding to each of the thread types. */
|
---|
52 | struct
|
---|
53 | {
|
---|
54 | /** For sanity include the array index. */
|
---|
55 | RTTHREADTYPE enmType;
|
---|
56 | /** The OS/2 priority class. */
|
---|
57 | ULONG ulClass;
|
---|
58 | /** The OS/2 priority delta. */
|
---|
59 | ULONG ulDelta;
|
---|
60 | } aTypes[RTTHREADTYPE_END];
|
---|
61 | } PROCPRIORITY;
|
---|
62 |
|
---|
63 | /** Matches any process priority class. */
|
---|
64 | #define ANY_PROCESS_PRIORITY_CLASS (~0U)
|
---|
65 |
|
---|
66 |
|
---|
67 | /*******************************************************************************
|
---|
68 | * Global Variables *
|
---|
69 | *******************************************************************************/
|
---|
70 | /**
|
---|
71 | * Array of static priority configurations.
|
---|
72 | */
|
---|
73 | static const PROCPRIORITY g_aPriorities[] =
|
---|
74 | {
|
---|
75 | {
|
---|
76 | RTPROCPRIORITY_FLAT, "Flat",
|
---|
77 | {
|
---|
78 | { RTTHREADTYPE_INVALID, ~0, ~0 },
|
---|
79 | { RTTHREADTYPE_INFREQUENT_POLLER, PRTYC_REGULAR, 0 },
|
---|
80 | { RTTHREADTYPE_MAIN_HEAVY_WORKER, PRTYC_REGULAR, 0 },
|
---|
81 | { RTTHREADTYPE_EMULATION, PRTYC_REGULAR, 0 },
|
---|
82 | { RTTHREADTYPE_DEFAULT, PRTYC_REGULAR, 0 },
|
---|
83 | { RTTHREADTYPE_GUI, PRTYC_REGULAR, 0 },
|
---|
84 | { RTTHREADTYPE_MAIN_WORKER, PRTYC_REGULAR, 0 },
|
---|
85 | { RTTHREADTYPE_VRDP_IO, PRTYC_REGULAR, 0 },
|
---|
86 | { RTTHREADTYPE_DEBUGGER, PRTYC_REGULAR, 0 },
|
---|
87 | { RTTHREADTYPE_MSG_PUMP, PRTYC_REGULAR, 0 },
|
---|
88 | { RTTHREADTYPE_IO, PRTYC_REGULAR, 0 },
|
---|
89 | { RTTHREADTYPE_TIMER, PRTYC_REGULAR, 0 }
|
---|
90 | }
|
---|
91 | },
|
---|
92 | {
|
---|
93 | RTPROCPRIORITY_LOW, "Low",
|
---|
94 | {
|
---|
95 | { RTTHREADTYPE_INVALID, ~0 },
|
---|
96 | { RTTHREADTYPE_INFREQUENT_POLLER, PRTYC_IDLETIME, 0 },
|
---|
97 | { RTTHREADTYPE_MAIN_HEAVY_WORKER, PRTYC_IDLETIME, 0 },
|
---|
98 | { RTTHREADTYPE_EMULATION, PRTYC_IDLETIME, 0 },
|
---|
99 | { RTTHREADTYPE_DEFAULT, PRTYC_IDLETIME, 30 },
|
---|
100 | { RTTHREADTYPE_GUI, PRTYC_IDLETIME, 30 },
|
---|
101 | { RTTHREADTYPE_MAIN_WORKER, PRTYC_IDLETIME, 30 },
|
---|
102 | { RTTHREADTYPE_VRDP_IO, PRTYC_REGULAR, 0 },
|
---|
103 | { RTTHREADTYPE_DEBUGGER, PRTYC_REGULAR, 0 },
|
---|
104 | { RTTHREADTYPE_MSG_PUMP, PRTYC_REGULAR, 0 },
|
---|
105 | { RTTHREADTYPE_IO, PRTYC_REGULAR, 0 },
|
---|
106 | { RTTHREADTYPE_TIMER, PRTYC_REGULAR, 0 }
|
---|
107 | }
|
---|
108 | },
|
---|
109 | {
|
---|
110 | RTPROCPRIORITY_NORMAL, "Normal",
|
---|
111 | {
|
---|
112 | { RTTHREADTYPE_INVALID, ~0 },
|
---|
113 | { RTTHREADTYPE_INFREQUENT_POLLER, PRTYC_IDLETIME, 30 },
|
---|
114 | { RTTHREADTYPE_MAIN_HEAVY_WORKER, PRTYC_IDLETIME, 31 },
|
---|
115 | { RTTHREADTYPE_EMULATION, PRTYC_REGULAR, 0 },
|
---|
116 | { RTTHREADTYPE_DEFAULT, PRTYC_REGULAR, 5 },
|
---|
117 | { RTTHREADTYPE_GUI, PRTYC_REGULAR, 10 },
|
---|
118 | { RTTHREADTYPE_MAIN_WORKER, PRTYC_REGULAR, 12 },
|
---|
119 | { RTTHREADTYPE_VRDP_IO, PRTYC_REGULAR, 15 },
|
---|
120 | { RTTHREADTYPE_DEBUGGER, PRTYC_REGULAR, 20 },
|
---|
121 | { RTTHREADTYPE_MSG_PUMP, PRTYC_REGULAR, 25 },
|
---|
122 | { RTTHREADTYPE_IO, PRTYC_FOREGROUNDSERVER, 5 },
|
---|
123 | { RTTHREADTYPE_TIMER, PRTYC_TIMECRITICAL, 0 }
|
---|
124 | }
|
---|
125 | },
|
---|
126 | {
|
---|
127 | RTPROCPRIORITY_HIGH, "High",
|
---|
128 | {
|
---|
129 | { RTTHREADTYPE_INVALID, ~0 },
|
---|
130 | { RTTHREADTYPE_INFREQUENT_POLLER, PRTYC_IDLETIME, 30 },
|
---|
131 | { RTTHREADTYPE_MAIN_HEAVY_WORKER, PRTYC_REGULAR, 0 },
|
---|
132 | { RTTHREADTYPE_EMULATION, PRTYC_REGULAR, 0 },
|
---|
133 | { RTTHREADTYPE_DEFAULT, PRTYC_REGULAR, 15 },
|
---|
134 | { RTTHREADTYPE_GUI, PRTYC_REGULAR, 20 },
|
---|
135 | { RTTHREADTYPE_MAIN_WORKER, PRTYC_REGULAR, 25 },
|
---|
136 | { RTTHREADTYPE_VRDP_IO, PRTYC_REGULAR, 30 },
|
---|
137 | { RTTHREADTYPE_DEBUGGER, PRTYC_TIMECRITICAL, 2 },
|
---|
138 | { RTTHREADTYPE_MSG_PUMP, PRTYC_TIMECRITICAL, 3 },
|
---|
139 | { RTTHREADTYPE_IO, PRTYC_TIMECRITICAL, 4 },
|
---|
140 | { RTTHREADTYPE_TIMER, PRTYC_TIMECRITICAL, 5 }
|
---|
141 | }
|
---|
142 | }
|
---|
143 | };
|
---|
144 |
|
---|
145 | /**
|
---|
146 | * The dynamic default priority configuration.
|
---|
147 | *
|
---|
148 | * This can be recalulated at runtime depending on what the
|
---|
149 | * system allow us to do. Presently we don't do this as it's
|
---|
150 | * generally not a bit issue on OS/2 hosts.
|
---|
151 | */
|
---|
152 | static PROCPRIORITY g_aDefaultPriority =
|
---|
153 | {
|
---|
154 | RTPROCPRIORITY_LOW, "Default",
|
---|
155 | {
|
---|
156 | { RTTHREADTYPE_INVALID, ~0 },
|
---|
157 | { RTTHREADTYPE_INFREQUENT_POLLER, PRTYC_IDLETIME, 30 },
|
---|
158 | { RTTHREADTYPE_MAIN_HEAVY_WORKER, PRTYC_IDLETIME, 31 },
|
---|
159 | { RTTHREADTYPE_EMULATION, PRTYC_REGULAR, 0 },
|
---|
160 | { RTTHREADTYPE_DEFAULT, PRTYC_REGULAR, 5 },
|
---|
161 | { RTTHREADTYPE_GUI, PRTYC_REGULAR, 10 },
|
---|
162 | { RTTHREADTYPE_MAIN_WORKER, PRTYC_REGULAR, 12 },
|
---|
163 | { RTTHREADTYPE_VRDP_IO, PRTYC_REGULAR, 15 },
|
---|
164 | { RTTHREADTYPE_DEBUGGER, PRTYC_REGULAR, 20 },
|
---|
165 | { RTTHREADTYPE_MSG_PUMP, PRTYC_REGULAR, 25 },
|
---|
166 | { RTTHREADTYPE_IO, PRTYC_FOREGROUNDSERVER, 5 },
|
---|
167 | { RTTHREADTYPE_TIMER, PRTYC_TIMECRITICAL, 0 }
|
---|
168 | }
|
---|
169 | };
|
---|
170 |
|
---|
171 |
|
---|
172 | /** Pointer to the current priority configuration. */
|
---|
173 | static const PROCPRIORITY *g_pProcessPriority = &g_aDefaultPriority;
|
---|
174 |
|
---|
175 |
|
---|
176 | /**
|
---|
177 | * Calculate the scheduling properties for all the threads in the default
|
---|
178 | * process priority, assuming the current thread have the type enmType.
|
---|
179 | *
|
---|
180 | * @returns iprt status code.
|
---|
181 | * @param enmType The thread type to be assumed for the current thread.
|
---|
182 | */
|
---|
183 | int rtSchedNativeCalcDefaultPriority(RTTHREADTYPE enmType)
|
---|
184 | {
|
---|
185 | Assert(enmType > RTTHREADTYPE_INVALID && enmType < RTTHREADTYPE_END);
|
---|
186 | return VINF_SUCCESS;
|
---|
187 | }
|
---|
188 |
|
---|
189 |
|
---|
190 | /**
|
---|
191 | * Validates and sets the process priority.
|
---|
192 | * This will check that all rtThreadNativeSetPriority() will success for all the
|
---|
193 | * thread types when applied to the current thread.
|
---|
194 | *
|
---|
195 | * @returns iprt status code.
|
---|
196 | * @param enmPriority The priority to validate and set.
|
---|
197 | * @remark Located in sched.
|
---|
198 | */
|
---|
199 | int rtProcNativeSetPriority(RTPROCPRIORITY enmPriority)
|
---|
200 | {
|
---|
201 | Assert(enmPriority > RTPROCPRIORITY_INVALID && enmPriority < RTPROCPRIORITY_LAST);
|
---|
202 | return VINF_SUCCESS;
|
---|
203 | }
|
---|
204 |
|
---|
205 |
|
---|
206 | /**
|
---|
207 | * Sets the priority of the thread according to the thread type
|
---|
208 | * and current process priority.
|
---|
209 | *
|
---|
210 | * The RTTHREADINT::enmType member has not yet been updated and will be updated by
|
---|
211 | * the caller on a successful return.
|
---|
212 | *
|
---|
213 | * @returns iprt status code.
|
---|
214 | * @param pThread The thread in question.
|
---|
215 | * @param enmType The thread type.
|
---|
216 | * @remark Located in sched.
|
---|
217 | */
|
---|
218 | int rtThreadNativeSetPriority(PRTTHREADINT pThread, RTTHREADTYPE enmType)
|
---|
219 | {
|
---|
220 | Assert(enmType > RTTHREADTYPE_INVALID && enmType < RTTHREADTYPE_END);
|
---|
221 | AssertMsg(g_pProcessPriority && g_pProcessPriority->aTypes[enmType].enmType == enmType,
|
---|
222 | ("enmType=%d entry=%d\n", enmType, g_pProcessPriority->aTypes[enmType].enmType));
|
---|
223 |
|
---|
224 | #ifdef OS2_SCHED_ENABLED
|
---|
225 | APIRET rc = DosSetPriority(PRTYS_THREAD, g_pProcessPriority->aTypes[enmType].ulClass, g_pProcessPriority->aTypes[enmType].ulDelta, (ULONG)pThread->Core.Key & 0xffff /*tid*/);
|
---|
226 | AssertMsg(rc == NO_ERROR, ("%d\n", rc));
|
---|
227 | return RTErrConvertFromOS2(rc);
|
---|
228 | #else
|
---|
229 | return VINF_SUCCESS;
|
---|
230 | #endif
|
---|
231 | }
|
---|
232 |
|
---|