mirror of
https://github.com/opnsense/src.git
synced 2026-06-08 16:22:46 -04:00
use a straight buffer instead of an iov w/ 1 segment... The aesni
driver when it hits a mbuf/iov buffer, it mallocs and copies the data for processing.. This improves perf by ~8-10% on my machine... I have thoughts of fixing AES-NI so that it can better handle segmented buffers, which should help improve IPSEC performance, but that is for the future...
This commit is contained in:
parent
e85326216f
commit
89fac384c8
3 changed files with 10 additions and 56 deletions
|
|
@ -32,7 +32,6 @@ __FBSDID("$FreeBSD$");
|
|||
#include <sys/systm.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/uio.h>
|
||||
#else
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
|
@ -63,8 +62,6 @@ g_eli_crypto_cipher(u_int algo, int enc, u_char *data, size_t datasize,
|
|||
struct cryptoini cri;
|
||||
struct cryptop *crp;
|
||||
struct cryptodesc *crd;
|
||||
struct uio *uio;
|
||||
struct iovec *iov;
|
||||
uint64_t sid;
|
||||
u_char *p;
|
||||
int error;
|
||||
|
|
@ -79,24 +76,13 @@ g_eli_crypto_cipher(u_int algo, int enc, u_char *data, size_t datasize,
|
|||
error = crypto_newsession(&sid, &cri, CRYPTOCAP_F_SOFTWARE);
|
||||
if (error != 0)
|
||||
return (error);
|
||||
p = malloc(sizeof(*crp) + sizeof(*crd) + sizeof(*uio) + sizeof(*iov),
|
||||
M_ELI, M_NOWAIT | M_ZERO);
|
||||
p = malloc(sizeof(*crp) + sizeof(*crd), M_ELI, M_NOWAIT | M_ZERO);
|
||||
if (p == NULL) {
|
||||
crypto_freesession(sid);
|
||||
return (ENOMEM);
|
||||
}
|
||||
crp = (struct cryptop *)p; p += sizeof(*crp);
|
||||
crd = (struct cryptodesc *)p; p += sizeof(*crd);
|
||||
uio = (struct uio *)p; p += sizeof(*uio);
|
||||
iov = (struct iovec *)p; p += sizeof(*iov);
|
||||
|
||||
iov->iov_len = datasize;
|
||||
iov->iov_base = data;
|
||||
|
||||
uio->uio_iov = iov;
|
||||
uio->uio_iovcnt = 1;
|
||||
uio->uio_segflg = UIO_SYSSPACE;
|
||||
uio->uio_resid = datasize;
|
||||
|
||||
crd->crd_skip = 0;
|
||||
crd->crd_len = datasize;
|
||||
|
|
@ -114,8 +100,8 @@ g_eli_crypto_cipher(u_int algo, int enc, u_char *data, size_t datasize,
|
|||
crp->crp_olen = datasize;
|
||||
crp->crp_opaque = NULL;
|
||||
crp->crp_callback = g_eli_crypto_done;
|
||||
crp->crp_buf = (void *)uio;
|
||||
crp->crp_flags = CRYPTO_F_IOV | CRYPTO_F_CBIFSYNC | CRYPTO_F_REL;
|
||||
crp->crp_buf = (void *)data;
|
||||
crp->crp_flags = CRYPTO_F_CBIFSYNC | CRYPTO_F_REL;
|
||||
crp->crp_desc = crd;
|
||||
|
||||
error = crypto_dispatch(crp);
|
||||
|
|
|
|||
|
|
@ -41,7 +41,6 @@ __FBSDID("$FreeBSD$");
|
|||
#include <sys/proc.h>
|
||||
#include <sys/sched.h>
|
||||
#include <sys/smp.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/vnode.h>
|
||||
|
||||
#include <vm/uma.h>
|
||||
|
|
@ -363,8 +362,6 @@ g_eli_auth_read(struct g_eli_softc *sc, struct bio *bp)
|
|||
size += sizeof(struct cryptop) * nsec;
|
||||
size += sizeof(struct cryptodesc) * nsec * 2;
|
||||
size += G_ELI_AUTH_SECKEYLEN * nsec;
|
||||
size += sizeof(struct uio) * nsec;
|
||||
size += sizeof(struct iovec) * nsec;
|
||||
cbp->bio_offset = (bp->bio_offset / bp->bio_to->sectorsize) * sc->sc_bytes_per_sector;
|
||||
bp->bio_driver2 = malloc(size, M_ELI, M_WAITOK);
|
||||
cbp->bio_data = bp->bio_driver2;
|
||||
|
|
@ -409,8 +406,6 @@ g_eli_auth_run(struct g_eli_worker *wr, struct bio *bp)
|
|||
struct g_eli_softc *sc;
|
||||
struct cryptop *crp;
|
||||
struct cryptodesc *crde, *crda;
|
||||
struct uio *uio;
|
||||
struct iovec *iov;
|
||||
u_int i, lsec, nsec, data_secsize, decr_secsize, encr_secsize;
|
||||
off_t dstoff;
|
||||
int err, error;
|
||||
|
|
@ -449,8 +444,6 @@ g_eli_auth_run(struct g_eli_worker *wr, struct bio *bp)
|
|||
size += sizeof(*crde) * nsec;
|
||||
size += sizeof(*crda) * nsec;
|
||||
size += G_ELI_AUTH_SECKEYLEN * nsec;
|
||||
size += sizeof(*uio) * nsec;
|
||||
size += sizeof(*iov) * nsec;
|
||||
data = malloc(size, M_ELI, M_WAITOK);
|
||||
bp->bio_driver2 = data;
|
||||
p = data + encr_secsize * nsec;
|
||||
|
|
@ -464,8 +457,6 @@ g_eli_auth_run(struct g_eli_worker *wr, struct bio *bp)
|
|||
crde = (struct cryptodesc *)p; p += sizeof(*crde);
|
||||
crda = (struct cryptodesc *)p; p += sizeof(*crda);
|
||||
authkey = (u_char *)p; p += G_ELI_AUTH_SECKEYLEN;
|
||||
uio = (struct uio *)p; p += sizeof(*uio);
|
||||
iov = (struct iovec *)p; p += sizeof(*iov);
|
||||
|
||||
data_secsize = sc->sc_data_per_sector;
|
||||
if ((i % lsec) == 0)
|
||||
|
|
@ -482,21 +473,13 @@ g_eli_auth_run(struct g_eli_worker *wr, struct bio *bp)
|
|||
plaindata += data_secsize;
|
||||
}
|
||||
|
||||
iov->iov_len = sc->sc_alen + data_secsize;
|
||||
iov->iov_base = data;
|
||||
data += encr_secsize;
|
||||
|
||||
uio->uio_iov = iov;
|
||||
uio->uio_iovcnt = 1;
|
||||
uio->uio_segflg = UIO_SYSSPACE;
|
||||
uio->uio_resid = iov->iov_len;
|
||||
|
||||
crp->crp_sid = wr->w_sid;
|
||||
crp->crp_ilen = uio->uio_resid;
|
||||
crp->crp_ilen = sc->sc_alen + data_secsize;
|
||||
crp->crp_olen = data_secsize;
|
||||
crp->crp_opaque = (void *)bp;
|
||||
crp->crp_buf = (void *)uio;
|
||||
crp->crp_flags = CRYPTO_F_IOV | CRYPTO_F_CBIFSYNC | CRYPTO_F_REL;
|
||||
crp->crp_buf = (void *)data;
|
||||
data += encr_secsize;
|
||||
crp->crp_flags = CRYPTO_F_CBIFSYNC | CRYPTO_F_REL;
|
||||
if (g_eli_batch)
|
||||
crp->crp_flags |= CRYPTO_F_BATCH;
|
||||
if (bp->bio_cmd == BIO_WRITE) {
|
||||
|
|
|
|||
|
|
@ -41,7 +41,6 @@ __FBSDID("$FreeBSD$");
|
|||
#include <sys/proc.h>
|
||||
#include <sys/sched.h>
|
||||
#include <sys/smp.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/vnode.h>
|
||||
|
||||
#include <vm/uma.h>
|
||||
|
|
@ -230,8 +229,6 @@ g_eli_crypto_run(struct g_eli_worker *wr, struct bio *bp)
|
|||
struct g_eli_softc *sc;
|
||||
struct cryptop *crp;
|
||||
struct cryptodesc *crd;
|
||||
struct uio *uio;
|
||||
struct iovec *iov;
|
||||
u_int i, nsec, secsize;
|
||||
int err, error;
|
||||
off_t dstoff;
|
||||
|
|
@ -254,8 +251,6 @@ g_eli_crypto_run(struct g_eli_worker *wr, struct bio *bp)
|
|||
*/
|
||||
size = sizeof(*crp) * nsec;
|
||||
size += sizeof(*crd) * nsec;
|
||||
size += sizeof(*uio) * nsec;
|
||||
size += sizeof(*iov) * nsec;
|
||||
/*
|
||||
* If we write the data we cannot destroy current bio_data content,
|
||||
* so we need to allocate more memory for encrypted data.
|
||||
|
|
@ -280,28 +275,18 @@ g_eli_crypto_run(struct g_eli_worker *wr, struct bio *bp)
|
|||
for (i = 0, dstoff = bp->bio_offset; i < nsec; i++, dstoff += secsize) {
|
||||
crp = (struct cryptop *)p; p += sizeof(*crp);
|
||||
crd = (struct cryptodesc *)p; p += sizeof(*crd);
|
||||
uio = (struct uio *)p; p += sizeof(*uio);
|
||||
iov = (struct iovec *)p; p += sizeof(*iov);
|
||||
|
||||
iov->iov_len = secsize;
|
||||
iov->iov_base = data;
|
||||
data += secsize;
|
||||
|
||||
uio->uio_iov = iov;
|
||||
uio->uio_iovcnt = 1;
|
||||
uio->uio_segflg = UIO_SYSSPACE;
|
||||
uio->uio_resid = secsize;
|
||||
|
||||
crp->crp_sid = wr->w_sid;
|
||||
crp->crp_ilen = secsize;
|
||||
crp->crp_olen = secsize;
|
||||
crp->crp_opaque = (void *)bp;
|
||||
crp->crp_buf = (void *)uio;
|
||||
crp->crp_buf = (void *)data;
|
||||
data += secsize;
|
||||
if (bp->bio_cmd == BIO_WRITE)
|
||||
crp->crp_callback = g_eli_crypto_write_done;
|
||||
else /* if (bp->bio_cmd == BIO_READ) */
|
||||
crp->crp_callback = g_eli_crypto_read_done;
|
||||
crp->crp_flags = CRYPTO_F_IOV | CRYPTO_F_CBIFSYNC | CRYPTO_F_REL;
|
||||
crp->crp_flags = CRYPTO_F_CBIFSYNC | CRYPTO_F_REL;
|
||||
if (g_eli_batch)
|
||||
crp->crp_flags |= CRYPTO_F_BATCH;
|
||||
crp->crp_desc = crd;
|
||||
|
|
|
|||
Loading…
Reference in a new issue