From 21fd08be71185f1525709fd76aeccfa59fd7056e Mon Sep 17 00:00:00 2001 From: David CARLIER Date: Tue, 11 Mar 2025 20:03:28 +0000 Subject: [PATCH] ext/sockets: adding SO_BUSY_POLL socket option for Linux. (#17954) To possibly reduce the latency when polling packets by activating it from the network interface for N microseconds. The kernel by doing so, increase the CPU(s) activity bound to the socket significantly. Note that not only the kernel needs to have support enabled for it (which the average distribution usually does) but the network interface itself needs to support it too. If not, it is just a no-op. --- NEWS | 1 + UPGRADING | 1 + ext/sockets/sockets.stub.php | 7 +++++++ ext/sockets/sockets_arginfo.h | 5 ++++- 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 68e7df9d84f..18e1f76dabe 100644 --- a/NEWS +++ b/NEWS @@ -150,6 +150,7 @@ PHP NEWS . socket_getsockname/socket_create/socket_bind handled AF_PACKET family socket. (David Carlier) . Added IP_BINDANY for a socket to bind to any address. (David Carlier) + . Added SO_BUSY_POOL to reduce packets poll latency. (David Carlier) - Sodium: . Fix overall theorical overflows on zend_string buffer allocations. diff --git a/UPGRADING b/UPGRADING index 21cf4d3062d..5d372c72e21 100644 --- a/UPGRADING +++ b/UPGRADING @@ -308,6 +308,7 @@ PHP 8.5 UPGRADE NOTES . TCP_BBR_ALGORITHM (FreeBSD only). . AF_PACKET (Linux only). . IP_BINDANY (FreeBSD/NetBSD/OpenBSD only). + . SO_BUSY_POLL (Linux only). ======================================== 11. Changes to INI File Handling diff --git a/ext/sockets/sockets.stub.php b/ext/sockets/sockets.stub.php index 4d6200fcd1f..d647f46b80d 100644 --- a/ext/sockets/sockets.stub.php +++ b/ext/sockets/sockets.stub.php @@ -454,6 +454,13 @@ const SO_BPF_EXTENSIONS = UNKNOWN; */ const SO_EXCLBIND = UNKNOWN; #endif +#ifdef SO_BUSY_POLL +/** + * @var int + * @cvalue SO_BUSY_POLL + */ +const SO_BUSY_POLL = UNKNOWN; +#endif #ifdef SKF_AD_OFF /** * @var int diff --git a/ext/sockets/sockets_arginfo.h b/ext/sockets/sockets_arginfo.h index 4a90b4d789f..45714fb2851 100644 --- a/ext/sockets/sockets_arginfo.h +++ b/ext/sockets/sockets_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: aac197335037777d31d83d4a4040bbfcd0c55813 */ + * Stub hash: 42d486d2666d23569e70860e2b1ef203161792b3 */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_socket_select, 0, 4, MAY_BE_LONG|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(1, read, IS_ARRAY, 1) @@ -476,6 +476,9 @@ static void register_sockets_symbols(int module_number) #if defined(SO_EXCLBIND) REGISTER_LONG_CONSTANT("SO_EXCLBIND", SO_EXCLBIND, CONST_PERSISTENT); #endif +#if defined(SO_BUSY_POLL) + REGISTER_LONG_CONSTANT("SO_BUSY_POLL", SO_BUSY_POLL, CONST_PERSISTENT); +#endif #if defined(SKF_AD_OFF) REGISTER_LONG_CONSTANT("SKF_AD_OFF", SKF_AD_OFF, CONST_PERSISTENT); #endif