[ECOS] BSD socket stall

Bernd Edlinger bernd.edlinger@hotmail.de
Fri Sep 14 08:21:00 GMT 2012

> Hi Bernd,
> Thank you for the reply. Our implementation did have two threads
> sending data on one socket.
> We have changed the code so that each thread has its own socket.
> I did look thru the modifications for the BSD stack, but I did not see
> you the spin lock was changed to a Mutex. Is that change in the diff? A
> matter of fact I do not see where the spin lock is implemented either.
I did not touch that code, because I do not have too much contention in that
spin lock:
 register struct sockbuf *sb;
 int error;
 while (sb->sb_flags & SB_LOCK) {
  sb->sb_flags |= SB_WANT;
  error = tsleep((caddr_t)&sb->sb_flags,
      (sb->sb_flags & SB_NOINTR) ? PSOCK : PSOCK|PCATCH,
      "sblock", 0);
  if (error)
   return (error);
 sb->sb_flags |= SB_LOCK;
 return (0);

that waits for the SB_LOCK bit to clear and set the SB_LOCK again.
what might have happened would be a priority inversion here.
however this might also be a real bug...
I am not sure at the moment, if this code might be missing
the splnet mutex?
in sosend()
 error = sblock(&so->so_snd, SBLOCKWAIT(so,flags));
 if (error)
  goto out;
 s = splnet();
 error = sblock(&so->so_snd, SBLOCKWAIT(so,flags));
 if (error)
  goto out;

what are the priorites of your writing threads?
and are other threads in between?
> Back to changing the code so that each thread has its own socket. Is
> there any history where a socket has problem when the socket receives
> data but no thread is reading from that socket. The socket is intened
> for transmit only but another happed to send data to that socket and
> the data was allowed to stay in the socket unread.
good point, I usually allocate 1-2 megabytes for MBUFs, but that might
not always be possible.
if you are concerned that the socket accumulates Packet Buffers,
there is a socket option SO_RCVBUF, maybe you set it to zero, then
the socket should discard any garbage that is received accidentally.
> Thanks
> Henry
Bernd Edlinger 		 	   		  

Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

More information about the Ecos-discuss mailing list