[AIX 성능 도구 5] hpm 라이브러리와 hpmcount·hpmstat·pmlist

핵심 정리

  • hpm 라이브러리는 pmapi 위의 고수준 계측 라이브러리입니다. 코드에 hpmInit → hpmStart(id) … hpmStop(id) → hpmTerminate를 넣으면 구간마다 하드웨어 카운터와 파생 지표를 <프로그램>_<pid>_<taskID>.hpm 파일로 남깁니다.
  • 컴파일할 때 -lhpm -lpmapi -lm(스레드 프로그램은 -lhpm_r)을 붙입니다. 안쪽 반복문에 계측 구간을 넣으면 부하가 큽니다.
  • 셀 이벤트는 집합(-s, HPM_EVENT_SET), (6.1) 그룹(-g, HPM_EVENT_GROUP), 파생 지표 그룹(-m, HPM_PMD_GROUP)으로 고르고, :u·:k 같은 집계 모드를 붙일 수 있습니다. HPM_flags.env 파일이 환경 변수보다 우선합니다.
  • 명령: hpmcount 프로그램(프로그램 하나 실행하며 측정), hpmstat -s 7 10 5(시스템 전체), pmlist -D -1(파생 지표 목록), pmlist -s(프로세서 정보).
  • 집합을 쉼표로 여럿 주면 시간 분할로 번갈아 셉니다(기본 100ms, HPM_MX_DURATION로 10~30000ms).
항목 내용
버전 AIX 5.3, AIX 6.1 (6.1에서 -g 이벤트 그룹, -m 파생 지표 그룹, 집계 모드 한정자, -x XML 출력, -b 정규화 기준이 더해짐)
원문 Performance Tools Guide and Reference — 5.3판 5장(134141쪽), 6.1판 7079쪽
파일 /usr/lib/libhpm.a, /usr/lib/libhpm_r.a, /usr/include/libhpm.h, f_hpm.h, HPM_flags.env
관련 명령어 hpmcount, hpmstat, pmlist, pmcycles

hpm 라이브러리는 pmapi 라이브러리를 바탕으로 한 고수준 계측 라이브러리입니다. 계측 구간 여러 개, 중첩 계측을 지원하고, 계측한 구간을 여러 번 부를 수 있습니다.

중첩 계측을 쓰면 바깥 구간에 대해 배타적(exclusive) 실행 시간이 만들어집니다. 계측 구간을 여러 번 실행하면 평균과 표준 편차를 줍니다.

라이브러리는 OpenMP와 스레드 응용 프로그램을 지원하며, 이때는 스레드 안전 버전 라이브러리 libhpm_r과 링크해야 합니다. 32비트와 64비트 라이브러리 모듈을 모두 제공합니다.

라이브러리는 실행 중에 정보를 모으고 하드웨어 성능 모니터 값을 요약합니다. 그래서 안쪽 반복문 안에 계측 구간을 넣으면 부하가 상당할 수 있습니다.

영어 원문

The hpm library and associated tools

The hpm libraries are higher-level instrumentation libraries based on the pmapi library. They support multiple instrumentation sections, nested instrumentation, and each instrumented section can be called multiple times.

When nested instrumentation is used, exclusive duration is generated for the outer sections. Average and standard deviation is provided when an instrumented section is activated multiple times.

The libraries support OpenMP and threaded applications, which requires linking with the thread-safe version of the library,libhpm_r. Both 32-bit and 64-bit library modules are provided.

The libraries collect information and hardware Performance Monitor summarization during run-time. So, there could be considerable overhead if instrumentation sections are inserted inside inner loops.

컴파일과 링크

libhpm_r 라이브러리의 기능은 libpmapi와 libm 라이브러리의 해당 함수에 의존합니다. 그러므로 hpm 라이브러리를 쓰는 응용 프로그램을 컴파일할 때 -lpmapi -lm 플래그를 지정해야 합니다.

기본으로 Fortran 응용 프로그램에서 hpm 라이브러리로 인수를 넘길 때는 값이 아니라 참조(포인터)로 넘깁니다. 또 문자열 뒤에는 길이 인수가 하나 더 붙습니다. 기본 인수 전달 방법은 내장 함수 %VAL과 %REF로 바꿀 수 있습니다.

영어 원문

Compiling and linking

The functionality of the libhpm_r library depends upon the corresponding functions in the libpmapi and libm libraries. Therefore, the lpmapi -lm flag must be specified when compiling applications using the hpm libraries.

By default, argument passing from Fortran applications to the hpm libraries is done by reference, or pointer, not by value. Also, there is an extra length argument following character strings. You can modify the default argument passing method by using the %VAL and %REF built-in functions.

부하와 측정 오차

소프트웨어 계측에는 어느 정도 부하가 따르기 마련입니다. 부하를 없앨 수는 없으므로 목표는 줄이는 것입니다. hpm 라이브러리에서 부하는 대부분 시간 측정에서 나오며, 시간 측정은 대부분의 시스템에서 비싼 작업입니다.

두 번째 부하는 실행 중에 성능 데이터를 누적하고 저장하는 데서 나옵니다. hpm 라이브러리는 실행 중에 정보를 모으고 요약하므로 안쪽 반복문 안에 계측 구간을 넣으면 부하가 상당할 수 있습니다.

hpm 라이브러리는 라이브러리 초기화와 종료 때 하드웨어 카운터를 써서, 카운터마다 둘 가운데 작은 값을 시작·멈춤 함수 한 번 호출의 비용 추정값으로 남깁니다. 추정한 부하를 각 계측 구간에서 얻은 값에서 빼므로 측정 오차가 0에 가까워집니다. 그러나 통계적 근사이므로, 추정 부하가 응용 프로그램의 측정값보다 큰 경우에는 이 방법이 실패합니다. 실패하면 추정 부하를 측정값에서 빼지 않았다는 다음 오류 메시지가 나올 수 있습니다.

text
WARNING: Measurement error for <event name> not removed

측정 오차를 없애려는 이 절차는 환경 변수 HPM_WITH_MEASUREMENT_ERROR를 TRUE(1)로 설정해 끌 수 있습니다.

영어 원문

Overhead and measurement error issues

It is expected for any software instrumentation to incur some overhead. Since it is not possible to eliminate the overhead, the goal is to minimize it. In the hpm library, most of the overhead is due to time measurement, which tends to be an expensive operation in most systems.

A second source of overhead is due to run-time accumulation and storage of performance data. The hpm libraries collect information and perform summarization during run-time. Hence, there could be a considerable amount of overhead if instrumentation sections are inserted inside inner loops.

The hpm library uses hardware counters during the initialization and finalization of the library, retaining the minimum of the two for each counter as an estimate of the cost of one call to the start and stop functions. The estimated overhead is subtracted from the values obtained on each instrumented code section, which ensures that the measurement of error becomes close to zero. However, since this is a statistical approximation, in some situations where estimated overhead is larger than a measured count for the application, the approach fails. When the approach fails, you might get the following error message, which indicates that the estimated overhead was not subtracted from the measured values:

text
WARNING: Measurement error for <event name> not removed

You can deactivate the procedure that attempts to remove measurement errors by setting the HPM_WITH_MEASUREMENT_ERROR environment variable to TRUE (1).

hpm 라이브러리의 공통 규칙

hpm 라이브러리 API에 공통인 규칙은 다음과 같습니다.

  • API의 다른 어떤 함수보다 먼저 hpmInit()이나 f_hpminit() 함수를 불러야 합니다.
  • 초기화 함수는 응용 프로그램에서 한 번만 부를 수 있습니다.
  • 이벤트 집합, 이벤트 그룹, 카운터/이벤트 쌍 같은 성능 모니터 문맥은 언제든 다시 프로그래밍할 수 없습니다.
  • API의 모든 함수는 void로 지정되어 값이나 상태를 돌려주지 않습니다.
영어 원문

Common hpm library rules

Review common hpm library rules.

The following rules are common to the hpm library APIs:

  • The hpmInit() or f_hpminit() function must be called before any other function in the API.

  • The initialization function can only be called once in an application.

  • Performance Monitor contexts, like the event set, event group, or counter/event pairs, cannot be reprogrammed at any time.

  • All functions of the API are specified as void and return no value or status.

hpm 라이브러리 API 호출

hpm 라이브러리 API 호출은 다음과 같습니다.

호출(C / Fortran) 설명
hpmInit / f_hpminit 지정한 노드 ID와 프로그램 이름으로 초기화합니다.
hpmStart / f_hpmstart 계측 식별자 InstID로 식별하는 계측 코드 구간의 시작을 표시합니다.
hpmStop / f_hpmstop 계측 코드 구간의 끝을 표시합니다. hpmStart()·f_hpmstart()를 부를 때마다 같은 계측 식별자로 hpmStop()·f_hpmstop()을 불러야 합니다.
hpmTstart / f_hpmtstart hpmStart()·f_hpmstart()와 같은 일을 하며 스레드 응용 프로그램에서 씁니다.
hpmTstop / f_hpmtstop hpmStop()·f_hpmstop()과 같은 일을 하며 스레드 응용 프로그램에서 씁니다.
hpmGetTimeAndCounters / f_hpmgettimeandcounters hpmInit()·f_hpminit() 초기화 이후의 시간(초)과 누적 카운트를 돌려줍니다.
hpmGetCounters / f_hpmgetcounter hpmInit()·f_hpminit() 초기화 이후의 누적 카운트를 모두 돌려줍니다.
hpmTerminate / f_hpmterminate 종료 처리를 하고 출력을 만듭니다. 응용 프로그램이 hpmTerminate()·f_hpmterminate()를 부르지 않고 끝나면 성능 정보가 만들어지지 않습니다.
영어 원문

Overview of the hpm library API calls

The following table lists the hpm library API calls.

  • hpmInit or f_hpminit — Performs initialization for a specified node ID and program name.
  • hpmStart or f_hpmstart — Indicates the beginning of an instrumented code segment, which is identified by an instrumentation identifier, InstID.
  • hpmStop or f_hpmstop — Indicates the end of an instrumented code segment. For each call to the hpmStart() or f_hpmstart() function, there should be a corresponding call to the hpmStop() or f_hpmstop() function with the matching instrumentation identifier.
  • hpmTstart or f_hpmtstart — Performs the same function as the hpmStart() and f_hpmstart() functions, but they are used in threaded applications.
  • hpmTstop or f_hpmtstop — Performs the same function as the hpmStop() and f_hpmstop() functions, but they are used in threaded applications.
  • hpmGetTimeAndCounters or f_hpmgettimeandcounters — Returns the time, in seconds, and the accumulated counts since the call to the hpmInit() or f_hpminit() initialization function.
  • hpmGetCounters or f_hpmgetcounter — Returns all the accumulated counts since the call to the hpmInit() or f_hpminit() initialization function.
  • hpmTerminate or f_hpmterminate — Performs termination and generates output. If an application exits without calling the hpmTerminate() or f_hpmterminate() function, no performance information is generated.

스레드 응용 프로그램

T/tstart와 T/tstop 함수는 각각 스레드마다 따로 카운터를 시작하고 멈춥니다. 서로 다른 두 스레드가 같은 instID 매개변수를 쓰면 출력에는 여러 번 호출된 것으로 나오지만 카운트는 누적됩니다.

instID 매개변수는 늘 상수 변수나 정수여야 하며 식(expression)이 될 수 없습니다. #define 문이 든 libhpm.h, f_hpm.h, f_hpm_i8.h 헤더 파일의 선언은 컴파일러 전처리 단계에서 평가되어 줄 번호와 소스 파일 이름을 모으기 때문입니다.

영어 원문

Threaded applications

The T/tstart and T/tstop functions respectively start and stop the counters independently on each thread. If two distinct threads use the same instID parameter, the output indicates multiple calls. However, the counts are accumulated.

The instID parameter is always a constant variable or integer. It cannot be an expression because the declarations in the libhpm.h, f_hpm.h, and f_hpm_i8.h header files that contain #define statements are evaluated during the compiler pre-processing phase, which permits the collection of line numbers and source file names.

hpm 라이브러리와 도구에서 이벤트 고르기

hpm 라이브러리는 hpmcount·hpmstat 도구와 같은 하드웨어 카운터와 이벤트를 씁니다. 이벤트는 집합(set) 단위로 고릅니다. 집합은 파생 지표를 계산할 수 있도록 특별히 표시한 이벤트 그룹입니다.

hpm 라이브러리에서는 다음 가운데 한 방법으로 쓸 이벤트 집합을 고릅니다.

  • 환경 변수 HPM_EVENT_SET. 환경에 직접 설정하거나 HPM_flags.env 파일에 적습니다.
  • libHPMevents 파일의 내용

hpmcount와 hpmstat 명령에서는 다음 가운데 한 방법으로 감시할 이벤트 종류와 해당 하드웨어 성능 카운터를 지정합니다.

  • -s 옵션
  • 환경 변수 HPM_EVENT_SET. 직접 설정하거나 HPM_flags.env 파일에 적습니다.
  • libHPM_events 파일의 내용

어느 경우든 HPM_flags.env 파일이 환경 변수 HPM_EVENT_SET을 직접 설정한 것보다 우선하고, libHPMevents나 libHPM_events 파일의 내용이 HPM_EVENT_SET 환경 변수보다 우선합니다.

(6.1) 이벤트 집합 대신 이벤트 그룹을 다음 가운데 한 방법으로 지정할 수 있습니다.

  • -g 옵션
  • 환경 변수 HPM_EVENT_GROUP. 직접 설정하거나 HPM_flags.env 파일에 적습니다.

어느 경우든 HPM_flags.env 파일이 HPM_EVENT_GROUP 환경 변수를 직접 설정한 것보다 우선합니다. HPM_EVENT_GROUP은 HPM_EVENT_SET보다 우선합니다. HPM_EVENT_GROUP은 그룹 이름이나 그룹 번호를 쉼표로 구분한 목록입니다.

(6.1) 평가할 파생 지표 그룹 목록을 다음 가운데 한 방법으로 지정할 수 있습니다.

  • -m 옵션
  • 환경 변수 HPM_PMD_GROUP. 직접 설정하거나 HPM_flags.env 파일에 적습니다.

어느 경우든 HPM_flags.env 파일이 HPM_PMD_GROUP 환경 변수를 직접 설정한 것보다 우선합니다. HPM_PMD_GROUP은 파생 지표 그룹 이름을 쉼표로 구분한 목록입니다.

(6.1) 집합, 그룹, 파생 지표 그룹마다 집계 모드를 붙일 수 있습니다. 쓸 수 있는 집계 모드는 다음과 같습니다.

한정자 모드
u 사용자 모드
k 커널 모드
h 하이퍼바이저 모드
r runlatch 모드
n nointerrupt 모드

집계 모드 한정자는 집합이나 그룹 뒤에 콜론(:)으로 구분해 붙입니다. 예:

text
HPM_EVENT_GROUP=pm_utilization:uk,pm_completion:u

시간 분할(time slice) 기능을 쓰려면 집합 번호 하나 대신 쉼표로 구분한 집합 목록을 지정합니다. 기본으로 집합마다 시간 조각은 100ms이며, 환경 변수 HPM_MX_DURATION으로 바꿀 수 있습니다. 값은 ms 단위이고 10ms~30000ms 범위여야 합니다.

libHPMevents와 libHPM_events 파일

libHPMevents와 libHPM_events 파일은 둘 다 사용자가 만들며 형식이 같습니다.

POWER3이나 PowerPC 604 RISC 마이크로프로세서 시스템에서는 다음 예처럼 카운터 번호와 이벤트 이름을 적습니다.

text
0 PM_LD_MISS_L2HIT
1 PM_TAG_BURSTRD_L2MISS
2 PM_TAG_ST_MISS_L2
3 PM_FPU0_DENORM
4 PM_LSU_IDLE
5 PM_LQ_FULL
6 PM_FPU_FMA
7 PM_FPU_IDLE

POWER4 이후 시스템에서는 다음 예처럼 이벤트 그룹 이름을 적습니다.

text
pm_hpmcount1

HPM_flags.env 파일

HPM_flags.env 파일에는 이벤트 집합을 지정하고 파생 지표를 계산하는 데 쓰는 환경 변수를 적습니다.

예:

text
HPM_L2_LATENCY 12
HPM_EVENT_SET  5
영어 원문

Selecting events when using the hpm libraries and tools

The hpm libraries use the same set of hardware counters and events used by the hpmcount and hpmstat tools. The events are selected by sets. Sets are specially marked event groups for whichever derived metrics are available.

For the hpm libraries, you can select the event set to be used by any of the following methods:

  • The HPM_EVENT_SET environment variable, which is either explicitly set in the environment or specified in the HPM_flags.env file.

  • The content of the libHPMevents file.

For the hpmcount and hpmstat commands, you can specify which event types you want to be monitored and the associated hardware performance counters by any of the following methods:

  • Using the -s option

  • The HPM_EVENT_SET environment variable, which you can set directly or define in the

HPM_flags.env file

  • The content of the libHPM_events file

In all cases, the HPM_flags.env file takes precedence over the explicit setting of the HPM_EVENT_SET environment variable and the content of the libHPMevents or libHPM_events file takes precedence over the HPM_EVENT_SET environment variable.

An event group can be specified instead of an event set, using any of the following methods:

  • The -g option

  • The HPM_EVENT_GROUP environment variable that you can set directly or define in the

HPM_flags.env file

In all cases, the HPM_flags.env file takes precedence over the explicit setting of the HPM_EVENT_GROUP environment variable. The HPM_EVENT_GROUP environment variable takes precedence over the explicit setting of the HPM_EVENT_SET environment variable. The HPM_EVENT_GROUP is a comma separated list of group names or group numbers.

A list of derived metric groups to be evaluated can be specified, using any of the following methods:

  • The -m option

  • The HPM_PMD_GROUP environment variable that you can set directly or define in the

HPM_flags.env file

In all cases, the HPM_flags.env file take precedence over the explicit setting of the HPM_PMD_GROUP environment variable. The HPM_PMD_GROUP is a comma-separated list of derived metric group names.

Each set, group or derived metric group can be qualified by a counting mode. The allowed counting modes are:

  • u: user mode

  • k: kernel mode

  • h: hypervisor mode

  • r: runlatch mode

  • n: nointerrupt mode

The counting mode qualifier is separated from the set or group by a colon ":". For example:

text
HPM_EVENT_GROUP=pm_utilization:uk,pm_completion:u

To use the time slice functionality, specify a comma-separated list of sets instead of a single set number. By default, the time slice duration for each set is 100 ms, but this can be modified with the HPM_MX_DURATION environment variable. This value must be expressed in ms, and in the range 10 ms to 30000 ms.

The libHPMevents and libHPM_events files

The libHPMevents and libHPM_events files are both supplied by the user and have the same format.

For POWER3 or PowerPC 604 RISC Microprocessor systems, the file contains the counter number and the event name, like in the following example:

text
0 PM_LD_MISS_L2HIT
1 PM_TAG_BURSTRD_L2MISS
2 PM_TAG_ST_MISS_L2
3 PM_FPU0_DENORM
4 PM_LSU_IDLE
5 PM_LQ_FULL
6 PM_FPU_FMA
7 PM_FPU_IDLE

For POWER4 and later systems, the file contains the event group name, like in the following example:

text
pm_hpmcount1

The HPM_flags.env file

The HPM_flags.env file contains environment variables that are used to specify the event set and for the computation of derived metrics

Example

text
HPM_L2_LATENCY 12
HPM_EVENT_SET  5

hpm 라이브러리의 출력 파일

hpmTerminate 함수를 부르면 기본으로 <progName>_<pid>_<taskID>.hpm 파일에 요약 보고서를 씁니다. taskID와 progName은 각각 hpmInit() 함수의 첫째, 둘째 매개변수입니다.

출력 파일 이름은 환경 변수 HPM_OUTPUT_NAME으로 정할 수 있습니다. hpm 라이브러리는 지정한 값 뒤에 늘 _<taskID>.hpm을 붙입니다. HPM_OUTPUT_NAME으로 파일 이름에 날짜와 시각을 넣을 수도 있습니다. 예를 들어 다음과 같이 하면

text
MYDATE=$(date +"m%d:2/2/06M%S")
export HPM_OUTPUT_NAME=myprogram_$MYDATE

task 27의 출력 파일 이름은 myprogram_yyyymmdd:HHMMSS_0027.hpm이 됩니다.

환경 변수 HPM_VIZ_OUTPUT=TRUE를 설정하면 XML 출력 파일도 만듭니다. 파일 이름은 <progName>_<pid>_<taskID>.viz나 HPM_OUTPUT_NAME_<taskID>.viz입니다.

영어 원문

Output files of the hpm library

When the hpmTerminate function is called, a summary report is written to the <progName>_<pid>_<taskID>.hpm file, by default. The taskID and progName values are the first and second parameters of the hpmInit() function, respectively.

You can define the name of the output file with the HPM_OUTPUT_NAME environment variable. The hpm libraries always add the _<taskID>.hpm suffix to the specified value. You can also include the date and time in the file name using the HPM_OUTPUT_NAME environment variable. For example, if you use the following code:

text
MYDATE=$(date +"m%d:2/2/06M%S")
export HPM_OUTPUT_NAME=myprogram_$MYDATE

the output file for task 27 is named myprogram_yyyymmdd:HHMMSS_0027.hpm.

You can also generate an XML output file by setting the HPM_VIZ_OUTPUT=TRUE environment variable. The generated output files are named either <progName>_<pid>_<taskID>.viz or HPM_OUTPUT_NAME_<taskID>.viz.

hpmcount 명령의 출력 파일

hpmcount 명령의 출력 파일은 설정한 환경 변수와 실행 환경에 따라 다릅니다.

hpmcount 명령의 출력 파일은 다음과 같습니다.

파일 이름 설명
file_<myID>.<pid> file은 -o 옵션으로 지정하고, myID에는 환경 변수 MP_CHILD의 값이 들어갑니다(기본 0000).
HPM_LOG_DIR/hpm_log.<pid> 환경 변수 HPM_LOG_DIR을 있는 디렉터리로 설정하면 결과를 hpm_log.<pid> 파일에도 씁니다.
HPM_LOG_DIR/hpm_log.MP_PARTITION 환경 변수 MP_PARTITION은 POE 환경에서 제공됩니다. hpm_log.MP_PARTITION 파일에는 합계 카운트가 들어갑니다.

(6.1) -x 옵션으로 XML 출력을 만들 수 있습니다.

(6.1) 결과 정규화에 쓸 다른 시간 기준을 다음 가운데 한 방법으로 고를 수 있습니다.

  • -b time|purr|spurr 옵션
  • 환경 변수 HPM_NORMALIZE. 직접 설정하거나 HPM_flags.env 파일에 적습니다.
영어 원문

Output files of the hpmcount command

The output file for the hpmcount command depend on the environment variables set and the execution environment.

The following are the output files of the hpmcount command:

File name

Description

file_<myID>.<pid>

The value for file is specified with the -o option and the myID value is assigned the value of the MP_CHILD environment variable, which has a default value of 0000.

HPM_LOG_DIR/hpm_log.<pid>

When the HPM_LOG_DIR environment variable is set to an existing directory, results are additionally written to the hpm_log.<pid> file.

HPM_LOG_DIR/hpm_log.MP_PARTITION

The MP_PARTITION environment variable is provided in POE environments. The hpm_log.MP_PARTITION file contains the aggregate counts.

An XML output can be provided by using the -x option.

An alternative time base for the result normalization can be selected using any of the following methods:

  • The -b time|purr|spurr option

  • The HPM_NORMALIZE environment variable that you can set directly or define in the

HPM_flags.env file

파생 지표와 관련 환경 변수

세도록 고른 하드웨어 이벤트와 쓰는 하드웨어 플랫폼에 따라 hpm 라이브러리 도구와 hpmterminate 함수의 출력에는 파생 지표가 들어갑니다.

프로세서에서 전역으로 지원하는 지표는 pmlist -D -1 [-p Processor_name] 명령으로 나열할 수 있습니다.

관련 파생 지표를 계산할 때 쓸 메모리, 캐시, TLB 미스 지연 시간의 추정값을 다음 환경 변수로 줄 수 있습니다.

  • HPM_MEM_LATENCY
  • HPM_L3_LATENCY
  • HPM_L35_LATENCY
  • HPM_AVG_L3_LATENCY
  • HPM_AVG_L2_LATENCY
  • HPM_L2_LATENCY
  • HPM_L25_LATENCY
  • HPM_L275_LATENCY
  • HPM_L1_LATENCY
  • HPM_TLB_LATENCY

HPM_flags.env 파일에 정의한 변수가 우선합니다.

POWER4 이후 시스템에서는 환경 변수 HPM_DIV_WEIGHT로 가중 flips(부동 소수점 명령 수)를 계산할 수 있습니다.

영어 원문

Derived metrics and related environment variables

In relation to the hardware events that are selected to be counted and the hardware platform that is used, the output for the hpm library tools and the hpmterminate function includes derived metrics.

You can list the globally supported metrics for a given processor with the pmlist -D -1 [-p Processor_name] command.

You can supply the following environment variables to specify estimations of memory, cache, and TLB miss latencies for the computation of related derived metrics:

  • HPM_MEM_LATENCY

  • HPM_L3_LATENCY

  • HPM_L35_LATENCY

  • HPM_AVG_L3_LATENCY

  • HPM_AVG_L2_LATENCY

  • HPM_L2_LATENCY

  • HPM_L25_LATENCY

  • HPM_L275_LATENCY

  • HPM_L1_LATENCY

  • HPM_TLB_LATENCY

Precedence is given to variables that are defined in the HPM_flags.env file.

You can use the HPM_DIV_WEIGHT environment variable to compute the weighted flips on systems that are POWER4 and later.

hpm 도구의 예

다음은 hpm 라이브러리 명령의 사용 예입니다.

pmlist 명령

POWER5 프로세서 시스템에서 pmlist 명령을 실행한 예입니다.

text
# pmlist -s
POWER5 supports 6 counters
Number of groups            : 144
Number of sets              : 8
Threshold multiplier (lower): 1
Threshold multiplier (upper): 32
Threshold multiplier (hyper): 64
Hypervisor counting mode is supported
Runlatch counting mode is supported

pmlist 명령의 다른 예입니다.

text
# pmlist -D -1  -p POWER5
Derived metrics supported:
        PMD_UTI_RATE                   Utilization rate
        PMD_MIPS                       MIPS
        PMD_INST_PER_CYC               Instructions per cycle
        PMD_HW_FP_PER_CYC              HW floating point instructions per Cycle
        PMD_HW_FP_PER_UTIME            HW floating point instructions / user time
        PMD_HW_FP_RATE                 HW floating point rate
        PMD_FX                         Total Fixed point operations
        PMD_FX_PER_CYC                 Fixed point operations per Cycle
        PMD_FP_LD_ST                   Floating point load and store operations
        PMD_INST_PER_FP_LD_ST          Instructions per floating point load/store
        PMD_PRC_INST_DISP_CMPL         % Instructions dispatched that completed
        PMD_DATA_L2                    Total L2 data cache accesses
        PMD_PRC_L2_ACCESS              % accesses from L2 per cycle
        PMD_L2_TRAF                    L2 traffic
        PMD_L2_BDW                     L2 bandwidth per processor
        PMD_L2_LD_EST_LAT_AVG          Estimated latency from loads from L2 (Average)
        PMD_UTI_RATE_RC                Utilization rate (versus run cycles)
        PMD_INST_PER_CYC_RC            Instructions per run cycle
        PMD_LD_ST                      Total load and store operations
PMD_INST_PER_LD_ST             Instructions per load/store
PMD_LD_PER_LD_MISS             Number of loads per load miss
PMD_LD_PER_DTLB                Number of loads per DTLB miss
PMD_ST_PER_ST_MISS             Number of stores per store miss
PMD_LD_PER_TLB                 Number of loads per TLB miss
PMD_LD_ST_PER_TLB              Number of load/store per TLB miss
PMD_TLB_EST_LAT                Estimated latency from TLB miss
PMD_MEM_LD_TRAF                Memory load traffic
PMD_MEM_BDW                    Memory bandwidth per processor
PMD_MEM_LD_EST_LAT             Estimated latency from loads from memory
PMD_LD_LMEM_PER_LD_RMEM        Number of loads from local memory per loads from remote memory
PMD_PRC_MEM_LD_RC              % loads from memory per run cycle

hpmcount 명령

hpmcount 명령의 출력 예입니다.

text
# hpmcount -m cpi_breakdown ls
bar           foo
 Workload context: ls (pid:42234)
 Execution time (wall clock time): 0.004222 seconds
 ########  Resource Usage Statistics  ########
 Total amount of time in user mode            : 0.001783 seconds
 Total amount of time in system mode          : 0.000378 seconds
 Maximum resident set size                    : 220 Kbytes
 Average shared memory use in text segment    : 0 Kbytes*sec
 Average unshared memory use in data segment  : 0 Kbytes*sec
 Number of page faults without I/O activity   : 63
 Number of page faults with I/O activity      : 0
 Number of times process was swapped out      : 0
 Number of times file system performed INPUT  : 0
 Number of times file system performed OUTPUT : 0
 Number of IPC messages sent                  : 0
 Number of IPC messages received              : 0
 Number of signals delivered                  : 0
 Number of voluntary context switches         : 0
 Number of involuntary context switches       : 0
 #######  End of Resource Statistics  ########
 Counting mode: user
  PM_1PLUS_PPC_CMPL (One or more PPC instruction completed)   :    143749896
  PM_GCT_EMPTY_CYC (Cycles GCT empty)                         :     12905400
  PM_GRP_CMPL (Group completed)                               :    144626424
  PM_CYC (Processor cycles)                                   :    434717274
  PM_INST_CMPL (Instructions completed)                       :    193121895
  PM_RUN_CYC (Run cycles)                                     :    378397903
  PM_GCT_NOSLOT_CYC (Cycles no GCT slot allocated)            :     87592746
  PM_GCT_NOSLOT_IC_MISS                                       :     16066248
    (No slot in GCT caused by I cache miss)
  PM_GCT_NOSLOT_SRQ_FULL (No slot in GCT caused by SRQ full)  :            0
  PM_GCT_NOSLOT_BR_MPRED                                      :     27869700
    (No slot in GCT caused by branch mispredict)
  PM_GRP_MRK (Group marked in IDU)                            :      6041616
  PM_CMPLU_STALL_LSU                                          :    117973392
    (Completion stall caused by LSU instruction)
  PM_IOPS_CMPL (Internal operations completed)                :    162398665
  PM_CMPLU_STALL_REJECT (Completion stall caused by reject)   :     24318036
  PM_CMPLU_STALL_DCACHE_MISS                                  :     25055262
    (Completion stall caused by D cache miss)
  PM_CMPLU_STALL_ERAT_MISS                                    :     17332764
    (Completion stall caused by ERAT miss)
  PM_GRP_IC_MISS_BR_REDIR_NONSPEC                             :      2551038
   (Group experienced non-speculative I cache miss or branch redirect)
  PM_CMPLU_STALL_FXU                                          :     69575412
    (Completion stall caused by FXU instruction)
  PM_CMPLU_STALL_DIV                                          :     45664068
    (Completion stall caused by DIV instruction)
  PM_FPU_FULL_CYC (Cycles FPU issue queue full)               :        27660
PM_CMPLU_STALL_FDIV                                         :       319104
  (Completion stall caused by FDIV or FQRT instruction)
PM_CMPLU_STALL_FPU                                          :       500274
  (Completion stall caused by FPU instruction)
Derived metric group: cpi_breakdown
Total cycles                                                  : 2.250999
    Completion cycles                                         : 0.748887
    Completion Table empty (GCT empty)                        : 0.266825
        I-Cache Miss Penalty                                  : 0.083192
        Branch Mispredication Penalty                         : 0.144311
        Others GCT stalls                                     : 0.039322
    Completion Stall cycles                                   : 1.435288
        Stall by LSU instruction                              : 0.610875
            Stall by LSU Reject                               : 0.125921
                Stall by LSU Translation Reject               : 0.089750
                Stall by LSU Other Reject                     : 0.036170
            Stall by LSU D-cache miss                         : 0.129738
            Stall by LSU basic latency, LSU Flush penalty     : 0.355217
        Stall by FXU instruction                              : 0.360267
            Stall by any form of DIV/MTSPR/MFSPR instruction  : 0.236452
            Stall by FXU basic latency                        : 0.123815
        Stall by FPU instruction                              : 0.002590
            Stall by any form of FDIV/FSQRT instruction       : 0.001652
            Stall by FPU basic latency                        : 0.000938
        Stall by others                                       : 0.462493

hpmstat 명령

hpmstat 명령의 출력 예입니다.

text
# hpmstat -s 7
 Execution time (wall clock time): 1.003946 seconds
 Counting mode: user
  PM_TLB_MISS (TLB misses)                           :          260847
  PM_CYC (Processor cycles)                          :      3013964331
  PM_ST_REF_L1 (L1 D cache store references)         :       161377371
  PM_LD_REF_L1 (L1 D cache load references)          :       255317480
  PM_INST_CMPL (Instructions completed)              :      1027391919
  PM_RUN_CYC (Run cycles)                            :      1495147343
  Derived metric group: default
  Utilization rate                                 :         181.243 %
  Total load and store operations                  :         416.695 M
  Instructions per load/store                      :           2.466
  MIPS                                             :        1023.354
  Instructions per cycle                           :           0.341

카운터 다중화를 쓰는 hpmstat 명령의 예입니다.

text
# hpmstat -s 1,2 -d
Execution time (wall clock time): 2.129755 seconds
Set: 1
Counting duration: 1.065 seconds
  PM_INST_CMPL (Instructions completed)                :          244687
  PM_FPU1_CMPL (FPU1 produced a result)                :               0
  PM_ST_CMPL (Store instruction completed)             :           31295
  PM_LD_CMPL (Loads completed)                         :           67414
  PM_FPU0_CMPL (Floating-point unit produced a result) :              19
  PM_CYC (Processor cycles)                            :          295427
  PM_FPU_FMA (FPU executed multiply-add instruction)   :               0
  PM_TLB_MISS (TLB misses)                             :             788
Set: 2
Counting duration: 1.064 seconds
  PM_TLB_MISS (TLB misses)                           :            379472
  PM_ST_MISS_L1 (L1 D cache store misses)            :             79943
  PM_LD_MISS_L1 (L1 D cache load misses)             :            307338
  PM_INST_CMPL (Instructions completed)              :         848578245
  PM_LSU_IDLE (Cycles LSU is idle)                   :         229922845
  PM_CYC (Processor cycles)                          :         757442686
  PM_ST_DISP (Store instructions dispatched)         :         125440562
  PM_LD_DISP (Load instr dispatched)                 :         258031257
Counting mode: user
  PM_TLB_MISS (TLB misses)                             :          380260
  PM_ST_MISS_L1 (L1 D cache store misses)              :          160017
  PM_LD_MISS_L1 (L1 D cache load misses)               :          615182
  PM_INST_CMPL (Instructions completed)                :       848822932
  PM_LSU_IDLE (Cycles LSU is idle)                     :       460224933
  PM_CYC (Processor cycles)                            :       757738113
  PM_ST_DISP (Store instructions dispatched)           :       251088030
  PM_LD_DISP (Load instr dispatched)                   :       516488120
  PM_FPU1_CMPL (FPU1 produced a result)                :               0
  PM_ST_CMPL (Store instruction completed)             :           62582
  PM_LD_CMPL (Loads completed)                         :          134812
  PM_FPU0_CMPL (Floating-point unit produced a result) :              38
  PM_FPU_FMA (FPU executed multiply-add instruction)   :               0
  Derived metric group: default
  Utilization rate                                 :         189.830 %
  % TLB misses per cycle                           :           0.050 %
  number of loads per TLB miss                     :           0.355
  Total l2 data cache accesses                     :           0.775 M
  % accesses from L2 per cycle                     :           0.102 %
  L2 traffic                                       :          47.276 MBytes
  L2 bandwidth per processor                       :          44.431 MBytes/sec
  Total load and store operations                  :           0.197 M
  Instructions per load/store                      :        4300.145
  number of loads per load miss                    :         839.569
  number of stores per store miss                  :        1569.133
  number of load/stores per D1 miss                :         990.164
  L1 cache hit rate                                :           0.999 %
  % Cycles LSU is idle                             :          30.355 %
  MIPS                                             :         199.113
  Instructions per cycle                           :           1.120
영어 원문

Examples of the hpm tools

The examples in this section demonstrate the usage of the following hpm library commands:

The pmlist command

The following is an example of the pmlist command on a POWER5 processor-based system.

text
# pmlist -s
POWER5 supports 6 counters
Number of groups            : 144
Number of sets              : 8
Threshold multiplier (lower): 1
Threshold multiplier (upper): 32
Threshold multiplier (hyper): 64
Hypervisor counting mode is supported
Runlatch counting mode is supported

The following is another example of the pmlist command:

(33줄짜리 예는 위 한글 본문에 그대로 실었습니다.)

The hpmcount command

The following is example output from the of the hpmcount command.

(75줄짜리 예는 위 한글 본문에 그대로 실었습니다.)

The hpmstat command

The following is an example output from the hpmstat command.

(15줄짜리 예는 위 한글 본문에 그대로 실었습니다.)

The following is an example of the hpmstat command with counter multiplexing:

(53줄짜리 예는 위 한글 본문에 그대로 실었습니다.)

hpm 라이브러리 사용 예

C 프로그램 예

다음 C 프로그램에는 계측 구간이 두 개 있습니다. 간단한 부동 소수점 연산을 하고, 결과를 출력하고, 명령 해석기를 띄워 ls -R / 2>&1 >/dev/null 명령을 실행합니다.

text
#include <sys/wait.h>
#include <unistd.h>
#include <stdio.h>
#include <libhpm.h>
void
do_work()
{
        pid_t p, wpid;
        int i, status;
        float f1 = 9.7641, f2 = 2.441, f3 = 0.0;
        f3 = f1 / f2;
        printf("f3=%f\n", f3);
        p = fork();
        if (p == -1) {
          perror("Mike fork error");
          exit(1);
        }
        if (p == 0) {
          i = execl("/usr/bin/sh", "sh", "-c", "ls -R / 2>&1 >/dev/null", 0);
          perror("Mike execl error");
          exit(2);
        }
        else
          wpid = waitpid(p, &status, WUNTRACED | WCONTINUED);
        if (wpid == -1) {
            perror("Mike waitpid error");
            exit(3);
        }
        return;
}
main(int argc, char **argv)
{
        int taskID = 999;
        hpmInit(taskID, "my_program");
        hpmStart(1, "outer call");
        do_work();
        hpmStart(2, "inner call");
        do_work();
        hpmStop(2);
        hpmStop(1);
        hpmTerminate(taskID);
}

Fortran 프로그램 예

계측 호출이 든 모든 소스 파일에 다음 선언이 있어야 합니다.

text
#include "f_hpm.h"

Fortran 프로그램은 다음 예처럼 f_ 접두사가 붙은 함수를 부릅니다.

text
call f_hpminit( taskID, "my_program" )
call f_hpmstart( 1, "Do Loop"  )
     do ...
      call do_work()
      call f_hpmstart( 5, "computing meaning of life" );
      call do_more_work();
      call f_hpmstop( 5 );
     end do
call f_hpmstop( 1 )
call f_hpmterminate( taskID )

다중 스레드 응용 프로그램 계측 예

병렬 영역 안에 계측을 넣을 때는 스레드마다 다른 ID를 씁니다.

text
!$OMP PARALLEL
!$OMP&PRIVATE (instID)
     instID = 30+omp_get_thread_num()
     call f_hpmtstart( instID, "computing meaning of life" )
!$OMP DO
      do ...
       do_work()
      end do
      call f_hpmtstop( instID )
!$OMP END PARALLEL

라이브러리는 스레드가 달라도 같은 instID를 쓰는 것을 받아들이지만, 같은 instID의 모든 인스턴스에 대해 카운터가 누적됩니다.

영어 원문

Examples of hpm library usage

The following are examples of hpm library usage:

A C programming language example

The following C program contains two instrumented sections which perform a trivial floating point operation, print the results, and then launch the command interpreter to execute the ls -R / 2>&1 >/dev/null command.

(42줄짜리 예는 위 한글 본문에 그대로 실었습니다.)

A Fortran programming language example

The following declaration is required on all source files that have instrumentation calls.

text
#include "f_hpm.h"

Fortran programs call functions that include the f_ prefix, as you can see in the following example:

text
call f_hpminit( taskID, "my_program" )
call f_hpmstart( 1, "Do Loop"  )
     do ...
      call do_work()
      call f_hpmstart( 5, "computing meaning of life" );
      call do_more_work();
      call f_hpmstop( 5 );
     end do
call f_hpmstop( 1 )
call f_hpmterminate( taskID )

Multithreaded application instrumentation example

When placing instrumentation inside of parallel regions, you should use a different ID for each thread.

The following is an example multithreaded application instrumentation:

text
!$OMP PARALLEL
!$OMP&PRIVATE (instID)
     instID = 30+omp_get_thread_num()
     call f_hpmtstart( instID, "computing meaning of life" )
!$OMP DO
      do ...
       do_work()
      end do
      call f_hpmtstop( instID )
!$OMP END PARALLEL

The library accepts the use of the same instID for different threads, but the counters are accumulated for all instances with the same instID.

자주 쓰는 형태

bash
pmlist -s                          # 프로세서와 카운터 정보
pmlist -D -1                       # 파생 지표 목록
hpmcount -m cpi_breakdown ./myprog # 프로그램 하나의 CPI 분석(6.1)
hpmstat -s 7 10 5                  # 이벤트 집합 7로 시스템 전체를 10초 간격 5번
cc -o myprog myprog.c -lhpm -lpmapi -lm