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");
147 SCLogDebug(
"CPUs configured: %"PRIu16, cpus_conf);
149 SCLogInfo(
"CPUs/cores online: %"PRIu16, cpus_online);
150 if (cpus_online == 0 && cpus_conf == 0)
151 SCLogInfo(
"Couldn't retrieve any information of CPU's, please, send your operating "
152 "system info and check util-cpu.{c,h}");
164#if defined(__GNUC__) && (defined(__x86_64) || defined(_X86_64_) || defined(ia_64) || defined(__i386__))
165#if defined(__x86_64) || defined(_X86_64_) || defined(ia_64)
166 __asm__ __volatile__ (
167 "xorl %%eax,%%eax\n\t"
169 :::
"%rax",
"%rbx",
"%rcx",
"%rdx");
171 __asm__ __volatile__ (
172 "xorl %%eax,%%eax\n\t"
176 :::
"%eax",
"%ecx",
"%edx");
179 __asm__ __volatile__ (
"rdtsc" :
"=a" (a),
"=d" (d));
180 val = ((uint64_t)a) | (((uint64_t)d) << 32);
181#if defined(__x86_64) || defined(_X86_64_) || defined(ia_64)
182 __asm__ __volatile__ (
183 "xorl %%eax,%%eax\n\t"
185 :::
"%rax",
"%rbx",
"%rcx",
"%rdx");
187 __asm__ __volatile__ (
188 "xorl %%eax,%%eax\n\t"
192 :::
"%eax",
"%ecx",
"%edx");
198 gettimeofday(&now, NULL);
199 val = (now.tv_sec * 1000000) + now.tv_usec;
int StringParseInt64(int64_t *res, int base, size_t len, const char *str)
uint16_t UtilCpuGetNumProcessorsConfigured(void)
Get the number of cpus configured in the system.
void UtilCpuPrintSummary(void)
Print a summary of CPUs detected (configured and online)
uint16_t UtilCpuGetNumProcessorsOnline(void)
Get the number of cpus online in the system.
uint64_t UtilCpuGetTicks(void)
#define SCLogWarning(...)
Macro used to log WARNING messages.
#define SCLogInfo(...)
Macro used to log INFORMATIONAL messages.
#define SCLogError(...)
Macro used to log ERROR messages.