Introduction to Linux Kernel Engineering--infrastructure

Source: Internet
Author: User

Basic functional Element Workqueue

The work queue under Linux is a way of delaying work, which can be performed by sleep, scheduling, and kernel threading, but is simpler than kernel threading and is typically used to handle task chains with dynamic task content. One feature of Workqueue is that it automatically generates different numbers of queues depending on the CPU. Each workqueue can add multiple work (using the Queue_work function).

Module Support Module Overview

Accessible address space, resources available,

Module parameters

User space modifies module parameters through "Echo-n ${value} >/sys/module/${modulename}/parameters/${parm}".

Module loading and unloading dynamic loading module Signature Special Hardware framework rapid I/O

is a physical connection, there is a corresponding software driver. For chip-to-chip, board-to-board connection, it can be used as the backplane connection of the embedded system. Uncommon in non-industry-specific systems.

Use of FPGAs: Xillybus

The Linux hardware system can contain FPGA chip, because FPGA can be programmed by hardware at random to achieve a specific function of the components, the implementation of the function is pure hardware, but it is also available to the Linux operating system, so need a kernel exists in the infrastructure to drive the FPGA to export to the user.

This driver component is xillybus. Xillybus users must put the IP core of the Xillybus module into the FPGA hardware in the FPGA, the kernel will run a Xillybus data forwarding module, exported to user space for user use. Since this is a versatile component, it is not possible to accurately guide the characteristics of data flow, so its data is used in FIFO caching. The devices in the user space are:/dev/xillybus_*,

$ cat MyData >/dev/xillybus_thisfifo

$ Cat/dev/xillybus_thatfifo > Hisdata

This allows the data to be read and written.

Rpmsg, Remoteproc

A board may have multiple CPUs running multiple operating systems at the same time, these operating systems may be able to share physical memory, possibly split. There is also a need for communication between the operating systems that share memory on these boards, but it is too expensive to use traditional socket communications. The kernel needs a cache that allows direct access to two CPUs as a communication space, creating a communication protocol called RPMSG. This mechanism has similar implementations in many upstream vendors ' SDKs. In general, large-scale embedded systems implement a protocol for inter-CPU communication, but roughly all use memory to divide a piece of memory into a block channel.

This board also has a need, is who first started the problem. The general practice is that one such system starts only one operating system, and the other operating system is started by the operating system that starts first. Starting someone else's operating system is called the main operating system system, not only it can control the startup, but also can control the shutdown restart, remote procedure calls. This framework function is called Remoteproc.

PWN

Universal interface for control of motors, LEDs, etc. A gpio that is similar to a soft-armor level.

PIN Controller

Many hardware devices have many configurable pins that are typically configured and managed through a series of registers, which are roughly the same type of configuration, resulting in abstract requirements. The configuration space for these pins is abstracted into a PIN controller registered to the kernel's PIN controll subsystem, unified management.

Vfio, UIO

Vfio is used to replace the UiO framework, allowing the client to access the device details directly, which means that the user-side device driver becomes possible. The main result of the work is that the client can configure the Iommu so that the client can also program the DMA. However, because it is a new thing, it currently only supports PCI device driver access (VFIO-PCI module), in addition to the CPU Iommu configuration, but also implemented only x86 and PowerPC two kinds.

The user-side device file is/dev/vfio/n. Users can use this to implement a full device driver, and the main purpose of the current is to drive transparent device-driven access to the virtual machine.

SysRq

SysRq Windows-like Ctrl+alt+del, as long as the system is not completely locked out of the state, will first respond to this command. In Linux This feature itself can be turned off or configured, in/PROC/SYS/KERNEL/SYSRQ. The way this series of commands is called in Linux sysrq key + command. SYSRQ is typically a secondary feature of the Print Screen button on most keyboards and needs to be called using Alt. Unlike Windows, Windows must jump out of the graphical interface after keystrokes, and Linux allows you to perform specific actions directly using key commands: sysrq+

' B ': Restart your computer now

' C ': immediately generates a system-level crash dump (accessed using a null pointer)

' d ': Displays all locks currently in use.

' E ': Send sigterm gives all processes outside of Init

' F ': Manually invoke Oom killer to kill one of the most CPU-capable processes

' G ': Used by kgdb

' H ': Show Help for using SYSRQ

' I ': Send Sigkill signal to all processes except Init

' J '-forcibly "Just thaw it"-filesystems frozen by the Fifreezeioctl.

' K ': kill all processes that are open on the current virtual terminal

' L '-shows a stack backtrace for all active CPUs.

' m ': Export the current memory information

' n '-used to make RT tasks nice-able

' O '-would shut your system off (if configured and supported).

' P '-would dump the current registers and the flags to your console.

' Q '-would dump per CPU lists of all armed hrtimers (and not regular

Timer_list timers) and detailed information about all

Clockevent devices.

' R '-Turns off keyboard raw mode and sets it to XLATE.

' s '-would attempt to sync all mounted filesystems.

' t '-would dump a list of current tasks and their information to your

Console.

' U '-would attempt to remount all mounted filesystems read-only.

' V '-forcefully restores framebuffer console

' V '-causes ETM buffer dump [arm-specific]

' W '-dumps tasks that is in uninterruptable (blocked) state.

' X '-used by Xmon interface on PPC/POWERPC platforms.

Show Global PMU registers on SPARC64.

' Y ': Print all registers

' Z ': Export ftrace buffer

' 0 '-' 9 ': Set the log level of the kernel

These commands are partially valid depending on the configuration of the kernel.

SysCtl

Clock high-precision clock synchronization: PTP

IEEE1588 defines a new method of clock synchronization. The advent of this approach is due to high-precision synchronization in the local area network does not have a good product. The accuracy of NTP and SNTP does not meet the requirements. PTP borrows from NTP, and the main idea is to synchronize the calibration with the device in the whole network through a synchronous signal periodically. There is only one master clock in a network, which is used to produce the highest precision signal, and the other is the boundary clock, which is used to receive synchronization information from the master clock to adjust itself.

Pps

The PPS device sends a pulse every second. The system can use this device to do clock synchronization, or other timing operations.

Watchdog

/dev/watchdog

Rtc

PC computers have a clock that can also be run offline, and there may be multiple non-PC computers. This clock can be seen as accurate and real-time in the runtime, but the hardware causes the deviation of long-term operation is unavoidable. The Linux kernel will query this value when it is started, and use it to maintain its own time information, and then when it starts, most Linux uses network time to re-determine the time of the machine, and also writes to the RTC hardware for calibration. The kernel subsystem that completes this work is called RTC.

Since the time of the RTC hardware is stored in the register, it is generally stored in the number of seconds since a certain time (1900 or 1970), and the size of the register is limited, so different systems approach this algorithm differently. For example, Uboot reads this value plus 1900 years is the current time, but Linux in addition will be judged if less than 1969, plus 100 years to get the current time. Because the algorithm is different, the clock time seen in Bootloader and Linux is not the same as normal.

The existence of the RTC subsystem makes different hardware clocks transparent to the system software, eliminating the hassle of programming. Similar to other modules, RTC also defines a device that can be accessed by the user in the/dev directory, called RTC or RTCN (n, a hardware system may have multiple RTC clocks, but most PCs have only one). Most RTC has interrupt function, the 8th interrupt in common x86 system is clock interrupt, the kernel can use the interrupt function to perform its own task periodically. The interrupt mechanism can also be used by the client via the RTC device. After you open the device file, use Ioctrl to set the frequency, periodically to read the device value, you can measure the time. Because the set frequency is set the clock to trigger the frequency of the 8th interrupt, the reading device is worth the number of interrupts since the last read operation so far. Therefore, each time you read it, you can get the current past. The granularity and accuracy of this time can be controlled by setting a different frequency and reading frequency. RTC user-side device files allow only one user to open at a time.

So, if you're just using Linux time normally, you don't need a particularly accurate time-based interrupt operation, and you have Internet access, you don't have to use RTC. You can also use a program to periodically read network time, and to make time-based interrupts by keeping in sync and sending out time signals outward. Since the system starts with crystal oscillator, the general system also uses this crystal oscillator as a measuring tool for time. Therefore, the need for RTC to exist in many cases is not large.

Padata

Parallel Data processing

Namaspacemagic number Reference count component: Kref

There are many places in the kernel that use reference counting. involves resource recycling and resource competition, or access statistics. This requirement is generally used as an integer to control its increase or decrease when written by itself. While the control of the time to consider concurrency conflicts and many other situations, usually to encapsulate their own functions. Linux implements a common data structure and related function calls that the user can use directly from the interface.

struct My_data

{

.

.

struct Kref refcount;

.

.

};

Binfmt_misc

The command we typed in the shell must be a built-in or elf executable that is located in Path variable paths. However, Linux can not only support elf-formatted files, such as the Python interpreter can execute Python programs, EMAC programs or Java programs, etc. by first enter the execution program on the command line, and then type the specific command program to execute.

The kernel provides a way to allow programs such as Java to be treated in a consistent manner with the elf. The user only needs to tap the Java program name (or Python program name) in the shell, as long as the program can be executed in the same way as the ELF format executable program under path. The way to do this is to use the BINFMT_MISC mechanism, the mechanism through the proc file system operation, to use the first mount up: Mount Binfmt_misc-t Binfmt_misc/proc/sys/fs/binfmt_misc. Then write the formatted string to the/proc/sys/fs/binfmt_misc/register.

: Name:type:offset:magic:mask:interpreter:flags

See Help for specific individual meanings.

Interrupt System

Interrupts in Linux are divided into 3 levels.

The lowest level is the code associated with each platform under arch, typically located in the Irq.c file below the platform code, which is directly related to the hardware and is finally called DO_IRQ (__DO_IRQ) for execution.

DO_IRQ is the middle of the interrupt system, which is based on the interrupt number from the lower layer to find the corresponding interrupt processing function, processing multi-CPU access and interrupt re-entry problems, and then invoke the real interrupt processing function, that is, the upper layer of interrupts. However, the kernel makes a difference here, if the kernel determines if the interrupt has been nested (at the same time more interrupts), the interrupt handler function is run as a kernel thread, otherwise it will run directly. So, we can often see in the output of the PS command:

These soft interrupts are kernel threads.

For the top level, it is related to the specific functions of each interrupt.

Multiple CPU interrupts

Interrupt Affinity

Interrupt domain

DMA System

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Introduction to Linux Kernel Engineering--infrastructure

Related Article

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.