Data processing method and device, equipment and storage medium

By utilizing semaphores and shared memory areas in the Linux operating system, real-time data interaction between user-state threads and kernel-state threads is solved, the problem of real-time requirements in industrial controllers is improved, data processing efficiency and delay are reduced .

CN118964063APending Publication Date: 2024-11-15GUANGDONG TOPSTAR TECH
View PDF 0 Cites 3 Cited by

Patent Information

Application Number
CN202411037415.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-31
Publication Date
2024-11-15

AI Technical Summary

Technical Problem

The existing Linux operating systems are difficult to ensure real-time performance in industrial controllers, especially when user-state threads interact with external devices, there are problems of efficiency loss and response lag, which cannot meet the real-time requirements of industrial controllers.

Method used

By releasing semaphores to wake up the kernel-state thread, store the external device's data in the shared memory area, and the user-state thread reads data from the shared memory area, real-time interaction between the user-state thread and the kernel-state thread, and improves data processing efficiency.

Benefits of technology

Real-time data interaction between user-state threads and kernel-state threads is realized, data processing efficiency is improved, industrial controllers have real-time requirements, and delay and preemptive interference are reduced.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118964063A_ABST
    Figure CN118964063A_ABST
Patent Text Reader

Abstract

The invention discloses a data processing method and device, equipment and a storage medium. The method comprises the following steps: if a data writing request sent by an external device is detected, waking up a kernel mode thread by releasing a first semaphore so as to determine target data sent by the external device; according to the preset address information, controlling the kernel mode thread to store the target data to a preset shared memory area and release the second semaphore; and controlling the user mode thread to read the target data from the shared memory area by calling a target function driven by the preset character equipment, and entering a second semaphore waiting state, so as to write the target data of the external equipment into the user mode thread. According to the technical scheme, the shared memory is used for reporting the data of the external equipment to the user mode, real-time interaction of the data between the user mode thread and the kernel mode thread can be achieved, and the data processing efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of embedded systems, and in particular to a data processing method, device, equipment and storage medium. Background Art

[0002] In the field of embedded devices, for an industrial controller, it is essential to rely on the real-time performance of the operating system (such as the Linux operating system). However, for the Linux operating system, even after adding the Preempt RT real-time patch, the external device driver is in kernel mode and its design generally follows high throughput requirements. Therefore, when the user-mode thread needs to interact with the external device, on the one hand, it has to face the efficiency loss of falling into kernel mode to call the driver, and on the other hand, it has to wait for the driver to complete the interaction with the external device through its own complex mechanism. In this way, the real-time performance of the user-mode thread is difficult to guarantee. At the same time, due to the real-time nature of interrupts, after the external device notifies Linux, the kernel-mode thread used for response will be preempted by some higher-priority system threads, causing a response delay. The above factors make it impossible for the existing mechanism to ensure that the Linux operating system meets the real-time requirements of industrial controllers.

[0003] Therefore, how to use shared memory to report data from external devices to user state, realize real-time data interaction between user state threads and kernel state threads, and improve data processing efficiency is a problem that needs to be solved urgently. Summary of the invention

[0004] The present invention provides a data processing method, device, equipment and storage medium to achieve real-time interaction of data between user state threads and kernel state threads, thereby improving data processing efficiency.

[0005] According to one aspect of the present invention, there is provided a data processing method, comprising:

[0006] If a data write request from an external device is detected, the kernel state thread is awakened by releasing the first semaphore to determine the target data sent by the external device;

[0007] According to the preset address information, the kernel state thread is controlled to store the target data into the preset shared memory area and release the second semaphore;

[0008] By calling the target function of the preset character device driver, the user state thread is controlled to read the target data from the shared memory area and enter the second semaphore waiting state, so as to write the target data of the external device to the user state thread.

[0009] According to another aspect of the present invention, there is provided a data processing device, comprising:

[0010] A determination module, configured to wake up the kernel state thread by releasing a first semaphore if a data write request from an external device is detected, so as to determine target data sent by the external device;

[0011] A release module, used for controlling the kernel state thread to store the target data into a preset shared memory area and release the second semaphore according to the preset address information;

[0012] The writing module is used to control the user state thread to read the target data from the shared memory area by calling the target function of the preset character device driver, and enter the second semaphore waiting state to write the target data of the external device to the user state thread.

[0013] According to another aspect of the present invention, there is provided an electronic device, the electronic device comprising:

[0014] at least one processor; and

[0015] a memory communicatively connected to the at least one processor; wherein,

[0016] The memory stores a computer program that can be executed by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can perform the data processing method described in any embodiment of the present invention.

[0017] According to another aspect of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the data processing method described in any embodiment of the present invention when executed.

[0018] According to another aspect of the present invention, an embodiment of the present invention further provides a computer program product, the computer program product includes a computer program, and when the computer program is executed by a processor, the data processing method of any embodiment of the present invention is implemented.

[0019] The technical solution of the embodiment of the present invention is as follows: if a data write request from an external device is detected, the kernel state thread is awakened by releasing a first semaphore to determine the target data sent by the external device; according to preset address information, the kernel state thread is controlled to store the target data in a preset shared memory area and release a second semaphore; by calling a target function of a preset character device driver, the user state thread is controlled to read the target data from the shared memory area and enter a second semaphore waiting state to write the target data of the external device to the user state thread. By using shared memory to report the data of the external device to the user state, real-time data interaction between the user state thread and the kernel state thread can be achieved, thereby improving data processing efficiency.

[0020] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present invention, nor are they intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0022] Figure 1 is a flow chart of a data processing method provided by Embodiment 1 of the present invention;

[0023] Figure 2 is a flow chart of a data processing method provided in Embodiment 2 of the present invention;

[0024] Figure 3 is a structural block diagram of a data processing device provided by Embodiment 3 of the present invention;

[0025] Figure 4 It is a schematic diagram of the structure of an electronic device provided in Embodiment 4 of the present invention. DETAILED DESCRIPTION

[0026] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.

[0027] It should be noted that the terms "first", "second", "target", "candidate", "alternative", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices. The acquisition, storage, use, processing, etc. of data in the technical solution of this application comply with the relevant provisions of national laws and regulations.

[0028] It should be noted that the current Preempt-RT patch solution on Linux is relatively mature and can greatly increase the real-time performance of Linux. However, in actual use, software development is generally carried out in the user-mode thread of Linux. When it comes to data interaction with external hardware, the data stream is received by the driver layer, and the data stream reporting driven under Preempt-RT is generally completed through the interrupt thread. The thread priority is only 50 (the highest priority is 99), which is easy to be preempted, resulting in untimely data reporting. At the same time, since the Linux system itself has many high-priority system-level threads, its interrupt will interrupt the operation of the thread. The preemption interference caused by these factors will preempt real-time tasks from time to time. The delay caused by the preemption may reach hundreds of us or even ms, seriously affecting the real-time transmission of data. At the same time, frequent falling into the kernel state will also cause efficiency loss and seriously interfere with the operation of user-mode threads.

[0029] In addition, the industry has extremely high requirements for real-time performance. Often, a task needs to be responded to within a few milliseconds. If the delay reaches hundreds of microseconds, the task may not be completed in time. Moreover, for some real-time buses such as EtherCAT, such a large delay will cause the real-time clock to time out and the data flow to be disconnected. Therefore, real-time applications that interact with external hardware data developed based on the traditional Linux Preempr-RT operating system cannot meet the requirements of industrial real-time performance.

[0030] Aiming at the problem that the Linux Preempr-RT operating system cannot meet the real-time requirements in the scenario of high real-time data interaction between external hardware and local CPU, the present invention proposes a high real-time data interaction solution, which can realize real-time and efficient data transmission between user-mode threads and external devices, and can meet the time-sensitive requirements of high real-time applications. The specific implementation process will be described in detail in subsequent embodiments.

[0031] Embodiment 1

[0032] Figure 1 1 is a flow chart of a data processing method provided in Embodiment 1 of the present invention; this embodiment is applicable to the situation where the local CPU (Central Processing Unit) of the operating system controls the kernel state thread and the user state thread to interact to write the data of the external device into the user state, the method can be executed by a data processing device, the data processing device can be implemented in the form of hardware and / or software, the data processing device can be configured in an electronic device, such as a computer device configured with a Linux operating system, and executed by the local CPU of the Linux operating system, wherein the Linux operating system can specifically be a Linux Preempr-RT operating system, such as Figure 1 As shown, the data processing method includes:

[0033] S101: If a data write request sent by an external device is detected, a kernel-mode thread is awakened by releasing a first semaphore to determine target data sent by the external device.

[0034] Wherein, the external device refers to an external hardware device connected to the local device through the target bus. The target bus can be an SPI (Serial Peripheral Interface) bus. A data write request refers to a request to write the target data generated by the external device to the local user-mode thread. A semaphore refers to a kernel-mode semaphore, which is generally used to provide lock protection for shared data. In the embodiment of the present invention, it is mainly used to cause the thread to fall into blocked sleep when it is in the pend (wait) state, and to wake up the corresponding thread in the pend state when it is in the post (release). The first semaphore refers to the semaphore that the kernel-mode thread waits for after starting. If the kernel-mode thread detects the first semaphore, it can be awakened to perform related data processing operations. The second semaphore refers to the semaphore that the user-mode thread waits for after starting. If the user-mode thread detects the second semaphore released by the kernel-mode thread, it can be awakened to perform related data processing operations.

[0035] It should be noted that when a thread pends a semaphore, that is, it acquires a semaphore, if the acquired semaphore count value is greater than 0, it is determined that the thread has successfully acquired the semaphore, and the semaphore count value is reduced by 1; if the acquired semaphore count value is 0, the current thread will be suspended until other threads release the semaphore so that the current thread can acquire it before it can be awakened and continue to run. When a thread posts a semaphore, the semaphore count value will be increased by 1. At this time, if other blocked threads obtain the semaphore, thread scheduling may be performed.

[0036] User state refers to the memory space where ordinary applications in the operating system are running. User state threads can request kernel state threads through system calls to access external device data. Kernel state refers to the memory space where drivers in the operating system are located. Kernel state threads can directly access all data resources of the CPU and external devices. Target data refers to the data sent by external devices to local devices.

[0037] Optionally, detecting a data write request from an external device includes: monitoring data transmission status of a target bus between the external device and the local device through a preset target hardware interface; if target data sent by the external device through the target hardware interface is detected, determining that a data write request for the target data is detected.

[0038] The target hardware interface refers to the bus interface between the external device and the local device, and the target hardware interface may be, for example, an SPI hardware interface. The target bus refers to the bus connecting the external device and the local device, and the target bus may be an SPI bus.

[0039] Optionally, the local device can monitor the data transmission status of the SPI bus. If data sent by an external device through the SPI bus is detected, the data is determined to be target data, that is, the target data sent by the external device through the target hardware interface is detected, and a data write request for the target data is determined to be detected.

[0040] Optionally, if a data write request issued by an external device is detected, the kernel state thread is awakened by releasing a first semaphore to determine the target data sent by the external device, including: if a data write request issued by an external device is detected, a hardware interrupt is generated, and the first semaphore is released in the hardware interrupt to wake up the kernel state thread; the kernel state thread is controlled to call the receiving interface function corresponding to the target hardware interface to obtain the target data sent by the external device.

[0041] The first semaphore refers to a semaphore released (posted) by the local CPU for waking up the kernel-mode thread. The receiving interface function may be, for example, a function of a preset SPI receiving interface.

[0042] Exemplarily, the local CPU of the local device can generate a corresponding hardware interrupt when detecting a data write request issued by an external device, and post a first semaphore in the hardware interrupt to wake up the kernel-mode thread. It can further control the kernel-mode thread to directly operate the receiving interface function of the SPI driver device, and determine the target data transmitted by the external device based on the return result of the function.

[0043] Optionally, after controlling the kernel state thread to determine the target data, the kernel state thread can be controlled to execute corresponding data processing logic to implement update processing of the target data, so as to subsequently store the updated target data in the shared memory area; the target data can also be directly stored in the shared memory area, which is not limited by the present invention.

[0044] Optionally, before writing the target data of the external device into the user-mode thread, the kernel-mode thread and the user-mode thread may be initialized and a shared memory area may be created. Specifically, before waking up the kernel-mode thread by releasing the first semaphore, the method further includes: controlling the kernel-mode thread to create a shared memory area through a creation function of a preset character device driver, and setting an operation instruction by calling a target function in a preset character device driver so that the user-mode thread has the function of waiting for a semaphore; creating a user-mode thread and a kernel-mode thread, and controlling the kernel-mode thread and the user-mode thread to enter a semaphore waiting state. It should be noted that the thread creation action is performed only once when the device is initialized.

[0045] Among them, the preset character device driver refers to a driver type in Linux, which refers to a device driver that can only read and write single bytes. The preset character device driver can be used to implement system call interaction between kernel state and user state. The creation function refers to a preset function for creating a shared memory area, and the creation function can be, for example, the mmap function of the character device driver. The shared memory area refers to a preset memory area for storing interactive data between user state threads and kernel state threads. The target function refers to a preset function for setting the user state thread to pend the second semaphore function. The target function can be, for example, the ioctl function of the character device driver. The function of waiting for the semaphore can specifically be the function of waiting (pend) the second semaphore. The semaphore waiting state refers to the state of continuously monitoring and starting the execution operation if the corresponding semaphore is detected. The kernel state thread entering the semaphore waiting state refers to the state in which the kernel state thread waits for the local CPU to generate an interrupt and then sends the first semaphore. The user state thread entering the semaphore waiting state refers to the state in which the user state thread waits for the kernel state thread to release the second semaphore to be awakened.

[0046] Exemplarily, the local CPU can apply for memory of a preset size by calling the mmap function of the preset character device driver, realize the creation of a shared memory area, and map it to the user state. Furthermore, by calling the ioctl function of the character device driver, a set operation instruction is issued, so that the user state thread can pend the second semaphore. Furthermore, corresponding user state and kernel state threads can be created and started. Finally, the kernel state thread can be controlled to pend the first semaphore after starting to wait for being awakened by an interrupt, and the user state thread can be controlled to pend the second semaphore after starting to wait for being awakened by the kernel state thread.

[0047] It should be noted that after the kernel-state thread is started, it pends the first semaphore, that is, it enters the semaphore waiting state. If the first semaphore is detected, it is awakened, that is, it waits to be awakened by an interrupt; after the user-state thread is started, it pends the second semaphore, that is, it enters the semaphore waiting state. If the first semaphore sent by the kernel-state thread is detected, it is awakened, that is, it waits to be awakened by the kernel-state thread.

[0048] It should be noted that the target data in the present invention refers to the data transmitted through the SPI bus. By sending and receiving the data of the SPI bus, the reconstruction of the SPI data receiving and sending process is realized, avoiding the complex process of data management by calling the native SPI driver in the related technology, thereby meeting the real-time requirements of industrial control.

[0049] S102. According to preset address information, control the kernel state thread to store the target data into a preset shared memory area and release the second semaphore.

[0050] The preset address information refers to the address information of the shared memory area, which can be specifically determined during the initialization process of the kernel state thread and the user state thread.

[0051] Optionally, the local CPU can obtain the data generated after the kernel state thread processes the target data and store it in the shared memory area, or obtain the original target data received by the kernel state thread from the external device and store it in the shared memory area; the present invention is not limited to this.

[0052] Optionally, the local CPU can control the kernel state thread to store the target data in the shared memory area corresponding to the preset address information, and further control the kernel state thread to release the second semaphore to free up the CPU, so that the local CPU can further control the user state thread to perform related operations.

[0053] Optionally, after controlling the kernel state thread to store the target data in a preset shared memory area and releasing the second semaphore, it also includes: controlling the kernel state thread to enter a first semaphore waiting state, and determining a current semaphore count value of the first semaphore; based on the current semaphore count value, if a sleep condition is detected, controlling the kernel state thread to enter a sleep state to give up the occupied space to the user state thread to run.

[0054] The first semaphore waiting state refers to a state in which a kernel-mode thread is suspended and waits for obtaining a first semaphore. The current semaphore count value refers to the number of first semaphores currently existing as determined by the kernel-mode thread. The sleep condition refers to a condition for evaluating whether to suspend a kernel-mode thread and enter a sleep state, and the sleep condition may be detecting that the current semaphore count value is 0.

[0055] Optionally, if it is detected that the current semaphore count value is 0, it is determined that the sleep condition is met, and the kernel state thread is controlled to enter sleep, that is, the current thread is suspended until other threads release the semaphore so that the current thread can be awakened and continue to execute.

[0056] S103, by calling the target function of the preset character device driver, controlling the user state thread to read the target data from the shared memory area and enter the second semaphore waiting state, so as to write the target data of the external device into the user state thread.

[0057] The target function is the ioctl function of the preset character device driver. The second semaphore waiting state is to control the user state thread to suspend and wait for the second semaphore to be obtained and to terminate the sleep state.

[0058] Optionally, the local CPU can control the user state thread to read the target data from the shared memory area according to the preset address information by calling the target function of the preset character device driver, and further control the user state thread to pend the second semaphore to enter the sleep state, waiting for the subsequent acquisition of the second semaphore to wake up the sleep state, that is, control the user state thread to enter the second semaphore waiting state, waiting to be awakened by the kernel state thread when the second semaphore is detected.

[0059] Optionally, the local CPU of the operating system can also write the newly generated data to the external device when detecting that the user state thread generates new data, thereby realizing the transmission of data from the user state thread to the external device, specifically including: if the data to be written generated by the user state thread is detected, the user state thread is controlled to copy the data to be written to the shared memory area and enter the sleep state; the kernel state thread is controlled to obtain the data to be written stored in the shared memory area after startup, and the data to be written is sent to the external device by calling the sending interface function corresponding to the target hardware interface, thereby realizing the writing of the data of the user state thread to the external device.

[0060] The data to be written refers to the data written from the user state thread to the external device. The dormant state refers to the state in which the thread is suspended and does not perform data processing operations, waiting to detect the corresponding semaphore to be awakened and continue to run. The sending interface function corresponding to the target hardware interface can be, for example, the sending interface function of the SPI interface.

[0061] Optionally, the user-state thread can be monitored. If it is detected that data is updated in the user-state thread, the updated data is determined to be data to be written, and the user-state thread is further controlled to copy the data to be written to the shared memory area, and the target function of the preset character device driver (i.e., ioctl function) is called to pend the second semaphore (i.e., enter the second semaphore waiting state), that is, enter the sleep state.

[0062] Optionally, after the kernel-state thread is successfully started, the local CPU can control the kernel-state thread to copy the data in the shared memory area, that is, obtain the data to be written stored in the shared memory area, and call the SPI sending interface function to send the data to be written to the program of the external device through the SPI hardware interface, thereby realizing the writing of the data of the user-state thread to the external device.

[0063] It should be noted that by utilizing character device drivers to request kernel mode in the form of system calls when the operating system is in user mode, data transmission to peripheral devices can be achieved, thereby improving data processing efficiency.

[0064] The technical solution of the embodiment of the present invention is as follows: if a data write request from an external device is detected, the kernel state thread is awakened by releasing a first semaphore to determine the target data sent by the external device; according to preset address information, the kernel state thread is controlled to store the target data in a preset shared memory area and release a second semaphore; by calling a target function of a preset character device driver, the user state thread is controlled to read the target data from the shared memory area and enter a second semaphore waiting state to write the target data of the external device to the user state thread. By using shared memory to report the data of the external device to the user state, real-time data interaction between the user state thread and the kernel state thread can be achieved, thereby improving data processing efficiency.

[0065] Embodiment 2

[0066] Figure 2 It is a flow chart of a data processing method provided in the second embodiment of the present invention; based on the above embodiment, this embodiment provides a preferred example of cooperation between a user-mode thread and a kernel-mode thread to perform data interaction with an external device.

[0067] like Figure 2 As shown, the method includes the following process:

[0068] Data initialization process: After the kernel-mode thread is started, a character device can be created, and shared memory can be created through the mmap function of the character device. The kernel-mode thread is controlled to pend semaphore 2 and enter sleep through the iotcl function of the character device, and further control the kernel-mode thread to pend semaphore 1 and enter sleep;

[0069] The process of writing external device data to user state: the external device can send the target data to the kernel state thread through the SPI receiving interface. After the local CPU detects the data sending process, it can generate an SPI interrupt and post semaphore 1 to wake up the kernel state thread, and further control the kernel state thread to write data to the shared memory, and post semaphore 2 to wake up the user state thread. After the user state thread reads the target function from the shared memory, it passes through the sleep function and calls the iotcl function of the character device to implement pend semaphore 2 and enter sleep, thereby completing the process of writing the target data of the external device to the user state thread.

[0070] The process of writing user-state thread data to external devices: The data generated by the user-state thread can be stored in the shared memory, so that the kernel-state thread can read the data generated by the user-state thread after startup, and further send the data to the external device through the SPI sending interface, thereby realizing the process of writing the user-state thread data to the external device.

[0071] The technical solution of the present invention utilizes the global real-time operability of Linux kernel-state threads for hardware drivers, the rapidity of shared memory, and the characteristics of interaction between character devices and user states, and can report the data flow of external hardware devices to the user state in real time through shared memory.

[0072] Embodiment 3

[0073] Figure 3 This is a structural block diagram of a data processing device provided in the third embodiment of the present invention; this embodiment is applicable to the situation where the local CPU (Central Processing Unit) of the operating system controls the kernel-mode thread and the user-mode thread to interact in order to write data from an external device into the user-mode. The data processing device provided in the embodiment of the present invention can execute the data processing method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method; the data processing device can be implemented in the form of hardware and / or software, and configured in a computer device with a Linux operating system, and executed by the local CPU of the Linux operating system. Figure 3 As shown, the data processing device specifically includes:

[0074] The determination module 301 is used for waking up the kernel state thread by releasing a first semaphore if a data write request sent by an external device is detected, so as to determine the target data sent by the external device;

[0075] A release module 302, used to control the kernel state thread to store the target data into a preset shared memory area and release the second semaphore according to the preset address information;

[0076] The writing module 303 is used to control the user state thread to read the target data from the shared memory area by calling the target function of the preset character device driver, and enter the second semaphore waiting state to write the target data of the external device into the user state thread.

[0077] The technical solution of the embodiment of the present invention is as follows: if a data write request from an external device is detected, the kernel state thread is awakened by releasing a first semaphore to determine the target data sent by the external device; according to preset address information, the kernel state thread is controlled to store the target data in a preset shared memory area and release a second semaphore; by calling a target function of a preset character device driver, the user state thread is controlled to read the target data from the shared memory area and enter a second semaphore waiting state to write the target data of the external device to the user state thread. By using shared memory to report the data of the external device to the user state, real-time data interaction between the user state thread and the kernel state thread can be achieved, thereby improving data processing efficiency.

[0078] Furthermore, the determination module 301 is specifically used for:

[0079] Monitor the data transmission status of the target bus between the external device and the local device through the preset target hardware interface;

[0080] If target data sent by the external device through the target hardware interface is detected, it is determined that a data write request for the target data is detected.

[0081] Furthermore, the determination module 301 is further used for:

[0082] If a data write request from an external device is detected, a hardware interrupt is generated, and a first semaphore is released in the hardware interrupt to wake up the kernel state thread;

[0083] The kernel state thread is controlled to call a receiving interface function corresponding to a target hardware interface to obtain target data sent by an external device.

[0084] Furthermore, the above device is also used for:

[0085] Control the kernel state thread to enter the first semaphore waiting state, and determine the current semaphore count value of the first semaphore;

[0086] According to the current semaphore count value, if a sleep condition is detected, the kernel-mode thread is controlled to enter a sleep state to give up the occupied space to the user-mode thread to run.

[0087] Furthermore, the above device is also used for:

[0088] By using a preset character device driver creation function, the kernel-mode thread is controlled to create a shared memory area, and by calling a target function in the preset character device driver to set an operation instruction, the user-mode thread has the function of waiting for a semaphore.

[0089] A user state thread and a kernel state thread are created, and the kernel state thread and the user state thread are controlled to enter a semaphore waiting state.

[0090] Furthermore, the above device is also used for:

[0091] If the data to be written generated by the user state thread is detected, the user state thread is controlled to copy the data to be written to the shared memory area and enter the dormant state;

[0092] After starting, the kernel state thread is controlled to obtain the data to be written stored in the shared memory area, and by calling the sending interface function corresponding to the target hardware interface, the data to be written is sent to the external device, thereby writing the data of the user state thread to the external device.

[0093] Embodiment 4

[0094] Figure 4 is a schematic diagram of the structure of an electronic device provided by Embodiment 4 of the present invention; Figure 4 A schematic diagram of the structure of an electronic device 10 that can be used to implement an embodiment of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.

[0095] like Figure 4As shown, the electronic device 10 includes at least one processor 11, and a memory connected to the at least one processor 11, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 to the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other through a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.

[0096] A number of components in the electronic device 10 are connected to the I / O interface 15, including: an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.

[0097] The processor 11 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 11 performs the various methods and processes described above, such as a data processing method.

[0098] In some embodiments, the data processing method may be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the data processing method described above may be performed. Alternatively, in other embodiments, the processor 11 may be configured to perform the data processing method in any other appropriate manner (e.g., by means of firmware).

[0099] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), system-on-chips (SOCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.

[0100] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the computer program is executed by the processor, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer program may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.

[0101] In the context of the present invention, a computer readable storage medium may be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, device, or equipment. A computer readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, semiconductor systems, devices, or equipment, or any suitable combination of the foregoing. Alternatively, a computer readable storage medium may be a machine readable signal medium. A more specific example of a machine readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0102] To provide interaction with a user, the systems and techniques described herein may be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).

[0103] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.

[0104] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The client and server relationship is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services.

[0105] In one embodiment, the present invention further includes a computer program product, the computer program product includes a computer program, and the computer program implements the data processing method of any embodiment of the present invention when executed by a processor.

[0106] In the process of implementation, the computer program product can be written in one or more programming languages ​​or a combination thereof to perform the computer program code of the present invention, including object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computer (for example, using an Internet service provider to connect through the Internet).

[0107] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps described in the present invention can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution of the present invention can be achieved, and this document does not limit this.

[0108] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims

1. A data processing method, characterized in that: include: If a data write request from an external device is detected, the kernel state thread is awakened by releasing the first semaphore to determine the target data sent by the external device; According to the preset address information, the kernel state thread is controlled to store the target data into the preset shared memory area and release the second semaphore; By calling the target function of the preset character device driver, the user state thread is controlled to read the target data from the shared memory area and enter the second semaphore waiting state, so as to write the target data of the external device to the user state thread.

2. The method according to claim 1, characterized in that Detects data write requests from external devices, including: Monitor the data transmission status of the target bus between the external device and the local device through the preset target hardware interface; If target data sent by the external device through the target hardware interface is detected, it is determined that a data write request for the target data is detected.

3. The method according to claim 1, characterized in that If a data write request from an external device is detected, the kernel state thread is awakened by releasing a first semaphore to determine target data sent by the external device, including: If a data write request from an external device is detected, a hardware interrupt is generated, and a first semaphore is released in the hardware interrupt to wake up the kernel state thread; The kernel state thread is controlled to call a receiving interface function corresponding to a target hardware interface to obtain target data sent by an external device.

4. The method according to claim 1, characterized in that: After controlling the kernel state thread to store the target data in the preset shared memory area and releasing the second semaphore, the method further includes: Control the kernel state thread to enter the first semaphore waiting state, and determine the current semaphore count value of the first semaphore; According to the current semaphore count value, if a sleep condition is detected, the kernel-mode thread is controlled to enter a sleep state to give up the occupied space to the user-mode thread to run.

5. The method according to claim 1, characterized in that Before waking up the kernel state thread by releasing the first semaphore, the method further includes: By using a preset character device driver creation function, the kernel-mode thread is controlled to create a shared memory area, and by calling a target function in the preset character device driver to set an operation instruction, the user-mode thread has the function of waiting for a semaphore. A user state thread and a kernel state thread are created, and the kernel state thread and the user state thread are controlled to enter a semaphore waiting state.

6. The method according to claim 1, characterized in that Also includes: If the data to be written generated by the user state thread is detected, the user state thread is controlled to copy the data to be written to the shared memory area and enter the dormant state; After starting, the kernel state thread is controlled to obtain the data to be written stored in the shared memory area, and by calling the sending interface function corresponding to the target hardware interface, the data to be written is sent to the external device, thereby writing the data of the user state thread to the external device.

7. A data processing device, characterized in that: include: A determination module, configured to wake up the kernel state thread by releasing a first semaphore if a data write request from an external device is detected, so as to determine target data sent by the external device; A release module, used for controlling the kernel state thread to store the target data into a preset shared memory area and release the second semaphore according to the preset address information; The writing module is used to control the user state thread to read the target data from the shared memory area by calling the target function of the preset character device driver, and enter the second semaphore waiting state to write the target data of the external device to the user state thread.

8. An electronic device, characterized in that: The electronic device comprises: at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executed by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the data processing method according to any one of claims 1 to 6.

9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the data processing method according to any one of claims 1 to 6 when executed.

10. A computer program product, characterized in that The computer program product comprises a computer program, which, when executed by a processor, implements the data processing method according to any one of claims 1 to 6.

Citation Information

Cited By

  • CAN communication acceleration method based on shared memory and upper computer

    CN120045486A

  • A CAN communication acceleration method based on shared memory and host computer

    CN120045486B

  • Data interaction method and device, storage medium and electronic equipment

    CN120669908A