Serial port communication method and system based on multi-core chip system and readable storage medium
By reserving CPU cores in the multi-core chip system and specifying the execution of serial port interrupts and data processing tasks, the problems of serial port data transmission delay and loss in multi-core CPU systems are solved, and the real-time and throughput of serial port data processing are improved.
Patent Information
- Application Number
- CN202411256770.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-09
- Publication Date
- 2024-12-27
AI Technical Summary
In embedded devices, multi-core CPU chip systems are prone to inadequate processing due to excessive serial port interruption in high-speed serial port data transmission scenarios, resulting in data loss.
A CPU core is reserved for serial port interrupt and data processing. By adding isolcpus command to the boot loader, the CPU core is isolated, the serial port interrupt and data processing tasks are only executed within the reserved CPU core, and the serial port data processing priority is set. is the highest priority.
It improves the serial port interrupt processing capability of multi-core chip systems, reduces data loss, enhances the throughput and real-time processing capability of serial port data, and avoids data loss caused by system scheduling.
Smart Images

Figure CN119201824A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data transmission, and in particular to a serial port communication method, system and computer-readable storage medium based on a multi-core chip system. Background Art
[0002] Due to the development of technology, embedded devices currently use multi-core CPU chips and multi-tasking Linux systems. In some data transmission scenarios that require high stability of serial ports, such as electrocardiogram data sampling and transmission of medical equipment, high-speed serial ports are often used for data transmission. However, due to cost considerations, embedded devices often have too many serial port interrupts on the high-speed serial ports of CPU chips. Multi-core CPU multi-tasking Linux systems are prone to untimely serial port interrupt processing, unable to receive serial port data in time, resulting in serial port fifo buffer overflow, and ultimately causing data transmission loss of serial port external devices.
[0003] Based on this, it is necessary to develop a serial port communication method based on a multi-core chip system to improve the serial port interrupt processing capability of the multi-core chip system, increase the throughput of serial port data, reduce the data loss problem caused by untimely serial port interrupt processing, and improve the system's real-time processing capability of the serial port. Summary of the invention
[0004] The technical problem to be solved by the present invention is to provide a serial port communication method, system and computer-readable storage medium based on a multi-core chip system.
[0005] In order to solve the above technical problems, the present invention adopts the following technical solutions:
[0006] A serial port communication method based on a multi-core chip system includes the following steps: reserving a CPU core;
[0007] Specify that serial port interrupt processing is executed only in the reserved CPU core; specify that serial port data processing tasks are executed only in the reserved CPU core; in the serial port data processing tasks, set the priority of serial port receiving and sending to the highest priority.
[0008] Preferably, the method for implementing the reserved CPU core is: adding an isolcpus command to the startup parameters of the boot loader, running the modified boot loader, and isolating a specific CPU core as the reserved CPU core.
[0009] Preferably, the implementation method of executing the designated serial port interrupt processing only in the reserved CPU core is: stopping the service process of automatic adjustment of interrupt requests, and binding the interrupt number of the serial port to the reserved CPU core.
[0010] Preferably, the implementation method for executing the specified serial port data processing task only in the reserved CPU core is: bind the serial port data processing task to the reserved CPU core, use the function pthread_setaffinity_np to set the CPU affinity of the thread, and then create a serial port data processing task thread so that the serial port data processing task thread is executed in the reserved CPU core.
[0011] Preferably, the implementation method of setting the priority of serial port reception and transmission to the highest priority in the task of serial port data processing is: changing the thread scheduling policy of the serial port data processing task, setting the thread scheduling policy of the serial port data processing task to the real-time scheduling policy SCHED_FIFO, and setting the priority of serial port reception and transmission to the highest priority in the task of serial port data processing.
[0012] A serial port communication system based on a multi-core chip system includes: a CPU resource planning module, which is used to set a CPU resource planning strategy and reserve CPU cores; an interrupt processing resource planning module, which is used to set a serial port interrupt processing resource planning strategy and specify that serial port interrupt processing is only executed in the reserved CPU core; a data processing task scheduling module, which is used to set a serial port data processing task scheduling strategy and specify that serial port data processing tasks are only executed in the reserved CPU core; and a priority setting module, which is used to set a serial port data processing task priority strategy and set the priority of serial port receiving and sending to the highest priority in the serial port data processing task.
[0013] Preferably, the specific method for the CPU resource planning module to set the CPU resource planning strategy is: adding an isolcpus command in the startup parameters of the boot loader to isolate a specific CPU core as a reserved CPU core.
[0014] Preferably, the specific method of the interrupt processing resource planning module to set the serial port interrupt processing resource planning strategy is: stopping the service process of automatic adjustment of interrupt requests, and binding the interrupt number of the serial port to the reserved CPU core.
[0015] Preferably, the specific method of setting the serial port data processing task scheduling strategy for the data processing task scheduling is: bind the serial port data processing task to the reserved CPU core, use the function pthread_setaffinity_np to set the CPU affinity of the thread, and then create a serial port data processing task thread so that the serial port data processing task thread is executed in the reserved CPU core.
[0016] A computer-readable storage medium stores program instructions, which, when executed by a processor, implement the serial port communication method based on a multi-core chip system as described above.
[0017] The beneficial technical effect of the present invention is that: the present invention reserves a CPU core and specifies that serial port interrupt processing is only executed in the reserved CPU core, ensuring that the serial port interrupt processing will not be affected by other processes and operating system scheduling, effectively improving the serial port interrupt processing capability of the multi-core chip system, increasing the throughput of serial port data, and reducing the problem of data loss due to untimely serial port interrupt processing; specifying that the serial port data processing task is only executed in the reserved CPU core, avoiding delays in serial port data processing due to system scheduling, improving the real-time capability of serial port data processing of the multi-core chip system, and improving the system's real-time processing capability of the serial port, and in the task of serial port data processing, the priority of serial port transmission and reception is set to the highest priority, giving priority to data transmission and reception, avoiding the loss of received data due to overflow of the receiving buffer. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] Figure 1 It is a flow chart of the serial port communication method based on the multi-core chip system of the present invention;
[0019] Figure 2 It is a functional structure diagram of the serial port communication system based on the multi-core chip system of the present invention. DETAILED DESCRIPTION
[0020] In order to enable those skilled in the art to more clearly understand the objectives, technical solutions and advantages of the present invention, the present invention is further described below in conjunction with the accompanying drawings and embodiments.
[0021] The invention provides a serial port communication method based on a multi-core chip system.
[0022] like Figure 1 As shown, in one embodiment of the present invention, the serial port communication method based on the multi-core chip system includes steps S10-S40:
[0023] S10, reserve CPU core.
[0024] This step mainly reserves CPU cores by running the bootloader to implement CPU resource planning. In specific implementation, add the isolcpus command to the startup parameters of the bootloader, run the modified bootloader, isolate specific CPU cores as reserved CPU cores, and do not participate in system scheduling.
[0025] For example, add the "isolcpus=1" command line to the U-Boot (U-Boot is a boot loader mainly used for embedded systems) startup parameters, and the count starts from 0. "isolcpus=1" means isolating the second CPU. After the system starts, the program cannot run on the second CPU, that is, the isolated CPU does not participate in system scheduling and is in an idle state.
[0026] S20, specifying that the serial port interrupt processing is executed only in the reserved CPU core.
[0027] The specified serial port interrupt processing is only executed in the reserved CPU core, and the serial port interrupt processing will not be affected by other processes and operating system scheduling, thereby avoiding the situation where the serial port interrupt processing is delayed due to the CPU being preempted by other interrupts. In specific implementation, the service process that automatically adjusts the interrupt request (IRQ) is stopped, and the interrupt number of the serial port is bound to the reserved CPU core. In this way, the serial port interrupt will only be generated on the reserved CPU core and will not be scheduled to other CPUs. Since the reserved CPU core is isolated and does not participate in the operating system scheduling, other processes will not be scheduled to the reserved CPU core, which is equivalent to the reserved CPU core only participating in the serial port interrupt processing, and the reserved CPU core will not be preempted by other interrupts.
[0028] S30, specifying that the serial port data processing task is executed only in the reserved CPU core.
[0029] When scheduling the execution of a process, a multi-CPU operating system cannot guarantee that serial port data processing is always executed in the same CPU. During the execution of serial port data processing, the cache in the CPU needs to be accessed. After the CPU is changed for the next execution, the cache of the previous CPU cannot be accessed. Therefore, if you want to access the cache in the CPU of this execution, the scheduling overhead is large.
[0030] The specified serial port data processing task is executed only in the reserved CPU core, and is not subject to the system process scheduling management, to avoid the delay caused by scheduling. In specific implementation, the serial port data processing task is bound to the reserved CPU core, the function pthread_setaffinity_np is used to set the CPU affinity of the thread, and then the serial port data processing task thread is created, so that the serial port data processing task thread is executed in the reserved CPU core.
[0031] S40. In the task of serial port data processing, the priority of serial port receiving and sending is set to the highest priority.
[0032] In the task of serial port data processing, the priority of serial port receiving and sending is set to the highest priority, and data receiving and sending are processed first to avoid data loss due to receiving buffer overflow. In specific implementation, by changing the thread scheduling strategy of the serial port data processing task, the thread scheduling strategy of the serial port data processing task is set to the real-time scheduling strategy SCHED_FIFO, and in the task of serial port data processing, the priority of serial port receiving and sending is set to the highest priority.
[0033] The serial port communication method based on a multi-core chip system of the present invention reserves a CPU core and specifies that serial port interrupt processing is only executed in the reserved CPU core, thereby ensuring that the serial port interrupt processing will not be affected by other processes and operating system scheduling, effectively improving the serial port interrupt processing capability of the multi-core chip system, increasing the throughput of serial port data, and reducing the problem of data loss due to untimely serial port interrupt processing; specifying that serial port data processing tasks are only executed in the reserved CPU core avoids delays in serial port data processing due to system scheduling, improving the real-time capability of serial port data processing of the multi-core chip system, and improving the system's real-time processing capability of the serial port, and in the task of serial port data processing, the priority of serial port transmission and reception is set to the highest priority, giving priority to processing data transmission and reception, avoiding the loss of received data due to overflow of the receiving buffer.
[0034] Based on Figure 1 The serial port communication method based on the multi-core chip system in the embodiment shown in the figure, the present invention provides a serial port communication system based on the multi-core chip system. Figure 2 As shown, the serial communication system based on the multi-core chip system includes:
[0035] The CPU resource planning module 10 is used to set the CPU resource planning strategy and reserve CPU cores. The specific method of the CPU resource planning module 10 to set the CPU resource planning strategy is to add the isolcpus command in the startup parameters of the boot loader to isolate a specific CPU core as a reserved CPU core.
[0036] The interrupt processing resource planning module 20 is used to set the serial port interrupt processing resource planning strategy, and specifies that the serial port interrupt processing is only executed in the reserved CPU core. The specific method of the interrupt processing resource planning module 20 to set the serial port interrupt processing resource planning strategy is: stop the service process of automatic adjustment of interrupt request, and bind the serial port interrupt number with the reserved CPU core.
[0037] The data processing task scheduling module 30 is used to set the serial port data processing task scheduling strategy, and specifies that the serial port data processing task is only executed in the reserved CPU core. The specific method of the data processing task scheduling 30 to set the serial port data processing task scheduling strategy is: bind the serial port data processing task to the reserved CPU core, use the function pthread_setaffinity_np to set the CPU affinity of the thread, and then create a serial port data processing task thread so that the serial port data processing task thread is executed in the reserved CPU core.
[0038] The priority setting module 40 is used to set the priority strategy of the serial port data processing task. In the task of serial port data processing, the priority of serial port receiving and sending is set to the highest priority. The specific method of the priority setting module 40 to set the priority strategy of the serial port data processing task is: changing the thread scheduling strategy of the serial port data processing task, setting the thread scheduling strategy of the serial port data processing task to the real-time scheduling strategy SCHED_FIFO, and setting the priority of serial port receiving and sending to the highest priority in the task of serial port data processing.
[0039] The serial port communication system based on the multi-core chip system of the present invention effectively improves the serial port interrupt processing capability and the real-time capability of serial port data processing of the multi-core chip system, increases the throughput of serial port data, and reduces the problem of data loss caused by untimely serial port interrupt processing and the inability to receive data in time due to system scheduling, through the CPU resource planning strategy, serial port interrupt processing resource planning strategy, serial port data processing task scheduling strategy and serial port data processing task priority strategy set by the above-mentioned CPU resource planning module 10, interrupt processing resource planning module 20, data processing task scheduling module 30 and priority setting module 40.
[0040] The present invention also provides a computer-readable storage medium, wherein the computer-readable storage medium stores program instructions, and when the program instructions are executed by a processor, the various steps of the serial port communication method based on the multi-core chip system are implemented. The computer-readable storage medium may be a memory including program instructions, and the memory may be implemented by one or more volatile or non-volatile storage devices of any type or a combination thereof, such as a static random access memory (SRAM), an electrically erasable programmable read-only memory (EEPROM), an erasable programmable read-only memory (EPROM), a programmable read-only memory (PROM), a read-only memory (ROM), a magnetic memory, a flash memory, a disk or an optical disk. The above program instructions may be executed by a processor to complete Figure 1 The various steps of the serial port communication method based on the multi-core chip system in the illustrated embodiment.
[0041] In summary, the present invention reserves a CPU solely for serial port data processing tasks, matches system resources to the serial port from bottom to top, solves the real-time problem of high-speed serial port data master-slave device communication, and solves the data loss problem caused by interrupt scheduling and the scheduling of upper-layer serial port data transmission and reception.
[0042] The above description is only a preferred embodiment of the present invention, and does not limit the present invention in any form. Those skilled in the art can make various equivalent changes and improvements based on the above embodiments, and all equivalent changes or modifications made within the scope of the claims should fall within the protection scope of the present invention.
Claims
1. A serial port communication method based on a multi-core chip system, characterized in that: The steps include: Reserve CPU cores; Specifies that serial port interrupt processing is executed only in the reserved CPU core; Specify that serial port data processing tasks are executed only in the reserved CPU cores; In the task of serial port data processing, set the priority of serial port receiving and sending to the highest priority.
2. The serial port communication method based on a multi-core chip system according to claim 1, characterized in that: The implementation method of reserving the CPU core is: adding the isolcpus command in the startup parameters of the boot loader, running the modified boot loader, and isolating the specific CPU core as the reserved CPU core.
3. The serial port communication method based on a multi-core chip system according to claim 1, characterized in that: The implementation method of executing the designated serial port interrupt processing only in the reserved CPU core is: stopping the service process of automatic adjustment of interrupt request, and binding the interrupt number of the serial port with the reserved CPU core.
4. The serial port communication method based on a multi-core chip system according to claim 1, characterized in that: The implementation method of specifying that the serial port data processing task is executed only in the reserved CPU core is: bind the serial port data processing task to the reserved CPU core, use the function pthread_setaffinity_np to set the CPU affinity of the thread, and then create a serial port data processing task thread so that the serial port data processing task thread is executed in the reserved CPU core.
5. The serial port communication method based on a multi-core chip system according to claim 1, characterized in that: The method for implementing setting the priority of serial port reception and transmission to the highest priority in the task of serial port data processing is as follows: changing the thread scheduling strategy of the serial port data processing task, setting the thread scheduling strategy of the serial port data processing task to the real-time scheduling strategy SCHED_FIFO, and setting the priority of serial port reception and transmission to the highest priority in the task of serial port data processing.
6. A serial communication system based on a multi-core chip system, characterized in that: Included are: CPU resource planning module, used to set CPU resource planning strategies and reserve CPU cores; The interrupt processing resource planning module is used to set the serial port interrupt processing resource planning strategy and specify that the serial port interrupt processing is only executed in the reserved CPU core; The data processing task scheduling module is used to set the serial port data processing task scheduling strategy and specify that the serial port data processing task is only executed in the reserved CPU core; The priority setting module is used to set the priority strategy of the serial port data processing task. In the task of serial port data processing, the priority of serial port receiving and sending is set to the highest priority.
7. The serial communication system based on a multi-core chip system as claimed in claim 6, characterized in that: The specific method for the CPU resource planning module to set the CPU resource planning strategy is: adding the isolcpus command in the startup parameters of the boot loader to isolate a specific CPU core as a reserved CPU core.
8. The serial communication system based on a multi-core chip system as claimed in claim 6, characterized in that: The specific method of the interrupt processing resource planning module to set the serial port interrupt processing resource planning strategy is: stop the service process of automatic adjustment of interrupt request, and bind the interrupt number of the serial port to the reserved CPU core.
9. The serial communication system based on a multi-core chip system as claimed in claim 6, characterized in that: The specific method of setting the serial port data processing task scheduling strategy is: bind the serial port data processing task to the reserved CPU core, use the function pthread_setaffinity_np to set the CPU affinity of the thread, and then create a serial port data processing task thread to execute the serial port data processing task thread in the reserved CPU core.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores program instructions, and when the program instructions are executed by the processor, the serial port communication method based on the multi-core chip system as described in any one of claims 1 to 5 is implemented.
Citation Information
Cited By
Method for ensuring hard real-time in Linux user mode based on multi-core CPU
CN121187791A