1#include <global.h>
2#include <log.h>
3#include <math/fixed.h>
4#include <mem/alloc.h>
5#include <mem/alloc_or_die.h>
6#include <sch/rt_sched.h>
7#include <sch/sched.h>
8#include <smp/core.h>
9
10#include "internal.h"
11
12LOG_SITE_DECLARE(rt_sched, .flags = LOG_SITE_DEFAULT,
13 .capacity = LOG_SITE_CAPACITY_DEFAULT,
14 .enabled_mask = LOG_SITE_ALL,
15 .dump_opts = (struct log_dump_options){});
16
17static void init_scheduler_boot(struct scheduler *sched) {
18 struct rt_scheduler_percpu *pcpu = alloc_or_die(
19 kmalloc(sizeof(struct rt_scheduler_percpu), ALLOC_FLAGS_ZERO));
20
21 struct log_site_options opts = {
22 .name = "rt_sched",
23 .capacity = LOG_SITE_CAPACITY_DEFAULT,
24 .enabled_mask = LOG_SITE_ALL,
25 .dump_opts = (struct log_dump_options){},
26 .flags = LOG_SITE_DEFAULT,
27 };
28
29 pcpu->log_site = alloc_or_die(log_site_create(opts));
30
31 pcpu->log_handle = LOG_HANDLE_DEFAULT;
32 pcpu->perms.allowed_capabilities = UINT16_MAX;
33 spinlock_init(lock: &pcpu->perms.lock);
34 INIT_LIST_HEAD(list: &pcpu->perms.blocklist);
35 pcpu->scheduler = sched;
36 pcpu->active_mapping = NULL;
37 semaphore_init(s: &pcpu->switch_semaphore, value: 1, SEMAPHORE_INIT_IRQ_DISABLE);
38
39 struct rt_scheduler *rts =
40 kmalloc_or_die(sizeof(struct rt_scheduler), ALLOC_FLAGS_ZERO);
41
42 rts->log_site = alloc_or_die(log_site_create(opts));
43
44 rts->log_handle = LOG_HANDLE_DEFAULT;
45 spinlock_init(lock: &rts->lock);
46 pcpu->born_with = rts;
47 sched->rt = pcpu;
48 rts->failed_internal = false;
49 rts->mapping_source = NULL;
50 rts->mapping_source = NULL;
51}
52
53void rt_scheduler_boot_init() {
54 rt_wq = alloc_or_die(workqueue_create_default("rt_wq"));
55
56 locked_list_init(ll: &rt_global.static_list, LOCKED_LIST_INIT_IRQ_DISABLE);
57 spinlock_init(lock: &rt_global.switch_lock);
58 rt_global.sch_pool = kmalloc_or_die(
59 sizeof(struct locked_list) * global.domain_count, ALLOC_FLAGS_ZERO);
60
61 struct domain *d;
62 domain_for_each_domain(d) {
63 locked_list_init(ll: &rt_global.sch_pool[d->id],
64 LOCKED_LIST_INIT_IRQ_DISABLE);
65 }
66
67 struct core *c;
68 for_each_cpu_struct(c) {
69 struct scheduler *s = global.schedulers[c->id];
70 init_scheduler_boot(sched: s);
71 }
72}
73