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);
65 SCLogError(
"Couldn't retrieve the number of cpus "
71 if (nprocs > UINT16_MAX) {
72 SCLogDebug(
"It seems that there are more than %d CPUs "
73 "configured on this system. You can modify util-cpu.{c,h} "
74 "to use uint32_t to support it", UINT16_MAX);
78 return (uint16_t)nprocs;
81 const char* envvar = getenv(
"NUMBER_OF_PROCESSORS");
91 SCLogError(
"Couldn't retrieve the number of cpus "
92 "configured from the NUMBER_OF_PROCESSORS environment variable");
95 return (uint16_t)nprocs;
97 SCLogError(
"Couldn't retrieve the number of cpus "
98 "configured, sysconf macro unavailable");
110 #ifdef SYSCONF_NPROCESSORS_ONLN_COMPAT
112 nprocs = sysconf(_SC_NPROCESSORS_ONLN);
114 SCLogError(
"Couldn't retrieve the number of cpus "
120 if (nprocs > UINT16_MAX) {
121 SCLogDebug(
"It seems that there are more than %d CPUs online. "
122 "You can modify util-cpu.{c,h} to use uint32_t to "
123 "support it", UINT16_MAX);
127 return (uint16_t)nprocs;
131 SCLogError(
"Couldn't retrieve the number of cpus online, "
132 "synconf macro unavailable");
146 #ifdef SYSCONF_NPROCESSORS_MAX_COMPAT
148 nprocs = sysconf(_SC_NPROCESSORS_MAX);
150 SCLogError(
"Couldn't retrieve the maximum number of cpus "
151 "allowed by the system (%s)",
156 if (nprocs > UINT16_MAX) {
157 SCLogDebug(
"It seems that the system support more that %"PRIu16
" CPUs. You "
158 "can modify util-cpu.{c,h} to use uint32_t to support it", UINT16_MAX);
162 return (uint16_t)nprocs;
164 SCLogError(
"Couldn't retrieve the maximum number of cpus allowed by "
165 "the system, synconf macro unavailable");
180 SCLogDebug(
"CPUs configured: %"PRIu16, cpus_conf);
182 SCLogInfo(
"CPUs/cores online: %"PRIu16, cpus_online);
183 if (cpus_online == 0 && cpus_conf == 0)
184 SCLogInfo(
"Couldn't retrieve any information of CPU's, please, send your operating "
185 "system info and check util-cpu.{c,h}");
197 #if defined(__GNUC__) && (defined(__x86_64) || defined(_X86_64_) || defined(ia_64) || defined(__i386__))
198 #if defined(__x86_64) || defined(_X86_64_) || defined(ia_64)
199 __asm__ __volatile__ (
200 "xorl %%eax,%%eax\n\t"
202 :::
"%rax",
"%rbx",
"%rcx",
"%rdx");
204 __asm__ __volatile__ (
205 "xorl %%eax,%%eax\n\t"
209 :::
"%eax",
"%ecx",
"%edx");
212 __asm__ __volatile__ (
"rdtsc" :
"=a" (a),
"=d" (d));
213 val = ((uint64_t)a) | (((uint64_t)d) << 32);
214 #if defined(__x86_64) || defined(_X86_64_) || defined(ia_64)
215 __asm__ __volatile__ (
216 "xorl %%eax,%%eax\n\t"
218 :::
"%rax",
"%rbx",
"%rcx",
"%rdx");
220 __asm__ __volatile__ (
221 "xorl %%eax,%%eax\n\t"
225 :::
"%eax",
"%ecx",
"%edx");
231 gettimeofday(&now, NULL);
232 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)
#define SCLogWarning(...)
Macro used to log WARNING messages.
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(...)
Macro used to log ERROR 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,...