Disabling IRQs doesn't works [SOLVED]

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
narke
Member
Member
Posts: 119
Joined: Wed Dec 26, 2007 3:37 am
Location: France

Disabling IRQs doesn't works [SOLVED]

Post 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
Last edited by narke on Fri May 06, 2011 11:14 am, edited 1 time in total.
OS for PowerPC Macs: https://github.com/narke/Einherjar
Operating system: colorForth computing environment for x86.: https://github.com/narke/Roentgenium
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Disabling IRQs doesn't works

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
narke
Member
Member
Posts: 119
Joined: Wed Dec 26, 2007 3:37 am
Location: France

Re: Disabling IRQs doesn't works [SOLVED]

Post 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.
OS for PowerPC Macs: https://github.com/narke/Einherjar
Operating system: colorForth computing environment for x86.: https://github.com/narke/Roentgenium
Post Reply