[comp.sys.atari.st] fast multi-sector floppy I/O with interrupts

johan@nlgvax.UUCP (Johan Stevenson) (07/14/87)

Working on a floppy disk driver for the MINIX operating system for
the Atari ST I encountered a problem for which some netters may
have an answer.  The problem is the speed of multi-sector I/O.

MINIX, being a variant of UNIX, uses interrupt driven I/O.
The MINIX file system is based on 1 KB blocks. So the most frequent
floppy disk I/O requests transfer two consecutive sectors of 512 bytes.
As far as I know it is impossible to transfer two sectors with
a singe controller request and a single interrupt.
The most straightforward driver and interrupt routine I tried need
an extra floppy disk revolution between the two sector transfers.

To speed up I see the following options:

 - improve the driver, so that the interrupt caused by the first sector
   is in time to start the transfer of the second sector

 - use a non-standard floppy disk formatter that gives physically
   consecutive sectors the following relative sector numbers:
	1, 6, 2, 7, 3, 8, 4, 9, 5

 - perform the same trick as above in the driver itself

I dislike options 2 and 3. But before I continue with my trial-and-error
approach to option 1 I would like answers on the following questions:

 - is option 1 feasible, i.e. did someone succesfully implement
   fast interrupt-based multi-sector floppy I/O?

 - does someone have an example driver? (any language)

 - how many microseconds are available for the interrupt routine?

 - is a single command for several sectors really impossible?

 - what is minimally required in the interrupt routine to restart
   for the second sector?
    - test for DMA errors? read only?
    - test for controller errors?
    - check for head/cylinder change?
    - set sector register?
    - set DMA addresses?
    - clear DMA status?
    - issue controller command?

My current driver (in C) is available on request to help me resolve
this performance problem.
Thanks in advance for any clues.

				Johan W. Stevenson,
				Philips Research Laboratories,
				Project Centre Geldrop,
				Building XR, Room 15,
				Willem Alexanderlaan 7B,
				5664 AN Geldrop, The Netherlands.
				phone: +31 40 892205
				uucp: mcvax!nlgvax!johan

apratt@atari.UUCP (Allan Pratt) (07/16/87)

in article <204@nlgvax.UUCP>, johan@nlgvax.UUCP (Johan Stevenson) says:
>  - is a single command for several sectors really impossible?

Yes, Virginia, multi-sector reads don't really work usefully with this
controller.

The ST BIOS manages to read a whole track in one revolution because it
polls the controller status, rather than waiting for the interrupt.  The
"fast" format skews the position of sector 0 on successive tracks by as
much time as it takes to step the head, so sector 0 is under the head
when it gets there, so you get one track per 1.2 (or so) revolutions. 

There is a gap of just over a millisecond between sectors -- plenty of
time for a 50-cycle interrupt and a service routine which loads pre-
computed values into the controller & sets up the DMA.

The problem is that it will take 5.5 revolutions to read a track (.5
latency, sectors 0&1 in one rev, then 2&3, then 4&5, then 6&7, then 8)
at this rate.  Does the filesystem ever make requests of more than one
block? If not, you might consider skewing pairs of sectors on pairs of
tracks:

Even track:	0 1 4 5 8 2 3 6 7	(0-1, 2-3, 4-5, 6-7 are paired)
Odd track:	0 5 6 1 2 7 8 3 4	(1-2, 3-4, 5-6, 7-8 are paired)
(even 8 and odd 0 are 1/2 track away from each other)

This way your two-sector requests will be serviced in minimal time, and
during the two-sector gap before the next pair, the filesystem has time
to make its next request.  This gives you the whole track in 3
revolutions (.5 rev latency, sectors 0,1 and 2,3 in one rev, 4,5 and 6,7
in the next, then .5 rev to pick up sector 8). 

Alternatively, you can have the driver always request a track at a
time, and keep a few track buffers around.  No skewing involved.

I know you want to make sure Minix is usable with floppies... I'm just
glad I have a hard disk!

/----------------------------------------------\
| Opinions expressed above do not necessarily  |  -- Allan Pratt, Atari Corp.
| reflect those of Atari Corp. or anyone else. |     ...lll-lcc!atari!apratt
\----------------------------------------------/	(APRATT on GEnie)

egisin@orchid.UUCP (07/19/87)

You could format the disk with 1K sectors.
The 1772 has the capability to do this, I don't know if the ST
would have problems with it.  You should also be able to get 5K per track.
Having the driver handle both 512 sectors for msdos format
and 1024 sectors for minix may be difficult.

csrobe@ICASE.ARPA (Charles S. Roberson) (07/21/87)

>From: mcvax!philmds!nlgvax!johan@seismo.css.gov  (Johan Stevenson)
>Subject: fast multi-sector floppy I/O with interrupts (question)
>To: info-atari16@score.stanford.edu
>
>To speed up I see the following options:
>
> - improve the driver, so that the interrupt caused by the first sector
>   is in time to start the transfer of the second sector
>
> - use a non-standard floppy disk formatter that gives physically
>   consecutive sectors the following relative sector numbers:
>	1, 6, 2, 7, 3, 8, 4, 9, 5
>
> - perform the same trick as above in the driver itself

Johan-
	Have you seen the Summer Edition of STart magazine (and/or
the Spring edition).  David Small used the "non-standard" TWISTER
file format to speed up access times and increase disk capacity.
This was presented in the Spring issue.

Well, in the summer issue they have an alert box about a minor bug,
and they say the Atari is "adopting the twister file format" [a very
loose recall from memory.]  This may solve some of your problems
(i.e.  The format will no-longer be "non-standard".)  Now, I haven't
seen any official words on this other than the magazine, but I never
had a reason to doubt the magazine.  Their reputation is solid.

If you can't get a copy of the magazine, let me know and I will
photocopy the article and the alert box and SMAIL to to you.

Good luck and i eagerly await MINIX ( I have the book, now i'm
waiting for the movie).

PS.  How hard would it be to put a graphic interface around MINIX?
If you have ever worked with SUN Workstations, that is what I'm
looking for...A nice big screen with bitmapped graphics and *NIX!

-chip
--------------------------------------------------------------------
Chip Roberson                ARPANET:  csrobe@icase.arpa
1105 London Company Way      BITNET:   $csrobe$wmmvs.bitnet
Williamsburg, VA 23185       UUCP:     ...!seismo!gmu90x!wmcs!csrobe
--------------------------------------------------------------------
"No matter where you go, there you are!"  --Buckaroo Bonzai

csrobe@ICASE.ARPA (Charles S. Roberson) (07/21/87)

>From: mcvax!philmds!nlgvax!johan@seismo.css.gov  (Johan Stevenson)
>Subject: fast multi-sector floppy I/O with interrupts (question)
>To: info-atari16@score.stanford.edu

>To speed up I see the following options:
>
> - improve the driver, so that the interrupt caused by the first sector
>   is in time to start the transfer of the second sector
>
> - use a non-standard floppy disk formatter that gives physically
>   consecutive sectors the following relative sector numbers:
>	1, 6, 2, 7, 3, 8, 4, 9, 5
>
> - perform the same trick as above in the driver itself

Alert Box, pg. 8, STart, The ST Quarterly, Summer 87, Volume 2, Number 1
	"Last issue, START presented several hard and floppy disk
	utilities by David Small and Dan Moore.  One of these was
	Twister, a program enabling you to add another 40K per side
	of your standard 3.5 inch ST disks.  Atari has even decided
	to adopt the Twister format, starting with the new TOS ROMS
	that will be available soon....".

I wish I had remembered to bring in the Winter/Spring issue (Vol 1, No. 4)
so I could see if the Twister format is the same as yours
(1,6,2,7,3,8,4,9,5).  Maybe tomorrow.

NB:  If anyone is using version of Twister that came out in that last
issue (Vol 1. No. 4), you should make a change in the source.  "The
code on your last START disk will place the same serial number on
each disk when you format the disk in Twister format.  This causes
your ST operating system to get confused..."  David Small had
"inadvertantly used a 'serial number' parameter of -1 in the Protobt()
call." When START tried to make a last minute change, they changed
the -1 to 1,000,000L.  

	"To correct it, change the value [1000000L] to 0x1000000L"

-chip
--------------------------------------------------------------------
Chip Roberson                ARPANET:  csrobe@icase.arpa
1105 London Company Way      BITNET:   $csrobe@wmmvs.bitnet    <NB!]
Williamsburg, VA 23185       UUCP:     ...!seismo!gmu90x!wmcs!csrobe
--------------------------------------------------------------------
NB: "Nota Bene" - Note Well!

csrobe@ICASE.ARPA.UUCP (07/21/87)

In article <8707211624.AA2765@cs.utah.edu> you write:

>Have you looked into the X Window System.  It is PD and runs under *NIX.

Do you know where I can find X Window System?  Is it on one of the nets?
What about some documentation?  User impressions?  This sounds very
interesting!

How about it world?  Any X Window Xperts out there?

Thanks for the info,
-c
--------------------------------------------------------------------
Chip Roberson                ARPANET:  csrobe@icase.arpa
1105 London Company Way      BITNET:   $csrobe@wmmvs.bitnet
Williamsburg, VA 23185       UUCP:     ...!seismo!gmu90x!wmcs!csrobe
--------------------------------------------------------------------
NB:  Note that I have fixed a typo in my BITNET address. (s/$wmmvs/@wmmvs)

braner@batcomputer.tn.cornell.edu (braner) (07/21/87)

[]

DBASIC (which has pretty impressive disk I/O performance in its DOS,
which completely ignores TOS) uses 1K sectors, five per track.
To enable booting, it uses normal TOS sectors on the first track.
So, it can be done!

- Moshe Braner

csrobe@ICASE.ARPA (Charles S. Roberson) (07/22/87)

>From: mcvax!philmds!nlgvax!johan@seismo.css.gov  (Johan Stevenson)
>Subject: fast multi-sector floppy I/O with interrupts (question)
>To: info-atari16@score.stanford.edu
>
>To speed up I see the following options:
>
> - improve the driver, so that the interrupt caused by the first sector
>   is in time to start the transfer of the second sector
>
> - use a non-standard floppy disk formatter that gives physically
>   consecutive sectors the following relative sector numbers:
>	1, 6, 2, 7, 3, 8, 4, 9, 5
>
> - perform the same trick as above in the driver itself

Johan-

	Well I haven't heard from you so i don't know if this stuff
is of any use to you, but I will finish off what i started.  (I hope
this is getting to you!)

STart, Spring 87, Vol. 1, No. 4, pp. 83-94
"Hard Disk Warfare" by Dave Small (and Dan Moore)

First off, "Twister isn't really a hard disk utilty, it's a program
which doubles your floppy disk speed and adds an additional 40K per
side.  It formats a disk in a special manner, letting the disk
drivers run at full speed instead of the normal half speed.  The
new format is completely compatible with your ST's operating system."

Ok, here is the gist.  Your disk is revolving at 300 rpm, which is
5 disk spins every second, or 200ms per spin.  "The floppy hardware
takes 16.6 ms to read a sector, with around 3-4 microseconds of
"dead space" between sectors.  If there's 20ms per sector and 200ms
per spin," then there's room for 10 sectors per track.  Ergo, the
extra 40K per side.

The disk is basically moving like this: "(index pulse)
1-2-3-4-5-6-7-8-9-10 (index pulse) 1-2-3-4-5-6-7-8-9-10..."
When moving from one track to the next, the head switches
tracks, settles, "seeks" for a track number and reports
back to _floprd that it is there.  Well, after reading
track 0 and moving to track 1, sector 1 is "used up" by
the Seek.  The rest of the track must spin by before we
can start the read.  "We thus miss sector #1 every
time we step to a new track, thereby adding 1/5 of a second
per track overhead to all floppy read/writes."

Dave Small and Dan Moore format (twist) their disk in this manner:

	Track 0:  1,2,3,4,5,6,7,8,9,10
	Track 1:  9,10,1,2,3,4,5,6,7,8
	Track 2:  7,8,9,10,1,2,3,4,5,6
	Track 3:  5,6,7,8,9,10,1,2,3,4
	Track 4:  3,4,5,6,7,8,9,10,1,2
	Track 5:  1,2,3,4,5,6,7,8,9,10 (which is the same as #0)

What happens is that after reading sector 10 of the previous
track, the Seek has time to move the head (2ms), let it settle
(about 30ms), and find a track number before sector 1 of the
next tract rolls around.  The two extra sectors give
Seek "33ms to quit rattling and catch a sector ID mark
before sector #1 shows up again."

"Actually benchmarking indicates Twister does exactly what it's
supposed to do, it can read in an entire disk side (80 tracks)
in 80 spins, plus about 10 for overhead, or 18 seconds.  A
double-sided disk takes one more spin for the back side of each
track, or 36 seconds."

"If we use double sided disks, we also have to twist the sector
data from side to side.  I don't really know why; there should
not be that much overhead in switching sides.  However, there
seems to be."

***DISCLAIMER:  The information presented above is NOT my work!
The information ALL comes from the forementioned STart article.
I have tried to encapsulate what I could without losing the
basic idea.  All inquiries should be directed to that article
(i.e. Read it), or to Dave Small or Dan Moore.  However, if
I have mis-stated something, please notify me so I make correct
the error of my ways.

Johan, i hope this helps.  I really like twister, and i use
these guys' Meg-a-minute Hard Disk Backup Utility and have no
complaints, yet (it relies on the twister disk format).

Best of luck, and the offer still stands to send you a copy
of the article if you need more information.  The source code
also came with the magazine, so you might consider trying to
find the magazine or writing to one of the authors care of
the magazine:

	Jon A. Bell
	Editor
	STart
	544 Second Street
	San Francisco, CA 94107

Question:  Do you know if the X Window System could run on MINIX?
Or where I could find out?

-chip
--------------------------------------------------------------------
Chip Roberson                ARPANET:  csrobe@icase.arpa
1105 London Company Way      BITNET:   $csrobe@wmmvs.bitnet
Williamsburg, VA 23185       UUCP:     ...!seismo!gmu90x!wmcs!csrobe
--------------------------------------------------------------------
NB: The correction in my BITNET address:  changed "$wmmvs" to "@wmmvs"

apratt@atari.UUCP (Allan Pratt) (07/22/87)

in article <8707211216.AA01884@work1.icase>, csrobe@ICASE.ARPA
(Charles S. Roberson) says:
>     they say the Atari is "adopting the twister file format"

I can't speak for the "twister" format specifically, but Atari *has*
adopted a disk format where tracks start at different locations on
the disk.  Note that there is still a skew factor of zero, meaning
the sectors within a track are sequential.  I don't know what the
offset from sector 0 of one track to sector 0 of another is, but
I guess I could find out...

The new format is the one you get if you select "Format..." from the
Disk menu on the desktop when you have Mega ROMs.  I don't know how it
could be more official. 


/----------------------------------------------\
| Opinions expressed above do not necessarily  |  -- Allan Pratt, Atari Corp.
| reflect those of Atari Corp. or anyone else. |     ...lll-lcc!atari!apratt
\----------------------------------------------/	(APRATT on GEnie)