From owner-dev-commits-src-main@freebsd.org Wed Dec 30 22:58:47 2020 Return-Path: Delivered-To: dev-commits-src-main@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id D15FC4D21B1; Wed, 30 Dec 2020 22:58:47 +0000 (UTC) (envelope-from bdragon@FreeBSD.org) Received: from smtp.freebsd.org (smtp.freebsd.org [IPv6:2610:1c1:1:606c::24b:4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4D5mtH5Kmqz4pQQ; Wed, 30 Dec 2020 22:58:47 +0000 (UTC) (envelope-from bdragon@FreeBSD.org) Received: from auth1-smtp.messagingengine.com (auth1-smtp.messagingengine.com [66.111.4.227]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) (Authenticated sender: bdragon/mail) by smtp.freebsd.org (Postfix) with ESMTPSA id 9F2FC91F6; Wed, 30 Dec 2020 22:58:47 +0000 (UTC) (envelope-from bdragon@FreeBSD.org) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailauth.nyi.internal (Postfix) with ESMTP id 9479827C0054; Wed, 30 Dec 2020 17:58:47 -0500 (EST) Received: from imap1 ([10.202.2.51]) by compute3.internal (MEProxy); Wed, 30 Dec 2020 17:58:47 -0500 X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrvddvgedgtdehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne gfrhhlucfvnfffucdluddtmdenucfjughrpefofgggkfgjfhffhffvufgtsehttdertder reejnecuhfhrohhmpedfuehrrghnughonhcuuegvrhhgrhgvnhdfuceosggurhgrghhonh eshfhrvggvuefuffdrohhrgheqnecuggftrfgrthhtvghrnhepheeiieekkeffkeelkeel geetgfeltdetgffhudetieekveefvdfhgefgffdujefgnecuffhomhgrihhnpehfrhgvvg gsshgurdhorhhgnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhf rhhomhepsggurhgrghhonhdomhgvshhmthhprghuthhhphgvrhhsohhnrghlihhthidqud dtgedvfeehkeeigedqudekuddtkeehuddqsggurhgrghhonheppefhrhgvvgeuufffrdho rhhgsehimhgrphdrtggt X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id E80A4C200A5; Wed, 30 Dec 2020 17:58:47 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.3.1-61-gb52c239-fm-20201210.001-gb52c2396 Mime-Version: 1.0 Message-Id: <2c16d4dd-30e4-40ae-91f9-1936434dc922@www.fastmail.com> In-Reply-To: <202012302245.0BUMjrQN032417@gitrepo.freebsd.org> References: <202012302245.0BUMjrQN032417@gitrepo.freebsd.org> Date: Wed, 30 Dec 2020 16:58:26 -0600 From: "Brandon Bergren" To: "Piotr Kubaj" , src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: =?UTF-8?Q?Re:_git:_6260bfb08742_-_main_-_powerpc:_Optimize_copyinstr()_t?= =?UTF-8?Q?o_avoid_repeatedly_mapping_user_strings?= Content-Type: text/plain X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: "Commit messages for the main branch of the src repository." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 30 Dec 2020 22:58:47 -0000 Approved-By: bdragon (in IRC) On Wed, Dec 30, 2020, at 4:45 PM, Piotr Kubaj wrote: > The branch main has been updated by pkubaj (ports committer): > > URL: > https://cgit.FreeBSD.org/src/commit/?id=6260bfb0874280d3fb58ac52699e2aee6ecca8a8 > > commit 6260bfb0874280d3fb58ac52699e2aee6ecca8a8 > Author: Justin Hibbits > AuthorDate: 2020-06-04 18:15:15 +0000 > Commit: Piotr Kubaj > CommitDate: 2020-12-30 22:45:35 +0000 > > powerpc: Optimize copyinstr() to avoid repeatedly mapping user strings > > Currently copyinstr() uses fubyte() to read each byte from userspace. > However, this means that for each byte, it calls pmap_map_user_ptr() to > map the string into memory. This is needlessly wasteful, since the > string will rarely ever cross a segment boundary. Instead, map a > segment at a time, and copy as much from that segment as possible at a > time. > > Measured with the HPT pmap on powerpc64, this saves roughly 8% time on > buildkernel, and 5% on buildworld, in wallclock time. > --- > sys/powerpc/powerpc/copyinout.c | 46 +++++++++++++++++++++++++++++------------ > 1 file changed, 33 insertions(+), 13 deletions(-) > > diff --git a/sys/powerpc/powerpc/copyinout.c b/sys/powerpc/powerpc/copyinout.c > index 76965ad996b8..1528accc0e0e 100644 > --- a/sys/powerpc/powerpc/copyinout.c > +++ b/sys/powerpc/powerpc/copyinout.c > @@ -236,31 +236,51 @@ REMAP(copyin)(const void *udaddr, void *kaddr, size_t len) > int > REMAP(copyinstr)(const void *udaddr, void *kaddr, size_t len, size_t *done) > { > + struct thread *td; > + pmap_t pm; > + jmp_buf env; > const char *up; > - char *kp; > - size_t l; > - int rv, c; > + char *kp, *p; > + size_t i, l, t; > + int rv; > > - kp = kaddr; > - up = udaddr; > + td = curthread; > + pm = &td->td_proc->p_vmspace->vm_pmap; > > + t = 0; > rv = ENAMETOOLONG; > > - for (l = 0; len-- > 0; l++) { > - if ((c = fubyte(up++)) < 0) { > + td->td_pcb->pcb_onfault = &env; > + if (setjmp(env)) { > + rv = EFAULT; > + goto done; > + } > + > + kp = kaddr; > + up = udaddr; > + > + while (len > 0) { > + if (pmap_map_user_ptr(pm, up, (void **)&p, len, &l)) { > rv = EFAULT; > - break; > + goto done; > } > > - if (!(*kp++ = c)) { > - l++; > - rv = 0; > - break; > + for (i = 0; len > 0 && i < l; i++, t++, len--) { > + if ((*kp++ = *p++) == 0) { > + i++, t++; > + rv = 0; > + goto done; > + } > } > + > + up += l; > } > > +done: > + td->td_pcb->pcb_onfault = NULL; > + > if (done != NULL) { > - *done = l; > + *done = t; > } > > return (rv); > -- Brandon Bergren bdragon@FreeBSD.org