Note that there are some explanatory texts on larger screens.

plurals
  1. POHow could I simulate the race condition scenario in an interrupt code
    text
    copied!<p>I am a beginner in learning Linux device driver. I wrote a keyboard driver:</p> <pre><code>#include &lt;linux/init.h&gt; #include &lt;linux/module.h&gt; #include &lt;linux/interrupt.h&gt; #include &lt;asm/io.h&gt; /* This function services keyboard interrupts. */ int packetNumber=3000; EXPORT_SYMBOL(packetNumber); irqreturn_t irq_handler (int irq, void *dev_id, struct pt_regs *regs) { static unsigned char scancode; /* Read keyboard status */ scancode = inb (0x60); if (scancode == 0x01) { packetNumber += 10; printk(KERN_ALERT "packetNumber:%x\n",&amp;packetNumber); printk (KERN_ALERT "You pressed Esc ! packetNumber: %d\n", packetNumber); } return (irqreturn_t) IRQ_HANDLED; } /* Initialize the module ? register the IRQ handler */ static int hello_keyboard (void) { /* Request IRQ 1, the keyboard IRQ, to go to our irq_handler SA_SHIRQ means we're willing to have othe handlers on this IRQ. SA_INTERRUPT can be used to make the handler into a fast interrupt. */ packetNumber += 10; printk(KERN_ALERT "hello, keyboard.%d\n", packetNumber); return request_irq (1, (irqreturn_t) irq_handler, SA_SHIRQ, "test_keyboard_irq_handler", (void *)(irq_handler)); } static void bye_keyboard(void) { printk(KERN_ALERT "Goodbye, keyboard\n"); } module_init(hello_keyboard); module_exit(bye_keyboard); MODULE_AUTHOR("e-Friends"); MODULE_LICENSE("Dual BSD/GPL"); MODULE_DESCRIPTION("a simple keyboard driver."); </code></pre> <p>I want to use this keyboard driver to simulate the race condition scenario like this: <a href="http://ww3.sinaimg.cn/mw690/5f10acdbjw1ealisec0frj20lk0e8gnm.jpg" rel="nofollow">http://ww3.sinaimg.cn/mw690/5f10acdbjw1ealisec0frj20lk0e8gnm.jpg</a></p> <hr> <p>I don't understand very much about the image above.</p> <blockquote> <p>For simulating the scenario, I want to know:</p> </blockquote> <ul> <li>Where the main_task function should be? in the driver, or a user application using the driver? </li> <li>If main_task function should be in the user application, how could I define the packetNumber variable to let both interrupt handler and user application can use this same variable?</li> </ul> <p>ps: I temporarily use the packetNumber variable in the init function(hello_keyboard function), does it right?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload