Linux is widely used in the field of embedded systems with its powerful functions, open source code, support for multiple hardware platforms, modular design solutions, and rich development tool support. As an operating system platform for embedded products, it has good real-time performance, system reliability, and task processing randomness are the goals pursued by the system. At present, the real-time performance of commercial embedded operating systems can meet the needs of the embedded field, but due to its price Expensive, application is limited. Embedded Linux, with its very low price, can greatly reduce costs, and has gradually become the first choice for embedded operating systems. However, due to its technical obstacles in the real-time application field, it is necessary to make necessary improvements to the Linux kernel if it is to be applied in the embedded field. In this paper, S3C2410+Linux is used as the mobile robot operating platform. In order to improve the real-time performance of the robot task processing, research on several aspects that affect the real-time performance of the Linux OS, and use the corresponding solutions to implement it based on the standard Linux2.6 kernel, and finally pass the test , Verifying the effect of this improved method.
1.1 The factors that restrict the real-time performance of the Linux kernel
The main indicators to measure the real-time performance of the operating system are interrupt delay and preemption delay. Many real-time tasks in embedded systems are driven by interrupts. Interrupt events must be processed within a limited time limit, otherwise catastrophic consequences will occur. Most real-time systems process some periodic or non-periodic repetitive events. The frequency of events determines the execution time limit of the task. Therefore, each time an event occurs, the corresponding processing task must respond in time, otherwise it will Unable to meet the time limit. The preemption delay reflects the timely response of the system. For the Linux kernel, interrupt shutdown and interrupt priority execution mechanism, kernel non-preemption, spinlock and large kernel lock, and some O(n) task scheduling algorithms affect the real-time performance of the system.
1.2 Existing technologies to enhance the real-time performance of the Linux kernel
Over the years, the development of Linux real-time improvement technology has mainly two technical solutions: (1) Directly modify the Linux kernel. According to the changes to the kernel data structure, scheduling function, and interrupt mode, a real-time scheduler driven by priority is redesigned to replace the process scheduler sched.c in the original Linux kernel. This scheme is mainly aimed at improving the interrupt mechanism and task scheduling algorithm. The more successful case is Kurt-Linux developed by Kansas University. Kurt improves the real-time accuracy in the Linux system and sets the clock chip to a one-shot state. For the scheduling of real-time tasks, Kurt-Linux uses a time-based static real-time CPU scheduling algorithm. Real-time tasks need to clearly state when their real-time events will occur in the design phase. This scheduling algorithm can achieve better scheduling results for tasks that are executed cyclically; (2) Real-time expansion outside the Linux kernel, adding a real-time kernel. The real-time kernel takes over all interrupts of the hardware and responds according to whether it is a real-time task. RTLinux developed by Fsm Labs is developed and designed according to this strategy. The two technical solutions discussed above have their lessons, but if you comprehensively consider task response, kernel preemptibility, real-time scheduling strategy, etc., it will affect the real-time performance of the operating system. Therefore, these two technologies are still not very good. Meet real-time requirements. In order to enhance the real-time performance of embedded Linux, the following will introduce related issues such as interrupt mechanism, kernel preemption, and large kernel locks.
2 Linux real-time improvement methodThe kernel of Linux 2.4 and previous versions cannot be preempted. In Linux 2.6, the kernel can be preempted, and the real-time performance has been enhanced. But there are still areas that cannot be preempted in the kernel, such as the critical area protected by the spinlock. In addition, factors that affect the real-time performance of the kernel include interrupt operation mechanism, large kernel lock mechanism, and scheduling algorithm.
2.1 Improvement of interrupt operation mechanism
In the Linux standard kernel, the interrupt is the highest priority execution unit, and the hardware architecture determines that when the hardware interrupt arrives, the interrupt must be processed without being shielded. No matter what the kernel is processing at the time, even the highest priority real-time process in Linux, as long as an interrupt occurs, the system will immediately respond to the event and execute the corresponding interrupt handler, which greatly weakens the real-time performance of Linux. Especially when the system has a serious network or I/O load, interrupts will be very frequent, and real-time tasks will hardly have a chance to run, which is unacceptable for real-time applications of Linux. The shut-off technology adopted by Linux makes the corresponding real-time task unresponsive in the shut-off area, which increases the interrupt delay of the real-time task. After Linux is real-time, the spin lock becomes a mutual exclusion lock technology, but because the interrupt processing of the spin lock cannot respond in time, the real-time performance of the system is reduced. Therefore, learn from the real-time method of Ingo Molnar's real-time patch, and use interrupt threading technology to improve the interrupt operation mechanism. The interrupt will run as a kernel thread and be given different real-time priorities. Real-time tasks can have a higher priority than interrupt threads. , Real-time tasks can be run as the highest-priority execution unit, and real-time performance is guaranteed even under severe loads. On the other hand, the interrupt processing thread can also be mounted in the lock waiting queue because the lock cannot be obtained in the kernel synchronization. Many shut-off interrupts do not need to really prohibit hardware interrupts, but prohibit the kernel process from preempting, thereby reducing Interrupt delay.
In the initialization phase, both conventional interrupt initialization and interrupt threading initialization call trap_init() and init_IRQ() in the start_kernel() function to initialize the irq_desc_t structure. The difference is mainly reflected in the interrupt thread when the init thread is created when the kernel is initialized. In the init() function, the customized interrupt will also call init_hardirqs (kernel/irq/manage.c) to create a kernel thread for each IRQ, the highest real-time priority is 50, and so on until 25. Therefore, the lowest real-time priority of any IRQ thread is 25, and the specific implementation is created by the kthread_create function. The function implementation is equivalent to the following code:
void __init init_hardirqs(void)
{……
for (i = 0; i《NR_IRQS; i++) {
//Create an interrupt thread for each interrupt
irq_desc_t *desc = irq_desc + i;
if (desc-"action &&! (desc-"status & IRQ_NODELAY))
//Interrupts with the IRQ_NODELAY flag are not allowed to be threaded
desc-"thread = kthread_create(do_irqd,
desc, "IRQ %d", irq); //Create thread
...
}
}
staTIc int do_irqd (void * __desc)
//Assign interrupt thread priority 50~25
{……
/*Scale irq thread prioriTIes from prio 50 to prio 25 */
param.sched_priority = curr_irq_prio;
if (param.sched_priority "25)
curr_irq_prio = param.sched_priority-1;
...
}
In the interrupt processing stage, when an interrupt occurs, the CPU calls the do_IRQ() function to process the interrupt, and do_IRQ() calls _do_IRQ() after necessary related processing. The main function of _do_IRQ() is to determine whether the interrupt has been threaded (check whether the status field of the terminal descriptor contains the IRQ_NODELAY flag). For interrupts that are not threaded, the handle_IRQ_event() function will be called directly to process. The function implementation is equivalent to the following code:
fastcall notrace unsigned int __do_IRQ (unsigned int irq,
struct pt_regs *regs)
{……
if (redirect_hardirq(desc))
//Check whether it is a threaded interrupt, and if so, wake up the interrupt thread
goto out_no_end;
...
acTIon_ret = handle_IRQ_event(irq, regs, acTIon);
//Handle non-threaded interrupts
...
}
int redirect_hardirq (struct irq_desc *desc)
//Check the irq_desc structure to determine whether it is threaded
{……
if (!hardirq_preemption || (desc-"status & IRQ_
NODELAY) ||! desc-"thread)
return 0;
...
if (desc-"thread && desc-"thread-"state != TASK_
RUNNING)
wake_up_process (desc-"thread);
...
}
For the threaded situation, call the wake_up_process() function to wake up the interrupt processing thread to execute, and the kernel thread will call do_hardirq() to handle the corresponding interrupt. The concrete realization is through the handle_IRQ_event() function to directly call the corresponding interrupt processing function to complete. For emergency interrupts (such as clock interrupts), the kernel maintains the original interrupt processing mode without creating an interrupt thread for it, thus ensuring a fast response to emergency interrupts.
2.2 Kernel preemptibility design
In the Linux standard kernel, because it is not preemptible and causes a large delay, increasing the preemptible performance of the kernel can improve the real-time task processing capability of the system. The current methods of modifying the Linux kernel to improve real-time performance mainly include increasing preemption points and transforming it into a preemptive kernel. The method of adding a preemption point is to insert a preemption point in the kernel, and determine whether to schedule a real-time task by detecting the preemption point scheduling flag. With this method, the system overhead is greatly increased when detecting the preemption point mark. Therefore, this solution adopts the method of directly transforming the Linux kernel, and improves the preemptibility of the kernel by modifying the spin lock to a mutual exclusion lock. That is, learn from the real-time method of Ingo Molnar's real-time patch, and use mutex mutex to replace spinlock. Use mutex to replace spinlock to make spinlock preemptible. At first, the purpose of spinlock's non-preemptive design was to avoid deadlocks. The preemptive design may lead to deadlocks between competitors and holders. The spinlock can also be used in the interrupt handling function. If the spinlock has been held by a certain process, the interrupt handling function cannot be performed, thus forming a deadlock. After the interrupt is threaded, the interrupt thread will hang on the waiting queue and give up the CPU to allow other threads or processes to run, so that each spinlock has a waiting queue, which is queued according to the process or thread priority. If a process or The spinlock of the thread competition has been held by another thread, it will hang itself on the priority waiting queue of the spinlock, and then scheduling will occur to give up the CPU to other processes or threads. After mutex replaces spinlock, the spinlock structure is defined as follows:
typedef struct {
struct rt_mutex lock; //New real-time mutex lock
unsigned int break_lock;
} spinlock_t;
The structure of struct rt_mutex is as follows:
struct rt_mutex {
raw_spinlock_t wait_lock;
struct plist wait_list; //Priority waiting queue
struct task_struct *owner; //Information of the process that owns the lock
int owner_prio;
……
};
In the above code, the type raw_spinlock_t is the original spinlock_t. That is, the spinlock_t in the code is the newly designed spinlock. In the rt_mutex structure, the wait_list field is the priority waiting queue. In the use of mutex, when a locked critical resource is encountered, the task is suspended to wait_list, and the waiting task is activated when the critical resource is unlocked. Critical resources can be preempted while being protected.
Since the critical resources at the bottom of the Linux kernel are not preemptible, this part can be retained during the process of replacing spinlock with mutex, and is still protected by non-preemptible spinlock, such as the lock to protect hardware registers, the run queue lock of the scheduler, and so on. The non-preemptible spinlock has been renamed raw_spinlock_t. spin_lock is defined by the macro as:
#define spin_lock(lock) PICK_OP(raw_spinlock_t, spin, _lock, lock)
The function PICK_OP supports two lock coexistence mechanisms. PICK_OP converts the lock operation into mutex or spinlock during the compilation stage:
#define PICK_OP (type, optype, op, lock) \
do {\
if (TYPE_EQUAL((lock), type)) \
_raw_##optype##op((type *)(lock)); \
else if (TYPE_EQUAL (lock, spinlock_t)) \
//Call gcc's built-in function __builtin_types_compatible_p()
_spin##op((spinlock_t *)(lock)); \
else __bad_spinlock_type(); \
} while (0)
#define TYPE_EQUAL(lock, type) \
__builtin_types_compatible_p(typeof(lock), type *)
The built-in function __builtin_types_compatible_p of gcc is used to determine whether the type of a variable is a specified type. If the type is spinlock_t, the function _spin_lock will be run; if the type is raw_spinlock_t, the function _raw_spin_lock will be run.
Real-time rt_mutex in specific applications, while a high priority task preempts the lock, adds the previous lock owner to the mutex waiting queue, and marks all tasks waiting for the lock in the task task_struct that currently owns the lock ; On the contrary, if the lock cannot be obtained, the current task is added to the priority waiting queue of the lock until the execution is awakened. In order to prevent priority reversal, the priority of the current owner of the lock can be changed to the highest priority of the task in the waiting queue of the lock.
rt_mutex can make high-priority tasks use preemption locks to enter the critical area, so that the number and range of kernel non-preemption areas are greatly reduced, the kernel's preemptibility has been greatly improved, and the preemption delay of real-time high-priority tasks is reduced and improved Improve the real-time performance of the system.
2.3 Design of a large kernel lock that can be preempted
The big kernel lock BKL (Big Kernel Lock) is essentially a spinlock, which is used to protect the entire kernel. The lock is held for a long time and has a great impact on the real-time performance of the system. Using Ingo Molnar's real-time method, BKL is implemented using semaphore, and the structure is defined as the following code:
struct semaphore {
atomic_t count;
struct rt_mutex lock; //Use of real-time mutex lock
};
It is found from the structure that the real-time mutex lock rt_mutex is used in the BKL implementation, and the real-time mutex lock rt_mutex is also used in the improved spinlock structure spinlock_t, so the large kernel lock can be preempted and the new spinlock shares the low-level processing Code. After using semaphore, the big kernel lock can be preempted.
3 Kernel real-time performance testFor the Linux 2.6 kernel, this article does not modify the kernel scheduling algorithm, but only discusses the limitations of the interrupt operation mechanism, spin lock and large kernel lock technology in the real-time performance of the system, so the experimental test mainly tests the interrupt delay time and Task response time. Experimental environment: Intel 2 GHz CPU, 256 DDR memory, Kernel 2.6.22 version. Test Results.
It can be seen from the table that the mark is written in the interrupt service program to test the average response time from the interrupt trigger to the execution of the interrupt service program. The average interrupt response time of the standard Linux2.6 kernel is 182 μs, and the improved Linux2.6 kernel is 14 μs. The open source software LMbench3.0 is used to test the system task scheduling delay time. The average task response time of the standard Linux2.6 kernel is 1 260 μs, and the improved Linux2.6 kernel is 162 μs. It can be seen that the improved strategy greatly reduces the interruption delay and task scheduling time to a certain extent, which is beneficial to improve the real-time performance of mobile robot task processing.
This paper analyzes the real-time performance based on the Linux2.6 kernel's close interruption, interrupt priority, non-preemptibility of the kernel, and long retention time of large kernel locks, and proposes corresponding improvement methods. The use of interrupt threading, the application of mutual exclusion locks and the improvement of large kernel locks improves the real-time performance of the system and reduces the kernel interrupt delay and scheduling delay. The improved kernel has very good application value in the mobile robot controller platform, which improves the real-time performance of robot control.
Solder Cup Waterproof D-Sub Connector
The Solder Cups D-sub connector, also known as Solder Cups D-sub connector , typically contains a pin layout of 9 pin, 15 pin, 25 pin, 37 pin & 50 pin positions housed in increasing shell sizes accordingly. They are available in both male (plug) and female (socket) variants with the male signal contacts/pins (current rating of 5A) spaced every 2.76mm in horizontal rows and the spacing of rows vertically at 2.84mm laid out half the distance between pins of existing rows.
IP66 IP67 Rated Waterproof D-Sub Panel Mount Solder Connectors
Harsh outdoor or indoor environments can destroy electronic equipment. Standard D-sub connectors are not intended to withstand contaminants such as water and dust. These waterproof solder cup connectors are available in male or female genders and DB9, DB15, DB25, and HD15 sizes. They will accommodate wire ranges from 30 - 20 AWG. Construction features gold plated brass contacts, nickel plated steel shells, and a silicone insulating ring. Maximum recommended panel thickness is 0.078".
Antenk offer a wide range of waterproof standard density and high density male and female high density D-Sub connectors solder cup with stamped and formed Contacts in cable mount used in a variety of demanding applications.
Antenk's Solder Cup D-Sub Connectors Stamped contacts
FEATURES
Solder cup d-subs available in industry sizes/positions
Low cost economy series.
Nickel shells have indents to provide grounding and additional retention.
Low cost & high performance, non-removable stamped contacts.
Optional mounting hardware available.
Antenk's SOLDER CUP D-SUB CONNECTORS Stamped contacts
MATERIALS
Shell: Steel, Tin or Nickel Plated
Insulator: Glass-filled thermoplastic. U.L. rated 94V-O
(230°C process temp)
Stamped contacts: Male pins - Brass | Female pins - Phosphor bronze
Plating: Gold flash on entire contact (contact us for other plating options)
Solder Cup Waterproof D-Sub Connector Stamped & Formed Contact, Solder Cup Waterproof D-Sub Connector Machined Contacts, Waterproof Panel Mount Solder Cup D-Sub Connector
ShenZhen Antenk Electronics Co,Ltd , https://www.pcbsocket.com