From patchwork Tue Jun 2 00:10:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wang X-Patchwork-Id: 1301983 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) 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.a=rsa-sha256 header.s=bombadil.20170209 header.b=PZpgjWRK; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=MB3qxmUs; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49bXWK585xz9sTc for ; Tue, 2 Jun 2020 10:10:53 +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:MIME-Version:Message-Id:Date:Subject:To :From: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=rCrjstkJEz++tZQxpzb/uODMcdPJeRid/J4ttcLeXio=; b=PZpgjWRKJUih8V cT4nSL8TgcZTxqhMb+5NsIvAxWMQSQgiAJ1GaHiEo/7LQFaLRNOXC1amiCKFzb+1OP4GdzFEJXJtx 2NKANuQtfb1Bwr2TFCoKK6bk5XF27jHEb6cv+J1uoFU9ttJsx/NbejIH26pigoarj18Aji3xIHobx MxwmnGZwB9Jo1Rwzqma8jLpPYhNPK8Q9TF4WFMDoa1Q+7QCS7YRRV/XlnV5j2Tqq3B1uIcgNK/V7g cee8Lalr75Gs8ocLIeGJYnzFFh8JhrRH4C0pkUwP5ymZFsdU1vT4a3RWi/W5WdIExUBnivWXQ5KPb I+kjE+Bli3JLTLRoILnA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jfuVj-0006kl-QL; Tue, 02 Jun 2020 00:10:31 +0000 Received: from mail-pj1-x1044.google.com ([2607:f8b0:4864:20::1044]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jfuVd-0006kA-Pw for hostap@lists.infradead.org; Tue, 02 Jun 2020 00:10:28 +0000 Received: by mail-pj1-x1044.google.com with SMTP id s88so561563pjb.5 for ; Mon, 01 Jun 2020 17:10:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=pZkRx16RcaHlbTqvzmRFlqNyVruMfbEdB8ELUjOYecA=; b=MB3qxmUsTN2+/3toC2khGaCK2PBzmyhPsSSkvPOsLrWfW7sRFIX9CtIC8oJEx7OyyY GR8T0vscVucPL1NlivJyZg+CUETn3DMjO2yNQDC5FMGsvF5wzNLfRtYBgRpJ8XLc04lT SFUTX39APC8kCpObTQN/I+cj9TCL0/hwP9ZVs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=pZkRx16RcaHlbTqvzmRFlqNyVruMfbEdB8ELUjOYecA=; b=EhYNHT4oe1g/eA3+MQsoNuFMpHt82XluUVI6WBdEI8XTMX294xaaKJCCd90Sws91wJ iB0ad8rHIz+K7GE73G4fBK7iCnHpJUeHEQiFbBPAPB63Q+aa0JOTw5+fLkl90tzm5d/E blq/Z8OAicrrqE8+n6mzH4oNKlYpKR34lJ4Gf9n/d12a4r0YhkB/TA9Hl+KfhltU/sjK mjgAAHSQA00cVGbgqVeLL67xAWWl1OJtVsj8K2yc9jykPHdYXvHKh2MpQBS8Cg3DR16V dEt4gVKEcii8VT3Ko5oeOuNwVauI/wOmZrejtXJEUn7X4W+8OzfKqJ2Dp1+ge6S8v6XK 30AQ== X-Gm-Message-State: AOAM533Mlo60M+LJ6Fu8T2UTnVsAo57JmgjqICcmZtOhsOJGs3Xtrih7 f1x27Z629lmiHSSeLl95OtUITw== X-Google-Smtp-Source: ABdhPJwmyL07RNrk2F9WipBSUPWH4CkvSR2PVXH07h8+87Z5iotTLM5r5JNAU3xZosUX283AYtMtBw== X-Received: by 2002:a17:902:9e0c:: with SMTP id d12mr23579867plq.29.1591056623289; Mon, 01 Jun 2020 17:10:23 -0700 (PDT) Received: from localhost ([2620:15c:202:201:2b10:8627:31e7:c5ec]) by smtp.gmail.com with ESMTPSA id p31sm517884pgb.46.2020.06.01.17.10.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 01 Jun 2020 17:10:22 -0700 (PDT) From: Matthew Wang To: j@w1.fi Subject: [PATCH 1/6] Use LUT instead of macro Date: Mon, 1 Jun 2020 17:10:13 -0700 Message-Id: <20200602001018.83640-1-matthewmwang@chromium.org> X-Mailer: git-send-email 2.27.0.rc2.251.g90737beb825-goog MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200601_171025_860136_C7BB0E9E X-CRM114-Status: GOOD ( 11.94 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 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 https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:1044 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.0 DKIMWL_WL_HIGH DKIMwl.org - Whitelisted High sender X-BeenThere: hostap@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: hostap@lists.infradead.org, Matthew Wang Sender: "Hostap" Errors-To: hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Change INTERPOLATE_RATE macro to a lookup-table instead for the sake of readability. Signed-off-by: Matthew Wang --- wpa_supplicant/scan.c | 127 ++++++++++++++++++++++++++---------------- 1 file changed, 79 insertions(+), 48 deletions(-) diff --git a/wpa_supplicant/scan.c b/wpa_supplicant/scan.c index b47573094..85513779f 100644 --- a/wpa_supplicant/scan.c +++ b/wpa_supplicant/scan.c @@ -2186,6 +2186,63 @@ void scan_snr(struct wpa_scan_res *res) } } +/* Minimum SNR required to achieve a certain bitrate. */ +struct minsnr_bitrate_entry { + int minsnr; + unsigned int bitrate; /* in Mbps */ +}; + + +/* VHT needs to be enabled in order to achieve MCS8 and MCS9 rates. */ +static const int vht_mcs = 8; + + +static struct minsnr_bitrate_entry vht20_table[] = { + {0, 0}, + {2, 6500}, /* HT20 MCS0 */ + {5, 13000}, /* HT20 MCS1 */ + {9, 19500}, /* HT20 MCS2 */ + {11, 26000}, /* HT20 MCS3 */ + {15, 39000}, /* HT20 MCS4 */ + {18, 52000}, /* HT20 MCS5 */ + {20, 58500}, /* HT20 MCS6 */ + {25, 65000}, /* HT20 MCS7 */ + {29, 78000}, /* VHT20 MCS8 */ + {-1, 78000} /* SNR > 29 */ +}; + + +static struct minsnr_bitrate_entry vht40_table[] = { + {0, 0}, + {5, 13500}, /* HT40 MCS0 */ + {8, 27000}, /* HT40 MCS1 */ + {12, 40500}, /* HT40 MCS2 */ + {14, 54000}, /* HT40 MCS3 */ + {18, 81000}, /* HT40 MCS4 */ + {21, 108000}, /* HT40 MCS5 */ + {23, 121500}, /* HT40 MCS6 */ + {28, 135000}, /* HT40 MCS7 */ + {32, 162000}, /* VHT40 MCS8 */ + {34, 180000}, /* VHT40 MCS9 */ + {-1, 180000} /* SNR > 34 */ +}; + + +static struct minsnr_bitrate_entry vht80_table[] = { + {0, 0}, + {8, 29300}, /* VHT80 MCS0 */ + {11, 58500}, /* VHT80 MCS1 */ + {15, 87800}, /* VHT80 MCS2 */ + {17, 117000}, /* VHT80 MCS3 */ + {21, 175500}, /* VHT80 MCS4 */ + {24, 234000}, /* VHT80 MCS5 */ + {26, 263300}, /* VHT80 MCS6 */ + {31, 292500}, /* VHT80 MCS7 */ + {35, 351000}, /* VHT80 MCS8 */ + {37, 390000}, /* VHT80 MCS9 */ + {-1, 390000} /* SNR > 37 */ +}; + static unsigned int interpolate_rate(int snr, int snr0, int snr1, int rate0, int rate1) @@ -2194,67 +2251,41 @@ static unsigned int interpolate_rate(int snr, int snr0, int snr1, } -#define INTERPOLATE_RATE(snr0, snr1, rate0, rate1) \ - if (snr < (snr1)) \ - return interpolate_rate(snr, (snr0), (snr1), (rate0), (rate1)) +static unsigned int max_rate(struct minsnr_bitrate_entry table[], + int snr, int vht) +{ + struct minsnr_bitrate_entry *prev, *entry = table; + + while ((entry->minsnr != -1) && + (snr >= entry->minsnr) && + (vht || entry - table <= vht_mcs)) + entry++; + if (entry == table) + return entry->bitrate; + prev = entry - 1; + if (entry->minsnr == -1 || (!vht && entry - table > vht_mcs)) + return prev->bitrate; + return interpolate_rate(snr, prev->minsnr, entry->minsnr, prev->bitrate, + entry->bitrate); +} + static unsigned int max_ht20_rate(int snr, int vht) { - if (snr < 0) - return 0; - INTERPOLATE_RATE(0, 2, 0, 6500); /* HT20 MCS0 */ - INTERPOLATE_RATE(2, 5, 6500, 13000); /* HT20 MCS1 */ - INTERPOLATE_RATE(5, 9, 13000, 19500); /* HT20 MCS2 */ - INTERPOLATE_RATE(9, 11, 19500, 26000); /* HT20 MCS3 */ - INTERPOLATE_RATE(11, 15, 26000, 39000); /* HT20 MCS4 */ - INTERPOLATE_RATE(15, 18, 39000, 52000); /* HT20 MCS5 */ - INTERPOLATE_RATE(18, 20, 52000, 58500); /* HT20 MCS6 */ - INTERPOLATE_RATE(20, 25, 58500, 65000); /* HT20 MCS7 */ - if (!vht) - return 65000; - INTERPOLATE_RATE(25, 29, 65000, 78000); /* VHT20 MCS8 */ - return 78000; + return max_rate(vht20_table, snr, vht); } static unsigned int max_ht40_rate(int snr, int vht) { - if (snr < 0) - return 0; - INTERPOLATE_RATE(0, 5, 0, 13500); /* HT40 MCS0 */ - INTERPOLATE_RATE(5, 8, 13500, 27000); /* HT40 MCS1 */ - INTERPOLATE_RATE(8, 12, 27000, 40500); /* HT40 MCS2 */ - INTERPOLATE_RATE(12, 14, 40500, 54000); /* HT40 MCS3 */ - INTERPOLATE_RATE(14, 18, 54000, 81000); /* HT40 MCS4 */ - INTERPOLATE_RATE(18, 21, 81000, 108000); /* HT40 MCS5 */ - INTERPOLATE_RATE(21, 23, 108000, 121500); /* HT40 MCS6 */ - INTERPOLATE_RATE(23, 28, 121500, 135000); /* HT40 MCS7 */ - if (!vht) - return 135000; - INTERPOLATE_RATE(28, 32, 135000, 162000); /* VHT40 MCS8 */ - INTERPOLATE_RATE(32, 34, 162000, 180000); /* VHT40 MCS9 */ - return 180000; + return max_rate(vht40_table, snr, vht); } static unsigned int max_vht80_rate(int snr) { - if (snr < 0) - return 0; - INTERPOLATE_RATE(0, 8, 0, 29300); /* VHT80 MCS0 */ - INTERPOLATE_RATE(8, 11, 29300, 58500); /* VHT80 MCS1 */ - INTERPOLATE_RATE(11, 15, 58500, 87800); /* VHT80 MCS2 */ - INTERPOLATE_RATE(15, 17, 87800, 117000); /* VHT80 MCS3 */ - INTERPOLATE_RATE(17, 21, 117000, 175500); /* VHT80 MCS4 */ - INTERPOLATE_RATE(21, 24, 175500, 234000); /* VHT80 MCS5 */ - INTERPOLATE_RATE(24, 26, 234000, 263300); /* VHT80 MCS6 */ - INTERPOLATE_RATE(26, 31, 263300, 292500); /* VHT80 MCS7 */ - INTERPOLATE_RATE(31, 35, 292500, 351000); /* VHT80 MCS8 */ - INTERPOLATE_RATE(35, 37, 351000, 390000); /* VHT80 MCS9 */ - return 390000; -} - -#undef INTERPOLATE_RATE + return max_rate(vht80_table, snr, 1); +} unsigned int wpas_get_est_tpt(const struct wpa_supplicant *wpa_s,