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
16484174
Commit
16484174
authored
4 years ago
by
Ruben Asplund
Browse files
Options
Downloads
Patches
Plain Diff
Implemented functions load_factor() and blocking()
parent
d30c0398
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
+98
-2
98 additions, 2 deletions
srp_analysis/src/main.rs
with
98 additions
and
2 deletions
srp_analysis/src/main.rs
+
98
−
2
View file @
16484174
mod
common
;
mod
common
;
use
common
::
*
;
use
common
::
*
;
use
std
::
collections
::
HashSet
;
fn
main
()
{
fn
main
()
{
let
t1
=
Task
{
let
t1
=
Task
{
...
@@ -67,10 +68,105 @@ fn main() {
...
@@ -67,10 +68,105 @@ fn main() {
// builds a vector of tasks t1, t2, t3
// builds a vector of tasks t1, t2, t3
let
tasks
:
Tasks
=
vec!
[
t1
,
t2
,
t3
];
let
tasks
:
Tasks
=
vec!
[
t1
,
t2
,
t3
];
println!
(
"tasks {:?}"
,
&
tasks
);
//
println!("tasks {:?}", &tasks);
//
println!("tot_util {}",
tot_util
(&tasks));
println!
(
"tot_util {}"
,
load_factor
(
&
tasks
));
let
(
ip
,
tr
)
=
pre_analysis
(
&
tasks
);
let
(
ip
,
tr
)
=
pre_analysis
(
&
tasks
);
println!
(
"ip: {:?}"
,
ip
);
println!
(
"ip: {:?}"
,
ip
);
println!
(
"tr: {:?}"
,
tr
);
println!
(
"tr: {:?}"
,
tr
);
for
t
in
&
tasks
{
blocking
(
t
,
&
tasks
);
}
}
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.start
);
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
if
!
tr
.contains_key
(
&
task
.id
)
{
println!
(
"0"
);
return
0
;
}
// Find lower prio tasks
let
mut
lower_prio_tasks
=
HashSet
::
new
();
for
t
in
tasks
{
if
t
.prio
<
task
.prio
{
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
)
{
continue
;
}
if
!
tr
.contains_key
(
&
t
.id
)
{
lower_prio_tasks
.remove
(
&
t
.id
);
}
}
// println!("{:?}", lower_prio_tasks);
if
lower_prio_tasks
.len
()
==
0
{
println!
(
"0"
);
return
0
;
}
/* Finding longest blocking */
let
resources
=
&
tr
[
&
task
.id
];
// Checking every resource it holds
let
mut
max_block
=
0
;
let
mut
current_block
=
0
;
// Iterate through current task resources
for
r1
in
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
);
// When current task use the same resource as a task
if
r1
==
r2
{
// Takes forward the blocking task
for
t
in
tasks
{
if
&
t
.id
==
t_id
{
// Iterate through first layer
for
inner
in
&
t
.trace.inner
{
if
&
inner
.id
==
r2
{
current_block
=
inner
.end
.wrapping_sub
(
inner
.start
);
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
)
}
// Iterate through second layer
for
inner2
in
&
inner
.inner
{
if
&
inner2
.id
==
r2
{
current_block
=
inner2
.end
.wrapping_sub
(
inner2
.start
);
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!
(
"{}"
,
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