Usenet comp.unix.tru64 (2000-2013)
 help / color / mirror / Atom feed
* Blocked kernel thread  misses wakeup  on SMP - Tru64 5.1A
@ 2003-09-23 21:36 Ron Jolly
  2003-09-24 20:55 ` Eric Dumazet
  2003-09-25 10:35 ` David Butenhof
  0 siblings, 2 replies; 5+ messages in thread
From: Ron Jolly @ 2003-09-23 21:36 UTC (permalink / raw)


Hello all,
I have a device driver operating on Tru64 that appears to miss
catching a thread_wakeup_one() only on a SMP system.

Here is the scenario:
The driver is for a PCI network memory board that has a DMA controller
for moving data from the PCI contained memory to main system memory.
I have a command line utility which allows me to select DMA reads or
writes through an API call.
When a DMA operation needs to be performed,
the driver sets up a simple_lock(), sets the DMA controller registers,
then as the last operation, starts the 
DMA. I then go into an mpsleep(), unlock the simple
lock, and block waiting for a wakeup or timeout. When the DMA has
finished,
an interrupt is generated and the interrupt handler initiates a
thread_wakeup_one() to send to the blocked  kernel thread.
This works fine on a uniprocessor system and one customer who has
a GS160 NUMA system  indicates that it always works on that system. My
problem
is on my DS20 SMP system.  If the DMA transfer is a length of
2k-4kbytes or larger, I have no problem. If the DMA transfer size is
set to approximately
512 bytes or less, I sometimes,
and I mean something like once every  30 - 40 thousand DMA transfers,
will get a EWOULDBLOCK returned from mpsleep() a and I can see that it
has timed out because I allow 3 seconds for the DMA to complete.
Now if  attempt the same small DMA transfer of 512 bytes or less, but
initiate the command line utility
with a  "runon 0 readdma"  I never get the EWOULDBLOCK error and the
DMA executes without any errors. If I execute the utility "runon 1
readdma" I will get the EWOULDBLOCK error.

My theory is that during a small DMA transfer, the transfer  starts
and finishes before the kernel thread is ready to correctly block and
the  thread_wakeup_one() call has been sent and so the
kernel thread misses the wakeup call.  I think it may work correctly
with larger DMA transfers because the DMA takes more time and the
blocked kernel thread is properly waitng for the wakeup call.
Another theory is that the kernel thread is started on one CPU and the
interrupt handler is executing
on the alternate CPU. Is this possible?
I have considered implementing the bind_to_cpu for the driver itself
but do not know if that would  work and anyway it seems to be a rather
draconian technique.
The environment is a DS-20, Tru64 5.1A with Patch Kit 5 and I did make
sure that the DecThreads fix Patch #1220, upgrades to DecThreads
V3.18-150 is installed.

Any suggestions welcomed...
thanks,
Ron Jolly
GE Embedded Systems
ron.jolly at gefanuc dot com


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Blocked kernel thread  misses wakeup  on SMP - Tru64 5.1A
  2003-09-23 21:36 Blocked kernel thread misses wakeup on SMP - Tru64 5.1A Ron Jolly
@ 2003-09-24 20:55 ` Eric Dumazet
  2003-09-25 19:04   ` Ron Jolly
  2003-09-25 10:35 ` David Butenhof
  1 sibling, 1 reply; 5+ messages in thread
From: Eric Dumazet @ 2003-09-24 20:55 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 3186 bytes --]


"Ron Jolly" <ron.jolly@gefanuc.com> a �crit dans le message de
news:c76164d.0309231336.377f5148@posting.google.com...
> Hello all,
> I have a device driver operating on Tru64 that appears to miss
> catching a thread_wakeup_one() only on a SMP system.
>
> Here is the scenario:
> The driver is for a PCI network memory board that has a DMA controller
> for moving data from the PCI contained memory to main system memory.
> I have a command line utility which allows me to select DMA reads or
> writes through an API call.
> When a DMA operation needs to be performed,
> the driver sets up a simple_lock(), sets the DMA controller registers,
> then as the last operation, starts the
> DMA. I then go into an mpsleep(), unlock the simple
> lock, and block waiting for a wakeup or timeout. When the DMA has
> finished,


what do you mean ? You manually unlock the simple lock before calling
mpsleep() ?
The locking kernel services works only if you use it correctly as :

lock_write(&mydriverlock) ;
initiate_transfert() ;
while (!finished_transfert()) {
    mpsleep(&mycondaddr, PCATCH | (PZERO + 1), "mydrivername", 0,
&mydriverlock, MS_LOCK_WRITE | MS_LOCK_ON_ERROR) ;
    }
ok_done:
lock_done(&mydriverlock) ;


> an interrupt is generated and the interrupt handler initiates a
> thread_wakeup_one() to send to the blocked  kernel thread.
> This works fine on a uniprocessor system and one customer who has
> a GS160 NUMA system  indicates that it always works on that system. My
> problem
> is on my DS20 SMP system.  If the DMA transfer is a length of
> 2k-4kbytes or larger, I have no problem. If the DMA transfer size is
> set to approximately
> 512 bytes or less, I sometimes,
> and I mean something like once every  30 - 40 thousand DMA transfers,
> will get a EWOULDBLOCK returned from mpsleep() a and I can see that it
> has timed out because I allow 3 seconds for the DMA to complete.
> Now if  attempt the same small DMA transfer of 512 bytes or less, but
> initiate the command line utility
> with a  "runon 0 readdma"  I never get the EWOULDBLOCK error and the
> DMA executes without any errors. If I execute the utility "runon 1
> readdma" I will get the EWOULDBLOCK error.
>
> My theory is that during a small DMA transfer, the transfer  starts
> and finishes before the kernel thread is ready to correctly block and
> the  thread_wakeup_one() call has been sent and so the
> kernel thread misses the wakeup call.  I think it may work correctly
> with larger DMA transfers because the DMA takes more time and the
> blocked kernel thread is properly waitng for the wakeup call.
> Another theory is that the kernel thread is started on one CPU and the
> interrupt handler is executing
> on the alternate CPU. Is this possible?
> I have considered implementing the bind_to_cpu for the driver itself
> but do not know if that would  work and anyway it seems to be a rather
> draconian technique.
> The environment is a DS-20, Tru64 5.1A with Patch Kit 5 and I did make
> sure that the DecThreads fix Patch #1220, upgrades to DecThreads
> V3.18-150 is installed.
>
> Any suggestions welcomed...
> thanks,
> Ron Jolly
> GE Embedded Systems
> ron.jolly at gefanuc dot com




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Blocked kernel thread  misses wakeup  on SMP - Tru64 5.1A
  2003-09-23 21:36 Blocked kernel thread misses wakeup on SMP - Tru64 5.1A Ron Jolly
  2003-09-24 20:55 ` Eric Dumazet
@ 2003-09-25 10:35 ` David Butenhof
  1 sibling, 0 replies; 5+ messages in thread
From: David Butenhof @ 2003-09-25 10:35 UTC (permalink / raw)


Ron Jolly wrote:

> The environment is a DS-20, Tru64 5.1A with Patch Kit 5 and I did make
> sure that the DecThreads fix Patch #1220, upgrades to DecThreads
> V3.18-150 is installed.

You've already got an answer from Eric Dumazet (which I suspect is probably 
correct), but as a "point of order" -- your question, and your problem, and 
any solution, have absolutely nothing to do with "DECthreads", which you 
can't even use in inner mode (much less in a device driver). So any 
"DECthreads" patches are completely irrelevant.

-- 
/--------------------[ David.Butenhof@hp.com ]--------------------\
| Hewlett-Packard Company       Tru64 UNIX & VMS Thread Architect |
|     My book: http://www.awl.com/cseng/titles/0-201-63392-2/     |
\----[ http://homepage.mac.com/dbutenhof/Threads/Threads.html ]---/


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Blocked kernel thread  misses wakeup  on SMP - Tru64 5.1A
  2003-09-24 20:55 ` Eric Dumazet
@ 2003-09-25 19:04   ` Ron Jolly
  2003-09-26 17:39     ` Eric Dumazet
  0 siblings, 1 reply; 5+ messages in thread
From: Ron Jolly @ 2003-09-25 19:04 UTC (permalink / raw)


"Eric Dumazet" <jsiour@nospam.cosmosbay.com> wrote in message news:<3f7204be$0$10421$626a54ce@news.free.fr>...
> "Ron Jolly" <ron.jolly@gefanuc.com> a �crit dans le message de
> news:c76164d.0309231336.377f5148@posting.google.com...
> > Hello all,
> > I have a device driver operating on Tru64 that appears to miss
> > catching a thread_wakeup_one() only on a SMP system.
> >
> > Here is the scenario:
> > The driver is for a PCI network memory board that has a DMA controller
> > for moving data from the PCI contained memory to main system memory.
> > I have a command line utility which allows me to select DMA reads or
> > writes through an API call.
> > When a DMA operation needs to be performed,
> > the driver sets up a simple_lock(), sets the DMA controller registers,
> > then as the last operation, starts the
> > DMA. I then go into an mpsleep(), unlock the simple
> > lock, and block waiting for a wakeup or timeout. When the DMA has
> > finished,
> 
> 
> what do you mean ? You manually unlock the simple lock before calling
> mpsleep() ?
> The locking kernel services works only if you use it correctly as :
> 
> lock_write(&mydriverlock) ;
> initiate_transfert() ;
> while (!finished_transfert()) {
>     mpsleep(&mycondaddr, PCATCH | (PZERO + 1), "mydrivername", 0,
> &mydriverlock, MS_LOCK_WRITE | MS_LOCK_ON_ERROR) ;
>     }
> ok_done:
> lock_done(&mydriverlock) ;

...deleted addtional

Thanks for the suggestions to Mr Dumazet and Mr. Butenhof.
In my driver code, I am doing precisely what you have
in your snippet of code. The statement I made "unlock the simple
lock..." should not have been listed in the sequence of steps.  No, I
do not manually unlock the simple lock before calling mpsleep().  Only
after the operation has completed do I call the unlock().
One thing that you have in the sample that I do not have implemented,
is the "(PZERO + 1)" for the priority. My code is setting this to
PZERO only. I recompiled with the PZERO+1, but it did not make any
difference. I still
miss a thread_wakeup_one call.

I have a Linux driver for the same hardware that approaches this
problem in a different way. The assumption is that at some point you
may miss a wakeup, so go ahead and code for this condition. In Linux
you plan for it by going "halfway asleep". See the O'Reilly book,
"Linux Device Drivers" by Rubini and Corbet.
In chapter 9, the section,"Going to Sleep Without Races"  (online at
http://www.xml.com/ldd/chapter/book/ch09.html ) explains
how this is done, on page 287.....

From the book:
/*************************************************************************
The way to solve this problem is to go halfway to sleep before
performing the test. The idea is that the process can add itself to
the wait queue, declare itself to be sleeping, and then perform its
tests. This is the typical implementation:

 wait_queue_t wait;
 init_waitqueue_entry(&wait, current);

 add_wait_queue(&short_queue, &wait);
 while (1) {
    set_current_state(TASK_INTERRUPTIBLE);
    if (short_head != short_tail) /* whatever test your driver needs
*/
    break;
    schedule();
 }
 set_current_state(TASK_RUNNING);
 remove_wait_queue(&short_queue, &wait);
**************************************************************************/

This works for my driver on Linux. The code runs without error on an
SMP system. Question is, how is this performed on Tru64?
Do I have access to the wait queue? How do I access the scheduler?
Any thoughts on why the current implementation works successfully on a
12 CPU NUMA (GS160) system but fails on a SMP system?

thanks
Ron

> > Any suggestions welcomed...
> > thanks,
> > Ron Jolly
> > GE Embedded Systems
> > ron.jolly at gefanuc dot com


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Blocked kernel thread  misses wakeup  on SMP - Tru64 5.1A
  2003-09-25 19:04   ` Ron Jolly
@ 2003-09-26 17:39     ` Eric Dumazet
  0 siblings, 0 replies; 5+ messages in thread
From: Eric Dumazet @ 2003-09-26 17:39 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1524 bytes --]


"Ron Jolly" <ron.jolly@gefanuc.com> a �crit dans le message de
news:c76164d.0309251104.53d09f38@posting.google.com...
> Thanks for the suggestions to Mr Dumazet and Mr. Butenhof.
> In my driver code, I am doing precisely what you have
> in your snippet of code. The statement I made "unlock the simple
> lock..." should not have been listed in the sequence of steps.  No, I
> do not manually unlock the simple lock before calling mpsleep().  Only
> after the operation has completed do I call the unlock().
> One thing that you have in the sample that I do not have implemented,
> is the "(PZERO + 1)" for the priority. My code is setting this to
> PZERO only. I recompiled with the PZERO+1, but it did not make any
> difference. I still
> miss a thread_wakeup_one call.

Weel, that's strange indeed. The Tru64 mpsleep() function is guaranted to
work, iff the waiter and wakeup threads are synchronized on the same simple
lock. So the question is now : do they lock the same simple lock ?
Do you verify returns from different kernel service functions you are
calling ?
I can make a review of your source if you are willing to, just send me a
pointer or the complete file.

> This works for my driver on Linux. The code runs without error on an
> SMP system. Question is, how is this performed on Tru64?
> Do I have access to the wait queue? How do I access the scheduler?
> Any thoughts on why the current implementation works successfully on a
> 12 CPU NUMA (GS160) system but fails on a SMP system?
>
> thanks
> Ron




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2003-09-26 17:39 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-09-23 21:36 Blocked kernel thread misses wakeup on SMP - Tru64 5.1A Ron Jolly
2003-09-24 20:55 ` Eric Dumazet
2003-09-25 19:04   ` Ron Jolly
2003-09-26 17:39     ` Eric Dumazet
2003-09-25 10:35 ` David Butenhof

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox