2012년 10월 26일 금요일

request_threaded_irq


int __must_check
request_threaded_irq(unsigned int irq, irq_handler_t handler,
             irq_handler_t thread_fn,
             unsigned long flags, const char *name, void *dev);


  • irq 에 따라서 handler, thread_fn 을 돌려달라고 등록하기.



  • handler 에 NULL을 넣으면 default handler(irq_default_primary_handler) 가 불려 thread_fn 이 수행되는 동안 해당 irq 를 disable 상태로 만들어둔다. return 은 IRQ_WAKE_THEAD.
    • 참고하여 handler function 을 만들도록 해야겠다. 또한, thread_fn 안에서는 irq 를 enable 해주도록 할 것.



  • 왜 handler 와 thread_fn 두 개인가?
    • thread_fn 을 NULL 로 넣어도 상관없음.
      • 이 경우 그냥 request_irq 와 같음.



예제: mmc host 에서 새로운 mmc card 인식을 위하여 gpio 를 irq 로 연결할 때.



linux version 2.6x  도입.

2012년 7월 31일 화요일

bluetooth stack 분석

Android : bluez 를 이용
* bluez 구성
* linux kernel (net/bluetooth ) 부분에 hci command 를 이용한 l2cap 이 구현되어 있음.
* library 형태로 profile 들이 구현되어 있음.
* bluetoothd 라는 daemon 을 띄우고 d-bus 를 통해 android platform 과 통신함.
* sdp tree 관련 처리는 tool을 이용해서 따로 하고 있음.

Windows 7,8
* MS 에서 구현 bthport.sys 라는 port 가 있고 여기에 miniport 로 bthusb.sys 랑 bthuart.sys 같은게 있음. ( l2cap 이 여기서 다 구현되어 있음)

- 참고
bthusb 등이 bthport 에 있는 함수를 직접 부를 형태여서 이 사이에 filter를 달거나 할 수 없음.
따라서 당연히 device tree 를 확인하는 툴로 봐도 bthport.sys는 안보임.

* profile 들도 driver 형태로 구현함
* BRB 라고 bluetooth request block 을 만들어서 ioctl로 내리면 알아서 처리해줌.
* sdp tree 관련해서 처리하는 inteface 를 비슷한 layer에서 제공해줌.

2012년 4월 25일 수요일

unlink 시에는 negative dentry 가 생기지 않는다

lookup 시에 찾으려는 file 이 없으면 dentry 가 가르키는 (vfs) inode 를 NULL 로 만들어둔다.

이런 dentry는 nagative dentry 가 되어서 다음 번 lookup에 활용된다.


unlink 시에는 inode 를 없애야 하는데, 이 때 dentry 가 가르키는 inode만 없애는 것이 아니라

dentry 까지 같이 free 한다.

2012년 4월 3일 화요일

linux getdents (readdir) 의 callback filldir 에 대하여

readdir 
linux 에서 directory file 의 내용을 읽기 위하여 사용하는 API 이다.


대표적으로는 ls 가 readdir을 통해서 구현되었다고 생각하면 된다.
실제로 사용하는 syscall 은 getdents 이다. 


이름으로 보면 getdent's' 복수형이다. 
즉, readdir을 directroy file 내용을 하나씩 읽어오고
getdents는 여러개씩 읽어오도록 되어있다.


당연히 getdents 가 성능이 더 좋다.


내부의 구현을 보면 둘다 vfs_readdir() 을 부르게 되는데, 다만 이 때 넘겨주는 callback fuction 인 filler (readdir은  fillonedir, getdents는 filldir) 의 차이로 구분하게 된다.

여기서 남기고 싶은 이야기는


getdents 가 넘거주는 filldir 에 d_type 에 대한 것이다.



static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
  u64 ino, unsigned int d_type)


뭐하는데 쓰이는 지 봤는데, 오로지 ext2,3,4, Btrfs 만 을 위한 field 같이 보인다.
다른 인자들은 특별할 것이 없이 fs 가 name, len, offset, ino 를 주면 buf 에 미리 약속된 형태(linux_dirent)로 적절히 넣어준다.
이 때 마지막에 d_type을 넣어주는데. 이것을 보고  block device, character device 인지 directory 인지 혹은 named pipe 인지 따위의 정보를 알 수 있다. 


http://linux.die.net/man/2/getdents 보면,
"Currently, only some file systems (among them: Btrfs, ext2, ext3, and ext4) have full support for returning the file type in d_type. All applications must properly handle a return of DT_UNKNOWN."


라고 되어있다.  


vfs code를 보다보니 Btrfs만을 위한 특별한 code가 들어있을 만큼 linux에서 Btrfs에게 신경을 써주는 거 같은데, 혹시나 이것도 그런 것일까? d_type 은 대체 무슨 이득이 있어서 넣어둔 것일까 궁금하다.