[1334] | 1 | package test.appProfConverter.dcworms; |
---|
| 2 | |
---|
| 3 | public class AppProfileConverter { |
---|
| 4 | |
---|
| 5 | public static SoftwareProfile convert(SoftwareProfile refSWProf, |
---|
| 6 | HardwareProfile targetHWProf) { |
---|
| 7 | SoftwareProfile newProf = new SoftwareProfile(); |
---|
| 8 | |
---|
| 9 | newProf.taskId = refSWProf.taskId; |
---|
| 10 | newProf.phases = new SoftwarePhase[refSWProf.phases.length]; |
---|
| 11 | for (int i = 0; i < newProf.phases.length; i++) { |
---|
| 12 | newProf.phases[i] = convertPhase(refSWProf.phases[i], targetHWProf); |
---|
| 13 | } |
---|
| 14 | |
---|
| 15 | return newProf; |
---|
| 16 | } |
---|
| 17 | |
---|
| 18 | private static SoftwarePhase convertPhase(SoftwarePhase refPhase, |
---|
| 19 | HardwareProfile targetHW) { |
---|
| 20 | SoftwarePhase newPhase; |
---|
| 21 | double refCpuWork; // workload is constant in a phase |
---|
| 22 | double loadCpu; |
---|
| 23 | double t_cpu, t_nic, t_best; |
---|
| 24 | |
---|
| 25 | newPhase = new SoftwarePhase(refPhase); |
---|
| 26 | newPhase.RefNode = targetHW.componentId; |
---|
| 27 | newPhase.RefFreq = targetHW.proc.maxClockSpeed; |
---|
| 28 | newPhase.RefCores = targetHW.proc.cores; |
---|
| 29 | newPhase.RefDownload = (double) targetHW.net.maxBandwidth; |
---|
| 30 | newPhase.RefUpload = (double) targetHW.net.maxBandwidth; |
---|
| 31 | |
---|
| 32 | refCpuWork = refPhase.RefFreq * refPhase.PM_CPU_Usage |
---|
| 33 | * refPhase.Duration * refPhase.RefCores; |
---|
| 34 | |
---|
| 35 | // Best CPU load and time duration |
---|
| 36 | loadCpu = Math.min(1.0, refPhase.PM_CPU_Usage) |
---|
| 37 | * Math.min(1.0, |
---|
| 38 | ((double) newPhase.PM_Threads / newPhase.RefCores)); |
---|
| 39 | System.out.println(loadCpu + ";" + refPhase.RefCores + ";" + refPhase.PM_CPU_Usage + ";" + newPhase.PM_Threads + ";" +newPhase.RefCores); |
---|
| 40 | t_cpu = refCpuWork / (newPhase.RefCores * newPhase.RefFreq * loadCpu); |
---|
| 41 | |
---|
| 42 | // Best network time duration |
---|
| 43 | t_nic = Math.max((double) newPhase.PM_Upload / newPhase.RefUpload, |
---|
| 44 | (double) newPhase.PM_Download / newPhase.RefDownload); |
---|
| 45 | |
---|
| 46 | t_best = Math.max(t_cpu, t_nic); |
---|
| 47 | |
---|
| 48 | // The duration in seconds will impact the load depending on the |
---|
| 49 | // approximation error |
---|
| 50 | newPhase.Duration = (int) Math.ceil(t_best); |
---|
| 51 | // use t_best to debug |
---|
| 52 | // newPhase.PM_CPU_Usage = refCpuWork |
---|
| 53 | // / (newPhase.RefCores * newPhase.RefFreq * t_best); |
---|
| 54 | newPhase.PM_CPU_Usage = refCpuWork |
---|
| 55 | / (newPhase.RefCores * newPhase.RefFreq * newPhase.Duration); |
---|
| 56 | |
---|
| 57 | System.out |
---|
| 58 | .printf("l0:%.2f\tl1:%.2f\td0:%d\td1:%d\tc0:%d\tc1:%d\tf0:%.2f\tf1:%.2f\tt0:%d\tt1:%d\n", |
---|
| 59 | refPhase.PM_CPU_Usage, newPhase.PM_CPU_Usage, |
---|
| 60 | refPhase.Duration, newPhase.Duration, |
---|
| 61 | refPhase.RefCores, newPhase.RefCores, refPhase.RefFreq, |
---|
| 62 | newPhase.RefFreq, refPhase.PM_Threads, |
---|
| 63 | newPhase.PM_Threads); |
---|
| 64 | |
---|
| 65 | // double newCpuWork = newPhase.RefFreq * newPhase.PM_CPU_Usage |
---|
| 66 | // * newPhase.Duration * newPhase.RefCores; |
---|
| 67 | // if (newCpuWork != refCpuWork) { |
---|
| 68 | // System.out.printf("w0:%.2f\tw0:%.2f\n", refCpuWork, newCpuWork); |
---|
| 69 | // } |
---|
| 70 | |
---|
| 71 | newPhase.PM_Power = AppPowerEstimator.PhasePower(newPhase, targetHW); |
---|
| 72 | |
---|
| 73 | return newPhase; |
---|
| 74 | } |
---|
| 75 | } |
---|