CONFIG_PREEMPT x86 assembly question

From: Nikita V. Youshchenko (yoush_at_cs.msu.su)
Date: 11/20/04

  • Next message: Jim Nelson: "Re: [2.6 patch] remove obsolete Computone MAINTAINERS entry (fwd)"
    To: linux-kernel@vger.kernel.org
    Date:	Sat, 20 Nov 2004 17:43:11 +0300
    
    

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    Hello

    Whily lazy-examining kernel code, I found the following interesting point.

    In arch/i386/kernel/entry.S

    ...
    ENTRY(resume_kernel)
     cmpl $0,TI_preempt_count(%ebp) # non-zero preempt_count ?
     jnz restore_all
    need_resched:
     movl TI_flags(%ebp), %ecx # need_resched set ?
     testb $_TIF_NEED_RESCHED, %cl
     jz restore_all
     testl $IF_MASK,EFLAGS(%esp) # interrupts off (exception path) ?
     jz restore_all
     movl $PREEMPT_ACTIVE,TI_preempt_count(%ebp)
     sti
     call schedule
     movl $0,TI_preempt_count(%ebp)
     cli
     jmp need_resched
    #endif
    ...

    Why, after return from schedule(), first 0 is written to
    TI_preempt_count(%ebp), and only then interrupts are disabled?
    Wht not the reverse order?

    As far as I understand, the idea of the preempt_count flag is to avoid
    nested preemts. The fact that flag is reset before interrupts are
    disabled, somewhat breaks this: interrupt may happen just after flag is
    reset, causing nested interrupt while preempt_count flag is already reset.
    In a very unprobable case this could happen unlimited number of times,
    causing kernel stack overflow.

    Very unprobable? But couldn't this be the cause of kernel lockups I
    suffered several times while writing DVD on a probably broken media (which
    could cause interrupt storm)?..
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.2.4 (GNU/Linux)

    iD8DBQFBn1jSv3x5OskTLdsRAu/lAKCCqeNbJSkhC4W3iWawjm4vctOzpwCeN7vX
    Cjk39KRgRSnjN8ktKGCfoUA=
    =XvKR
    -----END PGP SIGNATURE-----
    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/


  • Next message: Jim Nelson: "Re: [2.6 patch] remove obsolete Computone MAINTAINERS entry (fwd)"

    Relevant Pages

    • RE: Maximum frequency of re-scheduling (minimum time quantum) que stio n
      ... >interrupt will also schedule if necessary. ... >>The catch here is, without the preemptable kernel option, the kernel ... Even with the option, it can't preempt ...
      (Linux-Kernel)
    • Re: -rt more realtime scheduling issues
      ... are not delivered during __schedule processing. ... IPI' case where NEED_RESCHED is only set by the handler. ... where we 'reschedule' on a specific CPU the flag is set and IPI sent. ... schedule while coming back out of the interrupt handler as a preemption ...
      (Linux-Kernel)
    • Re: How linux schedules things when interrupts occur
      ... kernel deals with scheduling it's work. ... Suppose Linux is running on a single CPU system. ... When an APIC processed hardware interrupt comes and assuming the ... Then schedule is called and it will most likely schedule another process. ...
      (Linux-Kernel)
    • Re: __wait_event_interruptible question
      ... > I got the next macro from sched.h from kernel 2.4.23_pre5. ... > from an interrupt service routine, I think it is possible that the ... lose the CPU before it calls schedule(). ... how it would work with preemption. ...
      (comp.os.linux.development.system)
    • Re: kernel: return from interrupt
      ... why does the kernel refuse to schedule on ... > PREEMPTION turned on in 5.x you should see the same behavior. ... > interrupt handler. ...
      (freebsd-current)