VirtualBox

source: vbox/trunk/src/VBox/Runtime/r3/os2/sched-os2.cpp@ 18587

Last change on this file since 18587 was 8245, checked in by vboxsync, 17 years ago

rebranding: IPRT files again.

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette