Subject: Re: Bug in timeout()/untimeout() ?
To: enami tsugutomo <enami@sm.sony.co.jp>
From: Manuel Bouyer <bouyer@antioche.lip6.fr>
List: tech-kern
Date: 04/14/2000 12:14:05
On Fri, Apr 14, 2000 at 11:27:51AM +0900, enami tsugutomo wrote:
> Since there is a function call between each test of calltodo.c_next,
> the sane compiler shouldn't assume it can be cached.  At least 1.4.2

in scsipi, xs_status was changed to 'volatile' (commit message:
revision 1.5
date: 1997/11/20 04:09:19;  author: thorpej;  state: Exp;  lines: +2 -2
Declare the scsipi_xfer's "flags" member to be volatile, to force it
to be reloaded every time it is checked.  This avoids a condition where
it can be cached in a register in such a way that updates to the flags in
an interrupt handler to not be noticed, which in turn causes the process
doing the i/o to sleep forever.  Bug report and suggested fix from
Hiroshi HORIMOTO <horimoto@cs-yuugao.cs.sist.ac.jp>, PR $4460.

because of this code:
                s = splbio();
                while ((xs->xs_status & XS_STS_DONE) == 0)
                        tsleep(xs, PRIBIO + 1, "scsipi_cmd", 0);
                splx(s);

And tsleep *is* a function call. The case here is quite similar.

> compiler wit -O2 generates following assember code and it looks like
> doing memory access each time.
> 
>    583	.globl _softclock
>    584		.type	 _softclock,@function
>    585	_softclock:
>    586		pushl %ebp
> 	:
>    597		movl _calltodo,%edx
>    598		movl %ecx,%edi
>    599		notl %edi
>    600		testl %edx,%edx
>    601		je L178
>    602		.align 2,0x90
>    603	L184:
>    604		cmpl $0,12(%edx)
>    605		jg L178
> 	:
>    618		call _Xspllower
>    619	L182:
>    620		pushl %ebx
>    621		call *%esi
>    622		addl $4,%esp
>    623		movl _cpl,%eax
>    624		orl _imask+4,%eax
>    625		movl %eax,_cpl
>    626		movl _calltodo,%edx
>    627		testl %edx,%edx
>    628		jne L184
>    629	L178:
> 	:

What happens with other processors and/or more agressive compiler flags ?
Say, on shark (Hi Ignatios :) ?

--
Manuel Bouyer, LIP6, Universite Paris VI.           Manuel.Bouyer@lip6.fr
--