Changeset 86548 in vbox for trunk/src/VBox/Runtime/r0drv/linux/thread2-r0drv-linux.c
- Timestamp:
- Oct 12, 2020 6:58:24 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r0drv/linux/thread2-r0drv-linux.c
r86542 r86548 55 55 DECLHIDDEN(int) rtThreadNativeSetPriority(PRTTHREADINT pThread, RTTHREADTYPE enmType) 56 56 { 57 int iSchedClass = SCHED_FIFO; 58 int rc = VINF_SUCCESS; 59 struct sched_param Param = { 0 }; 60 61 RT_NOREF_PV(pThread); 62 #if RTLNX_VER_MIN(5,9,0) 63 RT_NOREF_PV(iSchedClass); 64 RT_NOREF_PV(Param); 65 #endif 57 #if RTLNX_VER_MIN(2,5,2) 58 /* 59 * Assignments are partially based on g_aTypesLinuxFree but 60 * scaled up in the high priority end. 61 * 62 * 5.9.0 - : 63 * The sched_set_normal interfaces does not really check the input, 64 * whereas sched_set_fifo & sched_set_fifo_low have fixed assignments. 65 * 2.6.11 - 5.9.0: 66 * Use sched_setscheduler to try effect FIFO scheduling 67 * for IO and TIMER threads, otherwise use set_user_nice. 68 * 2.5.2 - 5.9.0: 69 * Use set_user_nice to renice the thread. 70 */ 71 int iNice = 0; 72 # if RTLNX_VER_MAX(5,9,0) 73 int rc; 74 # if RTLNX_VER_MIN(2,6,11) 75 int iSchedClass = SCHED_NORMAL; 76 struct sched_param Param = { .sched_priority = 0 }; 77 # endif 78 # endif 66 79 switch (enmType) 67 80 { 81 case RTTHREADTYPE_INFREQUENT_POLLER: 82 iNice = +3; 83 break; 84 85 case RTTHREADTYPE_MAIN_HEAVY_WORKER: 86 iNice = +2; 87 break; 88 89 case RTTHREADTYPE_EMULATION: 90 iNice = +1; 91 break; 92 93 case RTTHREADTYPE_DEFAULT: 94 case RTTHREADTYPE_GUI: 95 case RTTHREADTYPE_MAIN_WORKER: 96 iNice = 0; 97 break; 98 99 case RTTHREADTYPE_VRDP_IO: 100 case RTTHREADTYPE_DEBUGGER: 101 iNice = -1; 102 break; 103 104 case RTTHREADTYPE_MSG_PUMP: 105 iNice = -2; 106 break; 107 68 108 case RTTHREADTYPE_IO: 69 #if RTLNX_VER_MAX(5,9,0) 70 /* Set max. priority to preempt all other threads on this CPU. */ 71 Param.sched_priority = MAX_RT_PRIO - 1; 72 #else 73 /* Effectively changes prio to 50 */ 109 # if RTLNX_VER_MIN(5,9,0) 110 sched_set_fifo_low(current); 111 return VINF_SUCCESS; 112 # else 113 iNice = -12; 114 # if RTLNX_VER_MIN(2,6,11) 115 iSchedClass = SCHED_FIFO; 116 Param.sched_priority = 1; /* => prio=98; */ 117 # endif 118 break; 119 # endif 120 121 case RTTHREADTYPE_TIMER: 122 # if RTLNX_VER_MIN(5,9,0) 74 123 sched_set_fifo(current); 75 #endif 76 break; 77 case RTTHREADTYPE_TIMER: 78 #if RTLNX_VER_MAX(5,9,0) 79 Param.sched_priority = 1; /* not 0 just in case */ 80 #else 81 /* Just one above SCHED_NORMAL class */ 82 sched_set_fifo_low(current); 83 #endif 84 break; 124 return VINF_SUCCESS; 125 # else 126 iNice = -19; 127 # if RTLNX_VER_MIN(2,6,11) 128 iSchedClass = SCHED_FIFO; 129 Param.sched_priority = MAX_RT_PRIO / 2; /* => prio=49 */ 130 # endif 131 break; 132 # endif 85 133 default: 86 /* pretend success instead of VERR_NOT_SUPPORTED */ 87 return rc; 134 AssertMsgFailedReturn(("enmType=%d\n", enmType), VERR_INVALID_PARAMETER); 88 135 } 89 #if RTLNX_VER_MAX(5,9,0) 90 if ((sched_setscheduler(current, iSchedClass, &Param)) != 0) { 91 rc = VERR_GENERAL_FAILURE; 136 137 # if RTLNX_VER_MIN(5,9,0) 138 /* 139 * We only get here for renice work. 140 */ 141 sched_set_normal(current, iNice); 142 143 # else /* < 5.9.0 */ 144 # if RTLNX_VER_MIN(2,6,11) 145 /* 146 * Try set scheduler parameters. 147 * Fall back on normal + nice if this fails for FIFO policy.* 148 */ 149 rc = sched_setscheduler(current, iSchedClass, &Param); 150 if (rc) 151 { 152 Param.sched_priority = 0; 153 iSchedClass = SCHED_NORMAL; 154 rc = sched_setscheduler(current, iSchedClass, &Param); 92 155 } 93 #endif 94 return rc; 156 157 /* 158 * Renice if using normal scheduling class. 159 */ 160 if (iSchedClass == SCHED_NORMAL) 161 # endif /* >= 2.6.11 */ 162 set_user_nice(current, iNice); 163 164 # endif /* < 5.9.0 */ 165 #else /* < 2.5.2 */ 166 RT_NOREF_PV(enmType); 167 #endif /* < 2.5.2 */ 168 RT_NOREF_PV(pThread); 169 return VINF_SUCCESS; 95 170 } 96 171
Note:
See TracChangeset
for help on using the changeset viewer.