Linux cryptographic layer development
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Huang Ying <ying.huang@intel.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-crypto@vger.kernel.org" <linux-crypto@vger.kernel.org>
Subject: Re: [PATCH 2/3] crypto: Per-CPU cryptd thread implementation based on kcrypto_wq
Date: Tue, 3 Feb 2009 01:10:38 -0800	[thread overview]
Message-ID: <20090203011038.c12acc5b.akpm@linux-foundation.org> (raw)
In-Reply-To: <1233556940.19806.58.camel@yhuang-dev.sh.intel.com>

On Mon, 02 Feb 2009 14:42:20 +0800 Huang Ying <ying.huang@intel.com> wrote:

> Original cryptd thread implementation has scalability issue, this
> patch solve the issue with a per-CPU thread implementation.
> 
> struct cryptd_queue is defined to be a per-CPU queue, which holds one
> struct cryptd_cpu_queue for each CPU. In struct cryptd_cpu_queue, a
> struct crypto_queue holds all requests for the CPU, a struct
> work_struct is used to run all requests for the CPU.
> 
> ...
>
> +int cryptd_init_queue(struct cryptd_queue *queue, unsigned int max_cpu_qlen)
> +{
> +	int cpu;
> +	struct cryptd_cpu_queue *cpu_queue;
> +
> +	queue->cpu_queue = alloc_percpu(struct cryptd_cpu_queue);
> +	if (!queue->cpu_queue)
> +		return -ENOMEM;
> +	for_each_possible_cpu(cpu) {
> +		cpu_queue = per_cpu_ptr(queue->cpu_queue, cpu);
> +		crypto_init_queue(&cpu_queue->queue, max_cpu_qlen);
> +		INIT_WORK(&cpu_queue->work, cryptd_queue_worker);
> +	}
> +	return 0;
> +}

Could be made static, I believe.

> +void cryptd_fini_queue(struct cryptd_queue *queue)
> +{
> +	int cpu;
> +	struct cryptd_cpu_queue *cpu_queue;
> +
> +	for_each_possible_cpu(cpu) {
> +		cpu_queue = per_cpu_ptr(queue->cpu_queue, cpu);
> +		BUG_ON(cpu_queue->queue.qlen);
> +	}
> +	free_percpu(queue->cpu_queue);
> +}

Ditto.

> +int cryptd_enqueue_request(struct cryptd_queue *queue,
> +			   struct crypto_async_request *request)
> +{
> +	int cpu, err;
> +	struct cryptd_cpu_queue *cpu_queue;
> +
> +	cpu = get_cpu();
> +	cpu_queue = per_cpu_ptr(queue->cpu_queue, cpu);
> +	err = crypto_enqueue_request(&cpu_queue->queue, request);
> +	queue_work_on(cpu, kcrypto_wq, &cpu_queue->work);
> +	put_cpu();
> +
> +	return err;
> +}

Ditto?

> +static void cryptd_queue_worker(struct work_struct *work)

A few comments explaining the code wouldn't kill us...

> +{
> +	struct cryptd_cpu_queue *cpu_queue;
> +	struct crypto_async_request *req, *backlog;
> +
> +	cpu_queue = container_of(work, struct cryptd_cpu_queue, work);
> +	/* Only handle one request at a time to avoid hogging crypto
> +	 * workqueue */

Not sure what that means.

> +	preempt_disable();
> +	backlog = crypto_get_backlog(&cpu_queue->queue);
> +	req = crypto_dequeue_request(&cpu_queue->queue);
> +	preempt_enable();

This function is run by a per-cpu thread, so it cannot be migrated to
another CPU by the CPU scheduler.

It is quite unclear what this preempt_disable() is needed for.  Please
either remove it or provide adequate comments.

> +	if (!req)
> +		goto out;
> +
> +	if (backlog)
> +		backlog->complete(backlog, -EINPROGRESS);
> +	req->complete(req, 0);
> +out:
> +	if (cpu_queue->queue.qlen)
> +		queue_work(kcrypto_wq, &cpu_queue->work);

Again, unclear and needs commentary.

If we come here via the `goto out;' path above, this CPU queue has no
more work do do, I think?  If so, why does it requeue itself?

> +}
> +
> 
> ...
>


  reply	other threads:[~2009-02-03  9:11 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-02  6:42 [PATCH 2/3] crypto: Per-CPU cryptd thread implementation based on kcrypto_wq Huang Ying
2009-02-03  9:10 ` Andrew Morton [this message]
2009-02-03  9:21   ` Herbert Xu
2009-02-04  1:07   ` Huang Ying

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=20090203011038.c12acc5b.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ying.huang@intel.com \
    /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