Commit 097811bb authored by Jiri Pirko's avatar Jiri Pirko Committed by David S. Miller

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: default avatarJiri Pirko <jpirko@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 5206e24c
...@@ -233,34 +233,27 @@ static void tlb_deinitialize(struct bonding *bond) ...@@ -233,34 +233,27 @@ static void tlb_deinitialize(struct bonding *bond)
_unlock_tx_hashtbl(bond); _unlock_tx_hashtbl(bond);
} }
static long long compute_gap(struct slave *slave)
{
return (s64) (slave->speed << 20) - /* Convert to Megabit per sec */
(s64) (SLAVE_TLB_INFO(slave).load << 3); /* Bytes to bits */
}
/* Caller must hold bond lock for read */ /* Caller must hold bond lock for read */
static struct slave *tlb_get_least_loaded_slave(struct bonding *bond) static struct slave *tlb_get_least_loaded_slave(struct bonding *bond)
{ {
struct slave *slave, *least_loaded; struct slave *slave, *least_loaded;
s64 max_gap; long long max_gap;
int i, found = 0; int i;
/* Find the first enabled slave */
bond_for_each_slave(bond, slave, i) {
if (SLAVE_IS_OK(slave)) {
found = 1;
break;
}
}
if (!found) {
return NULL;
}
least_loaded = slave; least_loaded = NULL;
max_gap = (s64)(slave->speed << 20) - /* Convert to Megabit per sec */ max_gap = LLONG_MIN;
(s64)(SLAVE_TLB_INFO(slave).load << 3); /* Bytes to bits */
/* Find the slave with the largest gap */ /* Find the slave with the largest gap */
bond_for_each_slave_from(bond, slave, i, least_loaded) { bond_for_each_slave(bond, slave, i) {
if (SLAVE_IS_OK(slave)) { if (SLAVE_IS_OK(slave)) {
s64 gap = (s64)(slave->speed << 20) - long long gap = compute_gap(slave);
(s64)(SLAVE_TLB_INFO(slave).load << 3);
if (max_gap < gap) { if (max_gap < gap) {
least_loaded = slave; least_loaded = slave;
max_gap = gap; max_gap = gap;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment