Top Banner
CSCI-3753: Operating Systems Spring 2019 Anh Nguyen Department of Computer Science University of Colorado Boulder
16

CSCI-3753: Operating Systems Spring 2019mnslab.org/.../CSCI3753_Materials/S19_3753_Anh_Recitation_Week4… · PA2 –Character Device File CSCI 3753 Spring 2019 4 Programs Kernel

May 28, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: CSCI-3753: Operating Systems Spring 2019mnslab.org/.../CSCI3753_Materials/S19_3753_Anh_Recitation_Week4… · PA2 –Character Device File CSCI 3753 Spring 2019 4 Programs Kernel

CSCI-3753: Operating SystemsSpring 2019

Anh NguyenDepartment of Computer Science University of Colorado Boulder

Page 2: CSCI-3753: Operating Systems Spring 2019mnslab.org/.../CSCI3753_Materials/S19_3753_Anh_Recitation_Week4… · PA2 –Character Device File CSCI 3753 Spring 2019 4 Programs Kernel

PA 2 – Questions & Answers

2CSCI 3753 Spring 2019

Page 3: CSCI-3753: Operating Systems Spring 2019mnslab.org/.../CSCI3753_Materials/S19_3753_Anh_Recitation_Week4… · PA2 –Character Device File CSCI 3753 Spring 2019 4 Programs Kernel

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 Spring 2019

Page 4: CSCI-3753: Operating Systems Spring 2019mnslab.org/.../CSCI3753_Materials/S19_3753_Anh_Recitation_Week4… · PA2 –Character Device File CSCI 3753 Spring 2019 4 Programs Kernel

PA2 – Character Device File

4CSCI 3753 Spring 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_device

c

240

0

<major>:<minor>

Device Driver

<minor><name>

Page 5: CSCI-3753: Operating Systems Spring 2019mnslab.org/.../CSCI3753_Materials/S19_3753_Anh_Recitation_Week4… · PA2 –Character Device File CSCI 3753 Spring 2019 4 Programs Kernel

/dev directory

• Device Type

• Permissions

• Owner

• Group

•Major Device Number

•Minor Device Number

• Timestamp

• Device Name

5CSCI 3753 Spring 2019

Documentation/admin-guide/devices.txt

Page 6: CSCI-3753: Operating Systems Spring 2019mnslab.org/.../CSCI3753_Materials/S19_3753_Anh_Recitation_Week4… · PA2 –Character Device File CSCI 3753 Spring 2019 4 Programs Kernel

PA2 – Requirements

1. Dynamically allocate 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. Offset pointer in read/write function

3. NO over seeking/reading/writing in buffer

6CSCI 3753 Spring 2019

Page 7: CSCI-3753: Operating Systems Spring 2019mnslab.org/.../CSCI3753_Materials/S19_3753_Anh_Recitation_Week4… · PA2 –Character Device File CSCI 3753 Spring 2019 4 Programs Kernel

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

• For seek operation, there is no pointer returned.loff_t (*llseek) (struct file *, loff_t, int)

change toloff_t abc_llseek (struct file *, loff_t, int)

7CSCI 3753 Spring 2019

Page 8: CSCI-3753: Operating Systems Spring 2019mnslab.org/.../CSCI3753_Materials/S19_3753_Anh_Recitation_Week4… · PA2 –Character Device File CSCI 3753 Spring 2019 4 Programs Kernel

Week 4: Processes vs Threads

8CSCI 3753 Spring 2019

Page 9: CSCI-3753: Operating Systems Spring 2019mnslab.org/.../CSCI3753_Materials/S19_3753_Anh_Recitation_Week4… · PA2 –Character Device File CSCI 3753 Spring 2019 4 Programs Kernel

Processes

•Are the programs that are running on your machine•Are 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

9CSCI 3753 Spring 2019

Page 10: CSCI-3753: Operating Systems Spring 2019mnslab.org/.../CSCI3753_Materials/S19_3753_Anh_Recitation_Week4… · PA2 –Character Device File CSCI 3753 Spring 2019 4 Programs Kernel

/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

10CSCI 3753 Spring 2019

Page 11: CSCI-3753: Operating Systems Spring 2019mnslab.org/.../CSCI3753_Materials/S19_3753_Anh_Recitation_Week4… · PA2 –Character Device File CSCI 3753 Spring 2019 4 Programs Kernel

/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

11CSCI 3753 Spring 2019

Page 12: CSCI-3753: Operating Systems Spring 2019mnslab.org/.../CSCI3753_Materials/S19_3753_Anh_Recitation_Week4… · PA2 –Character Device File CSCI 3753 Spring 2019 4 Programs Kernel

top command

•Display a list of processes with their resource usage.

12CSCI 3753 Spring 2019

Page 13: CSCI-3753: Operating Systems Spring 2019mnslab.org/.../CSCI3753_Materials/S19_3753_Anh_Recitation_Week4… · PA2 –Character Device File CSCI 3753 Spring 2019 4 Programs Kernel

Program vs Application vs Process vs Thread

13CSCI 3753 Spring 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• Race condition à Thread-safe, reentrant

Page 14: CSCI-3753: Operating Systems Spring 2019mnslab.org/.../CSCI3753_Materials/S19_3753_Anh_Recitation_Week4… · PA2 –Character Device File CSCI 3753 Spring 2019 4 Programs Kernel

Process State

•New: The process is being created. •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). •Ready: The process is waiting to be assigned to a

processor.•Terminated: The process has finished execution.

14CSCI 3753 Spring 2019

Page 15: CSCI-3753: Operating Systems Spring 2019mnslab.org/.../CSCI3753_Materials/S19_3753_Anh_Recitation_Week4… · PA2 –Character Device File CSCI 3753 Spring 2019 4 Programs Kernel

IPC Mechanisms

•Signals / Interrupts•Notifying that an event has occurred

•Message Passing• Pipes• Sockets

•Remote Procedure Calls

•Shared Memory• Race conditions• Synchronization

15CSCI 3753 Spring 2019

Page 16: CSCI-3753: Operating Systems Spring 2019mnslab.org/.../CSCI3753_Materials/S19_3753_Anh_Recitation_Week4… · PA2 –Character Device File CSCI 3753 Spring 2019 4 Programs Kernel

Week 4 – Checklist

q Discuss PA2q Discuss processes vs threadsq Read more about IPC

17CSCI 3753 Spring 2019