All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] random: avoid reading two cache lines on irq randomness
@ 2022-09-23 18:28 Jason A. Donenfeld
  2022-09-28 11:37 ` Sebastian Andrzej Siewior
  0 siblings, 1 reply; 2+ messages in thread
From: Jason A. Donenfeld @ 2022-09-23 18:28 UTC (permalink / raw)
  To: linux-kernel
  Cc: Jason A. Donenfeld, Sebastian Andrzej Siewior, Sultan Alsawaf

In order to avoid reading and dirtying two cache lines on every IRQ, move
the work_struct to the bottom of the fast_pool struct. add_interrupt_
randomness() always touches .pool and .count, which are currently split,
because .mix pushes everything down. Instead, move .mix to the bottom,
so that .pool and .count are always in the first cache line, since the
.mix is only accessed when the pool is full.

Fixes: 58340f8e952b ("random: defer fast pool mixing to worker")
Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: Sultan Alsawaf <sultan@kerneltoast.com>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
 drivers/char/random.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/char/random.c b/drivers/char/random.c
index 2f370aa248b2..a90d96f4b3bb 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -918,10 +918,10 @@ EXPORT_SYMBOL_GPL(unregister_random_vmfork_notifier);
 #endif
 
 struct fast_pool {
-	struct work_struct mix;
 	unsigned long pool[4];
 	unsigned long last;
 	unsigned int count;
+	struct work_struct mix;
 };
 
 static DEFINE_PER_CPU(struct fast_pool, irq_randomness) = {
-- 
2.37.3


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] random: avoid reading two cache lines on irq randomness
  2022-09-23 18:28 [PATCH] random: avoid reading two cache lines on irq randomness Jason A. Donenfeld
@ 2022-09-28 11:37 ` Sebastian Andrzej Siewior
  0 siblings, 0 replies; 2+ messages in thread
From: Sebastian Andrzej Siewior @ 2022-09-28 11:37 UTC (permalink / raw)
  To: Jason A. Donenfeld; +Cc: linux-kernel, Sultan Alsawaf

On 2022-09-23 20:28:49 [+0200], Jason A. Donenfeld wrote:
> In order to avoid reading and dirtying two cache lines on every IRQ, move
> the work_struct to the bottom of the fast_pool struct. add_interrupt_
> randomness() always touches .pool and .count, which are currently split,
> because .mix pushes everything down. Instead, move .mix to the bottom,
> so that .pool and .count are always in the first cache line, since the
> .mix is only accessed when the pool is full.
> 
> Fixes: 58340f8e952b ("random: defer fast pool mixing to worker")
> Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> Cc: Sultan Alsawaf <sultan@kerneltoast.com>
> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>

Reviewed-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>

Yup, makes sense.

Sebastian

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-09-28 11:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-23 18:28 [PATCH] random: avoid reading two cache lines on irq randomness Jason A. Donenfeld
2022-09-28 11:37 ` Sebastian Andrzej Siewior

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.