1 | package test.thermal.recs.plugins.scheduling; |
---|
2 | |
---|
3 | import java.io.FileInputStream; |
---|
4 | import java.io.FileNotFoundException; |
---|
5 | import java.io.IOException; |
---|
6 | import java.util.PropertyResourceBundle; |
---|
7 | import java.util.ResourceBundle; |
---|
8 | |
---|
9 | import schedframe.resources.computing.Node; |
---|
10 | import schedframe.resources.computing.Processor; |
---|
11 | import schedframe.scheduling.tasks.TaskInterface; |
---|
12 | import test.thermal.recs.utils.AppType; |
---|
13 | import test.thermal.recs.utils.TaskToApp; |
---|
14 | import dcworms.schedframe.scheduling.Executable; |
---|
15 | import example.localplugin.BaseLocalSchedulingPlugin; |
---|
16 | |
---|
17 | public abstract class RecsSP extends BaseLocalSchedulingPlugin { |
---|
18 | |
---|
19 | private static String EXEC_DATA_FILE_NAME = "src/test/thermal/recs/data/executiveness_data.properties"; |
---|
20 | |
---|
21 | private ResourceBundle execBundle; |
---|
22 | |
---|
23 | protected TaskToApp taskToApp = new TaskToApp(); |
---|
24 | |
---|
25 | protected void initApplicationType(TaskInterface<?> task){ |
---|
26 | taskToApp.getAppType(task); |
---|
27 | } |
---|
28 | |
---|
29 | protected String createExecutivenessQuery(TaskInterface<?> task, Node node) { |
---|
30 | Executable exec = (Executable)task; |
---|
31 | String query = getApplicationType(exec) + "." + getNodeCategory(node); |
---|
32 | return query; |
---|
33 | } |
---|
34 | |
---|
35 | protected String getApplicationType(TaskInterface<?> task){ |
---|
36 | AppType appType = taskToApp.getAppType(task); |
---|
37 | return appType.toString(); |
---|
38 | } |
---|
39 | |
---|
40 | protected String getNodeCategory(Node node){ |
---|
41 | return node.getCategory(); |
---|
42 | } |
---|
43 | |
---|
44 | protected int getCoreCnt(TaskInterface<?> task){ |
---|
45 | double cpuReq; |
---|
46 | try { |
---|
47 | cpuReq = task.getCpuCntRequest(); |
---|
48 | } catch (NoSuchFieldException e) { |
---|
49 | cpuReq = 1; |
---|
50 | } |
---|
51 | return Double.valueOf(cpuReq).intValue(); |
---|
52 | } |
---|
53 | |
---|
54 | protected int getFrequency(Node node){ |
---|
55 | Processor proc = (Processor) node.getProcessors().get(0); |
---|
56 | double freq = proc.getPowerInterface().getFrequency(); |
---|
57 | return Double.valueOf(freq).intValue(); |
---|
58 | } |
---|
59 | |
---|
60 | protected boolean getExecutiveness(String query) throws FileNotFoundException, IOException{ |
---|
61 | ResourceBundle execBundle = getExecBundle(); |
---|
62 | return Boolean.valueOf(execBundle.getString(query)).booleanValue(); |
---|
63 | } |
---|
64 | |
---|
65 | private ResourceBundle getExecBundle() throws FileNotFoundException, IOException{ |
---|
66 | if(execBundle == null){ |
---|
67 | execBundle = new PropertyResourceBundle(new FileInputStream(EXEC_DATA_FILE_NAME)); |
---|
68 | } |
---|
69 | return execBundle; |
---|
70 | } |
---|
71 | } |
---|