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