* [PATCH 0/2] crypto: replace cpumask_next with better API
@ 2025-06-04 20:47 Yury Norov
2025-06-04 20:47 ` [PATCH 1/2] crypto: pcrypt: Optimize pcrypt_aead_init_tfm() Yury Norov
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Yury Norov @ 2025-06-04 20:47 UTC (permalink / raw)
To: linux-kernel, linux-crypto, Steffen Klassert, Herbert Xu,
David S. Miller, Horia Geantă,
Pankaj Gupta, Gaurav Jain
Cc: Yury Norov [NVIDIA]
From: Yury Norov [NVIDIA] <yury.norov@gmail.com>
Recently added cpumask_next_wrap() and cpumask_nth() work better than
cpumask_next(). Use them where appropriate.
Yury Norov [NVIDIA] (2):
crypto: pcrypt: Optimize pcrypt_aead_init_tfm()
crypto: caam - Fix opencoded cpumask_next_wrap() in
caam_drv_ctx_init()
crypto/pcrypt.c | 7 ++-----
drivers/crypto/caam/qi.c | 5 +----
2 files changed, 3 insertions(+), 9 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH 1/2] crypto: pcrypt: Optimize pcrypt_aead_init_tfm()
2025-06-04 20:47 [PATCH 0/2] crypto: replace cpumask_next with better API Yury Norov
@ 2025-06-04 20:47 ` Yury Norov
2025-06-04 20:47 ` [PATCH 2/2] crypto: caam - Fix opencoded cpumask_next_wrap() in caam_drv_ctx_init() Yury Norov
2025-06-16 2:57 ` [PATCH 0/2] crypto: replace cpumask_next with better API Herbert Xu
2 siblings, 0 replies; 4+ messages in thread
From: Yury Norov @ 2025-06-04 20:47 UTC (permalink / raw)
To: linux-kernel, linux-crypto, Steffen Klassert, Herbert Xu,
David S. Miller, Horia Geantă,
Pankaj Gupta, Gaurav Jain
Cc: Yury Norov [NVIDIA]
From: Yury Norov [NVIDIA] <yury.norov@gmail.com>
The function opencodes cpumask_nth(). The dedicated helper is faster
than an open for-loop.
Signed-off-by: Yury Norov [NVIDIA] <yury.norov@gmail.com>
---
crypto/pcrypt.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
index c33d29a523e0..c3a9d4f2995c 100644
--- a/crypto/pcrypt.c
+++ b/crypto/pcrypt.c
@@ -178,7 +178,7 @@ static int pcrypt_aead_decrypt(struct aead_request *req)
static int pcrypt_aead_init_tfm(struct crypto_aead *tfm)
{
- int cpu, cpu_index;
+ int cpu_index;
struct aead_instance *inst = aead_alg_instance(tfm);
struct pcrypt_instance_ctx *ictx = aead_instance_ctx(inst);
struct pcrypt_aead_ctx *ctx = crypto_aead_ctx(tfm);
@@ -187,10 +187,7 @@ static int pcrypt_aead_init_tfm(struct crypto_aead *tfm)
cpu_index = (unsigned int)atomic_inc_return(&ictx->tfm_count) %
cpumask_weight(cpu_online_mask);
- ctx->cb_cpu = cpumask_first(cpu_online_mask);
- for (cpu = 0; cpu < cpu_index; cpu++)
- ctx->cb_cpu = cpumask_next(ctx->cb_cpu, cpu_online_mask);
-
+ ctx->cb_cpu = cpumask_nth(cpu_index, cpu_online_mask);
cipher = crypto_spawn_aead(&ictx->spawn);
if (IS_ERR(cipher))
--
2.43.0
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH 2/2] crypto: caam - Fix opencoded cpumask_next_wrap() in caam_drv_ctx_init()
2025-06-04 20:47 [PATCH 0/2] crypto: replace cpumask_next with better API Yury Norov
2025-06-04 20:47 ` [PATCH 1/2] crypto: pcrypt: Optimize pcrypt_aead_init_tfm() Yury Norov
@ 2025-06-04 20:47 ` Yury Norov
2025-06-16 2:57 ` [PATCH 0/2] crypto: replace cpumask_next with better API Herbert Xu
2 siblings, 0 replies; 4+ messages in thread
From: Yury Norov @ 2025-06-04 20:47 UTC (permalink / raw)
To: linux-kernel, linux-crypto, Steffen Klassert, Herbert Xu,
David S. Miller, Horia Geantă,
Pankaj Gupta, Gaurav Jain
Cc: Yury Norov [NVIDIA]
From: Yury Norov [NVIDIA] <yury.norov@gmail.com>
The dedicated cpumask_next_wrap() is more verbose and better optimized
comparing to cpumask_next() followed by cpumask_first().
Signed-off-by: Yury Norov [NVIDIA] <yury.norov@gmail.com>
---
drivers/crypto/caam/qi.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/drivers/crypto/caam/qi.c b/drivers/crypto/caam/qi.c
index b6e7c0b29d4e..1e731ed8702b 100644
--- a/drivers/crypto/caam/qi.c
+++ b/drivers/crypto/caam/qi.c
@@ -442,11 +442,8 @@ struct caam_drv_ctx *caam_drv_ctx_init(struct device *qidev,
if (!cpumask_test_cpu(*cpu, cpus)) {
int *pcpu = &get_cpu_var(last_cpu);
- *pcpu = cpumask_next(*pcpu, cpus);
- if (*pcpu >= nr_cpu_ids)
- *pcpu = cpumask_first(cpus);
+ *pcpu = cpumask_next_wrap(*pcpu, cpus);
*cpu = *pcpu;
-
put_cpu_var(last_cpu);
}
drv_ctx->cpu = *cpu;
--
2.43.0
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH 0/2] crypto: replace cpumask_next with better API
2025-06-04 20:47 [PATCH 0/2] crypto: replace cpumask_next with better API Yury Norov
2025-06-04 20:47 ` [PATCH 1/2] crypto: pcrypt: Optimize pcrypt_aead_init_tfm() Yury Norov
2025-06-04 20:47 ` [PATCH 2/2] crypto: caam - Fix opencoded cpumask_next_wrap() in caam_drv_ctx_init() Yury Norov
@ 2025-06-16 2:57 ` Herbert Xu
2 siblings, 0 replies; 4+ messages in thread
From: Herbert Xu @ 2025-06-16 2:57 UTC (permalink / raw)
To: Yury Norov
Cc: linux-kernel, linux-crypto, Steffen Klassert, David S. Miller,
Horia Geantă,
Pankaj Gupta, Gaurav Jain
On Wed, Jun 04, 2025 at 04:47:39PM -0400, Yury Norov wrote:
> From: Yury Norov [NVIDIA] <yury.norov@gmail.com>
>
> Recently added cpumask_next_wrap() and cpumask_nth() work better than
> cpumask_next(). Use them where appropriate.
>
> Yury Norov [NVIDIA] (2):
> crypto: pcrypt: Optimize pcrypt_aead_init_tfm()
> crypto: caam - Fix opencoded cpumask_next_wrap() in
> caam_drv_ctx_init()
>
> crypto/pcrypt.c | 7 ++-----
> drivers/crypto/caam/qi.c | 5 +----
> 2 files changed, 3 insertions(+), 9 deletions(-)
>
> --
> 2.43.0
All applied. Thanks.
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-06-16 2:57 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-06-04 20:47 [PATCH 0/2] crypto: replace cpumask_next with better API Yury Norov
2025-06-04 20:47 ` [PATCH 1/2] crypto: pcrypt: Optimize pcrypt_aead_init_tfm() Yury Norov
2025-06-04 20:47 ` [PATCH 2/2] crypto: caam - Fix opencoded cpumask_next_wrap() in caam_drv_ctx_init() Yury Norov
2025-06-16 2:57 ` [PATCH 0/2] crypto: replace cpumask_next with better API Herbert Xu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®