From mboxrd@z Thu Jan 1 00:00:00 1970 From: Tim Chen Subject: [PATCH v5 3/7] crypto: SHA1 multibuffer crypto opportunistic flush Date: Tue, 22 Jul 2014 15:09:35 -0700 Message-ID: <1406066975.2970.805.camel@schen9-DESK> References: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Cc: Chandramouli Narayanan , Vinodh Gopal , James Guilford , Wajdi Feghali , Tim Chen , Jussi Kivilinna , Thomas Gleixner , Tadeusz Struk , tkhai@yandex.ru, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org To: Herbert Xu , "H. Peter Anvin" , "David S.Miller" , Peter Zijlstra , Ingo Molnar Return-path: In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org List-Id: linux-crypto.vger.kernel.org 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 --- 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