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