Print
카테고리: [ Operating System ]
조회수: 6645

1. 개요

실행중인 프로세스나 프로그램을 특정 CPU core에 bind시켜주는 OS 기능이 있다. 

Cache Binding 작업이 많은 프로그램을 실행시킬 때 각각의 CPU를 분리하여 할당함으로써 CPU의 Cache Miss를 줄일 수도 있다고 한다.

 

2. CPU Affinity 적용 명령어 

 1) taskset 명령어

  -> 리눅스에서 프로그램이나 프로세스에 특정 CPU코어를 할당할때는 taskset이라는 명령어를 사용할 수 있다.

=====================================================================================

NAME
taskset - retrieve or set a process's CPU affinity

SYNOPSIS
taskset [options] mask command [arg]...
taskset [options] -p [mask] pid

DESCRIPTION
taskset is used to set or retrieve the CPU affinity of a running process given its PID or to launch a new COMMAND
with a given CPU affinity. CPU affinity is a scheduler property that "bonds" a process to a given set of CPUs on
the system. The Linux scheduler will honor the given CPU affinity and the process will not run on any other CPUs.
Note that the Linux scheduler also supports natural CPU affinity: the scheduler attempts to keep processes on the
same CPU as long as practical for performance reasons. Therefore, forcing a specific CPU affinity is useful only
in certain applications.

The CPU affinity is represented as a bitmask, with the lowest order bit corresponding to the first logical CPU and
the highest order bit corresponding to the last logical CPU. Not all CPUs may exist on a given system but a mask
may specify more CPUs than are present. A retrieved mask will reflect only the bits that correspond to CPUs phys‐
ically on the system. If an invalid mask is given (i.e., one that corresponds to no valid CPUs on the current
system) an error is returned. The masks are typically given in hexadecimal. For example,

0x00000001
is processor #0

0x00000003
is processors #0 and #1

0xFFFFFFFF
is all processors (#0 through #31).

When taskset returns, it is guaranteed that the given program has been scheduled to a legal CPU.

=====================================================================================

 

2) 실행중인 프로세스에 적용된 CPU Affinity 확인

$ taskset -p <pid>

 

3) 실행중인 프로세스가 사용할 CPU 지정

  : -c 옵션은 cpu core 넘버 지정 옵션

$ taskset -p <COREMASK> <PID>
$ taskset -cp <CORE-LIST> <PID>

 

4) 프로그램 실행 시 특정 CPU core 지정하여 실행

$ taskset <COREMASK> <EXECUTABLE>
$ taskset 0x1 vlc
   : vlc프로그램을 0번 코어에 지정하여 실행

 

5) 예시 : WAS 기동 시 0번 core 지정 (현재 경로 하위의 start.sh 이 WAS 기동 스크립트라고 가정) 

$ taskset -c 0 ./start.sh 

  top 명령어 수행 후  1 입력하여 core 별 CPU 사용률 확인