Skip to content

Commit

Permalink
Add some more system utilities, including sysconf and the ability to …
Browse files Browse the repository at this point in the history
…get corecount. Corresponds to llvm-project-deluge/1a82ad4ef4f3
  • Loading branch information
Filip Pizlo committed Apr 23, 2024
1 parent 183e9eb commit 58aae2e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
5 changes: 5 additions & 0 deletions src/conf/sysconf.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <sys/auxv.h>
#include "syscall.h"
#include "libc.h"
#include <stdfil.h>

#define JT(x) (-256|(x))
#define VER JT(1)
Expand All @@ -27,6 +28,10 @@

long sysconf(int name)
{
errno = 0;
long zsys_result = zsys_sysconf_override(name);
if (errno != ENOSYS)
return zsys_result;
static const short values[] = {
[_SC_ARG_MAX] = JT_ARG_MAX,
[_SC_CHILD_MAX] = RLIM(NPROC),
Expand Down
30 changes: 18 additions & 12 deletions src/sched/affinity.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,41 @@
#include <string.h>
#include "pthread_impl.h"
#include "syscall.h"
#include <stdfil.h>

int sched_setaffinity(pid_t tid, size_t size, const cpu_set_t *set)
{
return syscall(SYS_sched_setaffinity, tid, size, set);
errno = ENOSYS;
return -1;
}

int pthread_setaffinity_np(pthread_t td, size_t size, const cpu_set_t *set)
{
zerror("pthread_setaffinity_np not implemented");
return 0;
//return -__syscall(SYS_sched_setaffinity, td->tid, size, set);
return ENOSYS;
}

static int do_getaffinity(pid_t tid, size_t size, cpu_set_t *set)
static int do_getaffinity(size_t size, cpu_set_t *set)
{
long ret = __syscall(SYS_sched_getaffinity, tid, size, set);
if (ret < 0) return ret;
if (ret < size) memset((char *)set+ret, 0, size-ret);
return 0;
int numcores = zsys_numcores();
if (numcores < 0)
return -1;
cpu_set_t my_set;
memset(&my_set, 0, sizeof(my_set));
int index;
for (index = numcores; index--;)
CPU_SET(index, &my_set);
memcpy(set, &my_set, size);
return 0;
}

int sched_getaffinity(pid_t tid, size_t size, cpu_set_t *set)
{
return __syscall_ret(do_getaffinity(tid, size, set));
return do_getaffinity(size, set);
}

int pthread_getaffinity_np(pthread_t td, size_t size, cpu_set_t *set)
{
zerror("pthread_getaffinity_np not implemented");
if (do_getaffinity(size, set) < 0)
return errno;
return 0;
//return -do_getaffinity(td->tid, size, set);
}

0 comments on commit 58aae2e

Please sign in to comment.