This commit is contained in:
Andrew Clayton 2025-12-17 15:20:45 +08:00 committed by GitHub
commit 4079213c5f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 33 additions and 0 deletions

View File

@ -292,6 +292,17 @@ ngx_feature_test="cpu_set_t mask;
. auto/feature
ngx_feature="sched_getaffinity()"
ngx_feature_name="NGX_HAVE_SCHED_GETAFFINITY"
ngx_feature_run=no
ngx_feature_incs="#include <sched.h>"
ngx_feature_path=
ngx_feature_libs=
ngx_feature_test="cpu_set_t set;
sched_getaffinity(0, sizeof(set), &set);"
. auto/feature
ngx_feature="SO_SETFIB"
ngx_feature_name="NGX_HAVE_SETFIB"
ngx_feature_run=no

View File

@ -64,6 +64,28 @@ ngx_os_init(ngx_log_t *log)
}
#endif
#if (NGX_HAVE_SCHED_GETAFFINITY)
if (ngx_ncpu > 0) {
int err;
size_t sz;
cpu_set_t *mask;
mask = CPU_ALLOC(ngx_ncpu);
if (mask == NULL) {
return NGX_ERROR;
}
sz = CPU_ALLOC_SIZE(ngx_ncpu);
err = sched_getaffinity(0, sz, mask);
if (err == 0) {
ngx_ncpu = CPU_COUNT_S(sz, mask);
}
CPU_FREE(mask);
}
#endif
if (ngx_ncpu < 1) {
ngx_ncpu = 1;
}