40 #ifdef _SC_NPROCESSORS_CONF 41 #define SYSCONF_NPROCESSORS_CONF_COMPAT 44 #ifdef _SC_NPROCESSORS_ONLN 45 #define SYSCONF_NPROCESSORS_ONLN_COMPAT 49 #ifdef _SC_NPROCESSORS_MAX 50 #define SYSCONF_NPROCESSORS_MAX_COMPAT 60 #ifdef SYSCONF_NPROCESSORS_CONF_COMPAT 62 nprocs = sysconf(_SC_NPROCESSORS_CONF);
65 "configured (%s)", strerror(errno));
69 if (nprocs > UINT16_MAX) {
70 SCLogDebug(
"It seems that there are more than %d CPUs " 71 "configured on this system. You can modify util-cpu.{c,h} " 72 "to use uint32_t to support it", UINT16_MAX);
76 return (uint16_t)nprocs;
79 const char* envvar = getenv(
"NUMBER_OF_PROCESSORS");
80 nprocs = (NULL != envvar) ? atoi(envvar) : 0;
83 "configured from the NUMBER_OF_PROCESSORS environment variable");
86 return (uint16_t)nprocs;
89 "configured, sysconf macro unavailable");
101 #ifdef SYSCONF_NPROCESSORS_ONLN_COMPAT 103 nprocs = sysconf(_SC_NPROCESSORS_ONLN);
106 "online (%s)", strerror(errno));
110 if (nprocs > UINT16_MAX) {
111 SCLogDebug(
"It seems that there are more than %d CPUs online. " 112 "You can modify util-cpu.{c,h} to use uint32_t to " 113 "support it", UINT16_MAX);
122 "synconf macro unavailable");
136 #ifdef SYSCONF_NPROCESSORS_MAX_COMPAT 138 nprocs = sysconf(_SC_NPROCESSORS_MAX);
141 "allowed by the system (%s)", strerror(errno));
145 if (nprocs > UINT16_MAX) {
146 SCLogDebug(
"It seems that the system support more that %"PRIu16
" CPUs. You " 147 "can modify util-cpu.{c,h} to use uint32_t to support it", UINT16_MAX);
151 return (uint16_t)nprocs;
154 "the system, synconf macro unavailable");
169 SCLogDebug(
"CPUs configured: %"PRIu16, cpus_conf);
171 SCLogInfo(
"CPUs/cores online: %"PRIu16, cpus_online);
172 if (cpus_online == 0 && cpus_conf == 0)
173 SCLogInfo(
"Couldn't retireve any information of CPU's, please, send your operating " 174 "system info and check util-cpu.{c,h}");
186 #if defined(__GNUC__) && (defined(__x86_64) || defined(_X86_64_) || defined(ia_64) || defined(__i386__)) 187 #if defined(__x86_64) || defined(_X86_64_) || defined(ia_64) 188 __asm__ __volatile__ (
189 "xorl %%eax,%%eax\n\t" 191 :::
"%rax",
"%rbx",
"%rcx",
"%rdx");
193 __asm__ __volatile__ (
194 "xorl %%eax,%%eax\n\t" 198 :::
"%eax",
"%ecx",
"%edx");
201 __asm__ __volatile__ (
"rdtsc" :
"=a" (a),
"=d" (d));
202 val = ((uint64_t)a) | (((uint64_t)d) << 32);
203 #if defined(__x86_64) || defined(_X86_64_) || defined(ia_64) 204 __asm__ __volatile__ (
205 "xorl %%eax,%%eax\n\t" 207 :::
"%rax",
"%rbx",
"%rcx",
"%rdx");
209 __asm__ __volatile__ (
210 "xorl %%eax,%%eax\n\t" 214 :::
"%eax",
"%ecx",
"%edx");
220 gettimeofday(&now, NULL);
221 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 SCLogError(err_code,...)
Macro used to log ERROR messages.
void UtilCpuPrintSummary(void)
Print a summary of CPUs detected (configured and online)
#define SCLogInfo(...)
Macro used to log INFORMATIONAL 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, but it's not on linux or macosx. Maybe you should look at UtilCpuGetNumProcessorsConfigured()