From f0c3f895eba20e334e78a86cdb0bf55618458ab8 Mon Sep 17 00:00:00 2001 From: Jet Hughes Date: Thu, 22 Sep 2022 12:37:27 +1200 Subject: [PATCH] vault backup: 2022-09-22 12:37:27 --- content/notes/16-device-drivers.md | 64 ++++++++++++++++++++++++++++-- content/notes/cosc-204.md | 1 + 2 files changed, 61 insertions(+), 4 deletions(-) diff --git a/content/notes/16-device-drivers.md b/content/notes/16-device-drivers.md index 3282ed8e1..0e7e394c6 100644 --- a/content/notes/16-device-drivers.md +++ b/content/notes/16-device-drivers.md @@ -4,6 +4,9 @@ aliases: tags: - lecture - cosc204 +sr-due: 2022-09-25 +sr-interval: 3 +sr-ease: 250 --- # Device controller and driver @@ -36,12 +39,65 @@ the sequence of read/write requests can (should) be optimized also support buffering (accepting keyboard input line by line) and editing of buffers (e.g., spcial treatement of backspace character) # IO models - IO system calls use different IO models -- blocking - when a proccess needs IO input it waits to recieve it before c -- non blocking -- async +- blocking - when a proccess needs IO input it waits to recieve it before continuing +- non blocking - waits a fixed (small) amount of time, and returns (possibly with some data still untransferred) +- async - does not wait, is informed with a signal when io is completed # IO scheduling and buffering +for when there are several requests for IO waiting to be serviced +- first come firs served is not efficient + +IO buffers are used in main memroy to optimise file systems + +when a data block is used often, it is kept is memory and only written to secondary storage once all its accesses are finished + +# example ramdisk driver +![](https://i.imgur.com/NIqCAzy.png) + +## open +``` c +int temp_open (struct inode *inode, struct file *filp){ + // check if the process has the permission to access; + // suspend the calling process if the device is busy + // or used by another process; + // otherwise record the id of the calling process + // so that the device is owned by the process; + // initialise or reset the device. +} +``` + +## read +```c +ssize_t temp_read(struct file *filp, char __user *buf,size_t count,loff_t *f_pos){ + // find the location of data; + // ask the controller to copy data to kernel kbuf + // copy data to user space kbuf -> buf + copy_to_user (buf, kbuf, count); + *f_pos += count; // update pointer + return count; // return the number of bytes read +} +``` + +## write +```c +ssize_t temp_write(struct file *filp, char __user *bufsize_t count, loff_t *f_pos){ + // copy data from user space buf -> kbuf + copy_from_user (kbuf, buf, count); + // find the location of data; + // ask the controller to copy data from kernel kbuf + *f_pos += count; // update pointer + return count; // return the number of bytes written +} +``` + +## close +```c +int temp_release (struct inode *inode, struct file *filp){ + // release the device by removing the id of the process; + // check if there is any waiting process to wake up; + // undo anything done at open(), e.g. free memory. +} +``` # UI for IO devices diff --git a/content/notes/cosc-204.md b/content/notes/cosc-204.md index b37fd2447..342bd7a06 100644 --- a/content/notes/cosc-204.md +++ b/content/notes/cosc-204.md @@ -45,6 +45,7 @@ tags: - [14-processes-and-system-calls](notes/14-processes-and-system-calls.md) - [15-file-systems](notes/15-file-systems.md) - [16-device-drivers](notes/16-device-drivers.md) + # Archive # Info