typedef struct attribute packed xxxctrl int xxxopenstruct inode
여러 프로세스를 사용하는 시스템 • 프로세스별 데이터 관리 typedef struct { : } _ _ attribute _ _ ((packed)) xxx_ctrl; //관리 구조체 int xxx_open(struct inode *inode, struct file *filp) { file ->private_data = kmalloc(sizeof(xxx_ctrl), GFP_KERNEL); } ssize_t xxx_write(struct file *filp, const char *buf, size_t count, loff_t *f_pos) { xxx_ctrl *p. Data; p. Data = (xxx_ctrl *) filp->private_data; : } 프로세스별 관련 처리 비선점형 커널의 경우 //각 프로세스가 open시 메모리 할당 후 private_data에 대입하여 처리 : ssize_t xxx_read(struct file *filp, char *buf, size_t count, loff_t *f_pos) { xxx_ctrl *p. Data; p. Data = (xxx_ctrl *) filp->private_data; : } 단일 프로세스를 위한 디바이스 드라이버 선점형 커널의 경우 int xxx_release(struct inode *inode, struct file *filp) { xxx_ctrl *p. Data; p. Data = (xxx_ctrl *) filp->private_data; : kfree(filp -> private_data); //할당된 메모리 해제 : } 6/11
여러 프로세스를 사용하는 시스템 • 프로세스 재진입 • 해결방법 • 함수 내부에서 전역변수 사용 변경 int xxx_cnt = 0; ssize_t xxx_read(struct file *filp, char *buf, size_t count, loff_t *f_pos) { int local_cnt = 0; int old_cnt = xxx_cnt; 단일 프로세스를 위한 디바이스 드라이버 프로세스별 관련 처리 비선점형 커널의 경우 while(local_cnt < 10) { interruptible_sleep_on(&wait. Queue_read); local_cnt += (xxx_cnt – old_cnt); } return 0; } 8/11
Qna 12/29
- Slides: 13