GNU libmicrohttpd 1.0.0
Loading...
Searching...
No Matches
mhd_tool_get_cpu_count.c File Reference

Implementation of functions to detect the number of available CPU cores. More...

Include dependency graph for mhd_tool_get_cpu_count.c:

Go to the source code of this file.

Macros

#define CPU_SETSIZE   (1024)
 
#define CPU_SETSIZE_SAFE   (64)
 

Functions

static int mhd_tool_get_sys_cpu_count_sysctl_ (void)
 
static int mhd_tool_get_proc_cpu_count_sched_getaffinity_ (void)
 
static int mhd_tool_get_proc_cpu_count_cpuset_getaffinity_ (void)
 
static int mhd_tool_get_proc_cpu_count_sched_getaffinity_np_ (void)
 
static int mhd_tool_get_proc_cpu_count_w32_ (void)
 
int mhd_tool_get_proc_cpu_count (void)
 
static int mhd_tool_get_sys_cpu_count_special_api_ (void)
 
static int mhd_tool_get_sys_cpu_count_sysctl_fallback_ (void)
 
static int mhd_tool_get_sys_cpu_count_sysconf_ (void)
 
static int mhd_tool_get_sys_cpu_count_sysconf_fallback_ (void)
 
int mhd_tool_get_system_cpu_count (void)
 

Detailed Description

Implementation of functions to detect the number of available CPU cores.

Author
Karlson2k (Evgeny Grin)

Definition in file mhd_tool_get_cpu_count.c.

Macro Definition Documentation

◆ CPU_SETSIZE

#define CPU_SETSIZE   (1024)

Definition at line 78 of file mhd_tool_get_cpu_count.c.

◆ CPU_SETSIZE_SAFE

#define CPU_SETSIZE_SAFE   (64)

Definition at line 79 of file mhd_tool_get_cpu_count.c.

Function Documentation

◆ mhd_tool_get_proc_cpu_count()

int mhd_tool_get_proc_cpu_count ( void  )

Detect the number of logical CPU cores available for the process. The number of cores available for this process could be different from value of cores available on the system. The OS may have limit on number assigned/allowed cores for single process and process may have limited CPU affinity.

Returns
the number of logical CPU cores available for the process or -1 if failed to detect

Definition at line 524 of file mhd_tool_get_cpu_count.c.

References mhd_tool_get_proc_cpu_count_cpuset_getaffinity_(), mhd_tool_get_proc_cpu_count_sched_getaffinity_(), mhd_tool_get_proc_cpu_count_sched_getaffinity_np_(), and mhd_tool_get_proc_cpu_count_w32_().

Referenced by mhd_tool_get_system_cpu_count().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mhd_tool_get_proc_cpu_count_cpuset_getaffinity_()

static int mhd_tool_get_proc_cpu_count_cpuset_getaffinity_ ( void  )
static

Detect the number of logical CPU cores available for the process by cpuset_getaffinity() function.

Returns
the number of detected logical CPU cores or -1 if failed to detect (or this function unavailable).

Definition at line 192 of file mhd_tool_get_cpu_count.c.

References CPU_SETSIZE, CPU_SETSIZE_SAFE, and NULL.

Referenced by mhd_tool_get_proc_cpu_count().

Here is the caller graph for this function:

◆ mhd_tool_get_proc_cpu_count_sched_getaffinity_()

static int mhd_tool_get_proc_cpu_count_sched_getaffinity_ ( void  )
static

Detect the number of logical CPU cores available for the process by sched_getaffinity() (and related) function.

Returns
the number of detected logical CPU cores or -1 if failed to detect (or this function unavailable).

Definition at line 129 of file mhd_tool_get_cpu_count.c.

References CPU_SETSIZE, CPU_SETSIZE_SAFE, and NULL.

Referenced by mhd_tool_get_proc_cpu_count().

Here is the caller graph for this function:

◆ mhd_tool_get_proc_cpu_count_sched_getaffinity_np_()

static int mhd_tool_get_proc_cpu_count_sched_getaffinity_np_ ( void  )
static

Detect the number of logical CPU cores available for the process by sched_getaffinity_np() (and related) function.

Returns
the number of detected logical CPU cores or -1 if failed to detect (or this function unavailable).

Definition at line 259 of file mhd_tool_get_cpu_count.c.

References mhd_tool_get_sys_cpu_count_sysctl_(), and NULL.

Referenced by mhd_tool_get_proc_cpu_count().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mhd_tool_get_proc_cpu_count_w32_()

static int mhd_tool_get_proc_cpu_count_w32_ ( void  )
static

Detect the number of logical CPU cores available for the process by W32 API functions.

Returns
the number of detected logical CPU cores or -1 if failed to detect (or this function unavailable).

Definition at line 324 of file mhd_tool_get_cpu_count.c.

References NULL.

Referenced by mhd_tool_get_proc_cpu_count().

Here is the caller graph for this function:

◆ mhd_tool_get_sys_cpu_count_special_api_()

static int mhd_tool_get_sys_cpu_count_special_api_ ( void  )
static

Detect the number of processors by special API functions

Returns
number of processors as returned by special API functions or -1 in case of error or special API functions unavailable

Definition at line 569 of file mhd_tool_get_cpu_count.c.

References NULL.

Referenced by mhd_tool_get_system_cpu_count().

Here is the caller graph for this function:

◆ mhd_tool_get_sys_cpu_count_sysconf_()

static int mhd_tool_get_sys_cpu_count_sysconf_ ( void  )
static

Detect the number of processors by sysconf() function in reliable way.

This function uses reliable identificators that coreponds to actual number of CPU cores online currently.

Returns
number of processors as returned by 'sysconf' function or -1 in case of error or 'sysconf' unavailable

Definition at line 812 of file mhd_tool_get_cpu_count.c.

Referenced by mhd_tool_get_system_cpu_count().

Here is the caller graph for this function:

◆ mhd_tool_get_sys_cpu_count_sysconf_fallback_()

static int mhd_tool_get_sys_cpu_count_sysconf_fallback_ ( void  )
static

Detect the number of processors by sysconf() function, using fallback way.

This function uses less reliable (compared to mhd_tool_get_sys_cpu_count_sysconf_()) ways to detect the number of available CPU cores and may return values corresponding to the number of physically available (but possibly not used by the kernel) CPU logical cores.

Returns
number of processors as returned by 'sysconf' function or -1 in case of error or 'sysconf' unavailable

Definition at line 848 of file mhd_tool_get_cpu_count.c.

Referenced by mhd_tool_get_system_cpu_count().

Here is the caller graph for this function:

◆ mhd_tool_get_sys_cpu_count_sysctl_()

static int mhd_tool_get_sys_cpu_count_sysctl_ ( void  )
static

Detect the number of processors by sysctl*() functions in reliable way.

This function uses reliable identificators that coreponds to actual number of CPU cores online currently.

Returns
number of processors as returned by 'sysctl*' functions or -1 in case of error or the number cannot be detected by these functions

Definition at line 668 of file mhd_tool_get_cpu_count.c.

References NULL.

Referenced by mhd_tool_get_proc_cpu_count_sched_getaffinity_np_(), and mhd_tool_get_system_cpu_count().

Here is the caller graph for this function:

◆ mhd_tool_get_sys_cpu_count_sysctl_fallback_()

static int mhd_tool_get_sys_cpu_count_sysctl_fallback_ ( void  )
static

Detect the number of processors by sysctl*() functions, using fallback way.

This function uses less reliable (compared to mhd_tool_get_sys_cpu_count_sysctl_()) ways to detect the number of available CPU cores and may return values corresponding to the number of physically available (but possibly not used by the kernel) CPU logical cores.

Returns
number of processors as returned by 'sysctl*' functions or -1 in case of error or the number cannot be detected by these functions

Definition at line 766 of file mhd_tool_get_cpu_count.c.

References NULL.

Referenced by mhd_tool_get_system_cpu_count().

Here is the caller graph for this function:

◆ mhd_tool_get_system_cpu_count()

int mhd_tool_get_system_cpu_count ( void  )

Try to detect the number of logical CPU cores available for the system. The number of available logical CPU cores could be changed any time due to CPU hotplug.

Returns
the number of logical CPU cores available, -1 if failed to detect.

Definition at line 881 of file mhd_tool_get_cpu_count.c.

References mhd_tool_get_proc_cpu_count(), mhd_tool_get_sys_cpu_count_special_api_(), mhd_tool_get_sys_cpu_count_sysconf_(), mhd_tool_get_sys_cpu_count_sysconf_fallback_(), mhd_tool_get_sys_cpu_count_sysctl_(), and mhd_tool_get_sys_cpu_count_sysctl_fallback_().

Here is the call graph for this function: