powertop 커맨드는 네트워크 카드의 상태 모니터링 뿐 아니라, c-state로 들어갈 지 여부를 설정할 수 있다. 

또한 정보를 csv로 사용할 수 있다.


c-state는 Intel에서 만든 전원 상태를 관리할 수 있는 방법이라 할 수 있다. cpu 내부에서 사용중이면 활성화하고 사용 중이 아니라면 낮은 성능을 유지시켜 전원을 낮게 쓰게 하는 효율적으로 유지한다. 


아래 링크의 공식 문서(Controlling Processor C-StateUsage in Linux)에 따르면 설명이 되어 있다. 




while it does save power, it takes time to enter and exit C-states. Generally the higher theC-state, more power is saved when the processor is idle, but it takes longer to get the CPU back upagain when it is needed. The C-states are:


C0 The CPU is actively running code


C1 The CPU uses the HLT instruction when idle-the clock is gated off to parts of the core, but it is relatively quick to wake up


C1E This is actually just C1, except when C1E is enabled, the CPU lowers the CPU’s speed & voltage when it is in C1


C2 & up The CPU will shut off various parts of the core for greater power savings, at thecost of taking longer to wake up


In most Linux distributions today, C-states are enabled by default, which is great for most users. Theoperating system will choose which C-state to use based on processor utilization and other factors.Some users, though, want very low latency, and are very sensitive to how quickly a CPU can run codewhen needed, so user control is desired.



문제는 c-state 상태를 intel cpu가 마음대로 결정하는 것이 default 설정이라서, 서비스 장비의 네트워크 카드까지 idle로 만들 수 있다는 점이다. 잠깐 쉬고 있는 것이지 아예 안쓰는 것은 아니라서..


그래서 자바 애플리케이션 서버에서 다음과 같은 에러를 발생한다.


java.net.UnknownHostException: googleplus001: unknown error
    at java.net.InetAddress.getLocalHost(InetAddress.java:1505)



c-state가 적용되지 않게 하려면 다음을 설정한다. 아래 링크의 공식 문서(Controlling Processor C-StateUsage in Linux)대로 진행한다. 


if you want control over C-states, or if your system might have CPUs that are newerthan the version of intel_idle in your kernel, you should use kernel parameter "intel_idle.max_cstate=0" to disable this driver.


커널 매개 변수로 intel_idle.max_cstate=0을 적용한다. 

grub 파일을 쓰고 있다면, /boot/grub/grub.conf 파일에 intel_idle.max_cstate=0를 설정하고 재시작한다. 

기존에 어떻게 동작하고 있었는지 보려면 grep idle /var/log/messages를 실행한다. 




그러면 항상 cpu에서는 모든 프로세스를 c0 상태로 두게 될 것이다. (acpi_idle 모듈이 사용됨을 의미한다)



부팅후에는 아래 커맨드로 확인해서 정상적으로 적용되었는지 확인한다.  (디폴트 값도 확인할 수 있다)


$ dmesg | grep -i intel_idle


acpi_idle이 동작되는지 살펴보면 다음과 같다. 


$ cat /proc/acpi/processor/CPU0/power

active state:            C0

max_cstate:              C1

maximum allowed latency: 2000000000 usec

states:






powertop 설치와 사용 방법은 다음과 같다. 


$ yum install powertop


su 사용자이거나 sudo를 사용해 실행한다.

$ sudo powertop


탭 간 이동은 tab을 이용하고 종료는 q를 누른다. idle 상태를 확인한다. 




Idle stat을 보면 C0로 되어 있는지 여부를 확인할 수 있다. 











여기서 Bad는 실제 c-state과 관련된 설정임을 의미한다. 나쁘다는 의미는 아니다. 



참고 


http://www.tecmint.com/powertop-monitors-linux-laptop-battery-usage/


https://www.scribd.com/document/132381013/Controlling-Processor-C-State-Usage-in-Linux-Nov2012


https://events.linuxfoundation.org/slides/2010/linuxcon2010_brown.pdf



Posted by '김용환'
,