Skip to content

Commit

Permalink
Warn when we can't retrieve a core count
Browse files Browse the repository at this point in the history
  • Loading branch information
arr2036 committed May 31, 2023
1 parent a276ef7 commit 5b38c1a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/lib/server/main_config.c
Expand Up @@ -453,6 +453,10 @@ static int num_workers_dflt(CONF_PAIR **out, void *parent, CONF_SECTION *cs, fr_
main_config_t *conf = parent;

value = fr_hw_num_cores_active();
if (value < 0) {
cf_log_pwarn(parent, "Failed retrieving core count, defaulting to 1 worker");
value = 1;
}

/*
* If we've got more than four times
Expand Down
10 changes: 8 additions & 2 deletions src/lib/util/hw.c
Expand Up @@ -25,6 +25,9 @@
#define CORES_DEFAULT 1

#include <freeradius-devel/util/hw.h>
#include <freeradius-devel/util/syserror.h>
#include <freeradius-devel/util/strerror.h>
#include <errno.h>

#if defined(__APPLE__) || defined(__FreeBSD__)
#include <sys/sysctl.h>
Expand Down Expand Up @@ -96,13 +99,16 @@ uint32_t fr_hw_num_cores_active(void)
* You'd think this'd be enough to quiet clang scan,
* but it's not.
*/
if (unlikely((tsibs == 0) || (lcores == 0) || (lcores > tsibs))) return 1;
if (unlikely((tsibs == 0) || (lcores == 0) || (lcores > tsibs))) {
fr_strerror_const("Failed retrieving cpu topology info: %s", fr_syserror(errno));
return -1;
}

#ifdef STATIC_ANALYZER
/*
* Prevent static analyzer from warning about divide by zero
*/
if ((tsibs / lcores) == 0) return 1;
if ((tsibs / lcores) == 0) return -1;
#endif

return lcores / (tsibs / lcores);
Expand Down

0 comments on commit 5b38c1a

Please sign in to comment.