From nobody Thu May 12 20:22:53 2022 X-Original-To: dev-commits-src-main@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 680E71AC46F6; Thu, 12 May 2022 20:22:55 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (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 "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4KzjrZ6tJ4z4dGp; Thu, 12 May 2022 20:22:54 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1652386975; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=19hEgIdvnMVnO3ebH2EThCVec6S/UdfgbkfI8q3tH9E=; b=FsZRBlgD/vU9zLl0pqkB8LS7iCx2493BaNiVXvbt5jA+XseY9HnYxFUQIlgsFaUjncRNMn xGUSjOPqvPLo8lvYcSrdEGFb2WgBTmO58+HXRjbllDHA3NeI8GUUIeVPm3siwcvqXZRHVO byCSpZ0FJF0Ovxl2OxDjkhwjr0jqS/qXGaOjMYDE67JN22BoJXiszJcf4XWncLwaxuGdTN ARz58GNKCiD1uIVFpzyd34pv9w8WebJT0IH5mxhBWsMSNCY5eEjGUfse77Xyz1wAUA70S2 E+JiztWUTuKnYZG72okWP68FuvH94DHzCcafaU/SIGLSltpLlRR3Uue82Hll6A== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 70D36153F7; Thu, 12 May 2022 20:22:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 24CKMrPx016374; Thu, 12 May 2022 20:22:53 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 24CKMrZA016373; Thu, 12 May 2022 20:22:53 GMT (envelope-from git) Date: Thu, 12 May 2022 20:22:53 GMT Message-Id: <202205122022.24CKMrZA016373@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Smirnoff Subject: git: bb35a4e11d5e - main - unix: microoptimize unp_connectat() - one less lock on success List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: glebius X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: bb35a4e11d5ec70f99cd36caf5290a33afc9a515 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1652386975; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=19hEgIdvnMVnO3ebH2EThCVec6S/UdfgbkfI8q3tH9E=; b=k5k3bl/aydmcj8edvRLPqbqfm3kZUzYADy/dpmZcyWuThPMBs0xlVCnh6zzuO0kwTMvsa7 SH9m+qMX3Jup/jcTGc+AqZwFWDT3CWHhlfm4TPdze3LCYXu8/LZ/DRe5yJsMJ4CDmDXaLu iItQvoHIL2gksokD6ElBIgyNPQSmujnn/FIqAz4suQAWYKAhYgEJqyxz5nfjyzyUspbvXP 3yuazRIAiLlbNFeK2Q3K2u2pRQYtf2QgiXL/37p9nPkWQR5fNfTpt4qwNPBtzmpe1JK7vP 7OaQa1Ro6X6MAWv9O8ldnfRLjBVhS4Jl3GV1Vdowj8I6Kacmh6FkKNW1fernAA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1652386975; a=rsa-sha256; cv=none; b=hFNmxig5P2WzEWoech+l0r8U3PPKV0mRdFFPQuImsRNfOdcAgZ0LLYbbgJ94LZxB/uZjHP 2tG1fY27D1Sq8aBKfjf5LHW9yO/baplrj+GI/AYIzKprbboYjQeZF+LrBASG7iGSgWyeqE 3zHOfiOC9o1sJbIYHg9Z5dkSvtiheli2fSuA1ZgogRscBYIaX65YjtHJEO/Gfh9XP531TA TdDm/Fb7OgD7w/HoYfHtHIIZVgG4+U0ltgQU8xEaIA8nfnqffZ+uTCU3nWhMNUGrXeIfRG C1CbYroNvWe8acK2o7nsdI5VgIKyOEvNiopBm6ykVYEY7keq1TqTHu02wIFYGQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=bb35a4e11d5ec70f99cd36caf5290a33afc9a515 commit bb35a4e11d5ec70f99cd36caf5290a33afc9a515 Author: Gleb Smirnoff AuthorDate: 2022-05-12 20:22:39 +0000 Commit: Gleb Smirnoff CommitDate: 2022-05-12 20:22:39 +0000 unix: microoptimize unp_connectat() - one less lock on success This change is also a preparation for further optimization to allow locked return on success. Reviewed by: markj Differential revision: https://reviews.freebsd.org/D35182 --- sys/kern/uipc_usrreq.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c index 13fa7acfcdf3..d4e3b25c5479 100644 --- a/sys/kern/uipc_usrreq.c +++ b/sys/kern/uipc_usrreq.c @@ -1634,6 +1634,9 @@ unp_connectat(int fd, struct socket *so, struct sockaddr *nam, sotounpcb(so2) == unp2, ("%s: unp2 %p so2 %p", __func__, unp2, so2)); unp_connect2(so, so2, PRU_CONNECT); + KASSERT((unp->unp_flags & UNP_CONNECTING) != 0, + ("%s: unp %p has UNP_CONNECTING clear", __func__, unp)); + unp->unp_flags &= ~UNP_CONNECTING; unp_pcb_unlock_pair(unp, unp2); bad2: mtx_unlock(vplock); @@ -1642,11 +1645,13 @@ bad: vput(vp); } free(sa, M_SONAME); - UNP_PCB_LOCK(unp); - KASSERT((unp->unp_flags & UNP_CONNECTING) != 0, - ("%s: unp %p has UNP_CONNECTING clear", __func__, unp)); - unp->unp_flags &= ~UNP_CONNECTING; - UNP_PCB_UNLOCK(unp); + if (__predict_false(error)) { + UNP_PCB_LOCK(unp); + KASSERT((unp->unp_flags & UNP_CONNECTING) != 0, + ("%s: unp %p has UNP_CONNECTING clear", __func__, unp)); + unp->unp_flags &= ~UNP_CONNECTING; + UNP_PCB_UNLOCK(unp); + } return (error); }