Welcome! Log In Create A New Profile

Advanced

[nginx] Detect cache line size at runtime on macOS.

Sergey Kandaurov
March 27, 2024 01:48PM
details: https://hg.nginx.org/nginx/rev/61cd12c25878
branches:
changeset: 9231:61cd12c25878
user: Piotr Sikora <piotr@aviatrix.com>
date: Mon Feb 26 20:00:40 2024 +0000
description:
Detect cache line size at runtime on macOS.

Notably, Apple Silicon CPUs have 128 byte cache line size,
which is twice the default configured for generic aarch64.

Signed-off-by: Piotr Sikora <piotr@aviatrix.com>

diffstat:

src/os/unix/ngx_darwin_init.c | 16 +++++++++++-----
src/os/unix/ngx_posix_init.c | 5 ++++-
2 files changed, 15 insertions(+), 6 deletions(-)

diffs (55 lines):

diff -r fb989e24c60a -r 61cd12c25878 src/os/unix/ngx_darwin_init.c
--- a/src/os/unix/ngx_darwin_init.c Mon Feb 26 20:00:38 2024 +0000
+++ b/src/os/unix/ngx_darwin_init.c Mon Feb 26 20:00:40 2024 +0000
@@ -9,11 +9,12 @@
#include <ngx_core.h>


-char ngx_darwin_kern_ostype[16];
-char ngx_darwin_kern_osrelease[128];
-int ngx_darwin_hw_ncpu;
-int ngx_darwin_kern_ipc_somaxconn;
-u_long ngx_darwin_net_inet_tcp_sendspace;
+char ngx_darwin_kern_ostype[16];
+char ngx_darwin_kern_osrelease[128];
+int ngx_darwin_hw_ncpu;
+int ngx_darwin_kern_ipc_somaxconn;
+u_long ngx_darwin_net_inet_tcp_sendspace;
+int64_t ngx_darwin_hw_cachelinesize;

ngx_uint_t ngx_debug_malloc;

@@ -56,6 +57,10 @@ sysctl_t sysctls[] = {
&ngx_darwin_kern_ipc_somaxconn,
sizeof(ngx_darwin_kern_ipc_somaxconn), 0 },

+ { "hw.cachelinesize",
+ &ngx_darwin_hw_cachelinesize,
+ sizeof(ngx_darwin_hw_cachelinesize), 0 },
+
{ NULL, NULL, 0, 0 }
};

@@ -155,6 +160,7 @@ ngx_os_specific_init(ngx_log_t *log)
return NGX_ERROR;
}

+ ngx_cacheline_size = ngx_darwin_hw_cachelinesize;
ngx_ncpu = ngx_darwin_hw_ncpu;

if (ngx_darwin_kern_ipc_somaxconn > 32767) {
diff -r fb989e24c60a -r 61cd12c25878 src/os/unix/ngx_posix_init.c
--- a/src/os/unix/ngx_posix_init.c Mon Feb 26 20:00:38 2024 +0000
+++ b/src/os/unix/ngx_posix_init.c Mon Feb 26 20:00:40 2024 +0000
@@ -51,7 +51,10 @@ ngx_os_init(ngx_log_t *log)
}

ngx_pagesize = getpagesize();
- ngx_cacheline_size = NGX_CPU_CACHE_LINE;
+
+ if (ngx_cacheline_size == 0) {
+ ngx_cacheline_size = NGX_CPU_CACHE_LINE;
+ }

for (n = ngx_pagesize; n >>= 1; ngx_pagesize_shift++) { /* void */ }

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[nginx] Detect cache line size at runtime on macOS.

Sergey Kandaurov 248 March 27, 2024 01:48PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 119
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready