From 3d4bac98c34d64e99688375000de8ec5d2634824 Mon Sep 17 00:00:00 2001 From: Pawel Wieczorkiewicz Date: Fri, 8 Jul 2022 12:25:29 +0200 Subject: [PATCH] sched: add tasks types support Currently only KERNEL, USER, INTERRUPT and ACPI_SERVICE are defined. KERNEL type is the default one. Signed-off-by: Pawel Wieczorkiewicz --- common/kernel.c | 2 +- common/sched.c | 8 +++++--- drivers/acpi/acpica/osl.c | 2 +- include/sched.h | 19 ++++++++++++++++++- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/common/kernel.c b/common/kernel.c index 3c0b258a..fcfabac7 100644 --- a/common/kernel.c +++ b/common/kernel.c @@ -62,7 +62,7 @@ void kernel_main(void) { display_multiboot_mmap(); } - tests_task = new_task("tests", test_main, NULL); + tests_task = new_kernel_task("tests", test_main, NULL); schedule_task(tests_task, smp_processor_id()); run_tasks(smp_processor_id()); diff --git a/common/sched.c b/common/sched.c index f2c019d3..c6e81f39 100644 --- a/common/sched.c +++ b/common/sched.c @@ -108,7 +108,8 @@ static void destroy_task(task_t *task) { kfree(task); } -static int prepare_task(task_t *task, const char *name, task_func_t func, void *arg) { +static int prepare_task(task_t *task, const char *name, task_func_t func, void *arg, + task_type_t type) { if (!task) return -EINVAL; @@ -120,6 +121,7 @@ static int prepare_task(task_t *task, const char *name, task_func_t func, void * task->name = name; task->func = func; task->arg = arg; + task->type = type; set_task_state(task, TASK_STATE_READY); return ESUCCESS; } @@ -132,13 +134,13 @@ static void wait_for_task_state(task_t *task, task_state_t state) { cpu_relax(); } -task_t *new_task(const char *name, task_func_t func, void *arg) { +task_t *new_task(const char *name, task_func_t func, void *arg, task_type_t type) { task_t *task = create_task(); if (!task) return NULL; - if (unlikely(prepare_task(task, name, func, arg) != ESUCCESS)) { + if (unlikely(prepare_task(task, name, func, arg, type) != ESUCCESS)) { destroy_task(task); return NULL; } diff --git a/drivers/acpi/acpica/osl.c b/drivers/acpi/acpica/osl.c index 06f675d6..62edb800 100644 --- a/drivers/acpi/acpica/osl.c +++ b/drivers/acpi/acpica/osl.c @@ -369,7 +369,7 @@ ACPI_STATUS AcpiOsExecute(ACPI_EXECUTE_TYPE Type, ACPI_OSD_EXEC_CALLBACK Functio cb.Function = Function; cb.Context = Context; - task = new_task(name, _osd_exec_cb_wrapper, &cb); + task = new_kernel_task(name, _osd_exec_cb_wrapper, &cb); if (!task) return AE_NO_MEMORY; diff --git a/include/sched.h b/include/sched.h index 92941c2f..005f1607 100644 --- a/include/sched.h +++ b/include/sched.h @@ -48,12 +48,21 @@ enum task_group { }; typedef enum task_group task_group_t; +enum task_type { + TASK_TYPE_KERNEL = 0, + TASK_TYPE_USER, + TASK_TYPE_INTERRUPT, + TASK_TYPE_ACPI_SERVICE, +}; +typedef enum task_type task_type_t; + typedef unsigned int tid_t; struct task { list_head_t list; tid_t id; + task_type_t type; task_group_t gid; task_state_t state; @@ -73,10 +82,10 @@ extern void init_tasks(void); extern task_t *get_task_by_id(tid_t id); extern task_t *get_task_by_name(const char *name); extern task_t *get_task_for_cpu(unsigned int cpu); -extern task_t *new_task(const char *name, task_func_t func, void *arg); extern void schedule_task(task_t *task, unsigned int cpu); extern void run_tasks(unsigned int cpu); extern void wait_for_task_group(task_group_t group); +extern task_t *new_task(const char *name, task_func_t func, void *arg, task_type_t type); /* Static declarations */ @@ -84,4 +93,12 @@ static inline void set_task_group(task_t *task, task_group_t gid) { task->gid = static inline void wait_for_all_tasks(void) { wait_for_task_group(TASK_GROUP_ALL); } +static inline task_t *new_kernel_task(const char *name, task_func_t func, void *arg) { + return new_task(name, func, arg, TASK_TYPE_KERNEL); +} + +static inline task_t *new_user_task(const char *name, task_func_t func, void *arg) { + return new_task(name, func, arg, TASK_TYPE_USER); +} + #endif /* KTF_SCHED_H */