PHY 406 - Microprocessor Interfacing Techniques
Module 2
Disk Reading and Writing
Objective
In this module we will look at the theory and reality of writing data to disk. We will see
that the actual rate of writing to disk is much lower than the theoretical rate.
There are two parts to this module: Disk Writing and Advanced. The Advanced section
is optional and carries no marks.
In the real world questions sometimes don't have simple answers - because the world is
not that simple! In this course you may (will!) find that some of the most simple questions have
not-so-simple answers. Take heart, I am not trying to trick you - just getting you to think about
the problem a bit more. I am always more interested in whether you have thought about the
problem than whether you have the precise answer "in the back of the book". If you have any
doubts about whether you are on the right track or not - it is your duty to corner me or the
demonstrator and ask.
Preparation
You will need the following VIs
You should have read and understood the lecture notes on disks and how they are
structured.
File Types
LabVIEW is capable of writing four types of file:
- Spreadsheet: These files consist of ASCII (normal) text with commas in suitable places
for importing into a spreadsheet. The VIs which control this form write
one array to the file at a time.
- Character: These are similar to spreadsheet files in that they consist of ASCII text, but
the format is freer.
- Binary: Consist of the data in computer format instead of ASCII. That means that
the computer can read them, but you can't! They are more compact than
character files and do not suffer from round-off errors. They be translated
into ASCII by other programs. Since the data do not have to be translated
from binary to ASCII, they are also faster to write. Binary files can be
files of 16-bit integers or single-precision reals.
- Datalog: These are similar to binary files except that the data can be more complex
types (eg clusters). They must be read in the same format as they are
written which constrains them (more or less) to be read by a similar
LabVIEW program to the one which wrote them.
We will be concerned with spreadsheet files.
Local Variables
Another new feature of LabVIEW that the example VI uses is a "local variable". These
are additional references to controls/indicators in the diagram and permit you to do two useful
things: Change the value of a control on the front panel and alter the value of a control/indicator
from several points in the VI (whether this makes sense is a matter for the programmer - ie you!).
You will find one of the local variables and the indicator on the first and third panels of
the sequence in e:\l_view\examples\ex_write - on the first panel the "run/wait" indicator is set to
"running" and on the last panel the local variable of the same name is used to set the indicator to
"waiting". (You might like to think how you would do this without local variables).
You can generate a local variable by the sequence right click>>create>>local variable
on a indicator or control on the siring diagram. You may have as many local variables for a
single control or indicator as you wish.
A word of caution - since LabVIEW uses the label of the indicator/control to name the
local variable, it is a good idea to have the indicator/control labeled with something meaningful
before you create the local variable even if you don't display that label on the front panel.
Equipment
No external equipment is required for this module
If you have access to LabVIEW and another system, you can use that system, but you will
have to think a bit about how your answer might differ from that obtained with a laboratory
system.
Disk Reading and Writing
- The VI ex_write (which you will find under e:\l_view\examples\ex_write) shows you
simply how to write a set of arrays of numbers to a spreadsheet file and time the result.
- Modify the VI to generate an array of size size of array (a control) and write this to an
output file. The VI should then append similar arrays to the output file until it has written
number of arrays (another control) arrays to the file. Thus at the end the file contains
(size of array)*(number of arrays) numbers.
- Run the VI for various conditions and find out how long it takes to write a file for various
size of array and number of arrays using an output file in the C:\temp directory. By
running the VI with suitable numbers for the controls fill in the 2-dimensional table
(shown below) of the "time to write one number" as a function of these parameters for
powers of ten. You need not fill out any part of the table if you feel that the running time
will exceed five minutes - but please justify your choices
- Can you see a pattern in your results? Eg does it take longer (per number) to write large
arrays or short arrays? Does the total size of the file matter? Can you offer some
explanations?
- By looking at the files, the size of the files or some other manner, find out how many
bytes (characters) the system is using to write a real number. Is this a constant?
- Does the representation of the numbers in the file represent the precision with which the
number is internally represented in binary? If not, how many characters would you need
for that? (You may assume that the single precision numbers are stored in IEEE format)
Hint: you should use scientific notation. How does that compare to the amount of
internal storage used? You can look at a file by naming it with a ".txt" extension and
then following the "My Computer" tree on the main windows display to the directory
where the file is (Windows 95 will not show you the extension but the icon will look
vaguely like a notepad) Double-clicking will enable you to look at the file although the
system may have some trouble with the larger files.
- Write a similar VI or modify the one you have to read the arrays you have written and
find out how long it takes to read arrays. Compare the time to read a number with the
time to write it for various sizes of array. (You can just read the arrays into an array
indicator to satisfy the LabVIEW syntax)
- If your disk has 823 cylinders, 4 heads, and 504, 512-byte sectors per track, rotates at
4500rpm and takes 2mS to step from track-to-track what is the theoretical maximum
transfer speed in bytes/sec and how does that compare with your results above?
- For small files try using the F:\ drive instead of the C:\ drive and see how network speeds
(theoretical maximum of 1.25Mbytes/sec on the Ethernet) compares with local disk
speeds
- Delete all the temporary files you have created when you have finished.
Advanced
This section is for the intelligent/bored or otherwise fascinated. There are no marks for
this section - only the satisfaction of solving a problem or two.
- Try a similar exercise using binary files (you will need the Binary File Vis)
- There is a problem with the "stop" control in the above example. It doesn't stop the
program when you press it. Why not? Fix it!
- When writing very large files, you may have noticed that the system becomes very
unresponsive for a while after you have written the file - why is this? At what point (file
size) does this start to happen?
- How would you devise a system to optimise the speed at which data can be logged?
The Table
Number
of Arrays |
Size of Array |
1 |
10^1 |
10^2 |
10^3 |
10^4 |
10^5 |
10^6 |
10^7 |
1 |
|
|
|
|
|
|
|
|
10^1 |
|
|
|
|
|
|
|
|
10^2 |
|
|
|
|
|
|
|
|
10^3 |
|
|
|
|
|
|
|
|
10^4 |
|
|
|
|
|
|
|
|
10^5 |
|
|
|
|
|
|
|
|
10^6 |
|
|
|
|
|
|
|
|
10^7 |
|
|
|
|
|
|
|
|