QNX에서 Linux로 장치 드라이버를 이식 중입니다. QNX에서 이전 드라이버는 실제 인터럽트 핸들러를 등록하는 대신 인터럽트 발생을 모니터링하기 위해 무한 루프가있는 pthread를 사용했습니다. 전용 폴링 쓰레드 대신에 register_irq()를 사용하는 것의 효과를 증명하기 위해 리눅스에서 두 개의 드라이버를 썼다. 각각에 대한 관련 코드는 아래에 나와 있으며 질문은 맨 아래에 있습니다.Linux 외부 이벤트 처리 - IRQ 대 폴링 kthread
IRQ
핸들러
irqreturn_t timing_interrupt_handler(int irq, void *dev_id) {
u32 test;
/* read device interrupt command/status register */
test = ioread32(timing_card[3].base);
/* sanity check that the device reported the interrupt */
if (test & (1 << 2)) {
/* clear interrupt status */
iowrite32(0x0d, timing_card[3].base);
/* toggle digital output line */
test = ioread32(timing_card[2].base);
if (test & 0x01)
iowrite32(test & ~0x1, timing_card[2].base);
else
iowrite32(test | 0x1, timing_card[2].base);
}
return IRQ_HANDLED;
}
등록을 핸들러를 작성
rc = request_irq(irq_line, timing_interrupt_handler,
IRQF_SHARED, "timing", timing_card);
if (rc) {
printk(KERN_ALERT "Failed to register irq %d\n", irq_line);
return rc;
}
폴링 스레드
스레드 기능을 쓰기
int poll_irq(void *data) {
u32 test;
/* until module unload */
while (!kthread_should_stop()) {
/* read device interrupt command/status register */
test = ioread32(timing_card[3].base);
/* sanity check that the device reported the interrupt */
if (test & (1 << 2)) {
/* clear interrupt status */
iowrite32(0x0d, timing_card[3].base);
/* toggle digital output line */
test = ioread32(timing_card[2].base);
if (test & 0x01)
iowrite32(test & ~0x1, timing_card[2].base);
else
iowrite32(test | 0x1, timing_card[2].base);
}
else
usleep_range(9, 11);
}
return 0;
}
스레드
kthread = kthread_create(poll_irq, 0x0, "poll_IRQ_test");
wake_up_process(kthread);
을 시작
내가 오실로스코프에 두 개의 흔적을 넣어 질문
- (인터럽트를 발생하게됩니다) 카드의 디지털 입력을 모니터링 하나 하나 개 모니터링 카드의 디지털 출력 (인터럽트에 반응하는) 이벤트에 대한 반응 시간을 측정 할 수 있습니다.
IRQ를 등록하는 첫 번째 "적절한"방법은 약 80 마이크로 초가 걸립니다.
두 번째 방법은 무한 스레드를 실행하는 데 약 15-30 마이크로 초가 걸립니다.
무엇을 제공합니까? 첫 번째 이점은 처리 능력을 낭비하지 않는다는 것입니다.하지만 응답 시간이 왜 그렇게 급격하게 저하됩니까? 이 폴링 쓰레드를 갖는 것이 정말 얼마나 나쁜가요? 폴링 스레드가 CPU에 쏟아 부는 추가 대가를 어떻게 조사하고 결국 시연 할 수 있습니까?
시간 내 주셔서 감사합니다.
베스트
스콧
예. http://lwn.net/images/pdf/LDD3/ch17.pdf 섹션 "수신 인터럽트 완화"에서 네트워크 드라이버에 대해 설명합니다. –