Skip to the content.

sysfs cpu

/sys/devices/system/cpu

drivers/base/cpu.c 中的:

static struct attribute *cpu_root_attrs[] = {
#ifdef CONFIG_ARCH_CPU_PROBE_RELEASE
	&dev_attr_probe.attr,
	&dev_attr_release.attr,
#endif
	&cpu_attrs[0].attr.attr,
	&cpu_attrs[1].attr.attr,
	&cpu_attrs[2].attr.attr,
	&dev_attr_kernel_max.attr,
	&dev_attr_offline.attr,
	&dev_attr_enabled.attr,
	&dev_attr_isolated.attr,
#ifdef CONFIG_NO_HZ_FULL
	&dev_attr_nohz_full.attr,
#endif
#ifdef CONFIG_CRASH_HOTPLUG
	&dev_attr_crash_hotplug.attr,
#endif
#ifdef CONFIG_GENERIC_CPU_AUTOPROBE
	&dev_attr_modalias.attr,
#endif
	NULL
};
/* Keep in sync with cpu_subsys_attrs */
static struct cpu_attr cpu_attrs[] = {
	_CPU_ATTR(online, &__cpu_online_mask),
	_CPU_ATTR(possible, &__cpu_possible_mask),
	_CPU_ATTR(present, &__cpu_present_mask),
};

和这些都是可以完整的对应上的:

[!NOTE] 参考神奇海螺的意见,有待验证

(不过根据文档生成的,精度应该还可以的)

 cup0

(常规内容)

(有意思,但是现在不看)

  1. 接口路径: /sys/devices/system/cpu/cpu/cpuidle/state/ (其中 N 是 CPU 编号,M 是空闲状态编号)
    • above: 此空闲状态被请求但观察到的空闲时间肯定短于其目标驻留时间的次数。
    • below: 此空闲状态被请求但观察到的空闲时间肯定更适合更深状态的次数。
    • desc: 空闲状态的描述。
    • disable: 是否禁用此空闲状态。
    • default_status: 此状态的默认状态 (“enabled” 或 “disabled”)。
    • latency: 空闲状态的退出延迟(微秒)。
    • name: 空闲状态的名称。
    • power: (文档截断,可能包含功率相关数据)
    • time: CPU 在此空闲状态花费的总时间(纳秒)。
    • usage: 此空闲状态被请求的总次数。
  2. Intel 性能与能耗偏置提示 (Intel EPB - Energy Performance Bias) 接口路径: /sys/devices/system/cpu/cpu/power/ (其中 N 是 CPU 编号)
    • energy_perf_bias: 显示或设置此 CPU 的 EPB 值(0-15 数字或字符串),用于指示性能/能耗偏好。
  3. thermal_throttle 下的
    •  core_throttle_count
    •  core_throttle_max_time_ms
    •  core_throttle_total_time_ms
    •  package_throttle_count
    •  package_throttle_max_time_ms
    •  package_throttle_total_time_ms

[!NOTE] 参考神奇海螺的意见,有待验证

(似乎是这么回事)

 cpufreq

 cpuidle

全局 CPUIdle 接口路径

 intel_pstate

 intel_uncore_frequency

Intel Uncore 频率调节 (Intel Uncore Frequency Scaling)

 umwait_control

enable_c02 max_time

关联文件 arch/x86/kernel/cpu/umwait.c

和电源无关的内容,可以后面再说吧:

常用的总结

cat /sys/devices/system/cpu/cpufreq/policy0/scaling_driver cat /sys/devices/system/cpu/cpuidle/current_driver

问题?

thread_siblings_list

/sys/devices/system/node/node7/cpu255/topology/thread_siblings_list

怎么还有 node 的这个路径啊

cpupower frequency-info current policy 中的频率输出来自于哪里

  current policy: frequency should be within 4.00 GHz and 4.00 GHz.
                  The governor "performance" may decide which speed to use
                  within this range.

这个 4G ~ 4G 的原因是这个导致的:

🧀  grep . *
affected_cpus:0
cpuinfo_avg_freq:3997731
cpuinfo_max_freq:4000000
cpuinfo_min_freq:800000
cpuinfo_transition_latency:20000
related_cpus:0
scaling_available_governors:conservative ondemand userspace powersave performance schedutil
scaling_cur_freq:3997731
scaling_driver:intel_cpufreq
scaling_governor:powersave
scaling_max_freq:4000000
scaling_min_freq:4000000
scaling_setspeed:<unsupported>

类似的:

cpu/cpufreq/policy0🔒 🦆
🧀  sudo cpupower frequency-info
[sudo] password for martins3:
analyzing CPU 0:
  driver: intel_cpufreq
  CPUs which run at the same hardware frequency: 0
  CPUs which need to have their frequency coordinated by software: 0
  maximum transition latency: 20.0 us
  hardware limits: 800 MHz - 4.00 GHz
  available cpufreq governors: conservative ondemand userspace powersave performance schedutil
  current policy: frequency should be within 4.00 GHz and 4.00 GHz.
                  The governor "performance" may decide which speed to use
                  within this range.
  current CPU frequency: Unable to call hardware
  current CPU frequency: 3.59 GHz (asserted by call to kernel)
  boost state support:
    Supported: yes
    Active: yes

从这里发现可以频率就是从 800M 到 4G :

🧀  grep . *
affected_cpus:0
cpuinfo_avg_freq:3996068
cpuinfo_max_freq:4000000
cpuinfo_min_freq:800000
cpuinfo_transition_latency:20000
related_cpus:0
scaling_available_governors:conservative ondemand userspace powersave performance schedutil
scaling_cur_freq:3996068
scaling_driver:intel_cpufreq
scaling_governor:performance
scaling_max_freq:4000000
scaling_min_freq:4000000
scaling_setspeed:<unsupported>

这里就没有进一步追究这个sysfs 下面的实现了 感觉都很随意的,对实际没有什么参考价值。

cpupower frequency-info 输出 Unable to call hardware 的含义

🧀  sudo cpupower frequency-info
[sudo] password for martins3:
analyzing CPU 0:
  driver: intel_cpufreq
  CPUs which run at the same hardware frequency: 0
  CPUs which need to have their frequency coordinated by software: 0
  maximum transition latency: 20.0 us
  hardware limits: 800 MHz - 4.00 GHz
  available cpufreq governors: conservative ondemand userspace powersave performance schedutil
  current policy: frequency should be within 4.00 GHz and 4.00 GHz.
                  The governor "performance" may decide which speed to use
                  within this range.
  current CPU frequency: Unable to call hardware
  current CPU frequency: 3.52 GHz (asserted by call to kernel)
  boost state support:
    Supported: yes
    Active: yes

是看是否存在这个 sysfs 接口

/sys/devices/system/cpu/cpufreq/policy53/cpuinfo_cur_freq
/sys/devices/system/cpu/cpufreq/policy81/cpuinfo_cur_freq

而 sysfs 下是否会提供这个接口, 具体实现在 cpufreq_add_dev_interface 中:

	if (cpufreq_driver->get) {
		ret = sysfs_create_file(&policy->kobj, &cpuinfo_cur_freq.attr);
		if (ret)
			return ret;
	}

本站所有文章转发 CSDN 将按侵权追究法律责任,其它情况随意。