Skip to content

Commit bda87e0

Browse files
authored
[libc][sched] Implement CPU_ZERO, CPU_ISSET, CPU_SET macros (#131524)
This PR implements the following macros for `sched.h`: - `CPU_ZERO` - `CPU_ISSET` - `CPU_SET` Fixes #124642 --------- Signed-off-by: krishna2803 <[email protected]>
1 parent 0260bcb commit bda87e0

File tree

17 files changed

+314
-1
lines changed

17 files changed

+314
-1
lines changed

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,9 @@ if(LLVM_LIBC_FULL_BUILD)
910910

911911
# sched.h entrypoints
912912
libc.src.sched.__sched_getcpucount
913+
libc.src.sched.__sched_setcpuzero
914+
libc.src.sched.__sched_setcpuset
915+
libc.src.sched.__sched_getcpuisset
913916

914917
# strings.h entrypoints
915918
libc.src.strings.strcasecmp_l

libc/config/linux/riscv/entrypoints.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,9 @@ if(LLVM_LIBC_FULL_BUILD)
858858

859859
# sched.h entrypoints
860860
libc.src.sched.__sched_getcpucount
861+
libc.src.sched.__sched_setcpuzero
862+
libc.src.sched.__sched_setcpuset
863+
libc.src.sched.__sched_getcpuisset
861864

862865
# setjmp.h entrypoints
863866
libc.src.setjmp.longjmp

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,9 @@ if(LLVM_LIBC_FULL_BUILD)
10281028

10291029
# sched.h entrypoints
10301030
libc.src.sched.__sched_getcpucount
1031+
libc.src.sched.__sched_setcpuzero
1032+
libc.src.sched.__sched_setcpuset
1033+
libc.src.sched.__sched_getcpuisset
10311034

10321035
# setjmp.h entrypoints
10331036
libc.src.setjmp.longjmp

libc/hdr/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,15 @@ add_proxy_header_library(
7272
libc.include.fenv
7373
)
7474

75+
add_proxy_header_library(
76+
sched_macros
77+
HDRS
78+
sched_macros.h
79+
FULL_BUILD_DEPENDS
80+
libc.include.sched
81+
libc.include.llvm-libc-macros.sched_macros
82+
)
83+
7584
add_proxy_header_library(
7685
signal_macros
7786
HDRS

libc/hdr/sched_macros.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===-- Definition of macros from sched.h ---------------------------------===//
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_HDR_SCHED_MACROS_H
10+
#define LLVM_LIBC_HDR_SCHED_MACROS_H
11+
12+
#ifdef LIBC_FULL_BUILD
13+
14+
#include "include/llvm-libc-macros/sched-macros.h"
15+
16+
#else // Overlay mode
17+
18+
#include <sched.h>
19+
20+
#endif // LLVM_LIBC_FULL_BUILD
21+
22+
#endif // LLVM_LIBC_HDR_SCHED_MACROS_H

libc/hdr/types/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,3 +357,11 @@ add_proxy_header_library(
357357
FULL_BUILD_DEPENDS
358358
libc.include.llvm-libc-types.struct_pollfd
359359
)
360+
361+
add_proxy_header_library(
362+
cpu_set_t
363+
HDRS
364+
cpu_set_t.h
365+
FULL_BUILD_DEPENDS
366+
libc.include.llvm-libc-types.cpu_set_t
367+
)

libc/hdr/types/cpu_set_t.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===-- Proxy for cpu_set_t -----------------------------------------------===//
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_HDR_TYPES_CPU_SET_T_H
10+
#define LLVM_LIBC_HDR_TYPES_CPU_SET_T_H
11+
12+
#ifdef LIBC_FULL_BUILD
13+
14+
#include "include/llvm-libc-types/cpu_set_t.h"
15+
16+
#else // Overlay mode
17+
18+
#include <sched.h>
19+
20+
#endif // LLVM_LIBC_FULL_BUILD
21+
22+
#endif // LLVM_LIBC_HDR_TYPES_CPU_SET_T_H

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,15 @@
2323
#define SCHED_IDLE 5
2424
#define SCHED_DEADLINE 6
2525

26+
#define CPU_SETSIZE __CPU_SETSIZE
27+
#define NCPUBITS __NCPUBITS
2628
#define CPU_COUNT_S(setsize, set) __sched_getcpucount(setsize, set)
2729
#define CPU_COUNT(set) CPU_COUNT_S(sizeof(cpu_set_t), set)
30+
#define CPU_ZERO_S(setsize, set) __sched_setcpuzero(setsize, set)
31+
#define CPU_ZERO(set) CPU_ZERO_S(sizeof(cpu_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)
2836

2937
#endif // LLVM_LIBC_MACROS_LINUX_SCHED_MACROS_H

libc/include/llvm-libc-types/cpu_set_t.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
#ifndef LLVM_LIBC_TYPES_CPU_SET_T_H
1010
#define LLVM_LIBC_TYPES_CPU_SET_T_H
1111

12+
#define __CPU_SETSIZE 1024
13+
#define __NCPUBITS (8 * sizeof(unsigned long))
14+
1215
typedef struct {
1316
// If a processor with more than 1024 CPUs is to be supported in future,
1417
// we need to adjust the size of this array.

libc/src/sched/CMakeLists.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,24 @@ add_entrypoint_object(
7878
DEPENDS
7979
.${LIBC_TARGET_OS}.__sched_getcpucount
8080
)
81+
82+
add_entrypoint_object(
83+
__sched_setcpuzero
84+
ALIAS
85+
DEPENDS
86+
.${LIBC_TARGET_OS}.__sched_setcpuzero
87+
)
88+
89+
add_entrypoint_object(
90+
__sched_setcpuset
91+
ALIAS
92+
DEPENDS
93+
.${LIBC_TARGET_OS}.__sched_setcpuset
94+
)
95+
96+
add_entrypoint_object(
97+
__sched_getcpuisset
98+
ALIAS
99+
DEPENDS
100+
.${LIBC_TARGET_OS}.__sched_getcpuisset
101+
)

0 commit comments

Comments
 (0)