Skip to content

Commit

Permalink
auto: Add a check for Linux's sched_getaffinity(2)
Browse files Browse the repository at this point in the history
This will help to better determine the number of router threads to
create in certain situations.

Unlike sysconf(_SC_NPROCESSORS_ONLN) this takes into account per-process
cpu allowed masks as set by sched_setaffinity(2)/cpusets etc.

So while a system may have 64 on-line cpu's, Unit itself may be limited
to using just four of them in which case we should create four extra
router threads, not sixty-four!

Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
  • Loading branch information
ac000 committed Aug 12, 2024
1 parent 2022427 commit 9c137ad
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
19 changes: 19 additions & 0 deletions auto/sched
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright (C) Andrew Clayton
# Copyright (C) NGINX, Inc.


nxt_feature="Linux sched_getaffinity()"
nxt_feature_name=NXT_HAVE_LINUX_SCHED_GETAFFINITY
nxt_feature_run=no
nxt_feature_incs=
nxt_feature_libs=
nxt_feature_test="#define _GNU_SOURCE
#include <sched.h>

int main(void) {
cpu_set_t set;

sched_getaffinity(0, sizeof(set), &set);
return 0;
}"
. auto/feature
1 change: 1 addition & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ fi
. auto/cgroup
. auto/isolation
. auto/capability
. auto/sched


case "$NXT_SYSTEM_PLATFORM" in
Expand Down

0 comments on commit 9c137ad

Please sign in to comment.