Ignore:
Timestamp:
09/26/14 17:05:19 (11 years ago)
Author:
wojtekp
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • DCWoRMS/branches/coolemall/src/test/freqscaling/CB2_FCFS_Random_SP.java

    r1441 r1450  
    190190         
    191191        private void powerCap(ResourceManager resManager){ 
    192                 try { 
    193                         for(ComputingResource compRes: resManager.getResourcesOfType(StandardResourceType.Rack)){ 
    194                                 loadThresholds(compRes); 
    195  
    196                                 double powerConsumption = compRes.getPowerInterface().getRecentPowerUsage().getValue(); 
    197                                 //System.out.println(compRes.getFullName() + " current: " + powerConsumption); 
    198                                 if(powerConsumption > MAX_THRESHOLD){ 
    199                                         mode = compRes.getFullName(); 
    200                                         ComputeBox1 cb1 = (ComputeBox1) compRes; 
    201                                         List<Processor> processors = cb1.getProcessors(); 
    202                                          
    203                                         double currentFrequencyLevel = 0; 
    204                                         if(currentFrequencyLevels.get(compRes.getFullName()) != null){ 
    205                                                 currentFrequencyLevel = currentFrequencyLevels.get(compRes.getFullName()); 
    206                                         } else { 
    207                                                 currentFrequencyLevel = processors.get(0).getPowerInterface().getLowestPState().getFrequency(); 
    208                                         } 
    209                                         boolean overThreshold = true; 
    210                                         boolean canDoBetter = true; 
    211  
    212                                         while(overThreshold && canDoBetter){ 
    213                                                 //System.out.println(compRes.getFullName() + " - downgrading"); 
    214                                                 int procNumberWithoutChange = 0; 
    215                                                 boolean improvement = false; 
    216                                                 //System.out.println(compRes.getFullName() + "; currentFrequencyLevel: " + currentFrequencyLevel); 
     192                for(ComputingResource compRes: resManager.getResourcesOfType(StandardResourceType.Rack)){ 
     193                        loadThresholds(compRes); 
     194 
     195                        double powerConsumption = compRes.getPowerInterface().getRecentPowerUsage().getValue(); 
     196                        //System.out.println(compRes.getFullName() + " current: " + powerConsumption); 
     197                        if(powerConsumption > MAX_THRESHOLD){ 
     198                                mode = compRes.getFullName(); 
     199                                ComputeBox1 cb1 = (ComputeBox1) compRes; 
     200                                List<Processor> processors = cb1.getProcessors(); 
     201                                 
     202                                double currentFrequencyLevel = 0; 
     203                                if(currentFrequencyLevels.get(compRes.getFullName()) != null){ 
     204                                        currentFrequencyLevel = currentFrequencyLevels.get(compRes.getFullName()); 
     205                                } else { 
     206                                        currentFrequencyLevel = processors.get(0).getPowerInterface().getLowestPState().getFrequency(); 
     207                                } 
     208                                boolean overThreshold = true; 
     209                                boolean canDoBetter = true; 
     210 
     211                                while(overThreshold && canDoBetter){ 
     212                                        //System.out.println(compRes.getFullName() + " - downgrading"); 
     213                                        int procNumberWithoutChange = 0; 
     214                                        boolean improvement = false; 
     215                                        //System.out.println(compRes.getFullName() + "; currentFrequencyLevel: " + currentFrequencyLevel); 
     216                                        for (Processor proc: processors){ 
     217                                                PState currPState = proc.getPowerInterface().getPState(); 
     218                                                //System.out.println(proc.getFullName() + " - checking"); 
     219                                                if(currPState.getFrequency() <= currentFrequencyLevel && proc.getFreeCores().size() != proc.getCores().size()){ 
     220                                                        //System.out.println("operating same level"); 
     221                                                        procNumberWithoutChange++; 
     222                                                        continue; 
     223                                                }  
     224                                                if (proc.getFreeCores().size() == proc.getCores().size()){       
     225                                                        //System.out.println("free"); 
     226                                                        procNumberWithoutChange++; 
     227                                                        continue; 
     228                                                }  
     229                 
     230                                                double lowerFrequency = proc.getPowerInterface().getHighestPState().getFrequency(); 
     231                                                for(String pStateName: proc.getPowerInterface().getSupportedPStates().keySet()){ 
     232                                                        PState pState = proc.getPowerInterface().getSupportedPStates().get(pStateName); 
     233                                                        if(pState.getFrequency() > lowerFrequency && pState.getFrequency() < currPState.getFrequency()){ 
     234                                                                lowerFrequency = pState.getFrequency(); 
     235                                                        } 
     236                                                } 
     237                                                //System.out.println(proc.getFullName() + "; lower frequency: " + lowerFrequency); 
     238                                                if(lowerFrequency < currentFrequencyLevel){ 
     239                                                        //System.out.println(compRes.getFullName() + " - changing current frequency level"); 
     240                                                        currentFrequencyLevels.put(compRes.getFullName(), lowerFrequency); 
     241                                                        currentFrequencyLevel = currentFrequencyLevels.get(compRes.getFullName()); 
     242                                                } 
     243                                                 
     244                                                if(lowerFrequency != currPState.getFrequency()) { 
     245                                                        //System.out.println(proc.getFullName() + " - lowering frequency"); 
     246                                                        proc.getPowerInterface().setFrequency(lowerFrequency); 
     247                                                        Node n = proc.getNode(); 
     248                                                        for(Device device: n.getParent().getResourceCharacteristic().getDevices()){ 
     249                                                                 
     250                                                                if(device.getType().equals(StandardResourceType.Fan) || device.getType().equals(StandardResourceType.Inlet) | device.getType().equals(StandardResourceType.Outlet)){ 
     251                                                                        Fan fan = (Fan) device; 
     252 
     253                                                                        if(fan.getChilledResources().contains(n.getFullName())){ 
     254                                                                                fan.getAirflowInterface().setAirflowState(new CustomAirflowStateName("2")); 
     255                                                                        } 
     256                                                                } 
     257                                                        } 
     258                                                        improvement = true; 
     259                                                } 
     260                                                if(lowerFrequency == proc.getPowerInterface().getHighestPState().getFrequency()){ 
     261                                                        canDoBetter = false; 
     262                                                } else { 
     263                                                        canDoBetter = true; 
     264                                                } 
     265                                                if(compRes.getPowerInterface().getRecentPowerUsage().getValue() <= MAX_THRESHOLD){ 
     266                                                        overThreshold = false; 
     267                                                        break; 
     268                                                } 
     269                                        }        
     270                                        if(procNumberWithoutChange == processors.size() || improvement == false){ 
     271                                                //System.out.println(compRes.getFullName() + " - failed to improve"); 
     272                                                double nextFrequencyLevel = processors.get(0).getPowerInterface().getHighestPState().getFrequency(); 
    217273                                                for (Processor proc: processors){ 
    218                                                         PState currPState = proc.getPowerInterface().getPState(); 
    219                                                         //System.out.println(proc.getFullName() + " - checking"); 
    220                                                         if(currPState.getFrequency() <= currentFrequencyLevel && proc.getFreeCores().size() != proc.getCores().size()){ 
    221                                                                 //System.out.println("operating same level"); 
    222                                                                 procNumberWithoutChange++; 
    223                                                                 continue; 
    224                                                         }  
    225                                                         if (proc.getFreeCores().size() == proc.getCores().size()){       
    226                                                                 //System.out.println("free"); 
    227                                                                 procNumberWithoutChange++; 
    228                                                                 continue; 
    229                                                         }  
    230                          
    231                                                         double lowerFrequency = proc.getPowerInterface().getHighestPState().getFrequency(); 
    232274                                                        for(String pStateName: proc.getPowerInterface().getSupportedPStates().keySet()){ 
    233275                                                                PState pState = proc.getPowerInterface().getSupportedPStates().get(pStateName); 
    234                                                                 if(pState.getFrequency() > lowerFrequency && pState.getFrequency() < currPState.getFrequency()){ 
    235                                                                         lowerFrequency = pState.getFrequency(); 
    236                                                                 } 
    237                                                         } 
    238                                                         //System.out.println(proc.getFullName() + "; lower frequency: " + lowerFrequency); 
    239                                                         if(lowerFrequency < currentFrequencyLevel){ 
    240                                                                 //System.out.println(compRes.getFullName() + " - changing current frequency level"); 
    241                                                                 currentFrequencyLevels.put(compRes.getFullName(), lowerFrequency); 
    242                                                                 currentFrequencyLevel = currentFrequencyLevels.get(compRes.getFullName()); 
    243                                                         } 
    244                                                          
    245                                                         if(lowerFrequency != currPState.getFrequency()) { 
    246                                                                 //System.out.println(proc.getFullName() + " - lowering frequency"); 
    247                                                                 proc.getPowerInterface().setFrequency(lowerFrequency); 
    248                                                                 Node n = proc.getNode(); 
    249                                                                 for(Device device: n.getParent().getResourceCharacteristic().getDevices()){ 
    250                                                                          
    251                                                                         if(device.getType().equals(StandardResourceType.Fan) || device.getType().equals(StandardResourceType.Inlet) | device.getType().equals(StandardResourceType.Outlet)){ 
    252                                                                                 Fan fan = (Fan) device; 
    253  
    254                                                                                 if(fan.getChilledResources().contains(n.getFullName())){ 
    255                                                                                         fan.getAirflowInterface().setAirflowState(new CustomAirflowStateName("2")); 
    256                                                                                 } 
     276                                                                if(pState.getFrequency() > nextFrequencyLevel && pState.getFrequency() < currentFrequencyLevel){ 
     277                                                                        nextFrequencyLevel = pState.getFrequency(); 
     278                                                                }  
     279                                                        } 
     280                                                } 
     281                                                //System.out.println(compRes.getFullName() + "; nextFrequencyLevel: " + nextFrequencyLevel); 
     282                                                currentFrequencyLevels.put(compRes.getFullName(), nextFrequencyLevel); 
     283                                                currentFrequencyLevel = currentFrequencyLevels.get(compRes.getFullName()); 
     284                                                if(currentFrequencyLevel == processors.get(0).getPowerInterface().getHighestPState().getFrequency()){ 
     285                                                        canDoBetter = false; 
     286                                                } 
     287                                                procNumberWithoutChange = 0; 
     288                                        } 
     289                                } 
     290 
     291                        } else if (powerConsumption < MIN_THRESHOLD) { 
     292                                ComputeBox1 cb1 = (ComputeBox1) compRes; 
     293                                List<Processor> processors = cb1.getProcessors(); 
     294                                 
     295                                double currentFrequencyLevel = 0; 
     296                                if(currentFrequencyLevels.get(compRes.getFullName()) != null){ 
     297                                        currentFrequencyLevel = currentFrequencyLevels.get(compRes.getFullName()); 
     298                                } else { 
     299                                        currentFrequencyLevel = processors.get(0).getPowerInterface().getLowestPState().getFrequency(); 
     300                                } 
     301                                boolean overThreshold = true; 
     302                                boolean canDoBetter = true; 
     303 
     304                                while(overThreshold && canDoBetter){ 
     305                                        //System.out.println(compRes.getFullName() + " - downgrading"); 
     306                                        int procNumberWithoutChange = 0; 
     307                                        boolean improvement = false; 
     308                                        //System.out.println(compRes.getFullName() + "; currentFrequencyLevel: " + currentFrequencyLevel); 
     309                                        for (Processor proc: processors){ 
     310                                                PState currPState = proc.getPowerInterface().getPState(); 
     311                                                //System.out.println(proc.getFullName() + " - checking"); 
     312                                                if(currPState.getFrequency() >= currentFrequencyLevel && proc.getFreeCores().size() != proc.getCores().size()){ 
     313                                                        //System.out.println("operating same level"); 
     314                                                        procNumberWithoutChange++; 
     315                                                        continue; 
     316                                                }  
     317                                                if (proc.getFreeCores().size() == proc.getCores().size()){       
     318                                                        //System.out.println("free"); 
     319                                                        procNumberWithoutChange++; 
     320                                                        continue; 
     321                                                }  
     322                 
     323                                                double higherFrequency = proc.getPowerInterface().getLowestPState().getFrequency(); 
     324                                                for(String pStateName: proc.getPowerInterface().getSupportedPStates().keySet()){ 
     325                                                        PState pState = proc.getPowerInterface().getSupportedPStates().get(pStateName); 
     326                                                        if(pState.getFrequency() < higherFrequency && pState.getFrequency() > currPState.getFrequency()){ 
     327                                                                higherFrequency = pState.getFrequency(); 
     328                                                        } 
     329                                                } 
     330                                                //System.out.println(proc.getFullName() + "; lower frequency: " + lowerFrequency); 
     331                                                if(higherFrequency > currentFrequencyLevel){ 
     332                                                        //System.out.println(compRes.getFullName() + " - changing current frequency level"); 
     333                                                        currentFrequencyLevels.put(compRes.getFullName(), higherFrequency); 
     334                                                        currentFrequencyLevel = currentFrequencyLevels.get(compRes.getFullName()); 
     335                                                } 
     336                                                 
     337                                                if(higherFrequency != currPState.getFrequency()) { 
     338                                                        //System.out.println(proc.getFullName() + " - lowering frequency"); 
     339                                                        proc.getPowerInterface().setFrequency(higherFrequency); 
     340                                                        Node n = proc.getNode(); 
     341                                                        for(Device device: n.getParent().getResourceCharacteristic().getDevices()){ 
     342                                                                 
     343                                                                if(device.getType().equals(StandardResourceType.Fan) || device.getType().equals(StandardResourceType.Inlet) | device.getType().equals(StandardResourceType.Outlet)){ 
     344                                                                        Fan fan = (Fan) device; 
     345 
     346                                                                        if(fan.getChilledResources().contains(n.getFullName())){ 
     347                                                                                fan.getAirflowInterface().setAirflowState(new CustomAirflowStateName("2")); 
    257348                                                                        } 
    258349                                                                } 
    259                                                                 improvement = true; 
    260                                                         } 
    261                                                         if(lowerFrequency == proc.getPowerInterface().getHighestPState().getFrequency()){ 
    262                                                                 canDoBetter = false; 
    263                                                         } else { 
    264                                                                 canDoBetter = true; 
    265                                                         } 
    266                                                         if(compRes.getPowerInterface().getRecentPowerUsage().getValue() <= MAX_THRESHOLD){ 
    267                                                                 overThreshold = false; 
    268                                                                 break; 
    269                                                         } 
    270                                                 }        
    271                                                 if(procNumberWithoutChange == processors.size() || improvement == false){ 
    272                                                         //System.out.println(compRes.getFullName() + " - failed to improve"); 
    273                                                         double nextFrequencyLevel = processors.get(0).getPowerInterface().getHighestPState().getFrequency(); 
    274                                                         for (Processor proc: processors){ 
    275                                                                 for(String pStateName: proc.getPowerInterface().getSupportedPStates().keySet()){ 
    276                                                                         PState pState = proc.getPowerInterface().getSupportedPStates().get(pStateName); 
    277                                                                         if(pState.getFrequency() > nextFrequencyLevel && pState.getFrequency() < currentFrequencyLevel){ 
    278                                                                                 nextFrequencyLevel = pState.getFrequency(); 
    279                                                                         }  
    280                                                                 } 
    281                                                         } 
    282                                                         //System.out.println(compRes.getFullName() + "; nextFrequencyLevel: " + nextFrequencyLevel); 
    283                                                         currentFrequencyLevels.put(compRes.getFullName(), nextFrequencyLevel); 
    284                                                         currentFrequencyLevel = currentFrequencyLevels.get(compRes.getFullName()); 
    285                                                         if(currentFrequencyLevel == processors.get(0).getPowerInterface().getHighestPState().getFrequency()){ 
    286                                                                 canDoBetter = false; 
    287                                                         } 
    288                                                         procNumberWithoutChange = 0; 
    289                                                 } 
    290                                         } 
    291  
    292                                 } else if (powerConsumption < MIN_THRESHOLD) { 
    293                                         ComputeBox1 cb1 = (ComputeBox1) compRes; 
    294                                         List<Processor> processors = cb1.getProcessors(); 
    295                                          
    296                                         double currentFrequencyLevel = 0; 
    297                                         if(currentFrequencyLevels.get(compRes.getFullName()) != null){ 
    298                                                 currentFrequencyLevel = currentFrequencyLevels.get(compRes.getFullName()); 
    299                                         } else { 
    300                                                 currentFrequencyLevel = processors.get(0).getPowerInterface().getLowestPState().getFrequency(); 
    301                                         } 
    302                                         boolean overThreshold = true; 
    303                                         boolean canDoBetter = true; 
    304  
    305                                         while(overThreshold && canDoBetter){ 
    306                                                 //System.out.println(compRes.getFullName() + " - downgrading"); 
    307                                                 int procNumberWithoutChange = 0; 
    308                                                 boolean improvement = false; 
    309                                                 //System.out.println(compRes.getFullName() + "; currentFrequencyLevel: " + currentFrequencyLevel); 
     350                                                        } 
     351                                                        improvement = true; 
     352                                                } 
     353                                                if(higherFrequency == proc.getPowerInterface().getLowestPState().getFrequency()){ 
     354                                                        canDoBetter = false; 
     355                                                } else { 
     356                                                        canDoBetter = true; 
     357                                                } 
     358                                                if(compRes.getPowerInterface().getRecentPowerUsage().getValue() >= MAX_THRESHOLD){ 
     359                                                        overThreshold = false; 
     360                                                        break; 
     361                                                } 
     362                                        } 
     363                                        if(procNumberWithoutChange == processors.size() || improvement == false){ 
     364                                                //System.out.println(compRes.getFullName() + " - failed to improve"); 
     365                                                double nextFrequencyLevel = processors.get(0).getPowerInterface().getLowestPState().getFrequency(); 
    310366                                                for (Processor proc: processors){ 
    311                                                         PState currPState = proc.getPowerInterface().getPState(); 
    312                                                         //System.out.println(proc.getFullName() + " - checking"); 
    313                                                         if(currPState.getFrequency() >= currentFrequencyLevel && proc.getFreeCores().size() != proc.getCores().size()){ 
    314                                                                 //System.out.println("operating same level"); 
    315                                                                 procNumberWithoutChange++; 
    316                                                                 continue; 
    317                                                         }  
    318                                                         if (proc.getFreeCores().size() == proc.getCores().size()){       
    319                                                                 //System.out.println("free"); 
    320                                                                 procNumberWithoutChange++; 
    321                                                                 continue; 
    322                                                         }  
    323                          
    324                                                         double higherFrequency = proc.getPowerInterface().getLowestPState().getFrequency(); 
    325367                                                        for(String pStateName: proc.getPowerInterface().getSupportedPStates().keySet()){ 
    326368                                                                PState pState = proc.getPowerInterface().getSupportedPStates().get(pStateName); 
    327                                                                 if(pState.getFrequency() < higherFrequency && pState.getFrequency() > currPState.getFrequency()){ 
    328                                                                         higherFrequency = pState.getFrequency(); 
    329                                                                 } 
    330                                                         } 
    331                                                         //System.out.println(proc.getFullName() + "; lower frequency: " + lowerFrequency); 
    332                                                         if(higherFrequency > currentFrequencyLevel){ 
    333                                                                 //System.out.println(compRes.getFullName() + " - changing current frequency level"); 
    334                                                                 currentFrequencyLevels.put(compRes.getFullName(), higherFrequency); 
    335                                                                 currentFrequencyLevel = currentFrequencyLevels.get(compRes.getFullName()); 
    336                                                         } 
    337                                                          
    338                                                         if(higherFrequency != currPState.getFrequency()) { 
    339                                                                 //System.out.println(proc.getFullName() + " - lowering frequency"); 
    340                                                                 proc.getPowerInterface().setFrequency(higherFrequency); 
    341                                                                 Node n = proc.getNode(); 
    342                                                                 for(Device device: n.getParent().getResourceCharacteristic().getDevices()){ 
    343                                                                          
    344                                                                         if(device.getType().equals(StandardResourceType.Fan) || device.getType().equals(StandardResourceType.Inlet) | device.getType().equals(StandardResourceType.Outlet)){ 
    345                                                                                 Fan fan = (Fan) device; 
    346  
    347                                                                                 if(fan.getChilledResources().contains(n.getFullName())){ 
    348                                                                                         fan.getAirflowInterface().setAirflowState(new CustomAirflowStateName("2")); 
    349                                                                                 } 
    350                                                                         } 
    351                                                                 } 
    352                                                                 improvement = true; 
    353                                                         } 
    354                                                         if(higherFrequency == proc.getPowerInterface().getLowestPState().getFrequency()){ 
    355                                                                 canDoBetter = false; 
    356                                                         } else { 
    357                                                                 canDoBetter = true; 
    358                                                         } 
    359                                                         if(compRes.getPowerInterface().getRecentPowerUsage().getValue() >= MAX_THRESHOLD){ 
    360                                                                 overThreshold = false; 
    361                                                                 break; 
    362                                                         } 
    363                                                 } 
    364                                                 if(procNumberWithoutChange == processors.size() || improvement == false){ 
    365                                                         //System.out.println(compRes.getFullName() + " - failed to improve"); 
    366                                                         double nextFrequencyLevel = processors.get(0).getPowerInterface().getLowestPState().getFrequency(); 
    367                                                         for (Processor proc: processors){ 
    368                                                                 for(String pStateName: proc.getPowerInterface().getSupportedPStates().keySet()){ 
    369                                                                         PState pState = proc.getPowerInterface().getSupportedPStates().get(pStateName); 
    370                                                                         if(pState.getFrequency() < nextFrequencyLevel && pState.getFrequency() > currentFrequencyLevel){ 
    371                                                                                 nextFrequencyLevel = pState.getFrequency(); 
    372                                                                         }  
    373                                                                 } 
    374                                                         } 
    375                                                         //System.out.println(compRes.getFullName() + "; nextFrequencyLevel: " + nextFrequencyLevel); 
    376                                                         currentFrequencyLevels.put(compRes.getFullName(), nextFrequencyLevel); 
    377                                                         currentFrequencyLevel = currentFrequencyLevels.get(compRes.getFullName()); 
    378                                                         if(currentFrequencyLevel == processors.get(0).getPowerInterface().getLowestPState().getFrequency()){ 
    379                                                                 canDoBetter = false; 
    380                                                         } 
    381                                                         procNumberWithoutChange = 0; 
    382                                                 } 
    383                                         } 
    384  
    385                                 } 
    386                                 mode = ""; 
    387                         } 
    388                          
    389                 } catch (ResourceException e) { 
    390                         // TODO Auto-generated catch block 
    391                         e.printStackTrace(); 
    392                 } 
     369                                                                if(pState.getFrequency() < nextFrequencyLevel && pState.getFrequency() > currentFrequencyLevel){ 
     370                                                                        nextFrequencyLevel = pState.getFrequency(); 
     371                                                                }  
     372                                                        } 
     373                                                } 
     374                                                //System.out.println(compRes.getFullName() + "; nextFrequencyLevel: " + nextFrequencyLevel); 
     375                                                currentFrequencyLevels.put(compRes.getFullName(), nextFrequencyLevel); 
     376                                                currentFrequencyLevel = currentFrequencyLevels.get(compRes.getFullName()); 
     377                                                if(currentFrequencyLevel == processors.get(0).getPowerInterface().getLowestPState().getFrequency()){ 
     378                                                        canDoBetter = false; 
     379                                                } 
     380                                                procNumberWithoutChange = 0; 
     381                                        } 
     382                                } 
     383 
     384                        } 
     385                        mode = ""; 
     386                } 
     387 
    393388        } 
    394389         
Note: See TracChangeset for help on using the changeset viewer.