Skip to contentSkip to conversation

Use of sti in entry.S question

DISCUSSION Duncan Sands 1 participant 2 messages May 22, 2003

lore
Share & tools
lore
#0 lore raw

2.5/arch/i386/kernel/entry.S:

In work_resched, schedule may be called with
interrupts off:

work_resched:
call schedule
cli # make sure we don't miss an interrupt
# setting need_resched or sigpending # between sampling and the iret
movl TI_FLAGS(%ebp), %ecx
andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
# than syscall tracing?
jz restore_all
testb $_TIF_NEED_RESCHED, %cl
jnz work_resched <====== schedule with interrupts disabled

Is this a mistake or an optimization? Elsewhere in entry.S, interrupts are turned on before calling schedule:

#ifdef CONFIG_PREEMPT
ENTRY(resume_kernel)
cmpl $0,TI_PRE_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_PRE_COUNT(%ebp) sti <====== schedule with interrupts enabled call schedule
movl $0,TI_PRE_COUNT(%ebp)
cli
jmp need_resched
#endif

Thanks,

Duncan.

#1 lore raw

Another use of sti in entry.S question

Here is another place where interrupts get turned on in a called function:

work_resched disables interrupts and falls through to work_notifysig. work_notifysig calls do_notify_resume.
do_notify_resume calls do_signal.
do_signal calls get_signal_to_deliver. get_signal_to_deliver does an spin_unlock_irq before returning, enabling interrupts.

Is this a bug?

work_resched:
sti
call schedule
cli # make sure we don't miss an interrupt
# setting need_resched or sigpending # between sampling and the iret
movl TI_FLAGS(%ebp), %ecx
andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
# than syscall tracing?
jz restore_all
testb $_TIF_NEED_RESCHED, %cl
jnz work_resched

work_notifysig: # deal with pending signals and

                                        # notify-resume requests
        testl $VM_MASK, EFLAGS(%esp)
        movl %esp, %eax
        jne work_notifysig_v86          # returning to kernel-space or
                                        # vm86-space
        xorl %edx, %edx
        call do_notify_resume <== may enable interrupts
        jmp restore_all

ALIGN
work_notifysig_v86:
pushl %ecx
call save_v86_state
popl %ecx
movl %eax, %esp
xorl %edx, %edx
call do_notify_resume <== may enable interrupts jmp restore_all