<HTML><BODY style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space; ">Why is the rawInBuf.Semaphore a counting semaphore?    Should it not be a binary semaphore?<DIV><BR><DIV><DIV>On Oct 19, 2006, at 6:48 AM, <A href="mailto:jennifer@oarcorp.com">jennifer@oarcorp.com</A> wrote:</DIV><BR class="Apple-interchange-newline"><BLOCKQUOTE type="cite"><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">I have a system with 12 serial port.<SPAN class="Apple-converted-space">  </SPAN>The driver is configured to be</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">interrupt driven with one character arrival per interrupt.<SPAN class="Apple-converted-space">  </SPAN>Furthermore,<SPAN class="Apple-converted-space"> </SPAN></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">I am using 1 task which is set up to poll the serial ports in raw mode at</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">a 10 ms rate and distribute any data that has arrived.<SPAN class="Apple-converted-space">  </SPAN>To do this I have</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">set VMIN and VTIME to 0.<SPAN class="Apple-converted-space">  </SPAN>The problem occurs on high bandwidth devices</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">(after they have ran a while), when the device is turned off.<SPAN class="Apple-converted-space">  </SPAN>Turning off</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">the device results in the system locking up for several seconds then</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">recovering.<SPAN class="Apple-converted-space">  </SPAN>Analysis has shown that the read command is locking the</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">system during this time.<SPAN class="Apple-converted-space">  </SPAN>It appears to me that the problem is happening</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">is that inside of termios.c in the fillBufferQueue routine.<SPAN class="Apple-converted-space">  </SPAN>While the</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">device is running there are always characters available so rawInBuff.Head</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">and rawInBuffTail are never equal. <SPAN class="Apple-converted-space">  </SPAN>Then ccount is always >=<SPAN class="Apple-converted-space">  </SPAN>c_cc[VMIN]</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">which results in wait being set to 0 and the semaphore never being</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">decremented even thought it being incremented approximately 20 times</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">during the 10 ms application task poll rate.<SPAN class="Apple-converted-space">  </SPAN>When the serial device is</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">turned off and the characters are emptied out of the termios buffer, this</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">results in a spinlock of obtaining the rawInBufSemaphore several hundred</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">thousand times.</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">I have tried several things to balance the semaphore count,<SPAN class="Apple-converted-space">  </SPAN>but can’t</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">seem to get something that doesn’t break some other aspect of termios.<SPAN class="Apple-converted-space"> </SPAN></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Any suggestions would be appreciated</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Thanks</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Jennifer</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV> </BLOCKQUOTE></DIV><BR><DIV> <SPAN class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><SPAN class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><DIV>-- </DIV><DIV>Eric Norum <<A href="mailto:norume@aps.anl.gov">norume@aps.anl.gov</A>></DIV><DIV>Advanced Photon Source</DIV><DIV>Argonne National Laboratory</DIV><DIV>(630) 252-4793</DIV><BR class="Apple-interchange-newline"></SPAN></SPAN> </DIV><BR></DIV></BODY></HTML>