home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / unix / programm / 4265 < prev    next >
Encoding:
Internet Message Format  |  1992-08-12  |  2.8 KB

  1. Xref: sparky comp.unix.programmer:4265 comp.unix.internals:1684
  2. Path: sparky!uunet!sun-barr!male.EBay.Sun.COM!west.West.Sun.COM!cronkite.Central.Sun.COM!texsun!ttsi!mse
  3. From: mse@ttsi.lonestar.org (Mark Evans)
  4. Newsgroups: comp.unix.programmer,comp.unix.internals
  5. Subject: Re: SVR4 semaphore overhead???
  6. Message-ID: <1992Aug13.020203.7490@ttsi.lonestar.org>
  7. Date: 13 Aug 92 02:02:03 GMT
  8. References: <1992Aug8.131020.17966@ttsi.lonestar.org>
  9. Organization: st
  10. Lines: 51
  11.  
  12. In article <1992Aug8.131020.17966@ttsi.lonestar.org> I wrote:
  13. >I have seen postings from time to time regarding the overhead of
  14. >semaphores in SVR4, but not many followups.  I'm now in the boat
  15. >of considering the usage of semaphores for mutual exclusion and
  16. >resource coordination between a substantial number (~30) of 
  17. >processes.  There is a potential for a large number of semaphores
  18. >(60-90) to get allocated.
  19. >
  20. >Someone recently posted an observation that as the number of
  21. >semaphores in a system grows, so does the overhead.  Can anyone
  22. >confirm this?
  23.  
  24. On a Tandem Integrity R3000 machine running SVR4, I found no
  25. degradation in performance on a given semaphore as the number of 
  26. semaphores in a set increased from 1 to 25 (current sysgen'd max).
  27. I am chagrined, however, at the 70 microseconds or so taken to
  28. do a simple semop() lock, as compared to the .82 microseconds it
  29. takes to call _test_and_set(), a mips-supplied routine in 
  30. libc.a which performs an indivisible test-and-set (actually, it's
  31. read-modify-write).  As suggested in previous articles and by
  32. respondents to my original post, I am cooking up a
  33. lightweight semaphore package using _test_and_test() for the
  34. lock, and system semaphores (or message queue or pause/signal)
  35. for sleep/wakeup when contention arises.
  36.  
  37. A couple of questions have come up that require expert knowledge:
  38.  
  39. (1) Is there a way for a process to reschedule itself, i.e., go to
  40. the end of the current ready-to-run list?  I don't want to resort
  41. to a sleep_ms() call if I can avoid it.
  42.  
  43. (2) When multiple processes contend for a system semaphore, are
  44. they rewarded in FIFO order as the semaphore becomes available?
  45. I have gotten the impression from previous testing that this is not so.
  46. Can anyone explain the data structures & algorithm used behind the
  47. scenes?
  48.  
  49. Writing this simple lock/unlock package at the user level without
  50. resorting to priority controls is surprisingly mind-boggling if you 
  51. consider all the races.  I'm on my fourth "I've got it" approach.
  52. When I really do "have it," I'll happily share the results to the
  53. many who have expressed interest in the subject.  If you think
  54. you have a solution, I know many out here would love to see it.
  55.  
  56. Thanks
  57.  
  58. -- 
  59. Mark S. Evans                 Tandem Telecommunications Systems Inc.
  60. Phone: 214-516-6201           1255 W 15th St.
  61. Fax:   214-516-6805           Plano, TX 75075
  62. Mail:  mse@ttsi.lonestar.org
  63.