Page 1 of 1

Disabling IRQs doesn't works [SOLVED]

Posted: Thu May 05, 2011 1:42 pm
by narke
Hello,

I'm writing a round robin scheduler for kernel threads.
I'm disabling interrupts before processing threads in a scheduler and enable them after the scheduler routine executed but IRQs aren't disabled: an assert reports it.
There is the code:

Code: Select all

void timer_interrupt_handler(int interrupt_id)
{        
    static int tick = 0;
    static int sec = 0;
    uint32 flags;
                        
    tick++;
    vga_display_string("Tick:%d\n", tick);
                                
    if (tick % 100 == 0)
    {
        sec++;
        tick = 0;
    }
    
    x86_irq_disable_all(flags);                                                                               
    schedule();
    x86_irq_restore_all(flags);
                                                                                                
    /* Execute the expired timeout actions (if any) */
    /*
    if ( time_do_tick() != KERNEL_OK)
        vga_display_string("time subsystem error!\n");*/
                                                                                                                  
}
I also tried with

Code: Select all

__asm__ __volatile__("cli\n");   
and

Code: Select all

 __asm__ __volatile__("sti\n");
but the result is the same.

The IRQs #defines are:

Code: Select all

#define x86_save_flags(flags) \
    asm volatile("pushfl ; popl %0":"=g"(flags)::"memory")

#define x86_restore_flags(flags) \
    asm volatile("push %0; popfl"::"g"(flags):"memory")

#define x86_irq_disable_all(flags)    \
    ({ x86_save_flags(flags); asm("cli\n"); })

#define x86_irq_restore_all(flags)    \
    x86_restore_flags(flags)
I have not idea where I failed. Does someone has an idea please?

The whole code: http://versatile.git.sourceforge.net/gi ... ;a=summary
Interrupt part: http://versatile.git.sourceforge.net/gi ... 0d705af344
IRQ part: http://versatile.git.sourceforge.net/gi ... 0d705af344

Re: Disabling IRQs doesn't works

Posted: Thu May 05, 2011 3:00 pm
by Combuster
If you are referring to the following assertion:

Code: Select all

  69         /* Interrupt handlers are NOT allowed to block ! */
  70         KERNEL_FATAL_ASSERTION(!irq_is_servicing());
You forgot to realize that disabling interrupts does not magically undo interrupts that have already happened: you are calling the scheduler from the context of an interrupt and yet demand that no interrupt (the timer in this case) may currently take place.

That leads us to the next problem: the comment says that the code can't block. However there is no apparent locking in the scheduler.

Re: Disabling IRQs doesn't works [SOLVED]

Posted: Fri May 06, 2011 11:17 am
by narke
Thank you very much Combuster, my mistake comes from porting an old code and due to inattention.
Now it just works, I can work on other things now.