Skip to content

Commit 96e2378

Browse files
committed
feat: implement CPU_ISSET[_S] macro and fix CPU_SET[_S] macro
1 parent 597b872 commit 96e2378

File tree

9 files changed

+85
-3
lines changed

9 files changed

+85
-3
lines changed

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,7 @@ if(LLVM_LIBC_FULL_BUILD)
912912
libc.src.sched.__sched_getcpucount
913913
libc.src.sched.__sched_setcpuzero
914914
libc.src.sched.__sched_setcpuset
915+
libc.src.sched.__sched_getcpuisset
915916

916917
# strings.h entrypoints
917918
libc.src.strings.strcasecmp_l

libc/config/linux/riscv/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,7 @@ if(LLVM_LIBC_FULL_BUILD)
860860
libc.src.sched.__sched_getcpucount
861861
libc.src.sched.__sched_setcpuzero
862862
libc.src.sched.__sched_setcpuset
863+
libc.src.sched.__sched_getcpuisset
863864

864865
# setjmp.h entrypoints
865866
libc.src.setjmp.longjmp

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,6 +1030,7 @@ if(LLVM_LIBC_FULL_BUILD)
10301030
libc.src.sched.__sched_getcpucount
10311031
libc.src.sched.__sched_setcpuzero
10321032
libc.src.sched.__sched_setcpuset
1033+
libc.src.sched.__sched_getcpuisset
10331034

10341035
# setjmp.h entrypoints
10351036
libc.src.setjmp.longjmp

libc/include/llvm-libc-macros/linux/sched-macros.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
#define CPU_COUNT(set) CPU_COUNT_S(sizeof(cpu_set_t), set)
3030
#define CPU_ZERO_S(setsize, set) __sched_setcpuzero(setsize, set)
3131
#define CPU_ZERO(set) CPU_ZERO_S(sizeof(cpu_set_t), set)
32-
#define CPU_SET_S(setsize, set) __sched_setcpuset(setsize, set)
33-
#define CPU_SET(setsize, set) CPU_SET_S(sizeof(cpt_set_t), set)
32+
#define CPU_SET_S(cpu, setsize, set) __sched_setcpuset(cpu, setsize, set)
33+
#define CPU_SET(cpu, setsize, set) CPU_SET_S(cpu, sizeof(cpt_set_t), set)
34+
#define CPU_ISSET_S(cpu, setsize, set) __sched_getcpuisset(cpu, setsize, set)
35+
#define CPU_ISSET(cpu, setsize, set) CPU_ISSET_S(cpu, sizeof(cpt_set_t), set)
3436

3537
#endif // LLVM_LIBC_MACROS_LINUX_SCHED_MACROS_H

libc/src/sched/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,10 @@ add_entrypoint_object(
9292
DEPENDS
9393
.${LIBC_TARGET_OS}.__sched_setcpuset
9494
)
95+
96+
add_entrypoint_object(
97+
__sched_getcpuisset
98+
ALIAS
99+
DEPENDS
100+
.${LIBC_TARGET_OS}.__sched_getcpuisset
101+
)

libc/src/sched/linux/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,19 @@ add_entrypoint_object(
154154
HDRS
155155
../sched_setcpuset.h
156156
DEPENDS
157+
libc.hdr.sched_macros
158+
libc.hdr.types.cpu_set_t
159+
libc.hdr.types.size_t
160+
)
161+
162+
add_entrypoint_object(
163+
__sched_getcpuisset
164+
SRCS
165+
sched_getcpuisset.cpp
166+
HDRS
167+
../sched_getcpuisset.h
168+
DEPENDS
169+
libc.hdr.sched_macros
157170
libc.hdr.types.cpu_set_t
158171
libc.hdr.types.size_t
159172
)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//===-- Implementation of sched_getcpuisset -------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "src/sched/sched_getcpuisset.h"
10+
11+
#include "src/__support/common.h" // LLVM_LIBC_FUNCTION
12+
#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL
13+
14+
#include "hdr/sched_macros.h" // NCPUBITS
15+
#include "hdr/types/cpu_set_t.h"
16+
#include "hdr/types/size_t.h"
17+
18+
namespace LIBC_NAMESPACE_DECL {
19+
20+
LLVM_LIBC_FUNCTION(int, __sched_getcpuisset,
21+
(int cpu, const size_t cpuset_size, cpu_set_t *set)) {
22+
if (static_cast<size_t>(cpu) / 8 < cpuset_size) {
23+
const size_t element_index = static_cast<size_t>(cpu) / NCPUBITS;
24+
const size_t bit_position = static_cast<size_t>(cpu) % NCPUBITS;
25+
26+
const unsigned long mask = 1UL << bit_position;
27+
return set->__mask[element_index] & mask;
28+
}
29+
30+
return 0;
31+
}
32+
33+
} // namespace LIBC_NAMESPACE_DECL

libc/src/sched/linux/sched_setcpuset.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ LLVM_LIBC_FUNCTION(void, __sched_setcpuset,
2424
const size_t bit_position = static_cast<size_t>(cpu) % NCPUBITS;
2525

2626
const unsigned long mask = 1UL << bit_position;
27-
set->__bits[element_index] |= mask;
27+
set->__mask[element_index] |= mask;
2828
}
2929
}
3030

libc/src/sched/sched_getcpuisset.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//===-- Implementation header for sched_getcpuisset -------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_SRC_SCHED_SCHED_GETCPUISSET_H
10+
#define LLVM_LIBC_SRC_SCHED_SCHED_GETCPUISSET_H
11+
12+
#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL
13+
14+
#include "hdr/types/cpu_set_t.h"
15+
#include "hdr/types/size_t.h"
16+
17+
namespace LIBC_NAMESPACE_DECL {
18+
19+
// for internal use in the CPU_ISSET macro
20+
int __sched_getcpuisset(int cpu, const size_t cpuset_size, cpu_set_t *set);
21+
22+
} // namespace LIBC_NAMESPACE_DECL
23+
24+
#endif // LLVM_LIBC_SRC_SCHED_SCHED_GETCPUISSET_H

0 commit comments

Comments
 (0)