From patchwork Wed Jun 1 08:56:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tero Kristo X-Patchwork-Id: 9146697 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7D3F960777 for ; Wed, 1 Jun 2016 08:58:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 736471FF60 for ; Wed, 1 Jun 2016 08:58:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 67EBE26538; Wed, 1 Jun 2016 08:58:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.9 required=2.0 tests=BAYES_00,FSL_HELO_HOME, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ED4F51FF60 for ; Wed, 1 Jun 2016 08:58:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757603AbcFAI6S (ORCPT ); Wed, 1 Jun 2016 04:58:18 -0400 Received: from arroyo.ext.ti.com ([198.47.19.12]:50767 "EHLO arroyo.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757537AbcFAI6Q (ORCPT ); Wed, 1 Jun 2016 04:58:16 -0400 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by arroyo.ext.ti.com (8.13.7/8.13.7) with ESMTP id u518vR4d005308; Wed, 1 Jun 2016 03:57:27 -0500 Received: from DLEE70.ent.ti.com (dlemailx.itg.ti.com [157.170.170.113]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id u518vRdg020530; Wed, 1 Jun 2016 03:57:27 -0500 Received: from dlep32.itg.ti.com (157.170.170.100) by DLEE70.ent.ti.com (157.170.170.113) with Microsoft SMTP Server id 14.3.294.0; Wed, 1 Jun 2016 03:57:26 -0500 Received: from gomoku.home (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep32.itg.ti.com (8.14.3/8.13.8) with ESMTP id u518ug0c002676; Wed, 1 Jun 2016 03:57:22 -0500 From: Tero Kristo To: , , , , CC: , , Tero Kristo Subject: [PATCH 13/28] crypto: engine: avoid unnecessary context switches Date: Wed, 1 Jun 2016 11:56:14 +0300 Message-ID: <1464771389-10640-14-git-send-email-t-kristo@ti.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1464771389-10640-1-git-send-email-t-kristo@ti.com> References: <1464771389-10640-1-git-send-email-t-kristo@ti.com> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Crypto engine will now hi-jack the currently running thread for executing crypto functionality. Only if we are not running a thread (in interrupt context) the kthread will be scheduled. This will improve performance of crypto operations using crypto engine. Signed-off-by: Tero Kristo --- crypto/crypto_engine.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/crypto/crypto_engine.c b/crypto/crypto_engine.c index a55c82d..aac5870 100644 --- a/crypto/crypto_engine.c +++ b/crypto/crypto_engine.c @@ -136,6 +136,14 @@ static void crypto_pump_work(struct kthread_work *work) crypto_pump_requests(engine, true); } +static void queue_pump_work(struct crypto_engine *engine) +{ + if (in_interrupt()) + queue_kthread_work(&engine->kworker, &engine->pump_requests); + else + crypto_pump_requests(engine, true); +} + /** * crypto_transfer_request - transfer the new request into the engine queue * @engine: the hardware engine @@ -156,10 +164,11 @@ int crypto_transfer_request(struct crypto_engine *engine, ret = ablkcipher_enqueue_request(&engine->queue, req); + spin_unlock_irqrestore(&engine->queue_lock, flags); + if (!engine->busy && need_pump) - queue_kthread_work(&engine->kworker, &engine->pump_requests); + queue_pump_work(engine); - spin_unlock_irqrestore(&engine->queue_lock, flags); return ret; } EXPORT_SYMBOL_GPL(crypto_transfer_request); @@ -210,7 +219,7 @@ void crypto_finalize_request(struct crypto_engine *engine, req->base.complete(&req->base, err); - queue_kthread_work(&engine->kworker, &engine->pump_requests); + queue_pump_work(engine); } EXPORT_SYMBOL_GPL(crypto_finalize_request); @@ -234,7 +243,7 @@ int crypto_engine_start(struct crypto_engine *engine) engine->running = true; spin_unlock_irqrestore(&engine->queue_lock, flags); - queue_kthread_work(&engine->kworker, &engine->pump_requests); + queue_pump_work(engine); return 0; }