포토로그 마이가든



데비안 간단 패키지 만들기 Tips

1. deb 패키지 생성을 위한 기본 디렉토리 만들기

$> mkdir package

데비안 패키지를 만들 디렉토리를 만들고 그 안에다가 설치할 파일들을 구성한다.
예를 들면, ./package/usr/bin/helloworld 이렇게 구성해 놓으면 나중에 패키지를 설치할 때 /usr/bin/ 디렉토리에 helloworld 파일이 설치 되는 형식이다.

2. DEBIAN 디렉토리 구성하기

$> mkdir ./package/DEBIAN

DEBIAN 디렉토리를 만들고 그안에 여러가지 control 파일들을 생성한다. 필수적인 파일은 control 파일이다.

<control 파일 예제>
$> cat ./package/DEBIAN/control
Package: helloworld
Version: 1.1-1Section: base
Priority: optional
Architecture: all
Depends: bash (>= 2.05a-11)
Maintainer: Eunbyung Park <silverbottlep@gmail.com>
Description: Hello world package 
This script provides a broad overview of different system aspects.
3. 패키지 만들기
dpkg -b package/ package.deb




Idle loop Linux

운영체제에서 더이상 할일이 없으면, idle loop에 빠지게 된다.

idle loop을 구현하는 방법에서는 여러가지가 있겠지만 'hlt' 인스트럭션을 사용하는 것이 일반적인 것 같다.

7.6.9.1. HLT INSTRUCTION
The HLT instruction stops the execution of the logical processor on which it is executed and
places it in a halted state until further notice (see the description of the HLT instruction in
Chapter 3, Instruction Set Reference, of the IA-32 Intel Architecture Software Developer’s
Manual, Volume 2). When one logical processor is halted, the still active logical processors
continue to have full access to the shared resources within the physical package. Here shared
resources that were being used by the halted logical processor become available to the still active
logical processors, allowing them to execute at greater efficiency. When the halted logical
processor resumes execution, the shared resources are again shared among all active logical
processors. (See Section 7.6.11.2., “Halt Idle Logical Processors”, for more information about
using the HLT instruction with IA-32 processors with Hyper-Threading Technology.)

7.6.9.2. PAUSE INSTRUCTION
The PAUSE instruction improves the performance of IA-32 processors with Hyper-Threading
Technology when executing “spin-wait loops” and other routines where one thread is accessing
a shared lock or semaphore in a tight polling loop. When executing a spin-wait loop, the
processor can suffer a severe performance penalty when exiting the loop because it detects a
possible memory order violation and flushes the core processor’s pipeline. The PAUSE instruction
provides a hint to the processor that the code sequence is a spin-wait loop. The processor
uses this hint to avoid the memory order violation and prevent the pipeline flush. In addition, the
PAUSE instruction de-pipelines the spin-wait loop to prevent it from consuming execution
resources excessively. The result of these actions is greatly improved processor performance.
(See Section 7.6.11.1., “Use the PAUSE Instruction in Spin-Wait Loops”, for more information
about using the PAUSE instruction with IA-32 processors with Hyper-Threading Technology.)

--Intel reference menual

추가로 pause instruction은 spinlock을 좀더 효율적으로 구현하는데, 필요하다고 한다.

리눅스에서는 poll_idle, default_idle, mwait 세가지 방법을 사용하는 듯 하다.

1. default_idle는 hlt 명령어를 이용하여 잠들어버리게 되고, 전력을 최소화할 수 있다.

2. poll_idle은 말그대로 무한 루프를 도는 것이다. 전력소모는 어쩔 수 없지만 깨어날 때 반응속도가 빠르다는 장점이 있다.

3. mwait의 경우는 monitor/mwait라는 instruction을 이용한다. 원래 이 명령어의 목적은 thread 동기화에 사용한다고 한다. monitor로 어떤 memory region을 감시하고 mwait로 기다리다가 해당 memory region에 값이 변경되는 이벤트가 발생하면, 깨어나는 매커니즘이다. 그러나 리눅스 Documentation에는 전력소모가 poll_idle과 별반 다르지 않다고 한다.

그러므로 별일 없이면 그냥 default_idle을 사용하면 된다.

idle=       [X86]
        Format: idle=poll, idle=mwait, idle=halt, idle=nomwait
        Poll forces a polling idle loop that can slightly
        improve the performance of waking up a idle CPU, but
        will use a lot of power and make the system run hot.
        Not recommended.
        idle=mwait: On systems which support MONITOR/MWAIT but
        the kernel chose to not use it because it doesn't save
        as much power as a normal idle loop, use the
        MONITOR/MWAIT idle loop anyways. Performance should be
        the same as idle=poll.
        idle=halt: Halt is forced to be used for CPU idle.
        In such case C2/C3 won't be used again.
        idle=nomwait: Disable mwait for CPU C-states

--Documentation/kernel-parameter.txt

Xen에서는 Guest의 idle을 hlt instruction으로 감지한다. HVM환경에서 hlt instuction이 VM Exit을 발생시키고 결국 do_block()을 통해서 블록 시키다. event가 발생하면 깨어나게 된다. 

만약 poll_idle로 guest를 설정한다면 아마 xen은 guest OS가 idle이라는 상황을 감지하지 못하고, CPU를 계속 소모하게 될 것이다. 직접 확인해보니 idle상태에서도 계속 CPU를 소모하는 것을 확인하였다.



screen 창에 command 날리기 Tips

screen을 잘 사용 하면, 여러모로 편리하다. 

예를 들어 여러개의 창의 동시에 여러개의 명령어를 보내고 싶을 경우, 

일일이 창을 옮겨 다녀가며 손으로 명령어를 치는 일은 정말 고달픈 일이다.

screen의 각 창에 명령어를 날려보자

screen창의 이름을 'temp'라고 가정하면,

$> screen -S temp -p 0 -X stuff '명령어^M'  // 스크린창 temp의 0번창에 명령어를 전달한다.

여기서 ^M은 말그대로 ctrl-M을 입력하라는 것이다. 그냥 ^M을 타이핑 하라는 것이 아니다.

참고: 

ssh key로 접속하기 Tips

$> sh-keygen -t rsa

를 실행하면, ~/.ssh/ 디렉토리에
id_rsa(private key)과 id_rsa.pub(public key)의 key pair가 생성된다.

이중 접속하고자 하는 서버쪽의 ~/.ssh/authorized_keys에 id_rsa.pub를 추가한다.

그러면 비밀번호 없이 key기반으로 ssh 접속을 할 수 있다.


1