[comp.sys.mac.programmer] async write to disk

krn1@ra.msstate.edu (Ken Newton) (01/29/91)

I am working on a real-time application to run on a Mac fx that 
requires very fast data collection to disk.  The program is in MPW C
and I use the following calls to try to speed up the write and to 
allow the data collection to proceed while the disk is writing.
     ioerr = PBAllocContig( myPB, false);  /* allocates enough contig space */

in loop:
     collect a block of data (13K bytes)
     wait for ioResult == 0 from last write  
     PBWrite(myPB, true);     /* async true -- DOES NOT SEEM to work */
end loop

The write is taking about 50 msec and returning with ioResult already 0.  I.e.
the call does not get done in async fashion.  For this to work for our 
application, the call needs to return in less than 1 msec and (probably) has
to use the DMA capabilities of the fx.

Any suggestions?  This is my first venture in to MPW C programming after many
years with Pascal on Lisa and Mac.

Ken Newton
Mississippi State University
krn1@ra.msstate.edu
krn1@msstate.bitnet
krn1@vax.dial.msstate.edu

beard@ux5.lbl.gov (Patrick C Beard) (01/30/91)

In article <1016@ra.MsState.Edu> krn1@ra.msstate.edu (Ken Newton) writes:
#I am working on a real-time application to run on a Mac fx that 
#requires very fast data collection to disk.

The Macintosh OS is an unsuitable OS if you need asynchronous
access to the hard disk.  The SCSI manager can't work asynchronously in
its current design.  Thus you can't take advantage of DMA on the IIfx until
a later system (later even than system 7).  A new disk driver will be required,
I believe, or a new SCSI manager.

However, under A/UX, DMA can and is being used for disk access speedup on
the IIfx.  Ironically Unix is likely to give you better disk performance,
even though you will probably be spending a lot of time swapping programs
to and from disk.  A/UX has no SCSI manager, just different device drivers.

--
-------------------------------------------------------------------------------
-  Patrick Beard, Macintosh Programmer                        (beard@lbl.gov) -
-  Berkeley Systems, Inc.  ".......<dead air>.......Good day!" - Paul Harvey  -
-------------------------------------------------------------------------------

stevec@Apple.COM (Steve Christensen) (01/30/91)

In article <1016@ra.MsState.Edu> krn1@ra.msstate.edu (Ken Newton) writes:
>I am working on a real-time application to run on a Mac fx that 
>requires very fast data collection to disk.  The program is in MPW C
>and I use the following calls to try to speed up the write and to 
>allow the data collection to proceed while the disk is writing.
>     ioerr = PBAllocContig( myPB, false);  /* allocates enough contig space */
>
>in loop:
>     collect a block of data (13K bytes)
>     wait for ioResult == 0 from last write  
>     PBWrite(myPB, true);     /* async true -- DOES NOT SEEM to work */
>end loop
>
>The write is taking about 50 msec and returning with ioResult already 0.  I.e.
>the call does not get done in async fashion.  For this to work for our 
>application, the call needs to return in less than 1 msec and (probably) has
>to use the DMA capabilities of the fx.
>
>Any suggestions?

You're operating from a misconception.  The SCSI chip in the IIfx does indeed
provide DMA support, but the SCSI Manager doesn't use the feature.  Therefore
the SCSI Manager itself is still synchronous, so the data collection and
writes to disk are happening in a serial fashion, not concurrently.

The other way to do this is if your data acquisition hardware can generate an
interrupt, use that to collect data in the background, setting a buffer full
flag to alert the foreground part (write to disk) that another buffer is ready.

steve

-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  Steve Christensen	|  Apple Computer, Inc.		|  Disclaimer:
			|  20525 Mariani Ave, MS-81CS	|   the above may be
  stevec@apple.com	|  Cupertino, CA  95014		|   a lie...or not.

time@tbomb.ice.com (Tim Endres) (01/30/91)

In article <9341@dog.ee.lbl.gov>, beard@ux5.lbl.gov (Patrick C Beard) writes:
> In article <1016@ra.MsState.Edu> krn1@ra.msstate.edu (Ken Newton) writes:
> #I am working on a real-time application to run on a Mac fx that 
> #requires very fast data collection to disk.
> 
> The Macintosh OS is an unsuitable OS if you need asynchronous
> access to the hard disk.  The SCSI manager can't work asynchronously in
> its current design.  Thus you can't take advantage of DMA on the IIfx until
> a later system (later even than system 7).  A new disk driver will be required,
> I believe, or a new SCSI manager.

This is true with one exception. Several manufacturers now sell NuBus
cards that implement SCSI. These are designed in such a way as to
allow asynchronous I/O and dual I/O. I helped write a driver for just
such a card that allowed disk writes to occur while data was being
read from an image card. This worked very well.

I know MicroNet has such a card, I programmed the Golden Triangle
ASP card, and I think DayStar has a card.

> However, under A/UX, DMA can and is being used for disk access speedup on
> the IIfx.  Ironically Unix is likely to give you better disk performance,
> even though you will probably be spending a lot of time swapping programs
> to and from disk.  A/UX has no SCSI manager, just different device drivers.

Oh so true, however it is straight forward to design A/UX applications
such that they do not swap and are very efficient. Plus I believe
you can access more memory under A/UX than under MacOS currently.

tim.

-------------------------------------------------------------
Tim Endres                |  time@ice.com
ICE Engineering           |  uupsi!ice.com!time
8840 Main Street          |  Voice            FAX
Whitmore Lake MI. 48189   |  (313) 449 8288   (313) 449 9208

mandel@vax.anes.tulane.edu (Jeff E Mandel MD MS) (01/30/91)

In article <1CE00001.a1e4o2@tbomb.ice.com> time@tbomb.ice.com (Tim Endres)
writes:
>
>In article <9341@dog.ee.lbl.gov>, beard@ux5.lbl.gov (Patrick C Beard) writes:
>> In article <1016@ra.MsState.Edu> krn1@ra.msstate.edu (Ken Newton) writes:
>> #I am working on a real-time application to run on a Mac fx that 
>> #requires very fast data collection to disk.
>> 
>> The Macintosh OS is an unsuitable OS if you need asynchronous
>> access to the hard disk.  The SCSI manager can't work asynchronously in
>> its current design.  Thus you can't take advantage of DMA on the IIfx until
>> a later system (later even than system 7).  A new disk driver will be
required,
>> I believe, or a new SCSI manager.
>
>This is true with one exception. Several manufacturers now sell NuBus
>cards that implement SCSI. These are designed in such a way as to
>allow asynchronous I/O and dual I/O. I helped write a driver for just
>such a card that allowed disk writes to occur while data was being
>read from an image card. This worked very well.
>
>I know MicroNet has such a card, I programmed the Golden Triangle
>ASP card, and I think DayStar has a card.
>
>> However, under A/UX, DMA can and is being used for disk access speedup on
>> the IIfx.  Ironically Unix is likely to give you better disk performance,
>> even though you will probably be spending a lot of time swapping programs
>> to and from disk.  A/UX has no SCSI manager, just different device drivers.
>
>Oh so true, however it is straight forward to design A/UX applications
>such that they do not swap and are very efficient. Plus I believe
>you can access more memory under A/UX than under MacOS currently.
>

  You people are missing the point about real-time programming. Real-time data
comes in from outside the Mac, and there will almost always be a way to
generate an interrupt when it arrives. Even when the disk manager grabs the CPU
for several seconds to copy a big file, interrupts get serviced, and if you are
clever, you can continue to sample in real-time. The trick is to control your
disk writing so that it is efficient (write a whole disk block) and use the
Deferred Task Manager to keep your sampling from blocking the interrupts the
Disk Manager needs to complete its work.
  In any event, DMA will probably not solve your problems unless you are doing
something really compute intensive with the acquired data. The bus is blocked
during DMA, so you still can't get your data off the board.
  As far as real-time Unix, good luck. It has been done, but I don't think it
is pretty. The bigger issue for all of this is to what extent the Mac is the
right platform for embedded control. I have done it; we controlled blood
pressure on a number of patients undergoing cardiac surgery with our prototype
test bench for closed loop control without mishaps. I lived in terror, however,
that someone would decide that they absolutely had to spellcheck their doctoral
dissertation or such during a control run. If I ever do something like this
again, I will probably get the Serial NB card and do the guts of it in A/ROSE.
Flame me if you must, but until you have spent two years trying to make the Mac
push the envelope, try to remember your perspective may be limited.

Jeff E Mandel MD MS
Asst Professor of Anesthesiology
Tulane University School of Medicine
New Orleans, LA

Author of MacInfuse, the most expensive program you will never see.

urlichs@smurf.sub.org (Matthias Urlichs) (02/02/91)

In comp.sys.mac.programmer, article <48623@apple.Apple.COM>,
  stevec@Apple.COM (Steve Christensen) writes:
< >
< >[ async PBWrite to hard disk ]
< >The write is taking about 50 msec and returning with ioResult already 0.
< >
< >Any suggestions?
< 
< You're operating from a misconception.  The SCSI chip in the IIfx does indeed
< provide DMA support, but the SCSI Manager doesn't use the feature.  Therefore
< the SCSI Manager itself is still synchronous, so the data collection and
< writes to disk are happening in a serial fashion, not concurrently.
< 
It gets worse -- the current SCSI Manager interface prevents any attempt at
using the SCSI bus asynchronously, i.e. letting the target device disconnect
if it's going to seek, multiple outstanding requests (one per device for
SCSI-1, possibly more for SCSI-2), another initiator on the bus, etc.

One can play some dirty tricks (some backup software does, if it knows that
it has total control of the bus), but SCSI is intended to be target-driven
(i.e. the hard disk on the other end tells you what it wants to do next).
This doesn't match the SCSI Manager's idea of how to access the bus.

Whatever happened to the new SCSI Manager, as described in the Alpha 7.0
documentation ?? Some people out there think it is (has been?) the most
necessary feature of 7.0, at least for their applications...

-- 
Matthias Urlichs -- urlichs@smurf.sub.org -- urlichs@smurf.ira.uka.de     /(o\
Humboldtstrasse 7 - 7500 Karlsruhe 1 - FRG -- +49+721+621127(0700-2330)   \o)/