Brief Introduction to the Linux sysfs desktop operating system

Source: Internet
Author: User

I am very interested in Linux systems. Common Linux sysfs features Linux itself is the core part of this operating system, that is, the operating system kernel. The kernel is the most basic program for completing operations. It is responsible for the startup and termination of other programs, such as text editor programs, memory application processing, hard disk access, and network connection management.

The key to using Linux sysfs is to master the usage of these sysfs attributes. The following describes some common sysfs attributes to demonstrate their usage;
The sysfs attribute file of a device (PCI) is used as an example to list the usage of the attribute file on the corresponding kobject on a desktop video card. Generally, on the Linux desktop, There are video cards that support Xorg Software Package running as XWindow servers. Therefore, find the Xorg process number first, view All files used by the process. Note that the root user permission is required to view the process attributes );
# Ps xfa | grep Xorg
2001 tty1 Ss + 2: 24 \ _/usr/bin/Xorg: 0-nr-verbose-auth \
/Var/run/TPD/auth-for-TPD-NPrkZK/database-nolisten tcp vt1
# Lsof-nP-p 2001
Xorg 2001 root mem REG 617732 231033 \
/Usr/lib/xorg/modules/drivers/sis_drv.so
[...]
Xorg 2001 root mem REG 134217728 0 5529 \
/Sys/devices/pci0000: 00/0000: 00: 01.0/. 0/resource0
Xorg 2001 root mem REG 131072 0 5531 \
/Sys/devices/pci0000: 00/0000: 00: 01.0/. 0/resource1
[...]
Xorg 2001 root 7u REG 256 0 5504 \
/Sys/devices/pci0000: 00/0000: 00: 00.0/config
Xorg 2001 root 8u unix 0xdbe66000 0t0 8756 socket
Xorg 2001 root 9u REG 256 5528 \
/Sys/devices/pci0000: 00/0000: 00: 01.0/. 0/config

Note that the Xorg server opened "/sys/devices/pci0000: 00/0000: 00: 01.0/in the form of memory mem ing (mem. 0/resource0 "and"/sys/devices/pci0000: 00/0000: 00: 01.0. 0/resource1 "and opened"/sys/devices/pci0000: 00/0000: 00: 00.0/config "and"/sys/devices/pci0000: 00/0000: 00: 01.0. 0/config"
In fact, the config under the kobject directory corresponding to the PCI device represents the "configuration space" of the PCI device. For general PCI (non-PCI-E) devices, the configuration space is generally 256 bytes, this space can be dumped using the hexadecimal tool, as shown below. (For information about the three address spaces of the PCI device, see Appendix LDD3)

# Hexdump-C/sys/devices/pci0000: 00/0000: 00: 01.0/. 0/config
00000000 39 10 30 63 03 00 30 02 00 00 00 00 00 80 | 9.0c..0............. |
00000010 08 00 00 d8 00 00 00 e1 01 d0 00 00 00 00 | ...... |
00000020 00 00 00 00 00 00 00 00 00 00 00 00 19 10 30 1b | ...... 0 |
00000030 00 00 00 00 40 00 00 00 00 00 00 00 00 | ...... @ ...... |
00000040 01 50 02 06 00 00 00 00 00 00 00 00 00 |. P ...... |
00000050 02 00 30 00 0b 02 00 ff 00 00 00 00 00 00 |... 0 ...... |
00000060 00 00 00 00 00 00 00 00 00 00 00 00 | ...... |
*
00000100

The size of this space is exactly 256 bytes. People familiar with PCI can also know that the PCI configuration space can read a lot of useful information about this PCI device, such as vendor code, device code, IRQ Number, etc.; the first four bytes 0x39 0x10 0x30 0x63 are two short integers stored by little endian, therefore, their PCI vendor numbers and PCI device numbers are 0x1039 and 0x6330, respectively.
# Lspci-v-d 1039: 6330
. 0 VGA compatible controller: Silicon Integrated Systems [SiS] 661/741/760 PCI/AGP \
Or 662/761 Gx pcie vga Display Adapter (prog-if 00 [VGA controller])
Subsystem: Elitegroup Computer Systems Device 1b30
Flags: 66 MHz, medium devsel
BIST result: 00
Memory at d8000000 (32-bit, prefetchable) [size = 128 M]
Memory at e000000 (32-bit, non-prefetchable) [size = 128 K]
I/O ports at d000 [size = 128]
Capabilities: [40] Power Management version 2
Capabilities: [50] AGP version 3.0

On the PCI device, in addition to config, which is the interface of the configuration space for the user, there are also resource {, 2 ,...} is the resource space, which corresponds to the memory space that can be mapped to the PCI device. In addition, the PCI device provides many interfaces, all of which are listed as follows:

# Ls-lU/sys/devices/pci0000: 00/0000: 00: 01.0/. 0/
Total 0
-Rw-r -- 1 root 4096 12-09 uevent
-R -- 1 root 4096 12-09 resource
-R -- 1 root 4096 12-09 vendor
-R -- 1 root 4096 12-09 device
-R -- 1 root 4096 12-09 subsystem_vendor
-R -- 1 root 4096 12-09 00:28 subsystem_device
-R -- 1 root 4096 12-09 00:27 class
-R -- 1 root 4096 12-09 irq
-R -- 1 root 4096 12-09 local_cpus
-R -- 1 root 4096 12-09 00:28 local_cpulist
-R -- 1 root 4096 12-09 modalias
-Rw ------- 1 root 4096 12-09 enable
-Rw-r -- 1 root 4096 12-09 00:28 broken_parity_status
-Rw-r -- 1 root 4096 12-09 msi_bus
Lrwxrwxrwx 1 root 0 12-09 subsystem->.../bus/pci
Drwxr-xr-x 2 root 0 12-09 power
-Rw-r -- 1 root 256 12-08 23:03 config
-Rw ------- 1 root 134217728 12-08 23:03 resource0
-Rw ------- 1 root 134217728 12-09 resource0_wc
-Rw ------- 1 root 131072 12-08 23:03 resource1
-Rw ------- 1 root 128 12-09 resource2
-R -------- 1 root 0 12-09 rom

We can see many other property files. The permission bits of these property files are also correct, and those with w permission bits can be written. The 4096-byte attribute is generally a plain text description attribute, which can be read directly by cat and written using the echo string method. Other non-4096-byte attributes are generally binary attributes, similar to the preceding config attribute file. For plain text and binary attributes, the following section describes how to add Linux sysfs support.

From vendor, device, subsystem_vendor, subsystem_device, class, the read-only attributes of resource can read the vendor number, device number, subsystem vendor number, subsystem device number, PCI category, and resource table of the PCI device, these are the properties of the corresponding PCI device. In fact, they are read directly from the config binary file and read the numbers according to the configuration space format;
Enable can be used to disable or enable the PCI device. The process of the device is intuitive. Write 1 indicates enabled, and write 0 indicates disabled;
The subsystem and driver symbolic links point to the corresponding sysfs locations respectively. (The Missing driver symbolic links indicate that the device is not currently using a kernel-level driver)
Resource0, resource0_wc, resource1, and resource2 are generated separately from the resource definition section parsed from the "PCI configuration space". They are added by the PCI bus driver during the PCI device initialization phase, both are binary attributes, but no read/write interfaces are implemented. Only mmap memory ing interfaces are supported. IO errors are prompted when you try to read/write. The _ wc suffix indicates "write combined )", they are used for memory ing of applications to access the corresponding memory resource section on the corresponding PCI device;
With the complete support of the PCI core for Linux sysfs, each device does not even need a separate driver, as shown in. 0 "A kernel-level driver is not required. With the PCI core's configuration space discovery mechanism for the device, the system can automatically discover the resource attributes of different sections of the device, in the Xorg application, you can map the user space driver "/usr/lib/xorg/modules/drivers/sis_drv.so" directly, you can directly operate on the video card. You can see the example of this PCI device that has a/sys/devices/device object for the PCI device, it is very easy to access its attributes and set its attributes. The preceding section describes Linux sysfs desktop applications.

  1. Top 10 Linux operating system highlights
  2. Linux is not your reason
  3. Easily retrieve the lost root password in the Linux operating system
  4. Analyze the Linux and Windows operating systems for you
  5. Describes the hardware supported by Linux operating system installation and recognition.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.