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
41ffd8c2
Commit
41ffd8c2
authored
4 years ago
by
Ruben Asplund
Browse files
Options
Downloads
Patches
Plain Diff
Added schedulable function, and added an extra taskset
parent
2227ce09
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
srp_analysis/src/analysis.rs
+42
-19
42 additions, 19 deletions
srp_analysis/src/analysis.rs
srp_analysis/src/common.rs
+2
-2
2 additions, 2 deletions
srp_analysis/src/common.rs
srp_analysis/src/main.rs
+91
-11
91 additions, 11 deletions
srp_analysis/src/main.rs
with
135 additions
and
32 deletions
srp_analysis/src/analysis.rs
+
42
−
19
View file @
41ffd8c2
use
crate
::
common
::
*
;
use
std
::
collections
::
HashSet
;
#[derive(Debug,
Clone)]
pub
struct
TaskData
{
pub
task
:
Task
,
pub
response_time
:
u32
,
pub
wcet
:
u32
,
pub
blocking_time
:
u32
,
pub
preemption_time
:
u32
}
// Prints out vector with [task id, response time, wcet time, blocking time, preemption time]
pub
fn
print_analysis
(
tasks
:
&
Tasks
)
{
pub
fn
analysis
(
tasks
:
&
Tasks
,
exact
:
bool
)
->
Vec
<
TaskData
>
{
let
mut
analysis
:
Vec
<
TaskData
>
=
vec!
();
for
t
in
tasks
{
let
b
=
blocking
(
t
,
&
tasks
);
let
p
=
preemptions
(
t
,
&
tasks
,
true
)
.unwrap
();
let
r
=
response_time
(
t
,
&
tasks
,
true
);
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
)
analysis
.push
(
TaskData
{
task
:
t
.clone
(),
response_time
:
response_time
(
t
,
&
tasks
,
exact
),
wcet
:
wcet
(
t
),
blocking_time
:
blocking
(
t
,
&
tasks
),
preemption_time
:
preemptions
(
t
,
&
tasks
,
exact
)
.unwrap
()
})
}
return
analysis
;
}
// Checks if the analysis is schedulable
// returns false if it is not schedulable
pub
fn
schedulable_check
(
analysis
:
Vec
<
TaskData
>
)
->
bool
{
// check if response time is less then deadline
for
a
in
analysis
{
if
a
.task.deadline
<
a
.response_time
{
return
false
}
}
return
true
;
}
pub
fn
response_time
(
task
:
&
Task
,
tasks
:
&
Tasks
,
exact_solution
:
bool
)
->
u32
{
...
...
@@ -35,9 +59,9 @@ pub fn load_factor(tasks: &Tasks) -> f32{
return
l_tot
;
}
pub
fn
preemption
s
_approx
(
task
:
&
Task
,
tasks
:
&
Tasks
)
->
u32
{
pub
fn
preemption_approx
(
task
:
&
Task
,
tasks
:
&
Tasks
)
->
u32
{
let
mut
p_time
=
0
;
let
mut
busy_period
=
task
.deadline
;
let
busy_period
=
task
.deadline
;
for
t
in
tasks
{
if
(
t
.prio
>=
task
.prio
)
&&
(
t
.id
!=
task
.id
)
{
p_time
=
p_time
+
wcet
(
t
)
*
(((
busy_period
as
f32
)
/
(
t
.inter_arrival
as
f32
))
.ceil
()
as
u32
);
...
...
@@ -47,7 +71,7 @@ pub fn preemptions_approx(task: &Task, tasks: &Tasks) -> u32 {
}
pub
fn
preemption
s
_exact
(
task
:
&
Task
,
tasks
:
&
Tasks
,
busy_period
:
u32
)
->
Result
<
u32
,
String
>
{
pub
fn
preemption_exact
(
task
:
&
Task
,
tasks
:
&
Tasks
,
busy_period
:
u32
)
->
Result
<
u32
,
String
>
{
let
base_case
=
wcet
(
task
)
+
blocking
(
task
,
&
tasks
);
let
mut
new_busy_period
=
base_case
;
let
mut
busy_period
=
busy_period
;
...
...
@@ -67,20 +91,20 @@ pub fn preemptions_exact(task: &Task, tasks: &Tasks, busy_period: u32) -> Result
}
else
if
new_busy_period
==
busy_period
{
return
Ok
(
new_busy_period
-
base_case
);
}
else
{
return
preemption
s
_exact
(
task
,
&
tasks
,
new_busy_period
);
return
preemption_exact
(
task
,
&
tasks
,
new_busy_period
);
}
}
pub
fn
preemptions
(
task
:
&
Task
,
tasks
:
&
Tasks
,
exact
:
bool
)
->
Result
<
u32
,
String
>
{
if
exact
{
return
preemption
s
_exact
(
task
,
&
tasks
,
0
);
return
preemption_exact
(
task
,
&
tasks
,
0
);
}
else
{
return
Ok
(
preemption
s
_approx
(
task
,
&
tasks
));
return
Ok
(
preemption_approx
(
task
,
&
tasks
));
}
}
pub
fn
blocking
(
task
:
&
Task
,
tasks
:
&
Tasks
)
->
u32
{
let
(
ip
,
tr
)
=
pre_analysis
(
&
tasks
);
let
(
_
ip
,
tr
)
=
pre_analysis
(
&
tasks
);
// Checks if the Task is claming a resource
if
!
tr
.contains_key
(
&
task
.id
)
{
return
0
;
...
...
@@ -96,17 +120,16 @@ pub fn blocking(task: &Task, tasks: &Tasks) -> u32 {
return
0
;
}
let
resources
=
&
tr
[
&
task
.id
];
println!
(
"{}"
,
&
task
.id
);
println!
(
"{:?}"
,
tr
);
println!
(
"{:?}"
,
resources
);
//
println!("{}", &task.id);
//
println!("{:?}", tr);
//
println!("{:?}", resources);
// Checking every resource it holds
let
mut
max_block
=
0
;
let
mut
current_block
=
0
;
// Iterate through current task resources
for
r1
in
resources
{
// Iterate through lower prio tasks
for
t_id
in
&
lower_prio_tasks
{
let
mut
lower_prio_task_resources
=
&
tr
[
t_id
];
let
lower_prio_task_resources
=
&
tr
[
t_id
];
// Iterate through lower prio task resources
for
r2
in
lower_prio_task_resources
{
// When current task use the same resource as a task
...
...
This diff is collapsed.
Click to expand it.
srp_analysis/src/common.rs
+
2
−
2
View file @
41ffd8c2
...
...
@@ -2,7 +2,7 @@ use std::collections::{HashMap, HashSet};
// common data structures
#[derive(Debug)]
#[derive(Debug
,
Clone
)]
pub
struct
Task
{
pub
id
:
String
,
pub
prio
:
u8
,
...
...
@@ -12,7 +12,7 @@ pub struct Task {
}
//#[derive(Debug, Clone)]
#[derive(Debug)]
#[derive(Debug
,
Clone
)]
pub
struct
Trace
{
pub
id
:
String
,
pub
start
:
u32
,
...
...
This diff is collapsed.
Click to expand it.
srp_analysis/src/main.rs
+
91
−
11
View file @
41ffd8c2
...
...
@@ -4,6 +4,26 @@ use analysis::*;
use
common
::
*
;
fn
main
()
{
let
tasks
=
taskset_1
();
println!
(
"CPU load {}"
,
load_factor
(
&
tasks
));
let
analysis
=
analysis
(
&
tasks
,
true
);
for
a
in
&
analysis
{
println!
(
"{:?} Response time {} | WCET {} | Blocking time {} | Preemption time {}"
,
a
.task.id
,
a
.response_time
,
a
.wcet
,
a
.blocking_time
,
a
.preemption_time
);
}
if
schedulable_check
(
analysis
)
{
println!
(
"The taskset is schedulable!"
)
}
else
{
println!
(
"The taskset is NOT schedulable!"
)
}
}
fn
taskset_1
()
->
Tasks
{
let
t1
=
Task
{
id
:
"T1"
.to_string
(),
prio
:
1
,
...
...
@@ -65,17 +85,77 @@ fn main() {
}],
},
};
// builds a vector of tasks t1, t2, t3
let
tasks
:
Tasks
=
vec!
[
t1
,
t2
,
t3
];
return
tasks
;
}
fn
taskset_2
()
->
Tasks
{
let
t1
=
Task
{
id
:
"T1"
.to_string
(),
prio
:
1
,
deadline
:
200
,
inter_arrival
:
200
,
trace
:
Trace
{
id
:
"T1"
.to_string
(),
start
:
0
,
end
:
15
,
inner
:
vec!
[
Trace
{
id
:
"R1"
.to_string
(),
start
:
2
,
end
:
8
,
inner
:
vec!
[],
}],
},
};
let
t2
=
Task
{
id
:
"T2"
.to_string
(),
prio
:
2
,
deadline
:
200
,
inter_arrival
:
200
,
trace
:
Trace
{
id
:
"T2"
.to_string
(),
start
:
0
,
end
:
37
,
inner
:
vec!
[
Trace
{
id
:
"R1"
.to_string
(),
start
:
10
,
end
:
18
,
inner
:
vec!
[
Trace
{
id
:
"R2"
.to_string
(),
start
:
12
,
end
:
16
,
inner
:
vec!
[],
}],
},
Trace
{
id
:
"R1"
.to_string
(),
start
:
22
,
end
:
25
,
inner
:
vec!
[],
},
],
},
};
let
(
ip
,
tr
)
=
pre_analysis
(
&
tasks
);
println!
(
"ip: {:?}"
,
ip
);
println!
(
"tr: {:?}"
,
tr
);
println!
(
"tot_util {}"
,
load_factor
(
&
tasks
));
print_analysis
(
&
tasks
);
let
t3
=
Task
{
id
:
"T3"
.to_string
(),
prio
:
3
,
deadline
:
100
,
inter_arrival
:
100
,
trace
:
Trace
{
id
:
"T3"
.to_string
(),
start
:
0
,
end
:
20
,
inner
:
vec!
[
Trace
{
id
:
"R2"
.to_string
(),
start
:
8
,
end
:
20
,
inner
:
vec!
[],
}],
},
};
let
tasks
:
Tasks
=
vec!
[
t1
,
t2
,
t3
];
return
tasks
;
}
\ 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