The crypto daemon can take advantage of available cpu
cycles to flush any unfinished jobs if it is the
only task running on the cpu, and there are no more crypto
jobs to process.

Signed-off-by: Tim Chen <[email protected]>
---
 crypto/mcryptd.c | 39 ++++++++++++++++++++++++++++++++++++---
 1 file changed, 36 insertions(+), 3 deletions(-)

diff --git a/crypto/mcryptd.c b/crypto/mcryptd.c
index 622d6b4..dbc20d1 100644
--- a/crypto/mcryptd.c
+++ b/crypto/mcryptd.c
@@ -116,9 +116,40 @@ static int mcryptd_enqueue_request(struct mcryptd_queue 
*queue,
        return err;
 }
 
-/* Called in workqueue context, do one real cryption work (via
+/*
+ * Try to opportunisticlly flush the partially completed jobs if
+ * crypto daemon is the only task running.
+ */
+static void mcryptd_opportunistic_flush(void)
+{
+       struct mcryptd_flush_list *flist;
+       struct mcryptd_alg_cstate *cstate;
+
+       flist = per_cpu_ptr(mcryptd_flist, smp_processor_id());
+       while (single_task_running()) {
+               mutex_lock(&flist->lock);
+               if (list_empty(&flist->list)) {
+                       mutex_unlock(&flist->lock);
+                       return;
+               }
+               cstate = list_entry(flist->list.next,
+                               struct mcryptd_alg_cstate, flush_list);
+               if (!cstate->flusher_engaged) {
+                       mutex_unlock(&flist->lock);
+                       return;
+               }
+               list_del(&cstate->flush_list);
+               cstate->flusher_engaged = false;
+               mutex_unlock(&flist->lock);
+               cstate->alg_state->flusher(cstate);
+       }
+}
+
+/*
+ * Called in workqueue context, do one real cryption work (via
  * req->complete) and reschedule itself if there are more work to
- * do. */
+ * do.
+ */
 static void mcryptd_queue_worker(struct work_struct *work)
 {
        struct mcryptd_cpu_queue *cpu_queue;
@@ -144,8 +175,10 @@ static void mcryptd_queue_worker(struct work_struct *work)
                preempt_enable();
                local_bh_enable();
 
-               if (!req)
+               if (!req) {
+                       mcryptd_opportunistic_flush();
                        return;
+               }
 
                if (backlog)
                        backlog->complete(backlog, -EINPROGRESS);
-- 
1.7.11.7



--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to