Skip to content

[박성현] 프로젝트 결과 문서 #197

@ghost

Description

프로젝트 목표

  • 리눅스 커널 프로젝트 중 perf tools에 대한 컨트리뷰션
  • 코드 분석 기술, emacs 에디터 사용법과 리눅스 패치 메일 작성 요령 습득

개발환경 구성문서

기존 개발환경 구성 문서

#191

추가 내용 1: 코드 분석을 위한 etags, cscope 사용

코드 분석을 위해 심볼 찾기, 정의로 이동 등을 간편하게 할 수 있다.

  • 태그 파일 생성
$ find -H ./'*.[ch]' | xargs etags --apend
  • 단축키 설정 (pop-tag-mark)
$ cat > .emacs.d/init.el
(define-key global-map "\M-*" 'pop-tag-mark)

M-. 를 통해 태그 검색 및 이동, M-* 를 통해 이전 버퍼로 복귀

  • cscope 설치 및 el 파일 설정
$ sudo apt install cscope cscope-el
$ cat > .emac.d/init.el
(requre xcscope)
  • cscope 인덱스 파일 생성
M-x cscope-index-files

해당 경로에 cscope.out 생성 확인

C-c s s로 심볼 검색, C-c s d로 정의 검색을 주로 사용.

추가 내용 2: git send-email 설정 및 패치메일 전송 절차

  • patch 파일 생성
    패치 메일에 필요한 .patch 파일을 만들기 위해 다음의 명령어를 사용
$ git format-patch -1
  • git send-emali 설정
$ sudo apt install git-email
$ cat > ~/.gitconfig
[sendemail]
    smtpserver = smtp.gmail.com
    smptserverport = 587
    smptuser = "Your@e-mail.com"
    smptencryption = tls
  • 패치 메일 전송 방법
git send-email                                      \
--to "MAINTAINER" <*@kernel.org>                    \
--cc "linux-kernel@vger.kernel.org"                 \
--cc "REVIEWER <*@.kernel.org>"                     \
--cc "REVIEWER <*@.kernel.org>"                     \
[patch file]

성과 소개

동기

퍼포먼스 카운터 값을 읽어오는 시스템 콜을 찾던 중 /include/uapi/linux/perf_event.hperf_attr_open 함수가 사용됨을 알 수 있었음.

이 함수에 struct perf_event_attr가 인자로 넘겨지는 것을 확인. 각 필드의 역할을 살펴보던 중, perf tools에 포함된 /tests/attr.c 파일 내부 store_event 함수에서 이 struct의 각 필드를 복사하는 코드를 발견.

...
/* struct perf_event_attr */
WRITE_ASS(type,   PRIu32);
WRITE_ASS(size,   PRIu32);
WRITE_ASS(config,  "llu");
WRITE_ASS(sample_period, "llu");
WRITE_ASS(sample_type,   "llu");
WRITE_ASS(read_format,   "llu");
WRITE_ASS(disabled,       "d");
WRITE_ASS(inherit,        "d");
WRITE_ASS(pinned,         "d");
WRITE_ASS(exclusive,      "d");
WRITE_ASS(exclude_user,   "d");
WRITE_ASS(exclude_kernel, "d");
WRITE_ASS(exclude_hv,     "d");
WRITE_ASS(exclude_idle,   "d");
...

그런데 struct perf_event_attr 에 새롭게 추가된 필드에 대해서는 복사하는 코드가 누락돼 있었음. 이 부분을 추가하는 패치 메일을 작성하기로 결정

결과

$ git blame include/uapi/linux/perf_event_attr.c

13d7a2410fa63 (Stephane Eranian         2013-08-21 12:10:24 +0200  367) 				mmap2          :  1, /* include mmap with inode data     */
82b897782d10f (Adrian Hunter            2014-05-28 11:45:04 +0300  368) 				comm_exec      :  1, /* flag comm events that are due to an exec */
34f439278cef7 (Peter Zijlstra           2015-02-20 14:05:38 +0100  369) 				use_clockid    :  1, /* use @clockid for time fields */
45ac1403f564f (Adrian Hunter            2015-07-21 12:44:02 +0300  370) 				context_switch :  1, /* context switch data */
9ecda41acb971 (Wang Nan                 2016-04-05 14:11:18 +0000  371) 				write_backward :  1, /* Write ring buffer from end to beginning */
e422267322cd3 (Hari Bathini             2017-03-08 02:11:36 +0530  372) 				namespaces     :  1, /* include namespaces data */

$ git blame tools/perf/tests/attr.c
02554ff64438e (Seonghyun Park           2017-11-09 23:07:04 +0900 127) 	WRITE_ASS(mmap2,	  "d");
02554ff64438e (Seonghyun Park           2017-11-09 23:07:04 +0900 128) 	WRITE_ASS(comm_exec,	  "d");
02554ff64438e (Seonghyun Park           2017-11-09 23:07:04 +0900 129) 	WRITE_ASS(context_switch, "d");
02554ff64438e (Seonghyun Park           2017-11-09 23:07:04 +0900 130) 	WRITE_ASS(write_backward, "d");
02554ff64438e (Seonghyun Park           2017-11-09 23:07:04 +0900 131) 	WRITE_ASS(namespaces,	  "d");
02554ff64438e (Seonghyun Park           2017-11-09 23:07:04 +0900 132) 	WRITE_ASS(use_clockid,    "d");

다음과 같이 새롭게 추가된 영역에 대한 WRITE_ASS 를 추가

https://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git/commit/?h=perf/core&id=02554ff64438e4cd4f4d98f391a68417a59c74cf

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions