Go to the documentation of this file.
41 #ifdef _SC_NPROCESSORS_CONF
42 #define SYSCONF_NPROCESSORS_CONF_COMPAT
45 #ifdef _SC_NPROCESSORS_ONLN
46 #define SYSCONF_NPROCESSORS_ONLN_COMPAT
50 #ifdef _SC_NPROCESSORS_MAX
51 #define SYSCONF_NPROCESSORS_MAX_COMPAT
61 #ifdef SYSCONF_NPROCESSORS_CONF_COMPAT
63 nprocs = sysconf(_SC_NPROCESSORS_CONF);
66 "configured (%s)", strerror(errno));
70 if (nprocs > UINT16_MAX) {
71 SCLogDebug(
"It seems that there are more than %d CPUs "
72 "configured on this system. You can modify util-cpu.{c,h} "
73 "to use uint32_t to support it", UINT16_MAX);
77 return (uint16_t)nprocs;
80 const char* envvar = getenv(
"NUMBER_OF_PROCESSORS");
84 "processors: %s", envvar);
90 "configured from the NUMBER_OF_PROCESSORS environment variable");
93 return (uint16_t)nprocs;
96 "configured, sysconf macro unavailable");
108 #ifdef SYSCONF_NPROCESSORS_ONLN_COMPAT
110 nprocs = sysconf(_SC_NPROCESSORS_ONLN);
113 "online (%s)", strerror(errno));
117 if (nprocs > UINT16_MAX) {
118 SCLogDebug(
"It seems that there are more than %d CPUs online. "
119 "You can modify util-cpu.{c,h} to use uint32_t to "
120 "support it", UINT16_MAX);
124 return (uint16_t)nprocs;
129 "synconf macro unavailable");
143 #ifdef SYSCONF_NPROCESSORS_MAX_COMPAT
145 nprocs = sysconf(_SC_NPROCESSORS_MAX);
148 "allowed by the system (%s)", strerror(errno));
152 if (nprocs > UINT16_MAX) {
153 SCLogDebug(
"It seems that the system support more that %"PRIu16
" CPUs. You "
154 "can modify util-cpu.{c,h} to use uint32_t to support it", UINT16_MAX);
158 return (uint16_t)nprocs;
161 "the system, synconf macro unavailable");
176 SCLogDebug(
"CPUs configured: %"PRIu16, cpus_conf);
178 SCLogInfo(
"CPUs/cores online: %"PRIu16, cpus_online);
179 if (cpus_online == 0 && cpus_conf == 0)
180 SCLogInfo(
"Couldn't retireve any information of CPU's, please, send your operating "
181 "system info and check util-cpu.{c,h}");
193 #if defined(__GNUC__) && (defined(__x86_64) || defined(_X86_64_) || defined(ia_64) || defined(__i386__))
194 #if defined(__x86_64) || defined(_X86_64_) || defined(ia_64)
195 __asm__ __volatile__ (
196 "xorl %%eax,%%eax\n\t"
198 :::
"%rax",
"%rbx",
"%rcx",
"%rdx");
200 __asm__ __volatile__ (
201 "xorl %%eax,%%eax\n\t"
205 :::
"%eax",
"%ecx",
"%edx");
208 __asm__ __volatile__ (
"rdtsc" :
"=a" (a),
"=d" (d));
209 val = ((uint64_t)a) | (((uint64_t)d) << 32);
210 #if defined(__x86_64) || defined(_X86_64_) || defined(ia_64)
211 __asm__ __volatile__ (
212 "xorl %%eax,%%eax\n\t"
214 :::
"%rax",
"%rbx",
"%rcx",
"%rdx");
216 __asm__ __volatile__ (
217 "xorl %%eax,%%eax\n\t"
221 :::
"%eax",
"%ecx",
"%edx");
227 gettimeofday(&now, NULL);
228 val = (now.tv_sec * 1000000) + now.tv_usec;
uint16_t UtilCpuGetNumProcessorsConfigured(void)
Get the number of cpus configured in the system.
uint64_t UtilCpuGetTicks(void)
void UtilCpuPrintSummary(void)
Print a summary of CPUs detected (configured and online)
int StringParseInt64(int64_t *res, int base, size_t len, const char *str)
#define SCLogInfo(...)
Macro used to log INFORMATIONAL messages.
#define SCLogError(err_code,...)
Macro used to log ERROR messages.
#define SCLogWarning(err_code,...)
Macro used to log WARNING messages.
uint16_t UtilCpuGetNumProcessorsOnline(void)
Get the number of cpus online in the system.
uint16_t UtilCpuGetNumProcessorsMax(void)
Get the maximum number of cpus allowed in the system This syscall is present on Solaris,...