Skip to content

Commit

Permalink
LibC+Kernel: Start implementing sysconf
Browse files Browse the repository at this point in the history
For now, only the non-standard _SC_NPROCESSORS_CONF and
_SC_NPROCESSORS_ONLN are implemented.

Use them to make ninja pick a better default -j value.
While here, make the ninja package script not fail if
no other port has been built yet.
  • Loading branch information
nico authored and awesomekling committed Jul 14, 2020
1 parent 782cd93 commit 4eb967b
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 14 deletions.
3 changes: 2 additions & 1 deletion Kernel/API/Syscall.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ namespace Kernel {
__ENUMERATE_SYSCALL(ptrace) \
__ENUMERATE_SYSCALL(minherit) \
__ENUMERATE_SYSCALL(sendfd) \
__ENUMERATE_SYSCALL(recvfd)
__ENUMERATE_SYSCALL(recvfd) \
__ENUMERATE_SYSCALL(sysconf)

namespace Syscall {

Expand Down
2 changes: 2 additions & 0 deletions Kernel/Arch/i386/CPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,8 @@ class Processor {

static Processor& by_id(u32 cpu);

static size_t processor_count() { return processors().size(); }

template<typename Callback>
static inline IterationDecision for_each(Callback callback)
{
Expand Down
11 changes: 11 additions & 0 deletions Kernel/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5308,4 +5308,15 @@ int Process::sys$recvfd(int sockfd)
m_fds[new_fd].set(*received_descriptor_or_error.value(), 0);
return new_fd;
}

long Process::sys$sysconf(int name)
{
switch (name) {
case _SC_NPROCESSORS_CONF:
case _SC_NPROCESSORS_ONLN:
return Processor::processor_count();
default:
return -EINVAL;
}
}
}
1 change: 1 addition & 0 deletions Kernel/Process.h
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ class Process : public InlineLinkedListNode<Process> {
int sys$ptrace(const Syscall::SC_ptrace_params*);
int sys$sendfd(int sockfd, int fd);
int sys$recvfd(int sockfd);
long sys$sysconf(int name);

template<bool sockname, typename Params>
int get_sock_or_peer_name(const Params&);
Expand Down
5 changes: 5 additions & 0 deletions Kernel/UnixTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@
#define MS_RDONLY (1 << 4)
#define MS_REMOUNT (1 << 5)

enum {
_SC_NPROCESSORS_CONF,
_SC_NPROCESSORS_ONLN,
};

#define PERF_EVENT_MALLOC 1
#define PERF_EVENT_FREE 2

Expand Down
6 changes: 6 additions & 0 deletions Libraries/LibC/unistd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -722,4 +722,10 @@ char* getpass(const char* prompt)
dbg() << "FIXME: getpass(\"" << prompt << "\")";
ASSERT_NOT_REACHED();
}

long sysconf(int name)
{
int rc = syscall(SC_sysconf, name);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
}
6 changes: 6 additions & 0 deletions Libraries/LibC/unistd.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,10 @@ enum {
#define _POSIX_PRIORITY_SCHEDULING
#define _POSIX_VDISABLE '\0'

enum {
_SC_NPROCESSORS_CONF,
_SC_NPROCESSORS_ONLN,
};
long sysconf(int name);

__END_DECLS
1 change: 1 addition & 0 deletions Ports/ninja/package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ build() {
}

install() {
mkdir -p "${SERENITY_ROOT}/Build/Root/usr/local/bin"
cp "${workdir}/ninja" "${SERENITY_ROOT}/Build/Root/usr/local/bin/ninja"
}
13 changes: 0 additions & 13 deletions Ports/ninja/patches/nproc.patch

This file was deleted.

0 comments on commit 4eb967b

Please sign in to comment.