CS 635 Advanced Systems Programming Fall 2007 Professor Allan B. Cruse University of San Francisco.

Slides:



Advertisements
Similar presentations
Linux device-driver issues
Advertisements

Computer System Laboratory
Building and Running Modules Sarah Diesburg COP 5641.
Building and Running Modules Linux Kernel Programming CIS 4930/COP 5641.
Using VMX within Linux We explore the feasibility of executing ROM-BIOS code within the Linux x86_64 kernel.
Creating a device-file node An introduction to some privileged Linux system-calls (needed for an upcoming programming exercise)
Computer Science 635 Advanced Systems Programming Fall 2007 Professor Allan Cruse.
Timeout for some demos An instructive look at how the Linux Operating System sets up system data-structures.
SiS 315 Graphics Engine Introduction to some capabilities of graphics accelerator hardware.
Dynamic kernel patching Could we implement a new Linux system-call without modifying any officially released kernel sources?
CS 635 Advanced Systems Programming Spring 2003 Professor Allan B. Cruse University of San Francisco.
How to make a pseudo-file As a follow-up to our first lab, we examine the steps needed to create our own ‘/proc’ file.
The ‘net_device’ structure A look at the main kernel-object concerned with a Linux system’s network interface controller.
Computer Science 686 SPECIAL TOPIC: Programming Gigabit Ethernet Spring 2008 Professor Allan Cruse.
Rapid prototyping of LKMs Configuring our Linux systems for the quick creation and use of loadable kernel modules.
CS 635 Advanced Systems Programming Spring 2005 Professor Allan B. Cruse University of San Francisco.
F2032 Fundamental of OS Chapter 1 Introduction to Operating System Part 4.
Tutorial and Demos on Linux Virtual Machine
Alternate Project 4:- Software Management CS-502 (EMC) Fall Alternate Project #4 Software Management CS-3013 Operating Systems, A-term 2009 Project.
1 SEEM3460 Tutorial Unix Introduction. 2 Introduction What is Unix? An operation system (OS), similar to Windows, MacOS X Why learn Unix? Greatest Software.
1 Introduction to Tool chains. 2 Tool chain for the Sitara Family (but it is true for other ARM based devices as well) A tool chain is a collection of.
Introduction to Operating Systems J. H. Wang Sep. 18, 2012.
For OS Experiments. What Do We Need? A Computer &
Guide to Linux Installation and Administration, 2e1 Chapter 8 Basic Administration Tasks.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Course Overview Ted Baker  Andy Wang COP 5641 / CIS 4930.
Introduction to Operating Systems J. H. Wang Sep. 18, 2015.
Isecur1ty training center Presented by : Eng. Mohammad Khreesha.
Old Chapter 10: Programming Tools A Developer’s Candy Store.
1 計算機程式設計 Introduction to Computer Programming Lecture01: Introduction and Hello World 9/10/2012 Slides modified from Yin Lou, Cornell CS2022: Introduction.
Python – Part 1 Python Programming Language 1. What is Python? High-level language Interpreted – easy to test and use interactively Object-oriented Open-source.
CS 444 Introduction to Operating Systems
Python From the book “Think Python”
Introduction to Eclipse CSC 216 Lecture 3 Ed Gehringer Using (with permission) slides developed by— Dwight Deugo Nesa Matic
CS 390 Unix Programming Summer Unix Programming - CS 3902 Course Details Online Information Please check.
Guide to Linux Installation and Administration, 2e1 Chapter 7 The Role of the System Administrator.
Troubleshooting and Performance
Guide to Linux Installation and Administration1 Chapter 4 Running a Linux System.
Kernel Modules. Kernel Module Pieces of code that can be loaded and unloaded into the kernel upon demand. Compiled as an independent program With appropriate.
Course Overview Ted Baker  Andy Wang COP 5641 / CIS 4930.
CSC 660: Advanced Operating SystemsSlide #1 CSC 660: Advanced OS Memory Addressing / Kernel Modules.
CSNB334 Advanced Operating Systems Course Introduction Lecturer: Abdul Rahim Ahmad.
Fall 2004CSI University of Ottawa Introduction to PHP Basic principles and syntax.
Implementation of Embedded OS Lab3 Linux Kernel Modules.
Guide to Linux Installation and Administration, 2e1 Chapter 11 Using Advanced Administration Techniques.
Introduction to Operating Systems J. H. Wang Sep. 15, 2010.
LOGO System Call. Introduction System call is the mechanism used by an application program to request service from the OS. Users use it to communicate.
CPS120: Introduction to Computer Science Compiling a C++ Program From The Command Line.
Lab 12 Department of Computer Science and Information Engineering National Taiwan University Lab12 – Driver 2014/12/16 1 /21.
Introduction to Operating Systems J. H. Wang Sep. 13, 2013.
Course Overview Ted Baker  Andy Wang COP 5641 / CIS 4930.
Object Oriented Programming COP3330 / CGS5409.  Compiling with g++  Using Makefiles  Debugging.
1 Week 8 Creating Simple Shell Scripts. 2 Chapter Objectives  In this chapter, you will :  Learn how to create Shell Scripts  Commenting / Making Portable.
UNIX Development: g++ and make CS 2204 Class meeting 8 Created by Doug Bowman, 2001 Modified by Mir Farooq Ali, 2002.
1 Intro to Kernel Modules and /proc Sarah Diesburg CS 3430 Operating Systems.
Course : PGClass : MCA Subject: Operating SystemSub.Code : 3CT11 Staff Name : S.SomasundaramYear & Sem : II nd & III rd.
W4118 Operating Systems Junfeng Yang. What this course is about  Fundamental OS concepts  OS: one of the most crucial, almost everything thru OS  What?
Computer System Structures
Introduction to Operating Systems
Development Environment
Want to play a game? – Linux Kernel Modules
Week 1 Gates Introduction to Information Technology cosc 010 Week 1 Gates
What is make? make is a system utility for managing the build process (compilation/linking/etc). There are various versions of make; these notes discuss.
Introduction to Operating Systems
Intro to Kernel Modules and /proc
CS-3013 Operating Systems Hugh C. Lauer
CS 6560 Operating System Design
CS 6560 Operating System Design Kernel Loadable Modules
Week 1 – Lesson 2: Creating Shell Scripts, Linux Commands
Presentation transcript:

CS 635 Advanced Systems Programming Fall 2007 Professor Allan B. Cruse University of San Francisco

Instructor Contact Information Office: Harney Science Center – 212 Hours: Mon-Wed-Fri 12:45pm-1:30pm Tues-Thurs 6:30pm-7:15pm Phone: (415) Webpage:

The class website URL: –General description of the course –Links to some useful online resources –Lecture-slides and demo-programs –System software for use with this course –Class announcements (e.g., exam dates) –A link to our CS635 discussion-list –Our textbook reading assignments

Course Textbooks Jonathan Corbet, Alessandro Rubini and Greg Kroah-Hartman, Linux Device Drivers (3rd Ed), O’Reilly Media, Inc (2005) Daniel Bovet and Marco Cesati, Understanding the Linux Kernel (3rd Ed), O’Reilly Media, Inc (2006)

Some important prerequisites You are acquainted with x86 architecture You can execute Linux/UNIX commands You know how to use a text-editing tool You can write programs in the C language You can print out a program’s source-file

Typical C layout Basic structure of a C program: –Comment-banner (showing title and abstract) –Preprocessor directives (e.g., for header-files) –Global data-declarations (if they are needed) –Required ‘main()’ function (as the entry-point) –Can invoke ‘printf()’ (for ‘formatted’ output) –Optionally may define some other functions

Example program in C

‘Extensibility’ A modern OS needs the ability to evolve –Will need to support new devices –Will need to allow ‘bugs’ to be fixed –Will need to permit performance gains Else OS may suffer early obsolescence!

Extensibility with Linux Two mechanisms for ‘extensibility’: ‘Open Source’ development ‘Loadable’ kernel modules (LKMs)

Loadable Kernel Modules Convenient technique for OS ‘extensibility’ Also allows us to study how kernel works Kernel can be modified while it’s running No need to recompile and then reboot But inherently unsafe: any ‘bug’ can cause a system malfunction -- or complete crash!

‘Superuser’ privileges Modifying a running kernel is ‘risky’ Only authorized ‘system administrators’ are allowed to install kernel modules But our classroom workstations will allow us some (limited) administrator privileges

‘insmod’ and ‘rmmod’ We’re allowed to ‘install’ kernel objects: $ /sbin/insmod myLKM.ko We’re allowed to ‘remove’ kernel objects: $ /sbin/rmmod myLKM Anyone is allowed to ‘list’ kernel objects: $ /sbin/lsmod

Creating a new LKM You can use any text-editor (e.g., ‘vi’ or ‘emacs’) to create source-code (in the C language) for a Linux kernel module (i.e., an LKM) But a kernel module differs from a normal C application program (e.g., no ‘main()’ function) A kernel module cannot call any of the familiar functions from the standard C runtime libraries For any LKM, two entry-points are mandatory (one for ‘initialization’, and one for ‘cleanup’)

Normal LKM structure Resembles normal layout of C programs but Two ‘module administration’ functions [these are required] plus Appropriate ‘module service’ functions [these are optional]

Other LKM differences Module uses ‘printk()’ instead of ‘printf()’ Includes the header-file Specifies a legal software license (“GPL”) Compilation requires a special ‘Makefile’ Execution is “passive” (it’s a ‘side-effect’) Module has no restriction on ‘privileges’

Required module functions int init_module( void ); // this gets called during module installation void cleanup_module( void ); // this gets called during module removal A newer syntax allows memory-efficiency: module_init(my_init); module_exit(my_exit);

Kernel module written in C

Format of the ‘Makefile’ ifneq ($(KERNELRELEASE),) obj-m := mymod.o else KERNELDIR := /lib/modules/$(shell uname –r)/build PWD := $(shell pwd) default: $(MAKE) -C $(KERNELDIR) M=$(PWD) modules endif

Inconveniences That ‘Makefile’ has to be edited every time you create another new module!  Then, when you compile the new module, like this: $ make there are more than a half-dozen files that get created (some of them are ‘hidden’) in your current directory, but just one is the ‘.ko’ (kernel object) that you really wanted

Our ‘mmake’ tool Since we will be writing and compiling lots of modules during our course, we wrote a tool that conveniently automates the steps You can simply type: $./mmake It creates the ‘Makefile’ you need, in your current directory, to compile all modules that currently reside in that directory Afterward it erases all the unneeded files!

Improvement to ‘mmake’ After watching past students use ‘mmake’ we realized that it would be better to allow compiling just one module at a time We kept the former behavior as an option But now we allow the user to specify with a command-line parameter which module (or modules) they wish to re-compile: $./mmake mymod

In-class exercise #1 Download ‘mmake.cpp’ from class website and compile it with ‘make’ (or alternatively use: $ g++ mmake.cpp –o mmake ) Download the ‘kello.c’ source-file from the website, and compile it using ‘mmake’ Add the ‘kello.ko’ kernel-object to Linux using the Linux ‘/sbin/insmod’ command Use ‘dmesg’ to view the kernel’s log-file Remove ‘kello’ (with ‘/sbin/rmmod kello’)

Showing kernel messages You can modify the ‘printk()’ text-string so its message will be sure to be displayed – -- it will be output to the graphical desktop Here’s how you can do it: printk( “ Hello, everybody! \n” ); This log-level indicates a ‘kernel emergency’

In-class exercise #2 Modify the ‘kello.c’ source-file so that the messages will be visible in a window on the graphical desktop (in addition to being written to the kernel’s log-file) You can switch from graphics-mode to a text-mode console with F1 You can switch back to graphics mode by typing F7

Summary Download mmake.cpp and kello.c Compile mmake.cpp using ‘make’ Then compile kello.c using ‘mmake’ Install ‘kello.ko’ (and see printk-message) Remove ‘kello’ (to see another message) Modify the ‘printk()’ statements in kello.c Recompile and reinstall to view new info