From nobody Tue Oct 28 19:51:47 2025 X-Original-To: dev-commits-src-branches@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 4cx1HG0hLDz6DNgT for ; Tue, 28 Oct 2025 19:52:10 +0000 (UTC) (envelope-from marklmi@yahoo.com) Received: from sonic310-21.consmr.mail.gq1.yahoo.com (sonic310-21.consmr.mail.gq1.yahoo.com [98.137.69.147]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4cx1HD6QwJz3YjR for ; Tue, 28 Oct 2025 19:52:08 +0000 (UTC) (envelope-from marklmi@yahoo.com) Authentication-Results: mx1.freebsd.org; dkim=pass header.d=yahoo.com header.s=s2048 header.b=kFVBwBdF; dmarc=pass (policy=reject) header.from=yahoo.com; spf=pass (mx1.freebsd.org: domain of marklmi@yahoo.com designates 98.137.69.147 as permitted sender) smtp.mailfrom=marklmi@yahoo.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1761681122; bh=RlfspS5acCqOEU7NzPf4CxPw8eLgL3VBztuDm+6BY78=; h=From:Subject:Date:Cc:To:References:From:Subject:Reply-To; b=kFVBwBdFKer7JPM4z090F9CGf/yuzNArg5SDjlGoetreRcAc+N1XEQ/+AH7r+lxMwZh5OwT2A0GmPai/jzLhEBB9T0YuE7aP5sMdu4vUrEmkfyqYqj10BGvMjUaO8dJROGT40ENY6dRquUCuklG2DhckVimBFmVj1yrKvqC+UYGOxr/4lmezMqvRdd6HNSN04Acagjgr1w38whCjbG/GTIDwZqAY5id42851g5+9ywFdL5CSkzDgntKKqP8DYlLEigqRHuVCh8BZdUtDe5vRZmCxSBcKr2fvSkNw4tzOBjLllCOtCpbDTqqH2cEAouK9YTS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rvUaZk7QJGfPIg.ozYKYYF5xfaA01RAD_sYPGijnzR_WyiVIm5_U .R.tudygGoQ8zwGb5dWqTJWXusLMYJu0Wd_mXU1DA1Q8gr.iiixCB_00iuyn5QwZRbUNsg.VmH8U 23rBcE4oWmLL2iGEgzt8HyRi_fW94I7IqrQsV36f9eVXxxiycH0.vsvz0imihjIbYiMJ2Hj2n38e ZXB0eaMYvYv_VL5GXZLgn0ucaDAJNAGKBw_z8GWSEvwWwl.OC3rREwM5fp3WiDNXDvmQDhsLVxVj TdjQPYDYTpDRSlWVAVF_wN7z2hut5hWdXJOpbssftb9pGrw4uYd5NBrCY.pH0I7D8Ti5lBPxLgVj XCkeKFXnMjILkyb6haRcWk1e2ocBlxd_OfCddVVm4Ef9nCV8MTubpx1DCSrv8ii6pC7EGvCh4E3q 1yffbyIJ8Wd4pbimJM_bpHq_IKCj4J2RbMpINFzSvFdpKkA7XXvBsS4ewdclV8O6GTSR3q0wR26Q 1L9z2nZweC8WJu8n1n3f038yxZMKugUW3mnI0.MFGsHhVzOkv60LHM7hX_Z_MeWuxeQwrRmw_XO5 S4qT6PMxXkZwV8Dz70TP2QBLHHToC_Do0dAQqtGcAMCjSl5KjjinGhxE1FrVCf2L_.BtFfp4YBNc LV6AcASwKnBFTLiP5tEmlZPg5gbWy6Qk658QMh1bRYZmpd3DdJnJCOG.6h_IuqlNtLkoETCbhN0L N6CfS8CsLVyo- X-Sonic-MF: X-Sonic-ID: 0cb0ce9f-8851-47b2-b84d-bfb8e3de5bb1 Received: from sonic.gate.mail.ne1.yahoo.com by sonic310.consmr.mail.gq1.yahoo.com with HTTP; Tue, 28 Oct 2025 19:52:02 +0000 Received: by hermes--production-gq1-7cf9d58dc6-lwcr7 (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID c6950bef0f808d4f39c6b1e73b8fb3f0; Tue, 28 Oct 2025 19:51:58 +0000 (UTC) From: Mark Millard Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.700.81\)) Subject: Re: git: 3d73146baeb9 - main - pwait: Add an option to print remaining processes Message-Id: Date: Tue, 28 Oct 2025 12:51:47 -0700 Cc: =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= To: Zhenlei Huang , glebius@freebsd.org, dev-commits-src-branches@freebsd.org X-Mailer: Apple Mail (2.3826.700.81) References: X-Spamd-Bar: --- X-Spamd-Result: default: False [-4.00 / 15.00]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_SHORT(-1.00)[-1.000]; DMARC_POLICY_ALLOW(-0.50)[yahoo.com,reject]; R_DKIM_ALLOW(-0.20)[yahoo.com:s=s2048]; R_SPF_ALLOW(-0.20)[+ptr:yahoo.com]; MIME_GOOD(-0.10)[text/plain]; FROM_HAS_DN(0.00)[]; DKIM_TRACE(0.00)[yahoo.com:+]; RCVD_TLS_LAST(0.00)[]; ARC_NA(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; DWL_DNSWL_NONE(0.00)[yahoo.com:dkim]; FREEMAIL_FROM(0.00)[yahoo.com]; RCPT_COUNT_THREE(0.00)[4]; ASN(0.00)[asn:36647, ipnet:98.137.64.0/20, country:US]; RCVD_VIA_SMTP_AUTH(0.00)[]; TO_MATCH_ENVRCPT_SOME(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; FREEMAIL_ENVFROM(0.00)[yahoo.com]; MLMMJ_DEST(0.00)[dev-commits-src-branches@freebsd.org]; APPLE_MAILER_COMMON(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; RWL_MAILSPIKE_POSSIBLE(0.00)[98.137.69.147:from]; RCVD_IN_DNSWL_NONE(0.00)[98.137.69.147:from] X-Rspamd-Queue-Id: 4cx1HD6QwJz3YjR Zhenlei Huang wrote on Date: Tue, 28 Oct 2025 18:18:55 UTC : > > On Oct 29, 2025, at 1:28 AM, Gleb Smirnoff = wrote: > >=20 > > On Tue, Oct 28, 2025 at 11:57:43AM +0000, Dag-Erling Sm=C3=B8rgrav = wrote: > > D> +static int > > D> +pidcmp(const struct pid *a, const struct pid *b) > > D> +{ > > D> + return (a->pid > b->pid ? 1 : a->pid < b->pid ? -1 : 0); > > D> +} > > D> + > > D> +RB_HEAD(pidtree, pid); > > D> +static struct pidtree pids =3D RB_INITIALIZER(&pids); > > D> +RB_GENERATE_STATIC(pidtree, pid, entry, pidcmp); > >=20 > > We have a nice trick in our tree(3) that allows to use lighter = compare > > functions. The function can return any signed integer type, thus we > > can: > >=20 > > static pid_t > > pidcmp(const struct pid *a, const struct pid *b) > > { > > return (a->pid - b->pid); > > } >=20 > I'd prefer to return const 1 / -1 / 0, that is straight forward of a = comparator. Also the compiler is smart > enough to catch this pattern and generate optimized code, from my = experiment which is long long time ago. >=20 > The pid has type pid_t which is a type redefinition of __int32_t. = Although the pid will not reach > 2^31 or -2^31 - 1, in principle the computing of the delta of the two = signed integers may overflow > and that is bad smell. Dag-Erling's code is somewhat less dependent on the context of use, at least relative to the C11 language standard definitions. FreeBSD sometimes defines that it requires properties not guaranteed by language or other standards. So I'm not sure the "a->pid - b->pid" code in question is just depending on such a definition vs. not. Also, it may be that all the calls of pidcmp meet the criteria that I reference below. QUOTE (of C11 standard) When two pointers are subtracted, both shall point to elements of the same array object or one past the last element of the array object; the result is the difference of the subscripts of the two array elements. The size of the result is implementation-defined, and its type (a signed integer type) is ptrdiff_t . . . If the result is not representable in an object of that type, the behavior is undefined. END QUOTE So, making some language context more explicit, the return is more like: return (pid_t)(ptrdiff_t)(a->pid - b->pid); If pid_t is __int32_t even for 64 bit environments, the relationship to ptrdiff_t for the context could be a technical problem. I'm not sure if FreeBSD makes any guarantees that establish a sufficient relationship. Also, the above does not allow subtracting pointers to distinct members of the same struct, for example. Contrast with a->pid > b->pid and a->pid < b->pid use: The C11 standard wording covering a->pid > b->pid and a->pid < b->pid from the committed code actually allows a wider range of valid-to-compare pointer values, such as for pointers to of members of the same struct. But without being members of the same array or struct or union, the comparisons can be examples of "[i]n all other cases, the behavior is undefined". So what the language allows on its own is still limited. (My notes may span somewhat more than is needed for the context.) =3D=3D=3D Mark Millard marklmi at yahoo.com