1 | package de.uka.ipd.sdq.scheduler.timeslice.impl; |
2 | |
3 | import de.uka.ipd.sdq.scheduler.priority.IPriority; |
4 | import de.uka.ipd.sdq.scheduler.processes.impl.ProcessWithPriority; |
5 | |
6 | public class PriorityDependentTimeSlice extends ContinuousTimeSlice { |
7 | |
8 | private double min_time_to_be_scheduled; // Default value for Linux no x86 systems: 11 |
9 | |
10 | public PriorityDependentTimeSlice(ProcessWithPriority process, double basic_timeslice, double min_timeslice, double min_time_to_be_scheduled) { |
11 | double computed_timeslice = computeTicksFromPriority(process |
12 | .getStaticPriority(), basic_timeslice); |
13 | this.timeslice = Math.max(computed_timeslice, min_timeslice); |
14 | this.min_time_to_be_scheduled = min_time_to_be_scheduled; |
15 | } |
16 | |
17 | /** |
18 | * Computes the length of the current time slice according to the Linux |
19 | * 2.6.18 Scheduler. |
20 | * |
21 | * @param process |
22 | * @return |
23 | */ |
24 | public static double computeTicksFromPriority(IPriority prio, double basic_timeslice) { |
25 | double basic = getBasicTimeSlice(prio, basic_timeslice); |
26 | IPriority max_prio = prio.getManager().getHighestPriority(); |
27 | IPriority min_prio = prio.getManager().getLowestPriority(); |
28 | int distance = min_prio.distance(prio) + 1; |
29 | double factor = (min_prio.distance(max_prio) + 1) / 2.0; |
30 | return basic * distance / factor; |
31 | } |
32 | |
33 | /** |
34 | * Processes with a static priority above default are preferred. |
35 | * |
36 | * @param static_prio |
37 | * @return |
38 | */ |
39 | public static double getBasicTimeSlice(IPriority static_prio, double basicTimeslice) { |
40 | IPriority default_prio = static_prio.getManager().getDefaultPriority(); |
41 | if (static_prio.greaterThan(default_prio)) { |
42 | return basicTimeslice * 4; |
43 | } else { |
44 | return basicTimeslice; |
45 | } |
46 | } |
47 | |
48 | @Override |
49 | public void updateTimeForScheduling() { |
50 | // if the remaining time is smaller than a jiffies the |
51 | // timeslice needs to be reset first. |
52 | if (remaining_time < min_time_to_be_scheduled){ |
53 | remaining_time = 0; |
54 | } |
55 | } |
56 | } |