Linux와 C-State관리

1.
지난 한주동안 HP서버를 열심히 튜닝하였습니다. 공장 출시한 값으로 설정한 서버를 Low Latency Server로 바꾸는 일이죠. 문서는 HP에서 나온 문서입니다.

Configuring and Tuning HP ProLiant Servers for Low-Latency Applications

오래전 BIOS 설정을 할 때 C3-State관리가 중요하다는 사실을 알고 있기 때문에 BIOS설정을 먼저 하였습니다.

BIOS 셋팅과 레이턴시

그런데 HP문서를 보면서 C State를 BIOS뿐 아니라 커널에서도 설정을 해준다는 사실을 처음 알았습니다. 이 문장입니다.

Edit /boot/grub/grub.conf and add “nosoftlockup intel_idle.max_cstate=0 mce=ignore_ce” to the kernel line

nosoftlockup prevents RHEL from logging an event when a high-priority thread executes continuously on a core for longer than the soft lockup threshold. intel_idle.max_cstate=0 prevents the kernel from overriding the BIOS C-state setting. mce=ignore_ce prevents Linux from initiating a poll every five minutes of the Machine Check Banks for correctable errors, which can cause latency spikes.

2.
HP서버만 해당하는지 조사를 해보니 Dell 서버도 같았습니다. Controlling Processor C-State Usage in Linux라는 제목으로 자료까지 내었더군요. 아주 상세히 설명해놓은 자료입니다.

Download (PDF, 344KB)

그런데 설정을 해놓고 실제로 어떻게 동작하는지를 확인하여야 합니다. 이를 위해 도움을 주는 것이 PowerTOP입니다. Intel이 개발하여 공급하는 오픈소스 프로그램입니다.

PowerTOP

가장 최근 버전으로 설치하시려면 위에서 프로그램 소스를 받아서 컴파일을 하시면 됩니다. CentOS에서 그냥 패키지를 설치하시려면 아래와 같이 하시면 됩니다. 그러면 1.11버전이 깔립니다. 좀더 자세한 정보를 알고 싶으면 RedHat의 PowerTOP을 참고하세요.

ZeroAOS의 개발서버에 설치를 해서 실행을 시켜보았습니다. 아래와 같습니다.

powertop

튜닝을 하지 않은 상태입니다. C3 State의 비중이 앞도적입니다. 만약 매매중이라고 하면 High Latency입니다. wakeup을 많이 일으키는 프로세스를 확인해보았습니다. Ztermsvr입니다. ZTerminal로부터의 Request를 처리하는 서버입니다. 구조적으로 개선하여야 합니다.

왜 C-State관리가 중요할까요?

위의 그림을 보시면 C3(C4) State는 L1/L2 메모리를 깨끗히 청소하고 – L2는 일부 – CPU동작을 멈춥니다. 다시 동작을 하도록 하여 C0으로 가려면 wakeup time이 필요합니다. 이에 대한 설명을 하는 자료입니다.

On a typical processor, C1 will just turn off the processor clock, while C2 turns off other clocks in the system and C3 will actively power down parts of the CPU. On such a system, it would make sense to spend as much time as possible in the C3 state; indeed, while this sentence is being typed, the system is in C3 about 97% of the time. One might have thought that emacs could do a better job of hogging the CPU, but even emacs is no challenge for modern processors. The C1 state is not used at all, while a small amount of time is spent in C2.

One might wonder why the system bothers with anything but C3 at all; why not insist on the most nothing for the buck? The answer, of course, is that C3 has a cost. The 57µs exit latency means that the system must commit to doing nothing for a fair while. Bringing the processor back up also consumes power in its own right, and the ancillary costs – the C3 state might cause the flushing of the L2 cache – also hurt. So it’s only worth going into C3 if the power savings will be real and if the system knows that it will not have to respond to anything with less than 57µs latency. If those conditions do not hold, it makes more sense to use a different idle state. Making that decision is the cpuidle subsystem’s job.
The cpuidle subsystem중에서

그러면 구체적인 Wakeup Time은 얼마일까요? 위의 사례는 57마이크로초라고 했습니다. 개발서버에서 아래와 같이 해서 확인해보았습니다.

위의 숫자는 Exit Latency입니다. C-State를 관리하지 않으면 그 만큼 손해를 봅니다. 이번 경험을 보면 C-State를 설정하기전과 한 후를 비교하면 1/2로 줄어들었습니다.

참고로 어떤 이의 실험결과를 소개합니다. 다양한 실험을 하였습니다.

cpu_dma_latency를 이용하여 C-State를 관리한 경우입니다.

Leave a Comment

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다

이 사이트는 스팸을 줄이는 아키스밋을 사용합니다. 댓글이 어떻게 처리되는지 알아보십시오.