test/ProfileTest.cpp
// Get the number of CPUs in the cpuset of the test process
Get the number of CPUs in the cpuset of the test process
Get the number of CPUs in the cpuset of the test process
static size_t num_affinitized_cpus()
{
    int cpus_in_set = num_configured_cpus();
    static const int MAX_CPUS = 1 << 30;
    while (cpus_in_set < MAX_CPUS) {
        auto cpu_set = std::unique_ptr<cpu_set_t, std::function<void(cpu_set_t *)> >(
            CPU_ALLOC(cpus_in_set), [](cpu_set_t *cpu_set) { CPU_FREE(cpu_set); });
        size_t cpu_set_size = CPU_ALLOC_SIZE(cpus_in_set);
        if (sched_getaffinity(0, cpu_set_size, cpu_set.get()) == -1) {
            if (errno != EINVAL) {
                throw Exception("Unable to get affinity mask for tests",
                                errno ? errno : GEOPM_ERROR_RUNTIME, __FILE__,
                                __LINE__);
            }
            cpus_in_set *= 2;
        }
        else {
            return CPU_COUNT_S(cpu_set_size, cpu_set.get());
        }
    }
    throw Exception("Unable to get cpu count for tests. Gave up at cpu set size of " +
                        std::to_string(cpus_in_set),
                    GEOPM_ERROR_RUNTIME, __FILE__, __LINE__);
}
static size_t num_affinitized_cpus ( ) { int cpus_in_set = num_configured_cpus ( ) ; static const int MAX_CPUS = 1 << 30 ; while ( cpus_in_set < MAX_CPUS ) { auto cpu_set = std :: unique_ptr < cpu_set_t , std :: function < void ( cpu_set_t * ) > > ( CPU_ALLOC ( cpus_in_set ) , [ ] ( cpu_set_t * cpu_set ) { CPU_FREE ( cpu_set ) ; } ) ; size_t cpu_set_size = CPU_ALLOC_SIZE ( cpus_in_set ) ; if ( sched_getaffinity ( 0 , cpu_set_size , cpu_set . get ( ) ) == -1 ) { if ( errno != EINVAL ) { throw Exception ( " " , errno ? errno : GEOPM_ERROR_RUNTIME , __FILE__ , __LINE__ ) ; } cpus_in_set *= 2 ; } else { return CPU_COUNT_S ( cpu_set_size , cpu_set . get ( ) ) ; } } throw Exception ( " " + std :: to_string ( cpus_in_set ) , GEOPM_ERROR_RUNTIME , __FILE__ , __LINE__ ) ; }
Get the number of CPUs in the cpuset of the test process
Get the number of CPUs in the cpuset of the test process
// The number of bits in the system's CPU set isn't known ahead of time. // We need to repeatedly try with increasing set sizes until we stop // seeing errors for sets that are too small, or until we give up. // Otherwise, move on to the next-larger attempt