OS/Linux 144

work queue

작업 큐 소개 작업 큐는 2.5 버전의 Linux 커널에 추가된 최신 지연 메커니즘이다. 한번에 모든 작업을 처리하는 지연 스키마를 제공하는 태스크릿과는 달리 작업 큐는 작업 큐에 대한 핸들러 함수가 대기 상태에 있을 수 있는(태스크릿 모델에서는 가능하지 않음) 제네릭 지연 메커니즘이다. 작업 큐는 태스크릿보다 높은 지연 시간을 가질 수 있고 더 다양한 작업 지연 API를 포함하고 있다. 지연은 keventd를 통해 태스크 큐에 의해 관리되었지만 이제는 events/X라는 커널 작업자 스레드에 의해 관리된다. 작업 큐는 기능을 하반부로 지연시킬 수 있는 일반적인 방법을 제공한다. 중앙에 있는 작업 큐(struct workqueue_struct)는 작업이 배치되는 구조체이다. 작업은 work_struct ..

OS/Linux 2010.05.24

Ubuntu 설치 버전 확인

Ubuntu의 경우, patch도 많이되고,.. 설치 버전도 많이 틀리다. Ubuntu manual page(http://manpages.ubuntu.com/) 에서도 6개의 버전을 다 표시해준다. (6.06 LTS/ 8.04 LTS / 8.10 / 9.04 / 10.04 LTS ) 설치된 ubuntu 버전은 어떻게 확인할까?? $ uname -a 이걸로는 커널의 버전을 알수 있다. Ubuntu의 버전은 $ cat /etc/issue Ubuntu 10.04 LTS \n \l 위와 같이 표시해 준다. 참고로, ubuntu manual 에서 kqueue의 page는 http://manpages.ubuntu.com/manpages/lucid/en/man2/kqueue.2freebsd.html 요기임.. 휴~ ..

OS/Linux 2010.05.14

Kqueue 관련 함수

kqueue를 사용하려면 밑의 해더를 추가해야 합니다. #include #include #include int kqueue( void ); 설명 : 새로운 kernel event queue를 생성하고 해당 descriptor를 반환한다. 해당 queue는 fork()된 자식이 상속할 수 없다. 하지만 RFFDG 플래그를 쓰지 않고 rfork()를 호출한 경우에는 해당 descriptor table을 공유할 수 있다. 이렇게 해서 두개의 다른 process들이 한 kernel queue를 공유하게 된다. 리턴값 : error가 나면 -1을 리턴하고, errno 를 설정한다. 성공하면 kqueue의 descriptor을 리턴한다. int kevent( int kq, // [in] kqueue() 함수가 반환..

OS/Linux 2010.05.14

kthread - linux kernel 용

kthread를 이용한 thread 생성 test 한 source 샘플 코드가 별로 없어서.. 참조해서 구현 했음 좋겠다. [kthread1.c] #include #include #include #include #include #include struct task_struct *ts; int thread1(void *data) { int count =0; while(1) { count++; printk(KERN_ALERT "Hi!! I am kernel thread1[%d]!\n", count ); msleep(1000); if (kthread_should_stop()) break; } return 0; } int init_module(void) { printk(KERN_INFO "init_module(..

OS/Linux 2010.05.14

Kqueue 예제 - Echo.c

kqueue를 이용한 예제임. 내가 필요한 소스 이긴 한데.. 이번엔 잘 돌아갈려나..ㅠㅠ 아무튼 참조 하고,, 공부 하자 아자아자..!! /* echo.c - Simple `echo' server for N clients written using kqueue/kevent. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include typedef struct in_addr in_addr; typedef struct sockaddr_in sockaddr_in; typedef struct servent servent; typedef str..

OS/Linux 2010.05.14

Thread deatch

int pthread_detach(pthread_t th); detach 는 "떼어내다" 라는 뜻을 가지며 main 쓰레드에서 pthread_create 를 이용해 생성된 쓰레드를 분리시킨다. 이 함수는 식별번호th인 쓰레드를 detach 시키는데, detach 되었을경우 해당(detach 된) 쓰레드가 종료될경우 pthread_joinc 을 호출하지 않더라도 즉시 모든 자원이 해제(free) 된다. 여기에서는 pthread_create 호출후 detach 하는 방법을 설명하고 있는데, pthread_create 호출시에 쓰레드가 detach 되도록 할수도 있다. [pthread_detach.c] #include #include #include #include // 쓰레드 함수 // 1초를 기다린후 아규..

OS/Linux 2010.05.12

Kernel thread test[정말 간단한]

Thread의 개념도 완전하지 않은 상태에서 Linux kernel Thread를 만든 내용 정말 초 간단.. 한 소스 1초마다 2개의 thread에서 값을 출력하는 사항. pthread_create 와 pthread_join 함수 사용 cpp를 컴파일 하기 위해서 g++를 사용했다. 그냥 gcc로 컴파일 하면, pthread 관련한 함수 들이 undefined로 출력된다. [pthread_create.cpp] #include #include #include #include // 쓰레드 함수 void *t_function(void *data) { int id; int i = 0; id = *((int *)data); while(1) { printf("%d : %d\n", id, i); i++; sleep..

OS/Linux 2010.05.12

Linux kernel Threads

Purpose Linux Device Driver 개발하면서, Kernel Thread를 creat 하고 stop 하는 방법을 test 해보기 위함. 해외 사이트의 오픈 소스를 참조(거의 copy하여 Test 함) 한 것으로, 자세한 테클은 정중히 거절합니다..ㅠㅠ (허접의 슬픔..흑흑) (Ref. : http://www.scs.ch/~frey/linux/kernelthreads.html ) The driver is implemented as a loadable module. In the init_module() routine five kernel threads are created. This kernel threads sleep one second, wake up, print a message and ..

OS/Linux 2010.05.12