aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/bonding
diff options
context:
space:
mode:
authorJiri Pirko <jpirko@redhat.com>2010-05-18 23:26:39 -0400
committerDavid S. Miller <davem@davemloft.net>2010-06-02 07:16:24 -0400
commit097811bb48c7837db94d7fe5d94f0f4b5e19e78c (patch)
tree61701eb46c49d0a2db449be87ae1d114e03ac9f7 /drivers/net/bonding
parent5206e24c2c348d739c31ebed10a741a02bbde9e0 (diff)
bonding: optimize tlb_get_least_loaded_slave
In the worst case, when the first loop breaks an the end of the slave list, the slave list is iterated through twice. This patch reduces this function only to one loop. Also makes it simpler. Signed-off-by: Jiri Pirko <jpirko@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/bonding')
-rw-r--r--drivers/net/bonding/bond_alb.c33
1 files changed, 13 insertions, 20 deletions
diff --git a/drivers/net/bonding/bond_alb.c b/drivers/net/bonding/bond_alb.c
index 40fdc41446cc..25c14c6236f5 100644
--- a/drivers/net/bonding/bond_alb.c
+++ b/drivers/net/bonding/bond_alb.c
@@ -233,34 +233,27 @@ static void tlb_deinitialize(struct bonding *bond)
233 _unlock_tx_hashtbl(bond); 233 _unlock_tx_hashtbl(bond);
234} 234}
235 235
236static long long compute_gap(struct slave *slave)
237{
238 return (s64) (slave->speed << 20) - /* Convert to Megabit per sec */
239 (s64) (SLAVE_TLB_INFO(slave).load << 3); /* Bytes to bits */
240}
241
236/* Caller must hold bond lock for read */ 242/* Caller must hold bond lock for read */
237static struct slave *tlb_get_least_loaded_slave(struct bonding *bond) 243static struct slave *tlb_get_least_loaded_slave(struct bonding *bond)
238{ 244{
239 struct slave *slave, *least_loaded; 245 struct slave *slave, *least_loaded;
240 s64 max_gap; 246 long long max_gap;
241 int i, found = 0; 247 int i;
242
243 /* Find the first enabled slave */
244 bond_for_each_slave(bond, slave, i) {
245 if (SLAVE_IS_OK(slave)) {
246 found = 1;
247 break;
248 }
249 }
250
251 if (!found) {
252 return NULL;
253 }
254 248
255 least_loaded = slave; 249 least_loaded = NULL;
256 max_gap = (s64)(slave->speed << 20) - /* Convert to Megabit per sec */ 250 max_gap = LLONG_MIN;
257 (s64)(SLAVE_TLB_INFO(slave).load << 3); /* Bytes to bits */
258 251
259 /* Find the slave with the largest gap */ 252 /* Find the slave with the largest gap */
260 bond_for_each_slave_from(bond, slave, i, least_loaded) { 253 bond_for_each_slave(bond, slave, i) {
261 if (SLAVE_IS_OK(slave)) { 254 if (SLAVE_IS_OK(slave)) {
262 s64 gap = (s64)(slave->speed << 20) - 255 long long gap = compute_gap(slave);
263 (s64)(SLAVE_TLB_INFO(slave).load << 3); 256
264 if (max_gap < gap) { 257 if (max_gap < gap) {
265 least_loaded = slave; 258 least_loaded = slave;
266 max_gap = gap; 259 max_gap = gap;