Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127452 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by lists.php.net (Postfix) with ESMTPS id A4C0A1A00BC for ; Sun, 25 May 2025 10:08:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1748167570; bh=2gwMb8OF008bTqjxWCWkAMX08iX7y7AG9PnPulRo80Q=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=WWJCOCrkY+wRdtlUyTJxAzcEpyI7m+Ou7AhWjjYUH9UI6mbppXKWAMCfAbxeywvra McXoFDBngPCUL3m7anzciy3b1Ipu4DtIH6XirPpcSXqD3rnQCajMHMbiPU+EAFus1Q YV2ua/73plZOaqcL2NCV99AVWK/Znpvq4hJroi4DASz/KcTeshHeDJfzaj/qwBfGhT 7XanCxPrZ6JTjRIvdptEEm1cya+RRyag9XTeaNOSk+a7E9W8sl9p2f/+cVu8SdyI0R SzSD79CLhHQ3Zld+A9P16VU/OdyaI+jmEDTO1gExAXGuY2ZF1uSXCYWu8DR82MEVrU FA52oFhIxmx8Q== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 9D2CD18005D for ; Sun, 25 May 2025 10:06:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.2 required=5.0 tests=BAYES_20,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from outbound.qs.icloud.com (p-east3-cluster2-host6-snip4-2.eps.apple.com [57.103.87.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 25 May 2025 10:05:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=garsi.de; s=sig1; bh=9SCVVoWJBljHZOY+3nLynd2gKHbEff8nmW+oXR6xlTY=; h=Content-Type:Mime-Version:Subject:From:Date:Message-Id:To:x-icloud-hme; b=k+WcT8L0syHhJ1amo92jAwPJeTbwjkMGvMhyrs3jDpbeOw2waInKaWOWC5/c4fr1A nGK0nBwYPRvtWIgB3TlH4kCyH5Fi/Rc5KU4pj5rZyBc8wCw8dtOjCZlKExf2mfambQ 163pVPjb2jo0TxgKTji4SXo8vJA6EMj4Xkkftg9B4aOIm8uDCpYA2468vztn3Oe+QW 1b1j39nUxNWWlkFAx3PSkRGm6uQzmi+c2GJQP6TtNB9ozkBOp16cVP4eOIQBfZnBHu nISMw0tCCFPeeZnJqw9J6e09DmpiIv8BJswkJzzvCmX7huZ/yEicSkAKSIOGV605ff Kx5hcCCNCvfEQ== Received: from outbound.qs.icloud.com (localhost [127.0.0.1]) by outbound.qs.icloud.com (Postfix) with ESMTPS id AB529180193C; Sun, 25 May 2025 10:08:03 +0000 (UTC) Received: from smtpclient.apple (qs-asmtp-me-k8s.p00.prod.me.com [17.57.155.37]) by outbound.qs.icloud.com (Postfix) with ESMTPSA id 64BE91801914; Sun, 25 May 2025 10:08:02 +0000 (UTC) Content-Type: text/plain; charset=utf-8 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.500.181.1.5\)) Subject: Re: [PHP-DEV] [RFC] Add num_available_processors In-Reply-To: Date: Sun, 25 May 2025 12:07:50 +0200 Cc: PHP Internals Content-Transfer-Encoding: quoted-printable Message-ID: <60B4033B-2E6A-4157-A698-6C58454B07C9@garsi.de> References: To: Daniel Kesselberg , Rob Landers X-Mailer: Apple Mail (2.3826.500.181.1.5) X-Proofpoint-ORIG-GUID: XsjS3G6udxQX9fRJABFvzEdPjQB8i-4j X-Proofpoint-GUID: XsjS3G6udxQX9fRJABFvzEdPjQB8i-4j X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.0.736,FMLib:17.12.80.40 definitions=2025-05-25_04,2025-05-22_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 mlxscore=0 suspectscore=0 malwarescore=0 clxscore=1030 bulkscore=0 spamscore=0 phishscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.22.0-2503310001 definitions=main-2505250093 From: alwin@garsi.de (Alwin Garside) On 24 May 2025, at 20:48, Rob Landers wrote: >=20 > On Sat, May 24, 2025, at 19:37, Daniel Kesselberg wrote: >>=20 >>=20 >> Hi everyone, >>=20 >> I'm happy to share my first RFC :) It proposes adding a small = function=20 >> to retrieve the number of available processors; a feature that's=20 >> commonly found in other programming languages and one that I believe=20= >> would be a useful addition to PHP. >>=20 >> The related PR has already received a bit of early traction, and now=20= >> that the RFC is complete, I'm looking forward to your feedback! >>=20 >> RFC: https://wiki.php.net/RFC/num_available_processors >> Patch: https://github.com/php/php-src/pull/11137 >>=20 >> Best >> Daniel >>=20 >=20 > Looks good! >=20 > My main question is: what is this actually counting? In the RFC it = mentions "available processing units" ... which means, what? What counts = as a "processing unit"? Are we talking about CPU Threads/cores; NPU = cores; TPM cores; clocks? GPS? GPU? ... a modern computer has many = "processing units" for different purposes and workloads. I=E2=80=99m = assuming this is CPU Threads, not physical cores? I will refer to CPU = Threads as "Logical Cores" so we all don=E2=80=99t get confused since = most of us here are programmers and saying "thread" has a different = meaning. >=20 > Secondly, how is it counting "available"? If I assign PHP to a = specific CPU affinity mask (say one logical core), will it return 1, or = the total number of logical cores available on my machine? I would = expect it to be 1, since PHP only has access to 1, but I can also see = the logic in returning the total number. >=20 > =E2=80=94 Rob Hi Daniel, I agree with Rob that "processor" is a bit too ambiguous. I'd use the = phrase "cpu_core" instead. Yes, technically that's not entirely accurate = when hyper-threading is used, but in most cases it's not trivial to = distinguish physical cores from logical cores anyway, and "cpu_cores" = provides the most understandable abstraction for the vast majority of = use cases: deciding how many parallel processes one should use for = optimal use of the CPU. Also, is it really necessary to add "available" as a disambiguator? In = other words: are there future plans to add a function that provides the = "total" or "unavailable" number of processors? If not, I'd just drop the = "available" part. Finally, from a quick search in php-src there doesn't seem to be any = existing function name that starts with `num_`. For the sake of = consistency with the existing PHP functions, and similar functionality = in other languages, I suggest suffixing the function name with `_count` = instead. So, to wrap this all up, I'd like to respectfully propose the following = function name instead: cpu_core_count() Alwin=