diff --git a/include/kernel/kthread.h b/include/kernel/kthread.h index 74ce47db77a9ee2380733bd6baa14d0955fa74bf..112074aa675f2ff1295843b9330ff2f53baa5137 100644 --- a/include/kernel/kthread.h +++ b/include/kernel/kthread.h @@ -13,6 +13,16 @@ #include <kernel/time.h> + +struct remove_this_declaration { + struct list_head new; + struct list_head run; + struct list_head wake; + struct list_head dead; +}; + + + #define KTHREAD_CPU_AFFINITY_NONE (-1) diff --git a/init/main.c b/init/main.c index 61dbe82b43fad66140595aa79a3f95c535f78fe0..a79bcf74420eef6abde99d213d6d8d598bd33684 100644 --- a/init/main.c +++ b/init/main.c @@ -49,7 +49,7 @@ int task1(void *data) { while (1) { - printk("."); + // printk("."); // sched_yield(); } } @@ -58,7 +58,7 @@ int task1(void *data) int task2(void *data) { while (1) { - printk("-"); + // printk("-"); // sched_yield(); } } @@ -151,23 +151,50 @@ int kernel_main(void) /* elevate boot thread */ kernel = kthread_init_main(); + /* + * T1: (P=50, D=20, R=10) + * + * T2: (P= 4, D= 2, R= 1) + * T5: (P=20, D=12, R= 5) + * + * T6: (P=33, D=30, R= 4) + * T7: (P=50, D=46, R= 6) + */ + + t = kthread_create(task1, NULL, KTHREAD_CPU_AFFINITY_NONE, "T1"); + kthread_set_sched_edf(t, 50 * MSEC_PER_SEC, 10 * MSEC_PER_SEC, 20 * MSEC_PER_SEC); + + + t = kthread_create(task1, NULL, KTHREAD_CPU_AFFINITY_NONE, "T2"); + kthread_set_sched_edf(t, 4 * MSEC_PER_SEC, 1 * MSEC_PER_SEC, 2 * MSEC_PER_SEC); + + t = kthread_create(task1, NULL, KTHREAD_CPU_AFFINITY_NONE, "T5"); + kthread_set_sched_edf(t, 20 * MSEC_PER_SEC, 5 * MSEC_PER_SEC, 12 * MSEC_PER_SEC); + + + t = kthread_create(task1, NULL, KTHREAD_CPU_AFFINITY_NONE, "T6"); + kthread_set_sched_edf(t, 33 * MSEC_PER_SEC, 4 * MSEC_PER_SEC, 30 * MSEC_PER_SEC); + t = kthread_create(task1, NULL, KTHREAD_CPU_AFFINITY_NONE, "T7"); + kthread_set_sched_edf(t, 50 * MSEC_PER_SEC, 6 * MSEC_PER_SEC, 46 * MSEC_PER_SEC); + + + +#if 0 t = kthread_create(task1, NULL, KTHREAD_CPU_AFFINITY_NONE, "print"); - //kthread_set_sched_edf(t, 1000000, 50000, 90000); t->priority = 4; kthread_wake_up(t); t = kthread_create(task2, NULL, KTHREAD_CPU_AFFINITY_NONE, "print1"); - //kthread_set_sched_edf(t, 1000000, 50000, 90000); t->priority = 8; kthread_wake_up(t); - +#endif while(1) { - printk("|"); + //printk("|"); cpu_relax(); } diff --git a/kernel/Makefile b/kernel/Makefile index e6bb7a3e0ee3d1fc9843ec26863bf7a4b8634a8c..c45d0b7b431d7b209c0c42038888d6b2c0a0657d 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -1,3 +1,5 @@ +obj-y += sched/ + obj-y += kmem.o obj-y += ksym.o obj-$(CONFIG_KERNEL_PRINTK) += printk.o diff --git a/kernel/kthread.c b/kernel/kthread.c index c7ff049b644dc3bd7d5faec41b188774fb33a2a9..dfa624245b4795a10ceb3a80189978fe49ad0af1 100644 --- a/kernel/kthread.c +++ b/kernel/kthread.c @@ -24,12 +24,12 @@ #define MSG "KTHREAD: " -static struct { +struct remove_this_declaration /*{ struct list_head new; struct list_head run; struct list_head wake; struct list_head dead; -} _kthreads = { +}*/ _kthreads = { .new = LIST_HEAD_INIT(_kthreads.new), .run = LIST_HEAD_INIT(_kthreads.run), .wake = LIST_HEAD_INIT(_kthreads.wake), @@ -133,6 +133,9 @@ void sched_wake(struct task_struct *next, ktime now, int64_t slot_ns) #define OVERHEAD 0LL +/* XXX */ +int64_t schedule_edf(ktime now); + void schedule(void) { struct task_struct *next; @@ -203,7 +206,7 @@ void schedule(void) -#if 0 +#if 1 slot_ns = schedule_edf(now); #endif @@ -261,7 +264,7 @@ void schedule(void) } __attribute__((unused)) -static void kthread_set_sched_policy(struct task_struct *task, +/* static */ void kthread_set_sched_policy(struct task_struct *task, enum sched_policy policy) { arch_local_irq_disable(); diff --git a/kernel/sched/edf.c b/kernel/sched/edf.c index e19040f84fd9b5d8fd19d8baa3fc667b0fda1157..8bc3c15588431d7b0d1c787f6b604806e6593589 100644 --- a/kernel/sched/edf.c +++ b/kernel/sched/edf.c @@ -20,6 +20,11 @@ #include <kernel/tick.h> +extern struct remove_this_declaration _kthreads; +void kthread_set_sched_policy(struct task_struct *task, + enum sched_policy policy); + + void sched_print_edf_list_internal(ktime now) { @@ -65,7 +70,8 @@ void sched_print_edf_list_internal(ktime now) prevd = tsk->deadline; } } - +ktime total; +ktime times; void sched_print_edf_list(void) { printk("avg: %lld\n", ktime_to_us(total/times)); @@ -161,7 +167,7 @@ static inline void schedule_edf_reinit_task(struct task_struct *tsk, ktime now) #define SOME_DEFAULT_TICK_PERIOD_FOR_SCHED_MODE 10000000LL /* stupidly sort EDFs */ -static int64_t schedule_edf(ktime now) +/*static*/ int64_t schedule_edf(ktime now) { // ktime now; @@ -249,11 +255,13 @@ static int64_t schedule_edf(ktime now) BUG_ON(slot <= 0); } } - +#if 1 total = ktime_add(total, ktime_delta(ktime_get(), now)); times++; - - //printk("%3.d %3.lld\n", cnt, ktime_to_us(total / times) ); +#endif +#if 0 + printk("%3.d %3.lld\n", cnt, ktime_to_us(total / times) ); +#endif BUG_ON(slot < 0); return slot; @@ -577,7 +585,7 @@ void kthread_set_sched_edf(struct task_struct *task, unsigned long period_us, task->deadline_rel = us_to_ktime(deadline_rel_us); arch_local_irq_enable(); - + printk("\nvvvv EDF analysis vvvv\n\n"); { ktime p = hyperperiod(); ktime h ; @@ -605,7 +613,7 @@ void kthread_set_sched_edf(struct task_struct *task, unsigned long period_us, BUG_ON(p < t0->period); h = p / t0->period; -// printk("Period factor %lld %lld %lld\n", h, p, t0->period); + printk("Period factor %lld, duration %lld actual min period: %lld\n", h, ktime_to_ms(p), ktime_to_ms(t0->period)); @@ -614,7 +622,7 @@ void kthread_set_sched_edf(struct task_struct *task, unsigned long period_us, f1 = ut/h; - printk("max UH: %lld, UT: %lld\n", (uh), (ut)); + printk("max UH: %lld, UT: %lld\n", ktime_to_ms(uh), ktime_to_ms(ut)); list_for_each_entry_safe(tsk, tmp, &_kthreads.new, node) { @@ -647,7 +655,7 @@ void kthread_set_sched_edf(struct task_struct *task, unsigned long period_us, ut = ut - st; - printk("UH: %lld, UT: %lld\n", (uh),(ut)); + printk("UH: %lld, UT: %lld\n", ktime_to_ms(uh), ktime_to_ms(ut)); } @@ -692,6 +700,7 @@ void kthread_set_sched_edf(struct task_struct *task, unsigned long period_us, } } + printk("\n^^^^ EDF analysis ^^^^\n"); // arch_local_irq_enable();