SoftSys Lecture Notes, Wednesday 3/3/21 #
Demoscene #
Demoscene is about creating procedural audiovisual animations (called “intros” or “demos”). Artists challenge themselves by constraining how large the executable can be or what hardware their animation runs on.
https://www.youtube.com/watch?v=cjBEgPWT2sQ
If you want to see an insane level of performance optimization, you might enjoy demoscene.
Other videos you can check out:
- String Theory: https://www.youtube.com/watch?v=Ii0tcfpT0TE
- Stuck by Jetlag: https://www.youtube.com/watch?v=5k0OiT8X3z0
I/O Performance (Continued from last time) #
One of the simplest command-line utilities is a program called yes
. If you run it, you will see it simply print out y
over and over again, once per line. (Use Ctrl-C to stop this if you start running it.)
We’re going to try an exercise to see how it performs.
- First, install the program
pv
on your machine by runningsudo apt install pv
(or the equivalent command for Mac, probablybrew install pv
). - Let’s benchmark the actual version of
yes
to see how it performs. Runyes | pv -r > /dev/null
to see how fastyes
writes. (Again, use Ctrl-C to stop execution.) - Now write your own version of this utility called
yes.c
. Compile and run it in the same way as above to measure its speed. How does it compare? - Your implementation is probably a bit slower than the built-in
yes
program, so let’s try to get it a bit faster. Read about thewrite
system call by runningman 2 write
(on most systems). Try using this to writey
repeatedly. - Define a constant in
yes.c
calledCOPIES
(you can do this by adding a line like#define COPIES 42
at the top of the file). Then modify your implementation so that you create a string containingCOPIES
copies ofy\n
(whatyes
prints by default), and try measuring the speed of your program again. - If you have time, try playing around with the value of
COPIES
to see what kinds of values help make the performance faster or slower.
Filesystems: Disk Times #
Exercise:
Assume 10 ms random seek time and 4 ms rotational latency. Assume 1 Gb/s transfer rate.
- What is the total time to seek a random track, read a random block, and transfer 8 KiB from disk?
- 14 + 0.065 = 14.065 ms
- How much additional time would it take if we transferred 800 KiB instead?
- 14 + 6.5 = 20.5 ms
Filesystems: Inodes #
Exercise:
- In a file system with 48-bit block addresses, how many blocks can be addressed? Express your answer in base 10 scientific notation.
- 2^48 = 2.81e14
- If each block is 8 KiB, what is the total size of all addressable blocks? Express your answer in binary prefix units.
- 2^48*8KiB = 2^48*8192 = 2.31e18 bytes
- How many block addresses can fit in a block?
- 2^13 * 8 / 48 = 1365
- 1 KiB = 2^13 bits
- If the system uses UNIX-style inodes that contain 12 direct block pointers, what is the biggest file we can address using only the direct pointers?
- 98304 bytes
- What is the biggest file we can address using the direct pointers and the singly indirect pointer?
- Bonus question: what is the biggest file we can address using the inode, the singly indirect pointer, and the doubly indirect pointer?