home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / sys / stratus / 89 < prev    next >
Encoding:
Internet Message Format  |  1993-01-06  |  4.6 KB

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!usc!news.bbn.com!noc.near.net!transfer.stratus.com!transfer.stratus.com!usenet
  2. From: dan@quiensabe.az.stratus.com (Dan Danz)
  3. Newsgroups: comp.sys.stratus
  4. Subject: Re: Shared Virtual Memory & mp_debug
  5. Date: 7 Jan 1993 04:30:11 GMT
  6. Organization: Stratus Computer Inc, Marlboro MA
  7. Lines: 81
  8. Message-ID: <1igbkjINN4fo@transfer.stratus.com>
  9. References: <C0Fzpp.6qD@world.std.com>
  10. Reply-To: dan@az.stratus.com
  11. NNTP-Posting-Host: quiensabe.az.stratus.com
  12.  
  13. Tom M Moravansky writes
  14. > A programmer I work with ran across something unusual yesterday.
  15. > We are running VOS 11.5 on a Stratus.  He found that when an SVM
  16. > lock word is displayed using mp_debug, the value of that word is
  17. > set to hex 7fff.  This value causes the word to be locked.  The
  18. > debugger never unlocks the word and it must be manually unlocked.
  19. > Anyone else ever see this behavior?  Does it exist in older
  20. > versions of VOS?
  21.  
  22. If a page of shared virtual memory is declared as a lock word region
  23. then things like this begin to happen.  This is by design and is the way
  24. that hardware locking works.
  25.  
  26. When a page is marked as a lock word region, the StrataBUS interface to the  
  27. memory treats ALL reads to the page as READ-MODIFY-WRITE cycles.  These  
  28. so-called interlock cycles are indivisible -- no other board can access the bus  
  29. during the time.   
  30.  
  31. During the read phase, the original 16 bits of data at the given address are  
  32. fetched (and will be given to the requester of the memory fetch);  next, the  
  33. most significant bit is changed to 0; and finally the modified value is  
  34. rewritten to the physical memory location.
  35.  
  36. Now, using the convention that a lock word with the MSB SET is NOT locked and
  37. one with the bit set IS locked,  it becomes very easy to implement locks to  
  38. protect critical sections of code or to prevent data in shared virtual memory  
  39. from being manipulated by more than one cpu at a time.
  40.  
  41. Initialize the lock word region so that any lock words in it contain a value
  42. of minus one (0x7FFF).  Then, use the following algorithm whenever you need
  43. to perform a critical section of code.
  44.  
  45. 1.  Read the lock word as a 16-bit value.
  46.  
  47. 2.  If the value you read has the most significant bit cleared (the value
  48.     will be zero or positive if the lock word is regarded as a 16-bit 
  49.     signed integer), then some other entity owns the lock.
  50.     Delay for a bit (to prevent hogging of the bus or the cpu) and 
  51.     then restart at step 1.
  52.     
  53. 3.  If the value you get has the high bit set,  you just acquired
  54.     the lock. However, the hardware cleared the high bit when it rewrote
  55.     the lock word.  Thus any other cpu reading the locaction will find
  56.     the high bit cleared (as in step 2 above).   Because of the interlocked
  57.     access, and the fact that only one requester can use the bus at a time,
  58.     only one requester will receive a value with the high bit set, even if
  59.     both requests are made at exactly the same instant.
  60.  
  61. 3.  Perform the critical section of code.
  62.  
  63. 4.  Clear the lock by writing any value that has the most significant bit
  64.     set in the 16-bit value.
  65.  
  66. Lock word access is set on a PAGE (4096 bytes) of memory at a time;  any area  
  67. of that page that is not used as lock words is not much good for anything else  
  68. because of the effects noted in the original post.    For example, if you wrote
  69. -1 (0xFFFF) to the location in the program, and then examined it with the
  70. debugger, the first display by the debugger would show -1, but the second
  71. and all following displays would show 32767 (0x7FFF) until either the  
  72. programmer or the debugger wrote a value with the high bit set.
  73.  
  74. And if you want more information, consult the subroutine manual pages for  
  75. s$connect_vm_region.   Additional information about locking is in the
  76. document (master_disk)>system>doc>spin_lock.doc, which should be consulted
  77. if you intend to wait for the lock by spinning on the read of the lock word.
  78.  
  79. Why not use a test-and-set (TAS) instruction, you ask?  Well, one reason is  
  80. that system memory is accessed by I/O controllers as well as CPU's, and locks
  81. are used to protect data areas accessed by both.  Even if the main CPU chip had  
  82. a TAS instruction, the CPU used in the early controllers (a Z80) had none, so  
  83. the capability for locking was designed into the StrataBUS interface. 
  84.  
  85. And, now you know the rest of the story .... 
  86.  
  87. --
  88. L. W. "Dan" Danz         (WA5SKM) VOS Mail:  Dan_Danz@vos.stratus.com
  89. Sr Consulting Software SE         NeXT Mail: dan@az.stratus.com
  90. Customer Assistance Center        Voice Mail/Pager: (602) 852-3107
  91. Telecommunications Division       Customer Service: (800) 828-8513
  92. Stratus Computer, Inc. 4455 E. Camelback #115-A, Phoenix AZ 85018
  93.