Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/opencrypto Reduce crypto_ret_q_mtx lock regions.



details:   https://anonhg.NetBSD.org/src/rev/3296cc2d33b8
branches:  trunk
changeset: 824704:3296cc2d33b8
user:      knakahara <knakahara%NetBSD.org@localhost>
date:      Thu Jun 15 12:45:10 2017 +0000

description:
Reduce crypto_ret_q_mtx lock regions.

crypto.c does not access the members of crp when the crp is in crp_q or
crp_ret_q. Furthermore, crp_q and crp_ret_q are protected by each mutex,
so the members of crp is not shared. That means crp_flags is not required
mutex in crypto.c.

diffstat:

 sys/opencrypto/crypto.c |  16 ++++++++--------
 1 files changed, 8 insertions(+), 8 deletions(-)

diffs (81 lines):

diff -r 885b98653fd0 -r 3296cc2d33b8 sys/opencrypto/crypto.c
--- a/sys/opencrypto/crypto.c   Thu Jun 15 12:41:18 2017 +0000
+++ b/sys/opencrypto/crypto.c   Thu Jun 15 12:45:10 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: crypto.c,v 1.89 2017/06/14 07:38:24 knakahara Exp $ */
+/*     $NetBSD: crypto.c,v 1.90 2017/06/15 12:45:10 knakahara Exp $ */
 /*     $FreeBSD: src/sys/opencrypto/crypto.c,v 1.4.2.5 2003/02/26 00:14:05 sam Exp $   */
 /*     $OpenBSD: crypto.c,v 1.41 2002/07/17 23:52:38 art Exp $ */
 
@@ -53,7 +53,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.89 2017/06/14 07:38:24 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.90 2017/06/15 12:45:10 knakahara Exp $");
 
 #include <sys/param.h>
 #include <sys/reboot.h>
@@ -1494,7 +1494,6 @@
 void
 crypto_done(struct cryptop *crp)
 {
-       int wasempty;
 
        KASSERT(crp != NULL);
 
@@ -1520,9 +1519,7 @@
                * callback routine does very little (e.g. the
                * /dev/crypto callback method just does a wakeup).
                */
-               mutex_spin_enter(&crypto_ret_q_mtx);
                crp->crp_flags |= CRYPTO_F_DONE;
-               mutex_spin_exit(&crypto_ret_q_mtx);
 
 #ifdef CRYPTO_TIMING
                if (crypto_timing) {
@@ -1539,7 +1536,6 @@
 #endif
                crp->crp_callback(crp);
        } else {
-               mutex_spin_enter(&crypto_ret_q_mtx);
                crp->crp_flags |= CRYPTO_F_DONE;
 #if 0
                if (crp->crp_flags & CRYPTO_F_USER) {
@@ -1555,6 +1551,9 @@
                } else
 #endif
                {
+                       int wasempty;
+
+                       mutex_spin_enter(&crypto_ret_q_mtx);
                        wasempty = TAILQ_EMPTY(&crp_ret_q);
                        DPRINTF("lid[%u]: queueing %p\n",
                                CRYPTO_SESID2LID(crp->crp_sid), crp);
@@ -1567,8 +1566,8 @@
                                        CRYPTO_SESID2LID(crp->crp_sid), crp);
                                cv_signal(&cryptoret_cv);
                        }
+                       mutex_spin_exit(&crypto_ret_q_mtx);
                }
-               mutex_spin_exit(&crypto_ret_q_mtx);
        }
 }
 
@@ -1578,7 +1577,6 @@
 void
 crypto_kdone(struct cryptkop *krp)
 {
-       int wasempty;
 
        KASSERT(krp != NULL);
 
@@ -1596,6 +1594,8 @@
        if (krp->krp_flags & CRYPTO_F_CBIMM) {
                krp->krp_callback(krp);
        } else {
+               int wasempty;
+
                mutex_spin_enter(&crypto_ret_q_mtx);
                wasempty = TAILQ_EMPTY(&crp_ret_kq);
                krp->krp_flags |= CRYPTO_F_ONRETQ;



Home | Main Index | Thread Index | Old Index