0. Overview

There are various power modes of the CPU which are determined based on their current usage and are collectively called “C-states” or “C-modes.” With CPU C-states, the CPU can enter the idle status to optimize energy consumption.

The CPU has a different C-state, and the deeper state means more energy saving. To save power/energy, stop the CPU clock and circuits. ie., so when CPU moving to the work(C0) state from idle state(Cx), it needs more switch time. The deeper the state, the more switch time is needed.

The CPU will switch the state from running to idle automatically, so when the fast path (lower latency) application has bound to the CPU, the application shall keep the busy state (ex: busy-loop) to avoid the state switch of the CPU, and for the slow path (no high require for latency), the application can allow the CPU wake up from idle to running for service.

1. CPU C-states

1.1 Enable CPU C-states

To enable the CPU C-state, an operator can set the max_cstate during BIOS installation. Take an example:

// server 1
# cat /sys/module/intel_idle/parameters/max_cstate
9 // server 2
# cat /sys/module/intel_idle/parameters/max_cstate
0

Let's see, server 1 has enabled a max 9 C-state, and server 2 has set no CPU C-state supported.

Note: It's an example of setting the C-state, more detailed information can refer to the CPU C-states

1.2 CPU C-states latency

We can also read the latency from cpu_dma_latency as:

// server 1
# hexdump -C /dev/cpu_dma_latency
00000000  00 94 35 77                                       |..5w|
00000004
# echo $(( 0x77359400 ))
2000000000 // server 2
# hexdump -C /dev/cpu_dma_latency
00000000 01 00 00 00 |....|
00000004
# echo $(( 0x00000001 ))
1

Here server 1 has 2000 seconds latency(from idle to C0 running state), and server 2 has 1 microsecond latency.

1.3 CPU C-states monitor

The cpupower-monitor can monitor the CPU processor and report processor frequency and idle statistics, for example:

# cpupower monitor
    | Nehalem                   || Mperf              || Idle_Stats
 CPU| C3   | C6   | PC3  | PC6   || C0   | Cx   | Freq  || POLL | C1   | C1E  | C6
   0|  0.00|  0.00|  0.00|  0.00||  0.53| 99.47|  2084||  0.00|  0.01| 99.52|  0.00
  24|  0.00|  0.00|  0.00|  0.00||  0.26| 99.74|  2252||  0.00|  0.24| 99.51|  0.00
   1|  0.00|  0.00|  0.00|  0.00||  0.33| 99.67|  2422||  0.00|  0.00| 99.67|  0.00
  25|  0.00|  0.00|  0.00|  0.00||  0.90| 99.10|  2580||  0.01|  0.26| 98.91|  0.00
   2|  0.00|  0.00|  0.00|  0.00||  0.20| 99.80|  1810||  0.00|  0.00| 99.81|  0.00
  26|  0.00|  0.00|  0.00|  0.00||  0.84| 99.16|  2867||  0.01|  0.29| 98.88|  0.00
   3|  0.00|  0.00|  0.00|  0.00||  0.83| 99.17|  2686||  0.01|  0.55| 98.66|  0.00
  27|  0.00|  0.00|  0.00|  0.00||  1.47| 98.53|  2979||  0.00|  0.00| 98.53|  0.00
   4|  0.00|  0.00|  0.00|  0.00||  0.40| 99.60|  1914||  0.00|  0.02| 99.66|  0.00
  28|  0.00|  0.00|  0.00|  0.00||  1.61| 98.39|  2995||  0.00|  0.00| 98.39|  0.00
   5|  0.00|  0.00|  0.00|  0.00||  0.73| 99.27|  2527||  0.00|  0.29| 99.03|  0.00

There are three monitors Nehalem, Mperf and Idle_Stats has monitor the process information. From the report, we can see that most CPUs are in the C1E idle state.

To make the CPU switch to a running(C0) state, we can use stress to make a trial, after stress the CPU load is higher and higher, the more CPUs will switch from the C1E idle state to C0, the detailed information as the CPU C-states.

1.4 CPU C-states driver

To enable the CPU C-states, the hardware driver acpi_idle or intel_idle is needed.

  • "acpi_idle" cpuidle driver: The acpi_idle cpuidle driver retrieves available sleep states (C-states) from the ACPI BIOS tables (from the _CST ACPI function on recent platforms or from the FADT BIOS table on older ones). The C1 state is not retrieved from ACPI tables. If the C1 state is entered, the kernel will call the hlt instruction (or mwait on Intel).
  • "intel_idle" cpuidle driver: In kernel 2.6.36 the intel_idle driver was introduced. It only serves recent Intel CPUs (Nehalem, Westmere, Sandybridge, Atoms or newer). On older Intel CPUs the acpi_idle driver is still used (if the BIOS provides C-state ACPI tables). The intel_idle driver knows the sleep state capabilities of the processor and ignores ACPI BIOS exported processor sleep states tables.

To Check the cpuidle driver from /sys/devices/system/cpu/cpuidle/current_driver as:

// server 1
# cat /sys/devices/system/cpu/cpuidle/current_driver
intel_idle // server 2
# cat /sys/devices/system/cpu/cpuidle/current_driver
acpi_idle

2. Reference


Linux: CPU C-states的更多相关文章

  1. Understanding Linux CPU stats

    Your Linux server is running slow, so you follow standard procedure and run top. You see the CPU met ...

  2. Linux CPU亲缘性详解

    前言 在淘宝开源自己基于nginx打造的tegine服务器的时候,有这么一项特性引起了笔者的兴趣.“自动根据CPU数目设置进程个数和绑定CPU亲缘性”.当时笔者对CPU亲缘性没有任何概念,当时作者只是 ...

  3. 查看线程linux cpu使用率

    Linux下如何查看高CPU占用率线程 LINUX CPU利用率计算 转 http://www.cnblogs.com/lidabo/p/4738113.html目录(?)[-] proc文件系统 p ...

  4. Linux CPU数量判断,通过/proc/cpuinfo.

    Linux CPU数量判断,通过/proc/cpuinfo. 相同 physical id :决定一个物理处理器 如果“siblings”和“cpu cores”一致,则说明不支持超线程,或者超线程未 ...

  5. How do I Find Out Linux CPU Utilization?

    From:http://www.cyberciti.biz/tips/how-do-i-find-out-linux-cpu-utilization.html Whenever a Linux sys ...

  6. Linux CPU监控指标

    Linux CPU监控指标 Linux提供了非常丰富的命令可以进行CPU相关数据进行监控,例如:top.vmstat等命令.top是一个动态显示过程,即可以通过用户按键来不断刷新当前状态.如果在前台执 ...

  7. 转载: 一、linux cpu、内存、IO、网络的测试工具

    来源地址: http://blog.csdn.net/wenwenxiong/article/details/77197997 记录一下 以后好找.. 一.linux cpu.内存.IO.网络的测试工 ...

  8. Linux CPU使用率含义及原理

    相关概念 在Linux/Unix下,CPU利用率分为用户态.系统态和空闲态,分别表示CPU处于用户态执的时间,系统内核执行的时间,和空闲系统进程执行的时间. 下面是几个与CPU占用率相关的概念. CP ...

  9. Linux CPU Load Average

    理解Linux系统负荷 LINUX下CPU Load Average的一点研究 Linux load average负载量分析与解决思路 Understanding Linux CPU Load - ...

  10. 理解Linux CPU负载和 CPU使用率

    CPU负载和 CPU使用率 这两个从一定程度上都可以反映一台机器的繁忙程度. cpu使用率反映的是当前cpu的繁忙程度,忽高忽低的原因在于占用cpu处理时间的进程可能处于io等待状态但却还未释放进入w ...

随机推荐

  1. 使用CEF(七)详解macOS下基于CEF的多进程应用程序CMake项目搭建

    由于macOS下的应用程序结构导致了CEF这样的多进程架构程序在项目结构.运行架构上有很多细节需要关注,这一块的内容比起Windows要复杂的多,所以本文将会聚焦macOS下基于CEF的多进程应用架构 ...

  2. 好家伙,这个开源项目硬生生复制了一个 ChatGPT Plus 出来

    最近有一款聊天机器人框架 Lobe Chat 火出了天际,它不仅支持多模态,支持语音会话,还有一个强大的 Function Calling 插件生态系统(可以作为 ChatGPT 插件的平替).最重要 ...

  3. 华企盾DSC控制台无法登录常见处理方法

    1.查看服务器服务是否正常运行 2.服务器电脑的防火墙关闭了 3.telnet服务器IP和端口(服务器端口和数据库端口)是否是通的 4.如果是外网需要再控制台安装目录改setting配置文件 5.my ...

  4. ElasticSearch之cat datafeeds API

    命令样例如下: curl -X GET "https://localhost:9200/_cat/ml/datafeeds?v=true&pretty" --cacert ...

  5. Python中的协程、线程和进程

    一.协程与多线程和多进程一起使用有什么不同   协程.多线程和多进程都是实现程序并发执行的方法,不过它们在工作方式和适合的应用场景上存在一些区别. 1.协程(Coroutine)   协程是在单一线程 ...

  6. SpringBoot结合ajax实现登录功能

    1:ajax是什么(https://www.w3school.com.cn/ajax/ajax_intro.asp)? AJAX 是一种在无需重新加载整个网页的情况下,能够更新部分网页的技术. AJA ...

  7. 【开源项目】轻量元数据管理解决方案——Marquez

    大家好,我是独孤风. 又到了本周的开源项目推荐.最近推荐的元数据管理项目很多,但是很多元数据管理平台的功能复杂难用. 那么有没有轻量一点的元数据管理项目呢? 今天为大家推荐的开源项目,就是一个轻量级的 ...

  8. 业务并发度不够,数仓的CN可以来帮忙

    摘要: CN全称协调节点(Coordinator Node),是和用户关系最密切也是DWS内部非常重要的一个组件,它负责提供外部应用接口.优化全局执行计划.向Datanode分发执行计划,以及汇总.处 ...

  9. SDK设计与封装:从基础概念入门到架构设计落地笔记

    什么是 SDK? SDK 全称 Software Development Kit,广义上的 SDK 是为特定的软件包.软件框架.硬件平台.操作系统等建立应用程序时所使用的开发工具的集合(在 iOS 项 ...

  10. nginx网站限速限流配置——网站被频繁攻击,nginx上的设置limit_req和limit_conn

    利用ngx_http_limit_req_module模块,可根据键值(如ip)限制每分钟的速率: limit_req_zone 用来限制单位时间内的请求数,即速率限制,采用的漏桶算法 "l ...