Skip to content

Commit

Permalink
sched: add tasks types support
Browse files Browse the repository at this point in the history
Currently only KERNEL, USER, INTERRUPT and ACPI_SERVICE are defined.
KERNEL type is the default one.

Signed-off-by: Pawel Wieczorkiewicz <[email protected]>
  • Loading branch information
wipawel committed Jul 8, 2022
1 parent 0bf1efc commit 3d4bac9
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion common/kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
8 changes: 5 additions & 3 deletions common/sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/acpi/acpica/osl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
19 changes: 18 additions & 1 deletion include/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -73,15 +82,23 @@ 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 */

static inline void set_task_group(task_t *task, task_group_t gid) { task->gid = 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 */

0 comments on commit 3d4bac9

Please sign in to comment.