From a066dd1fac2bfea0439c9b4646a3efd6a4306b99 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 8 Apr 2020 15:13:49 +0200 Subject: [PATCH] Kernel: Move sync and finalization tasks into their own files Instead of clogging up the initialization sequence, put these tasks in their own files. --- Kernel/Makefile | 2 ++ Kernel/Tasks/FinalizerTask.cpp | 49 ++++++++++++++++++++++++++++++++++ Kernel/Tasks/FinalizerTask.h | 34 +++++++++++++++++++++++ Kernel/Tasks/SyncTask.cpp | 45 +++++++++++++++++++++++++++++++ Kernel/Tasks/SyncTask.h | 34 +++++++++++++++++++++++ Kernel/init.cpp | 25 +++-------------- 6 files changed, 168 insertions(+), 21 deletions(-) create mode 100644 Kernel/Tasks/FinalizerTask.cpp create mode 100644 Kernel/Tasks/FinalizerTask.h create mode 100644 Kernel/Tasks/SyncTask.cpp create mode 100644 Kernel/Tasks/SyncTask.h diff --git a/Kernel/Makefile b/Kernel/Makefile index 340a0e4861..357f0dc97a 100644 --- a/Kernel/Makefile +++ b/Kernel/Makefile @@ -98,6 +98,8 @@ OBJS = \ Scheduler.o \ SharedBuffer.o \ Syscall.o \ + Tasks/FinalizerTask.o \ + Tasks/SyncTask.o \ TimerQueue.o \ TTY/MasterPTY.o \ TTY/PTYMultiplexer.o \ diff --git a/Kernel/Tasks/FinalizerTask.cpp b/Kernel/Tasks/FinalizerTask.cpp new file mode 100644 index 0000000000..4b1f1ef738 --- /dev/null +++ b/Kernel/Tasks/FinalizerTask.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2020, Andreas Kling + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +namespace Kernel { + +void FinalizerTask::spawn() +{ + Process::create_kernel_process(g_finalizer, "FinalizerTask", [] { + Thread::current->set_priority(THREAD_PRIORITY_LOW); + for (;;) { + { + InterruptDisabler disabler; + if (!g_finalizer_has_work) + Thread::current->wait_on(*g_finalizer_wait_queue); + ASSERT(g_finalizer_has_work); + g_finalizer_has_work = false; + } + Thread::finalize_dying_threads(); + } + }); +} + +} diff --git a/Kernel/Tasks/FinalizerTask.h b/Kernel/Tasks/FinalizerTask.h new file mode 100644 index 0000000000..f31ef7b579 --- /dev/null +++ b/Kernel/Tasks/FinalizerTask.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2020, Andreas Kling + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +namespace Kernel { +class FinalizerTask { +public: + static void spawn(); +}; +} diff --git a/Kernel/Tasks/SyncTask.cpp b/Kernel/Tasks/SyncTask.cpp new file mode 100644 index 0000000000..f4d1dffafd --- /dev/null +++ b/Kernel/Tasks/SyncTask.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2020, Andreas Kling + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include + +namespace Kernel { + +void SyncTask::spawn() +{ + Thread* syncd_thread = nullptr; + Process::create_kernel_process(syncd_thread, "SyncTask", [] { + for (;;) { + VFS::the().sync(); + Thread::current->sleep(1 * TimeManagement::the().ticks_per_second()); + } + }); +} + +} diff --git a/Kernel/Tasks/SyncTask.h b/Kernel/Tasks/SyncTask.h new file mode 100644 index 0000000000..c3697c3c08 --- /dev/null +++ b/Kernel/Tasks/SyncTask.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2020, Andreas Kling + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +namespace Kernel { +class SyncTask { +public: + static void spawn(); +}; +} diff --git a/Kernel/init.cpp b/Kernel/init.cpp index cc49a0465f..cd2832e985 100644 --- a/Kernel/init.cpp +++ b/Kernel/init.cpp @@ -66,6 +66,8 @@ #include #include #include +#include +#include #include #include #include @@ -164,27 +166,8 @@ extern "C" [[noreturn]] void init() void init_stage2() { - Thread* syncd_thread = nullptr; - Process::create_kernel_process(syncd_thread, "syncd", [] { - for (;;) { - VFS::the().sync(); - Thread::current->sleep(1 * TimeManagement::the().ticks_per_second()); - } - }); - - Process::create_kernel_process(g_finalizer, "Finalizer", [] { - Thread::current->set_priority(THREAD_PRIORITY_LOW); - for (;;) { - { - InterruptDisabler disabler; - if (!g_finalizer_has_work) - Thread::current->wait_on(*g_finalizer_wait_queue); - ASSERT(g_finalizer_has_work); - g_finalizer_has_work = false; - } - Thread::finalize_dying_threads(); - } - }); + SyncTask::spawn(); + FinalizerTask::spawn(); // Sample test to see if the ACPI parser is working... klog() << "ACPI: HPET table @ " << ACPI::Parser::the().find_table("HPET");