GPIO (General Purpose Input / Output) signal active polling detection method, system, equipment and medium
Through the active polling detection method and the CPU resource reservation mechanism, the real-time and accuracy of GPIO signal detection in the prior art are solved, and efficient and real-time microsecond level GPIO signal detection is achieved.
Patent Information
- Application Number
- CN202510486212.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-17
- Publication Date
- 2025-05-23
- Estimated Expiration
- 2045-04-17
AI Technical Summary
The prior art has real-time and accuracy problems when detecting microsecond-level GPIO signals. Interrupt delay and scheduling delay lead to large detection time overhead, and interrupt priority and conflict bring uncertain interference.
The active polling detection method is adopted, and the GPIO port status bit is detected in real time by creating a kernel thread. If it is not completed, signal detection is performed, and the signal processing program is entered when the signal is detected. At the same time, through the CPU resource reservation mechanism, we ensure that detection will not be preempted by other processes, reducing scheduling delays and deprivation delays.
It improves the real-time and accuracy of GPIO signal detection, reduces dependence on interrupt controllers, releases hardware resources, improves system efficiency, and supports the detection of microsecond GPIO signals.
Smart Images

Figure CN120029736A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer communication technology, and in particular to a GPIO signal active polling detection method, system, device and medium. Background Art
[0002] GPIO (General-Purpose Input / Output) interrupt is a hardware mechanism that allows external events to trigger interrupt service routines in microcontrollers. It detects state changes of GPIO signals in real time and generates interrupt requests when changes are detected. GPIO interrupts are essential for real-time response to external events and are widely used in fields such as data acquisition, peripheral control, and fault detection.
[0003] The GPIO signal response process is as follows Figure 1 As shown in the figure, it only responds when the GPIO signal generates an interrupt. Before it actually enters the signal processing process (thread), it will be affected by interrupt delays caused by interrupt detection, interrupt arbitration, interrupt vector acquisition, interrupt service routine (ISR), and other processes. The scheduling delay caused by allocating CPU usage rights according to the priority of the signal processing process, as well as the deprivation delay caused by the reallocation of CPU usage rights to a higher priority signal processing process, bring a lot of extra time overhead to the detection of microsecond GPIO signals. In addition, issues such as interrupt priority, interrupt conflict, and interrupt nesting will also bring uncertain interference, making it difficult to ensure the real-time and accuracy of GPIO signal detection. Summary of the invention
[0004] Based on this, it is necessary to provide a GPIO signal active polling detection method, system, device and medium to address the above technical problems, so as to support real-time detection of GPIO signals at the microsecond level.
[0005] A GPIO signal active polling detection method, the method comprising: Initialize active polling operation; Create a kernel thread for active polling operations, set the kernel thread affinity to the reserved CPU resources, and start the kernel thread. During the running of the kernel thread, the current GPIO port status bit is retained in real time and it is determined whether the signal detection is completed. If not, the GPIO signal detection is performed. When the GPIO signal is detected, the signal processing program is entered, and the current GPIO port status bit is retained, and the next round of detection is entered until all GPIO signal detections are completed; After all GPIO signal detections are completed, the active polling operation is terminated, the kernel thread is stopped, and the resources occupied by the kernel thread are released.
[0006] In one of the embodiments, before initiating the active polling operation, the method further includes: Define a void pointer to point to a function; Create an active polling operation structure, in which an integer variable, a Boolean variable, a thread descriptor, a void pointer pointing to a function type variable, and a void variable are created; wherein the integer variable includes the GPIO port number, the state of the active polling operation, and the signal trigger mode; the Boolean variable is the termination state of the active polling operation; the thread descriptor is the kernel thread descriptor; the void pointer pointing to a function type variable is a signal processing function; the void variable is a pointer to a void type; Create an active polling operation structure type variable and put it into the gpio_desc structure.
[0007] In one embodiment, initiating an active polling operation includes: Convert the GPIO port number to the corresponding gpio_desc structure pointer; Allocate memory space for active polling operation structure type variables; The GPIO port number, signal trigger mode, signal processing function and pointer to void type are used to initialize the active polling operation structure type variable, set the termination state of the active polling operation in the active polling operation structure type variable to no, and set the state of the active polling operation to the initial state.
[0008] In one embodiment, creating a kernel thread for active polling operations includes: Use the kthread_create function or the application programming interface for creating threads in the kernel to create a kernel thread for active polling operations and set the thread function.
[0009] In one embodiment, the method further comprises: In Linux, the CPU resources reserved for active polling detection of GPIO signals are isolated by increasing and modifying the GRUB_CMDLINE_LINUX value; Among them, adding and modifying the GRUB_CMDLINE_LINUX value includes: Added the isolcpus kernel parameter, which is a kernel startup parameter used to isolate the specified CPU to ensure that the isolated CPU will not be used by the scheduler for ordinary task scheduling and is only used to run specific tasks; Configure interrupt affinity parameters, uninstall RCU callback processing parameters, and disable NMI watchdog parameters; the interrupt affinity parameters are used to bind interrupts to specific CPUs and specify certain CPUs to handle specific hardware interrupts; the uninstall RCU callback processing parameters are used to specify certain CPUs not to process RCU callbacks, but to transfer RCU callbacks to other CPUs for processing; the disable NMI watchdog parameter is used to stop detecting whether the system is in a long-term locked state; Add the parameter for disabling interrupt optimization allocation and the parameter for disabling soft-lockup detector. The parameter for disabling interrupt optimization allocation is used to stop the CPU automatic balancing behavior of interrupt processing. The parameter for disabling soft-lockup detector is used to stop monitoring whether kernel tasks occupy the CPU for a long time.
[0010] In one embodiment, GPIO signal detection includes: If the detection finds that the current GPIO port status bit is a trigger bit and the previous GPIO port status bit is a non-trigger bit, it is determined that the GPIO signal is detected and the signal processing program is entered; otherwise, it is determined that the GPIO signal is not detected, the current GPIO port status bit is directly retained, and the next round of detection is entered.
[0011] A GPIO signal active polling detection system, the system is used to implement the above-mentioned GPIO signal active polling detection method, the system comprises: a driver layer, a hardware abstraction layer and a hardware layer; The driver layer includes a GPIO device driver; wherein the GPIO device driver is used to encapsulate the kernel thread of active polling detection into the internal gpiolib library; The hardware abstraction layer includes CPU architecture-related codes, which are used to implement CPU isolation using a CPU reservation mechanism and reserve CPU resources for active polling detection of GPIO signals; The hardware layer includes several reserved CPUs and GPIO devices. The reserved CPU is isolated based on the CPU architecture-related code to provide CPU resources for active polling detection of GPIO signals and directly access the GPIO device by calling the real-time kernel thread of active polling detection in the GPIO device driver of the driver layer.
[0012] A computer device comprises a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented: Initialize active polling operation; Create a kernel thread for active polling operations, set the kernel thread affinity to the reserved CPU resources, and start the kernel thread. During the running of the kernel thread, the current GPIO port status bit is retained in real time and it is determined whether the signal detection is completed. If not, the GPIO signal detection is performed. When the GPIO signal is detected, the signal processing program is entered, and the current GPIO port status bit is retained, and the next round of detection is entered until all GPIO signal detections are completed; After all GPIO signal detections are completed, the active polling operation is terminated, the kernel thread is stopped, and the resources occupied by the kernel thread are released.
[0013] A computer-readable storage medium stores a computer program, which, when executed by a processor, implements the following steps: Initialize active polling operation; Create a kernel thread for active polling operations, set the kernel thread affinity to the reserved CPU resources, and start the kernel thread. During the running of the kernel thread, the current GPIO port status bit is retained in real time and it is determined whether the signal detection is completed. If not, the GPIO signal detection is performed. When the GPIO signal is detected, the signal processing program is entered, and the current GPIO port status bit is retained, and the next round of detection is entered until all GPIO signal detections are completed; After all GPIO signal detections are completed, the active polling operation is terminated, the kernel thread is stopped, and the resources occupied by the kernel thread are released.
[0014] Compared with the existing GPIO signal response process, the above-mentioned GPIO signal active polling detection method, system, device and medium have the following beneficial effects: 1. Active polling is used to detect GPIO signals. The delay of active polling detection is much smaller than the interrupt delay, which improves the real-time performance of GPIO signal detection. This method allows the system to efficiently process GPIO signals without interruption, reduces dependence on interrupt controllers, releases more hardware resources for other tasks, and improves overall system efficiency. 2. By reserving CPU resources to run active polling detection, while minimizing interference from other processes and interrupts, it also ensures that active polling detection will not be preempted by higher priority processes, thereby reducing scheduling delays and preemption delays.
[0015] 3. By creating a kernel thread for active polling operations, running active polling detection at the kernel level reduces the switching between user mode and kernel mode, saving the additional overhead and time delay caused by context switching.
[0016] 4. Support waking up the CPU in advance to enter the active polling detection mode. After the detection is completed, the CPU resources are released, the CPU power consumption is reduced, and energy efficiency is optimized.
[0017] 5. It is scalable. Kernel thread encapsulation ensures the integrity of the entire active polling detection method at the kernel level so that it can be expanded to detect other types of signals. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] Figure 1 A schematic diagram of a GPIO signal response process in an embodiment; Figure 2 A schematic diagram of a process of active polling detection of a GPIO signal in one embodiment; Figure 3 A schematic diagram of the progress of active polling detection of GPIO signals in one embodiment; Figure 4 A schematic diagram of CPU resource reservation in one embodiment; Figure 5 A schematic diagram showing a comparison between a GPIO signal active polling detection system and an external hardware interrupt system in an embodiment; Figure 6 A schematic diagram of the effect of active polling detection of GPIO signals in one embodiment; Figure 7 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0019] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0020] In order to ensure and improve the real-time and accuracy of the system in detecting the GPI signal, in one embodiment, Figure 2 and Figure 3 As shown, a GPIO signal active polling detection method is provided, and the main process includes four parts: request, start, stop, and release.
[0021] In the request section: Initiate active polling operation.
[0022] In the start part: create a kernel thread for active polling operation, and start the kernel thread after setting the affinity of the kernel thread to the reserved CPU resources; during the operation of the kernel thread, keep the current GPIO port status bit in real time and determine whether the signal detection is completed. If not, perform GPIO signal detection. When the GPIO signal is detected, enter the signal processing program, keep the current GPIO port status bit, enter the next round of detection, until all GPIO signal detections are completed, and enter the stop part.
[0023] In the stop section: terminate the active polling operation and stop the kernel thread.
[0024] In the release section, release the resources occupied by the kernel thread.
[0025] This method uses a polling detection mechanism. Under the same hardware conditions, the polling delay is lower than the interrupt delay. For example, for Cortex-M core chips, the typical interrupt delay time is 12-16 clock cycles, which will be higher if affected by other interrupts. In the polling operation, it only takes 1 or several clock cycles from detecting the signal to the reserved CPU directly executing the signal processing program. Therefore, when processing microsecond-level GPIO signals, the real-time improvement brought by polling detection is more obvious.
[0026] In one of the embodiments, before initiating the active polling operation, the method further includes: Define a null pointer to point to the function polling_handler_t; Create an active polling operation structure poll_info, which contains integer variables, Boolean variables, thread descriptors, void pointers to function type variables, and void variables; the integer variable includes the GPIO port number gpio, the status of the active polling operation status, and the signal trigger mode trigger; the Boolean variable is the termination state of the active polling operation terminated; the thread descriptor is the kernel thread descriptor polling_task; the void pointer points to the function polling_handler_t type variable which is the signal processing function handler; the void variable is a pointer to the void type arg; Create an active polling operation structure of poll_info type variable poll and put it into the gpio_desc structure.
[0027] In one embodiment, initiating an active polling operation includes: Convert the GPIO port number gpio to the corresponding gpio_desc structure pointer desc; Allocate memory space for the active polling operation structure type variable poll; Use the GPIO port number gpio, signal trigger mode trigger, signal processing function handler and pointer arg pointing to void type to initialize the active polling operation structure type variable poll, set the termination status of the active polling operation in the active polling operation structure type variable poll to no, that is, set terminated to false, and set the status of the active polling operation to the initial state, that is, set status to GPIOF_STATUS_NONE.
[0028] In one embodiment, creating a kernel thread for active polling operations includes: The kernel thread for active polling operation is created and the thread function is set by using the kthread_create function or other methods such as an application programming interface for creating threads in the kernel.
[0029] Furthermore, the method also adopts a CPU resource reservation mechanism. In a system that requires real-time processing, CPU resource reservation is one of the key technologies to ensure that tasks can be completed within a specified time. CPU resource reservation means that the system reserves a certain proportion of CPU time or processing power for specific tasks or processes to ensure that these tasks or processes can obtain the necessary computing resources and maintain a certain performance and response time even when the system load is high. Therefore, critical tasks and processes will not be seriously affected by competition from other processes, and the frequency of context switching can be reduced, which helps to improve CPU utilization and maintain the stability and responsiveness of the entire system.
[0030] exist Figure 1 In the GPIO signal response process shown, no CPU resources are reserved. At this time, after the interrupt delay, the external hardware interrupt wakes up the signal processing process through the ISR. The kernel process scheduler selects the signal processing process awakened by the ISR and allocates the CPU usage rights. This process will cause scheduling delay. Obviously, when there are more processes and more processes with higher priorities, the time overhead of context switching caused by the kernel process scheduler will become larger and larger. At the same time, the existence of higher priority processes will deprive the signal processing process of CPU resources, resulting in deprivation delay. When the deprivation delay exceeds the deadline, it is very likely that the signal processing cannot be completed before the deadline, resulting in an increase in the delay of the next signal detection, or even missing the detection of the next signal, which brings huge pressure to the detection of subsequent signals.
[0031] Therefore, this application reserves CPU resources for active polling detection of GPIO signals by using CPU resource reservation. Figure 4As shown in the figure, when the CPU resource reservation mechanism is applied in the external hardware interrupt system, at the hardware level, one or more CPU cores can be reserved (that is, isolating the CPU) for subsequent active polling detection tasks without processing any other processes. At the same time, the interrupts that interfere with active polling detection on the reserved CPU core are transferred to other non-reserved CPU cores. At this time, the reserved CPU does not need to select the signal processing process from a large number of processes through the kernel process scheduler and allocate the right to use it, and the signal processing process will not be deprived of the CPU right to use by other higher priority processes when it is running. When the reserved CPU detects a GPIO signal, it immediately enters the signal processing program. After processing, the reserved CPU returns and continues to detect the GPIO signal. Only when all signals have been detected will the reserved CPU stop the thread, thereby releasing its right to use so that other tasks can use CPU resources.
[0032] In one of the embodiments, in Linux, CPU resources reserved for active polling detection of GPIO signals are isolated by adding and modifying the GRUB_CMDLINE_LINUX value.
[0033] Among them, adding and modifying the GRUB_CMDLINE_LINUX value includes: (1) Add the isolcpus kernel parameter, which is a kernel startup parameter used to isolate the specified CPU and ensure that the isolated CPU will not be used by the scheduler for ordinary task scheduling, but only for running specific tasks, such as tasks with high real-time requirements. For example, isolcpus=3 means isolating the fourth CPU (CPU number 3).
[0034] (2) Configure interrupt affinity parameters, uninstall RCU callback processing parameters, and disable NMI watchdog parameters.
[0035] Interrupt affinity parameter (irqaffinity): used to bind interrupts to specific CPUs and specify certain CPUs to handle specific hardware interrupts. Based on this parameter, context switches and cache misses can be reduced, thereby improving performance. For example, if interrupt affinity is set to the first CPU core, irqaffinity = 0.
[0036] Offload RCU callback processing parameters (rcu_nocbs): RCU (Read-Copy-Update) is a mechanism for synchronization in the kernel that allows multiple readers to access data simultaneously, while writers update data after copying it. RCU callbacks are executed when memory is reclaimed. rcu_nocbs is used to specify that certain CPUs do not process RCU callbacks, but transfer RCU callbacks to other CPUs for processing, which helps reduce the load on specific CPUs and improve system performance. For example, if the fourth CPU is isolated, set rcu_nocbs=3.
[0037] Disable NMI watchdog parameter (nmi_watchdog=0): NMI (Non-Maskable Interrupt) is the highest level hardware interrupt and cannot be disabled by software. NMI watchdog is a mechanism used to detect whether the system has been in a locked state for a long time, that is, the CPU cannot respond for a long time. Disable NMI watchdog parameter to stop detecting whether the system has been locked for a long time. It is usually used when the system is known not to be locked or when the mechanism needs to be disabled to avoid false alarms.
[0038] (3) Added parameters for disabling interrupt optimization allocation and disabling soft-lockup detector.
[0039] Disable interrupt optimization allocation parameters (noirqbalance): irqbalance is a daemon in the system that automatically balances interrupt processing so that all CPU cores can handle interrupts as evenly as possible. noirqbalance is used to stop the CPU automatic balancing behavior of interrupt processing. It is usually used after manually setting interrupt affinity to maintain the stability of interrupt processing.
[0040] Disable soft-lockup detector parameter (nosoftlockup): The soft-lockup detector is used to monitor whether the system cannot schedule other tasks because some kernel tasks occupy the CPU for a long time. If this situation is detected, the system may print stack trace information and enter a locked state or trigger a panic. nosoftlockup is used to stop monitoring whether kernel tasks occupy the CPU for a long time. Disabling this detector is usually used for system debugging, or to reduce the noise of system logs when it is known that the system will not experience soft-lockup.
[0041] It should be noted that other kernel parameters may need to be set when using other non-Linux kernels. For example, in Xenomai: Set xenomai.supported_cpus: used to specify the list of CPU cores that Xenomai can use. This parameter is usually passed to the Xenomai kernel through the kernel command line (cmdline) when the system starts. In this way, users can limit Xenomai to execute its tasks only on specific CPU cores, thereby improving the real-time performance of the system. For example, xenomai.supported_cpus=0x0f means that Xenomai supports all 4 CPUs numbered 0, 1, 2, and 3; Disable xenomai.smi (xenomai.smi=disabled): used to turn off detection and warnings for SMI (System Management Interrupts). SMI is a high-priority interrupt triggered by the CPU to perform system management tasks implemented in the BIOS (Basic Input Output System), such as power management, hardware monitoring, etc. These interrupts interrupt the current real-time task and cause unpredictable delays, which is unacceptable for real-time systems.
[0042] In one embodiment, GPIO signal detection includes: If the detection finds that the current GPIO port status bit is a trigger bit and the previous GPIO port status bit is a non-trigger bit, it is determined that the GPIO signal is detected and the signal processing program is entered; otherwise, it is determined that the GPIO signal is not detected, the current GPIO port status bit is directly retained, and the next round of detection is entered.
[0043] In one embodiment, the present application further provides a GPIO signal active polling detection system, which is used to implement the above-mentioned GPIO signal active polling detection method, and the system includes: a driver layer, a hardware abstraction layer and a hardware layer; The driver layer includes a GPIO device driver; wherein the GPIO device driver is used to encapsulate the kernel thread of active polling detection into the internal gpiolib library; The hardware abstraction layer includes CPU architecture-related codes, which are used to implement CPU isolation using a CPU reservation mechanism and reserve CPU resources for active polling detection of GPIO signals; The hardware layer includes several reserved CPUs and GPIO devices. The reserved CPU is isolated based on the CPU architecture-related code to provide CPU resources for active polling detection of GPIO signals and directly access the GPIO device by calling the real-time kernel thread of active polling detection in the GPIO device driver of the driver layer.
[0044] Further, as shown in 5, the GPIO signal active polling detection system is compared with the external hardware interrupt system in the same architecture. Figure 5 The solid line in the middle represents the GPIO signal active polling detection system that combines kernel thread active polling detection with CPU resource reservation. Figure 5 The dotted line in the middle represents the hardware interrupt system. The interrupt signal is sent from the peripherals (i.e., devices and GPIO devices) to the interrupt controller, which manages it uniformly and routes it to the CPU core. When the peripheral triggers an interrupt, the interrupt controller drives the corresponding callback processing. Figure 5 It can be seen that this application adds a kernel thread of active polling detection in the gpiolib library of the GPIO device driver in the driver layer of the GPIO signal active polling detection system and combines the CPU resources reserved in the hardware layer (i.e., reserving CPU Core1), so that the GPIO device can be directly accessed without going through the driver of the interrupt controller.
[0045] Among them, in the GPIO signal active polling detection system, the kernel thread of active polling detection is encapsulated into the gpiolib library in the GPIO device driver. By using kernel-level threads, on the one hand, if a process (thread) in user mode is used, the process (thread) can only access limited resources and perform limited operations because the operating system has restrictions on the instructions they can execute and the memory address space they can access. On the contrary, in the kernel state, not only are there no such restrictions, but the operating system does not need to switch frequently between user mode and kernel mode. In addition, it is scalable in the kernel. In addition to GPIO signals, the system has other signals. By encapsulating at the kernel level, the connection between each part of the method is maintained, ensuring the integrity of the entire method, so that it can be extended to other kernel drivers to detect other types of signals.
[0046] Furthermore, in order to more effectively illustrate the beneficial effects of the method / system proposed in the present application, an experimental verification is conducted on the above-mentioned GPIO signal active polling detection method / system. The GPIO signal active polling detection effect is as follows: Figure 6 This method / system starts in advance before the GPIO signal arrives, and stops the detection after the detection is completed. During the detection process, by combining kernel-level active polling detection and CPU resource reservation, this application realizes that the reserved CPU will continue to poll until the generated GPIO signal is detected, and then the CPU will enter the signal processing process until the signal processing is completed. Finally, the CPU will continue to detect the GPIO signal, which can realize the kernel real-time drive of the reserved CPU to actively poll and detect microsecond-level GPIO signals.
[0047] In one embodiment, a computer device is provided. The computer device may be a terminal, and its internal structure diagram may be as follows: Figure 7As shown. The computer device includes a processor, a memory, a network interface, a display screen, and an input device connected via a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external terminal via a network connection. When the computer program is executed by the processor, it implements a method for actively polling GPIO signals. The display screen of the computer device can be a liquid crystal display screen or an electronic ink display screen. The input device of the computer device can be a touch layer covering the display screen, or a button, trackball, or touchpad provided on the computer device housing, or an external keyboard, touchpad, or mouse, etc.
[0048] Those skilled in the art can understand that Figure 7 the structure shown in is only a block diagram of some structures related to the solution of this application, and does not constitute a limitation on the computer device to which the solution of this application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine some components, or have different component arrangements.
[0049] In one embodiment, a computer device is provided, including a memory and a processor. The memory stores a computer program. When the processor executes the computer program, the following steps are implemented: Initialize the active polling operation; Create a kernel thread for the active polling operation, and after setting the affinity of the kernel thread to reserve CPU resources, start the kernel thread; During the running of the kernel thread, continuously retain the current GPIO port status bits and determine whether the signal detection is completed. If not, perform GPIO signal detection. When a GPIO signal is detected, enter the signal processing program, retain the current GPIO port status bits, and enter the next round of detection until all GPIO signals are detected; After all GPIO signals are detected, terminate the active polling operation, stop the kernel thread, and release the resources occupied by the kernel thread.
[0050] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by the processor, the following steps are implemented: Initialize the active polling operation; Create a kernel thread for the active polling operation, and after setting the affinity of the kernel thread to reserve CPU resources, start the kernel thread; During the running of the kernel thread, the current GPIO port status bit is retained in real time and it is determined whether the signal detection is completed. If not, the GPIO signal detection is performed. When the GPIO signal is detected, the signal processing program is entered, and the current GPIO port status bit is retained, and the next round of detection is entered until all GPIO signal detections are completed; After all GPIO signal detections are completed, the active polling operation is terminated, the kernel thread is stopped, and the resources occupied by the kernel thread are released.
[0051] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be implemented by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application may include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
[0052] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0053] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A GPIO signal active polling detection method, characterized in that: The method comprises: Initialize active polling operation; Creating a kernel thread for active polling operation, and starting the kernel thread after setting the affinity of the kernel thread to the reserved CPU resource; During the operation of the kernel thread, the current GPIO port status bit is retained in real time and it is determined whether the signal detection is completed. If not, GPIO signal detection is performed. When the GPIO signal is detected, the signal processing program is entered, and the current GPIO port status bit is retained, and the next round of detection is entered until all GPIO signal detections are completed; After all GPIO signal detections are completed, the active polling operation is terminated, the kernel thread is stopped, and the resources occupied by the kernel thread are released.
2. The method according to claim 1, characterized in that Before initiating active polling operations, it also includes: Define a void pointer to point to a function; An active polling operation structure is created, in which an integer variable, a Boolean variable, a thread descriptor, a null pointer pointing to a function type variable and a void variable are created; wherein the integer variable includes a GPIO port number, a state of the active polling operation and a signal trigger mode; the Boolean variable is the termination state of the active polling operation; the thread descriptor is a kernel thread descriptor; the null pointer pointing to a function type variable is a signal processing function; and the void variable is a pointer to a void type; Create an active polling operation structure type variable and put it into the gpio_desc structure.
3. The method according to claim 2, characterized in that Initialize active polling operations, including: Convert the GPIO port number to the corresponding gpio_desc structure pointer; Allocate memory space for active polling operation structure type variables; The GPIO port number, signal trigger mode, signal processing function and pointer to void type are used to initialize the active polling operation structure type variable, set the termination state of the active polling operation in the active polling operation structure type variable to no, and set the state of the active polling operation to the initial state.
4. The method according to claim 1, characterized in that: Create a kernel thread for active polling operations, including: Use the kthread_create function or the application programming interface for creating threads in the kernel to create a kernel thread for active polling operations and set the thread function.
5. The method according to claim 1, characterized in that The method further comprises: In Linux, the CPU resources reserved for active polling detection of GPIO signals are isolated by increasing and modifying the GRUB_CMDLINE_LINUX value; Among them, adding and modifying the GRUB_CMDLINE_LINUX value includes: Added the isolcpus kernel parameter, which is a kernel startup parameter used to isolate the specified CPU to ensure that the isolated CPU will not be used by the scheduler for ordinary task scheduling and is only used to run specific tasks; Configure interrupt affinity parameters, offload RCU callback processing parameters and turn off NMI watchdog parameters; wherein the interrupt affinity parameters are used to bind interrupts to specific CPUs and specify certain CPUs to process specific hardware interrupts; the offload RCU callback processing parameters are used to specify certain CPUs not to process RCU callbacks, but to transfer RCU callbacks to other CPUs for processing; the turn off NMI watchdog parameter is used to stop detecting whether the system is in a long-term locked state; Add a parameter for disabling interrupt optimization allocation and a parameter for disabling soft-lockup detector; wherein the parameter for disabling interrupt optimization allocation is used to stop the CPU automatic balancing behavior of interrupt processing; and the parameter for disabling soft-lockup detector is used to stop monitoring whether the kernel task occupies the CPU for a long time.
6. The method according to claim 1, characterized in that The GPIO signal detection includes: If the detection finds that the current GPIO port status bit is a trigger bit and the previous GPIO port status bit is a non-trigger bit, it is determined that the GPIO signal is detected and the signal processing program is entered; otherwise, it is determined that the GPIO signal is not detected, the current GPIO port status bit is directly retained, and the next round of detection is entered.
7. A GPIO signal active polling detection system, characterized in that: The system is used to implement a GPIO signal active polling detection method according to any one of claims 1 to 6, and the system comprises: a driver layer, a hardware abstraction layer and a hardware layer; The driver layer includes a GPIO device driver; wherein the GPIO device driver is used to encapsulate the kernel thread of active polling detection into the internal gpiolib library; The hardware abstraction layer includes CPU architecture related codes, and the CPU architecture related codes are used to implement CPU isolation by adopting a CPU reservation mechanism, and reserve CPU resources for active polling detection of GPIO signals; The hardware layer includes several reserved CPUs and GPIO devices. The reserved CPU is isolated based on the CPU architecture related code, and is used to provide CPU resources for active polling detection of GPIO signals, and directly access the GPIO device by calling the real-time kernel thread of active polling detection in the GPIO device driver of the driver layer.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 6 are implemented.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
Citation Information
Patent Citations
Cloud load balancing optimization method and system
CN110636139A
Method for improving vhost-scsi and improving virtualized storage performance
CN117573041A
Multi-thread DMA high-speed data transmission method and system
CN117851303A
Health management and control method and system based on SPI bus full duplex communication
CN118467293A
Remote radio data communication system with data rate switching
US20030078006A1