Character Device Drivers One Module - Multiple Devices

Size: px
Start display at page:

Download "Character Device Drivers One Module - Multiple Devices"

Transcription

1 Review from previous classes Three Types: Block, Character, and Network Interface Device Drivers MAJOR & MINOR numbers assigned register_chrdev_region(), alloc_chrdev_region(), unregister_chrdev_region() Examined Install and Cleanup Scripts struct file_operations, struct cdev, struct inode, and struct file open(), read(), write(), and release() Kernel Primitives for Memory Access: copy_to_user(), copy_from_user(), put_user(), and get_user(). request_region(), release_region() outb(), inb() ndelay(), udelay(), mdelay()

2 One Module for Multiple Devices App Driver DEV 1 DEV 2 The module will register multiple minor device numbers, one for each hardware device it plans to control. Consider COM ports. One common driver for all COM ports. This concept leads to critical region management. What s a critical region of code?

3 Case Study: Stepper Motor via Parallel Port App L R Driver? Motor 0 Motor 1 Out of the parallel port (0x378) bit winding D C B A D C B A motor motor 1 motor 0 Rotate Pattern: A AB B BC C CD D DA and repeat

4 Case Study: Stepper Motor via Parallel Port Our general algorithm for write() would be static int pos = 0; static char motor_table[8] = { 0x01, 0x03, 0x02, 0x06, 0x04, 0x0C, 0x08, 0x09 }; int module4_write (struct file *fp, const char user *buffer, size_t len, loff_t *offset) { int bytes_written = 0; char ch; const char *tmp; printk (KERN_INFO "module4: module4_write... \n"); tmp = buffer + len - 1; copy_from_user (&ch, tmp, 1); bytes_written = 1;

5 Case Study: Stepper Motor via Parallel Port switch (ch) { case 'L': pos++; if (pos > 7) pos = 0; break; case 'R': } pos--; if (pos < 0) pos = 7; break; ch = motor_table[pos]; outb (ch, MODULE4_PORT); module4_lastbytewritten = ch; return bytes_written; } /* end module4_write */

6 Case Study: Stepper Motor via Parallel Port static char motor_table[8] = { 0x01, 0x03, 0x02, 0x06, 0x04, 0x0C, 0x08, 0x09 }; Bit pattern is only for motor0 Same pattern can be used for motor1 Can we use one module to control both motors? What do we need to keep track of?

7 Case Study: Stepper Motor via Parallel Port We need to treat the parallel port data as two separate instances of data (low 4 bits for one motor, high 4 bits for the second) We need to extend our module, so that we can create two nodes within the /dev folder - one for motor0 and one for motor1 We have already seen how to allocate and register a cdev structure for an existing node we wish to install in /dev. Now we allocate two minor numbers, and register two cdev structures for, one for each minor number Let s examine the initialization process

8 Case Study: Stepper Motor via Parallel Port // we now need two separate cdev structures for the two nodes static int motor0_cdev; static int motor1_cdev; static struct semaphore motor_semaphore; // discussed later! static int init initialize_motor(void) { int rc; printk(kern_info "motor: initialize_motor() called.\n"); // allocate a major number for our module, along with 2 // minor numbers this time! "motor_minor" is our first of // two minor numbers. Thus, we'll have minor numbers // 0 and 1 for this driver. >> rc = alloc_chrdev_region (&motor_devicenumber, motor_minor, 2, motor_name); if (rc < 0) { printk(kern_info "motor: unable to allocate device region.\n"); goto init_error_0; } /* endif */

9 Case Study: Stepper Motor via Parallel Port motor_major = MAJOR (motor_devicenumber); printk (KERN_INFO "motor: during INIT... major: %d minor: %d\n", motor_major, motor_minor); // initialize and register our character driver's file operations // we'll do this TWICE... once for minor 0, once for minor 1 >> cdev_init (&motor0_cdev, &motor_fops); motor0_cdev.owner = THIS_MODULE; motor0_cdev.ops = &motor_fops; >> rc = cdev_add (&motor0_cdev, MKDEV(motor_major, motor_minor), 1); if (rc) { printk(kern_info "motor: unable to add cdev struct.\n"); goto init_error_1; } /* endif */

10 Case Study: Stepper Motor via Parallel Port >> cdev_init (&motor1_cdev, &motor_fops); motor1_cdev.owner = THIS_MODULE; motor1_cdev.ops = &motor_fops; >> rc = cdev_add (&motor1_cdev, MKDEV(motor_major, motor_minor + 1), 1); if (rc) { printk(kern_info "motor: unable to add cdev struct.\n"); goto init_error_2; } /* endif */

11 Case Study: Stepper Motor via Parallel Port // now, initialize our access to I/O Port hardware // for this example, we're going to try to connect to // parallel port. Note that even though we have two // "logical" motors to support, there's only ONE parallel // port that they're controlled with! motor_region = request_region (MOTOR_PORT, 1, motor_name); if (motor_region == NULL) { printk (KERN_INFO "motor: unable to gain exclusive access to parallel port... " "but we'll use it anyways!\n"); // uncomment the next 2 lines if you wish to exit with // an error condition // rc = -EIO; // goto init_error_3; } /* endif */

12 Case Study: Stepper Motor via Parallel Port // initialize semaphore to control critical regions init_mutex (&motor_semaphore); // discussed later printk (KERN_INFO "motor: successfully completed init!\n"); return 0; // common error support for initialization init_error_3: cdev_del (&motor1_cdev); init_error_2: cdev_del (&motor0_cdev); init_error_1: unregister_chrdev_region (motor_devicenumber, 2); init_error_0: return rc; } /* end initialize_motor */

13 Two Motors with Common Handler Now let s look at the WRITE process again Select the appropriate value out of the table, and write the value to the parallel port. However, the work for motor1 is slightly different We need to shift the motor table value up by 4 bits, and then feed it out the parallel port. To avoid altering the positional information for motor0, We need to OR the data for motor1 with the existing data for motor0. And of course, vice versa if we're controlling motor

14 Two Motors with Common Handler int motor_write (struct file *fp, const char user *buffer, size_t len, loff_t *offset) We're missing a crucial piece of information - the inode structure We can't dereference this data during a write() operation, and hence, it appears we're destined to implement two separate drivers for the two motors. So, what do we do?

15 Two Motors with Common Handler int motor_open (struct inode *i, struct file *fp) The solution is within the file structure during the OPEN The file structure has a member called private_data, and is usually set to NULL to indicate "no private data". We allocate our own relative information to this pointer and we ll have access to it during the write process

16 Two Motors with Common Handler #include <asm/semaphore.h> typedef struct MOTOR_DATA { int pos; int minor; struct semaphore *sem; } MOTOR_DATA; // discussed later We dynamically allocate one of these structures extract the minor number from the user's request to open a node initialize the positional data member of this structure, connect the address of this structure to the private data member of the file structure passed down to the write() support (as well as read() and other functions) In release(), we deallocate the structure

17 Two Motors with Common Handler As usual, the KERNEL has versions of memory allocation and deallocation. kmalloc() for allocation of memory kfree() for release of memory

18 Two Motors with Common Handler // note: two flags, one for each motor, to ensure that only // one top level app has a given motor open at one time static int motor0_flagopen = 0; static int motor1_flagopen = 0; int motor_open (struct inode *i, struct file *fp) { int minor; MOTOR_DATA *pmotordata; // dereference device number from inode structure, // and extract the minor number. There are two macros, // imajor() and iminor(), which are used to extract the // major and minor values out of an inode structure! >> minor = iminor (i); printk (KERN_INFO "motor: motor_open for %d starting... \n", minor);

19 Two Motors with Common Handler // we will limit out char driver to only allow one // // Hence, return an error code (EBUSY in this case) >> switch (minor) { case 0: if (motor0_flagopen) { return -EBUSY; } /* endif */ motor0_flagopen++; break; case 1: if (motor1_flagopen) { return -EBUSY; } /* endif */ motor1_flagopen++; break; default: // a fault... invalid minor device number! return -EFAULT; } /* end switch */

20 Two Motors with Common Handler // at this point, either motor0 or motor1 has been // opened, and is now in use once and only once. // now we can allocate private data for this request // and store away in the file structure for later use. // NOTE: you MUST use kmalloc() and kfree() to support // kernel level memory allocation. The normal user level // malloc() and free() cannot be used! >> pmotordata = (MOTOR_DATA *)kmalloc (sizeof (MOTOR_DATA), GFP_KERNEL); if (pmotordata == NULL) { return -EFAULT; } /* endif */ // init our private data appropriately, and store the // pointer in our file structure pmotordata->minor = minor; pmotordata->pos = 0; pmotordata->sem = &motor_semaphore; // discussed later >> fp->private_data = (void *)pmotordata;

21 Update to the write() Support Now we have a mechanism for accessing the specific motor How do we use it?

22 Update to the write() Support int motor_write (struct file *fp, const char user *buffer, size_t len, loff_t *offset) { int bytes_written = 0; char ch; const char *tmp; MOTOR_DATA *pmotordata; // fetch our private motor data structure >> pmotordata = (MOTOR_DATA *)fp->private_data; printk (KERN_INFO "motor: motor_write %d... \n", pmotordata->minor);

23 Update to the write() Support tmp = buffer + len - 1; copy_from_user (&ch, tmp, 1); bytes_written = 1; >> switch (ch) { case 'L': pmotordata->pos++; if (pmotordata->pos > 7) pmotordata->pos = 0; break; case 'R': } pmotordata->pos--; if (pmotordata->pos < 0) pmotordata->pos = 7; break; >> ch = motor_table[pmotordata->pos];

24 Update to the write() Support // ensure we combine the motor table data found above, // // mask appropriately. // AAA >> switch (pmotordata->minor) { case 0: motor_lastbytewritten = motor_lastbytewritten & 0xF0; motor_lastbytewritten = motor_lastbytewritten ch; break; case 1: motor_lastbytewritten = motor_lastbytewritten & 0x0F; motor_lastbytewritten = motor_lastbytewritten (ch << 4); break; } /* end switch */ >> outb (motor_lastbytewritten, MOTOR_PORT); // BBB return bytes_written; } /* end motor_write */

25 Concurrency A module may in fact be rescheduled to run at a later time, if the Linux kernel deems something more worthy needs to go first. When we're altering the value in our global variable motor_lastbytewritten, and since we can have two opened motors concurrently, there exists a race condition during this adjustment. So, what do we do?

26 Concurrency We solve this problem with either a semaphore or a mutex Within the write() code (between AAA and BBB) we have our CRITICAL REGION semaphore needs to be initialized static struct semaphore motor_semaphore;... // inside the initialization function... init_mutex (&motor_semaphore);

27 Concurrency After initialization, we add the reference to the private_data structure // init our private data appropriately, and store the // pointer in our file structure pmotordata->minor = minor; pmotordata->pos = 0; >> pmotordata->sem = &motor_semaphore; fp->private_data = (void *)pmotordata;

28 Concurrency To use the mutex within the write() /* * insert in place of // AAA */ >> if (down_interruptible (pmotordata->sem)) return -ERESTARTSYS; /* * insert in place of // BBB */ >> up (pmotordata->sem);

29 Concurrency The down_interruptible() function manipulates the kernel semaphore cause a module to wait until the semaphore becomes available. This is essentially using the semaphore as a mutex object (supporting our required mutual exclusion). To release a semaphore, use the companion up() function. For more info: 1. Do a Google search for down_interruptible() to find out other ways to set up a mutex! 2. LDD #3 Chapter 5 Definitely take a look at Completions, SpinLocks, and seqlocks

30 In-Class Exercises Notes for Week 6 Student exercise to complete the CLEAR and RELEASE parts of today s class Exercise: Work on Assignment #3 Instead: Review Assignment #3 in class and discuss how to implement based upon the information reviewed in class. ioctl() will be reviewed next class. Need to know Project Choice by everyone by end of class

31 For next class Read the notes for Weeks 1 to 6 Read Linux Device Drivers Chapters 1, 2, 3, 5, & 9 Reminders: Mid-Term in 2 weeks October 28 th Projects Due: December 9 th

Linux Device Drivers

Linux Device Drivers Linux Device Drivers Modules A piece of code that can be added to the kernel at runtime is called a module A device driver is one kind of module Each module is made up of object code that can be dynamically

More information

The Note/1 Driver Design

The Note/1 Driver Design Nathan Lay Kelly Hirai 6/14/06 Device Drivers The Note/1 Driver Design Introduction The Music Quest Note/1 midi engine is a small midi controller that communicates over the parallel port. It features two

More information

Character Device Drivers

Character Device Drivers Character Device Drivers 張大緯 CSIE, NCKU The information on the slides are from Linux Device Drivers, Third Edition, by Jonathan Corbet, Alessandro Rubini, and Greg Kroah-Hartman. Copyright 2005 O Reilly

More information

REVISION HISTORY NUMBER DATE DESCRIPTION NAME

REVISION HISTORY NUMBER DATE DESCRIPTION NAME i ii REVISION HISTORY NUMBER DATE DESCRIPTION NAME iii Contents 1 The structure of a Linux kernel module 1 1.1 Install XV6...................................................... 1 1.2 Compile and load a

More information

Concurrency and Race Conditions (Linux Device Drivers, 3rd Edition (www.makelinux.net/ldd3))

Concurrency and Race Conditions (Linux Device Drivers, 3rd Edition (www.makelinux.net/ldd3)) (Linux Device Drivers, 3rd Edition (www.makelinux.net/ldd3)) Concurrency refers to the situation when the system tries to do more than one thing at once Concurrency-related bugs are some of the easiest

More information

CS 378 (Spring 2003)

CS 378 (Spring 2003) Department of Computer Sciences THE UNIVERSITY OF TEXAS AT AUSTIN CS 378 (Spring 2003) Linux Kernel Programming Yongguang Zhang (ygz@cs.utexas.edu) Copyright 2003, Yongguang Zhang This Lecture Device Driver

More information

Linux Device Drivers. 3. Char Drivers cont. 3. Char Drivers. 1. Introduction 2. Kernel Modules 3. Char Drivers 4. Advanced Char Drivers 5.

Linux Device Drivers. 3. Char Drivers cont. 3. Char Drivers. 1. Introduction 2. Kernel Modules 3. Char Drivers 4. Advanced Char Drivers 5. Linux Device Drivers Dr. Wolfgang Koch Friedrich Schiller University Jena Department of Mathematics and Computer Science Jena, Germany wolfgang.koch@uni-jena.de Linux Device Drivers 1. Introduction 2.

More information

What is a Linux Device Driver? Kevin Dankwardt, Ph.D. VP Technology Open Source Careers

What is a Linux Device Driver? Kevin Dankwardt, Ph.D. VP Technology Open Source Careers What is a Linux Device Driver? Kevin Dankwardt, Ph.D. VP Technology Open Source Careers kdankwardt@oscareers.com What does a driver do? Provides a more convenient interface to user-space for the hardware.

More information

Linux Device Drivers. 3. Char Drivers. 1. Introduction 2. Kernel Modules 3. Char Drivers 4. Advanced Char Drivers 5. Interrupts

Linux Device Drivers. 3. Char Drivers. 1. Introduction 2. Kernel Modules 3. Char Drivers 4. Advanced Char Drivers 5. Interrupts Linux Device Drivers Dr. Wolfgang Koch Friedrich Schiller University Jena Department of Mathematics and Computer Science Jena, Germany wolfgang.koch@uni-jena.de Linux Device Drivers 1. Introduction 2.

More information

Introduction Reading Writing scull. Linux Device Drivers - char driver

Introduction Reading Writing scull. Linux Device Drivers - char driver Overview 1 2 3 4 Major, minor File Operations The file Structure The inode structure Registraction simplest driver, suitable for most simple devices, follow the book. Jernej Figure: Vičič. (Simple Character

More information

Introduction to Operating Systems. Device Drivers. John Franco. Dept. of Electrical Engineering and Computing Systems University of Cincinnati

Introduction to Operating Systems. Device Drivers. John Franco. Dept. of Electrical Engineering and Computing Systems University of Cincinnati Introduction to Operating Systems Device Drivers John Franco Dept. of Electrical Engineering and Computing Systems University of Cincinnati Basic Computer Architecture CPU Main Memory System Bus Channel

More information

Kernel Modules. Kartik Gopalan

Kernel Modules. Kartik Gopalan Kernel Modules Kartik Gopalan Kernel Modules Allow code to be added to the kernel, dynamically Only those modules that are needed are loaded. Unload when no longer required - frees up memory and other

More information

Designing and developing device drivers. Coding drivers

Designing and developing device drivers. Coding drivers Designing and developing device drivers Coding drivers Registering a driver 2 calls to register a driver defined in int register_chrdev_region(dev_t first, unsigned int count, char *name);

More information

NPTEL Course Jan K. Gopinath Indian Institute of Science

NPTEL Course Jan K. Gopinath Indian Institute of Science Storage Systems NPTEL Course Jan 2012 (Lecture 17) K. Gopinath Indian Institute of Science Accessing Devices/Device Driver Many ways to access devices under linux Non-block based devices ( char ) - stream

More information

Introduction to Linux Device Drivers Recreating Life One Driver At a Time

Introduction to Linux Device Drivers Recreating Life One Driver At a Time Introduction to Linux Device Drivers Recreating Life One Driver At a Time Muli Ben-Yehuda mulix@mulix.org IBM Haifa Research Labs, Haifa Linux Club Linux Device Drivers, Technion, Jan 2004 p.1/42 why write

More information

USB. Development of a USB device driver working on Linux and Control Interface. Takeshi Fukutani, Shoji Kodani and Tomokazu Takahashi

USB. Development of a USB device driver working on Linux and Control Interface. Takeshi Fukutani, Shoji Kodani and Tomokazu Takahashi Linux USB Development of a USB device driver working on Linux and Control Interface Takeshi Fukutani, Shoji Kodani and Tomokazu Takahashi Recently, it s becoming more popular to utilize Linux for controlling

More information

Linux drivers - Exercise

Linux drivers - Exercise Embedded Realtime Software Linux drivers - Exercise Scope Keywords Prerequisites Contact Learn how to implement a device driver for the Linux OS. Linux, driver Linux basic knowledges Roberto Bucher, roberto.bucher@supsi.ch

More information

CS 423 Operating System Design: Introduction to Linux Kernel Programming (MP1 Q&A)

CS 423 Operating System Design: Introduction to Linux Kernel Programming (MP1 Q&A) CS 423 Operating System Design: Introduction to Linux Kernel Programming (MP1 Q&A) Professor Adam Bates Fall 2018 Learning Objectives: Talk about the relevant skills required in MP1 Announcements: MP1

More information

Device Drivers Demystified ESC 117. Doug Abbott, Principal Consultant Intellimetrix. Why device drivers? What s a device driver?

Device Drivers Demystified ESC 117. Doug Abbott, Principal Consultant Intellimetrix. Why device drivers? What s a device driver? ESC 117, Principal Consultant Intellimetrix Outline Introduction Why device drivers? What s a device driver? Abstract model of device driver OS agnostic What makes drivers seem complicated? Independently

More information

Memory Mapping. Sarah Diesburg COP5641

Memory Mapping. Sarah Diesburg COP5641 Memory Mapping Sarah Diesburg COP5641 Memory Mapping Translation of address issued by some device (e.g., CPU or I/O device) to address sent out on memory bus (physical address) Mapping is performed by

More information

The device driver (DD) implements these user functions, which translate system calls into device-specific operations that act on real hardware

The device driver (DD) implements these user functions, which translate system calls into device-specific operations that act on real hardware Introduction (Linux Device Drivers, 3rd Edition (www.makelinux.net/ldd3)) Device Drivers -> DD They are a well defined programming interface between the applications and the actual hardware They hide completely

More information

Interrupt handling. Interrupt handling. Deferred work. Interrupt handling. Remove an interrupt handler. 1. Link a struct work to a function

Interrupt handling. Interrupt handling. Deferred work. Interrupt handling. Remove an interrupt handler. 1. Link a struct work to a function Interrupt handling Interrupt handling error = request_irq(irq_number, interrupt_service_routine, flags, module_name, (void*)dataptr); error: == 0 OK!= 0 FAILED interrupt_service_routine: irqreturn_t interrupt_service_routine(int

More information

NPTEL Course Jan K. Gopinath Indian Institute of Science

NPTEL Course Jan K. Gopinath Indian Institute of Science Storage Systems NPTEL Course Jan 2012 (Lecture 18) K. Gopinath Indian Institute of Science Spinlocks & Semaphores Shared data betw different parts of code in kernel most common: access to data structures

More information

Embedded data structures and lifetime management

Embedded data structures and lifetime management Embedded data structures and lifetime management LinuxCon NA, August 24 th 2016 Shuah Khan shuahkh@osg.samsung.com 1 Abstract... Embedded data structures are a common occurrence in Linux Kernel code. When

More information

Prof. Dr. Hasan Hüseyin

Prof. Dr. Hasan Hüseyin Department of Electrical And Computer Engineering Istanbul, Turkey ECE519 Advanced Operating Systems Kernel Concurrency Mechanisms By Mabruka Khlifa Karkeb Student Id: 163103069 Prof. Dr. Hasan Hüseyin

More information

Linux Device Drivers Interrupt Requests

Linux Device Drivers Interrupt Requests Overview 1 2 3 Installation of an interrupt handler Interface /proc 4 5 6 7 primitive devices can be managed only with I/O regions, most devices require a more complicated approach, devices cooperate with

More information

MP3: VIRTUAL MEMORY PAGE FAULT MEASUREMENT

MP3: VIRTUAL MEMORY PAGE FAULT MEASUREMENT MP3: VIRTUAL MEMORY PAGE FAULT MEASUREMENT University of Illinois at Urbana-Champaign Department of Computer Science CS423 Fall 2011 Keun Soo Yim GOAL A Linux kernel module to profile VM system events

More information

Kernel Internals. Course Duration: 5 days. Pre-Requisites : Course Objective: Course Outline

Kernel Internals. Course Duration: 5 days. Pre-Requisites : Course Objective: Course Outline Course Duration: 5 days Pre-Requisites : Good C programming skills. Required knowledge Linux as a User Course Objective: To get Kernel and User Space of Linux and related programming Linux Advance Programming

More information

Simple char driver. for Linux. my_first.c: headers. my_first.c: file structure. Calcolatori Elettronici e Sistemi Operativi.

Simple char driver. for Linux. my_first.c: headers. my_first.c: file structure. Calcolatori Elettronici e Sistemi Operativi. Calcolatori Elettronici e Sistemi Operativi Simple char driver Simple char driver for Linux Code organization my_first.c driver code: Headers Macro definitions Device structure definition Globals and module

More information

Finish up OS topics Group plans

Finish up OS topics Group plans Finish up OS topics Group plans Today Finish up and review Linux device driver stuff Walk example again See how it all goes together Discuss talking to MMIO RTOS (on board) Deferred interrupts Discussion

More information

Memory Mapped I/O. Michael Jantz. Prasad Kulkarni. EECS 678 Memory Mapped I/O Lab 1

Memory Mapped I/O. Michael Jantz. Prasad Kulkarni. EECS 678 Memory Mapped I/O Lab 1 Memory Mapped I/O Michael Jantz Prasad Kulkarni EECS 678 Memory Mapped I/O Lab 1 Introduction This lab discusses various techniques user level programmers can use to control how their process' logical

More information

CS5460/6460: Operating Systems. Lecture 24: Device drivers. Anton Burtsev April, 2014

CS5460/6460: Operating Systems. Lecture 24: Device drivers. Anton Burtsev April, 2014 CS5460/6460: Operating Systems Lecture 24: Device drivers Anton Burtsev April, 2014 Device drivers Conceptually Implement interface to hardware Expose some high-level interface to the kernel or applications

More information

Memory Management: The process by which memory is shared, allocated, and released. Not applicable to cache memory.

Memory Management: The process by which memory is shared, allocated, and released. Not applicable to cache memory. Memory Management Page 1 Memory Management Wednesday, October 27, 2004 4:54 AM Memory Management: The process by which memory is shared, allocated, and released. Not applicable to cache memory. Two kinds

More information

Hunting Down Data Races in the Linux Kernel

Hunting Down Data Races in the Linux Kernel Hunting Down Data Races in the Linux Kernel Eugene A. Shatokhin www.rosalab.com Data Race "Simultaneous access to the same memory location by multiple threads, where at least one of the accesses modifies

More information

Formal Verification of Linux Device Drivers

Formal Verification of Linux Device Drivers Master s Thesis Formal Verification of Linux Device Drivers Thomas Witkowski May 2007 Supervisors: Prof. Dr. Daniel Kroening and Nicolas Blanc Contents 1. Introduction 7 1.1. Related Work...............................

More information

Administrivia. Introduction to Computer Systems. Pointers, cont. Pointer example, again POINTERS. Project 2 posted, due October 6

Administrivia. Introduction to Computer Systems. Pointers, cont. Pointer example, again POINTERS. Project 2 posted, due October 6 CMSC 313 Introduction to Computer Systems Lecture 8 Pointers, cont. Alan Sussman als@cs.umd.edu Administrivia Project 2 posted, due October 6 public tests s posted Quiz on Wed. in discussion up to pointers

More information

7.4 Simple example of Linux drivers

7.4 Simple example of Linux drivers 407 7.4 Simple example of Linux drivers In the previous section, we introduce a simple Hello module driver, it is just some information from the serial port output, the board did not correspond to the

More information

Loadable Kernel Module

Loadable Kernel Module Instituto Superior de Engenharia do Porto Mestrado em Engenharia Eletrotécnica e de Computadores Arquitetura de Computadores Loadable Kernel Module The objective of this lesson is to analyze, compile and

More information

Final Step #7. Memory mapping For Sunday 15/05 23h59

Final Step #7. Memory mapping For Sunday 15/05 23h59 Final Step #7 Memory mapping For Sunday 15/05 23h59 Remove the packet content print in the rx_handler rx_handler shall not print the first X bytes of the packet anymore nor any per-packet message This

More information

CSC369 Lecture 2. Larry Zhang, September 21, 2015

CSC369 Lecture 2. Larry Zhang, September 21, 2015 CSC369 Lecture 2 Larry Zhang, September 21, 2015 1 Volunteer note-taker needed by accessibility service see announcement on Piazza for details 2 Change to office hour to resolve conflict with CSC373 lecture

More information

Introduction to C: Pointers

Introduction to C: Pointers Introduction to C: Pointers Nils Moschüring PhD Student (LMU) Nils Moschüring PhD Student (LMU), Introduction to C: Pointers 1 1 Introduction 2 Pointers Basics Useful: Function

More information

- Knowledge of basic computer architecture and organization, ECE 445

- Knowledge of basic computer architecture and organization, ECE 445 ECE 446: Device Driver Development Fall 2014 Wednesdays 7:20-10 PM Office hours: Wednesdays 6:15-7:15 PM or by appointment, Adjunct office Engineering Building room 3707/3708 Last updated: 8/24/14 Instructor:

More information

Do not start the test until instructed to do so!

Do not start the test until instructed to do so! Instructions: Print your name in the space provided below. This examination is closed book and closed notes, aside from the permitted one-page formula sheet. No calculators or other electronic devices

More information

Class Information ANNOUCEMENTS

Class Information ANNOUCEMENTS Class Information ANNOUCEMENTS Third homework due TODAY at 11:59pm. Extension? First project has been posted, due Monday October 23, 11:59pm. Midterm exam: Friday, October 27, in class. Don t forget to

More information

Lecture. DM510 - Operating Systems, Weekly Notes, Week 11/12, 2018

Lecture. DM510 - Operating Systems, Weekly Notes, Week 11/12, 2018 Lecture In the lecture on March 13 we will mainly discuss Chapter 6 (Process Scheduling). Examples will be be shown for the simulation of the Dining Philosopher problem, a solution with monitors will also

More information

POSIX Shared Memory. Linux/UNIX IPC Programming. Outline. Michael Kerrisk, man7.org c 2017 November 2017

POSIX Shared Memory. Linux/UNIX IPC Programming. Outline. Michael Kerrisk, man7.org c 2017 November 2017 Linux/UNIX IPC Programming POSIX Shared Memory Michael Kerrisk, man7.org c 2017 mtk@man7.org November 2017 Outline 10 POSIX Shared Memory 10-1 10.1 Overview 10-3 10.2 Creating and opening shared memory

More information

Short Notes of CS201

Short Notes of CS201 #includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system

More information

Programming the GPMC driver

Programming the GPMC driver Embedded Systems with Linux Programming the GPMC driver Manuel Domínguez-Pumar Embedded Systems with Linux series Volume 3: Manuel Domínguez Pumar Electronic Engineering Department Technical University

More information

CS201 - Introduction to Programming Glossary By

CS201 - Introduction to Programming Glossary By CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with

More information

Computer Core Practice1: Operating System Week10. locking Protocol & Atomic Operation in Linux

Computer Core Practice1: Operating System Week10. locking Protocol & Atomic Operation in Linux 1 Computer Core Practice1: Operating System Week10. locking Protocol & Atomic Operation in Linux Jhuyeong Jhin and Injung Hwang Race Condition & Critical Region 2 Race Condition Result may change according

More information

Concurrency Aspects of Project 2

Concurrency Aspects of Project 2 Locking Concurrency Aspects of Project 2 Multiple producers, one consumer Multiple users can issue system calls at the same time Need to protect all shared data Examples Passengers may appear on a floor

More information

Linux Synchronization Mechanisms in Driver Development. Dr. B. Thangaraju & S. Parimala

Linux Synchronization Mechanisms in Driver Development. Dr. B. Thangaraju & S. Parimala Linux Synchronization Mechanisms in Driver Development Dr. B. Thangaraju & S. Parimala Agenda Sources of race conditions ~ 11,000+ critical regions in 2.6 kernel Locking mechanisms in driver development

More information

THREADS: (abstract CPUs)

THREADS: (abstract CPUs) CS 61 Scribe Notes (November 29, 2012) Mu, Nagler, Strominger TODAY: Threads, Synchronization - Pset 5! AT LONG LAST! Adversarial network pong handling dropped packets, server delays, overloads with connection

More information

REVISION HISTORY NUMBER DATE DESCRIPTION NAME

REVISION HISTORY NUMBER DATE DESCRIPTION NAME i ii REVISION HISTORY NUMBER DATE DESCRIPTION NAME iii Contents 1 Walking through the Assignment 2 1 1.1 Preparing the base code from Assignment 1..................................... 1 1.2 Dummy port

More information

Synchronization Spinlocks - Semaphores

Synchronization Spinlocks - Semaphores CS 4410 Operating Systems Synchronization Spinlocks - Semaphores Summer 2013 Cornell University 1 Today How can I synchronize the execution of multiple threads of the same process? Example Race condition

More information

Project 2-1 User Programs

Project 2-1 User Programs Project 2-1 User Programs Prof. Jin-Soo Kim ( jinsookim@skku.edu) T.A. Sejun Kwon (sejun000@csl.skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Supporting User Programs

More information

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files CSC209 Review CSC209: Software tools Unix files and directories permissions utilities/commands Shell programming quoting wild cards files ... and systems programming C basic syntax functions arrays structs

More information

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files. Compiler vs.

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files. Compiler vs. CSC209 Review CSC209: Software tools Unix files and directories permissions utilities/commands Shell programming quoting wild cards files... and systems programming C basic syntax functions arrays structs

More information

Linux DRM Developer s Guide

Linux DRM Developer s Guide Linux DRM Developer s Guide Linux DRM Developer s Guide Copyright 2008 Intel Corporation (Jesse Barnes ) The contents of this file may be used under the terms of the GNU General

More information

CSC369 Lecture 2. Larry Zhang

CSC369 Lecture 2. Larry Zhang CSC369 Lecture 2 Larry Zhang 1 Announcements Lecture slides Midterm timing issue Assignment 1 will be out soon! Start early, and ask questions. We will have bonus for groups that finish early. 2 Assignment

More information

Virtual File System (VFS) Implementation in Linux. Tushar B. Kute,

Virtual File System (VFS) Implementation in Linux. Tushar B. Kute, Virtual File System (VFS) Implementation in Linux Tushar B. Kute, http://tusharkute.com Virtual File System The Linux kernel implements the concept of Virtual File System (VFS, originally Virtual Filesystem

More information

Step Motor. Step Motor Device Driver. Step Motor. Step Motor (2) Step Motor. Step Motor. source. open loop,

Step Motor. Step Motor Device Driver. Step Motor. Step Motor (2) Step Motor. Step Motor. source. open loop, Step Motor Device Driver Step Motor Step Motor Step Motor source Embedded System Lab. II Embedded System Lab. II 2 Step Motor (2) open loop, : : Pulse, Pulse,, -, +5%, step,, Step Motor Step Motor ( ),

More information

Concurrency, Thread. Dongkun Shin, SKKU

Concurrency, Thread. Dongkun Shin, SKKU Concurrency, Thread 1 Thread Classic view a single point of execution within a program a single PC where instructions are being fetched from and executed), Multi-threaded program Has more than one point

More information

Operating Systems, Assignment 2 Threads and Synchronization

Operating Systems, Assignment 2 Threads and Synchronization Operating Systems, Assignment 2 Threads and Synchronization Responsible TA's: Zohar and Matan Assignment overview The assignment consists of the following parts: 1) Kernel-level threads package 2) Synchronization

More information

Recitation 14: Proxy Lab Part 2

Recitation 14: Proxy Lab Part 2 Recitation 14: Proxy Lab Part 2 Instructor: TA(s) 1 Outline Proxylab Threading Threads and Synchronization 2 ProxyLab ProxyLab is due in 1 week. No grace days Late days allowed (-15%) Make sure to submit

More information

Synchronization. CS61, Lecture 18. Prof. Stephen Chong November 3, 2011

Synchronization. CS61, Lecture 18. Prof. Stephen Chong November 3, 2011 Synchronization CS61, Lecture 18 Prof. Stephen Chong November 3, 2011 Announcements Assignment 5 Tell us your group by Sunday Nov 6 Due Thursday Nov 17 Talks of interest in next two days Towards Predictable,

More information

Motivation was to facilitate development of systems software, especially OS development.

Motivation was to facilitate development of systems software, especially OS development. A History Lesson C Basics 1 Development of language by Dennis Ritchie at Bell Labs culminated in the C language in 1972. Motivation was to facilitate development of systems software, especially OS development.

More information

Unix (Linux) Device Drivers

Unix (Linux) Device Drivers Unix (Linux) Device Drivers Kernel module that handles the interaction with an specific hardware device, hiding its operational details behind a common interface Three basic categories Character Block

More information

Crit-bit Trees. Adam Langley (Version )

Crit-bit Trees. Adam Langley (Version ) CRITBIT CWEB OUTPUT 1 Crit-bit Trees Adam Langley (agl@imperialviolet.org) (Version 20080926) 1. Introduction This code is taken from Dan Bernstein s qhasm and implements a binary crit-bit (alsa known

More information

Synchronization I. Jo, Heeseung

Synchronization I. Jo, Heeseung Synchronization I Jo, Heeseung Today's Topics Synchronization problem Locks 2 Synchronization Threads cooperate in multithreaded programs To share resources, access shared data structures Also, to coordinate

More information

Unleashing D* on Android Kernel Drivers. Aravind Machiry

Unleashing D* on Android Kernel Drivers. Aravind Machiry Unleashing D* on Android Kernel Drivers Aravind Machiry (@machiry_msidc) $ whoami Fourth year P.h.D Student at University of California, Santa Barbara. Vulnerability Detection in System software. machiry.github.io

More information

Embedded Systems Programming

Embedded Systems Programming Embedded Systems Programming Work Queue and Input Processing in Linux (Module 16) Yann-Hang Lee Arizona State University yhlee@asu.edu (480) 727-7507 Summer 2014 Example of Work Structure and Handler #include

More information

RCU in the Linux Kernel: One Decade Later

RCU in the Linux Kernel: One Decade Later RCU in the Linux Kernel: One Decade Later by: Paul E. Mckenney, Silas Boyd-Wickizer, Jonathan Walpole Slides by David Kennedy (and sources) RCU Usage in Linux During this same time period, the usage of

More information

ENCM 501 Winter 2019 Assignment 9

ENCM 501 Winter 2019 Assignment 9 page 1 of 6 ENCM 501 Winter 2019 Assignment 9 Steve Norman Department of Electrical & Computer Engineering University of Calgary April 2019 Assignment instructions and other documents for ENCM 501 can

More information

Linux Kernel Application Interface

Linux Kernel Application Interface Linux Kernel Application Interface Arseny Kurnikov Aalto University School of Electrical Engineering PO Box 13000, FI-00076 Aalto Espoo, Finland arseny.kurnikov@aalto.fi ABSTRACT This paper describes different

More information

Operating systems for embedded systems

Operating systems for embedded systems Operating systems for embedded systems Embedded operating systems How do they differ from desktop operating systems? Programming model Process-based Event-based How is concurrency handled? How are resource

More information

Chapter 6: Process Synchronization

Chapter 6: Process Synchronization Chapter 6: Process Synchronization Objectives Introduce Concept of Critical-Section Problem Hardware and Software Solutions of Critical-Section Problem Concept of Atomic Transaction Operating Systems CS

More information

Here's how you declare a function that returns a pointer to a character:

Here's how you declare a function that returns a pointer to a character: 23 of 40 3/28/2013 10:35 PM Violets are blue Roses are red C has been around, But it is new to you! ANALYSIS: Lines 32 and 33 in main() prompt the user for the desired sort order. The value entered is

More information

Laboratory Assignment #3. Extending scull, a char pseudo-device

Laboratory Assignment #3. Extending scull, a char pseudo-device Laboratory Assignment #3 Extending scull, a char pseudo-device Value: (See the Grading section of the Syllabus.) Due Date and Time: (See the Course Calendar.) Summary: This is your first exercise that

More information

Parameter passing. Programming in C. Important. Parameter passing... C implements call-by-value parameter passing. UVic SEng 265

Parameter passing. Programming in C. Important. Parameter passing... C implements call-by-value parameter passing. UVic SEng 265 Parameter passing Programming in C UVic SEng 265 Daniel M. German Department of Computer Science University of Victoria 1 SEng 265 dmgerman@uvic.ca C implements call-by-value parameter passing int a =

More information

CSci 4061 Introduction to Operating Systems. Programs in C/Unix

CSci 4061 Introduction to Operating Systems. Programs in C/Unix CSci 4061 Introduction to Operating Systems Programs in C/Unix Today Basic C programming Follow on to recitation Structure of a C program A C program consists of a collection of C functions, structs, arrays,

More information

CPSC 8220 FINAL EXAM, SPRING 2016

CPSC 8220 FINAL EXAM, SPRING 2016 CPSC 8220 FINAL EXAM, SPRING 2016 NAME: Questions are short answer and multiple choice. For each of the multiple choice questions, put a CIRCLE around the letter of the ONE correct answer. Make sure that

More information

Table of Contents. Preface... xi

Table of Contents. Preface... xi ,ldr3toc.fm.4587 Page v Thursday, January 20, 2005 9:30 AM Table of Contents Preface................................................................. xi 1. An Introduction to Device Drivers.....................................

More information

CSC209 Review. Yeah! We made it!

CSC209 Review. Yeah! We made it! CSC209 Review Yeah! We made it! 1 CSC209: Software tools Unix files and directories permissions utilities/commands Shell programming quoting wild cards files 2 ... and C programming... C basic syntax functions

More information

CSE 451: Operating Systems Winter Lecture 7 Synchronization. Steve Gribble. Synchronization. Threads cooperate in multithreaded programs

CSE 451: Operating Systems Winter Lecture 7 Synchronization. Steve Gribble. Synchronization. Threads cooperate in multithreaded programs CSE 451: Operating Systems Winter 2005 Lecture 7 Synchronization Steve Gribble Synchronization Threads cooperate in multithreaded programs to share resources, access shared data structures e.g., threads

More information

CS 453: Operating Systems Programming Project 5 (100 points) Linux Device Driver

CS 453: Operating Systems Programming Project 5 (100 points) Linux Device Driver CS 453: Operating Systems Programming Project 5 (100 points) Linux Device Driver 1 Setup In this assignment, we will write a simple character driver called booga. Please do a git pull --rebase in your

More information

Data Storage. August 9, Indiana University. Geoffrey Brown, Bryce Himebaugh 2015 August 9, / 19

Data Storage. August 9, Indiana University. Geoffrey Brown, Bryce Himebaugh 2015 August 9, / 19 Data Storage Geoffrey Brown Bryce Himebaugh Indiana University August 9, 2016 Geoffrey Brown, Bryce Himebaugh 2015 August 9, 2016 1 / 19 Outline Bits, Bytes, Words Word Size Byte Addressable Memory Byte

More information

Embedded Linux. Session 4: Introduction to the GPIO Kernel API. Martin Aebersold BFH-TI Dipl. El.-Ing. FH.

Embedded Linux. Session 4: Introduction to the GPIO Kernel API. Martin Aebersold BFH-TI Dipl. El.-Ing. FH. Embedded Linux Session 4: Introduction to the GPIO Kernel API Martin Aebersold BFH-TI Dipl. El.-Ing. FH martin.aebersold@bfh.ch Dr. Franz Meyer BFH-TI Prof. em. Franz.Meyer@bfh.ch GPIO General Purpose

More information

A Crash Course in C. Steven Reeves

A Crash Course in C. Steven Reeves A Crash Course in C Steven Reeves This class will rely heavily on C and C++. As a result this section will help students who are not familiar with C or who need a refresher. By the end of this section

More information

MaRTE OS Misc utilities

MaRTE OS Misc utilities MaRTE OS Misc utilities Daniel Sangorrin daniel.sangorrin@{unican.es, gmail.com} rev 0.1: 2008-5-12 1. Circular Memory Buffer This is a generic software component that allows the user to write some data

More information

CS140 Operating Systems Final December 12, 2007 OPEN BOOK, OPEN NOTES

CS140 Operating Systems Final December 12, 2007 OPEN BOOK, OPEN NOTES CS140 Operating Systems Final December 12, 2007 OPEN BOOK, OPEN NOTES Your name: SUNet ID: In accordance with both the letter and the spirit of the Stanford Honor Code, I did not cheat on this exam. Furthermore,

More information

CSE 509: Computer Security

CSE 509: Computer Security CSE 509: Computer Security Date: 2.16.2009 BUFFER OVERFLOWS: input data Server running a daemon Attacker Code The attacker sends data to the daemon process running at the server side and could thus trigger

More information

CS342 - Spring 2019 Project #3 Synchronization and Deadlocks

CS342 - Spring 2019 Project #3 Synchronization and Deadlocks CS342 - Spring 2019 Project #3 Synchronization and Deadlocks Assigned: April 2, 2019. Due date: April 21, 2019, 23:55. Objectives Practice multi-threaded programming. Practice synchronization: mutex and

More information

SYSTEM CALL IMPLEMENTATION. CS124 Operating Systems Fall , Lecture 14

SYSTEM CALL IMPLEMENTATION. CS124 Operating Systems Fall , Lecture 14 SYSTEM CALL IMPLEMENTATION CS124 Operating Systems Fall 2017-2018, Lecture 14 2 User Processes and System Calls Previously stated that user applications interact with the kernel via system calls Typically

More information

Exercise Session 2 Systems Programming and Computer Architecture

Exercise Session 2 Systems Programming and Computer Architecture Systems Group Department of Computer Science ETH Zürich Exercise Session 2 Systems Programming and Computer Architecture Herbstsemester 216 Agenda Linux vs. Windows Working with SVN Exercise 1: bitcount()

More information

CS 153 Design of Operating Systems Winter 2016

CS 153 Design of Operating Systems Winter 2016 CS 153 Design of Operating Systems Winter 2016 Lecture 7: Synchronization Administrivia Homework 1 Due today by the end of day Hopefully you have started on project 1 by now? Kernel-level threads (preemptable

More information

2 nd Half. Memory management Disk management Network and Security Virtual machine

2 nd Half. Memory management Disk management Network and Security Virtual machine Final Review 1 2 nd Half Memory management Disk management Network and Security Virtual machine 2 Abstraction Virtual Memory (VM) 4GB (32bit) linear address space for each process Reality 1GB of actual

More information

Pointers. 1 Background. 1.1 Variables and Memory. 1.2 Motivating Pointers Massachusetts Institute of Technology

Pointers. 1 Background. 1.1 Variables and Memory. 1.2 Motivating Pointers Massachusetts Institute of Technology Introduction to C++ Massachusetts Institute of Technology ocw.mit.edu 6.096 Pointers 1 Background 1.1 Variables and Memory When you declare a variable, the computer associates the variable name with a

More information

Driving Me Nuts Writing a Simple USB Driver

Driving Me Nuts Writing a Simple USB Driver Driving Me Nuts Writing a Simple USB Driver Give your Linux box a multicolored light you can see from across the room, and learn how to write a simple driver for the next piece of hardware you want to

More information