THINK FIRST·CODE LATER

← All labs

Polling, interrupts or DMA? An I/O overhead calculator

Problem

For each device of an EdgeCampus server, compute the CPU overhead of the three I/O methods.

Input: first line cpuHz (e.g. 1000000000). Then one device per line:

name bytesPerSecond wordBytes pollCycles irqCycles dmaBlockBytes dmaCycles
  • Polling: one poll per word → (bytesPerSecond / wordBytes) × pollCycles cycles/s
  • Interrupts: one interrupt per word → (bytesPerSecond / wordBytes) × irqCycles
  • DMA: one setup+interrupt per block → (bytesPerSecond / dmaBlockBytes) × dmaCycles

Print for each device:

name: polling 40.0000% | interrupts 50.0000% | DMA 0.1465% -> best DMA

(percent of cpuHz, four decimals; best is the method with the lowest overhead, ties resolved in the order polling, interrupts, DMA). Finally Total with best methods: X% (four decimals).

Input:

1000000000
disk 4000000 4 400 500 4096 1500
keyboard 10 1 400 300 4096 1500

Output:

disk: polling 40.0000% | interrupts 50.0000% | DMA 0.1465% -> best DMA
keyboard: polling 0.0004% | interrupts 0.0003% | DMA 0.0000% -> best DMA
Total with best methods: 0.1465%

(The keyboard's DMA figure rounds to zero, but a real keyboard produces single keystrokes, not blocks — see the model solution's comment.)

Data for this lab

Your program reads its data from standard input. Download the file, then give it to your program as shown below. Start with data set 1: its expected output is given.

os2-1-data-1.txt

1000000000
disk 4000000 4 400 500 4096 1500
keyboard 10 1 400 300 4096 1500
What your program must print for os2-1-data-1.txt
disk: polling 40.0000% | interrupts 50.0000% | DMA 0.1465% -> best DMA
keyboard: polling 0.0004% | interrupts 0.0003% | DMA 0.0000% -> best DMA
Total with best methods: 0.1465%

Run your program first, then open this and compare line by line: your output must contain these lines exactly.

How to give the file to my program

Terminal (macOS, Linux, or Windows Command Prompt), after compiling:

java Main < os2-1-data-1.txt

Windows PowerShell does not understand <:

Get-Content os2-1-data-1.txt | java Main

IntelliJ IDEA: Run → Edit Configurations → Redirect input from. Or simply paste the content of the file into the console when the program waits for input.

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.