home *** CD-ROM | disk | FTP | other *** search
/ hobbes.nmsu.edu / 2008-06-02_hobbes.nmsu.edu.zip / os2 / info / 16550.doc < prev    next >
Text File  |  1995-01-29  |  18KB  |  341 lines

  1. Area Os2, Msg#1586, Sep-09-92 09:52PM
  2.    From: Wilson Navarro                       
  3.      To: All                                  
  4. Subject: 16550 under os2
  5.  
  6. I found this message on internet. I hope it helps someone understand com 
  7. ports under OS/2. ------------------------------------------------------------
  8. ------------ Article 11617 (102 more) in comp.os.os2.misc: From: db3l@ans.net 
  9. (David Bolen)
  10.  
  11. Subject: COM performance hints with 16550 Date: Thu, 3 Sep 1992 20:18:53 GMT 
  12. Organization: Advanced Network & Services, Inc. - Elmsford, NY Lines: 325
  13.  
  14. Warning: This is pretty long, but there's a summary at the end.  If you just
  15.          want to see a brief statement now:
  16.  
  17.      If you have a 16550, have a serial device that keeps DSR high while
  18.      it is on (I think most modems do this by default, or are configurable),
  19.      doesn't do hardware flow control, or doesn't mind getting up to 15
  20.      characters after dropping CTS and/or DSR, make sure you set BUFFER=ON
  21.      when configuring your COM port with the MODE command.  With default
  22.      settings, BUFFER=AUTO is really no different than BUFFER=DISABLED.
  23.  
  24.          - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  25.  
  26. I recently obtained a copy of the OS/2 physical device driver reference and 
  27. was reading through the information about the async drivers (COM/VCOM.SYS).
  28.  
  29. From the number of posts on the subject (some from myself), it seems that a 
  30. number of people are confused about what the various MODE COM settings mean, 
  31. and what sort of setup was the most efficient use of COM ports when a 16550 
  32. UART was present (which seems to be universally regarded as a good idea to 
  33. have in order to gain good performance).  I normally use OS/2 COM programs 
  34. with the RTS=HS,BUFFER=AUTO settings (as is normally recommended on the net 
  35. and in the FAQ) and wondered if I was fully exploiting the capabilities of my 
  36. 16550.  In addition, I was still having problems with DOS environment 
  37. programs (notably kermit 3.11 that just dies a horrible death) and hoped to 
  38. learn a bit about how that might be improved.
  39.  
  40. After reading a bit, and performing some experimentation, I've come up with 
  41. the following information and conclusions that may help other people with the 
  42. 16550s.  I don't place any guarantees on this information, other than that it 
  43. is accurate to the best of my knowledge and seems to be backed up by my 
  44. experimental results.  I hope it proves helpful, or at least helps to explain 
  45. the relationship between some of the MODE parameters and the use of the FIFO 
  46. buffers provided by the 16550.
  47.  
  48. (in the following, when I use the term 16550, the OS/2 drivers actually
  49.  require an NS-16550A or compatible chip, and I believe the current level
  50.  chips as discussed previously in the OS/2 groups are 16550AFN or 16550AF)
  51.  
  52.          - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  53.  
  54. Introduction:
  55. ------------
  56.  
  57. The 16550 provides for a 16-character receive hardware buffer that can be set 
  58. to generate an interrupt every 1, 4, 8 or 14 characters.  It can also hold up 
  59. to 16 characters in a transmit buffer, generating an interrupt only when that 
  60. buffer is empty.  In other words, in its most efficient mode, the 16550 can 
  61. handle transmission and receipt of data in roughly 16-byte chunks, only 
  62. interrupting the CPU at the end of each chunk.
  63.  
  64. Note that even if you don't make use of the extended buffering from the point 
  65. of view of interrupt handling, but still receive an interrupt for every 
  66. character received or transmitted, the 16550 buffer can be helpful, as it can 
  67. buffer received characters if the COM handler misses an interrupt, thereby 
  68. preventing receive overruns.
  69.  
  70. The OS/2 COM driver can fully exploit these capabilities of the 16550 
  71. depending on how it is configured.  Here's the rub though - if you take the 
  72. default COM settings, and even if you use MODE to set the BUFFER parameter to 
  73. AUTO, the COM driver is only partially using the capabilities of the UART. In 
  74. other words, the settings that are normally posted to these groups, and are 
  75. in the FAQ are not the most efficient settings.  In fact, from what I can 
  76. tell, a BUFFER value of AUTO is no better than DISABLED with the other 
  77. defaults for the modem signaling values.
  78.  
  79.  
  80. COM Driver Settings (MODE):
  81. --------------------------
  82.  
  83. The extended hardware buffering mode of the async driver can be controlled 
  84. via the BUFFER parameter of the MODE command.  It can take on three values:
  85.  
  86.      ON         Set transmit/receive triggers to fully exploit buffering.
  87.                 (16-character transmit/receive queues for 16550).
  88.      OFF        Set transmit/receive triggers to a single character.
  89.      AUTO       "Automatic Protocol Override".  Adjust the transmit/receive
  90.                 triggers according to handshaking protocols in effect.
  91.  
  92. The "handshaking protocols" for AUTO mode use the following signals:
  93.  
  94.         RTS = Request To Send           ( Signals FROM OS/2 COM Driver )
  95.         DTR = Data Terminal Ready
  96.         CTS = Clear To Send             ( Signals TO OS/2 COM Driver )
  97.         DCD = Data Carrier Detect
  98.         DSR = Data Set Ready
  99.  
  100. and refer to the following:
  101.  
  102.    * Input Sensitivity using DSR
  103.         - MODE option IDSR, default ON
  104.         - If this setting is ON, then the driver will only accept data from
  105.           the device while the DSR line is active.
  106.    * Output Handshaking using CTS, DSR, DCD
  107.         - MODE options OCTS, ODSR, default is both ON
  108.         - No MODE option for DCD - MODE always sets it OFF
  109.         - This setting controls whether CTS, DSR or DCD are used to control
  110.           the flow of data to the modem.  If any of these settings are ON,
  111.           the driver stops giving data to the transmit hardware as soon as
  112.           the corresponding control signal drops.
  113.    * RTS Control Mode
  114.         - MODE option RTS, default is ON.  Can be one of the following:
  115.             + Enabled                                              [MODE=ON]
  116.             + Disabled                                             [MODE=OFF]
  117.             + Input Handshaking (RTS drops on input queue full)    [MODE=HS]
  118.             + Toggling on Transmit (RTS drops unless transmitting) [MODE=TOG]
  119.         - This setting controls how the RTS signal is controlled by the
  120.           driver.  If ON, DTR is used to signal when the COM port is
  121.           active, while if HS, DTR is used to control the flow of data
  122.           from the modem.
  123.    * DTR Control Mode
  124.         - MODE option DTR, default is ON.  Can be one of the following:
  125.             + Enabled                                              [MODE=ON]
  126.             + Disabled                                             [MODE=OFF]
  127.             + Input Handshaking (DTR drops on input queue full)    [MODE=HS]
  128.         - This setting controls how the DTR signal is used to control
  129.           the flow of data.
  130.         - This setting controls how the RTS signal is controlled by the
  131.           driver.  If ON, DTR is used to signal when the COM port is
  132.           active, while if HS, DTR is used to control the flow of data
  133.           from the modem.
  134.  
  135. A typical default configuration for the COM port is (ignoring some of the 
  136. MODE parameters not relevant to this post):
  137.  
  138.         IDSR = ON               ODSR   = ON
  139.         OCTS = ON               DTR    = ON
  140.         RTS  = ON               BUFFER = AUTO
  141.  
  142. And most suggestions for configuring the COM port for better control 
  143. explicitly set RTS=HS, and BUFFER=AUTO, so I expect that many people are 
  144. running with the above settings, except with RTS=HS, allowing full hardware 
  145. flow control (RTS/CTS) to the modem.
  146.  
  147.  
  148. Setting Interaction:
  149. -------------------
  150.  
  151. For the purposes of this post (getting the most performance out of the 
  152. 16550), the only settings that are really important from the above discussion 
  153. are the "Extended Hardware Buffering" (BUFFER), "Input Sensitivity using DSR" 
  154. (IDSR), and "Output Handshaking using CTS, DSR, DCD" (OCTS,ODSR).
  155.  
  156. Here's the basic problem.  In order to accomplish the latter two settings in 
  157. their default modes, the AUTO buffering mode basically stops using the FIFO 
  158. buffers.  In particular, the following adjustments are "automatically" made:
  159.  
  160.    * If IDSR is enabled, then the COM driver is set up to respond
  161.      to a lowering of the DSR signal within one character time.  To ensure
  162.      this, the driver adjusts the receive trigger to be a single character.
  163.      In other words, it lets the 16550 generate an interrupt per character.
  164.      The full 16-character receive buffer is still available to prevent
  165.      receive overruns, and the transmit trigger is not adjusted.
  166.    * If either OCTS, ODSR (or ODCD - only changeable from a program) are
  167.      enabled, then the device driver will respond to a lowering of the
  168.      appropriate signal within a single character time.  To do this, the
  169.      transmit trigger is lowered to a single character - the 16550 is set
  170.      to generate a transmit interrupt for each character, although the
  171.      receive trigger is not adjusted.
  172.  
  173. The reason both of these automatic adjustments are made is to take the safe 
  174. course, and assume that anything using those signals has been designed to 
  175. assume that the signals take action within a single character time.  For 
  176. example, without fixing the transmit trigger, the modem could lower the CTS 
  177. signal, but the 16550 might continue transmitting up to 15 characters that 
  178. might still be in the FIFO transmit queue.
  179.  
  180. Of course, the problem is that with the default settings, both of these rules 
  181. come into effect, and the driver ends up getting an interrupt per character 
  182. for both transmitting and receiving characters.  In other words, you end up 
  183. using the 16550 just like any lower UART, with the single advantage that the 
  184. receive FIFO buffer on the chip helps avoid receive overruns.
  185.  
  186.  
  187. Improving Settings
  188. ------------------
  189.  
  190. In order to make more effective use of the 16550, you can do one of three 
  191. things:
  192.  
  193.    * Explicitly set the extended buffering on (MODE BUFFER=ON).
  194.    * Disable IDSR sensitivity (MODE IDSR=OFF)
  195.    * Disable any output flow control (MODE OCTS=OFF,ODSR=OFF)
  196.  
  197. Of the three, I generally prefer the former, but you may have reasons to do 
  198. one of the latter two.  By explicitly setting the buffering on, you will 
  199. override the rules above that adjust the receive and transmit triggers.  What 
  200. this means is that you may receive extraneous data if DSR is actually being 
  201. used to signal input and that if the modem asks the driver to stop sending 
  202. data (CTS), it may still receive up to 15 more characters.
  203.  
  204. I don't think either of these problems should hit most people using modems 
  205. today.  I believe most modems hold DSR high while they are on (or at least 
  206. are configurable to do this), and most modems that handle hardware flow 
  207. control (RTS/CTS) drop CTS before they are absolutely out of room.  For 
  208. example, the USR Courier v.32bis modem I have has a transmit buffer of 1.5K 
  209. (3.25K for error control connections) and drops CTS when the buffer is 90% 
  210. full (plenty of room for 15 extra characters).  But of course, for a specific 
  211. case the second or third choice can be made, which will make better use of 
  212. the 16550 than the default settings, but not the best.
  213.  
  214.  
  215. Some experiments
  216. ----------------
  217.  
  218. Just to see if any of the stuff I was learning seemed to apply, I ran some 
  219. quick tests.  Nothing extremely scientific - just a couple of quick file 
  220. transfers.
  221.  
  222. Using a SLIP connection (TCP/IP over a serial line), with USR v.32bis modems 
  223. on either end, I transferred a reasonably sized (115K or so) file down from a 
  224. workstation.  My COM port was set at 38.4K.  The transfer was from the 
  225. workstation back to my machine so I was mostly testing the receive 
  226. characteristics although the program used (FTP) does transmit data during the 
  227. transfer.
  228.  
  229. I tested using both the normal COM port settings (plus RTS=HS), and then with 
  230. BUFFER=ON rather than AUTO.  Also, I first ran the transfers without anything 
  231. else occurring on the system, and then re-ran the same transfers with a PM 
  232. monitor (one of the ones from ftp-os2 - pmload11.zoo).  The results were 
  233. interesting:
  234.  
  235.  
  236.            FTP Transfer Time (binary mode, size = 114688 bytes)
  237.    MONITOR      BUFFER          Time (s)        Rate (cps)      Load (%)
  238.    ---------------------------------------------------------------------
  239.    No           Auto            41              2797            N/A
  240.    No           On              41              2797            N/A
  241.  
  242.    Yes          Auto            53              2164            98-100
  243.    Yes          On              41              2797            82-86
  244.  
  245.  
  246. When nothing else was running, BUFFER didn't really make much of a 
  247. difference. I guess this just meant that my machine itself was fast enough to 
  248. keep up with an interrupt a character in general.  I presume though (given 
  249. the next set of results) that the load on the system in the On mode was much 
  250. less.
  251.  
  252. When something was running (even the load program, as a PM program, takes up 
  253. CPU time and interferes with running applications - I had it iconized, so it 
  254. had to update the icon each second), things were very different.  In Auto 
  255. mode, I got a much worse transfer time, and my system load was pretty much 
  256. pegged at 100%.  In On mode, I got as good a transfer time as when nothing 
  257. else was running, but at a much smaller load on the machine.
  258.  
  259. So I think this is pretty strong evidence that using BUFFER=ON is very 
  260. different than BUFFER=AUTO when the other signaling settings are using their 
  261. default values.
  262.  
  263.  
  264. Virtual COM Driver (DOS Boxes)
  265. ------------------------------
  266.  
  267. After reading about VCOM (of which little is written), I don't see a magic 
  268. pill for DOS box users, other than that a BUFFER=ON setting should help lower 
  269. the CPU load and make it easier to keep the virtual interrupt rate up in the 
  270. DOS environment.
  271.  
  272. There was one discovery I did make however, that may help some people out. 
  273. VCOM supports two modes of accessing the COM ports - either through BIOS 
  274. calls or via virtual I/O ports.  The virtual I/O ports only emulate the lower 
  275. end INS8250 UART, and as others have noted, the virtual interrupt rate is 
  276. limited to around 1000Hz or so.
  277.  
  278. Since I figured it had something to do with the virtual I/O ports that was 
  279. causing the most problem with kermit, I reset kermit to use BIOS1 as its 
  280. method for accessing the COM port.  Although access through the BIOS is 
  281. technically limited to 9600 baud maximum, I was able to run kermit without a 
  282. failure, including file downloads.  When letting kermit use the virtual I/O 
  283. port, I'd generate traps at rates even as low as 2400 baud.
  284.  
  285. I think this behavior arises from the fact that when the application is 
  286. controlling the hardware directly, it is issuing a lot more I/O requests to 
  287. the virtual I/O port that must be handled by VCOM.  With the BIOS interface, 
  288. the application basically asks BIOS for a character, and gets them back one 
  289. at a time.  Since VCOM goes off to COM to get the character, all of the 
  290. hardware flow control and buffering used by COM is available to VCOM, and the 
  291. DOS application doesn't have to concern itself with anything.
  292.  
  293. So - if someone else is trying to run a COM program in a DOS box and it can 
  294. use BIOS to access the COM port rather than trying to run the hardware itself 
  295. you may be able to get it working reasonably.  At the very least, it gave me 
  296. a way to test the DOS version of kermit some of my users use from home at a 
  297. reasonable speed (although not as high as I would like) from within a DOS box.
  298.  
  299.  
  300. Summary
  301. -------
  302.  
  303. An important aspect of the support for 16550 UARTs within the OS/2 2.0 COM 
  304. driver is the interaction between various modem control handshaking settings 
  305. and the automatic control of extended buffering.  In particular, several of 
  306. the default COM port settings (IDSR=ON,OCTS=ON,ODSR=ON) when automatic 
  307. control (BUFFER=AUTO) is enabled force the driver not to use the enhanced 
  308. buffering of the 16550, and instead generate interrupts for each character 
  309. transmitted or received.  This can decrease performance and definitely places 
  310. a heavier load on the machine.
  311.  
  312. The easiest way to solve this is to use a setting of BUFFER=ON rather than 
  313. BUFFER=AUTO, as long as it won't cause problems overrunning your modem or 
  314. receiving extraneous information (see "Improving Settings" above).  I don't 
  315. think many users will encounter a problem if they make these changes.  From 
  316. my experiments, switching to BUFFER=ON can decrease the load on a 16MHz 386 
  317. by at least 15%, while allowing the same transfer rate on a busier system.
  318.  
  319. For the DOS Box, one hint to users trying to get reasonable performance out 
  320. of DOS COM applications - BUFFER=ON may also help this situation, but if you 
  321. can live with 9600 baud, and your application supports using the BIOS 
  322. interface to the COM port, try using that mode.  You may be to run the 
  323. application successfully at higher data rates through the emulated BIOS 
  324. interface than if the application tries to use the emulated COM hardware 
  325. directly.
  326.  
  327.  
  328. I hope someone else finds this information useful - I know it's helped me to 
  329. get a better handle on how OS/2 manages the COM port, and how various 
  330. settings affect its use of the capabilities of my 16550 UARTs.
  331.  
  332.  
  333. --
  334. -- David
  335. --
  336. /-----------------------------------------------------------------------\
  337.  \              David Bolen             \  Internet: db3l@ans.net      /
  338.   |   Advanced Network & Services, Inc.   \   Phone: (914) 789-5327   |
  339.  / 100 Clearbrook Road, Elmsford, NY 10523  \   Fax: (914) 789-5310    \ \----
  340. -------------------------------------------------------------------/
  341.