{"componentChunkName":"component---src-templates-post-template-js","path":"/posts/operatingsystems/input-output","result":{"data":{"markdownRemark":{"id":"d27989b8-3194-5292-9bd1-b27c0f24d11d","html":"<h1 id=\"motivation\" style=\"position:relative;\"><a href=\"#motivation\" aria-label=\"motivation permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Motivation</h1>\n<p>Without I/O, computers are useless. However, there are thousands of devices, each one slightly different. How do we standardize the interfaces? Devices can be unreliable(media failures/transmission errors/ packet loss), how do we make them predictable, fast, and reliable?</p>\n<h2 id=\"bus\" style=\"position:relative;\"><a href=\"#bus\" aria-label=\"bus permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Bus</h2>\n<ul>\n<li>Common set of wires for communication among hardware devices + associated protocols to transfer data</li>\n<li>Allows for read, write</li>\n<li>Connects n devices over a single set of wires, connections, protocols O(n^2) relationships with 1 set of wires</li>\n<li>Cons: Only one transaction at a time</li>\n</ul>\n<h2 id=\"how-does-the-processor-talk-to-the-device\" style=\"position:relative;\"><a href=\"#how-does-the-processor-talk-to-the-device\" aria-label=\"how does the processor talk to the device permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>How does the Processor Talk to the Device?</h2>\n<ul>\n<li>The CPU contains a set of registers that can be read and written</li>\n<li><strong>Port Mapped I/O:</strong> in/out instructions</li>\n<li><strong>Memory Mapped I/O:</strong> load/store instructions</li>\n</ul>\n<h3 id=\"optimal-parameters-for-io\" style=\"position:relative;\"><a href=\"#optimal-parameters-for-io\" aria-label=\"optimal parameters for io permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Optimal Parameters for I/O</h3>\n<ul>\n<li><strong>Data granularity:</strong> Some devices provide single bytes at a time(keyboards), while other provide whole blocks (disks, networks)</li>\n<li><strong>Access Pattern:</strong> Some devices must be accessed sequentially(tape), others can be accessed randomly (disk, cd). Some devices require continual monitoring while other generate interrupts when they need service</li>\n</ul>\n<h2 id=\"transferring-data-tofrom-controller\" style=\"position:relative;\"><a href=\"#transferring-data-tofrom-controller\" aria-label=\"transferring data tofrom controller permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Transferring Data To/From Controller</h2>\n<ul>\n<li>\n<p><strong>Programmed I/O:</strong> Each byte transferred via processor in/out or load/store</p>\n<ul>\n<li>Pros: Simple hardware and software</li>\n<li>Cons: Consumes processor cycles proportional to data size</li>\n</ul>\n</li>\n<li><strong>Direct Memory Access:</strong> Give controller access to memory bus and asks it to transfer data blocks to/from memory directly</li>\n<li><strong>Blocking Interface:</strong> When system reads data, sleep the process until the data is ready. When the system writes data, sleep the process until device is ready for data.</li>\n<li><strong>Non-blocking Interface:</strong> Return quickly from read/write with count of bytes transferred. It may return nothing and write may write nothing.</li>\n<li><strong>Async Interface:</strong> When reading data, take pointer to user buffer, return immediately since the kernel will fill the user buffer and notify user. When writing data, get the pointer to user buffer, return immediately. The kernel will read the data and notify the user.</li>\n</ul>","fields":{"slug":"/posts/operatingsystems/input-output","tagSlugs":["/tag/notes/","/tag/textbook/","/tag/operating-system/"]},"frontmatter":{"date":"2021-10-25T23:46:37.121Z","description":"Notes on I/O","tags":["Notes","Textbook","Operating System"],"title":"Input and Output"}}},"pageContext":{"slug":"/posts/operatingsystems/input-output"}},"staticQueryHashes":["251939775","401334301","825871152"]}