Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/opencrypto split the "crypto_mtx" spinlock into 3: one s...
details: https://anonhg.NetBSD.org/src/rev/5aea68260ba7
branches: trunk
changeset: 765027:5aea68260ba7
user: drochner <drochner%NetBSD.org@localhost>
date: Mon May 16 10:27:49 2011 +0000
description:
split the "crypto_mtx" spinlock into 3: one spinlock each for
the incoming and outgoing request queues (which can be dealt with
by hardware accelerators) and an adaptive lock for "all the rest"
(mostly driver configuration, but also some unrelated stuff in
cryptodev.c which should be revisited)
The latter one seems to be uneeded at many places, but for now I've
done simple replacements only, except minor fixes (where
softint_schedule() was called without the lock held)
diffstat:
sys/opencrypto/crypto.c | 124 +++++++++++++++++++++------------------
sys/opencrypto/cryptodev.c | 136 ++++++++++++++++++++++----------------------
sys/opencrypto/ocryptodev.c | 8 +-
3 files changed, 138 insertions(+), 130 deletions(-)
diffs (truncated from 1004 to 300 lines):
diff -r 3c5238e0b90b -r 5aea68260ba7 sys/opencrypto/crypto.c
--- a/sys/opencrypto/crypto.c Mon May 16 10:18:52 2011 +0000
+++ b/sys/opencrypto/crypto.c Mon May 16 10:27:49 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: crypto.c,v 1.39 2011/05/06 21:48:46 drochner Exp $ */
+/* $NetBSD: crypto.c,v 1.40 2011/05/16 10:27:49 drochner 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.39 2011/05/06 21:48:46 drochner Exp $");
+__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.40 2011/05/16 10:27:49 drochner Exp $");
#include <sys/param.h>
#include <sys/reboot.h>
@@ -70,6 +70,8 @@
#include <opencrypto/cryptodev.h>
#include <opencrypto/xform.h> /* XXX for M_XDATA */
+kmutex_t crypto_q_mtx;
+kmutex_t crypto_ret_q_mtx;
kcondvar_t cryptoret_cv;
kmutex_t crypto_mtx;
@@ -247,7 +249,9 @@
{
int error;
- mutex_init(&crypto_mtx, MUTEX_DEFAULT, IPL_NET);
+ mutex_init(&crypto_mtx, MUTEX_DEFAULT, IPL_NONE);
+ mutex_init(&crypto_q_mtx, MUTEX_DEFAULT, IPL_NET);
+ mutex_init(&crypto_ret_q_mtx, MUTEX_DEFAULT, IPL_NET);
cv_init(&cryptoret_cv, "crypto_w");
pool_init(&cryptop_pool, sizeof(struct cryptop), 0, 0,
0, "cryptop", NULL, IPL_NET);
@@ -303,7 +307,7 @@
u_int32_t hid, lid;
int err = EINVAL;
- mutex_spin_enter(&crypto_mtx);
+ mutex_enter(&crypto_mtx);
if (crypto_drivers == NULL)
goto done;
@@ -366,7 +370,7 @@
}
}
done:
- mutex_spin_exit(&crypto_mtx);
+ mutex_exit(&crypto_mtx);
return err;
}
@@ -380,7 +384,7 @@
u_int32_t hid;
int err = 0;
- mutex_spin_enter(&crypto_mtx);
+ mutex_enter(&crypto_mtx);
if (crypto_drivers == NULL) {
err = EINVAL;
@@ -415,7 +419,7 @@
memset(&crypto_drivers[hid], 0, sizeof(struct cryptocap));
done:
- mutex_spin_exit(&crypto_mtx);
+ mutex_exit(&crypto_mtx);
return err;
}
@@ -431,7 +435,7 @@
crypto_init(); /* XXX oh, this is foul! */
- mutex_spin_enter(&crypto_mtx);
+ mutex_enter(&crypto_mtx);
for (i = 0; i < crypto_drivers_num; i++)
if (crypto_drivers[i].cc_process == NULL &&
(crypto_drivers[i].cc_flags & CRYPTOCAP_F_CLEANUP) == 0 &&
@@ -442,7 +446,7 @@
if (i == crypto_drivers_num) {
/* Be careful about wrap-around. */
if (2 * crypto_drivers_num <= crypto_drivers_num) {
- mutex_spin_exit(&crypto_mtx);
+ mutex_exit(&crypto_mtx);
printf("crypto: driver count wraparound!\n");
return -1;
}
@@ -450,7 +454,7 @@
newdrv = malloc(2 * crypto_drivers_num *
sizeof(struct cryptocap), M_CRYPTO_DATA, M_NOWAIT|M_ZERO);
if (newdrv == NULL) {
- mutex_spin_exit(&crypto_mtx);
+ mutex_exit(&crypto_mtx);
printf("crypto: no space to expand driver table!\n");
return -1;
}
@@ -471,7 +475,7 @@
if (bootverbose)
printf("crypto: assign driver %u, flags %u\n", i, flags);
- mutex_spin_exit(&crypto_mtx);
+ mutex_exit(&crypto_mtx);
return i;
}
@@ -496,7 +500,7 @@
struct cryptocap *cap;
int err;
- mutex_spin_enter(&crypto_mtx);
+ mutex_enter(&crypto_mtx);
cap = crypto_checkdriver(driverid);
if (cap != NULL &&
@@ -525,7 +529,7 @@
} else
err = EINVAL;
- mutex_spin_exit(&crypto_mtx);
+ mutex_exit(&crypto_mtx);
return err;
}
@@ -544,7 +548,7 @@
struct cryptocap *cap;
int err;
- mutex_spin_enter(&crypto_mtx);
+ mutex_enter(&crypto_mtx);
cap = crypto_checkdriver(driverid);
/* NB: algorithms are in the range [1..max] */
@@ -579,7 +583,7 @@
} else
err = EINVAL;
- mutex_spin_exit(&crypto_mtx);
+ mutex_exit(&crypto_mtx);
return err;
}
@@ -596,7 +600,7 @@
u_int32_t ses;
struct cryptocap *cap;
- mutex_spin_enter(&crypto_mtx);
+ mutex_enter(&crypto_mtx);
cap = crypto_checkdriver(driverid);
if (cap != NULL &&
@@ -625,7 +629,7 @@
} else
err = EINVAL;
- mutex_spin_exit(&crypto_mtx);
+ mutex_exit(&crypto_mtx);
return err;
}
@@ -647,7 +651,7 @@
u_int32_t ses;
struct cryptocap *cap;
- mutex_spin_enter(&crypto_mtx);
+ mutex_enter(&crypto_mtx);
cap = crypto_checkdriver(driverid);
if (cap != NULL) {
for (i = CRYPTO_ALGORITHM_MIN; i <= CRYPTO_ALGORITHM_MAX; i++) {
@@ -667,7 +671,7 @@
} else
err = EINVAL;
- mutex_spin_exit(&crypto_mtx);
+ mutex_exit(&crypto_mtx);
return err;
}
@@ -681,7 +685,7 @@
struct cryptocap *cap;
int needwakeup, err;
- mutex_spin_enter(&crypto_mtx);
+ mutex_spin_enter(&crypto_q_mtx);
cap = crypto_checkdriver(driverid);
if (cap != NULL) {
needwakeup = 0;
@@ -694,12 +698,12 @@
cap->cc_kqblocked = 0;
}
err = 0;
- mutex_spin_exit(&crypto_mtx);
if (needwakeup)
setsoftcrypto(softintr_cookie);
+ mutex_spin_exit(&crypto_q_mtx);
} else {
err = EINVAL;
- mutex_spin_exit(&crypto_mtx);
+ mutex_spin_exit(&crypto_q_mtx);
}
return err;
@@ -715,7 +719,7 @@
u_int32_t hid = CRYPTO_SESID2HID(crp->crp_sid);
int result;
- mutex_spin_enter(&crypto_mtx);
+ mutex_spin_enter(&crypto_q_mtx);
DPRINTF(("crypto_dispatch: crp %p, reqid 0x%x, alg %d\n",
crp, crp->crp_reqid, crp->crp_desc->crd_alg));
@@ -734,7 +738,7 @@
*/
cap = crypto_checkdriver(hid);
if (cap && !cap->cc_qblocked) {
- mutex_spin_exit(&crypto_mtx);
+ mutex_spin_exit(&crypto_q_mtx);
result = crypto_invoke(crp, 0);
if (result == ERESTART) {
/*
@@ -742,11 +746,11 @@
* driver ``blocked'' for cryptop's and put
* the op on the queue.
*/
- mutex_spin_enter(&crypto_mtx);
+ mutex_spin_enter(&crypto_q_mtx);
crypto_drivers[hid].cc_qblocked = 1;
TAILQ_INSERT_HEAD(&crp_q, crp, crp_next);
cryptostats.cs_blocks++;
- mutex_spin_exit(&crypto_mtx);
+ mutex_spin_exit(&crypto_q_mtx);
}
goto out_released;
} else {
@@ -767,8 +771,8 @@
*/
TAILQ_INSERT_TAIL(&crp_q, crp, crp_next);
if (wasempty) {
- mutex_spin_exit(&crypto_mtx);
setsoftcrypto(softintr_cookie);
+ mutex_spin_exit(&crypto_q_mtx);
result = 0;
goto out_released;
}
@@ -776,7 +780,7 @@
result = 0;
}
- mutex_spin_exit(&crypto_mtx);
+ mutex_spin_exit(&crypto_q_mtx);
out_released:
return result;
}
@@ -791,12 +795,12 @@
struct cryptocap *cap;
int result;
- mutex_spin_enter(&crypto_mtx);
+ mutex_spin_enter(&crypto_q_mtx);
cryptostats.cs_kops++;
cap = crypto_checkdriver(krp->krp_hid);
if (cap && !cap->cc_kqblocked) {
- mutex_spin_exit(&crypto_mtx);
+ mutex_spin_exit(&crypto_q_mtx);
result = crypto_kinvoke(krp, 0);
if (result == ERESTART) {
/*
@@ -804,11 +808,11 @@
* driver ``blocked'' for cryptop's and put
* the op on the queue.
*/
- mutex_spin_enter(&crypto_mtx);
+ mutex_spin_enter(&crypto_q_mtx);
crypto_drivers[krp->krp_hid].cc_kqblocked = 1;
TAILQ_INSERT_HEAD(&crp_kq, krp, krp_next);
cryptostats.cs_kblocks++;
- mutex_spin_exit(&crypto_mtx);
+ mutex_spin_exit(&crypto_q_mtx);
}
} else {
/*
@@ -817,7 +821,7 @@
*/
TAILQ_INSERT_TAIL(&crp_kq, krp, krp_next);
result = 0;
- mutex_spin_exit(&crypto_mtx);
+ mutex_spin_exit(&crypto_q_mtx);
}
return result;
@@ -841,7 +845,7 @@
return EINVAL;
}
- mutex_spin_enter(&crypto_mtx);
Home |
Main Index |
Thread Index |
Old Index