I have been watching the device model over the past few days, and the kernel code has become increasingly frustrating, especially the relationship between kboject, kset, and ktype. However, I plan to skip these important structures and introduce the bus, device, and driver-device management. First, we will introduce how to use it and have the opportunity to introduce the general principles.
Http://www.360doc.com/content/11/0902/12/7534118_145217834.shtml
Bytes
1. sysfs File System
The device model is a new feature introduced by kernel 2.6. The device model provides an independent mechanism to represent a device and describe its topological structure in the system.
In the 2.4 kernel, information about the device is stored in/proc.
In the 2.6 kernel, the kernel classifies device-related information into the newly added sysfs file system and mounts it to the/sys directory, allows users to access through user space.
Next we will briefly introduce some directories in SYS:
Block: used to manage Block devices ,(
I/O devices are generally divided into two categories: Block devices and character devices. Block devices store information in blocks of a fixed size. Each block has its own address. The size of a data block is usually between 512 bytes and 32768 bytes. The basic feature of Block devices is that each block can be read and written independently of other blocks. A disk is the most common block device. In most UNIX operating systems, Block devices only support block-based access, such as disks. kylin supports accessing Block devices in character mode, that is, it supports reading/writing disks and other Block devices in character units. Therefore, Block devices, such as disks, In the/dev directory appear as character devices. Therefore, the differences between character devices and Block devices are mainly reflected in the management method in the Kylin kernel, the operation method and the kernel/Device Driver Interface.
) Each block device in the system corresponds to a sub-directory under this directory.
Bus: used to manage the bus. If a bus is not registered, there is a subdirectory under the directory.
Each sub-directory of the bus has two sub-directories: devices and drivers.
Devices includes all devices in the system that belong to the bus.
Drivers contains all drivers of the bus in the system.
Class: classifies devices in the system by function.
Devices: This Directory provides the device topology in the system.
Dev: View of the registered device nodes in this directory.
Kernel: Related Parameters in the kernel.
Module: the module information in the kernel.
Fireware: the firmware information in the kernel.
FS: Describes the file system in the kernel.
//////////////////////////////////////// //////////////////////////////
/ProcThe system information provided by various files in a file system is not specific to a specific process, but can be used in the context of the entire system. Files that can be used vary with system configurations. The command procinfo can display multiple system information based on some of the files. The files under/proc are described in detail below.
--------------------------------------------------------------------------------
/Proc/cmdline File
This file provides the command line for Kernel startup. It is very similar to the cmdline entry used for processes.
Example:
[Root @ localhost proc] # Cat cmdline
RO root = label =/rhgb quiet
--------------------------------------------------------------------------------
/Proc/cpuinfo File
This file provides a variety of information about the system CPU. This information is obtained from the CPU test code in the kernel. The file lists the general CPU model (386,486,586,686, etc.) and more specific information (manufacturer, model, and version ). The file also contains the processor speed represented by bogomips. If multiple features or bugs of the CPU are detected, the file also contains the corresponding identifier. The format of this file is: The file consists of multiple lines, each line includes a domain name, a colon and a value.
Example:
[Root @ localhost proc] # Cat cpuinfo
Processor: 0
Vendor_id: authenticamd
CPU family: 6
Model: 8
Model name: AMD athlon (TM) XP 1800 +
Stepping: 1
CPU MHz: 1530.165
Cache size: 256 KB
Fdiv_bug: No
Hlt_bug: No
F00f_bug: No
Coma_bug: No
FPU: Yes
Fpu_exception: Yes
Cpuid level: 1
WP: Yes
Flags: fpu vme de pse tsc msr pae mce cx8 APIC mtrr pge mca cmov Pat limit 36 MMX fxsr SSE syscall mmxext 3 dnowext 3 dnow
Bogomips: 2998.27
--------------------------------------------------------------------------------
/Proc/devices File
This file lists the characters and main device numbers of Block devices, and the names of devices allocated to these device numbers.
Example:
[Root @ localhost/] # Cat/proc/devices
Character devices:
1 mem
4/dev/VC/0
4 tty
4 TTYs
5/dev/tty
5/dev/console
5/dev/ptmx
6 lp
7 VCs
10 Misc
13 Input
14. Sound
29 FB
36 Netlink
116 ALSA
128 PTM
136 PTS
180 USB
Block devices:
1 ramdisk
2 FD
3 ide0
9 MD
22 ide1
253 device-mapper
254 MDP
--------------------------------------------------------------------------------
/Proc/DMA File
This file lists the DMA channels retained by the driver and the names of the drivers that keep them. Casade is used to separate the sub-DMA controller from the master controller for the DMA row; this row cannot be used for other purposes.
Example:
[Root @ localhost ~] # Cat/proc/DMA
4: Cascade
--------------------------------------------------------------------------------
/Proc/filesystems File
This file lists available file system types, one type and one row. Although they are usually file system types compiled into the kernel, the file can also contain other file system types that can be attached to the loaded kernel module.
Example:
[Root @ localhost proc] # Cat/proc/filesystems
Nodev sysfs
Nodev rootfs
Nodev bdev
Nodev proc
Nodev sockfs
Nodev binfmt_misc
Nodev usbfs
Nodev usbdevfs
Nodev futexfs
Nodev tmpfs
Nodev pipefs
Nodev eventpollfs
Nodev devpts
Ext2
Nodev ramfs
Nodev hugetlbfs
Iso9660
Nodev mqueue
Nodev selinuxfs
Ext3
Nodev rpc_pipefs
Nodev autofs
--------------------------------------------------------------------------------
/Proc/interrupts File
Each row of this file has a reserved interrupt. The fields in each row include the interrupt number, the number of times the thread is interrupted, the domain with a plus sign (sa_interrupt flag setting), and the name of the driver that registers the interrupt. You can run the cat command to manually view the current file, just like View/proc/DMA and/proc/ioports, before installing the new hardware. These files list the resources currently in use (but do not include the resources used by the hardware that does not load the driver ).
Example:
[Root @ localhost specs] # Cat/proc/interrupts
Cpu0
0: 7039406 XT-PIC Timer
1: 6533 XT-PIC i8042
2: 0 XT-PIC Cascade
3: 0 XT-PIC uhci_hcd.
5: 108 XT-PIC via8233, uhci_hcd
8: 1 XT-PIC rtc
9: 0 XT-PIC ACPI
10: 0 XT-PIC ehci_hcd
11: 17412 XT-PIC uhci_hcd, eth0
12: 140314 XT-PIC i8042
14: 37897 XT-PIC ide0
15: 60813 XT-PIC ide1
NMI: 0
Err: 1
--------------------------------------------------------------------------------
/Proc/ioports File
This file lists the many I/O port ranges registered by drivers of multiple devices, such as disk drives, Ethernet cards, and sound card devices.
Example:
[Root @ localhost specs] # Cat/proc/ioports
2017-001f: dma1
0020-0021: pic1
0040-0043: timer0
0050-0053: timer1
0060-006f: keyboard
0070-0077: rtc
0080-008f: DMA page Reg
00a0-00a1: pic2
00c0-00df: dma2
00f0-00ff: FPU
0170-0177: ide1
01f0-01f7: ide0
0376-0376: ide1
0-037a: parport0
037b-037f: parport0
03c0-03df: VGA +
03f6-03f6: ide0
03f8-03ff: Serial
0800-0803: pm1a_evt_blk
0804-0805: pm1a_cnt_blk
0808-080b: pm_tmr
0810-0815: acpi cpu throttle
0820-0823: gpe0_blk
0cf8-0cff: PCI conf1
Dc00-dcff:. 0
Dc00-dcff: Via-Rhine.
E000-e0ff:. 5
E000-e0ff: via8233
E400-e41f:. 0
E400-e41f: uhci_hcd.
E800-e81f:. 1
E800-e81f: uhci_hcd.
Ec00-ec1f:. 2
Ec00-ec1f: uhci_hcd.
Fc00-fc0f:. 1
Fc00-fc07: ide0
Fc08-fc0f: ide1
--------------------------------------------------------------------------------
/Proc/kcore File
This file is the file stored in the system's physical memory in the core file format. For example, GDB can use it to check the data structure of the kernel. It is not a plain text, but one of the few binary format items in the/proc directory.
Example:
None
--------------------------------------------------------------------------------
/Proc/kmsg File
This file is used to retrieve kernel messages generated by printk. At any time, only one Super User-authorized process can read the file. You can also use the system to call syslog To retrieve these messages. You can use the dmesg tool or the klogd daemon to retrieve these messages.
Example:
None
--------------------------------------------------------------------------------
/Proc/ksyms File
This file lists the registered kernel symbols that give the addresses of variables or functions. Each line provides the address, name, and module for registering the symbol. The program ksyms, insmod and kmod use this file. It also lists the number of running tasks, the total number of tasks, and the last assigned PID.
Example:
None
--------------------------------------------------------------------------------
/Proc/loadavg File
This file provides the average system load calculated at several different time intervals, as shown in the uptime command. The first three figures show average load. This is calculated by calculating the average number of tasks in the queue in the past 1 minute, 5 minutes, and 15 minutes. Then there is the number of running tasks and total number of tasks. The last process ID used.
Example:
[Root @ localhost ~] # Cat/proc/loadavg
0.11 0.16 0.14 3/126 3912
--------------------------------------------------------------------------------
/Proc/locks File
This file contains the lock information on the opened file. Each row in the file describes the lock information on a specific file and document and the type of lock applied to the file. The kernel can also apply a mandatory lock to the file as needed.
Example:
[Root @ localhost RedHat] # Cat/proc/locks
1: POSIX advisory read 3822 03: 0a: 1067117 0 EOF
2: POSIX advisory read 3822 03: 0a: 1067138 0 EOF
3: POSIX advisory write 3326 03: 0a: 2326540 0 EOF
4: POSIX advisory write 2639 03: 0a: 2966595 0 EOF
5: Flock advisory write 2591 03: 0a: 2966586 0 EOF
6: POSIX advisory write 2540 03: 0a: 2966578 0 EOF
7: POSIX advisory write 2530 03: 0a: 2966579 0 EOF
8: POSIX advisory write 2402 03: 0a: 2966563 0 EOF
9: POSIX advisory write 2371 03: 0a: 2966561 0 EOF