Changeset 6340 in vbox for trunk/src/VBox/HostDrivers
- Timestamp:
- Jan 11, 2008 2:26:32 PM (17 years ago)
- Location:
- trunk/src/VBox/HostDrivers/Support
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/Support/SUPDRV.h
r5999 r6340 96 96 # include <linux/timer.h> 97 97 98 # if 0 99 # include <linux/hrtimer.h> 100 # define VBOX_HRTIMER 101 # endif 102 98 103 #elif defined(RT_OS_DARWIN) 99 104 # include <libkern/libkern.h> … … 259 264 /** Pointer to the device extension. */ 260 265 typedef struct SUPDRVDEVEXT *PSUPDRVDEVEXT; 266 267 #ifdef RT_OS_LINUX 268 # ifdef VBOX_HRTIMER 269 typedef struct hrtimer VBOXKTIMER; 270 # else 271 typedef struct timer_list VBOXKTIMER; 272 # endif 273 #endif 261 274 262 275 #ifdef VBOX_WITH_IDT_PATCHING … … 710 723 unsigned iSmpProcessorId; 711 724 /** The per cpu timer. */ 712 struct timer_listTimer;725 VBOXKTIMER Timer; 713 726 } aCPUs[256]; 714 727 # endif -
trunk/src/VBox/HostDrivers/Support/linux/SUPDrv-linux.c
r6046 r6340 41 41 42 42 #include <linux/module.h> 43 #include <linux/moduleparam.h> 43 44 #include <linux/kernel.h> 44 45 #include <linux/init.h> … … 261 262 262 263 /** Timer structure for the GIP update. */ 263 static struct timer_listg_GipTimer;264 static VBOXKTIMER g_GipTimer; 264 265 /** Pointer to the page structure for the GIP. */ 265 266 struct page *g_pGipPage; … … 280 281 static int g_iModuleMajor; 281 282 #endif /* !CONFIG_VBOXDRV_AS_MISC */ 283 284 /** Module parameter */ 285 static int force_async_tsc = 0; 282 286 283 287 /** The module name. */ … … 303 307 * Internal Functions * 304 308 *******************************************************************************/ 309 #ifdef VBOX_HRTIMER 310 typedef enum hrtimer_restart (*VBOXTIMERFN)(struct hrtimer *); 311 #else 312 typedef void (*VBOXTIMERFN)(unsigned long); 313 #endif 314 305 315 static int VBoxDrvLinuxInit(void); 306 316 static void VBoxDrvLinuxUnload(void); … … 315 325 static int VBoxDrvLinuxInitGip(PSUPDRVDEVEXT pDevExt); 316 326 static int VBoxDrvLinuxTermGip(PSUPDRVDEVEXT pDevExt); 327 #ifdef VBOX_HRTIMER 328 static enum hrtimer_restart VBoxDrvLinuxGipTimer(struct hrtimer *timer); 329 #else 317 330 static void VBoxDrvLinuxGipTimer(unsigned long ulUser); 331 #endif 318 332 #ifdef CONFIG_SMP 333 # ifdef VBOX_HRTIMER 334 static enum hrtimer_restart VBoxDrvLinuxGipTimerPerCpu(struct hrtimer *timer); 335 # else 319 336 static void VBoxDrvLinuxGipTimerPerCpu(unsigned long ulUser); 337 # endif 320 338 static void VBoxDrvLinuxGipResumePerCpu(void *pvUser); 321 339 #endif … … 349 367 }; 350 368 #endif 369 370 static inline void vbox_ktimer_init(VBOXKTIMER *timer, VBOXTIMERFN function, unsigned long data) 371 { 372 #ifdef VBOX_HRTIMER 373 hrtimer_init(timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS); 374 timer->function = function; 375 #else 376 init_timer(timer); 377 timer->data = data; 378 timer->function = function; 379 timer->expires = jiffies; 380 #endif 381 } 382 383 static inline void vbox_ktimer_start(VBOXKTIMER *timer) 384 { 385 #ifdef VBOX_HRTIMER 386 hrtimer_start(timer, ktime_add_ns(ktime_get(), 1000000), HRTIMER_MODE_ABS); 387 #else 388 mod_timer(timer, jiffies); 389 #endif 390 } 391 392 static inline void vbox_ktimer_stop(VBOXKTIMER *timer) 393 { 394 #ifdef VBOX_HRTIMER 395 hrtimer_cancel(timer); 396 #else 397 if (timer_pending(timer)) 398 del_timer_sync(timer); 399 #endif 400 } 351 401 352 402 #ifdef CONFIG_X86_LOCAL_APIC … … 647 697 if (!rc) 648 698 { 699 printk(KERN_INFO DEVICE_NAME ": TSC mode is %s, kernel timer mode is " 700 #ifdef VBOX_HRTIMER 701 "'high-res'" 702 #else 703 "'normal'" 704 #endif 705 ".\n", 706 g_DevExt.pGip->u32Mode == SUPGIPMODE_SYNC_TSC ? "'synchronous'" : "'asynchronous'"); 649 707 dprintf(("VBoxDrv::ModuleInit returning %#x\n", rc)); 650 708 printk(KERN_DEBUG DEVICE_NAME ": Successfully loaded version " … … 977 1035 * Initialize the timer. 978 1036 */ 979 init_timer(&g_GipTimer); 980 g_GipTimer.data = (unsigned long)pDevExt; 981 g_GipTimer.function = VBoxDrvLinuxGipTimer; 982 g_GipTimer.expires = jiffies; 1037 vbox_ktimer_init(&g_GipTimer, VBoxDrvLinuxGipTimer, (unsigned long)pDevExt); 983 1038 #ifdef CONFIG_SMP 984 1039 for (i = 0; i < RT_ELEMENTS(pDevExt->aCPUs); i++) … … 987 1042 pDevExt->aCPUs[i].ulLastJiffies = pDevExt->ulLastJiffies; 988 1043 pDevExt->aCPUs[i].iSmpProcessorId = -512; 989 init_timer(&pDevExt->aCPUs[i].Timer); 990 pDevExt->aCPUs[i].Timer.data = i; 991 pDevExt->aCPUs[i].Timer.function = VBoxDrvLinuxGipTimerPerCpu; 992 pDevExt->aCPUs[i].Timer.expires = jiffies; 1044 vbox_ktimer_init(&pDevExt->aCPUs[i].Timer, VBoxDrvLinuxGipTimerPerCpu, i); 993 1045 } 994 1046 #endif … … 1016 1068 * Delete the timer if it's pending. 1017 1069 */ 1018 if (timer_pending(&g_GipTimer)) 1019 del_timer_sync(&g_GipTimer); 1070 vbox_ktimer_stop(&g_GipTimer); 1020 1071 #ifdef CONFIG_SMP 1021 1072 for (i = 0; i < RT_ELEMENTS(pDevExt->aCPUs); i++) 1022 if (timer_pending(&pDevExt->aCPUs[i].Timer)) 1023 del_timer_sync(&pDevExt->aCPUs[i].Timer); 1073 vbox_ktimer_stop(&pDevExt->aCPUs[i].Timer); 1024 1074 #endif 1025 1075 … … 1054 1104 * @param ulUser The device extension pointer. 1055 1105 */ 1106 #ifdef VBOX_HRTIMER 1107 static enum hrtimer_restart VBoxDrvLinuxGipTimer(struct hrtimer* timer) 1108 #else 1056 1109 static void VBoxDrvLinuxGipTimer(unsigned long ulUser) 1110 #endif 1057 1111 { 1058 1112 PSUPDRVDEVEXT pDevExt; … … 1062 1116 uint64_t u64Monotime; 1063 1117 unsigned long SavedFlags; 1118 #ifdef VBOX_HRTIMER 1119 ktime_t kNow; 1120 #endif 1064 1121 1065 1122 local_irq_save(SavedFlags); 1066 1123 1067 1124 ulNow = jiffies; 1125 #ifdef VBOX_HRTIMER 1126 kNow = ktime_get(); 1127 pDevExt = &g_DevExt; 1128 #else 1068 1129 pDevExt = (PSUPDRVDEVEXT)ulUser; 1130 #endif 1069 1131 pGip = pDevExt->pGip; 1070 1132 … … 1089 1151 supdrvGipUpdate(pDevExt->pGip, u64Monotime); 1090 1152 if (RT_LIKELY(!pDevExt->fGIPSuspended)) 1153 { 1154 #ifdef VBOX_HRTIMER 1155 hrtimer_forward(&g_GipTimer, kNow, ktime_set(0, 1000000)); 1156 #else 1091 1157 mod_timer(&g_GipTimer, ulNow + ONE_MSEC_IN_JIFFIES); 1158 #endif 1159 } 1092 1160 1093 1161 local_irq_restore(SavedFlags); 1162 1163 #ifdef VBOX_HRTIMER 1164 return pDevExt->fGIPSuspended ? HRTIMER_NORESTART : HRTIMER_RESTART; 1165 #endif 1094 1166 } 1095 1167 … … 1101 1173 * @param iTimerCPU The APIC ID of this timer. 1102 1174 */ 1175 #ifdef VBOX_HRTIMER 1176 static enum hrtimer_restart VBoxDrvLinuxGipTimerPerCpu(struct hrtimer *timer) 1177 #else 1103 1178 static void VBoxDrvLinuxGipTimerPerCpu(unsigned long iTimerCPU) 1179 #endif 1104 1180 { 1105 1181 PSUPDRVDEVEXT pDevExt; … … 1109 1185 unsigned long SavedFlags; 1110 1186 unsigned long ulNow; 1187 # ifdef VBOX_HRTIMER 1188 unsigned long iTimerCPU; 1189 ktime_t kNow; 1190 # endif 1111 1191 1112 1192 local_irq_save(SavedFlags); … … 1116 1196 pGip = pDevExt->pGip; 1117 1197 iCPU = ASMGetApicId(); 1198 # ifdef VBOX_HRTIMER 1199 iTimerCPU = iCPU; /* XXX hrtimer does not support a 'data' field */ 1200 kNow = ktime_get(); 1201 # endif 1118 1202 1119 1203 if (RT_LIKELY(iCPU < RT_ELEMENTS(pGip->aCPUs))) … … 1128 1212 supdrvGipUpdatePerCpu(pGip, u64Monotime, iCPU); 1129 1213 if (RT_LIKELY(!pDevExt->fGIPSuspended)) 1214 { 1215 # ifdef VBOX_HRTIMER 1216 hrtimer_forward(&pDevExt->aCPUs[iCPU].Timer, kNow, ktime_set(0, 1000000)); 1217 # else 1130 1218 mod_timer(&pDevExt->aCPUs[iCPU].Timer, ulNow + ONE_MSEC_IN_JIFFIES); 1219 # endif 1220 } 1131 1221 } 1132 1222 else … … 1139 1229 1140 1230 local_irq_restore(SavedFlags); 1231 1232 # ifdef VBOX_HRTIMER 1233 return pDevExt->fGIPSuspended ? HRTIMER_NORESTART : HRTIMER_RESTART; 1234 # endif 1141 1235 } 1142 1236 #endif /* CONFIG_SMP */ … … 1253 1347 { 1254 1348 #endif 1255 mod_timer(&g_GipTimer, jiffies);1349 vbox_ktimer_start(&g_GipTimer); 1256 1350 #ifdef CONFIG_SMP 1257 1351 } 1258 1352 else 1259 1353 { 1260 mod_timer(&g_GipTimer, jiffies);1354 vbox_ktimer_start(&g_GipTimer); 1261 1355 smp_call_function(VBoxDrvLinuxGipResumePerCpu, pDevExt, 0 /* retry */, 1 /* wait */); 1262 1356 } … … 1286 1380 1287 1381 pDevExt->aCPUs[iCPU].iSmpProcessorId = smp_processor_id(); 1288 mod_timer(&pDevExt->aCPUs[iCPU].Timer, jiffies);1382 vbox_ktimer_start(&pDevExt->aCPUs[iCPU].Timer); 1289 1383 } 1290 1384 #endif /* CONFIG_SMP */ … … 1304 1398 ASMAtomicXchgU8(&pDevExt->fGIPSuspended, true); 1305 1399 1306 if (timer_pending(&g_GipTimer)) 1307 del_timer_sync(&g_GipTimer); 1400 vbox_ktimer_stop(&g_GipTimer); 1308 1401 #ifdef CONFIG_SMP 1309 1402 for (i = 0; i < RT_ELEMENTS(pDevExt->aCPUs); i++) 1310 if (timer_pending(&pDevExt->aCPUs[i].Timer)) 1311 del_timer_sync(&pDevExt->aCPUs[i].Timer); 1403 vbox_ktimer_stop(&pDevExt->aCPUs[i].Timer); 1312 1404 #endif 1313 1405 } … … 1339 1431 bool VBOXCALL supdrvOSGetForcedAsyncTscMode(void) 1340 1432 { 1341 return f alse;1433 return force_async_tsc != 0; 1342 1434 } 1343 1435 … … 1436 1528 MODULE_VERSION(VBOX_VERSION_STRING " (" xstr(SUPDRVIOC_VERSION) ")"); 1437 1529 #endif 1530 1531 module_param(force_async_tsc, int, 0444); 1532 MODULE_PARM_DESC(force_async_tsc, "force the asynchronous TSC mode"); 1533
Note:
See TracChangeset
for help on using the changeset viewer.