Openembedded Core Discussions
 help / color / mirror / Atom feed
From: "Yu, Mingli" <mingli.yu@windriver.com>
To: <openembedded-core@lists.openembedded.org>
Subject: [PATCH] rng-tools: disable the CPU affinity mask
Date: Mon, 10 May 2021 10:33:10 +0800	[thread overview]
Message-ID: <20210510023310.5516-1-mingli.yu@windriver.com> (raw)

From: Mingli Yu <mingli.yu@windriver.com>

For the jitter entropy source, each task thread will create an internal
counter timer thread when the system clock resolution is under 5MHz.

But it will introduce high cpu usage for a long time and also make random
data generate too slow if sets the CPU affinity mask of the internal counter
timer thread.

There is no solution until now and the Upstream recommends to disable
the internal timer and think Jitter RNG will not work due to the coarse
timer. Check [1] and [2] for more details.

So disable the CPU affinity mask as a workaround to avoid lots of context
switch and too high cpu load for a long time.

[1] https://github.com/smuellerDD/jitterentropy-library/issues/37
[2] https://github.com/nhorman/rng-tools/pull/123

Signed-off-by: Mingli Yu <mingli.yu@windriver.com>
---
 ...tter.c-disable-the-CPU-affinity-mask.patch | 48 +++++++++++++++++++
 .../rng-tools/rng-tools_6.11.bb               |  1 +
 2 files changed, 49 insertions(+)
 create mode 100644 meta/recipes-support/rng-tools/rng-tools/0001-rngd_jitter.c-disable-the-CPU-affinity-mask.patch

diff --git a/meta/recipes-support/rng-tools/rng-tools/0001-rngd_jitter.c-disable-the-CPU-affinity-mask.patch b/meta/recipes-support/rng-tools/rng-tools/0001-rngd_jitter.c-disable-the-CPU-affinity-mask.patch
new file mode 100644
index 0000000000..e5fe1b0021
--- /dev/null
+++ b/meta/recipes-support/rng-tools/rng-tools/0001-rngd_jitter.c-disable-the-CPU-affinity-mask.patch
@@ -0,0 +1,48 @@
+From e44e35dd0b739da8718a5c78e0092bd2feabf5ce Mon Sep 17 00:00:00 2001
+From: Zhantao Tang <zhantao.tang@windriver.com>
+Date: Sun, 25 Apr 2021 11:33:24 +0800
+Subject: [PATCH] rngd_jitter.c: disable the CPU affinity mask
+
+For the jitter entropy source, each task thread will create an internal
+counter timer thread when the system clock resolution is under 5MHz.
+
+But it will introduce high cpu usage for a long time and also make random
+data generate too slow if sets the CPU affinity mask of the internal counter
+timer thread.
+
+So disable the CPU affinity mask to avoid lots of context switch and too
+high cpu load for a long time.
+
+Upstream-Status: Denied[There is no solution until now and Upstream recommend
+                        to disable the internal timer and think Jitter RNG will
+                        not work due to the coarse timer. Check [1] and [2] for
+                        more details]
+
+[1] https://github.com/smuellerDD/jitterentropy-library/issues/37
+[2] https://github.com/nhorman/rng-tools/pull/123
+
+Signed-off-by: Zhantao Tang <zhantao.tang@windriver.com>
+Signed-off-by: Mingli Yu <mingli.yu@windriver.com>
+---
+ rngd_jitter.c | 5 -----
+ 1 file changed, 5 deletions(-)
+
+diff --git a/rngd_jitter.c b/rngd_jitter.c
+index c803f0d..ef03c6c 100644
+--- a/rngd_jitter.c
++++ b/rngd_jitter.c
+@@ -252,11 +252,6 @@ static void *thread_entropy_task(void *data)
+ 		me->slptm.tv_nsec = 0;
+ 	}
+ 
+-	/* fill initial entropy */
+-	CPU_ZERO(&cpuset);
+-	CPU_SET(me->core_id, &cpuset);
+-	pthread_setaffinity_np(pthread_self(), CPU_ALLOC_SIZE(me->core_id+1), &cpuset);
+-
+ 	tmpbuf = malloc(me->buf_sz);
+ 	if (!tmpbuf) {
+ 		message_entsrc(me->ent_src,LOG_DAEMON|LOG_DEBUG, "Unable to allocate temp buffer on cpu %d\n", me->core_id);
+-- 
+2.17.1
+
diff --git a/meta/recipes-support/rng-tools/rng-tools_6.11.bb b/meta/recipes-support/rng-tools/rng-tools_6.11.bb
index 61a0cef2e0..e45a7d12cb 100644
--- a/meta/recipes-support/rng-tools/rng-tools_6.11.bb
+++ b/meta/recipes-support/rng-tools/rng-tools_6.11.bb
@@ -10,6 +10,7 @@ DEPENDS = "sysfsutils openssl"
 
 SRC_URI = "\
     git://github.com/nhorman/rng-tools.git \
+    file://0001-rngd_jitter.c-disable-the-CPU-affinity-mask.patch \
     file://init \
     file://default \
     file://rngd.service \
-- 
2.29.2


             reply	other threads:[~2021-05-10  2:33 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-10  2:33 Yu, Mingli [this message]
2021-05-10  9:48 ` [OE-core] [PATCH] rng-tools: disable the CPU affinity mask Richard Purdie
2021-05-10 13:23   ` Jack Mitchell
2021-05-10 13:34     ` Mikko Rapeli
2021-05-13 15:48     ` Joshua Watt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210510023310.5516-1-mingli.yu@windriver.com \
    --to=mingli.yu@windriver.com \
    --cc=openembedded-core@lists.openembedded.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox