Bridge timer performance enhancement
Subsystems (3)
PATCH 1/1 Bridge timer performance enhancement
Existing bridge code was waking up every jiffie then scanning internal structures for what internal timers had expired. This is a waste of CPU especially given the efficient kernel timer interface. With this patch, code should scale better to 1000's of forward table entries and many ports.
- Change Ethernet bridge to use multiple kernel timers.
- Prevent restarting timers during shutdown.
- Keep ordered list of forward table entries, so oldest entries show up first; then only older entries need to be scanned.
- Automatically adjust GC interval to the next entry to delete existing parameter is ignored.
No visible changes to the API or other devices.
net/bridge/br_fdb.c +59 -64
@@ -20,25 +20,19 @@#include <asm/uaccess.h> #include "br_private.h" -static __inline__unsigned long __timeout (struct net_bridge *br) +/* if topology_changing then use forward_delay (default 15 sec) +* otherwise keep longer (default 5 minutes) +*/ +static __inline__unsigned long hold_time (const struct net_bridge *br) { -unsigned long timeout; - - timeout = jiffies - br->ageing_time; -if (br->topology_change) - timeout = jiffies - br->forward_delay; - -return timeout; +return br->topology_change ? br->forward_delay : br->ageing_time; } -static __inline__int has_expired (struct net_bridge *br, -struct net_bridge_fdb_entry *fdb) +static __inline__int has_expired (const struct net_bridge *br, +const struct net_bridge_fdb_entry *fdb) { -if (!fdb->is_static && -time_before_eq (fdb->ageing_timer,__timeout (br))) -return 1 ; - -return 0 ; +return !fdb->is_static + &&time_before_eq (fdb->ageing_timer +hold_time (br), jiffies); } static __inline__ void copy_fdb(struct __fdb_entry *ent,
@@ -52,7 +46,7 @@ static __inline__ void copy_fdb(struct _ : ((jiffies - f->ageing_timer) * USER_HZ) / HZ; } -static __inline__int br_mac_hash (unsigned char *mac) +static __inline__int br_mac_hash (const unsigned char *mac) {unsigned long x;
@@ -68,7 +62,14 @@ static __inline__ int br_mac_hash(unsignreturn x & (BR_HASH_SIZE -1 ); } -void br_fdb_changeaddr (struct net_bridge_port *p,unsigned char *newaddr) +static __inline__void fdb_delete (struct net_bridge_fdb_entry *f) +{ +hlist_del (&f->hlist); +list_del (&f->age_list); +br_fdb_put (f); +} + +void br_fdb_changeaddr (struct net_bridge_port *p,const unsigned char *newaddr) {struct net_bridge *br;int i;
@@ -98,25 +99,29 @@ void br_fdb_changeaddr(struct net_bridgewrite_unlock_bh (&br->hash_lock); } -void br_fdb_cleanup (struct net_bridge *br) +void br_fdb_cleanup (unsigned long _data) { -int i; -unsigned long timeout; - - timeout =__timeout (br); +struct net_bridge *br = (struct net_bridge *)_data; +struct list_head *l, *n; +unsigned long delay;write_lock_bh (&br->hash_lock); -for (i=0 ;i<BR_HASH_SIZE ;i++) { -struct hlist_node *h, *g; - -hlist_for_each_safe (h, g, &br->hash[i]) { -struct net_bridge_fdb_entry *f - = hlist_entry(h, struct net_bridge_fdb_entry, hlist); -if (!f->is_static && -time_before_eq (f->ageing_timer, timeout)) { -hlist_del (&f->hlist); -br_fdb_put (f); + delay =hold_time (br); + +list_for_each_safe (l, n, &br->age_list) { +struct net_bridge_fdb_entry *f + = list_entry(l, struct net_bridge_fdb_entry, age_list); +unsigned long expires = f->ageing_timer + delay; + +if (time_before_eq (expires, jiffies)) { +if (!f->is_static) { +pr_debug ("expire age %lu jiffies %lu\n" , + f->ageing_timer, jiffies); +fdb_delete (f); } + }else { +mod_timer (&br->gc_timer, expires); +break ; } }write_unlock_bh (&br->hash_lock);
@@ -134,8 +139,7 @@ void br_fdb_delete_by_port(struct net_brstruct net_bridge_fdb_entry *f = hlist_entry(h, struct net_bridge_fdb_entry, hlist);if (f->dst == p) { -hlist_del (&f->hlist); -br_fdb_put (f); +fdb_delete (f); } } }
@@ -237,55 +241,46 @@ int br_fdb_get_entries(struct net_bridgereturn num; } -static __inline__void __fdb_possibly_replace (struct net_bridge_fdb_entry *fdb, -struct net_bridge_port *source, -int is_local) -{ -if (!fdb->is_static || is_local) { - fdb->dst = source; - fdb->is_local = is_local; - fdb->is_static = is_local; - fdb->ageing_timer = jiffies; - } -} - -void br_fdb_insert (struct net_bridge *br, -struct net_bridge_port *source, -unsigned char *addr, -int is_local) +void br_fdb_insert (struct net_bridge *br,struct net_bridge_port *source, +const unsigned char *addr,int is_local) {struct hlist_node *h;struct net_bridge_fdb_entry *fdb; -int hash; - - hash =br_mac_hash (addr); +int hash =br_mac_hash (addr);write_lock_bh (&br->hash_lock);hlist_for_each (h, &br->hash[hash]) { fdb = hlist_entry(h, struct net_bridge_fdb_entry, hlist);if (!fdb->is_local && !memcmp (fdb->addr.addr, addr,ETH_ALEN )) { -__fdb_possibly_replace (fdb, source, is_local); -write_unlock_bh (&br->hash_lock); -return ; +if (likely (!fdb->is_static || is_local)) { +/* move to end of age list */ +list_del (&fdb->age_list); + goto update; + } + goto out; } - } fdb =kmalloc (sizeof (*fdb),GFP_ATOMIC ); -if (fdb ==NULL ) { -write_unlock_bh (&br->hash_lock); -return ; - } +if (fdb ==NULL ) + goto out;memcpy (fdb->addr.addr, addr,ETH_ALEN );atomic_set (&fdb->use_count,1 ); +hlist_add_head (&fdb->hlist, &br->hash[hash]); + +if (!timer_pending (&br->gc_timer)) { + br->gc_timer.expires = jiffies +hold_time (br); +add_timer (&br->gc_timer); + } + + update: fdb->dst = source; fdb->is_local = is_local; fdb->is_static = is_local; fdb->ageing_timer = jiffies; - -hlist_add_head (&fdb->hlist, &br->hash[hash]); - +list_add_tail (&fdb->age_list, &br->age_list); + out:write_unlock_bh (&br->hash_lock); }
net/bridge/br_if.c +3 -7
@@ -84,8 +84,6 @@ static struct net_bridge *new_nb(const cmemset (br,0 ,sizeof (*br)); dev = &br->dev; -init_timer (&br->tick); -strncpy (dev->name, name,IFNAMSIZ ); dev->priv = br; dev->priv_flags =IFF_EBRIDGE ;
@@ -109,12 +107,10 @@ static struct net_bridge *new_nb(const c br->bridge_forward_delay = br->forward_delay =15 *HZ ; br->topology_change =0 ; br->topology_change_detected =0 ; -br_timer_clear (&br->hello_timer); -br_timer_clear (&br->tcn_timer); -br_timer_clear (&br->topology_change_timer); - br->ageing_time =300 *HZ ; - br->gc_interval =4 *HZ ; +INIT_LIST_HEAD (&br->age_list); + +br_stp_timer_init (br);return br; }
net/bridge/br_ioctl.c +4 -5
@@ -32,9 +32,10 @@ static inline unsigned long ticks_to_use }/* Report time remaining in user HZ */ -static unsigned long timer_residue (const struct br_timer *timer) +static unsigned long timer_residue (const struct timer_list *timer) { -return ticks_to_user (timer->running ? (jiffies - timer->expires) :0 ); +return ticks_to_user (timer_pending (timer) + ? (timer->expires - jiffies) :0 ); } static int br_ioctl_device(struct net_bridge *br,
@@ -87,7 +88,6 @@ static int br_ioctl_device(struct net_br b.root_port = br->root_port; b.stp_enabled = br->stp_enabled; b.ageing_time =ticks_to_user (br->ageing_time); - b.gc_interval =ticks_to_user (br->gc_interval); b.hello_timer_value =timer_residue (&br->hello_timer); b.tcn_timer_value =timer_residue (&br->tcn_timer); b.topology_change_timer_value =timer_residue (&br->topology_change_timer);
@@ -146,8 +146,7 @@ static int br_ioctl_device(struct net_br br->ageing_time =user_to_ticks (arg0);return 0 ; -case BRCTL_SET_GC_INTERVAL : - br->gc_interval =user_to_ticks (arg0); +case BRCTL_SET_GC_INTERVAL :/* no longer used */ return 0 ;case BRCTL_GET_PORT_INFO :
net/bridge/br_private.h +21 -19
@@ -18,7 +18,6 @@#include <linux/netdevice.h> #include <linux/miscdevice.h> #include <linux/if_bridge.h> -#include "br_private_timer.h" #define BR_HASH_BITS 8#define BR_HASH_SIZE (1 << BR_HASH_BITS)
@@ -44,10 +43,11 @@ struct mac_addrstruct net_bridge_fdb_entry {struct hlist_node hlist; -atomic_t use_count; -mac_addr addr;struct net_bridge_port *dst; +struct list_head age_list; +atomic_t use_count;unsigned long ageing_timer; +mac_addr addr;unsigned is_local:1 ;unsigned is_static:1 ; };
@@ -71,10 +71,9 @@ struct net_bridge_port unsigned config_pending:1;int priority; -struct br_timer forward_delay_timer; -struct br_timer hold_timer; -struct br_timer message_age_timer; - +struct timer_list forward_delay_timer; +struct timer_list hold_timer; +struct timer_list message_age_timer;struct rcu_head rcu; };
@@ -86,7 +85,7 @@ struct net_bridgestruct net_device_stats statistics;rwlock_t hash_lock;struct hlist_head hash[BR_HASH_SIZE ]; -struct timer_list tick; +struct list_head age_list;/* STP */ bridge_id designated_root;
@@ -103,13 +102,12 @@ struct net_bridge unsigned topology_change:1; unsigned topology_change_detected:1; -struct br_timer hello_timer; -struct br_timer tcn_timer; -struct br_timer topology_change_timer; -struct br_timer gc_timer; +struct timer_list hello_timer; +struct timer_list tcn_timer; +struct timer_list topology_change_timer; +struct timer_list gc_timer;int ageing_time; -int gc_interval; };extern struct notifier_block br_device_notifier;
@@ -128,8 +126,8 @@ extern int br_dev_xmit(struct sk_buff *s/* br_fdb.c */ extern void br_fdb_changeaddr (struct net_bridge_port *p, -unsigned char *newaddr); -extern void br_fdb_cleanup (struct net_bridge *br); +const unsigned char *newaddr); +extern void br_fdb_cleanup (unsigned long arg);extern void br_fdb_delete_by_port (struct net_bridge *br,struct net_bridge_port *p); extern struct net_bridge_fdb_entry *br_fdb_get(struct net_bridge *br,
@@ -140,9 +138,9 @@ extern int br_fdb_get_entries(struct neint maxnum, int offset);extern void br_fdb_insert (struct net_bridge *br, -struct net_bridge_port *source, -unsigned char *addr, -int is_local); +struct net_bridge_port *source, +const unsigned char *addr, +int is_local);/* br_forward.c */ extern void br_deliver(const struct net_bridge_port *to,
@@ -188,10 +186,10 @@ extern int br_netfilter_init(void);extern void br_netfilter_fini (void );/* br_stp.c */ +extern void br_log_state (const struct net_bridge_port *p);extern struct net_bridge_port *br_get_port (struct net_bridge *br,int port_no);extern void br_init_port (struct net_bridge_port *p); -extern port_id br_make_port_id (struct net_bridge_port *p);extern void br_become_designated_port (struct net_bridge_port *p);/* br_stp_if.c */
@@ -210,4 +208,8 @@ extern void br_stp_set_path_cost(struct/* br_stp_bpdu.c */ extern void br_stp_handle_bpdu (struct sk_buff *skb); +/* br_stp_timer.c */ +extern void br_stp_timer_init (struct net_bridge *br); +extern void br_stp_port_timer_init (struct net_bridge_port *p); +#endif
net/bridge/br_private_stp.h +0 -1
@@ -47,7 +47,6 @@ extern void br_configuration_update(struextern void br_port_state_selection (struct net_bridge *);extern void br_received_config_bpdu (struct net_bridge_port *p,struct br_config_bpdu *bpdu);extern void br_received_tcn_bpdu (struct net_bridge_port *p); -extern void br_tick (unsigned long __data);extern void br_transmit_config (struct net_bridge_port *p);extern void br_transmit_tcn (struct net_bridge *br);extern void br_topology_change_detection (struct net_bridge *br);
net/bridge/br_private_timer.h +0 -54
54 lines not on this page · raw message
net/bridge/br_stp.c +60 -43
251 lines not on this page · raw message
net/bridge/br_stp_if.c +23 -28
95 lines not on this page · raw message
net/bridge/br_stp_timer.c +93 -91
251 lines not on this page · raw message
From: Stephen Hemminger <[email protected]>
Date: Fri, 9 May 2003 13:20:12 -0700
Existing bridge code was waking up every jiffie then scanning internal structures for what internal timers had expired.
You're going to have to redo the rest of these bridging patches since I'm not going to apply the one which kills off destructor usage.
Stephen,
Seems you are the new maintainer to the bridging code? I suppose Lennert is still still listening in the background somewhere. One thing we should do post 2.6 is move all the STP protocol specific out of the kernel. i.e leave the datapath controllers (such as controlling STP states) in the kernel but have a user sapce daemon. This way you can start adding a lot more feature rich extensions in user space without waiting for kernel releases or having kernel patches (Fast Forward etc). A second item is to start looking at integrating STP with the VLAN code. Too bad Lennert (and someone else - cant remember the name) VLAN code never made it in. We can still fix this.
cheers,
jamal