Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
K
klee_tutorial
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ruben Asplund
klee_tutorial
Commits
570955e0
Commit
570955e0
authored
4 years ago
by
Ruben Asplund
Browse files
Options
Downloads
Patches
Plain Diff
Fixed preemption with exact calculation
parent
e9ae2680
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
srp_analysis/src/main.rs
+38
-31
38 additions, 31 deletions
srp_analysis/src/main.rs
with
38 additions
and
31 deletions
srp_analysis/src/main.rs
+
38
−
31
View file @
570955e0
...
@@ -76,13 +76,16 @@ fn main() {
...
@@ -76,13 +76,16 @@ fn main() {
println!
(
"tr: {:?}"
,
tr
);
println!
(
"tr: {:?}"
,
tr
);
print_analysis
(
&
tasks
,
&
ip
,
&
tr
);
print_analysis
(
&
tasks
,
&
ip
,
&
tr
);
let
test
=
(
10.0
as
f32
/
30.0
as
f32
)
.ceil
();
println!
(
"Test {}"
,
test
);
}
}
// Prints out vector with [task id, response time, wcet time, blocking time, preemption time]
// Prints out vector with [task id, response time, wcet time, blocking time, preemption time]
fn
print_analysis
(
tasks
:
&
Tasks
,
ip
:
&
IdPrio
,
tr
:
&
TaskResources
)
{
fn
print_analysis
(
tasks
:
&
Tasks
,
ip
:
&
IdPrio
,
tr
:
&
TaskResources
)
{
for
t
in
tasks
{
for
t
in
tasks
{
let
b
=
blocking
(
t
,
&
tasks
,
&
ip
,
&
tr
);
let
b
=
blocking
(
t
,
&
tasks
,
&
ip
,
&
tr
);
// let p = preemptions(t, &tasks);
// let p = preemptions(t, &tasks);
let
p
=
recurrence_
preemption
(
t
,
&
tasks
,
&
ip
,
&
tr
,
true
)
.unwrap
();
let
p
=
preemption
s
(
t
,
&
tasks
,
&
ip
,
&
tr
,
true
)
.unwrap
();
let
r
=
response_time
(
t
,
&
tasks
,
&
ip
,
&
tr
,
true
);
let
r
=
response_time
(
t
,
&
tasks
,
&
ip
,
&
tr
,
true
);
let
c
=
wcet
(
t
);
let
c
=
wcet
(
t
);
let
tasks_analysis
=
vec!
[
t
.id
.to_string
(),
r
.to_string
(),
c
.to_string
(),
b
.to_string
(),
p
.to_string
()];
let
tasks_analysis
=
vec!
[
t
.id
.to_string
(),
r
.to_string
(),
c
.to_string
(),
b
.to_string
(),
p
.to_string
()];
...
@@ -93,8 +96,7 @@ fn print_analysis(tasks: &Tasks, ip: &IdPrio, tr: &TaskResources) {
...
@@ -93,8 +96,7 @@ fn print_analysis(tasks: &Tasks, ip: &IdPrio, tr: &TaskResources) {
fn
response_time
(
task
:
&
Task
,
tasks
:
&
Tasks
,
ip
:
&
IdPrio
,
tr
:
&
TaskResources
,
exact_solution
:
bool
)
->
u32
{
fn
response_time
(
task
:
&
Task
,
tasks
:
&
Tasks
,
ip
:
&
IdPrio
,
tr
:
&
TaskResources
,
exact_solution
:
bool
)
->
u32
{
let
b
=
blocking
(
task
,
&
tasks
,
&
ip
,
&
tr
);
let
b
=
blocking
(
task
,
&
tasks
,
&
ip
,
&
tr
);
let
c
=
wcet
(
task
);
let
c
=
wcet
(
task
);
// let p = preemptions(task, &tasks);
let
p
=
preemptions
(
task
,
&
tasks
,
&
ip
,
&
tr
,
exact_solution
)
.unwrap
();
let
p
=
recurrence_preemption
(
task
,
&
tasks
,
&
ip
,
&
tr
,
exact_solution
)
.unwrap
();
return
b
+
c
+
p
;
return
b
+
c
+
p
;
}
}
...
@@ -113,43 +115,48 @@ fn load_factor(tasks: &Tasks) -> f32{
...
@@ -113,43 +115,48 @@ fn load_factor(tasks: &Tasks) -> f32{
return
l_tot
;
return
l_tot
;
}
}
fn
recurrence_preemption
(
task
:
&
Task
,
tasks
:
&
Tasks
,
ip
:
&
IdPrio
,
tr
:
&
TaskResources
,
exact_solution
:
bool
)
->
Result
<
u32
,
String
>
{
fn
preemptions_approx
(
task
:
&
Task
,
tasks
:
&
Tasks
,
ip
:
&
IdPrio
,
tr
:
&
TaskResources
)
->
u32
{
if
!
exact_solution
{
let
mut
p_time
=
0
;
return
Ok
(
preemptions
(
task
,
&
tasks
,
0
,
exact_solution
));
let
mut
busy_period
=
task
.deadline
;
}
for
t
in
tasks
{
let
sum
=
wcet
(
task
)
+
blocking
(
task
,
&
tasks
,
&
ip
,
&
tr
);
if
(
t
.prio
>=
task
.prio
)
&&
(
t
.id
!=
task
.id
)
{
let
mut
current_busy_period
:
u32
=
sum
+
preemptions
(
task
,
&
tasks
,
sum
,
exact_solution
);
p_time
=
p_time
+
wcet
(
t
)
*
(((
busy_period
as
f32
)
/
(
t
.inter_arrival
as
f32
))
.ceil
()
as
u32
);
loop
{
let
busy_period
:
u32
=
current_busy_period
+
preemptions
(
task
,
&
tasks
,
current_busy_period
,
exact_solution
);
if
current_busy_period
==
busy_period
{
return
Ok
(
busy_period
);
}
if
current_busy_period
>
task
.deadline
{
return
Err
(
"Deadline miss!"
.to_string
());
}
current_busy_period
=
busy_period
;
}
}
}
}
return
p_time
;
}
fn
preemptions
(
task
:
&
Task
,
tasks
:
&
Tasks
,
busy_period
:
u32
,
exact_solution
:
bool
)
->
u32
{
fn
preemptions_exact
(
task
:
&
Task
,
tasks
:
&
Tasks
,
ip
:
&
IdPrio
,
tr
:
&
TaskResources
,
busy_period
:
u32
)
->
Result
<
u32
,
String
>
{
let
mut
p_time
=
0
;
let
base_case
=
wcet
(
task
)
+
blocking
(
task
,
&
tasks
,
&
ip
,
&
tr
);
let
mut
new_busy_period
=
base_case
;
let
mut
busy_period
=
busy_period
;
let
mut
busy_period
=
busy_period
;
if
!
exact_solution
{
if
busy_period
==
0
{
busy_period
=
t
as
k
.deadlin
e
;
busy_period
=
b
as
e_cas
e
;
}
}
for
t
in
tasks
{
for
t
in
tasks
{
if
t
.id
==
task
.id
{
if
t
.prio
>=
task
.prio
&&
(
t
.id
!=
task
.id
)
{
continue
;
new_busy_period
=
new_busy_period
+
wcet
(
t
)
*
(((
busy_period
as
f32
)
/
(
t
.inter_arrival
as
f32
))
.ceil
()
as
u32
);
}
}
}
if
t
.prio
>=
task
.prio
{
println!
(
"nb {}, b {}"
,
new_busy_period
,
busy_period
);
let
inter_arrival
=
t
.inter_arrival
;
if
new_busy_period
.wrapping_sub
(
base_case
)
==
0
{
// println!("bp{} ia{}", busy_period, inter_arrival);
return
Ok
(
0
);
p_time
=
p_time
+
wcet
(
t
)
*
(((
busy_period
as
f32
)
/
(
inter_arrival
as
f32
))
.ceil
()
as
u32
);
}
else
if
new_busy_period
>
task
.deadline
{
return
Err
(
"Deadline miss!"
.to_string
());
}
else
if
new_busy_period
==
busy_period
{
return
Ok
(
new_busy_period
-
base_case
);
}
else
{
return
preemptions_exact
(
task
,
&
tasks
,
ip
,
tr
,
new_busy_period
);
}
}
}
}
println!
(
"{}"
,
p_time
);
return
p_time
;
fn
preemptions
(
task
:
&
Task
,
tasks
:
&
Tasks
,
ip
:
&
IdPrio
,
tr
:
&
TaskResources
,
exact
:
bool
)
->
Result
<
u32
,
String
>
{
if
exact
{
return
preemptions_exact
(
task
,
&
tasks
,
ip
,
tr
,
0
);
}
else
{
return
Ok
(
preemptions_approx
(
task
,
&
tasks
,
ip
,
tr
));
}
}
}
fn
blocking
(
task
:
&
Task
,
tasks
:
&
Tasks
,
ip
:
&
IdPrio
,
tr
:
&
TaskResources
)
->
u32
{
fn
blocking
(
task
:
&
Task
,
tasks
:
&
Tasks
,
ip
:
&
IdPrio
,
tr
:
&
TaskResources
)
->
u32
{
...
...
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