[vbox-dev] Patch for kernel 4.15-rc1
Larry Finger
Larry.Finger at lwfinger.net
Fri Dec 1 17:10:12 UTC 2017
On 12/01/2017 07:50 AM, Gianfranco Costamagna wrote:
> Hello,
>> I had that part. It fails build because the parameter of
>> rtTimerLinuxStdCallback() needs to be "struct timer_list *t". The part I have
>> not gotten right is how one uses that "t" to get the correct value of pSubTimer
>>from "t" using the from_timer() macro.
>
>
> indeed...
> maybe something like this? (sorry can't check right now)
> @@ -720,10 +720,18 @@ static enum hrtimer_restart rtTimerLinuxHrCallback(struct hrtimer *pHrTimer)
> *
> * @param ulUser Address of the sub-timer structure.
> */
> +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 15, 0)
> +static void rtTimerLinuxStdCallback(struct timer_list *ulUser)
> +#else
> static void rtTimerLinuxStdCallback(unsigned long ulUser)
> +#endif
> {
> +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 15, 0)
> + PRTTIMER pTimer = from_timer(pTimer, ulUser, aSubTimers[iCpu].u.Std.LnxTimer);
> +#else
> PRTTIMERLNXSUBTIMER pSubTimer = (PRTTIMERLNXSUBTIMER)ulUser;
> PRTTIMER pTimer = pSubTimer->pParent;
> +#endif
>
> RTTIMERLNX_LOG(("stdcallback %p\n", pTimer));
> if (RT_UNLIKELY(!rtTimerLnxChangeToCallbackState(pSubTimer)))
>
I finally got it with code that is similar to what you posted. It builds and works.
--- VirtualBox-5.1.30.orig/src/VBox/Runtime/r0drv/linux/timer-r0drv-linux.c
+++ VirtualBox-5.1.30/src/VBox/Runtime/r0drv/linux/timer-r0drv-linux.c
@@ -715,6 +715,14 @@ static enum hrtimer_restart rtTimerLinux
#endif /* RTTIMER_LINUX_WITH_HRTIMER */
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 15, 0)
+/**
+ * Timer callback for kernels 4.15 and later
+ */
+static void rtTimerLinuxStdCallback(struct timer_list *t)
+{
+ PRTTIMERLNXSUBTIMER pSubTimer = from_timer(pSubTimer, t, u.Std.LnxTimer);
+#else
/**
* Timer callback function for standard timers.
*
@@ -723,6 +731,7 @@ static enum hrtimer_restart rtTimerLinux
static void rtTimerLinuxStdCallback(unsigned long ulUser)
{
PRTTIMERLNXSUBTIMER pSubTimer = (PRTTIMERLNXSUBTIMER)ulUser;
+#endif
PRTTIMER pTimer = pSubTimer->pParent;
RTTIMERLNX_LOG(("stdcallback %p\n", pTimer));
@@ -1584,13 +1593,17 @@ RTDECL(int) RTTimerCreateEx(PRTTIMER *pp
else
#endif
{
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0)
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 15, 0)
+
timer_setup(&pTimer->aSubTimers[iCpu].u.Std.LnxTimer,rtTimerLinuxStdCallback,
TIMER_PINNED);
+#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0)
init_timer_pinned(&pTimer->aSubTimers[iCpu].u.Std.LnxTimer);
#else
init_timer(&pTimer->aSubTimers[iCpu].u.Std.LnxTimer);
#endif
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 15, 0)
pTimer->aSubTimers[iCpu].u.Std.LnxTimer.data = (unsigned
long)&pTimer->aSubTimers[iCpu];
pTimer->aSubTimers[iCpu].u.Std.LnxTimer.function =
rtTimerLinuxStdCallback;
+#endif
pTimer->aSubTimers[iCpu].u.Std.LnxTimer.expires = jiffies;
pTimer->aSubTimers[iCpu].u.Std.u64NextTS = 0;
}
More information about the vbox-dev
mailing list