?? soft_irq2.c
字號:
/* * Written by Der Herr Hofrat, der.herr@hofr.at * (C) 2002 FSMLabs * License: GPL Version 2 */#include <rtl.h>#include <time.h>#include <pthread.h>#include <rtl_fifo.h>#include <unistd.h>#include "common.h"static pthread_t thread;static int my_softirq;hrtime_t call_time;hrtime_t last_time=0;hrtime_t max_diff=-200000;hrtime_t min_diff=200000;int ntests=500;int count=0;int fifo_size=4096;int rtf_fd;#define PERIOD 1000000void * start_routine(void *arg){ hrtime_t abstime = clock_gethrtime(CLOCK_REALTIME) + 1000000000; struct sched_param p; p . sched_priority = 1; pthread_setschedparam (pthread_self(), SCHED_FIFO, &p); rtf_fd = open("/dev/rtf0", O_NONBLOCK); if (rtf_fd < 0) { printk("/dev/rtf0 open returned %d\n", rtf_fd); return (void *)-1; } while (1) { clock_nanosleep (CLOCK_REALTIME, TIMER_ABSTIME, hrt2ts(abstime), NULL); call_time = clock_gethrtime(CLOCK_REALTIME);// rtl_global_pend_irq(my_softirq); pthread_kill (pthread_linux (), RTL_LINUX_MIN_SIGNAL+my_softirq); abstime += PERIOD; } return 0;}static void my_handler(int irq,void *ignore,struct pt_regs *ignoreregs){ hrtime_t diff; struct sample samp; hrtime_t now = clock_gethrtime(CLOCK_REALTIME); diff = now - call_time; if( count < ntests){ if( diff > max_diff ){ max_diff = diff; } if( diff < min_diff ){ min_diff = diff; } } else { samp.min = min_diff; samp.max = max_diff; write(rtf_fd,&samp,sizeof(samp)); count=0; max_diff=-200000; min_diff=200000; } count++;}int init_module(void){ int ret; rtf_destroy(0); ret=rtf_create(0,fifo_size); if(ret){ printk("rtf_create failed\n"); return -1; } ret=pthread_create( &thread, NULL, start_routine, 0); if(ret){ printk("pthread_create failed\n"); return -1; } my_softirq=rtl_get_soft_irq( my_handler, "sofirq jitter test"); if(ret < 0){ /* actually irq 0 never can be legal ither...*/ printk("rtl_get_soft_irq failed with %d\n",-ret); return -ret; } return 0;}void cleanup_module(void) { rtl_free_soft_irq(my_softirq); pthread_cancel(thread); pthread_join(thread,NULL); close(rtf_fd); rtf_destroy(0);}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -