Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
FlightOS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Armin Luntzer
FlightOS
Commits
21662754
Commit
21662754
authored
5 years ago
by
Armin Luntzer
Browse files
Options
Downloads
Patches
Plain Diff
mostly there, initial wakeup needs work
parent
d7b4041d
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
include/kernel/kthread.h
+0
-1
0 additions, 1 deletion
include/kernel/kthread.h
init/main.c
+48
-12
48 additions, 12 deletions
init/main.c
kernel/sched/core.c
+4
-4
4 additions, 4 deletions
kernel/sched/core.c
kernel/sched/edf.c
+76
-28
76 additions, 28 deletions
kernel/sched/edf.c
with
128 additions
and
45 deletions
include/kernel/kthread.h
+
0
−
1
View file @
21662754
...
...
@@ -111,7 +111,6 @@ void switch_to(struct task_struct *next);
void
schedule
(
void
);
void
sched_yield
(
void
);
void
sched_print_edf_list_internal
(
ktime
now
);
void
sched_print_edf_list
(
void
);
void
kthread_set_sched_edf
(
struct
task_struct
*
task
,
unsigned
long
period_us
,
...
...
This diff is collapsed.
Click to expand it.
init/main.c
+
48
−
12
View file @
21662754
...
...
@@ -45,12 +45,15 @@
#endif
/* GCC_VERSION */
volatile
int
inc
;
volatile
int
xa
,
xb
,
xc
;
int
task1
(
void
*
data
)
{
while
(
1
)
{
printk
(
"."
);
sched_yield
();
xa
++
;
//printk("#");
// sched_yield();
}
}
...
...
@@ -59,7 +62,8 @@ int task2(void *data)
{
while
(
1
)
{
//printk("x %llu\n", ktime_get());
printk
(
"_
\n
"
);
//printk("_");
xb
++
;
// sched_yield();
// printk("-");
// sched_yield();
...
...
@@ -85,14 +89,25 @@ int task3(void *data)
#endif
//printk("y %llu\n", ktime_get());
printk
(
".
\n
"
);
//printk(".");
xc
++
;
// sched_yield();
}
}
int
task0
(
void
*
data
)
{
int
a
,
b
,
c
;
while
(
1
)
{
a
=
xa
;
b
=
xb
;
c
=
xc
;
printk
(
"%d %d %d
\n
"
,
a
,
b
,
c
);
// sched_yield();
}
}
extern
struct
task_struct
*
kernel
;
...
...
@@ -231,20 +246,40 @@ int kernel_main(void)
t
=
kthread_create
(
task2
,
NULL
,
KTHREAD_CPU_AFFINITY_NONE
,
"print1"
);
sched_get_attr
(
t
,
&
attr
);
attr
.
policy
=
SCHED_EDF
;
attr
.
period
=
m
s_to_ktime
(
1000
);
attr
.
deadline_rel
=
m
s_to_ktime
(
900
);
attr
.
wcet
=
m
s_to_ktime
(
200
);
attr
.
period
=
u
s_to_ktime
(
1000
);
attr
.
deadline_rel
=
u
s_to_ktime
(
900
);
attr
.
wcet
=
u
s_to_ktime
(
200
);
sched_set_attr
(
t
,
&
attr
);
kthread_wake_up
(
t
);
t
=
kthread_create
(
task3
,
NULL
,
KTHREAD_CPU_AFFINITY_NONE
,
"print2"
);
sched_get_attr
(
t
,
&
attr
);
attr
.
policy
=
SCHED_EDF
;
attr
.
period
=
ms_to_ktime
(
1000
);
attr
.
period
=
us_to_ktime
(
800
);
attr
.
deadline_rel
=
us_to_ktime
(
700
);
attr
.
wcet
=
us_to_ktime
(
100
);
sched_set_attr
(
t
,
&
attr
);
kthread_wake_up
(
t
);
t
=
kthread_create
(
task1
,
NULL
,
KTHREAD_CPU_AFFINITY_NONE
,
"print3"
);
sched_get_attr
(
t
,
&
attr
);
attr
.
policy
=
SCHED_EDF
;
attr
.
period
=
us_to_ktime
(
400
);
attr
.
deadline_rel
=
us_to_ktime
(
200
);
attr
.
wcet
=
us_to_ktime
(
90
);
sched_set_attr
(
t
,
&
attr
);
kthread_wake_up
(
t
);
t
=
kthread_create
(
task0
,
NULL
,
KTHREAD_CPU_AFFINITY_NONE
,
"res"
);
sched_get_attr
(
t
,
&
attr
);
attr
.
policy
=
SCHED_EDF
;
attr
.
period
=
ms_to_ktime
(
2000
);
attr
.
deadline_rel
=
ms_to_ktime
(
900
);
attr
.
wcet
=
ms_to_ktime
(
2
00
);
attr
.
wcet
=
ms_to_ktime
(
1
00
);
sched_set_attr
(
t
,
&
attr
);
kthread_wake_up
(
t
);
#endif
...
...
@@ -290,7 +325,8 @@ int kernel_main(void)
//printk("%d\n", cnt);
printk
(
"o
\n
"
);
// printk("o");
// printk("\n");
// sched_yield();
// cpu_relax();
...
...
This diff is collapsed.
Click to expand it.
kernel/sched/core.c
+
4
−
4
View file @
21662754
...
...
@@ -146,13 +146,13 @@ void schedule(void)
// printk("real next %s %llu %llu\n", next->name, next->exec_start, slot_ns);
/* kthread_unlock(); */
// printk("wake %llu\n", slot_ns);
// printk("wake %llu\n",
ktime_to_us(
slot_ns)
)
;
/* subtract readout overhead */
tick_set_next_ns
(
ktime_sub
(
slot_ns
,
1
000LL
));
#if
0
tick_set_next_ns
(
ktime_sub
(
slot_ns
,
2
000LL
));
#if
1
if
(
slot_ns
<
20000UL
)
{
printk("wake %llu
\n", slot_ns
);
printk
(
"wake %llu
slot %llu %s
\n
"
,
wake_ns
,
slot_ns
,
next
->
name
);
BUG
();
}
#endif
...
...
This diff is collapsed.
Click to expand it.
kernel/sched/edf.c
+
76
−
28
View file @
21662754
...
...
@@ -20,9 +20,9 @@
#include
<kernel/tick.h>
#if
0
#if
1
void sched_print_edf_list_internal(ktime now)
void
sched_print_edf_list_internal
(
struct
task_queue
*
tq
,
ktime
now
)
{
// ktime now;
char
state
=
'U'
;
...
...
@@ -40,7 +40,7 @@ void sched_print_edf_list_internal(ktime now)
printk
(
"
\n
t: %lld
\n
"
,
ktime_to_us
(
now
));
printk
(
"S
\t
Deadline
\t
Wakeup
\t
delta W
\t
delta P
\t
t_rem
\t
total
\t
slices
\t
Name
\t\t
firstwake, firstdead, execstart
\n
"
);
printk
(
"----------------------------------------------
\n
"
);
list_for_each_entry_safe(tsk, tmp, &
_kthreads.
run, node) {
list_for_each_entry_safe
(
tsk
,
tmp
,
&
tq
->
run
,
node
)
{
if
(
tsk
->
attr
.
policy
==
SCHED_RR
)
continue
;
...
...
@@ -725,6 +725,7 @@ static struct task_struct *edf_pick_next(struct task_queue *tq)
struct
task_struct
*
go
=
NULL
;
struct
task_struct
*
tsk
;
struct
task_struct
*
tmp
;
struct
task_struct
*
first
;
ktime
now
=
ktime_get
();
slot
=
1000000000000
;
//SOME_DEFAULT_TICK_PERIOD_FOR_SCHED_MODE;
...
...
@@ -734,7 +735,7 @@ static struct task_struct *edf_pick_next(struct task_queue *tq)
/* time to wake up yet? */
delta
=
ktime_delta
(
tsk
->
wakeup
,
now
);
if
(
delta
>=
0
)
{
if
(
delta
>=
2000
0
)
{
/* nope, just update minimum runtime for this slot */
...
...
@@ -744,7 +745,7 @@ static struct task_struct *edf_pick_next(struct task_queue *tq)
}
// printk("delta %llu %llu\n", delta, tsk->wakeup);
//
continue;
continue
;
}
if
(
delta
<
0
)
{
...
...
@@ -759,18 +760,15 @@ static struct task_struct *edf_pick_next(struct task_queue *tq)
schedule_edf_reinit_task
(
tsk
,
now
);
/* nope, update minimum runtime for this slot */
delta
=
ktime_delta
(
tsk
->
wakeup
,
now
);
#if 1
if
(
delta
<
0
)
{
delta
=
tsk
->
attr
.
wcet
;
slot
=
delta
;
// printk("NOW!\n");
}
#endif
if
(
delta
<
slot
)
{
// printk("HERE!\n");
/* if wakeup must happen earlier than the next
* scheduling event, adjust the slot timeout
*/
if
(
delta
<
slot
)
{
slot
=
delta
;
// printk("slot %lld\n", ktime_to_us(delta));
}
if
(
delta
<
0
)
printk
(
"delta %lld %lld
\n
"
,
ktime_to_us
(
delta
),
ktime_to_us
(
tick_get_period_min_ns
()));
BUG_ON
(
delta
<
0
);
...
...
@@ -778,9 +776,18 @@ static struct task_struct *edf_pick_next(struct task_queue *tq)
continue
;
}
/* move to top */
go
=
tsk
;
list_move
(
&
tsk
->
node
,
&
tq
->
run
);
/* if our deadline is earlier than the deadline at the
* head of the list, move us to top */
first
=
list_first_entry
(
&
tq
->
run
,
struct
task_struct
,
node
);
if
(
ktime_before
(
tsk
->
deadline
,
first
->
deadline
))
{
// go = tsk;
list_move
(
&
tsk
->
node
,
&
tq
->
run
);
// printk("1 to top! %s\n", tsk->name);
}
// printk("1 nope %s\n", tsk->name);
continue
;
}
...
...
@@ -788,12 +795,49 @@ static struct task_struct *edf_pick_next(struct task_queue *tq)
if
(
tsk
->
state
==
TASK_IDLE
)
{
tsk
->
state
=
TASK_RUN
;
/* move to top */
list_move
(
&
tsk
->
node
,
&
tq
->
run
);
go
=
tsk
;
break
;
/* if our deadline is earlier than the deadline at the
* head of the list, move us to top */
first
=
list_first_entry
(
&
tq
->
run
,
struct
task_struct
,
node
);
if
(
ktime_before
(
tsk
->
deadline
,
first
->
deadline
))
{
// go = tsk;
list_move
(
&
tsk
->
node
,
&
tq
->
run
);
// printk("2 to top! %s\n", tsk->name);
}
// printk("2 nope %s\n", tsk->name);
continue
;
}
}
first
=
list_first_entry
(
&
tq
->
run
,
struct
task_struct
,
node
);
delta
=
ktime_delta
(
first
->
wakeup
,
now
);
if
(
delta
<=
0
)
if
(
first
->
state
==
TASK_RUN
)
go
=
first
;
#if 0
list_for_each_entry_safe(tsk, tmp, &tq->run, node) {
printk("%c %s %lld %lld\n",
(tsk->state == TASK_RUN) ? 'R' : 'I',
tsk->name,
ktime_to_ms(ktime_delta(tsk->wakeup, now)),
ktime_to_ms(ktime_delta(tsk->deadline, now))
);
}
#endif
if
(
slot
<
20000
)
printk
(
"BUG %lld
\n
"
,
slot
);
// if (!go)
// printk("NULL\n");
// printk("in %llu\n", ktime_to_ms(slot));
#if 0
/** XXX **/
tsk = list_entry(tq->run.next, struct task_struct, node);
...
...
@@ -813,6 +857,7 @@ static void edf_wake_next(struct task_queue *tq)
struct
task_struct
*
task
;
ktime
last
=
0
;
ktime
per
=
50000
;
if
(
list_empty
(
&
tq
->
wake
))
return
;
...
...
@@ -825,6 +870,9 @@ static void edf_wake_next(struct task_queue *tq)
list_for_each_entry_safe
(
tsk
,
tmp
,
&
tq
->
run
,
node
)
{
if
(
tsk
->
deadline
>
last
)
last
=
tsk
->
deadline
;
if
(
tsk
->
attr
.
period
>
per
)
per
=
tsk
->
attr
.
period
;
}
// if (next->attr.policy == SCHED_EDF)
...
...
@@ -833,7 +881,8 @@ static void edf_wake_next(struct task_queue *tq)
/* initially furthest deadline as wakeup */
task
->
wakeup
=
ktime_add
(
last
,
task
->
attr
.
period
);
/* add overhead */
task
->
wakeup
=
ktime_add
(
task
->
wakeup
,
2000UL
);
// task->wakeup = ktime_add(task->wakeup, 50000UL);
task
->
wakeup
=
ktime_add
(
task
->
wakeup
,
per
);
task
->
deadline
=
ktime_add
(
task
->
wakeup
,
task
->
attr
.
deadline_rel
);
task
->
first_wake
=
task
->
wakeup
;
...
...
@@ -929,7 +978,6 @@ error:
ktime
edf_task_ready_ns
(
struct
task_queue
*
tq
)
{
/* now find the closest relative deadline */
int64_t
delta
;
...
...
@@ -945,14 +993,14 @@ ktime edf_task_ready_ns(struct task_queue *tq)
if
(
tsk
->
state
!=
TASK_RUN
)
break
;
if
(
ktime_before
(
wake
,
tsk
->
deadline
))
if
(
ktime_before
(
wake
,
tsk
->
wakeup
))
continue
;
delta
=
ktime_delta
(
wake
,
tsk
->
deadline
);
delta
=
ktime_delta
(
wake
,
tsk
->
wakeup
);
if
(
delta
<
0
)
{
delta
=
ktime_delta
(
now
,
tsk
->
deadline
);
printk
(
"
\n
[%lld] %s
deadline
violated by %lld us
\n
"
,
ktime_to_ms
(
now
),
tsk
->
name
,
ktime_to_us
(
delta
));
delta
=
ktime_delta
(
now
,
tsk
->
wakeup
);
printk
(
"
\n
[%lld] %s
wakeup
violated by %lld us
\n
"
,
ktime_to_ms
(
now
),
tsk
->
name
,
ktime_to_us
(
delta
));
}
...
...
@@ -961,9 +1009,9 @@ ktime edf_task_ready_ns(struct task_queue *tq)
slot
=
delta
;
else
delta
=
tsk
->
runtime
;
wake
=
ktime_add
(
now
,
slot
);
/* update next wakeup */
//
wake = ktime_add(now, slot); /* update next wakeup */
/* move to top */
list_move
(
&
tsk
->
node
,
&
tq
->
run
);
//
list_move(&tsk->node, &tq->run);
BUG_ON
(
slot
<=
0
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment