2002-03-27 00:20:12

by Melkor Ainur

[permalink] [raw]
Subject: signal_pending() and schedule()

Hello all,

I have been writing a hw driver for SAN. In my
implementation of tcp_sendmsg, I attempt to force
the application to sleep until the data buffer has
been dma-ed:


if (signal_pending(current)) {
return -ERESTARTSYS;
}
// no signal was pending

// timeo == MAX_SCHEDULE_TIMEOUT in this case
timeo = schedule_timeout(timeo);
// signal is always pending
if (signal_pending(current)) {
return -ERESTARTSYS;
}
This works fine for some applications like netcat,etc
but fails for netscape. In debugging this, I observe
that after calling schedule_timeout(), the sigpending
bit appears to be set immediately and thus
schedule() doesn't actually put the process to sleep.
I will continue to look for where schedule_timeout()
or schedule() could affect sigpending. In the mean
time, I am hoping for any hints/suggestions that could
help me solve this issue of why schedule_timeout
appears to affect sigpending. (2.4.7-10smp on x86)

Thanks,
Melkor



__________________________________________________
Do You Yahoo!?
Yahoo! Movies - coverage of the 74th Academy Awards?
http://movies.yahoo.com/


2002-03-27 00:36:53

by Alan

[permalink] [raw]
Subject: Re: signal_pending() and schedule()

> but fails for netscape. In debugging this, I observe
> that after calling schedule_timeout(), the sigpending
> bit appears to be set immediately and thus

It means a signal was delivered

> schedule() doesn't actually put the process to sleep.

Because the signal is pending. The kernel is expecting to return or take
some action and return to user space if its an interrutible sleep

2002-03-27 01:49:52

by Joel Becker

[permalink] [raw]
Subject: Re: signal_pending() and schedule()

On Tue, Mar 26, 2002 at 04:19:55PM -0800, Melkor Ainur wrote:
> This works fine for some applications like netcat,etc
> but fails for netscape. In debugging this, I observe
> that after calling schedule_timeout(), the sigpending
> bit appears to be set immediately and thus
> schedule() doesn't actually put the process to sleep.

This is happening exactly for the reason you would expect it to:
A signal has arrived. Netscape's userspace "threading" is based
entirely on signals. Netscape sends itself SIGALRM almost continuously.
You'll have to expect this from Netscape and work around or with it.

Joel

--

Life's Little Instruction Book #337

"Reread your favorite book."

Joel Becker
Senior Member of Technical Staff
Oracle Corporation
E-mail: [email protected]
Phone: (650) 506-8127

2002-03-27 03:52:28

by Melkor Ainur

[permalink] [raw]
Subject: Re: signal_pending() and schedule()

Hi Joel, everyone,

Thanks for the info about the SIGALRM. I had not
noticed this until I did an strace on netscape.

I had been simple minded in my implementation of
tcp_sendmsg. For a userspace application such as
netscape, I allocate a kernel buffer(s)and copy the
data from user space into this/these buffer(s)
(because I am unaware of a way around singlecopy
when the app uses a userspace buffer). I then schedule
dma. After that I put the calling application to
sleep. I don't have a good idea of how I would
handle this if the application got woken up out of the
sleep by a signal before the dma was done. I suppose
I could spin but that seems unclean. I will
look through other drivers and see if/how this is
handled but any leads would be greatly appreciated.

Thanks,
Melkor

--- Joel Becker <[email protected]> wrote:
> A signal has arrived. Netscape's userspace
> "threading" is based
> entirely on signals. Netscape sends itself SIGALRM
> almost continuously.
> You'll have to expect this from Netscape and work
> around or with it.
>
> Joel
>


__________________________________________________
Do You Yahoo!?
Yahoo! Movies - coverage of the 74th Academy Awards?
http://movies.yahoo.com/