arch-x86,sim: Implement sched_getaffinity
sched_getaffinity is different from other syscalls in the raw syscall return the size of the cpumask being used to represent the CPU bit mask. Because of this, when a library (libnuma in this case) directly called sched_getaffinity and got a return value of 0, it errored out, thinking that there were no CPUs available. This implementation assumes that all CPUs are available, so it sets all simulated CPUs in the bitmask Change-Id: Id95c919986cc98a411877056256604f57a29f0f9 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/46243 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Matt Sinclair <mattdsinclair@gmail.com> Reviewed-by: Jason Lowe-Power <power.jg@gmail.com> Maintainer: Jason Lowe-Power <power.jg@gmail.com>
This commit is contained in:
@@ -244,7 +244,7 @@ SyscallDescTable<EmuLinux::SyscallABI64> EmuLinux::syscallDescs64 = {
|
||||
{ 201, "time", timeFunc<X86Linux64> },
|
||||
{ 202, "futex", futexFunc<X86Linux64> },
|
||||
{ 203, "sched_setaffinity", ignoreFunc },
|
||||
{ 204, "sched_getaffinity", ignoreFunc },
|
||||
{ 204, "sched_getaffinity", schedGetaffinityFunc<X86Linux64> },
|
||||
{ 205, "set_thread_area" },
|
||||
{ 206, "io_setup" },
|
||||
{ 207, "io_destroy" },
|
||||
|
||||
@@ -57,6 +57,7 @@
|
||||
/// application on the host machine.
|
||||
|
||||
#if defined(__linux__)
|
||||
#include <sched.h>
|
||||
#include <sys/eventfd.h>
|
||||
#include <sys/statfs.h>
|
||||
|
||||
@@ -2603,4 +2604,26 @@ eventfdFunc(SyscallDesc *desc, ThreadContext *tc,
|
||||
#endif
|
||||
}
|
||||
|
||||
/// Target sched_getaffinity
|
||||
template <class OS>
|
||||
SyscallReturn
|
||||
schedGetaffinityFunc(SyscallDesc *desc, ThreadContext *tc,
|
||||
pid_t pid, size_t cpusetsize, VPtr<> cpu_set_mask)
|
||||
{
|
||||
#if defined(__linux__)
|
||||
if (cpusetsize < CPU_ALLOC_SIZE(tc->getSystemPtr()->threads.size()))
|
||||
return -EINVAL;
|
||||
|
||||
BufferArg maskBuf(cpu_set_mask, cpusetsize);
|
||||
maskBuf.copyIn(tc->getVirtProxy());
|
||||
for (int i = 0; i < tc->getSystemPtr()->threads.size(); i++) {
|
||||
CPU_SET(i, (cpu_set_t *)maskBuf.bufferPtr());
|
||||
}
|
||||
maskBuf.copyOut(tc->getVirtProxy());
|
||||
return CPU_ALLOC_SIZE(tc->getSystemPtr()->threads.size());
|
||||
#else
|
||||
warnUnsupportedOS("sched_getaffinity");
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
#endif // __SIM_SYSCALL_EMUL_HH__
|
||||
|
||||
Reference in New Issue
Block a user