On 9/20/05, Sanjay Kumar, Noida <sanjayku@xxxxxxxxxxxxxxxxx> wrote: > Hi, > > > >-----Original Message----- > >From: raja [mailto:vnagaraju@xxxxxxxxxxxx] > >Sent: Tuesday, September 20, 2005 5:26 PM > >To: kernel; fawadlateef@xxxxxxxxx > >Subject: Re: interrupts > > > >actually i am writing a module to sense the timer interrupt. > >Any way for every clock tick the timer updates the system time.I want > to > >find out the process's information that was running at the time the > >timer interrupt occures. > >I have registered my handler that prints simply a message when ever the > >timer interrupt occures.But it is not working.It is not printing any > >message. > > I couldn't get the usage of char device in your code. > See if this sample code helps you. Here I have: > ~~~~~~~~~~~ > > struct timer_list tick_timer; > void timer_func(unsigned int data) > { > /* > Do all the processing here > Print pid of the currently running task. > */ > mod_timer(&tick_timer, jiffies + 1); > } > > static int __init start_timer(void) > { > init_timer(&tick_timer); > tick_timer.expires = jiffies + 1; > tick_timer.function=timer_func; > add_timer(&tick_timer); > return 0; > } > > Static void __exit exit_timer(void) > { > del_timer(&my_timer); > } > module_init(start_timer); > module_exit(exit_timer); > ~~~~~~~~~~~~~~~~~~~~~~~~ I could not find the code in timer_interrupt() which actually schedules the timer on timer bottom half ..... can someone point out where it is .... it should be somewhere in timer_interrupt() or its children functions. Here is the code for timer_interrupt() ========================================== 221 static inline void do_timer_interrupt(int irq, void *dev_id, 222 struct pt_regs *regs) 223 { 224 #ifdef CONFIG_X86_IO_APIC 225 if (timer_ack) { 226 /* 227 * Subtle, when I/O APICs are used we have to ack timer IRQ 228 * manually to reset the IRR bit for do_slow_gettimeoffset(). 229 * This will also deassert NMI lines for the watchdog if run 230 * on an 82489DX-based system. 231 */ 232 spin_lock(&i8259A_lock); 233 outb(0x0c, PIC_MASTER_OCW3); 234 /* Ack the IRQ; AEOI will end it automatically. */ 235 inb(PIC_MASTER_POLL); 236 spin_unlock(&i8259A_lock); 237 } 238 #endif 239 240 do_timer_interrupt_hook(regs); 241 242 /* 243 * If we have an externally synchronized Linux clock, then update 244 * CMOS clock accordingly every ~11 minutes. Set_rtc_mmss() has to be 245 * called as close as possible to 500 ms before the new second starts. 246 */ 247 if ((time_status & STA_UNSYNC) == 0 && 248 xtime.tv_sec > last_rtc_update + 660 && 249 (xtime.tv_nsec / 1000) 250 >= USEC_AFTER - ((unsigned) TICK_SIZE) / 2 && 251 (xtime.tv_nsec / 1000) 252 <= USEC_BEFORE + ((unsigned) TICK_SIZE) / 2) { 253 /* horrible...FIXME */ 254 if (efi_enabled) { 255 if (efi_set_rtc_mmss(xtime.tv_sec) == 0) 256 last_rtc_update = xtime.tv_sec; 257 else 258 last_rtc_update = xtime.tv_sec - 600; 259 } else if (set_rtc_mmss(xtime.tv_sec) == 0) 260 last_rtc_update = xtime.tv_sec; 261 else 262 last_rtc_update = xtime.tv_sec - 600; /* do it again in 60 s */ 263 } 264 265 if (MCA_bus) { 266 /* The PS/2 uses level-triggered interrupts. You can't 267 turn them off, nor would you want to (any attempt to 268 enable edge-triggered interrupts usually gets intercepted by a 269 special hardware circuit). Hence we have to acknowledge 270 the timer interrupt. Through some incredibly stupid 271 design idea, the reset for IRQ 0 is done by setting the 272 high bit of the PPI port B (0x61). Note that some PS/2s, 273 notably the 55SX, work fine if this is removed. */ 274 275 irq = inb_p( 0x61 ); /* read the current state */ 276 outb_p( irq|0x80, 0x61 ); /* reset the IRQ */ 277 } 278 } 279 280 /* 281 * This is the same as the above, except we _also_ save the current 282 * Time Stamp Counter value at the time of the timer interrupt, so that 283 * we later on can estimate the time of day more exactly. 284 */ 285 irqreturn_t timer_interrupt(int irq, void *dev_id, struct pt_regs *regs) 286 { 287 /* 288 * Here we are in the timer irq handler. We just have irqs locally 289 * disabled but we don't know if the timer_bh is running on the other 290 * CPU. We need to avoid to SMP race with it. NOTE: we don' t need 291 * the irq version of write_lock because as just said we have irq 292 * locally disabled. -arca 293 */ 294 write_seqlock(&xtime_lock); 295 296 cur_timer->mark_offset(); 297 298 do_timer_interrupt(irq, NULL, regs); 299 300 write_sequnlock(&xtime_lock); 301 return IRQ_HANDLED; 302 } ========================================== regards, -Gaurav > > Sanjay > > > > > > > >I am listing my code below.Will you please help me > > > > > > > > > > > > > > > > > > > >#ifndef __KERNEL__ > > #define __KERNEL__ > >#endif > > > >#ifndef MODULE > > #define MODULE > >#endif > > > >#include <linux/kernel.h> > >#include <linux/init.h> > >#include <linux/module.h> > >#include <linux/fs.h> > >#include <linux/interrupt.h> > > > >MODULE_AUTHOR("RAJA"); > >MODULE_DESCRIPTION("TIMER INTERRUPT"); > >MODULE_LICENSE("GPL"); > > > >#define DEVICE_NAME "timer_interrupt" > >#define TIMER_INTERRUPT 0 > >static int __init init_timer_interrupt(void); > >static void __exit exit_timer_interrupt(void); > > > >static irqreturn_t timer_interrupt_handler(unsigned int,void *, struct > >pt_regs *); > > > >int devNo; > >struct file_operations fops = {}; > > > >static irqreturn_t timer_interrupt_handler(unsigned int irq,void *data, > >struct pt_regs *regs) > >{ > > printk("Timer Interrupt Occured\n"); > > return 0; > >} > > > >static int __init init_timer_interrupt() > >{ > > printk("Entered Into init_timer\n"); > > devNo = register_chrdev(0,DEVICE_NAME,&fops); > > > >request_irq(TIMER_INTERRUPT,timer_interrupt_handler,SA_SHIRQ,DEVICE_NAM > E,&d > >evNo); > > printk("Exited From init_timer\n"); > > return 0; > >} > > > >static void __exit exit_timer_interrupt() > >{ > > printk("Entered Into exit_timer\n"); > > unregister_chrdev(devNo,DEVICE_NAME); > > free_irq(TIMER_INTERRUPT,&devNo); > > printk("Exited From exit_timer\n"); > >} > > > >module_init(init_timer_interrupt); > >module_exit(exit_timer_interrupt); > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >On Tue, 2005-09-20 at 17:02 +0500, Fawad Lateef wrote: > >> On 9/20/05, raja <vnagaraju@xxxxxxxxxxxx> wrote: > >> > yaa. > >> > I have checked /proc/interrupts. > >> > But there it is given the interrupt numbers. > >> > > >> > actually the requirement is i am writing a module that it senses > when > >> > ever the interrupt occures and prints the interrupt number. > >> > > >> > Will you please help me. > >> > > >> > > >> > >> What sort of module you are writing ?? How you are going to sense > >> interrupts when they occurs ?? I think for getting signal through the > >> call-backed function from the kernel you have to register your > >> interrupt handlers, so that you can be notified by the kernel > ........ > >> > >> Or hack into the kernel, to get notified for each interrupt, but > AFAIK > >> your module can't get every single interrupt until you register them > >> with the kernel ........ > >> > >> Correct me if I m wrong !!!! > >> > >> > > > > > >-- > >Kernelnewbies: Help each other learn about the Linux kernel. > >Archive: http://mail.nl.linux.org/kernelnewbies/ > >FAQ: http://kernelnewbies.org/faq/ > > -- > Kernelnewbies: Help each other learn about the Linux kernel. > Archive: http://mail.nl.linux.org/kernelnewbies/ > FAQ: http://kernelnewbies.org/faq/ > > -- - Gaurav my blog: http://lkdp.blogspot.com/ -- -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/