Hi Oleksij,

Please try the attached patch. No valid ADC randomness will cause the issue.

--
Regards,
Miaoqing


> Hallo all,
>
> on my last train trip i noticed that ath9k-rng produce continuous 15%
> cpu load. Probably two factor coused this issue:
> - my STA was not associated with any AP
> - on the road there is enough noise.
>
> from why i see, this code has all reasons to consume all CPU time it
> get, so far ath9k_rng_data_read can provide some data.
>
>         while (!kthread_should_stop()) {
>                 bytes_read = ath9k_rng_data_read(sc, rng_buf,
>                                                  ATH9K_RNG_BUF_SIZE);
>                 if (unlikely(!bytes_read)) {
>                         msleep_interruptible(10);
>                         continue;
>                 }
>
>                 /* sleep until entropy bits under write_wakeup_threshold
> */
>                 add_hwgenerator_randomness((void *)rng_buf, bytes_read,
>                                            ATH9K_RNG_ENTROPY(bytes_read));
>         }
>
> --
> Regards,
> Oleksij
>
>
>From b915bd98c523c39a6e8dd0a1c5046a6715a724d1 Mon Sep 17 00:00:00 2001
From: Miaoqing Pan <miaoq...@codeaurora.org>
Date: Fri, 11 Mar 2016 17:25:31 +0800
Subject: [PATCH] ath9k: fix rng high cpu load

Signed-off-by: Miaoqing Pan <miaoq...@codeaurora.org>
---
 drivers/net/wireless/ath/ath9k/rng.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/drivers/net/wireless/ath/ath9k/rng.c b/drivers/net/wireless/ath/ath9k/rng.c
index c9cb2aa..cf41f21 100644
--- a/drivers/net/wireless/ath/ath9k/rng.c
+++ b/drivers/net/wireless/ath/ath9k/rng.c
@@ -55,11 +55,24 @@ static int ath9k_rng_data_read(struct ath_softc *sc, u32 *buf, u32 buf_size)
 	return j << 2;
 }
 
+static u32 ath9k_rng_delay_get(u32 fail_stats)
+{
+	if (fail_stats < 100)
+		delay = 10;
+	else if (fail_stats < 105)
+		delay = 1000;
+	else
+		delay = 10000;
+
+	return delay;
+}
+
 static int ath9k_rng_kthread(void *data)
 {
 	int bytes_read;
 	struct ath_softc *sc = data;
 	u32 *rng_buf;
+	u32 delay, fail_stats = 0;
 
 	rng_buf = kmalloc_array(ATH9K_RNG_BUF_SIZE, sizeof(u32), GFP_KERNEL);
 	if (!rng_buf)
@@ -69,10 +82,13 @@ static int ath9k_rng_kthread(void *data)
 		bytes_read = ath9k_rng_data_read(sc, rng_buf,
 						 ATH9K_RNG_BUF_SIZE);
 		if (unlikely(!bytes_read)) {
-			msleep_interruptible(10);
+			delay = ath9k_rng_delay_get(fail_stats++);
+			msleep_interruptible(delay);
 			continue;
 		}
 
+		fail_stats = 0;
+
 		/* sleep until entropy bits under write_wakeup_threshold */
 		add_hwgenerator_randomness((void *)rng_buf, bytes_read,
 					   ATH9K_RNG_ENTROPY(bytes_read));
-- 
1.9.1
_______________________________________________
ath9k-devel mailing list
ath9k-devel@lists.ath9k.org
https://lists.ath9k.org/mailman/listinfo/ath9k-devel

Reply via email to