VirtualBox

source: vbox/trunk/src/VBox/Runtime/r0drv/linux/thread2-r0drv-linux.c@ 36241

Last change on this file since 36241 was 36241, checked in by vboxsync, 14 years ago

cosmetics

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.3 KB
Line 
1/* $Id: thread2-r0drv-linux.c 36241 2011-03-09 17:48:07Z vboxsync $ */
2/** @file
3 * IPRT - Threads (Part 2), Ring-0 Driver, Linux.
4 */
5
6/*
7 * Copyright (C) 2006-2007 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
28/*******************************************************************************
29* Header Files *
30*******************************************************************************/
31#include "the-linux-kernel.h"
32#include "internal/iprt.h"
33
34#include <iprt/assert.h>
35#include <iprt/thread.h>
36#include <iprt/err.h>
37#include "internal/thread.h"
38
39
40RTDECL(RTTHREAD) RTThreadSelf(void)
41{
42 return rtThreadGetByNative((RTNATIVETHREAD)current);
43}
44
45int rtThreadNativeInit(void)
46{
47 return VINF_SUCCESS;
48}
49
50/*
51 * Following is verbatim comment from Linux's sched.h.
52 *
53 * Priority of a process goes from 0..MAX_PRIO-1, valid RT
54 * priority is 0..MAX_RT_PRIO-1, and SCHED_NORMAL/SCHED_BATCH
55 * tasks are in the range MAX_RT_PRIO..MAX_PRIO-1. Priority
56 * values are inverted: lower p->prio value means higher priority.
57 *
58 * The MAX_USER_RT_PRIO value allows the actual maximum
59 * RT priority to be separate from the value exported to
60 * user-space. This allows kernel threads to set their
61 * priority to a value higher than any user task. Note:
62 * MAX_RT_PRIO must not be smaller than MAX_USER_RT_PRIO.
63 */
64
65int rtThreadNativeSetPriority(PRTTHREADINT pThread, RTTHREADTYPE enmType)
66{
67 int sched_class = SCHED_NORMAL;
68 struct sched_param param = { .sched_priority = MAX_PRIO-1 };
69 switch (enmType)
70 {
71 case RTTHREADTYPE_INFREQUENT_POLLER:
72 {
73 param.sched_priority = MAX_RT_PRIO + 5;
74 break;
75 }
76 case RTTHREADTYPE_EMULATION:
77 {
78 param.sched_priority = MAX_RT_PRIO + 4;
79 break;
80 }
81 case RTTHREADTYPE_DEFAULT:
82 {
83 param.sched_priority = MAX_RT_PRIO + 3;
84 break;
85 }
86 case RTTHREADTYPE_MSG_PUMP:
87 {
88 param.sched_priority = MAX_RT_PRIO + 2;
89 break;
90 }
91 case RTTHREADTYPE_IO:
92 {
93 sched_class = SCHED_FIFO;
94 param.sched_priority = MAX_RT_PRIO - 1;
95 break;
96 }
97 case RTTHREADTYPE_TIMER:
98 {
99 sched_class = SCHED_FIFO;
100 param.sched_priority = 1; /* not 0 just in case */
101 }
102 default:
103 AssertMsgFailed(("enmType=%d\n", enmType));
104 return VERR_INVALID_PARAMETER;
105 }
106 sched_setscheduler(current, sched_class, &param);
107
108 return VINF_SUCCESS;
109}
110
111int rtThreadNativeAdopt(PRTTHREADINT pThread)
112{
113 return VERR_NOT_IMPLEMENTED;
114}
115
116
117void rtThreadNativeDestroy(PRTTHREADINT pThread)
118{
119 NOREF(pThread);
120}
121
122/**
123 * Native kernel thread wrapper function.
124 *
125 * This will forward to rtThreadMain and do termination upon return.
126 *
127 * @param pvArg Pointer to the argument package.
128 */
129static int rtThreadNativeMain(void *pvArg)
130{
131 PRTTHREADINT pThread = (PRTTHREADINT)pvArg;
132
133 rtThreadMain(pThread, (RTNATIVETHREAD)current, &pThread->szName[0]);
134 return 0;
135}
136
137
138int rtThreadNativeCreate(PRTTHREADINT pThreadInt, PRTNATIVETHREAD pNativeThread)
139{
140 struct task_struct *NativeThread;
141
142 RT_ASSERT_PREEMPTIBLE();
143
144 NativeThread = kthread_run(rtThreadNativeMain, pThreadInt, "vbox-%s", pThreadInt->szName);
145
146 if (IS_ERR(NativeThread))
147 return VERR_GENERAL_FAILURE;
148
149 *pNativeThread = (RTNATIVETHREAD)NativeThread;
150 return VINF_SUCCESS;
151}
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