VirtualBox

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

Last change on this file since 47052 was 44528, checked in by vboxsync, 12 years ago

header (C) fixes

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