From patchwork Wed Nov 13 09:54:19 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karl Beldan X-Patchwork-Id: 290884 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 2F35A2C009E for ; Wed, 13 Nov 2013 20:54:56 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759275Ab3KMJyv (ORCPT ); Wed, 13 Nov 2013 04:54:51 -0500 Received: from mail-wg0-f48.google.com ([74.125.82.48]:43965 "EHLO mail-wg0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759211Ab3KMJyt (ORCPT ); Wed, 13 Nov 2013 04:54:49 -0500 Received: by mail-wg0-f48.google.com with SMTP id n12so161101wgh.15 for ; Wed, 13 Nov 2013 01:54:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=bshQAuL6YbuJ3Wi59VePK+urCULS8Ue4JC8zgKLjzjM=; b=i7MwXLpSZer2hbZkcaXfzn8fPI0TEgKTjL2yfRHphVaq3dX90IjWByjIkvko7u0K6q u2eeLv7QV7d5o9e47zX5cqERhTMZ4AGoFwJiXSWDxpExTq3CwbwUUSnuBiTSfSVxgMPG 2etPuHLzTIJjZ3ysLt3zPpb4pBFrRORS1ESKu8tMhnpnPOKNb9sElcx9RhWzYavD54KR uyCzRCIln0/rb8Vf2fdIhagBgC12sypjC306M8TyfcQrV0EXkQgRMqmMaGLQbapTcrv8 SiHCn3EWjslnrHfzjxHJsOciN8G+zAwtO+QjwIEkA4SNN8wU4jKbiKi8cbPt1w5Sjn/Z NPgA== X-Received: by 10.180.182.47 with SMTP id eb15mr18443587wic.51.1384336487566; Wed, 13 Nov 2013 01:54:47 -0800 (PST) Received: from magnum.frso.rivierawaves.com (ppp-seco11pa2-46-193-143.43.wb.wifirst.net. [46.193.143.43]) by mx.google.com with ESMTPSA id dn2sm53204623wid.1.2013.11.13.01.54.46 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Nov 2013 01:54:47 -0800 (PST) From: Karl Beldan To: Johannes Berg Cc: Felix Fietkau , linux-wireless , Hannes Frederic Sowa , netdev@vger.kernel.org, Karl Beldan Subject: [PATCH] mac80211: minstrels: spare numerous useless calls to get_random_bytes Date: Wed, 13 Nov 2013 10:54:19 +0100 Message-Id: <1384336459-5322-1-git-send-email-karl.beldan@gmail.com> X-Mailer: git-send-email 1.8.2 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Karl Beldan ATM, only the first array value returned by get_random_bytes is used. This change moves the call to get_random_bytes from the nested loop it is in to its parent. While at it, replace get_random_bytes with prandom_bytes since PRNs are way enough for the selection process. After this, minstrel_ht reclaims 80 PR-bytes instead of 640 R-bytes. minstrels use sample tables to probe different rates in a randomized manner. minstrel_ht inits one single sample table upon registration (during subsys_initcalls) and minstrel uses one per STA addition in minstrel. Signed-off-by: Karl Beldan --- net/mac80211/rc80211_minstrel.c | 3 +-- net/mac80211/rc80211_minstrel_ht.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/net/mac80211/rc80211_minstrel.c b/net/mac80211/rc80211_minstrel.c index 7fa1b36..d2f19f7 100644 --- a/net/mac80211/rc80211_minstrel.c +++ b/net/mac80211/rc80211_minstrel.c @@ -422,10 +422,9 @@ init_sample_table(struct minstrel_sta_info *mi) memset(mi->sample_table, 0xff, SAMPLE_COLUMNS * mi->n_rates); for (col = 0; col < SAMPLE_COLUMNS; col++) { + prandom_bytes(rnd, sizeof(rnd)); for (i = 0; i < mi->n_rates; i++) { - get_random_bytes(rnd, sizeof(rnd)); new_idx = (i + rnd[i & 7]) % mi->n_rates; - while (SAMPLE_TBL(mi, new_idx, col) != 0xff) new_idx = (new_idx + 1) % mi->n_rates; diff --git a/net/mac80211/rc80211_minstrel_ht.c b/net/mac80211/rc80211_minstrel_ht.c index 5d60779..91912f8 100644 --- a/net/mac80211/rc80211_minstrel_ht.c +++ b/net/mac80211/rc80211_minstrel_ht.c @@ -1052,10 +1052,9 @@ init_sample_table(void) memset(sample_table, 0xff, sizeof(sample_table)); for (col = 0; col < SAMPLE_COLUMNS; col++) { + prandom_bytes(rnd, sizeof(rnd)); for (i = 0; i < MCS_GROUP_RATES; i++) { - get_random_bytes(rnd, sizeof(rnd)); new_idx = (i + rnd[i]) % MCS_GROUP_RATES; - while (sample_table[col][new_idx] != 0xff) new_idx = (new_idx + 1) % MCS_GROUP_RATES;