cli () + interruptible_sleep_on_timeout () on 2.4
From: Learning Stuff (dude10939_at_yahoo.com)
Date: 08/26/04
- Next message: Kasper Dupont: "Re: Rentrant and Pre-emptive Kernels"
- Previous message: Robert Redelmeier: "Re: Rentrant and Pre-emptive Kernels"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 26 Aug 2004 09:35:06 -0700
Assume 2.4 kernel.
Assume an user space task has to read some data from a device. So it
invokes read system call, which in turn invokes my module's
"wait_for_interrupt_before_proceeding" function.
User space task has to wait for a interrupt before proceeding further.
Here is some dummy code that I have come across, but not sure how this
works.
==============
static wait_queue_head_t my_wait_q;
int my_module_init()
{
...
init_waitqueue_head(&my_wait_q);
request_irq(my_irq_num, my_isr, 0, "my_dev_name", NULL);
...
}
void my_isr(int irq, void *dev_id, struct pt_regs * regs)
{
/* Some code goes here */
wake_up_interruptible(&my_wait_q);
}
void wait_for_interrupt_before_proceeding()
{
unsigned long flags;
save_flags(flags);
cli();
/* Calling task needs to wait for interrupt b4 proceeding */
interruptible_sleep_on_timeout(&my_wait_q,1*HZ);
/* ### */
/* Some code goes here */
restore_flags(flags);
return;
}
Could someone please explain why do we need
save_flage-cli-restore-flags calls here?
cli() is supposed to disable all interrupts on all CPUs in the system.
So if wait_for_interrupt_before_proceeding() is called on behalf of a
user space task, all interrupts are disabled by cli() when control
reaches to interruptible_sleep_on_timeout() and thus
interruptible_sleep_on_timeout will not return if my_irq interrupt
occurs.
I think that control will reach at code marked by /* ### */ above,
only if:
1. Interrupt my_irq occurs within 1sec OR
2. after 1sec if no interrupt occurs.
Am I correct?
In above code, interruptible_sleep_on_timeout can only return after
timeout (1sec) because all intrs were already disabled by cli().
Am I correct?
Could someone please explain control flow of above code? I am not sure
how above code works.
and whether is this the correct way and do we really need
save_flage-cli-restore-flags calls here.
Regards
- Next message: Kasper Dupont: "Re: Rentrant and Pre-emptive Kernels"
- Previous message: Robert Redelmeier: "Re: Rentrant and Pre-emptive Kernels"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|