-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode.ceu
57 lines (52 loc) · 2.42 KB
/
node.ceu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
code/await NodeProcess (var int num_nodes, var _double freq, event& _double time_event, var int my_id)
-> (var _double frequency, var int id, event none local_clock_tick, var _double next_clock_tick_time, pool[100] Buffer localBuffers) -> NEVER do // defines the "Anim" code abstraction
var int num_buffers_needed = num_nodes-1;
id = my_id;
frequency = freq;
next_clock_tick_time = 1/frequency;
var _double previous_occupancy = 50;
var _double kp = 5;
var _double ki = 0;
var _double integral_deadzone = 0;
var _double integral_sum = 0;
par/and do
loop do
var _double simulation_time = await time_event;
if (simulation_time >= next_clock_tick_time) then
emit local_clock_tick;
next_clock_tick_time = next_clock_tick_time + 1/frequency;
end
end
with
every local_clock_tick do
_printf("Clock ticked on node %d\n", id);
//update frequency with control policy
//for each buffer connected, send its occupancy
var&? Buffer buff_it;
var _double cumulative_occupancy = 0;
var int count = 0;
loop buff_it in localBuffers do
var& Buffer my_buff = &buff_it!;
var _double percent_occupancy = call GetOccupancyPcnt(&my_buff.buff);
cumulative_occupancy = cumulative_occupancy + percent_occupancy;
count = count + 1;
end
var _double average_occupancy = (cumulative_occupancy / count) * 100;
//_printf("Average occupancy: %lf\n", average_occupancy);
var _double change = average_occupancy - previous_occupancy;
integral_sum = integral_sum + change;
previous_occupancy = average_occupancy;
var _double p_term = kp * change;
var _double i_term = 0;
if (_abs(integral_sum) > integral_deadzone) then
i_term = ki * integral_sum;
end
var _double frequency_adjustment = p_term + i_term;
_printf("Node %d frequency adjustment: %lf\n",id, frequency_adjustment);
frequency = frequency + frequency_adjustment;
// _printf("Integral sum is now %lf\n", integral_sum);
_printf("Frequency on node %d is now: %lf\n", id, frequency);
end
end
await FOREVER; //really we should not reach this line
end