Skip to contentSkip to conversation

Reduce frequency of cleanup timer in bridge

PATCH New Baruch Even 3 participants 4 messages May 19, 2007 – May 31, 2007

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Reduce frequency of cleanup timer in bridge

The bridge cleanup timer is fired 10 times a second for timers that are at least 15 seconds ahead in time and that are not critical to be cleaned asap.

This patch calculates the next time to run the timer as the minimum of all timers or a minimum based on the current state.

net/bridge/br_fdb.c +11 -3
@@ -121,6 +121,7 @@
 {
 	struct net_bridge *br = (struct net_bridge *)_data;
 	unsigned long delay = hold_time(br);
+	unsigned long next_timer = jiffies + br->forward_delay;
 	int i;
 
 	spin_lock_bh(&br->hash_lock);
@@ -129,14 +130,21 @@
 		struct hlist_node *h, *n;
 
 		hlist_for_each_entry_safe(f, h, n, &br->hash[i], hlist) {
+			unsigned long this_timer;
+			if (f->is_static)
+				continue;
+			this_timer = f->ageing_timer + delay;
+			if (time_before_eq(this_timer, jiffies))
-			if (!f->is_static &&
-			    time_before_eq(f->ageing_timer + delay, jiffies))
 				fdb_delete(f);
+			else if (this_timer < next_timer)
+				next_timer = this_timer;
 		}
 	}
 	spin_unlock_bh(&br->hash_lock);
 
+	/* Add HZ/4 to ensure we round the jiffies upwards to be after the next
+	 * timer, otherwise we might round down and will have no-op run. */
+	mod_timer(&br->gc_timer, round_jiffies(next_timer + HZ/4));
-	mod_timer(&br->gc_timer, jiffies + HZ/10);
 }
 
 /* Completely flush all dynamic entries in forwarding database.*/
#1 lore raw

PATCH 1/2 bridge: reduce frequency of forwarding cleanup timer in bridge

The bridge cleanup timer is fired 10 times a second for timers that are at least 15 seconds ahead in time and that are not critical to be cleaned asap.

This patch calculates the next time to run the timer as the minimum of all timers or a minimum based on the current state.

net/bridge/br_fdb.c +11 -3
@@ -121,6 +121,7 @@
 {
 	struct net_bridge *br = (struct net_bridge *)_data;
 	unsigned long delay = hold_time(br);
+	unsigned long next_timer = jiffies + br->forward_delay;
 	int i;
 
 	spin_lock_bh(&br->hash_lock);
@@ -129,14 +130,21 @@
 		struct hlist_node *h, *n;
 
 		hlist_for_each_entry_safe(f, h, n, &br->hash[i], hlist) {
+			unsigned long this_timer;
+			if (f->is_static)
+				continue;
+			this_timer = f->ageing_timer + delay;
+			if (time_before_eq(this_timer, jiffies))
-			if (!f->is_static &&
-			    time_before_eq(f->ageing_timer + delay, jiffies))
 				fdb_delete(f);
+			else if (this_timer < next_timer)
+				next_timer = this_timer;
 		}
 	}
 	spin_unlock_bh(&br->hash_lock);
 
+	/* Add HZ/4 to ensure we round the jiffies upwards to be after the next
+	 * timer, otherwise we might round down and will have no-op run. */
+	mod_timer(&br->gc_timer, round_jiffies(next_timer + HZ/4));
-	mod_timer(&br->gc_timer, jiffies + HZ/10);
 }
 
 /* Completely flush all dynamic entries in forwarding database.*/
#2 lore raw

PATCH 2/2 bridge: round off STP perodic timers

Peroidic STP timers don't have to be exact.
The hold timer runs at 1HZ, and the hello timer normally runs at 2HZ; save power by aligning it them to next second.

---
 net/bridge/br_stp.c       |    3 ++-
 net/bridge/br_stp_timer.c |    2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)
net/bridge/br_stp.c +2 -1
@@ -178,7 +178,8 @@ void br_transmit_config(struct net_bridg
 		br_send_config_bpdu(p, &bpdu);
 		p->topology_change_ack = 0;
 		p->config_pending = 0;
-		mod_timer(&p->hold_timer, jiffies + BR_HOLD_TIME);
+		mod_timer(&p->hold_timer,
+			  round_jiffies(jiffies + BR_HOLD_TIME));
 	}
 }
 
net/bridge/br_stp_timer.c +1 -1
@@ -42,7 +42,7 @@ static void br_hello_timer_expired(unsig
 	if (br->dev->flags & IFF_UP) {
 		br_config_bpdu_generation(br);
 
-		mod_timer(&br->hello_timer, jiffies + br->hello_time);
+		mod_timer(&br->hello_timer, round_jiffies(jiffies + br->hello_time));
 	}
 	spin_unlock(&br->lock);
 }
maintainer Applied
#3 lore raw

Re: [PATCH 2/2] bridge: round off STP perodic timers

From: Stephen Hemminger <[email protected]>
Date: Wed, 30 May 2007 12:14:22 -0700

Quoted 5 lines

Peroidic STP timers don't have to be exact.
The hold timer runs at 1HZ, and the hello timer normally runs at 2HZ; save power by aligning it them to next second.

Applied, thanks Stephen.