Commit 8a9a17da authored by Marco Perronet's avatar Marco Perronet
Browse files

Fix RBF sum

parent 898f110b
......@@ -7,8 +7,8 @@ import os
# workload = "evaluation/workloads/uniprocessor_double/1_uni_double_slow.json"
# workload = "evaluation/workloads/uniprocessor_double/2_uni_double.json"
# workload = "evaluation/workloads/uniprocessor_double/3_uni_double_fast.json"
workload = "evaluation/workloads/uniprocessor_double/4_uni_double_veryfast.json"
# workload = "evaluation/workloads/uniprocessor_all/8_uni_stress_veryfast.json"
# workload = "evaluation/workloads/uniprocessor_double/4_uni_double_veryfast.json"
workload = "evaluation/workloads/uniprocessor_all/8_uni_stress_veryfast.json"
print()
print("*** RUNNING WORKLOAD: " + os.path.basename(workload) + " ***")
......
......@@ -74,7 +74,7 @@ fn rta_loop(rx_analyzer: Receiver<ModelUpdate>, sys_conf: &SysConf) {
scalar_rta(analysis, &analyzed_tasks, &cluster.threads, &update.chosen_models, &mut wc_response_times);
} else if analysis.is_rbf() {
rbf_rta(&analyzed_tasks, &cluster.threads, &update.events.rbfs, &mut rtb_curves);
eprintln!("{:#?}", rtb_curves); // TODO properly output
// eprintln!("{:#?}", rtb_curves); // TODO properly output
}
}
......
......@@ -66,30 +66,57 @@ impl RbfCurve {
pub fn sum(&mut self, other: &RbfCurve) {
// Cloning the first curve because we would need to mutate it while iterating
let curve_iter = self.curve.clone();
let mut iter = merge(curve_iter.into_iter(), other.curve.into_iter()).peekable();
let mut curr_base_cost = 0;
let curve_1_clone = self.curve.clone();
let mut curve_1 = curve_1_clone.into_iter();
let mut curve_2 = other.curve.into_iter();
let mut last_cost_1 = 0;
let mut last_cost_2 = 0;
let mut point_1 = curve_1.next();
let mut point_2 = curve_2.next();
// Unlike "add", the "insert" method does not delete entries to keep monotonicity
while let Some(point) = iter.next() {
// Add the point with the lowest delta
while let (Some(p_1), Some(p_2)) = (point_1, point_2) {
if p_1.delta == p_2.delta {
let res = self.curve.insert(Point::new(p_1.delta, p_1.cost + p_2.cost));
if let Some(next_point) = iter.peek() {
last_cost_1 = p_1.cost + p_2.cost;
last_cost_2 = p_1.cost + p_2.cost;
point_1 = curve_1.next();
point_2 = curve_2.next();
} else if p_1.delta < p_2.delta {
self.curve.insert(Point::new(p_1.delta, p_1.cost + last_cost_2));
if point.delta == next_point.delta { // Both curves have this step
curr_base_cost = point.cost + next_point.cost;
let res = self.curve.update_cost(point.delta, curr_base_cost);
assert!(res.is_ok());
iter.next(); // Skip next entry
} else { // Only one curve has this step
eprintln!("base {} += {}", curr_base_cost, point.cost);
curr_base_cost += point.cost; // TODO attempt to add with overflow
self.curve.insert(Point::new(point.delta, curr_base_cost));
}
last_cost_1 = p_1.cost;
point_1 = curve_1.next();
} else {
self.curve.insert(Point::new(p_2.delta, p_2.cost + last_cost_1));
} else { // End reached, only one curve has this step
self.curve.insert(Point::new(point.delta, curr_base_cost + point.cost));
last_cost_2 = p_2.cost;
point_2 = curve_2.next();
}
}
// Edge case: in the last step, both iterators stepped before exiting the loop
if let Some(p_1) = point_1 {
self.curve.insert(Point::new(p_1.delta, p_1.cost + last_cost_2));
}
if let Some(p_2) = point_2 {
self.curve.insert(Point::new(p_2.delta, p_2.cost + last_cost_1));
}
// Add any other remaining points
for p_1 in curve_1 {
self.curve.insert(Point::new(p_1.delta, p_1.cost + last_cost_2));
}
for p_2 in curve_2 {
self.curve.insert(Point::new(p_2.delta, p_2.cost + last_cost_1));
}
}
pub fn print_curve(&self) {
for point in &self.curve {
print!("[{} : {}] ", point.delta, point.cost);
}
print!("\n");
}
pub fn new(pid: Pid) -> Self {
......
......@@ -227,5 +227,5 @@ impl<'a> Iterator for SparseMapIterator<'a> {
}
// https://doc.rust-lang.org/nomicon/send-and-sync.html
// Problem: linked_list::LinkedList<T> contains raw pointers, and as such Rust does not derive Send automatically for it. The linked list in the standard library does not allow insertion in the middle of the list, so we had to use this alternative implementaion.
// Problem: linked_list::LinkedList<T> contains raw pointers, and as such Rust does not derive Send automatically for it. The linked list in the standard library does not allow insertion in the middle of the list, so we had to use this alternative implementation.
unsafe impl Send for SparseMap {}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment