stp: Fix tick remainder calculation.
authorJustin Pettit <jpettit@nicira.com>
Tue, 15 Nov 2011 08:20:09 +0000 (00:20 -0800)
committerJustin Pettit <jpettit@nicira.com>
Tue, 15 Nov 2011 18:18:04 +0000 (10:18 -0800)
The spanning tree library keeps track of time to know how often it
should update its state and send out BPDUs.  OVS is able to track time
in milliseconds, but STP uses a coarser-grained count (256 ticks per
second).  To prevent losing milliseconds that didn't account for an
entire tick, the library keeps track of these remaining milliseconds.  A
bug miscalculated the remainder and made it too high, which caused the
library to think time was passing more quickly than it was.

This bug wasn't noticeable on a quiet system, since STP only asks to be
woken every second.  However, a system with a lot of activity would wake
OVS more frequently and have it call the subsystems' "run" functions.

Bug #8283

lib/stp.c

index 62c2ea8..3e9a5b6 100644 (file)
--- a/lib/stp.c
+++ b/lib/stp.c
@@ -192,7 +192,6 @@ static void stp_update_bridge_timers(struct stp *);
 
 static int clamp(int x, int min, int max);
 static int ms_to_timer(int ms);
-static int ms_to_timer_remainder(int ms);
 static int timer_to_ms(int timer);
 static void stp_start_timer(struct stp_timer *, int value);
 static void stp_stop_timer(struct stp_timer *);
@@ -281,7 +280,7 @@ stp_tick(struct stp *stp, int ms)
      * are called too frequently. */
     ms = clamp(ms, 0, INT_MAX - 1000) + stp->elapsed_remainder;
     elapsed = ms_to_timer(ms);
-    stp->elapsed_remainder = ms_to_timer_remainder(ms);
+    stp->elapsed_remainder = ms - timer_to_ms(elapsed);
     if (!elapsed) {
         return;
     }
@@ -1253,14 +1252,6 @@ ms_to_timer(int ms)
     return ms * 0x100 / 1000;
 }
 
-/* Returns the number of leftover milliseconds when 'ms' is converted to STP
- * timer ticks. */
-static int
-ms_to_timer_remainder(int ms)
-{
-    return ms * 0x100 % 1000;
-}
-
 /* Returns the number of whole milliseconds in 'timer' STP timer ticks.  There
  * are 256 STP timer ticks per second. */
 static int