mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-20 04:56:32 +00:00
Add dummy syscall sched_getaffinity
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
e1480f94ee
commit
2ecca7af6b
@ -12,6 +12,7 @@ REGRESSION_BUILD_DIR ?= $(INITRAMFS)/regression
|
||||
TEST_APPS := \
|
||||
alarm \
|
||||
clone3 \
|
||||
cpu_affinity \
|
||||
eventfd2 \
|
||||
execve \
|
||||
file_io \
|
||||
|
5
regression/apps/cpu_affinity/Makefile
Normal file
5
regression/apps/cpu_affinity/Makefile
Normal file
@ -0,0 +1,5 @@
|
||||
# SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
include ../test_common.mk
|
||||
|
||||
EXTRA_C_FLAGS :=
|
35
regression/apps/cpu_affinity/sched_getaffinity.c
Normal file
35
regression/apps/cpu_affinity/sched_getaffinity.c
Normal file
@ -0,0 +1,35 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
#define _GNU_SOURCE
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <syscall.h>
|
||||
#include <errno.h>
|
||||
#include <sched.h> // Include sched.h for CPU_SETSIZE
|
||||
|
||||
int main()
|
||||
{
|
||||
// Create a mask for CPU_SETSIZE number of CPUs
|
||||
unsigned long mask[CPU_SETSIZE / sizeof(unsigned long)];
|
||||
int mask_size = sizeof(mask);
|
||||
|
||||
// Call the raw syscall to retrieve the CPU affinity mask of the current process
|
||||
long res = syscall(__NR_sched_getaffinity, 0, mask_size, &mask);
|
||||
|
||||
if (res < 0) {
|
||||
perror("Error calling sched_getaffinity");
|
||||
return errno;
|
||||
}
|
||||
|
||||
// Print the CPUs that are part of the current process's affinity mask
|
||||
printf("Process can run on: ");
|
||||
for (int i = 0; i < CPU_SETSIZE; ++i) {
|
||||
if (mask[i / (8 * sizeof(long))] &
|
||||
(1UL << (i % (8 * sizeof(long))))) {
|
||||
printf("%d ", i);
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user