Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE
pacemaker.8750
pacemaker-libcrmcommon-function-get-number-of-C...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File pacemaker-libcrmcommon-function-get-number-of-CPU-cores.patch of Package pacemaker.8750
commit 89175e75f3b38b10ea163c1a8d621d1296570e7f Author: Ken Gaillot <kgaillot@redhat.com> Date: Fri Apr 28 14:30:55 2017 -0500 Feature: libcrmcommon: add function to get number of CPU cores Compared to the previous implementation in crmd/throttle.c, this parses /proc/stat, which is smaller than /proc/cpuinfo. diff --git a/include/crm/common/internal.h b/include/crm/common/internal.h index 475128f2f..c34b03b89 100644 --- a/include/crm/common/internal.h +++ b/include/crm/common/internal.h @@ -54,6 +54,7 @@ int crm_write_sync(int fd, const char *contents); int crm_procfs_process_info(struct dirent *entry, char *name, int *pid); int crm_procfs_pid_of(const char *name); +unsigned int crm_procfs_num_cores(void); /* internal XML schema functions (from xml.c) */ diff --git a/lib/common/procfs.c b/lib/common/procfs.c index 12d01ff7a..fbbf9ebdd 100644 --- a/lib/common/procfs.c +++ b/lib/common/procfs.c @@ -28,6 +28,7 @@ #include <sys/stat.h> #include <sys/types.h> #include <dirent.h> +#include <ctype.h> /*! * \internal @@ -140,3 +141,32 @@ crm_procfs_pid_of(const char *name) closedir(dp); return pid; } + +/*! + * \internal + * \brief Calculate number of logical CPU cores from procfs + * + * \return Number of cores (or 1 if unable to determine) + */ +unsigned int +crm_procfs_num_cores(void) +{ + int cores = 0; + FILE *stream = NULL; + + /* Parse /proc/stat instead of /proc/cpuinfo because it's smaller */ + stream = fopen("/proc/stat", "r"); + if (stream == NULL) { + crm_perror(LOG_INFO, "Could not open /proc/stat"); + } else { + char buffer[2048]; + + while (fgets(buffer, sizeof(buffer), stream)) { + if (!strncmp(buffer, "cpu", 3) && isdigit(buffer[3])) { + ++cores; + } + } + fclose(stream); + } + return cores? cores : 1; +}
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor