home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / ada / 3810 < prev    next >
Encoding:
Internet Message Format  |  1992-12-23  |  4.1 KB

  1. Path: sparky!uunet!paladin.american.edu!gatech!prism!jm59
  2. From: jm59@prism.gatech.EDU (MILLS,JOHN M.)
  3. Newsgroups: comp.lang.ada
  4. Subject: Re: Using Shared memory from Ada code.
  5. Message-ID: <78757@hydra.gatech.EDU>
  6. Date: 23 Dec 92 14:39:19 GMT
  7. References: <1992Dec23.040144.7581@leeweyr.sccsi.com>
  8. Organization: Georgia Institute of Technology
  9. Lines: 79
  10.  
  11. In article <1992Dec23.040144.7581@leeweyr.sccsi.com> bill@leeweyr.sccsi.com (Bill Lee) writes:
  12. >
  13. >I have a couple of questions needing serious answers.
  14. >
  15. >First question:
  16. >
  17.  [..deletions ..]
  18. >
  19. >"...There is uncertainty about whether the compiler will generate code that
  20. > reads and writes data through to memory. In the absence of pragmas specifying
  21. > otherwise, ... there is no guarantee that a reference or assignment to a 
  22. > shared memory object in the Ada source code will result in a compiler 
  23. > generating actual read or write operations to memory......"
  24. >
  25. >O.k, the question: How do I use shared memory in my Ada programs
  26. >so that the above concerns are mitigated? How do I make SURE that
  27. >every reference to a shared memory object actually uses the shared
  28. >memory?
  29.  
  30. This is implementation dependent, but here's our approach:
  31.  
  32. We are developing a system using three cpu's (MVME147S's) in a VME environment,
  33. and have both shared memory (our global variables) and memory-mapped I/O
  34. buffers which receive and return arrays of ASCII traffic.
  35.  
  36. Global memory is a set of variable definitions and declarations 'with'ed
  37. by the user packages in our various processors.
  38.  
  39. We use 'for ... use at ...' constructs and packed record definitions to
  40. place our I/O buffers and controls, and our global memory blocks, in the
  41. appropriate address spaces.
  42.  
  43. The memory address bases and offsets are defined as symbolic constants,
  44. and evaluated at compilation time (no surprise). We found it necessary
  45. to select between alternative bases for global memory using logical switches
  46. to compile for each target processor, since (1) the global memory resided in
  47. fact on one of the cpu cards, and thus (2) the address space for this memory
  48. had a different offset when seen from onboard _vs_ offboard the card.
  49.  
  50. We defined a single global memory map and tasks were held responsible to not
  51. to not trash other processors' data there.
  52. This was acceptable to us because of the small size and close communications 
  53. among our working team.  YMMV, naturally. 
  54.  
  55. A safer, more encapsulated approach would have been to subdivide the data
  56. into "to" and "from" blocks _viz_ each processor, and then provide functions
  57. to access the data in only the appropriate direction.  This would have
  58. proliferated our global data definitions and also multiplied the complexity
  59. of defining the appropriate memory basis offset for each cpu.  We decided
  60. the simpler approach was more maintainable, and more explainable. 
  61.  
  62. We took a close look at the actual data to confirm that none of it involved
  63. multi-word reads and writes, where cpu's could collide.  You would need some
  64. type of semaphore data-locking mechanism if you couldn't ensure that.
  65.  
  66. We are using TeleSoft RTAda for a one-cpu system, and XDAda for the
  67. three-cpu system.  RTAda and XDAda didn't share memory -- I mention this only
  68. because both systems used memory-mapped I/O, implemented in the same fashion.
  69.  
  70. The 'for .. use at' is generic, but compilers' bit assignments and storage
  71. formats must be considered in defining the records for memory-mapped I/O.
  72. The conventions of our two compilers _were_not_the_same_ [8-<).
  73. We also had to resort to a couple of 'unchecked conversion's. 
  74. (They are in Ada for a reason [8*>).
  75.  
  76. Our design was heavily driven by speed requirements, we had quite a
  77. lot of data to shepherd around (though most of it was quasi-constant --
  78. initialization parameters, etc.), and we distrusted both the speed and the
  79. initial handshaking of manufacturer-supplied mailboxes and sempahores.
  80. Maybe we were too cautious.
  81. Well, how _should_ we have done it?  (now that we're done)
  82.  
  83. Regards --jmm--
  84.  
  85. -- 
  86. John M. Mills, SRE; Georgia Tech/GTRI/TSDL, Atlanta, GA 30332
  87. uucp: ...!{decvax,hplabs,ncar,purdue,rutgers}!gatech!prism!jm59
  88. Internet: jm59@prism.gatech.edu
  89.  ... Not so fast -- I'm still thinking.
  90.