10b790afbSMichael Jones //===-- Implementation of sched_getcpucount -------------------------------===// 20b790afbSMichael Jones // 30b790afbSMichael Jones // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b790afbSMichael Jones // See https://llvm.org/LICENSE.txt for license information. 50b790afbSMichael Jones // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b790afbSMichael Jones // 70b790afbSMichael Jones //===----------------------------------------------------------------------===// 80b790afbSMichael Jones 90b790afbSMichael Jones #include "src/sched/sched_getcpucount.h" 100b790afbSMichael Jones 110b790afbSMichael Jones #include "src/__support/common.h" 12*5ff3ff33SPetr Hosek #include "src/__support/macros/config.h" 130b790afbSMichael Jones 140b790afbSMichael Jones #include <sched.h> 150b790afbSMichael Jones #include <stddef.h> 160b790afbSMichael Jones 17*5ff3ff33SPetr Hosek namespace LIBC_NAMESPACE_DECL { 180b790afbSMichael Jones 190b790afbSMichael Jones LLVM_LIBC_FUNCTION(int, __sched_getcpucount, 200b790afbSMichael Jones (size_t cpuset_size, const cpu_set_t *mask)) { 210b790afbSMichael Jones int result = 0; 220b790afbSMichael Jones for (size_t i = 0; i < cpuset_size / sizeof(long); ++i) { 230b790afbSMichael Jones result += __builtin_popcountl(mask->__mask[i]); 240b790afbSMichael Jones } 250b790afbSMichael Jones return result; 260b790afbSMichael Jones } 270b790afbSMichael Jones 28*5ff3ff33SPetr Hosek } // namespace LIBC_NAMESPACE_DECL 29