If we should ever compile timing.c for 32 bit inmates, then unsigned long is
the wrong type. A 32 bit type (aka unsigned long on 32 bit) is too small to
hold the result.

This ensures that we won't hit a bug when enabling on 32 bit. Once we will
enable timing.c on 32 bit, we will have to implement 64 bit division
intrinsics.

Signed-off-by: Ralf Ramsauer <[email protected]>
---
 inmates/lib/x86/include/inmate.h |  2 +-
 inmates/lib/x86/timing.c         | 10 +++++-----
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/inmates/lib/x86/include/inmate.h b/inmates/lib/x86/include/inmate.h
index f8208b7d..e57d7271 100644
--- a/inmates/lib/x86/include/inmate.h
+++ b/inmates/lib/x86/include/inmate.h
@@ -241,7 +241,7 @@ void ioapic_pin_set_vector(unsigned int pin,
                           enum ioapic_trigger_mode trigger_mode,
                           unsigned int vector);
 
-unsigned long pm_timer_read(void);
+unsigned long long pm_timer_read(void);
 
 unsigned long tsc_read_ns(void);
 unsigned long tsc_init(void);
diff --git a/inmates/lib/x86/timing.c b/inmates/lib/x86/timing.c
index 2d485e4b..ccdc10e2 100644
--- a/inmates/lib/x86/timing.c
+++ b/inmates/lib/x86/timing.c
@@ -50,7 +50,7 @@
 #define X2APIC_TDCR            0x83e
 
 static unsigned long apic_tick_freq;
-static unsigned long pm_timer_last[SMP_MAX_CPUS];
+static unsigned long long pm_timer_last[SMP_MAX_CPUS];
 static unsigned long pm_timer_overflows[SMP_MAX_CPUS];
 static unsigned long tsc_freq, tsc_overflow;
 static unsigned long tsc_last[SMP_MAX_CPUS];
@@ -92,13 +92,13 @@ unsigned long tsc_init(void)
        return tsc_freq;
 }
 
-unsigned long pm_timer_read(void)
+unsigned long long pm_timer_read(void)
 {
        unsigned int cpu = cpu_id();
-       unsigned long tmr;
+       unsigned long long tmr;
 
-       tmr = ((inl(comm_region->pm_timer_address) & 0x00ffffff) * NS_PER_SEC)
-               / PM_TIMER_HZ;
+       tmr = ((unsigned long long)(inl(comm_region->pm_timer_address)
+               & 0x00ffffff) * NS_PER_SEC) / PM_TIMER_HZ;
        if (tmr < pm_timer_last[cpu])
                pm_timer_overflows[cpu] += PM_TIMER_OVERFLOW;
        pm_timer_last[cpu] = tmr;
-- 
2.22.0

-- 
You received this message because you are subscribed to the Google Groups 
"Jailhouse" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jailhouse-dev/20190612130332.6175-5-ralf.ramsauer%40oth-regensburg.de.
For more options, visit https://groups.google.com/d/optout.

Reply via email to