Skip to contentSkip to conversation

Use of sti in entry.S question

DISCUSSION Andi Kleen 2 participants 2 messages May 22, 2003 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Andi Kleen

author
#1 lore raw
Quoted 17 lines · Duncan Sands

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

Quoted 2 lines

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

It's a mistake, but a harmless one. The scheduler turns off interrupts soon itself and the instructions it executes before that don't care. The only reason it's not recommended to call schedule with interrupts off is that the scheduler will turn them on again, usually breaking your critical section. In this case it's ok because the next instrution is a cli again.

-Andi

#2 lore raw

...

Quoted 9 lines
Quoted 2 lines

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

It's a mistake, but a harmless one. The scheduler turns off interrupts soon itself and the instructions it executes before that don't care. The only reason it's not recommended to call schedule with interrupts off is that the scheduler will turn them on again, usually breaking your critical section. In this case it's ok because the next instrution is a cli again.

Do you think it's worth pushing this fix?

arch/i386/kernel/entry.S +1 -0
diff -Nru a/arch/i386/kernel/entry.S b/arch/i386/kernel/entry.S
@@ -306,6 +306,7 @@
 	testb $_TIF_NEED_RESCHED, %cl
 	jz work_notifysig
 work_resched:
+	sti
 	call schedule
 	cli				# make sure we don't miss an interrupt
 					# setting need_resched or sigpending