home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / arch / 8356 < prev    next >
Encoding:
Text File  |  1992-07-27  |  4.0 KB  |  81 lines

  1. Newsgroups: comp.arch
  2. Path: sparky!uunet!paladin.american.edu!darwin.sura.net!wupost!csus.edu!netcomsv!aim.com!rec
  3. From: rec@aim.com (Bob Cousins)
  4. Subject: Re: Solaris (was: Sun 600MP Benchmark Anomaly)
  5. Message-ID: <1992Jul27.182052.5196@aim.com>
  6. Sender: news@aim.com
  7. Nntp-Posting-Host: lightning
  8. Organization: /usr/lib/news/organization
  9. References: <14pkdrINN5ni@uk-news.UK.Sun.COM> <1992Jul25.142435.9821@athena.mit.edu> <nodh0gc@rhyolite.wpd.sgi.com>
  10. Date: Mon, 27 Jul 1992 18:20:52 GMT
  11. Lines: 68
  12.  
  13. In article <nodh0gc@rhyolite.wpd.sgi.com> vjs@rhyolite.wpd.sgi.com (Vernon Schryver) writes:
  14. >In article <1992Jul25.142435.9821@athena.mit.edu>, jfc@athena.mit.edu (John F Carr) writes:
  15. >> In article <14pkdrINN5ni@uk-news.UK.Sun.COM>
  16. >>     adrian.cockcroft@uk.sun.com writes:
  17. >> How much of the 95% is spent in the locking code?  How much is spent
  18. >> waiting for locks?
  19. >You must have see some of the some MP UNIX kernel implementations, and
  20. >wondered how they get anything done what with all of the locking and
  21. >P'ing and V'ing.
  22.  
  23. This brings up an important point! There is a relationship between
  24. CPU speed, number of CPUs and the "desireable granularity" of locks.
  25. When one has a large number of faster CPUs and a mechanism to quickly
  26. handle the common case of no contention for a lock, very fine-grained 
  27. locking can be optimal. However,the overhead  of the 
  28. system by adding locks must be viewed as a cost/benefit decision.
  29. Just because one *CAN* do fine grained locking, does not mean that
  30. it will result in better performance or *SHOULD* be done.
  31.  
  32. Case in point: Years ago, I was in charge of architecting a series
  33. of Z80 based multiprocessor machines. All code was written in a 
  34. reentrant fashion in assembly language (this was a long time ago).
  35. It quickly became apparent that there was an "optimal granularity"
  36. for semaphore locking. If the granularity became too small, the
  37. system wasted too much time doing semaphore operations (about 10
  38. instructions in the successful case). If the granularity became
  39. too large, contention caused decreases in performance as more
  40. and more "large" locks began to gate tasks.
  41.  
  42. The next hardware generation used 80186s but functionally identical
  43. technology. It became apparent that the locking strategies
  44. which were ideal for Z80s were too coarse grained for the '186.
  45. By adding more locks (about 2x if my memory is right) we reached
  46. the optimal point. The '186 seemed to be about 4 or 5 times faster
  47. than the Z80. (I'm sure there is a PhD thesis in this area just
  48. waiting to be written!)
  49.  
  50. The final solution was to rewrite the code so that fewer locks
  51. were needed. (It seems that so many immature implementations 
  52. are based upon lock-crazy designs.) By careful coding, we were
  53. able to substantially reduce the need for locks through atomic
  54. updates, pointer traveling techniques and a number of similarly
  55. simple changes. In one case, we were able to eliminate all but 
  56. one semaphore in a disk driver which covered a small code region
  57. which modified device registers. The result was a virtually 
  58. contention free driver which had substantially reduced overhead.
  59. The code was cleaner, faster, smaller and in all important metrics
  60. better.
  61.  
  62. The point I'm trying to make is simple: the degree of granularity
  63. which provides *MAXIMUM* performance varies from system to system
  64. (and will likely be a source of tweaking throughout the life of the
  65. code). As machines scale, the optimal locking scheme will change.
  66. The best solution, both short term and long term, is to avoid locking 
  67. whenever possible. IMHO, many locks can be avoided. The use of locks 
  68. should be viewed as a necessary evil and almost as an implementational 
  69. failure. 
  70.  
  71. BTW: we eventually worked out a scheme to deal with hardware registers
  72. which avoided all need for semaphores in the common case. It required
  73. some unusual hardare features but it worked.
  74.  
  75.  
  76.  
  77. -- 
  78. ________________________________________________________________________________
  79. Robert Cousins                    rec@aim.com                  (408)748-8649x212
  80. Consultant to Aim Technology                          Speaking for myself alone.
  81.