Kernel: Add debugging macro to dump syscalls that take a long time
This commit is contained in:
parent
eecdad50a6
commit
5eefd98e1b
|
@ -4,10 +4,12 @@
|
||||||
#include <kernel/Process.h>
|
#include <kernel/Process.h>
|
||||||
#include <kernel/Scheduler.h>
|
#include <kernel/Scheduler.h>
|
||||||
#include <kernel/Syscall.h>
|
#include <kernel/Syscall.h>
|
||||||
|
#include <kernel/Timer/Timer.h>
|
||||||
|
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
|
|
||||||
#define DUMP_ALL_SYSCALLS 0
|
#define DUMP_ALL_SYSCALLS 0
|
||||||
|
#define DUMP_LONG_SYSCALLS 0
|
||||||
|
|
||||||
namespace Kernel
|
namespace Kernel
|
||||||
{
|
{
|
||||||
|
@ -40,7 +42,7 @@ namespace Kernel
|
||||||
{
|
{
|
||||||
ASSERT(GDT::is_user_segment(interrupt_stack->cs));
|
ASSERT(GDT::is_user_segment(interrupt_stack->cs));
|
||||||
|
|
||||||
asm volatile("sti");
|
Processor::set_interrupt_state(InterruptState::Enabled);
|
||||||
|
|
||||||
BAN::ErrorOr<long> ret = BAN::Error::from_errno(ENOSYS);
|
BAN::ErrorOr<long> ret = BAN::Error::from_errno(ENOSYS);
|
||||||
|
|
||||||
|
@ -50,6 +52,10 @@ namespace Kernel
|
||||||
dprintln("{} pid {}: {}", process_path, Process::current().pid(), s_syscall_names[syscall]);
|
dprintln("{} pid {}: {}", process_path, Process::current().pid(), s_syscall_names[syscall]);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if DUMP_LONG_SYSCALLS
|
||||||
|
const uint64_t start_ns = SystemTimer::get().ns_since_boot();
|
||||||
|
#endif
|
||||||
|
|
||||||
if (syscall < 0 || syscall >= __SYSCALL_COUNT)
|
if (syscall < 0 || syscall >= __SYSCALL_COUNT)
|
||||||
dwarnln("No syscall {}", syscall);
|
dwarnln("No syscall {}", syscall);
|
||||||
else if (syscall == SYS_FORK)
|
else if (syscall == SYS_FORK)
|
||||||
|
@ -62,7 +68,7 @@ namespace Kernel
|
||||||
ret = (Process::current().*s_syscall_handlers[syscall])(arg1, arg2, arg3, arg4, arg5);
|
ret = (Process::current().*s_syscall_handlers[syscall])(arg1, arg2, arg3, arg4, arg5);
|
||||||
#pragma GCC diagnostic pop
|
#pragma GCC diagnostic pop
|
||||||
|
|
||||||
asm volatile("cli");
|
Processor::set_interrupt_state(InterruptState::Disabled);
|
||||||
|
|
||||||
#if DUMP_ALL_SYSCALLS
|
#if DUMP_ALL_SYSCALLS
|
||||||
if (ret.is_error())
|
if (ret.is_error())
|
||||||
|
@ -74,6 +80,17 @@ namespace Kernel
|
||||||
dwarnln("{} pid {}: {}: ENOTSUP", process_path, Process::current().pid(), s_syscall_names[syscall]);
|
dwarnln("{} pid {}: {}: ENOTSUP", process_path, Process::current().pid(), s_syscall_names[syscall]);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if DUMP_LONG_SYSCALLS
|
||||||
|
const uint64_t end_ns = SystemTimer::get().ns_since_boot();
|
||||||
|
const uint64_t duration_us = (end_ns - start_ns) / 1000;
|
||||||
|
if (duration_us > 1'000)
|
||||||
|
dwarnln("{} {} took {}.{3} ms",
|
||||||
|
Process::current().name(),
|
||||||
|
s_syscall_names[syscall],
|
||||||
|
duration_us / 1000, duration_us % 1000
|
||||||
|
);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (ret.is_error() && ret.error().is_kernel_error())
|
if (ret.is_error() && ret.error().is_kernel_error())
|
||||||
Kernel::panic("Kernel error while returning to userspace {}", ret.error());
|
Kernel::panic("Kernel error while returning to userspace {}", ret.error());
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue