Пример #1
0
    def _retrive_cpufreq_info(self):
        '''
        Tries to retrieve cpu freq information for all cpus on device.
        For each cpu domain, only one cpu is queried for information and
        duplicated across related cpus. This is to reduce calls to the target
        and as long as one core per domain is online the remaining cpus information
        can still be populated.
        '''
        for cluster_cpu in resolve_unique_domain_cpus('all', self.target):
            domain_cpus = self.target.cpufreq.get_related_cpus(cluster_cpu)
            for cpu in domain_cpus:
                if cpu in self.target.list_online_cpus():
                    supported_cpu_freqs = self.target.cpufreq.list_frequencies(
                        cpu)
                    supported_cpu_governors = self.target.cpufreq.list_governors(
                        cpu)
                    break
            else:
                msg = 'CPUFreq information could not be retrieved for{};'\
                      'Will not be validated against device.'
                logger.debug(
                    msg.format(' CPU{},'.format(cpu for cpu in domain_cpus)))
                return

            for cpu in domain_cpus:
                self.supported_cpu_freqs[cpu] = supported_cpu_freqs
                self.supported_cpu_governors[cpu] = supported_cpu_governors
Пример #2
0
 def set_param(obj, value, core, parameter):
     '''Method to store passed parameter if it is not already specified for that cpu'''
     cpus = resolve_unique_domain_cpus(core, obj.target)
     for cpu in cpus:
         if parameter in obj.config[cpu]:
             msg = 'Cannot set "{}" for core "{}"; Parameter for CPU{} has already been set'
             raise ConfigError(msg.format(parameter, core, cpu))
         obj.config[cpu][parameter] = value
Пример #3
0
 def set_param(obj, value, core, parameter):
     '''Method to store passed parameter if it is not already specified for that cpu'''
     cpus = resolve_unique_domain_cpus(core, obj.target)
     for cpu in cpus:
         if parameter in obj.config[cpu]:
             msg = 'Cannot set "{}" for core "{}"; Parameter for CPU{} has already been set'
             raise ConfigError(msg.format(parameter, core, cpu))
         obj.config[cpu][parameter] = value
Пример #4
0
    def _get_common_values(self):
        ''' Find common values for frequency and governors across all cores'''
        common_freqs = None
        common_gov = None
        all_freqs = None
        initialized = False
        for cpu in resolve_unique_domain_cpus('all', self.target):
            if not initialized:
                initialized = True
                common_freqs = set(self.supported_cpu_freqs.get(cpu) or [])
                all_freqs = copy(common_freqs)
                common_gov = set(self.supported_cpu_governors.get(cpu) or [])
            else:
                common_freqs = common_freqs.intersection(self.supported_cpu_freqs.get(cpu) or set())
                all_freqs = all_freqs.union(self.supported_cpu_freqs.get(cpu) or set())
                common_gov = common_gov.intersection(self.supported_cpu_governors.get(cpu) or set())

        return all_freqs, common_freqs, common_gov
Пример #5
0
    def _get_common_values(self):
        ''' Find common values for frequency and governors across all cores'''
        common_freqs = None
        common_gov = None
        all_freqs = None
        initialized = False
        for cpu in resolve_unique_domain_cpus('all', self.target):
            if not initialized:
                initialized = True
                common_freqs = set(self.supported_cpu_freqs.get(cpu) or [])
                all_freqs = copy(common_freqs)
                common_gov = set(self.supported_cpu_governors.get(cpu) or [])
            else:
                common_freqs = common_freqs.intersection(self.supported_cpu_freqs.get(cpu) or set())
                all_freqs = all_freqs.union(self.supported_cpu_freqs.get(cpu) or set())
                common_gov = common_gov.intersection(self.supported_cpu_governors.get(cpu))

        return all_freqs, common_freqs, common_gov
Пример #6
0
    def test_resolve_cpu(self):
        # Set up a mock target
        mock = Mock()
        mock.big_core = "A72"
        mock.little_core = "A53"
        mock.core_names = ['A72', 'A72', 'A53', 'A53']
        mock.number_of_cpus = 4

        def mock_core_cpus(core):
            return [i for i, c in enumerate(mock.core_names) if c == core]

        def mock_online_cpus():
            return [0, 1, 2]

        def mock_offline_cpus():
            return [3]

        def mock_related_cpus(core):
            if core in [0, 1]:
                return [0, 1]
            elif core in [2, 3]:
                return [2, 3]

        mock.list_online_cpus = mock_online_cpus
        mock.list_offline_cpus = mock_offline_cpus
        mock.core_cpus = mock_core_cpus
        mock.core_cpus = mock_core_cpus
        mock.cpufreq.get_related_cpus = mock_related_cpus

        # Check retrieving cpus from a given prefix
        assert_equal(resolve_cpus('A72', mock), [0, 1])
        assert_equal(resolve_cpus('A53', mock), [2, 3])
        assert_equal(resolve_cpus('big', mock), [0, 1])
        assert_equal(resolve_cpus('little', mock), [2, 3])
        assert_equal(resolve_cpus('', mock), [0, 1, 2, 3])
        assert_equal(resolve_cpus('cpu0', mock), [0])
        assert_equal(resolve_cpus('cpu3', mock), [3])

        # Check get unique domain cpus
        assert_equal(resolve_unique_domain_cpus('A72', mock), [0])
        assert_equal(resolve_unique_domain_cpus('A53', mock), [2])
        assert_equal(resolve_unique_domain_cpus('big', mock), [0])
        assert_equal(resolve_unique_domain_cpus('little', mock), [2])
        assert_equal(resolve_unique_domain_cpus('', mock), [0, 2])
        assert_equal(resolve_unique_domain_cpus('cpu0', mock), [0])
        assert_equal(resolve_unique_domain_cpus('cpu3', mock), [2])
    def test_resolve_cpu(self):
        # Set up a mock target
        mock = Mock()
        mock.big_core = "A72"
        mock.little_core = "A53"
        mock.core_names = ['A72', 'A72', 'A53', 'A53']
        mock.number_of_cpus = 4
        def mock_core_cpus(core):
            return [i for i, c in enumerate(mock.core_names) if c == core]
        def mock_online_cpus():
            return [0, 1, 2]
        def mock_offline_cpus():
            return [3]
        def mock_related_cpus(core):
            if core in [0, 1]:
                return [0, 1]
            elif core in [2, 3]:
                return [2, 3]

        mock.list_online_cpus = mock_online_cpus
        mock.list_offline_cpus = mock_offline_cpus
        mock.core_cpus = mock_core_cpus
        mock.core_cpus = mock_core_cpus
        mock.cpufreq.get_related_cpus = mock_related_cpus

        # Check retrieving cpus from a given prefix
        assert_equal(resolve_cpus('A72', mock), [0, 1])
        assert_equal(resolve_cpus('A53', mock), [2, 3])
        assert_equal(resolve_cpus('big', mock), [0, 1])
        assert_equal(resolve_cpus('little', mock), [2, 3])
        assert_equal(resolve_cpus('', mock), [0, 1, 2, 3])
        assert_equal(resolve_cpus('cpu0', mock), [0])
        assert_equal(resolve_cpus('cpu3', mock), [3])

        # Check get unique domain cpus
        assert_equal(resolve_unique_domain_cpus('A72', mock), [0])
        assert_equal(resolve_unique_domain_cpus('A53', mock), [2])
        assert_equal(resolve_unique_domain_cpus('big', mock), [0])
        assert_equal(resolve_unique_domain_cpus('little', mock), [2])
        assert_equal(resolve_unique_domain_cpus('', mock), [0, 2])
        assert_equal(resolve_unique_domain_cpus('cpu0', mock), [0])
        assert_equal(resolve_unique_domain_cpus('cpu3', mock), [2])
Пример #8
0
    def _retrive_cpufreq_info(self):
        '''
        Tries to retrieve cpu freq information for all cpus on device.
        For each cpu domain, only one cpu is queried for information and
        duplicated across related cpus. This is to reduce calls to the target
        and as long as one core per domain is online the remaining cpus information
        can still be populated.
        '''
        for cluster_cpu in resolve_unique_domain_cpus('all', self.target):
            domain_cpus = self.target.cpufreq.get_related_cpus(cluster_cpu)
            for cpu in domain_cpus:
                if cpu in self.target.list_online_cpus():
                    supported_cpu_freqs = self.target.cpufreq.list_frequencies(cpu)
                    supported_cpu_governors = self.target.cpufreq.list_governors(cpu)
                    break
            else:
                msg = 'CPUFreq information could not be retrieved for{};'\
                      'Will not be validated against device.'
                logger.debug(msg.format(' CPU{},'.format(cpu for cpu in domain_cpus)))
                return

            for cpu in domain_cpus:
                self.supported_cpu_freqs[cpu] = supported_cpu_freqs
                self.supported_cpu_governors[cpu] = supported_cpu_governors
Пример #9
0
    def initialize(self):
        # pylint: disable=too-many-statements
        if not self.target.has('cpufreq'):
            return

        self._retrive_cpufreq_info()
        _, common_freqs, common_gov = self._get_common_values()

        # Add common parameters if available.
        freq_val = FreqValue(common_freqs)
        param_name = 'frequency'
        self._runtime_params[param_name] = \
            RuntimeParameter(
                param_name, kind=freq_val,
                setter=self.set_frequency,
                setter_params={'core': None},
                description="""
                The desired frequency for all cores
                """)
        param_name = 'max_frequency'
        self._runtime_params[param_name] = \
            RuntimeParameter(
                param_name, kind=freq_val,
                setter=self.set_max_frequency,
                setter_params={'core': None},
                description="""
                The maximum frequency for all cores
                """)
        param_name = 'min_frequency'
        self._runtime_params[param_name] = \
            RuntimeParameter(
                param_name, kind=freq_val,
                setter=self.set_min_frequency,
                setter_params={'core': None},
                description="""
                The minimum frequency for all cores
                """)

        if common_gov:
            param_name = 'governor'
            self._runtime_params[param_name] = \
                RuntimeParameter(
                    param_name, kind=str,
                    allowed_values=common_gov,
                    setter=self.set_governor,
                    setter_params={'core': None},
                    description="""
                    The governor to be set for all cores
                    """)

        param_name = 'gov_tunables'
        self._runtime_params[param_name] = \
            RuntimeParameter(
                param_name, kind=dict,
                merge=True,
                setter=self.set_governor_tunables,
                setter_params={'core': None},
                aliases=['governor_tunables'],
                description="""
                The governor tunables to be set for all cores
                """)

        # Add core name parameters
        for name in unique(self.target.platform.core_names):
            cpu = resolve_unique_domain_cpus(name, self.target)[0]
            freq_val = FreqValue(self.supported_cpu_freqs.get(cpu))
            avail_govs = self.supported_cpu_governors.get(cpu)

            param_name = '{}_frequency'.format(name)
            self._runtime_params[param_name] = \
                RuntimeParameter(
                    param_name, kind=freq_val,
                    setter=self.set_frequency,
                    setter_params={'core': name},
                    description="""
                    The desired frequency for the {} cores
                    """.format(name))
            param_name = '{}_max_frequency'.format(name)
            self._runtime_params[param_name] = \
                RuntimeParameter(
                    param_name, kind=freq_val,
                    setter=self.set_max_frequency,
                    setter_params={'core': name},
                    description="""
                    The maximum frequency for the {} cores
                    """.format(name))
            param_name = '{}_min_frequency'.format(name)
            self._runtime_params[param_name] = \
                RuntimeParameter(
                    param_name, kind=freq_val,
                    setter=self.set_min_frequency,
                    setter_params={'core': name},
                    description="""
                    The minimum frequency for the {} cores
                    """.format(name))
            param_name = '{}_governor'.format(name)
            self._runtime_params[param_name] = \
                RuntimeParameter(
                    param_name, kind=str,
                    allowed_values=avail_govs,
                    setter=self.set_governor,
                    setter_params={'core': name},
                    description="""
                    The governor to be set for the {} cores
                    """.format(name))
            param_name = '{}_gov_tunables'.format(name)
            self._runtime_params[param_name] = \
                RuntimeParameter(
                    param_name, kind=dict,
                    setter=self.set_governor_tunables,
                    setter_params={'core': name},
                    merge=True,
                    description="""
                    The governor tunables to be set for the {} cores
                    """.format(name))

        # Add cpuX parameters.
        for cpu_no in range(self.target.number_of_cpus):
            freq_val = FreqValue(self.supported_cpu_freqs.get(cpu_no))
            avail_govs = self.supported_cpu_governors.get(cpu_no)

            param_name = 'cpu{}_frequency'.format(cpu_no)
            self._runtime_params[param_name] = \
                RuntimeParameter(
                    param_name, kind=freq_val,
                    setter=self.set_frequency,
                    setter_params={'core': cpu_no},
                    description="""
                    The desired frequency for cpu{}
                    """.format(cpu_no))
            param_name = 'cpu{}_max_frequency'.format(cpu_no)
            self._runtime_params[param_name] = \
                RuntimeParameter(
                    param_name, kind=freq_val,
                    setter=self.set_max_frequency,
                    setter_params={'core': cpu_no},
                    description="""
                    The maximum frequency for cpu{}
                    """.format(cpu_no))
            param_name = 'cpu{}_min_frequency'.format(cpu_no)
            self._runtime_params[param_name] = \
                RuntimeParameter(
                    param_name, kind=freq_val,
                    setter=self.set_min_frequency,
                    setter_params={'core': cpu_no},
                    description="""
                    The minimum frequency for cpu{}
                    """.format(cpu_no))
            param_name = 'cpu{}_governor'.format(cpu_no)
            self._runtime_params[param_name] = \
                RuntimeParameter(
                    param_name, kind=str,
                    allowed_values=avail_govs,
                    setter=self.set_governor,
                    setter_params={'core': cpu_no},
                    description="""
                    The governor to be set for cpu{}
                    """.format(cpu_no))
            param_name = 'cpu{}_gov_tunables'.format(cpu_no)
            self._runtime_params[param_name] = \
                RuntimeParameter(
                    param_name, kind=dict,
                    setter=self.set_governor_tunables,
                    setter_params={'core': cpu_no},
                    merge=True,
                    description="""
                    The governor tunables to be set for cpu{}
                    """.format(cpu_no))

        # Add big.little cores if present on device.
        if self.target.has('bl'):
            for cluster in ['big', 'little']:
                cpu = resolve_unique_domain_cpus(cluster, self.target)[0]
                freq_val = FreqValue(self.supported_cpu_freqs.get(cpu))
                avail_govs = self.supported_cpu_governors.get(cpu)
                param_name = '{}_frequency'.format(cluster)

                self._runtime_params[param_name] = \
                    RuntimeParameter(
                        param_name, kind=freq_val,
                        setter=self.set_frequency,
                        setter_params={'core': cluster},
                        description="""
                        The desired frequency for the {} cluster
                        """.format(cluster))
                param_name = '{}_max_frequency'.format(cluster)
                self._runtime_params[param_name] = \
                    RuntimeParameter(
                        param_name, kind=freq_val,
                        setter=self.set_max_frequency,
                        setter_params={'core': cluster},
                        description="""
                        The maximum frequency for the {} cluster
                        """.format(cluster))
                param_name = '{}_min_frequency'.format(cluster)
                self._runtime_params[param_name] = \
                    RuntimeParameter(
                        param_name, kind=freq_val,
                        setter=self.set_min_frequency,
                        setter_params={'core': cluster},
                        description="""
                        The minimum frequency for the {} cluster
                        """.format(cluster))
                param_name = '{}_governor'.format(cluster)
                self._runtime_params[param_name] = \
                    RuntimeParameter(
                        param_name, kind=str,
                        allowed_values=avail_govs,
                        setter=self.set_governor,
                        setter_params={'core': cluster},
                        description="""
                        The governor to be set for the {} cores
                        """.format(cluster))
                param_name = '{}_gov_tunables'.format(cluster)
                self._runtime_params[param_name] = \
                    RuntimeParameter(
                        param_name, kind=dict,
                        setter=self.set_governor_tunables,
                        setter_params={'core': cluster},
                        merge=True,
                        description="""
                        The governor tunables to be set for the {} cores
                        """.format(cluster))
Пример #10
0
    def initialize(self):
        # pylint: disable=too-many-statements
        if not self.target.has('cpufreq'):
            return

        self._retrive_cpufreq_info()
        _, common_freqs, common_gov = self._get_common_values()

        # Add common parameters if available.
        freq_val = FreqValue(common_freqs)
        param_name = 'frequency'
        self._runtime_params[param_name] = \
            RuntimeParameter(
                param_name, kind=freq_val,
                setter=self.set_frequency,
                setter_params={'core': None},
                description="""
                The desired frequency for all cores
                """)
        param_name = 'max_frequency'
        self._runtime_params[param_name] = \
            RuntimeParameter(
                param_name, kind=freq_val,
                setter=self.set_max_frequency,
                setter_params={'core': None},
                description="""
                The maximum frequency for all cores
                """)
        param_name = 'min_frequency'
        self._runtime_params[param_name] = \
            RuntimeParameter(
                param_name, kind=freq_val,
                setter=self.set_min_frequency,
                setter_params={'core': None},
                description="""
                The minimum frequency for all cores
                """)

        if common_gov:
            param_name = 'governor'
            self._runtime_params[param_name] = \
                RuntimeParameter(
                    param_name, kind=str,
                    allowed_values=common_gov,
                    setter=self.set_governor,
                    setter_params={'core': None},
                    description="""
                    The governor to be set for all cores
                    """)

        param_name = 'governor_tunables'
        self._runtime_params[param_name] = \
            RuntimeParameter(
                param_name, kind=dict,
                merge=True,
                setter=self.set_governor_tunables,
                setter_params={'core': None},
                description="""
                The governor tunables to be set for all cores
                """)

        # Add core name parameters
        for name in unique(self.target.platform.core_names):
            cpu = resolve_unique_domain_cpus(name, self.target)[0]
            freq_val = FreqValue(self.supported_cpu_freqs.get(cpu))
            avail_govs = self.supported_cpu_governors.get(cpu)

            param_name = '{}_frequency'.format(name)
            self._runtime_params[param_name] = \
                RuntimeParameter(
                    param_name, kind=freq_val,
                    setter=self.set_frequency,
                    setter_params={'core': name},
                    description="""
                    The desired frequency for the {} cores
                    """.format(name))
            param_name = '{}_max_frequency'.format(name)
            self._runtime_params[param_name] = \
                RuntimeParameter(
                    param_name, kind=freq_val,
                    setter=self.set_max_frequency,
                    setter_params={'core': name},
                    description="""
                    The maximum frequency for the {} cores
                    """.format(name))
            param_name = '{}_min_frequency'.format(name)
            self._runtime_params[param_name] = \
                RuntimeParameter(
                    param_name, kind=freq_val,
                    setter=self.set_min_frequency,
                    setter_params={'core': name},
                    description="""
                    The minimum frequency for the {} cores
                    """.format(name))
            param_name = '{}_governor'.format(name)
            self._runtime_params[param_name] = \
                RuntimeParameter(
                    param_name, kind=str,
                    allowed_values=avail_govs,
                    setter=self.set_governor,
                    setter_params={'core': name},
                    description="""
                    The governor to be set for the {} cores
                    """.format(name))
            param_name = '{}_gov_tunables'.format(name)
            self._runtime_params[param_name] = \
                RuntimeParameter(
                    param_name, kind=dict,
                    setter=self.set_governor_tunables,
                    setter_params={'core': name},
                    merge=True,
                    description="""
                    The governor tunables to be set for the {} cores
                    """.format(name))

        # Add cpuX parameters.
        for cpu_no in range(self.target.number_of_cpus):
            freq_val = FreqValue(self.supported_cpu_freqs.get(cpu_no))
            avail_govs = self.supported_cpu_governors.get(cpu_no)

            param_name = 'cpu{}_frequency'.format(cpu_no)
            self._runtime_params[param_name] = \
                RuntimeParameter(
                    param_name, kind=freq_val,
                    setter=self.set_frequency,
                    setter_params={'core': cpu_no},
                    description="""
                    The desired frequency for cpu{}
                    """.format(cpu_no))
            param_name = 'cpu{}_max_frequency'.format(cpu_no)
            self._runtime_params[param_name] = \
                RuntimeParameter(
                    param_name, kind=freq_val,
                    setter=self.set_max_frequency,
                    setter_params={'core': cpu_no},
                    description="""
                    The maximum frequency for cpu{}
                    """.format(cpu_no))
            param_name = 'cpu{}_min_frequency'.format(cpu_no)
            self._runtime_params[param_name] = \
                RuntimeParameter(
                    param_name, kind=freq_val,
                    setter=self.set_min_frequency,
                    setter_params={'core': cpu_no},
                    description="""
                    The minimum frequency for cpu{}
                    """.format(cpu_no))
            param_name = 'cpu{}_governor'.format(cpu_no)
            self._runtime_params[param_name] = \
                RuntimeParameter(
                    param_name, kind=str,
                    allowed_values=avail_govs,
                    setter=self.set_governor,
                    setter_params={'core': cpu_no},
                    description="""
                    The governor to be set for cpu{}
                    """.format(cpu_no))
            param_name = 'cpu{}_gov_tunables'.format(cpu_no)
            self._runtime_params[param_name] = \
                RuntimeParameter(
                    param_name, kind=dict,
                    setter=self.set_governor_tunables,
                    setter_params={'core': cpu_no},
                    merge=True,
                    description="""
                    The governor tunables to be set for cpu{}
                    """.format(cpu_no))

        # Add big.little cores if present on device.
        if self.target.has('bl'):
            for cluster in ['big', 'little']:
                cpu = resolve_unique_domain_cpus(cluster, self.target)[0]
                freq_val = FreqValue(self.supported_cpu_freqs.get(cpu))
                avail_govs = self.supported_cpu_governors.get(cpu)
                param_name = '{}_frequency'.format(cluster)

                self._runtime_params[param_name] = \
                    RuntimeParameter(
                        param_name, kind=freq_val,
                        setter=self.set_frequency,
                        setter_params={'core': cluster},
                        description="""
                        The desired frequency for the {} cluster
                        """.format(cluster))
                param_name = '{}_max_frequency'.format(cluster)
                self._runtime_params[param_name] = \
                    RuntimeParameter(
                        param_name, kind=freq_val,
                        setter=self.set_max_frequency,
                        setter_params={'core': cluster},
                        description="""
                        The maximum frequency for the {} cluster
                        """.format(cluster))
                param_name = '{}_min_frequency'.format(cluster)
                self._runtime_params[param_name] = \
                    RuntimeParameter(
                        param_name, kind=freq_val,
                        setter=self.set_min_frequency,
                        setter_params={'core': cluster},
                        description="""
                        The minimum frequency for the {} cluster
                        """.format(cluster))
                param_name = '{}_governor'.format(cluster)
                self._runtime_params[param_name] = \
                    RuntimeParameter(
                        param_name, kind=str,
                        allowed_values=avail_govs,
                        setter=self.set_governor,
                        setter_params={'core': cluster},
                        description="""
                        The governor to be set for the {} cores
                        """.format(cluster))
                param_name = '{}_gov_tunables'.format(cluster)
                self._runtime_params[param_name] = \
                    RuntimeParameter(
                        param_name, kind=dict,
                        setter=self.set_governor_tunables,
                        setter_params={'core': cluster},
                        merge=True,
                        description="""
                        The governor tunables to be set for the {} cores
                        """.format(cluster))