Upload
ruth-holt
View
222
Download
1
Embed Size (px)
Citation preview
User-Space-to-Kernel InterfaceChapter 3
Presenter: Mojtaba MalekpourProfessor: Dr. Seyed Vahid Azhari
Introduction
User Mode
Kernel
Hardware
Application
Abstraction Implementation
Abstraction Detail
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?
Mechanisms
• Kernel Interfaces• Socket Based• Ioctl• Kernel System Calls• Sending Signals• Upcall• Mmap
Kernel Interfaces
• Kernel Interfaces• Procfs• Sysfs• Sysctl• Configfs• Debugfs
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
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
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
Practical!
• Example:• Exe Read.c
Sysfs
• Represent the device model• Contains information about
• Devices• Drivers• Buses
• Use for device• Heavily structured • A lot of links between the individual directories
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
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
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
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
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
Sysctl
• Example• cat /proc/sys/net/ipv4/ip_default_ttl • cat /proc/sys/net/ipv4/ipfrag_high_thresh
add a new file
• How can add a new file in /proc• Exe jif.c
• Show number of clock• cat /prog/jif
Ioctl
• Documentation/ioctl-number.txt • ifconfig command uses ioctl to communicate with the kernel
• #include <sys/ioctl.h>• int ioctl(int d, int request, ...);
Practical
• Exe iotcl.c• Turn on and off capslook
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
Tanks for your
attention