11import logging
22from collections import defaultdict , OrderedDict
3+ from copy import copy
34
45from wa .framework .exception import ConfigError
56from wa .framework .plugin import Plugin , Parameter
@@ -255,17 +256,16 @@ def __call__(self, value):
255256 return value
256257 elif isinstance (value , basestring ):
257258 value = caseless_string (value )
258- if value == 'max' :
259- return self .values [- 1 ]
260- elif value == 'min' :
261- return self .values [0 ]
259+ if value in ['min' , 'max' ]:
260+ return value
262261
263262 msg = 'Invalid frequency value: {}; Must be in {}'
264263 raise ValueError (msg .format (value , self .values ))
265264
266265 def __str__ (self ):
267266 return 'valid frequency value: {}' .format (self .values )
268267
268+
269269class CpufreqRuntimeConfig (RuntimeConfig ):
270270
271271 name = 'rt-cpufreq'
@@ -311,35 +311,34 @@ def initialize(self):
311311 return
312312
313313 self ._retrive_cpufreq_info ()
314- common_freqs , common_gov = self ._get_common_values ()
314+ all_freqs , common_freqs , common_gov = self ._get_common_values ()
315315
316316 # Add common parameters if available.
317- if common_freqs :
318- freq_val = FreqValue (common_freqs )
319- param_name = 'frequency'
320- self ._runtime_params [param_name ] = \
321- RuntimeParameter (param_name , kind = freq_val ,
322- setter = self .set_frequency ,
323- setter_params = {'core' : None },
324- description = """
325- The desired frequency for all cores
326- """ )
327- param_name = 'max_frequency'
328- self ._runtime_params [param_name ] = \
329- RuntimeParameter (param_name , kind = freq_val ,
330- setter = self .set_max_frequency ,
331- setter_params = {'core' : None },
332- description = """
333- The maximum frequency for all cores
334- """ )
335- param_name = 'min_frequency'
336- self ._runtime_params [param_name ] = \
337- RuntimeParameter (param_name , kind = freq_val ,
338- setter = self .set_min_frequency ,
339- setter_params = {'core' : None },
340- description = """
341- The minimum frequency for all cores
342- """ )
317+ freq_val = FreqValue (all_freqs )
318+ param_name = 'frequency'
319+ self ._runtime_params [param_name ] = \
320+ RuntimeParameter (param_name , kind = freq_val ,
321+ setter = self .set_frequency ,
322+ setter_params = {'core' : None },
323+ description = """
324+ The desired frequency for all cores
325+ """ )
326+ param_name = 'max_frequency'
327+ self ._runtime_params [param_name ] = \
328+ RuntimeParameter (param_name , kind = freq_val ,
329+ setter = self .set_max_frequency ,
330+ setter_params = {'core' : None },
331+ description = """
332+ The maximum frequency for all cores
333+ """ )
334+ param_name = 'min_frequency'
335+ self ._runtime_params [param_name ] = \
336+ RuntimeParameter (param_name , kind = freq_val ,
337+ setter = self .set_min_frequency ,
338+ setter_params = {'core' : None },
339+ description = """
340+ The minimum frequency for all cores
341+ """ )
343342
344343 if common_gov :
345344 param_name = 'governor'
@@ -351,6 +350,7 @@ def initialize(self):
351350 description = """
352351 The governor to be set for all cores
353352 """ )
353+
354354 param_name = 'governor_tunables'
355355 self ._runtime_params [param_name ] = \
356356 RuntimeParameter (param_name , kind = dict ,
@@ -544,8 +544,14 @@ def commit(self):
544544 self .configure_governor (cpu ,
545545 config .get ('governor' ),
546546 config .get ('governor_tunables' ))
547+
548+ frequency = config .get ('frequency' )
549+ if frequency == 'min' :
550+ frequency = self .target .cpufreq .get_min_frequency (cpu )
551+ elif frequency == 'max' :
552+ frequency = self .target .cpufreq .get_max_frequency (cpu )
547553 self .configure_frequency (cpu ,
548- config . get ( ' frequency' ) ,
554+ frequency ,
549555 config .get ('min_frequency' ),
550556 config .get ('max_frequency' ),
551557 config .get ('governor' ))
@@ -647,21 +653,20 @@ def _get_common_values(self):
647653 ''' Find common values for frequency and governors across all cores'''
648654 common_freqs = None
649655 common_gov = None
656+ all_freqs = None
650657 initialized = False
651658 for cpu in resolve_unique_domain_cpus ('all' , self .target ):
652659 if not initialized :
653660 initialized = True
654- if self .supported_cpu_freqs .get (cpu ):
655- common_freqs = set (self .supported_cpu_freqs .get (cpu ))
656- if self .supported_cpu_governors .get (cpu ):
657- common_gov = set (self .supported_cpu_governors .get (cpu ))
661+ common_freqs = set (self .supported_cpu_freqs .get (cpu ) or [])
662+ all_freqs = copy (common_freqs )
663+ common_gov = set (self .supported_cpu_governors .get (cpu ) or [])
658664 else :
659- if self .supported_cpu_freqs .get (cpu ):
660- common_freqs = common_freqs .intersection (self .supported_cpu_freqs .get (cpu ))
661- if self .supported_cpu_governors .get (cpu ):
662- common_gov = common_gov .intersection (self .supported_cpu_governors .get (cpu ))
665+ common_freqs = common_freqs .intersection (self .supported_cpu_freqs .get (cpu ) or set ())
666+ all_freqs = all_freqs .union (self .supported_cpu_freqs .get (cpu ) or set ())
667+ common_gov = common_gov .intersection (self .supported_cpu_governors .get (cpu ))
663668
664- return common_freqs , common_gov
669+ return all_freqs , common_freqs , common_gov
665670
666671class IdleStateValue (object ):
667672
0 commit comments