summaryrefslogtreecommitdiff
path: root/Kernel
diff options
context:
space:
mode:
authorNico Weber <thakis@chromium.org>2020-07-14 16:41:59 -0400
committerAndreas Kling <kling@serenityos.org>2020-07-15 00:07:20 +0200
commit4eb967b5ebd5ca7a00049c7f958011e54b975040 (patch)
tree25da6871473ae3484cf3c1c894b287b8be42626c /Kernel
parent782cd93c012bcad8a96dfd67aeb782ef49d380f9 (diff)
downloadserenity-4eb967b5ebd5ca7a00049c7f958011e54b975040.zip
LibC+Kernel: Start implementing sysconf
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.
Diffstat (limited to 'Kernel')
-rw-r--r--Kernel/API/Syscall.h3
-rw-r--r--Kernel/Arch/i386/CPU.h2
-rw-r--r--Kernel/Process.cpp11
-rw-r--r--Kernel/Process.h1
-rw-r--r--Kernel/UnixTypes.h5
5 files changed, 21 insertions, 1 deletions
diff --git a/Kernel/API/Syscall.h b/Kernel/API/Syscall.h
index 8c11349c16..8412971bf6 100644
--- a/Kernel/API/Syscall.h
+++ b/Kernel/API/Syscall.h
@@ -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 {
diff --git a/Kernel/Arch/i386/CPU.h b/Kernel/Arch/i386/CPU.h
index 95f8980a50..de90cd6dc9 100644
--- a/Kernel/Arch/i386/CPU.h
+++ b/Kernel/Arch/i386/CPU.h
@@ -744,6 +744,8 @@ public:
static Processor& by_id(u32 cpu);
+ static size_t processor_count() { return processors().size(); }
+
template<typename Callback>
static inline IterationDecision for_each(Callback callback)
{
diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp
index 3bb727452e..a051e8145b 100644
--- a/Kernel/Process.cpp
+++ b/Kernel/Process.cpp
@@ -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;
+ }
+}
}
diff --git a/Kernel/Process.h b/Kernel/Process.h
index 48d386c6aa..ebec0c73ea 100644
--- a/Kernel/Process.h
+++ b/Kernel/Process.h
@@ -327,6 +327,7 @@ public:
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&);
diff --git a/Kernel/UnixTypes.h b/Kernel/UnixTypes.h
index a07ebf4f57..9115c22daa 100644
--- a/Kernel/UnixTypes.h
+++ b/Kernel/UnixTypes.h
@@ -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