LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 11-26-2015, 12:10 AM   #1
Yunas Rashid
LQ Newbie
 
Registered: Nov 2015
Posts: 1

Rep: Reputation: Disabled
Keyboard interrupts missed in a kernel module


Hi all,

I was working on a project where I was doing some action based on the keyboard interrupt received. So I registered for the keyboard interrupt and mark the interrupt as shared. But my program wasnt working as it should. To debug the issue, I wrote a small program that just registers for the keyboard interrupt and outputs some message to kernel when interrupt from keyboard is received. But I found out a lot of interrupts from keyboard are missed when interrupt rate is high. For example, in the sample code below, I register for the interrupt and output message to kernel when either Esc or A is pressed. From the counter value, the total number of interrupts are less than the actual number of interrupts geenrated by keyboard. I found this out by echoing the keypress to a terminal and counting the number of a's echoed to the terminal. So for example if there are 350 echoed a's on the terminal, the count will only be around 300-320. Same goes for higher number of interrupts. The larger the number of interrupts, the more interrupts are missed but the percentage of interrupts missed seems to be nearly equal in all cases. Can someone please explain what is the reason for this behaviour? Thanks in advance. Below is source code.

Code:
#include <linux/kernel.h>
#include <linux/interrupt.h>
#include <linux/module.h>
#include <linux/signal.h>
#include <asm/io.h>

/*
 The keyboard ISR
*/
irq_handler_t irq_handler (int irq, void *dev_id, struct pt_regs *regs)
{
        static int count = 0;
	static unsigned char scancode;
	
	scancode = inb (0x60);

	if (0x1E == scancode)
	{
                count++;
		printk ("\nKeyboard key 'a' pressed !");
	}

	return (irq_handler_t) IRQ_HANDLED;
}

/*
 Register IRQ handler
*/
int init_module ()
{
	return request_irq (1, (irq_handler_t) irq_handler, IRQF_SHARED, "kbd_irq_handler", (void *)(irq_handler));
}


MODULE_LICENSE ("GPL");
 
Old 11-27-2015, 08:03 AM   #2
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,671
Blog Entries: 4

Rep: Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945
First of all, don't do printk() ... don't do anything "else" ... in the IRQ handler.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Kernel code: calling suspend to ram function from keyboard module belvy Linux - Kernel 11 05-18-2012 07:12 AM
[SOLVED] Install older kernel module into newer kernel - no symbol version for module bayoulinux Linux - Kernel 4 10-26-2011 04:32 AM
Lost DMA interrupts (2.6 kernel) cgr Linux - Hardware 1 02-16-2007 04:19 PM
linux kernel module for seriell keyboard kostja1 Programming 0 04-05-2004 12:01 PM
Kernel compilation, what module did I missed ? Kocil Linux - Software 7 08-10-2003 06:03 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 03:47 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration