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>
This commit is contained in:
Piotr Sikora 2024-02-26 20:00:40 +00:00
parent 818f98da1c
commit 1bc19fe2db
2 changed files with 15 additions and 6 deletions

View File

@ -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) {

View File

@ -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 */ }