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
ceacb8de
Commit
ceacb8de
authored
4 years ago
by
Ruben Asplund
Browse files
Options
Downloads
Patches
Plain Diff
Added functions preemtions(), wcet(), response_time() and print_analysis()
parent
16484174
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
+66
-18
66 additions, 18 deletions
srp_analysis/src/main.rs
with
66 additions
and
18 deletions
srp_analysis/src/main.rs
+
66
−
18
View file @
ceacb8de
...
...
@@ -74,27 +74,77 @@ fn main() {
let
(
ip
,
tr
)
=
pre_analysis
(
&
tasks
);
println!
(
"ip: {:?}"
,
ip
);
println!
(
"tr: {:?}"
,
tr
);
for
t
in
&
tasks
{
blocking
(
t
,
&
tasks
);
print_analysis
(
&
tasks
,
&
ip
,
&
tr
);
}
fn
print_analysis
(
tasks
:
&
Tasks
,
ip
:
&
IdPrio
,
tr
:
&
TaskResources
)
{
for
t
in
tasks
{
let
b
=
blocking
(
t
,
&
tasks
,
&
ip
,
&
tr
);
let
p
=
preemptions
(
t
,
&
tasks
);
let
r
=
response_time
(
t
,
&
tasks
,
&
ip
,
&
tr
);
let
c
=
wcet
(
t
);
let
tasks_analysis
=
vec!
[
t
.id
.to_string
(),
r
.to_string
(),
c
.to_string
(),
b
.to_string
(),
p
.to_string
()];
println!
(
"{:?}"
,
tasks_analysis
)
}
}
fn
response_time
(
task
:
&
Task
,
tasks
:
&
Tasks
,
ip
:
&
IdPrio
,
tr
:
&
TaskResources
)
->
u32
{
let
blocking
=
blocking
(
task
,
&
tasks
,
&
ip
,
&
tr
);
let
wcet
=
wcet
(
task
);
let
preemption
=
preemptions
(
task
,
&
tasks
);
return
blocking
+
wcet
+
preemption
;
}
fn
wcet
(
task
:
&
Task
)
->
u32
{
let
c
=
task
.trace.end
.wrapping_sub
(
task
.trace.start
);
return
c
}
fn
load_factor
(
tasks
:
&
Tasks
)
->
f32
{
let
mut
l_tot
:
f32
=
0.0
;
for
t
in
tasks
{
let
c
=
t
.trace.end
.wrapping_sub
(
t
.trace.star
t
);
let
c
=
wcet
(
t
);
let
a
=
t
.inter_arrival
;
l_tot
=
l_tot
+
(
c
as
f32
)
/
(
a
as
f32
);
}
return
l_tot
;
}
fn
blocking
(
task
:
&
Task
,
tasks
:
&
Tasks
)
->
u32
{
let
(
ip
,
tr
)
=
pre_analysis
(
&
tasks
);
// If the Task is claming a resource
fn
preemptions
(
task
:
&
Task
,
tasks
:
&
Tasks
)
->
u32
{
// Find higher or same task prio
let
mut
higher_prio_tasks
=
HashSet
::
new
();
for
t
in
tasks
{
if
t
.id
==
task
.id
{
continue
;
}
if
t
.prio
>=
task
.prio
{
higher_prio_tasks
.insert
(
t
.id
.to_string
());
}
}
// Calculate preemptions time (I(t))
let
mut
p_time
=
0
;
for
t_id
in
higher_prio_tasks
{
for
t
in
tasks
{
if
t_id
==
t
.id
{
let
inter_arrival
=
t
.inter_arrival
;
let
busy_period
=
t
.deadline
;
p_time
=
p_time
+
wcet
(
t
)
*
(
busy_period
/
inter_arrival
);
}
}
}
// println!("{}", p_time);
return
p_time
;
}
fn
blocking
(
task
:
&
Task
,
tasks
:
&
Tasks
,
ip
:
&
IdPrio
,
tr
:
&
TaskResources
)
->
u32
{
// Checks if the Task is claming a resource
if
!
tr
.contains_key
(
&
task
.id
)
{
println!
(
"0"
);
//
println!("0");
return
0
;
}
// Find lower prio tasks
...
...
@@ -104,7 +154,6 @@ fn blocking(task: &Task, tasks: &Tasks) -> u32 {
lower_prio_tasks
.insert
(
t
.id
.to_string
());
}
}
// Do these task hold a resource, if not delete from list
for
t
in
tasks
{
if
!
lower_prio_tasks
.contains
(
&
t
.id
)
{
...
...
@@ -116,10 +165,9 @@ fn blocking(task: &Task, tasks: &Tasks) -> u32 {
}
// println!("{:?}", lower_prio_tasks);
if
lower_prio_tasks
.len
()
==
0
{
println!
(
"0"
);
//
println!("0");
return
0
;
}
/* Finding longest blocking */
let
resources
=
&
tr
[
&
task
.id
];
// Checking every resource it holds
...
...
@@ -127,13 +175,13 @@ fn blocking(task: &Task, tasks: &Tasks) -> u32 {
let
mut
current_block
=
0
;
// Iterate through current task resources
for
r1
in
resources
{
println!
(
"Resource 1: {}, Resources 1 {:?}"
,
r1
,
resources
);
//
println!("Resource 1: {}, Resources 1 {:?}", r1, resources);
// Iterate through lower prio tasks
for
t_id
in
&
lower_prio_tasks
{
let
mut
lower_prio_task_resources
=
&
tr
[
t_id
];
// Iterate through lower prio task resources
for
r2
in
lower_prio_task_resources
{
println!
(
"Resource 2: {}, Resources 2 {:?}"
,
r2
,
lower_prio_task_resources
);
//
println!("Resource 2: {}, Resources 2 {:?}", r2, lower_prio_task_resources);
// When current task use the same resource as a task
if
r1
==
r2
{
// Takes forward the blocking task
...
...
@@ -146,8 +194,8 @@ fn blocking(task: &Task, tasks: &Tasks) -> u32 {
if
max_block
<
current_block
{
max_block
=
current_block
;
}
println!
(
"1: start:{}, end:{}"
,
inner
.start
,
inner
.end
);
println!
(
"For id {} and resource 2 {}"
,
t_id
,
r2
)
//
println!("1: start:{}, end:{}", inner.start, inner.end);
//
println!("For id {} and resource 2 {}", t_id, r2)
}
// Iterate through second layer
for
inner2
in
&
inner
.inner
{
...
...
@@ -156,8 +204,8 @@ fn blocking(task: &Task, tasks: &Tasks) -> u32 {
if
max_block
<
current_block
{
max_block
=
current_block
;
}
println!
(
"2: start:{}, end:{}"
,
inner2
.start
,
inner2
.end
);
println!
(
"For id {} and resource 2 {}"
,
t_id
,
r2
)
//
println!("2: start:{}, end:{}", inner2.start, inner2.end);
//
println!("For id {} and resource 2 {}", t_id, r2)
}
}
}
...
...
@@ -167,6 +215,6 @@ fn blocking(task: &Task, tasks: &Tasks) -> u32 {
}
}
}
println!
(
"{}"
,
max_block
);
//
println!("{}", max_block);
return
max_block
;
}
\ No newline at end of file
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