csci-3753: operating systems fall 2019mnslab.org/.../f19_3753_anh_recitation_week4.pdf ·...
TRANSCRIPT
CSCI-3753: Operating SystemsFall 2019
Anh NguyenDepartment of Computer Science University of Colorado Boulder
Programming Assignment 2
2CSCI 3753 Fall 2019
LKM – Quick Recap
•What are two main functions required in a LKM code?
•How to compile the LKM code?
•How to load the module into the kernel?
•How to unload the module from the kernel?
3CSCI 3753 Fall 2019
PA2 – Character Device File
4CSCI 3753 Fall 2019
Programs
Kernel
User Space
Physical Device
Device File (/dev/<name>)
Open, Read, Write, Close, Seek
File Operations
mknod –m <permission> <device_file_location><type of driver><major number><minor number>
For example,sudo mknod –m 777
/dev/simple_character_devicec2400
<major>:<minor>
Device Driver
<minor><name>
PA2 – Requirements
1. Dynamically allocate constant-size kernel buffer to store the data written by the user • kmalloc() • Allocate memory for objects smaller than page size in the
kernel at initialization time
• kfree()• Free memory previously allocated using kmalloc() before
exiting
2. NO over seeking/reading/writing in buffer
3. Always remember the position of pointer in the device file after each input action
6CSCI 3753 Fall 2019
PA2 – Requirements
1. Read/write function• Input: device file, user-space buffer, offset•Output (recommended): the number of bytes you read or
write at the end of each function call• If error, return -1
2. Seek function• Input: device file, offset, whence•Output (recommended)• If error, return -1
• If successful, return 0 or positive value
7CSCI 3753 Fall 2019
PA2 – Requirements
1. Open the device file at the beginning of the test program
2. Use the "register_chrdev" function to attach the module to the device file when loading the module
3. Use the ”unregister_chrdev" function to detach the module from the device file when unloading the module
8CSCI 3753 Fall 2019
PA2 – Updates
•asm/uaccess.h à linux/uaccess.h
• file_operations structure à start from line 1695 in file
/lib/modules/4.15.0-33-generic/build/include/linux/fs.h
• .close à .release
• For seek operation, there is no pointer returned.
loff_t (*llseek) (struct file *, loff_t, int)
change to
loff_t simple_character_driver_seek (struct file *, loff_t, int)
9CSCI 3753 Fall 2019
Week 4: Processes
10CSCI 3753 Fall 2019
Processes
•Programs that are running on your machine
•Managed by the kernel
•Have an ID associated with it called the process ID (PID)
•ps command• PID: Process ID
• TTY: Controlling terminal
associated with the process
• STAT: Process status code• TIME: Total CPU usage time
• CMD: Name of executable/command
11CSCI 3753 Fall 2019
/proc directory
•Contain virtual files and numbered directories corresponding to each running process
•Directory names = process ids
•When a process ends, its directory in /proc disappears automatically.
•Files in a numbered directory• cmdline• cwd
• environ• fd•maps, statm, mem; stat, status
12CSCI 3753 Fall 2019
/proc directory
• Some typical virtual files that provide • Hardware information:• /proc/cpuinfo: identifies the type of processor used by your
system• /proc/iomem: shows you the current map of the system's
memory for each physical device • /proc/meminfo• /proc/interrupts
• File-related info:• /proc/filesystems: displays a list of the file system types currently
supported by the kernel • /proc/partitions
• Kernel configuration parameters:• /proc/cmdline: shows the parameters passed to the kernel at the
time it is started• /proc/sys
13CSCI 3753 Fall 2019
top command
•Display a list of processes with their resource usage.
14CSCI 3753 Fall 2019
Process State
•New: The process is being created.
•Ready: The process is waiting to be assigned to a processor.
•Running: Instructions are being executed.
•Waiting: The process is waiting for some event to occur (such as an I/O completion or reception of a signal).
•Terminated: The process has finished execution.
15CSCI 3753 Fall 2019
Program vs Application vs Process vs Thread
16CSCI 3753 Fall 2019
•Program: a passive entity
•Application: a program loaded into the memory
•Process: a program actively executing from main memory within its own address space
•Thread: a logical flow or unit of execution that runs within the context of a process• Thread-safety, race condition, reentrancy
Week 4 – Checklist
q Discuss PA2
q Discuss processes vs threads
19CSCI 3753 Fall 2019