From: gezelter@rlgsc.com
Newsgroups: comp.os.vms
Subject: Re: $QIO: What happens within?
Date: 15 Dec 92 10:02:35 EST
Distribution: na
Organization: Robert Gezelter Software Consultant, Flushing, NY

In article <1992Dec14.164552.28939@bnlux1.bnl.gov>, kushmer@bnlux1.bnl.gov (christopher kushmerick) writes:
> What is the sequence of events when a qio is executed? In particular:
> 
> 
> I am using a $QIO to send data between mail boxes. I have a global structure
> which is updated at AST level by various tasks. When I get a request from 
> another program, I send the structure by qio, specifying the address of the
> actual global structure, rather than first making a copy.
> 
> This is in FORTRAN so both the global structure and any local copies would be
> at some fixed location in memory and _NOT_ on the stack.
> 
> 
> Here is the question: Does $qio (not $qiow) make its own copy of the data 
> prior to returning, or does it just use the data at the memory location speced?
> 
> Here is what I am worried about
> 
> 1) Stack frames: If I were doing this in Pascal or C and sent a local
> variable via qio. By the time the qio got around to actually sending the data,
> the routine that called the qio may have returned, the stack frame would no
> longed be valid and who knows what might be in the (stack) memory location that
> used to contain the data.
> 
> 2) The data in my case is updated by ast-level interrupt routines. What if
> the updating routine is executing when the $qio is ready to start shipping the 
> data. Will the qio interrupt the ast routine to ship the data? Does it
> matter if the qio was called at AST level or at "normal" level? Is it possible
> that the data will be corrupt due to incomplete updating of the data?
> 
> Perhaps a milbox is a bad example because it is all memory. what if I was 
> sending large amounts of data down a slow serial line, using local 
> variables in a stack-frame language like pascal.
> -- 
> Chris Kushmerick
> kushmer@bnlux1.bnl.gov
-- 
Chris,
 
You ask an important question!
 
The important answer is more complex than you might expect. To be 
absolutely correct, the definition of the $QIO (and the $QIOW 
system service requires that the data structures supplied to the 
system service remain unchanged until the time that the IO 
operation has been uncompleted. IO completion is signaled by some 
combination of Event Flag posting, AST queueing, and the posting 
of a non-zero IO completion code in the IOSB (any combination of 
these is possible, they will all occur simultaneously).
 
It is permissible for a driver to make copies of buffers and data 
structures. It is also permissible for a driver NOT to make such 
copies. In fact, if you want to be technical about it, such 
behavior can change from release to release (as is the case with 
all "internal" behavior).
 
In short, to ensure proper functioning, the buffer must remain 
intact until the IO completes.
 
Since you are incurring the overhead of mailboxes anyway, you 
mayu want to reconsider your use of global memory. Depending of 
course, on your data volume, you may already be paying most of 
the cost of actually moving the data, the data move itself may 
not be all that expensive.
 
I hope that the above information is helpful. If I can be of 
further assistance, please feel free to contact me via Email or 
phone.
 
- Bob
+--------------------------------------------------------------------------+
| Robert "Bob" Gezelter                       E-Mail:  gezelter@rlgsc.com  |
| Robert Gezelter Software Consultant         Voice:   +1 718 463 1079     |
| 35-20 167th Street, Suite 215               Fax:       (on Request)      |
| Flushing, New York  11358-1731                                           |
| United States of America                                                 |
+--------------------------------------------------------------------------+