27 lines
850 B
C++
27 lines
850 B
C++
// SPDX-FileCopyrightText: 2023 Tobias Schmidl
|
|
//
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
#include <glimpses/glimpses.hpp>
|
|
#include <sched.h>
|
|
#include <thread>
|
|
#include <unistd.h>
|
|
|
|
using namespace glimpses;
|
|
|
|
Glimpses::Glimpses()
|
|
{
|
|
}
|
|
|
|
Glimpses::CPUSet Glimpses::getCPUCount() const
|
|
{
|
|
cpu_set_t cpuset;
|
|
auto minmax = [](int64_t min, int64_t value, int64_t max) -> CPUCount {
|
|
return std::min(std::max(value, min), max);
|
|
};
|
|
sched_getaffinity(0, sizeof(cpuset), &cpuset);
|
|
return CPUSet{{"configured", minmax(0, sysconf(_SC_NPROCESSORS_CONF), MAX_CPU_COUNT)},
|
|
{"logical", minmax(0, std::thread::hardware_concurrency(), MAX_CPU_COUNT)},
|
|
{"online", minmax(0, sysconf(_SC_NPROCESSORS_ONLN), MAX_CPU_COUNT)},
|
|
{"allowed", minmax(0, CPU_COUNT(&cpuset), MAX_CPU_COUNT)}};
|
|
}
|