chapter 3 presenter: mojtaba malekpour professor: dr. seyed vahid azhari
TRANSCRIPT
![Page 1: Chapter 3 Presenter: Mojtaba Malekpour Professor: Dr. Seyed Vahid Azhari](https://reader036.vdocument.in/reader036/viewer/2022070413/5697bff61a28abf838cbe221/html5/thumbnails/1.jpg)
User-Space-to-Kernel InterfaceChapter 3
Presenter: Mojtaba MalekpourProfessor: Dr. Seyed Vahid Azhari
![Page 2: Chapter 3 Presenter: Mojtaba Malekpour Professor: Dr. Seyed Vahid Azhari](https://reader036.vdocument.in/reader036/viewer/2022070413/5697bff61a28abf838cbe221/html5/thumbnails/2.jpg)
Introduction
User Mode
Kernel
Hardware
Application
Abstraction Implementation
Abstraction Detail
![Page 3: Chapter 3 Presenter: Mojtaba Malekpour Professor: Dr. Seyed Vahid Azhari](https://reader036.vdocument.in/reader036/viewer/2022070413/5697bff61a28abf838cbe221/html5/thumbnails/3.jpg)
A Question
• How a user application use kernel info?
• Example:• How can find number of CPU clock in a C++ application?• How can access ARP table in a application?
![Page 4: Chapter 3 Presenter: Mojtaba Malekpour Professor: Dr. Seyed Vahid Azhari](https://reader036.vdocument.in/reader036/viewer/2022070413/5697bff61a28abf838cbe221/html5/thumbnails/4.jpg)
Mechanisms
• Kernel Interfaces• Socket Based• Ioctl• Kernel System Calls• Sending Signals• Upcall• Mmap
![Page 5: Chapter 3 Presenter: Mojtaba Malekpour Professor: Dr. Seyed Vahid Azhari](https://reader036.vdocument.in/reader036/viewer/2022070413/5697bff61a28abf838cbe221/html5/thumbnails/5.jpg)
Kernel Interfaces
• Kernel Interfaces• Procfs• Sysfs• Sysctl• Configfs• Debugfs
![Page 6: Chapter 3 Presenter: Mojtaba Malekpour Professor: Dr. Seyed Vahid Azhari](https://reader036.vdocument.in/reader036/viewer/2022070413/5697bff61a28abf838cbe221/html5/thumbnails/6.jpg)
Procfs
• Procfs• Located in /proc• Originally designed to export all kind of process information
• Current status of the process• All open file descriptors to the user space
![Page 7: Chapter 3 Presenter: Mojtaba Malekpour Professor: Dr. Seyed Vahid Azhari](https://reader036.vdocument.in/reader036/viewer/2022070413/5697bff61a28abf838cbe221/html5/thumbnails/7.jpg)
Procfs and other purposes
• Provide information about the running system• CPU information• Interrupts information• Available memory• Version of kernel
• Information about • "idle devices“• "scsi devices“• "tty's".
• Networking information• Arp table• Network statistics• Lists of used sockets
![Page 8: Chapter 3 Presenter: Mojtaba Malekpour Professor: Dr. Seyed Vahid Azhari](https://reader036.vdocument.in/reader036/viewer/2022070413/5697bff61a28abf838cbe221/html5/thumbnails/8.jpg)
Practical!
• Example:• ls proc/• cat /proc/version• cat cpuinfo• cat filesystem• cat /proc/looks• cat /proc/net/dev• cat /proc/net/arp• cat /proc/net/route• cat /proc/net/tcp
![Page 9: Chapter 3 Presenter: Mojtaba Malekpour Professor: Dr. Seyed Vahid Azhari](https://reader036.vdocument.in/reader036/viewer/2022070413/5697bff61a28abf838cbe221/html5/thumbnails/9.jpg)
Practical!
• Example:• Exe Read.c
![Page 10: Chapter 3 Presenter: Mojtaba Malekpour Professor: Dr. Seyed Vahid Azhari](https://reader036.vdocument.in/reader036/viewer/2022070413/5697bff61a28abf838cbe221/html5/thumbnails/10.jpg)
Sysfs
• Represent the device model• Contains information about
• Devices• Drivers• Buses
• Use for device• Heavily structured • A lot of links between the individual directories
![Page 11: Chapter 3 Presenter: Mojtaba Malekpour Professor: Dr. Seyed Vahid Azhari](https://reader036.vdocument.in/reader036/viewer/2022070413/5697bff61a28abf838cbe221/html5/thumbnails/11.jpg)
Sysfs
• kernel 2.6.23 it contains the following 9 top-level directories• sys/block/ all known block devices such as hda/ ram/ sda/• sys/bus/ all registered buses
• device/ for all devices attached to that bus• driver/ for all drivers assigned with that bus.
• sys/class/ each device type have a subdirectory: for example /printer or /sound
• sys/device/ all devices known by the kernel, connected by the bus• sys/firmware/ files in this directory handle the firmware of some hardware• sys/fs/ files to control a file system• sys/kernel/ holds directories (mount points) for other filesystems• sys/module/ each kernel module loaded is represented with a directory.• sys/power/ files to handle the power state of some hardware
![Page 12: Chapter 3 Presenter: Mojtaba Malekpour Professor: Dr. Seyed Vahid Azhari](https://reader036.vdocument.in/reader036/viewer/2022070413/5697bff61a28abf838cbe221/html5/thumbnails/12.jpg)
Practical
• Example:• cat sys/• cat sys/class/ieee80211/phy0/macaddress• cat sys/class/net/wlan0/phy80211/macaddress• cat sys/class/power_supply/BAT1/energy_now• cat class/block/sda1/size
![Page 13: Chapter 3 Presenter: Mojtaba Malekpour Professor: Dr. Seyed Vahid Azhari](https://reader036.vdocument.in/reader036/viewer/2022070413/5697bff61a28abf838cbe221/html5/thumbnails/13.jpg)
Configfs
• The configfs is some what the counterpart of the sysfs• Full control by user• Difference between configfs and sysfs
• Configfs all objects are created from user space with a call to mkdir• The kernel responds with creating the attributes (files)• Can be read and written by the user• Use rmdir to deleted• life cycle of a configfs object is fully controlled by user space
![Page 14: Chapter 3 Presenter: Mojtaba Malekpour Professor: Dr. Seyed Vahid Azhari](https://reader036.vdocument.in/reader036/viewer/2022070413/5697bff61a28abf838cbe221/html5/thumbnails/14.jpg)
Debugfs
• To use RAM based file system • Especially designed for debugging purposes• Obtain some debugging information from their kernel code• Provide set or get a single value• Developer is also allowed to write its own read/write functions
![Page 15: Chapter 3 Presenter: Mojtaba Malekpour Professor: Dr. Seyed Vahid Azhari](https://reader036.vdocument.in/reader036/viewer/2022070413/5697bff61a28abf838cbe221/html5/thumbnails/15.jpg)
Sysctl
• Designed to configure kernel parameters at run time• Heavily used by the Linux networking subsystem• It can be used to configure some core kernel parameters• Represented as files in /proc/sys/*• The values can be accessed by
• cat• echo: set: only persists as long as the kernel is runningbut gets lost as
soon as the machine is rebooted• sysctl
![Page 16: Chapter 3 Presenter: Mojtaba Malekpour Professor: Dr. Seyed Vahid Azhari](https://reader036.vdocument.in/reader036/viewer/2022070413/5697bff61a28abf838cbe221/html5/thumbnails/16.jpg)
Sysctl
• Example• cat /proc/sys/net/ipv4/ip_default_ttl • cat /proc/sys/net/ipv4/ipfrag_high_thresh
![Page 17: Chapter 3 Presenter: Mojtaba Malekpour Professor: Dr. Seyed Vahid Azhari](https://reader036.vdocument.in/reader036/viewer/2022070413/5697bff61a28abf838cbe221/html5/thumbnails/17.jpg)
add a new file
• How can add a new file in /proc• Exe jif.c
• Show number of clock• cat /prog/jif
![Page 18: Chapter 3 Presenter: Mojtaba Malekpour Professor: Dr. Seyed Vahid Azhari](https://reader036.vdocument.in/reader036/viewer/2022070413/5697bff61a28abf838cbe221/html5/thumbnails/18.jpg)
Ioctl
• Documentation/ioctl-number.txt • ifconfig command uses ioctl to communicate with the kernel
• #include <sys/ioctl.h>• int ioctl(int d, int request, ...);
![Page 19: Chapter 3 Presenter: Mojtaba Malekpour Professor: Dr. Seyed Vahid Azhari](https://reader036.vdocument.in/reader036/viewer/2022070413/5697bff61a28abf838cbe221/html5/thumbnails/19.jpg)
Practical
• Exe iotcl.c• Turn on and off capslook
![Page 20: Chapter 3 Presenter: Mojtaba Malekpour Professor: Dr. Seyed Vahid Azhari](https://reader036.vdocument.in/reader036/viewer/2022070413/5697bff61a28abf838cbe221/html5/thumbnails/20.jpg)
Netlink Sockets
• Especially designed for the communication between the kernel space and the user space
• Full-duplex communication link between the Linux kernel and user space
![Page 21: Chapter 3 Presenter: Mojtaba Malekpour Professor: Dr. Seyed Vahid Azhari](https://reader036.vdocument.in/reader036/viewer/2022070413/5697bff61a28abf838cbe221/html5/thumbnails/21.jpg)
Tanks for your
attention