EAS调度器之能量模型(EM)

 (本文内容来自于8450的kernel文档:/kernel_platform/msm-kernel/Documentation/power/energy-model.rst)

目录

概述

核心API

配置选项

性能域(performance domains)的注册

访问性能域 

驱动实例代码


概述

        EM(Energy Model)框架作为驱动与kernel的一个接口在两者之间起到了桥梁的作用,在驱动部分可以计算出不同的性能级别消耗的能量,在kernel那些对关注能量消耗的子系统中,可以使用这些信息。

        在不同的设备中,关于设备能量的消耗的来源可能有很大的不同。在某些情况下,这些能量消耗可以使用devicetree中的数据进行计算,而在另外的情况下可能firmware能够更好知道消耗了多少的能量。为了避免每个客户端子系统重新实现对每个可能的信息源的支持,EM框架作为抽象层进行干预,标准化内核中的电力成本表的格式,从而避免冗余工作。

        下图描述了为EM框架提供电力成本的驱动程序(此处为Arm特定,但该方法适用于任何架构)以及从中读取数据的感兴趣客户端的示例:

         对于CPU设备,EM框架管理系统中每个“性能域”的电力成本表,性能域是一组性能可以一起扩展的CPU。性能域通常与CPUFreq策略有一对一的映射,性能域中的所有CPU都需要具有相同的微架构,不同性能域中的CPU可以具有不同的微架构。

1. Overview
-----------

The Energy Model (EM) framework serves as an interface between drivers knowing
the power consumed by devices at various performance levels, and the kernel
subsystems willing to use that information to make energy-aware decisions.

The source of the information about the power consumed by devices can vary greatly
from one platform to another. These power costs can be estimated using
devicetree data in some cases. In others, the firmware will know better.
Alternatively, userspace might be best positioned. And so on. In order to avoid
each and every client subsystem to re-implement support for each and every
possible source of information on its own, the EM framework intervenes as an
abstraction layer which standardizes the format of power cost tables in the
kernel, hence enabling to avoid redundant work.

The figure below depicts an example of drivers (Arm-specific here, but the
approach is applicable to any architecture) providing power costs to the EM
framework, and interested clients reading the data from it::

       +---------------+  +-----------------+  +---------------+
       | Thermal (IPA) |  | Scheduler (EAS) |  |     Other     |
       +---------------+  +-----------------+  +---------------+
               |                   | em_cpu_energy()   |
               |                   | em_cpu_get()      |
               +---------+         |         +---------+
                         |         |         |
                         v         v         v
                        +---------------------+
                        |    Energy Model     |
                        |     Framework       |
                        +---------------------+
                           ^       ^       ^
                           |       |       | em_dev_register_perf_domain()
                +----------+       |       +---------+
                |                  |                 |
        +---------------+  +---------------+  +--------------+
        |  cpufreq-dt   |  |   arm_scmi    |  |    Other     |
        +---------------+  +---------------+  +--------------+
                ^                  ^                 ^
                |                  |                 |
        +--------------+   +---------------+  +--------------+
        | Device Tree  |   |   Firmware    |  |      ?       |
        +--------------+   +---------------+  +--------------+

In case of CPU devices the EM framework manages power cost tables per
'performance domain' in the system. A performance domain is a group of CPUs
whose performance is scaled together. Performance domains generally have a
1-to-1 mapping with CPUFreq policies. All CPUs in a performance domain are
required to have the same micro-architecture. CPUs in different performance
domains can have different micro-architectures.

核心API

配置选项

        使用EM框架必须打开编译配置 CONFIG_ENERGY_MODEL

性能域(performance domains)的注册

        驱动程序应通过以下方式将性能域注册到EM框架中

  int em_dev_register_perf_domain(struct device *dev, unsigned int nr_states,
		struct em_data_callback *cb, cpumask_t *cpus);

        驱动程序必须为每个性能状态提供返回<frequency,power>元组的回调函数。驱动程序提供的回调函数可以自由地从任何相关位置(DT、固件等)获取数据,并且可以通过任何必要的方式获取数据。仅对于CPU设备,驱动程序必须使用cpumask指定性能域的CPU。对于CPU以外的其他设备,最后一个参数必须设置为NULL。

        有关实现此回调的驱动程序和kernel/power/energy_model.c的示例,请参见第3节。

访问性能域 

        有两个API函数提供了对能量模型的访问:em_cpu_get()以cpu id为参数,em_pd_get()以设备指针为参数。这取决于它将使用哪个接口的子系统,但在CPU设备的情况下,两个功能都返回相同的性能域。

        对CPU能量模型感兴趣的子系统可以使用em_CPU_get()API检索它,能量模型表在创建性能域时被分配一次,并保持在内存中不变。

        可以使用em_cpu_energy()API估计性能域所消耗的能量。在CPU设备的情况下,假设使用schedutil CPUfreq调节器进行估计。目前,没有为其他类型的设备提供此计算。

        有关上述API的更多详细信息,请参见include/linux/energy_model.h。

2. Core APIs
------------

2.1 Config options
^^^^^^^^^^^^^^^^^^

CONFIG_ENERGY_MODEL must be enabled to use the EM framework.


2.2 Registration of performance domains
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Drivers are expected to register performance domains into the EM framework by
calling the following API::

  int em_dev_register_perf_domain(struct device *dev, unsigned int nr_states,
		struct em_data_callback *cb, cpumask_t *cpus);

Drivers must provide a callback function returning <frequency, power> tuples
for each performance state. The callback function provided by the driver is free
to fetch data from any relevant location (DT, firmware, ...), and by any mean
deemed necessary. Only for CPU devices, drivers must specify the CPUs of the
performance domains using cpumask. For other devices than CPUs the last
argument must be set to NULL.
See Section 3. for an example of driver implementing this
callback, and kernel/power/energy_model.c for further documentation on this
API.


2.3 Accessing performance domains
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

There are two API functions which provide the access to the energy model:
em_cpu_get() which takes CPU id as an argument and em_pd_get() with device
pointer as an argument. It depends on the subsystem which interface it is
going to use, but in case of CPU devices both functions return the same
performance domain.

Subsystems interested in the energy model of a CPU can retrieve it using the
em_cpu_get() API. The energy model tables are allocated once upon creation of
the performance domains, and kept in memory untouched.

The energy consumed by a performance domain can be estimated using the
em_cpu_energy() API. The estimation is performed assuming that the schedutil
CPUfreq governor is in use in case of CPU device. Currently this calculation is
not provided for other type of devices.

More details about the above APIs can be found in include/linux/energy_model.h.

驱动实例代码

        本节提供了一个使用(fake)“foo”协议在Energy Model框架中注册性能域的CPUFreq驱动程序的简单示例。驱动程序实现了要提供给EM框架的est_power()函数:


  -> drivers/cpufreq/foo_cpufreq.c

  01	static int est_power(unsigned long *mW, unsigned long *KHz,
  02			struct device *dev)
  03	{
  04		long freq, power;
  05
  06		/* Use the 'foo' protocol to ceil the frequency */
  07		freq = foo_get_freq_ceil(dev, *KHz);
  08		if (freq < 0);
  09			return freq;
  10
  11		/* Estimate the power cost for the dev at the relevant freq. */
  12		power = foo_estimate_power(dev, freq);
  13		if (power < 0);
  14			return power;
  15
  16		/* Return the values to the EM framework */
  17		*mW = power;
  18		*KHz = freq;
  19
  20		return 0;
  21	}
  22
  23	static int foo_cpufreq_init(struct cpufreq_policy *policy)
  24	{
  25		struct em_data_callback em_cb = EM_DATA_CB(est_power);
  26		struct device *cpu_dev;
  27		int nr_opp, ret;
  28
  29		cpu_dev = get_cpu_device(cpumask_first(policy->cpus));
  30
  31     	/* Do the actual CPUFreq init work ... */
  32     	ret = do_foo_cpufreq_init(policy);
  33     	if (ret)
  34     		return ret;
  35
  36     	/* Find the number of OPPs for this policy */
  37     	nr_opp = foo_get_nr_opp(policy);
  38
  39     	/* And register the new performance domain */
  40     	em_dev_register_perf_domain(cpu_dev, nr_opp, &em_cb, policy->cpus);
  41
  42	        return 0;
  43	}

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值