62 lines
1.2 KiB
C++
62 lines
1.2 KiB
C++
#pragma once
|
|
|
|
#include <cstdint>
|
|
#include <cstdlib>
|
|
#include <cstring>
|
|
#include <ctime>
|
|
#include <cstdio>
|
|
#include <sys/types.h>
|
|
#include <sys/cpuset.h>
|
|
|
|
#define DISALLOW_EVIL_CONSTRUCTORS(TypeName) \
|
|
TypeName(const TypeName &) = delete; \
|
|
void operator=(const TypeName &) = delete
|
|
|
|
#define UNUSED __attribute__((unused))
|
|
|
|
constexpr static unsigned long S2NS = 1000000000UL;
|
|
constexpr static unsigned long S2US = 1000000UL;
|
|
constexpr static unsigned long MS2NS = 1000000UL;
|
|
|
|
constexpr static int NEXT_CPU_NULL = -1;
|
|
|
|
|
|
#if defined(__x86_64__)
|
|
static inline int
|
|
cmask_get_next_cpu(uint64_t *mask)
|
|
{
|
|
int ffs = ffsll(*mask);
|
|
*mask &= ~(1ul << (ffs - 1));
|
|
return ffs - 1;
|
|
}
|
|
|
|
static inline int
|
|
cmask_get_num_cpus(const uint64_t mask)
|
|
{
|
|
return __builtin_popcount(mask);
|
|
}
|
|
#endif
|
|
|
|
static inline uint64_t
|
|
get_uptime()
|
|
{
|
|
struct timespec tp;
|
|
clock_gettime(CLOCK_MONOTONIC, &tp);
|
|
return (tp.tv_sec * S2NS + tp.tv_nsec);
|
|
}
|
|
|
|
static inline void
|
|
cpulist_to_cpuset(char * cpulist, cpuset_t * cpuset)
|
|
{
|
|
char * cpu = strtok(cpulist, ",");
|
|
CPU_ZERO(cpuset);
|
|
|
|
while (cpu != nullptr) {
|
|
CPU_SET(atoi(cpu), cpuset);
|
|
cpu = strtok(nullptr, ",");
|
|
}
|
|
}
|
|
|
|
#define ATTR_UNUSED __attribute__((unused))
|
|
|