Implement getcpu syscall and add corresponding test application

This commit is contained in:
wheatfox
2025-02-25 17:24:28 +08:00
committed by Tate, Hongliang Tian
parent 9b8c6b5aa9
commit 6d42a07e95
8 changed files with 63 additions and 1 deletions

24
test/apps/getcpu/getcpu.c Normal file
View File

@ -0,0 +1,24 @@
// SPDX-License-Identifier: MPL-2.0
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/syscall.h>
int main()
{
unsigned int cpu, node;
// Directly test the getcpu syscall because glibc's getcpu() may not
// use the getcpu syscall to retrieve CPU info
long ret = syscall(SYS_getcpu, &cpu, &node, NULL);
if (ret != 0) {
perror("syscall getcpu");
exit(EXIT_FAILURE);
}
printf("getcpu syscall: cpu = %u, node = %u\n", cpu, node);
return 0;
}