From patchwork Tue Jul 17 17:56:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wang X-Patchwork-Id: 946822 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="uGtOAKcl"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41X6pm1JbHz9s3R for ; Fri, 20 Jul 2018 20:40:16 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:From:Subject:Message-Id:Date: MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=HnLJdPT9DGrSCdxDUDc7grbCtiYO1ocsq3olDuEZACY=; b=uGtOAKclmaQfKH XUHM9Lusyr0tmy0E8Fax5TAao7VGwpEoYm7UswcPpmTAqdDtbSyDFdwwtkuU5TyKMz+wylFWd5N4J VGKDg3WIHLgbC0opJrr+x/yMnkhRz9sY8XeN3X2KsWNU0KHvlEggM/6zRMm4ZHU79/eAaY43Lgatk 8+XdMqX1cA8qKBCkKdEkRTQfITdzu4obvX6B8MUm4aphWvJkUYYRTfpqFM/UT+VQc4f5L67WAKqCR 7er2KCQNYLopyewUeszCUy/1TPc/cHDiAe+0ySSdlpfa1m5EGYQ9nc31VLfrj0DkjRmehIgmb6ZAE Mu5Jx2H0npsj3SypNwPQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fgSpK-0006lm-7m; Fri, 20 Jul 2018 10:39:58 +0000 Received: from mail-yb0-f202.google.com ([209.85.213.202]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1ffUDH-0000Hm-6r for hostap@lists.infradead.org; Tue, 17 Jul 2018 17:56:41 +0000 Received: by mail-yb0-f202.google.com with SMTP id o18-v6so942806ybp.13 for ; Tue, 17 Jul 2018 10:56:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:date:message-id:subject:from:to:cc; bh=JsqUPIAU/t9f3lm9MKDUjGAWVr8x+ePUxHjDl+CELu8=; b=lfNspt02hmlaF/ZendEqwjXPTU6ldNxoKyDiSqkmE9lpDbhQvqAM8lHjN4zC4QkJlf oRpXAmbO6sB1/tNSb32293Yxug3o4O4DpZITmZQ6OB6rpmPCtbkmoyIzNKDPDsHMtRj8 lyccrlbU15XD+3VZqAFr1MRRcdmuzEtLYm7SY+8zGBv7NWBAUygpKcPTvUwaC2BsHpvq dtxmTL8RxZGRqlwq6bv/REbl2+CiEYGP/weprIquS+aw5xQM3jXk3JmKRc4VOWqWkrbb SS4q0US/1SFhDD4mz74wgY7PN72/NTwKIPhjEq3x8/UZKvVqqdyFZ8GBhWlxM0VGHRuT /rNQ== X-Gm-Message-State: AOUpUlFfzy1CHTfxhqHekhPsXrqO2oaN7EZsG+LYG0JmCQV23peMkWYR cb0Gi+z/Os4jal8ivCzHhTTVbuaaA8YWah+GTB8= X-Google-Smtp-Source: AAOMgpegGEDBWkfASMTnispWXJzx9GG/pqv2IP6LZBN/iqwCujiwIvwer0Dgd+ft+UwxzXBaT3Rntt/G65LaGiCHBlA= MIME-Version: 1.0 X-Received: by 2002:a5b:7cf:: with SMTP id t15-v6mr750107ybq.27.1531850187028; Tue, 17 Jul 2018 10:56:27 -0700 (PDT) Date: Tue, 17 Jul 2018 10:56:21 -0700 Message-Id: <20180717175621.167407-1-matthewmwang@chromium.org> X-Mailer: git-send-email 2.18.0.203.gfac676dfb9-goog Subject: [PATCH] Improve roaming logic From: Matthew Wang To: j@w1.fi X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180717_105639_250160_83D2B104 X-CRM114-Status: GOOD ( 16.62 ) X-Spam-Score: 0.2 (/) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [209.85.213.202 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [209.85.213.202 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record 0.2 HEADER_FROM_DIFFERENT_DOMAINS From and EnvelopeFrom 2nd level mail domains are different -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-Mailman-Approved-At: Fri, 20 Jul 2018 03:39:43 -0700 X-BeenThere: hostap@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: hostap@lists.infradead.org, matthewmwang@chromium.org Sender: "Hostap" Errors-To: hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Currently, wpa_supplicant roams too aggressively; the need_to_roam() function will return early with a roaming decision if the difference in signal level or throughput between the current and selected APs is "sufficiently large." In particular, if the selected AP's estimated throughput is more than 5k greater than the current AP's estimated throughput, supplicant will decide to roam. Otherwise, if the selected AP's signal level is less than the current AP's signal level, or the selected AP's estimated throughput is at least 5k less than the current AP's estimated throughput, supplicant will skip the roam. These decisions are based only on one factor and can lead to poor roaming choices (e.g. a roam should not happen if the selected AP's estimated througput meets the threshold but the current signal and throughput are already good, whereas a roam should happen if the signal is slightly worse but the estimated throughput is significantly better). This change standardizes the roaming heuristic and will hopefully improve user WiFi experience. The change can be summarized as follows: based on the current signal level, a certain roaming difficulty is assigned. Based on the selected AP's estimated throughput relative to the current AP's estimated throughput, the difficulty is adjusted up or down. If the difference in signal level meets the threshold, a roam happens. The hard-coded values were selected purely based on the previous version of this function. They may eventually need to be fine-tuned for optimal performance. Signed-off-by: Matthew Wang --- wpa_supplicant/events.c | 65 +++++++++++++---------------------------- 1 file changed, 21 insertions(+), 44 deletions(-) diff --git a/wpa_supplicant/events.c b/wpa_supplicant/events.c index 66d9f88db..a095ee02f 100644 --- a/wpa_supplicant/events.c +++ b/wpa_supplicant/events.c @@ -1683,27 +1683,8 @@ static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s, return 1; } - if (selected->est_throughput > current_bss->est_throughput + 5000) { - wpa_dbg(wpa_s, MSG_DEBUG, - "Allow reassociation - selected BSS has better estimated throughput"); - return 1; - } - to_5ghz = selected->freq > 4000 && current_bss->freq < 4000; - if (current_bss->level < 0 && - current_bss->level > selected->level + to_5ghz * 2) { - wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better " - "signal level"); - return 0; - } - - if (current_bss->est_throughput > selected->est_throughput + 5000) { - wpa_dbg(wpa_s, MSG_DEBUG, - "Skip roam - Current BSS has better estimated throughput"); - return 0; - } - cur_est = current_bss->est_throughput; sel_est = selected->est_throughput; min_diff = 2; @@ -1718,32 +1699,28 @@ static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s, min_diff = 4; else min_diff = 5; - if (cur_est > sel_est * 1.5) - min_diff += 10; - else if (cur_est > sel_est * 1.2) - min_diff += 5; - else if (cur_est > sel_est * 1.1) - min_diff += 2; - else if (cur_est > sel_est) - min_diff++; - } - if (to_5ghz) { - int reduce = 2; - - /* Make it easier to move to 5 GHz band */ - if (sel_est > cur_est * 1.5) - reduce = 5; - else if (sel_est > cur_est * 1.2) - reduce = 4; - else if (sel_est > cur_est * 1.1) - reduce = 3; - - if (min_diff > reduce) - min_diff -= reduce; - else - min_diff = 0; } - diff = abs(current_bss->level - selected->level); + + if (cur_est > sel_est * 1.5) + min_diff += 10; + else if (cur_est > sel_est * 1.2) + min_diff += 5; + else if (cur_est > sel_est * 1.1) + min_diff += 2; + else if (cur_est > sel_est) + min_diff++; + else if (sel_est > cur_est * 1.5) + min_diff -= 10; + else if (sel_est > cur_est * 1.2) + min_diff -= 5; + else if (sel_est > cur_est * 1.1) + min_diff -= 2; + else if (sel_est > cur_est) + min_diff--; + + if (to_5ghz) + min_diff -= 2; + diff = selected->level - current_bss->level; if (diff < min_diff) { wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference in signal level (%d < %d)",