From nobody Tue Sep 26 18:08:39 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Rw76J6DhTz4vTHb for ; Tue, 26 Sep 2023 18:08:56 +0000 (UTC) (envelope-from bT.i22eqlze30=w1gt6t1smgu9=bjay8tmso9@em790814.fubar.geek.nz) Received: from e2i432.smtp2go.com (e2i432.smtp2go.com [103.2.141.176]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4Rw76G5Ddjz3JFj for ; Tue, 26 Sep 2023 18:08:54 +0000 (UTC) (envelope-from bT.i22eqlze30=w1gt6t1smgu9=bjay8tmso9@em790814.fubar.geek.nz) Authentication-Results: mx1.freebsd.org; dkim=none ("invalid DKIM record") header.d=smtpservice.net header.s=mgy720.a1-4.dyn header.b=yO44AD0f; dkim=pass header.d=fubar.geek.nz header.s=s790814 header.b=LvRFB533; spf=pass (mx1.freebsd.org: domain of "bT.i22eqlze30=w1gt6t1smgu9=bjay8tmso9@em790814.fubar.geek.nz" designates 103.2.141.176 as permitted sender) smtp.mailfrom="bT.i22eqlze30=w1gt6t1smgu9=bjay8tmso9@em790814.fubar.geek.nz"; dmarc=pass (policy=none) header.from=fubar.geek.nz DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=smtpservice.net; s=mgy720.a1-4.dyn; x=1695752634; h=Feedback-ID: X-Smtpcorp-Track:To:Message-Id:Date:From:Subject:Reply-To:Sender: List-Unsubscribe; bh=q41EjXJ9dZ5oSbfC8M65JFafrYPkKjdge6fbG8lIAoo=; b=yO44AD0f IZmEXG/JFGwm6Azhdu7iy9eWxGByVu0eEgCdCkyP225+sz78hLGiJnQVKaI0e/S3hHxO/G5n+9hH0 Lo8uqNM90wbgtyKKgBPYkxIpZfxvKVfMX0skrEh43lZ0mKaNBDvL4j0XCev1XByasB/J6KBzvXhua d3G+D9/VC+p7g1NQiIXqPpTgW8QZz4wU+OOvfvnlD8OrAD8CM0WrLawdU+ELF5lDY1+jd5gK1b9vA gs8GKQbh4NzI3qyvH0VMCc1Ib5/VAeN6FbjFoKXobE3eR+FdOwhmV6ZigX1UJVk3Gsh2wzJ6tQdH4 ePXhkoWLE3FSF7ajrrxC10JXXA==; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fubar.geek.nz; i=@fubar.geek.nz; q=dns/txt; s=s790814; t=1695751734; h=from : subject : to : message-id : date; bh=q41EjXJ9dZ5oSbfC8M65JFafrYPkKjdge6fbG8lIAoo=; b=LvRFB533pjLXTdfKk3B8k10sOmqsdxrn7WxafGtW37G17Fp9sfQPHHrns75/BsPRC9z6C H2DvJDBtCmgoGGzuml1DPn+9Orajhzx3Fdoh9z6Mgb10m7zQIOezLi7NlMCRtR22MePScJO XIo0c1rKuMs7YCO+A71jtbF/+mxs9wOOa0JWdIvlrmhgWJVwaRccZVfnsm0Z63vcRwl+YIC Chd6GZgVs08JatRnPFAZNFR8nBlHwKbErIiI4nnx4ufM8SIeVMPbO+R92TqUSMTAZlPclSI ENSDJWnb9N3I1QqjMnt8lqt+pUNqy+8nJT9jk+Es+TDwcVkHNXF/IvThJH0Q== Received: from [10.176.58.103] (helo=SmtpCorp) by smtpcorp.com with esmtpsa (TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.94.2-S2G) (envelope-from ) id 1qlCUM-TRk1Xc-VF; Tue, 26 Sep 2023 18:08:50 +0000 Received: from [10.99.243.232] (helo=morbo.fubar.geek.nz) by smtpcorp.com with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.96-S2G) (envelope-from ) id 1qlCUM-9ERRJu-2A; Tue, 26 Sep 2023 18:08:50 +0000 Received: from smtpclient.apple (cpc91210-cmbg18-2-0-cust37.5-4.cable.virginm.net [81.102.44.38]) by morbo.fubar.geek.nz (Postfix) with ESMTPSA id 1283A3FFC2; Tue, 26 Sep 2023 18:08:50 +0000 (UTC) Content-Type: text/plain; charset=utf-8 List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.700.6\)) Subject: Re: git: f1c5a2e3a625 - main - virtio_random: Pipeline fetching the data From: Andrew Turner In-Reply-To: <202309051600.385G0Bmk031832@gitrepo.freebsd.org> Date: Tue, 26 Sep 2023 19:08:39 +0100 Cc: "src-committers@freebsd.org" , "dev-commits-src-all@freebsd.org" , "dev-commits-src-main@freebsd.org" Content-Transfer-Encoding: quoted-printable Message-Id: <8B2042EF-728E-4A8A-8878-640B3097191E@fubar.geek.nz> References: <202309051600.385G0Bmk031832@gitrepo.freebsd.org> To: John Baldwin X-Mailer: Apple Mail (2.3731.700.6) X-Smtpcorp-Track: 1q_Clu9ERRJI2j.E84zHw8sX4v4w Feedback-ID: 790814m:790814amQcrys:790814sA5QavheWS X-Report-Abuse: Please forward a copy of this message, including all headers, to X-Spamd-Bar: --- X-Spamd-Result: default: False [-3.70 / 15.00]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_SHORT(-1.00)[-1.000]; MV_CASE(0.50)[]; DMARC_POLICY_ALLOW(-0.50)[fubar.geek.nz,none]; RWL_MAILSPIKE_EXCELLENT(-0.40)[103.2.141.176:from]; FORGED_SENDER(0.30)[andrew@fubar.geek.nz,bT.i22eqlze30=w1gt6t1smgu9=bjay8tmso9@em790814.fubar.geek.nz]; R_DKIM_ALLOW(-0.20)[fubar.geek.nz:s=s790814]; R_SPF_ALLOW(-0.20)[+ip4:103.2.140.0/22]; RCVD_IN_DNSWL_LOW(-0.10)[103.2.141.176:from]; MIME_GOOD(-0.10)[text/plain]; FROM_HAS_DN(0.00)[]; TO_DN_EQ_ADDR_SOME(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; R_DKIM_PERMFAIL(0.00)[smtpservice.net:s=mgy720.a1-4.dyn]; TO_MATCH_ENVRCPT_SOME(0.00)[]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; MID_RHS_MATCH_FROM(0.00)[]; DKIM_MIXED(0.00)[]; TO_DN_SOME(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_NEQ_ENVFROM(0.00)[andrew@fubar.geek.nz,bT.i22eqlze30=w1gt6t1smgu9=bjay8tmso9@em790814.fubar.geek.nz]; RCVD_COUNT_THREE(0.00)[3]; MLMMJ_DEST(0.00)[dev-commits-src-all@FreeBSD.org]; DKIM_TRACE(0.00)[smtpservice.net:~,fubar.geek.nz:+]; ASN(0.00)[asn:23352, ipnet:103.2.140.0/22, country:US]; RCVD_TLS_ALL(0.00)[] X-Rspamd-Queue-Id: 4Rw76G5Ddjz3JFj Is there a plan to MFC this to 14? Without it I=E2=80=99m seeing 50% CPU = on a dual core arm64 Hetzner VM. Andrew > On 5 Sep 2023, at 17:00, John Baldwin wrote: >=20 > The branch main has been updated by jhb: >=20 > URL: = https://cgit.FreeBSD.org/src/commit/?id=3Df1c5a2e3a625053e2b70d5b1777d849a= 4d9328f2 >=20 > commit f1c5a2e3a625053e2b70d5b1777d849a4d9328f2 > Author: John-Mark Gurney > AuthorDate: 2023-09-05 15:59:43 +0000 > Commit: John Baldwin > CommitDate: 2023-09-05 15:59:43 +0000 >=20 > virtio_random: Pipeline fetching the data >=20 > Queue an initial fetch of data during attach and after every read > rather than synchronously fetching data and polling for completion. >=20 > If data has not been returned from an previous fetch during read, > just return EAGAIN rather than blocking. >=20 > Co-authored-by: John Baldwin >=20 > Reviewed by: markj > Differential Revision: https://reviews.freebsd.org/D41656 > --- > sys/dev/virtio/random/virtio_random.c | 73 = +++++++++++++++++++++-------------- > 1 file changed, 43 insertions(+), 30 deletions(-) >=20 > diff --git a/sys/dev/virtio/random/virtio_random.c = b/sys/dev/virtio/random/virtio_random.c > index c02b5c98cece..d54e2e6b70d4 100644 > --- a/sys/dev/virtio/random/virtio_random.c > +++ b/sys/dev/virtio/random/virtio_random.c > @@ -54,6 +54,8 @@ struct vtrnd_softc { > struct virtqueue *vtrnd_vq; > eventhandler_tag eh; > bool inactive; > + struct sglist *vtrnd_sg; > + uint32_t *vtrnd_value; > }; >=20 > static int vtrnd_modevent(module_t, int, void *); > @@ -67,6 +69,7 @@ static int vtrnd_negotiate_features(struct = vtrnd_softc *); > static int vtrnd_setup_features(struct vtrnd_softc *); > static int vtrnd_alloc_virtqueue(struct vtrnd_softc *); > static int vtrnd_harvest(struct vtrnd_softc *, void *, size_t *); > +static void vtrnd_enqueue(struct vtrnd_softc *sc); > static unsigned vtrnd_read(void *, unsigned); >=20 > #define VTRND_FEATURES 0 > @@ -138,12 +141,17 @@ static int > vtrnd_attach(device_t dev) > { > struct vtrnd_softc *sc, *exp; > + size_t len; > int error; >=20 > sc =3D device_get_softc(dev); > sc->vtrnd_dev =3D dev; > virtio_set_feature_desc(dev, vtrnd_feature_desc); >=20 > + len =3D sizeof(*sc->vtrnd_value) * HARVESTSIZE; > + sc->vtrnd_value =3D malloc_aligned(len, len, M_DEVBUF, = M_WAITOK); > + sc->vtrnd_sg =3D sglist_build(sc->vtrnd_value, len, M_WAITOK); > + > error =3D vtrnd_setup_features(sc); > if (error) { > device_printf(dev, "cannot setup features\n"); > @@ -174,6 +182,8 @@ vtrnd_attach(device_t dev) > sc->inactive =3D false; > random_source_register(&random_vtrnd); >=20 > + vtrnd_enqueue(sc); > + > fail: > if (error) > vtrnd_detach(dev); > @@ -185,6 +195,7 @@ static int > vtrnd_detach(device_t dev) > { > struct vtrnd_softc *sc; > + uint32_t rdlen; >=20 > sc =3D device_get_softc(dev); > KASSERT( > @@ -197,7 +208,13 @@ vtrnd_detach(device_t dev) > sc->eh =3D NULL; > } > random_source_deregister(&random_vtrnd); > + > + /* clear the queue */ > + virtqueue_poll(sc->vtrnd_vq, &rdlen); > + > atomic_store_explicit(&g_vtrnd_softc, NULL, = memory_order_release); > + sglist_free(sc->vtrnd_sg); > + zfree(sc->vtrnd_value, M_DEVBUF); > return (0); > } >=20 > @@ -251,49 +268,45 @@ vtrnd_alloc_virtqueue(struct vtrnd_softc *sc) > return (virtio_alloc_virtqueues(dev, 0, 1, &vq_info)); > } >=20 > +static void > +vtrnd_enqueue(struct vtrnd_softc *sc) > +{ > + struct virtqueue *vq; > + int error __diagused; > + > + vq =3D sc->vtrnd_vq; > + > + KASSERT(virtqueue_empty(vq), ("%s: non-empty queue", __func__)); > + > + error =3D virtqueue_enqueue(vq, sc, sc->vtrnd_sg, 0, 1); > + KASSERT(error =3D=3D 0, ("%s: virtqueue_enqueue returned error: = %d", > + __func__, error)); > + > + virtqueue_notify(vq); > +} > + > static int > vtrnd_harvest(struct vtrnd_softc *sc, void *buf, size_t *sz) > { > - struct sglist_seg segs[1]; > - struct sglist sg; > struct virtqueue *vq; > - uint32_t value[HARVESTSIZE] __aligned(sizeof(uint32_t) * = HARVESTSIZE); > + void *cookie; > uint32_t rdlen; > - int error; > - > - _Static_assert(sizeof(value) < PAGE_SIZE, "sglist assumption"); >=20 > if (sc->inactive) > return (EDEADLK); >=20 > - sglist_init(&sg, 1, segs); > - error =3D sglist_append(&sg, value, *sz); > - if (error !=3D 0) > - panic("%s: sglist_append error=3D%d", __func__, error); > - > vq =3D sc->vtrnd_vq; > - KASSERT(virtqueue_empty(vq), ("%s: non-empty queue", __func__)); > - > - error =3D virtqueue_enqueue(vq, buf, &sg, 0, 1); > - if (error !=3D 0) > - return (error); > - > - /* > - * Poll for the response, but the command is likely already > - * done when we return from the notify. > - */ > - virtqueue_notify(vq); > - virtqueue_poll(vq, &rdlen); >=20 > - if (rdlen > *sz) > - panic("%s: random device wrote %zu bytes beyond end of = provided" > - " buffer %p:%zu", __func__, (size_t)rdlen - *sz, > - (void *)value, *sz); > - else if (rdlen =3D=3D 0) > + cookie =3D virtqueue_dequeue(vq, &rdlen); > + if (cookie =3D=3D NULL) > return (EAGAIN); > + KASSERT(cookie =3D=3D sc, ("%s: cookie mismatch", __func__)); > + > *sz =3D MIN(rdlen, *sz); > - memcpy(buf, value, *sz); > - explicit_bzero(value, *sz); > + memcpy(buf, sc->vtrnd_value, *sz); > + > + vtrnd_enqueue(sc); > + > return (0); > } >=20 >=20