Device Access Methods, Explained

UPI Study › Courses › Introduction to Operating Systems › Free lessons › Lesson 5.5 Free with a free account

Device Access Methods

Introduction to Operating Systems · Chapter 5: Peripheral Devices and I/O SystemsSection 5.5 · lesson 40 of 838 min · free with a free account

← Classifying Peripheral DevicesNext lesson: How Devices Communicate →

A free account plays all of Chapter 1 and 3 more lessons of Introduction to Operating Systems. Create a free account →

Earn 3 college credits for Introduction to Operating SystemsRecommended for credit by NCCRS · Computer Science 354 · self-paced · one payment, lifetime access

In this lesson

Polling, interrupts and DMA, plus memory-mapped and port-mapped I/O.

  • Compare polling, interrupt-driven I/O and DMA by the CPU time they use
  • Choose a suitable access method for a given device and workload
  • Distinguish memory-mapped I/O from port-mapped I/O
  • Explain why naming a device and waiting for it are separate choices

Free study notes

Get this lesson's notes by email

The key points and 4 practice questions with answers, in your inbox. One email, free.

One email. Unsubscribe in one click.

Transcript

Everything said in the video, section by section (1,113 words). Read along, or search it.

Opening Analogy

Three Ways to Wait for an Oven

Sam, who runs a small online bakery, is waiting for the oven timer, while also answering the shop's phone. One way to wait: stand in front of the oven, and stare at it until it rings. Another: carry on with other work, and let the timer interrupt. A third: ask a helper to watch the oven, and shout only when all the trays are done. A computer faces the same three choices every time it talks to a slow device. And the choice decides how much of the processor's time is wasted.

Programmed I/O

Polling Keeps the CPU Asking

Peripherals are far slower than the processor. Even a drive takes ages to deliver its next byte, compared with how fast the CPU runs instructions. The first method is programmed I/O, also called polling. The CPU runs a loop. Is the device ready? No. Is it ready now? No. Now? Yes! Then it moves one byte, and starts asking again. Polling is simple, needs no special hardware, and answers instantly once the device is ready. But the CPU is busy for the whole transfer. While it waits, nothing else gets done.

Interrupt-Driven I/O

Let the Device Signal When Ready

The second method is interrupt-driven I/O. The CPU starts the device, and goes back to other work. When the device is ready, it sends an interrupt: a signal on the control bus from lesson 5.3. The CPU pauses, saves its place, runs a short routine called an interrupt handler to move the data, and then returns to what it was doing. Lesson 3.3 showed interrupts in general. Here, they serve devices. Interrupts waste far less waiting time. But they aren't free. Stopping, saving, and resuming cost a little every time. For a device that delivers lots of data, one byte at a time, those costs add up.

Direct Memory Access

A Controller Moves the Whole Block

The third method is direct memory access, or DMA. It hands a whole block transfer to a separate chip, the DMA controller. The CPU only sets up the job: which device, where in memory, and how many bytes. The controller then moves all of it, between the device and RAM, borrowing the bus when it needs to. And it sends a single interrupt at the very end. The CPU is free for the whole transfer, except at the start and the finish. A common mistake is thinking DMA means no CPU at all. The CPU still sets up the transfer, and handles that done interrupt. It's only free during the long middle part.

Toy Model

Busy Ticks for One Hundred Bytes

How much does the choice matter? Here's a toy model: move one hundred bytes from a slow device. The time unit is a tick, invented for this model, so the numbers show a pattern, not a measurement of any real machine. The device delivers one byte every ten ticks, so every method needs at least a thousand ticks. What changes is how many of those ticks the CPU spends busy. Polling keeps the CPU busy for all one thousand ticks, leaving none free. Interrupts cost five ticks per byte, two to copy and three to switch. That's five hundred busy ticks, so half the time is free. DMA costs only eight ticks, at the two ends. Nine hundred ninety-two ticks, about ninety-nine percent, are free for other work.

Rule of Thumb

Matching the Method to the Device

So here's a rule of thumb. Polling suits a device that's almost always ready, or a very short wait. Interrupts suit slow, occasional events, like keystrokes. DMA suits big blocks, like a drive moving thousands of bytes. Real systems mix all three. Sam's order program once froze for a few seconds each time it saved the daily backup. Ivy, who looks after the computers at a school, found that the old drive's driver was copying every byte through the CPU. Switch it to DMA, she said, and the CPU can go on serving customers while the drive copies. After the change, the program kept responding during the save.

Quick Check

An Always-Ready Temperature Sensor

Quick check. Ivy's server room has a temperature sensor. It always has a fresh reading ready, the instant it's asked. The CPU only wants one reading a minute: a couple of bytes. Which method fits best: interrupts, polling, or DMA? Pause, and decide. Polling. The device is always ready, so one quick question gets the answer at once. No waiting loop ever spins. Interrupts are tempting, but they exist so the CPU needn't wait for a slow device. Here there's no wait to avoid, and the stop and save would cost more than the question. And DMA is meant for big blocks, not a couple of bytes.

Naming Devices

Memory-Mapped Versus Port-Mapped I/O

All three methods still need a way for the CPU to name a device. Devices have small storage spots called registers. One holds a status, like ready. Another holds a command, like start. Another holds a byte of data. Two common designs reach them. In memory-mapped I/O, device registers take some addresses from the same address space as RAM. The CPU uses its ordinary load and store instructions, as if they were memory. In port-mapped I/O, also called isolated I/O, devices get a separate address space of ports, reached with special in and out instructions. A signal on the control bus says: this address is a port, not memory.

Processor Families

Naming Is Separate From Waiting

Which design a machine uses depends on its processor family. Intel and AMD chips offer both. ARM chips, like the one in many phones and in recent Macs, use only memory-mapped I/O. With memory-mapped devices, one set of instructions reaches both RAM and devices. The cost is that some of the address space, from lesson 5.3, is used up by device registers. And notice: these two designs are about how the CPU names a device. Polling, interrupts, and DMA are about how it waits, and who moves the data. You can combine any naming scheme with any waiting method.

Quick Check

Ordinary Stores and One Done Interrupt

One more. A driver stores a memory address, and a byte count, into a controller's registers, using ordinary store instructions. Then the CPU runs other programs, until a single done interrupt arrives. Which pair describes this: how it names the device, and how it waits? Pause, and decide. Memory-mapped, with DMA. Ordinary stores reach the registers, so they sit in the memory address space. And a set-up, then other work, then one done interrupt for the whole job, is DMA's signature. The third choice gets the naming right, but polling would keep the CPU asking, with no time for other programs.

Key Takeaways

Polling, Interrupts, DMA and Naming

To recap. Polling keeps the CPU asking, and busy, the whole time. Interrupts free the CPU, but each one costs a stop and a save. DMA hands a whole block to a controller, with one interrupt at the end. And memory-mapped or port-mapped I/O is how the CPU names a device: a separate choice from how it waits.

About Introduction to Operating Systems at UPI Study

Introduction to Operating Systems (Computer Science 354) is a self-paced online course of 83 video lessons in 10 chapters, from what an operating system does and process scheduling to concurrency, memory, devices, file systems, networks, the internet, security and virtual machines. It carries a NCCRS credit recommendation for 3 semester credits.

Every lesson transcript is free on pages like this one, and the videos are free with a free UPI Study account. Enrolling adds a practice quiz after each lesson, the graded work and final exam that earn the credit, lifetime access, and an official transcript on completion. UPI Study has helped over 130,000 students with college credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.

Compare: Linux vs Operating Systems

Why take it here

Why students take Introduction to Operating Systems with UPI Study

What happens under every app you runIntroduction to Operating Systems explains the software that runs a computer: processes and scheduling, threads and synchronization, deadlock, memory and paging, devices and storage, file systems, networking, security and virtualization. It suits computer science and information technology degrees.
Credit at a fraction of the priceThe same 3 credits can cost $750 or more at a US college. Here it is one payment, self-paced, with lifetime access.
Finish your degree soonerTransfer credits reduce the courses you still owe, so you can graduate earlier or lighten a heavy semester.
Strengthen an applicationA completed college-level course on an official transcript shows admissions and scholarship committees you can do the work.
Study on your own scheduleNo start dates, no deadlines. Watch the lessons, practice, and take the final when you are ready.
130,000+students helped with college creditsACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.

Where the credit goes

Universities that work with NCCRS

Introduction to Operating Systems carries a NCCRS credit recommendation. These universities work with NCCRS; some are UPI Study's signed partners. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.

Find my college → Not listed? Ask Athena in the corner of this page, or book a 15-minute call.

FAQ

Questions students ask us

About Device Access Methods

What is the difference between polling and interrupts?
With polling, the CPU repeatedly asks a device whether it is ready and stays busy for the whole transfer, while with interrupts, the CPU starts the device, does other work, and is signaled when the device is ready. Polling is simple and responds instantly but wastes CPU time on slow devices. Interrupts free the CPU, though each one costs a stop, a save and a resume.
How does direct memory access work?
Direct memory access, or DMA, hands a whole block transfer to a separate DMA controller. The CPU sets up the job by naming the device, the memory location and the byte count. The controller then moves the data between the device and RAM, borrowing the bus as needed, and raises one interrupt when it finishes. The CPU stays free during the long middle part.
When is polling better than interrupts?
Polling is better when a device is almost always ready or the wait is very short. A temperature sensor that has a fresh reading the instant it is asked, read once a minute, is a good fit, because one quick question returns the answer. An interrupt would add the cost of stopping and saving state with no wait to avoid, while DMA suits large blocks.
What is the difference between memory-mapped I/O and port-mapped I/O?
In memory-mapped I/O, device registers occupy addresses in the same address space as RAM, so the CPU reaches them with ordinary load and store instructions. In port-mapped, or isolated, I/O, devices have a separate address space of ports, reached with special in and out instructions. Intel and AMD processors support both designs, while ARM processors use memory-mapped I/O only.

About the Introduction to Operating Systems course

How many college credits is Introduction to Operating Systems?
Introduction to Operating Systems (Computer Science 354) carries a NCCRS credit recommendation for 3 semester credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
How much does Introduction to Operating Systems cost and what is included?
$250, paid once, with lifetime access: all 83 video lessons, a practice quiz after each, the graded work and final exam, and an official transcript when you finish. Students who want several courses choose UPI Study PRO instead.
Which universities accept UPI Study credits?
UPI Study has signed partner agreements with universities such as Thomas Edison State University, University of the People and Charter Oak State College, and works with universities such as Penn State, SNHU and SUNY. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities. Use "Find my college" on this page to check yours.
How long does Introduction to Operating Systems take?
It is self-paced with no deadlines. The 83 lessons total about 10 hours of video; most students add reading and practice time and finish in a few weeks to a few months, on their own schedule.
How are the exams done?
Quizzes and assignments are online in the course. The final exam is taken online with proctoring; a person on the UPI Study team checks assignments, usually within two days.
How do my credits reach my college?
When the course shows 100% complete, request the official transcript from your dashboard. It is sent to the college you name, and you can send it to more than one. Check your college first with "Find my college" on this page, or ask Athena.

Ready for the full course? Earn 3 credits in Introduction to Operating Systems.

83 video lessons, a quiz after each one, and the graded work that earns the credit. Recommended for credit by NCCRS.

Updated

Introduction to Operating Systems
3 credits · NCCRS
Enroll →