> Date: Thu, 20 Jul 2017 16:27:20 +0200 (CEST)
> From: Mark Kettenis <mark.kette...@xs4all.nl>
> 
> > Date: Thu, 20 Jul 2017 15:51:55 +0300
> > From: Paul Irofti <p...@irofti.net>
> > 
> > > >Fix:
> > >   Unknown.
> > 
> > Here is a potential fix.
> 
> Can you try this diff instead?

Hmm, this still suffers from potential wraparound issues since "ticks"
is an int, but "jiffies" is supposed to be a volatile unsigned long.
I don't really like infecting the core kernel code with Linux compat
API goo, but in this case I think all the alternatives are worse.
Perhaps in the long run we want to make ticks a volatile unsigned long
as well.

ok?


Index: kern/kern_clock.c
===================================================================
RCS file: /cvs/src/sys/kern/kern_clock.c,v
retrieving revision 1.92
diff -u -p -r1.92 kern_clock.c
--- kern/kern_clock.c   5 Apr 2017 03:59:13 -0000       1.92
+++ kern/kern_clock.c   20 Jul 2017 18:15:06 -0000
@@ -103,6 +103,8 @@ int psratio;                        /* ratio: prof / stat */
 
 void   *softclock_si;
 
+volatile unsigned long jiffies;                /* XXX Linux API for drm(4) */
+
 /*
  * Initialize clock frequencies and start both clocks running.
  */
@@ -116,6 +118,7 @@ initclocks(void)
                panic("initclocks: unable to register softclock intr");
 
        ticks = INT_MAX - (15 * 60 * hz);
+       jiffies = ULONG_MAX - (10 * 60 * hz);
 
        /*
         * Set divisors to 1 (normal case) and let the machine-specific
@@ -194,6 +197,7 @@ hardclock(struct clockframe *frame)
 
        tc_ticktock();
        ticks++;
+       jiffies++;
 
        /*
         * Update real-time timeout queue.
Index: dev/pci/drm/drmP.h
===================================================================
RCS file: /cvs/src/sys/dev/pci/drm/drmP.h,v
retrieving revision 1.214
diff -u -p -r1.214 drmP.h
--- dev/pci/drm/drmP.h  19 Jul 2017 22:05:58 -0000      1.214
+++ dev/pci/drm/drmP.h  20 Jul 2017 18:15:06 -0000
@@ -122,8 +122,6 @@ struct fb_image;
 
 #define DRM_WAKEUP(x)          wakeup(x)
 
-extern int ticks;
-
 #define drm_msleep(x)          mdelay(x)
 
 extern struct cfdriver drm_cd;
Index: dev/pci/drm/drm_linux.h
===================================================================
RCS file: /cvs/src/sys/dev/pci/drm/drm_linux.h,v
retrieving revision 1.57
diff -u -p -r1.57 drm_linux.h
--- dev/pci/drm/drm_linux.h     17 Jul 2017 17:57:27 -0000      1.57
+++ dev/pci/drm/drm_linux.h     20 Jul 2017 18:15:06 -0000
@@ -839,8 +839,7 @@ timespec_sub(struct timespec t1, struct 
 
 #define time_in_range(x, min, max) ((x) >= (min) && (x) <= (max))
 
-extern int ticks;
-#define jiffies ticks
+extern volatile unsigned long jiffies;
 #undef HZ
 #define HZ     hz
 
@@ -858,10 +857,10 @@ round_jiffies_up_relative(unsigned long 
        return roundup(j, hz);
 }
 
-#define jiffies_to_msecs(x)    (((int64_t)(x)) * 1000 / hz)
-#define jiffies_to_usecs(x)    (((int64_t)(x)) * 1000000 / hz)
-#define msecs_to_jiffies(x)    (((int64_t)(x)) * hz / 1000)
-#define nsecs_to_jiffies64(x)  (((int64_t)(x)) * hz / 1000000000)
+#define jiffies_to_msecs(x)    (((uint64_t)(x)) * 1000 / hz)
+#define jiffies_to_usecs(x)    (((uint64_t)(x)) * 1000000 / hz)
+#define msecs_to_jiffies(x)    (((uint64_t)(x)) * hz / 1000)
+#define nsecs_to_jiffies64(x)  (((uint64_t)(x)) * hz / 1000000000)
 #define get_jiffies_64()       jiffies
 #define time_after(a,b)                ((long)(b) - (long)(a) < 0)
 #define time_after_eq(a,b)     ((long)(b) - (long)(a) <= 0)
@@ -886,7 +885,7 @@ timespec_to_ns(const struct timespec *ts
        return ((ts->tv_sec * NSEC_PER_SEC) + ts->tv_nsec);
 }
 
-static inline int
+static inline unsigned long
 timespec_to_jiffies(const struct timespec *ts)
 {
        long long to_ticks;

Reply via email to