Skip to content

Commit

Permalink
Use sysconf to determine cacheline size at runtime.
Browse files Browse the repository at this point in the history
Determine cacheline size at runtime if supported
using sysconf(_SC_LEVEL1_DCACHE_LINESIZE). In case not supported,
fallback to compile time defaults.
  • Loading branch information
debayang committed Dec 11, 2017
1 parent b75f419 commit d2d737e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions auto/unix
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,16 @@ ngx_feature_test="sysconf(_SC_NPROCESSORS_ONLN)"
. auto/feature


ngx_feature="sysconf(_SC_LEVEL1_DCACHE_LINESIZE)"
ngx_feature_name="NGX_HAVE_LEVEL1_DCACHE_LINESIZE"
ngx_feature_run=no
ngx_feature_incs=
ngx_feature_path=
ngx_feature_libs=
ngx_feature_test="sysconf(_SC_LEVEL1_DCACHE_LINESIZE)"
. auto/feature


ngx_feature="openat(), fstatat()"
ngx_feature_name="NGX_HAVE_OPENAT"
ngx_feature_run=no
Expand Down
10 changes: 10 additions & 0 deletions src/os/unix/ngx_posix_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ ngx_os_init(ngx_log_t *log)
{
ngx_time_t *tp;
ngx_uint_t n;
#if (NGX_HAVE_LEVEL1_DCACHE_LINESIZE)
long size;
#endif

#if (NGX_HAVE_OS_SPECIFIC_INIT)
if (ngx_os_specific_init(log) != NGX_OK) {
Expand All @@ -62,6 +65,13 @@ ngx_os_init(ngx_log_t *log)
ngx_ncpu = 1;
}

#if (NGX_HAVE_LEVEL1_DCACHE_LINESIZE)
size = sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
if (size > 0) {
ngx_cacheline_size = size;
}
#endif

ngx_cpuinfo();

if (getrlimit(RLIMIT_NOFILE, &rlmt) == -1) {
Expand Down

0 comments on commit d2d737e

Please sign in to comment.