Serial port instruction optimization method, device, equipment and computer storage medium
By binding the interrupt controller to optimize serial port instructions in serial port communication, the problem of easy interruption of data transmission is solved, the accuracy and data integrity of product testing are improved, and the CPU load is reduced.
Patent Information
- Application Number
- CN202210441817.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-25
- Publication Date
- 2025-08-29
- Estimated Expiration
- 2042-04-25
AI Technical Summary
The traditional serial communication testing method is easily interrupted and interfered when the data transmission volume increases, resulting in low data integrity, affecting the accuracy of product testing, and a single CPU processing leads to an increase in load.
By obtaining the target parameters, configuring the serial port, establishing a target product connection, binding the interrupt controller to optimize the serial port instructions, and using the interrupt controller to control the target serial port to reduce data transmission interference and improve accuracy.
By binding the interrupt controller to optimize serial port instructions, it reduces CPU load, improves the accuracy of product testing, avoids interrupted interference from data transmission, and improves data integrity.
Smart Images

Figure CN114691216B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of serial port communications, and in particular to a serial port instruction optimization method, device, equipment and computer storage medium. Background Art
[0002] With the rapid development of serial communication technology, users have increasingly higher requirements for automated testing of serial communication. They hope to test products quickly while improving the accuracy of product testing, which also places higher demands on the accuracy and efficiency of serial communication. The traditional product testing method is to perform automated testing on the products to be tested based on serial port instructions, and only a single CPU (Central Processing Unit) is used to process serial port instructions and serial port communications. This product testing method has a major flaw. In the test environment, as the number of test items increases, the amount of data required to be transmitted also increases, resulting in data transmission being easily interfered with by other interruptions, affecting the complete transmission of data. This product testing method not only increases the CPU load due to the single CPU processing serial port instructions and serial port communications, but also leads to low data integrity due to interruptions in data transmission, which in turn leads to low product test accuracy. Summary of the Invention
[0003] The main purpose of the present invention is to propose a serial port instruction optimization method, device, equipment and computer storage medium, aiming to solve the technical problem of how to optimize serial port instructions and thus improve the accuracy of product testing.
[0004] To achieve the above object, the present invention provides a serial port instruction optimization method, the serial port instruction optimization method steps comprising:
[0005] Obtain input target parameters, and configure the preset serial port parameters according to the target parameters to obtain the target serial port;
[0006] If an input communication connection instruction is obtained, determining a target product to be connected to the target serial port according to the communication connection instruction;
[0007] Determine an interrupt instruction according to the target product, and bind a corresponding interrupt controller according to the interrupt instruction;
[0008] The target serial port is controlled based on the interrupt controller to optimize serial port instructions.
[0009] Optionally, the step of configuring parameters of a preset serial port according to the target parameters to obtain a target serial port includes:
[0010] Determine the serial port attribute parameters in the target parameters, and configure the parameters of the preset serial port according to the serial port instruction parameters to obtain the target serial port;
[0011] A preset activation instruction is obtained, and the target serial port is activated according to the activation instruction to obtain the target serial port.
[0012] Optionally, the step of determining a target product to which the target serial port is to establish a connection according to the communication connection instruction includes:
[0013] Determine the product file path information in the communication connection instruction, and establish serial port communication between the target serial port and the target product according to the product file path information.
[0014] Optionally, the step of determining an interrupt instruction according to the target product includes:
[0015] Obtaining configuration conditions within the target product and detecting whether the configuration conditions match preset configuration conditions;
[0016] If a match is found, the product number of the target product is determined, and all interrupt instructions in the product number are determined.
[0017] Optionally, after the step of determining the interrupt instruction according to the target product, the method further includes:
[0018] Determining all automatic adjustment instructions corresponding to each of the interrupt instructions, and detecting each of the automatic adjustment instructions;
[0019] If it is detected that each of the automatic adjustment instructions has been turned off, executing the step of binding the corresponding interrupt controller according to the interrupt instruction;
[0020] If it is detected that there is an unclosed automatic adjustment instruction in the automatic adjustment instructions, the unclosed automatic adjustment instruction is closed.
[0021] Optionally, the step of binding a corresponding interrupt controller according to the interrupt instruction includes:
[0022] Determine an interrupt instruction number corresponding to the interrupt instruction, and obtain an input affinity setting value corresponding to the interrupt instruction number;
[0023] A preset controller sequence value is obtained, and an interrupt controller corresponding to the interrupt instruction is bound according to the controller sequence value and the input affinity setting value.
[0024] Optionally, the step of binding the interrupt controller corresponding to the interrupt instruction according to the controller sequence value and the input affinity setting value includes:
[0025] determining a first binary value corresponding to the controller sequence value, and determining a second binary value corresponding to the input affinity setting value;
[0026] The first binary value and the second binary value are ANDed to obtain an affinity control number, and a corresponding interrupt controller is bound according to the affinity control number.
[0027] In addition, to achieve the above-mentioned purpose, the present invention also provides a serial port instruction optimization device, comprising:
[0028] An acquisition module is used to acquire input target parameters and configure the preset serial port parameters according to the target parameters to obtain the target serial port;
[0029] A connection module, configured to determine a target product to be connected to the target serial port according to the communication connection instruction if an input communication connection instruction is obtained;
[0030] A first processing module is configured to determine an interrupt instruction according to the target product, and bind a corresponding interrupt controller according to the interrupt instruction;
[0031] The second processing module is configured to control the target serial port based on the interrupt controller to optimize serial port instructions.
[0032] In addition, to achieve the above-mentioned purpose, the present invention also provides a serial port instruction optimization device, including: a memory, a processor, and a serial port instruction optimization program stored on the memory and capable of running on the processor. When the serial port instruction optimization program is executed by the processor, the steps of the serial port instruction optimization method described above are implemented.
[0033] In addition, to achieve the above-mentioned purpose, the present invention also provides a serial port instruction optimization computer storage medium, on which a serial port instruction optimization program is stored. When the serial port instruction optimization program is executed by a processor, the steps of the serial port instruction optimization method described above are implemented.
[0034] After determining the preset serial port that needs to be processed, the present invention obtains the target serial port by obtaining the input target parameters and configuring the parameters of the preset serial port according to the target parameters, wherein the target parameters include serial port attributes such as transmission rate, character size, parity, and stop bit; if the input communication connection instruction is obtained, the target product to which the target serial port establishes a connection is determined according to the communication connection instruction, and various definition relationships of the target serial port are determined according to the communication connection instruction; at the same time, the interrupt instruction is also determined according to the target product, and whether the configuration conditions inside the target product support the preset configuration conditions SMP is first judged, and after obtaining the product number of the target product, all interrupt instructions are obtained according to the product, and the corresponding interrupt controller is bound according to the interrupt instruction and the internally defined binding rules; the target serial port is controlled based on the interrupt controller to optimize the serial port instructions. Through interrupt instructions and internally defined binding rules, the serial port instruction-related instructions in the product are bound to the corresponding interrupt controller, thereby avoiding the phenomenon in the existing technology that as the test items in the same CPU increase, the amount of data required to be transmitted also increases continuously, resulting in data transmission being easily interfered with by other interrupts, affecting the complete transmission of data. This product testing method not only reduces the CPU load by binding a specific CPU that processes serial port instructions, but also improves the accuracy of product testing because the specific CPU accurately controls serial port communication for interrupt instructions. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] Figure 1 Schematic diagram of the structure of a serial port instruction optimization device in a hardware operating environment according to an embodiment of the present invention;
[0036] Figure 2 This is a flow chart of a first embodiment of a method for optimizing serial port instructions according to the present invention;
[0037] Figure 3 Schematic diagram of the device module for serial port instruction optimization of the present invention;
[0038] Figure 4 This is a flow chart of the technical solution for optimizing serial port instructions according to the present invention.
[0039] The purpose, features and advantages of the present invention will be further described with reference to the accompanying drawings and in conjunction with the embodiments. DETAILED DESCRIPTION
[0040] It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.
[0041] Reference Figure 1 , Figure 1 This is a schematic diagram of the structure of a serial port instruction optimization device for the hardware operating environment involved in an embodiment of the present invention.
[0042] like Figure 1 As shown, the serial port instruction optimization device may include: a processor 0003, such as a central processing unit (CPU), a communication bus 0001, an acquisition interface 0002, a processing interface 0004, and a memory 0005. Among them, the communication bus 0001 is used to realize the connection and communication between these components. The acquisition interface 0002 may include an information acquisition device and an acquisition unit such as a computer. Optionally, the acquisition interface 0002 may also include a standard wired interface and a wireless interface. The processing interface 0004 may optionally include a standard wired interface and a wireless interface. The memory 0005 may be a high-speed random access memory (RAM) or a stable non-volatile memory (NVM), such as a disk storage. The memory 0005 may also be a storage device independent of the aforementioned processor 0003.
[0043] Those skilled in the art will understand that Figure 1 The structure shown in the figure does not constitute a limitation on the serial port instruction optimization device, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.
[0044] like Figure 1 As shown, the memory 0005 as a computer storage medium may include an operating system, an acquisition interface module, a processing interface module, and a serial port instruction optimization program.
[0045] exist Figure 1 In the serial port instruction optimization device shown, the communication bus 0001 is mainly used to realize the connection communication between components; the acquisition interface 0002 is mainly used to connect to the background server and communicate data with the background server; the processing interface 0004 is mainly used to connect to the deployment end (user end) and communicate data with the deployment end; the processor 0003 and the memory 0005 in the serial port instruction optimization device of the present invention can be set in the serial port instruction optimization device, and the serial port instruction optimization device calls the serial port instruction optimization program stored in the memory 0005 through the processor 0003, and executes the serial port instruction optimization method provided by the embodiment of the present invention.
[0046] Based on the above hardware structure, an embodiment of the serial port instruction optimization method of the present invention is proposed.
[0047] The embodiment of the present invention provides a method for optimizing serial port instructions. Figure 2 , Figure 2 FIG. 1 is a flow chart of a first embodiment of a serial port instruction optimization method according to the present invention.
[0048] In this embodiment, the serial port instruction optimization method includes:
[0049] Step S10, obtaining input target parameters, and configuring parameters of a preset serial port according to the target parameters to obtain a target serial port;
[0050] In this embodiment, when the serial port command needs to be optimized, the input target parameters are obtained, and the preset serial port parameters are configured according to the target parameters to obtain the target serial port. The target parameters refer to the parameters input by the user for setting the serial port parameters, and the target serial port refers to the serial port obtained after the parameter configuration. The step of configuring the preset serial port parameters according to the target parameters to obtain the target serial port includes:
[0051] Step C11, determining the serial port attribute parameters in the target parameters, and configuring the parameters of the preset serial port according to the serial port instruction parameters to obtain a simulated target serial port;
[0052] In this embodiment, after determining the target parameters, the serial port attribute parameters within the target parameters are determined, and the parameters are configured based on the serial port attribute parameters to obtain a target serial port. The serial port attribute parameters refer to the attribute parameters used to configure the serial port, and the target serial port refers to the serial port obtained after the serial port attribute parameters are configured. The serial port attribute parameters refer to the original serial port attributes saved using the tcgetattr function. These primarily involve: 1. activating the local connection (CLOCAL) and accept enable (CREAD) options via a bit mask; 2. setting the data transfer rate using the cfsetispeed and cfsetospeed functions; 3. setting the character size via a bit mask; and 4. setting the parity bit using two termios members: c_cflag and c_iflag. First, the parity bit enable flag PARENB and whether to perform parity checking must be activated in c_cflag, as well as the parity enable flag in c_iflag; and 5. activating CSTOPB in c_cflag to set the stop bit. If the stop bit is 1, clear CSTOPB; if the stop bit is 0, activate CSTOPB; 6. Set the minimum characters and waiting time. If there are no special requirements for the received characters and waiting time, they can be set to 0; 7. Call a specific function to process the introduced object, among which the function tcflush(fd,queue_selector)" is used to process the object to be written to the reference. The possible values of queue_selector are as follows: TCIFLUSH: refresh the received data but do not read; TCOFLUSH: refresh the written data but do not transmit; TCIOFLUSH: refresh the received data but do not read, and refresh the written data but do not transmit. After setting the above parameters for the preset serial port, the target serial port will be obtained. The accuracy of the serial port parameters can be guaranteed by the preset serial port. The serial port parameters can be quickly set by setting the serial port according to the target parameters.
[0053] Step C12: obtaining a preset activation instruction, and activating the proposed target serial port according to the activation instruction to obtain the target serial port.
[0054] After obtaining the intended target serial port, the pre-set opportunistic command is retrieved and activated according to the activation command. The activation command activates the configuration after setting the serial port parameters. This means that after completing the configuration, the configuration must be activated for it to take effect. The function uses int tcsetattr(intfiledes, int opt, const struct termios*termptr): TCSANOW: changes attributes immediately without waiting for data transfer to complete; TCSADRAIN: waits for all data transfers to complete before changing attributes; and TCSAFLUSH: waits for all data transfers to complete and the input and output buffers to clear before changing attributes. Error messages include: EBADF: invalid file descriptor; EINTR: the tcsetattr function call was interrupted by a signal; EINVAL: an invalid value was used in the optional_actions parameter or the termios parameter; and ENOTTY: a non-terminal file descriptor. Once the intended target serial port is activated, the target serial port is obtained. Other operations can then be used to control the serial port, ensuring the accuracy of the target serial port and subsequent serial communication.
[0055] Step S20: If the input communication connection instruction is obtained, the target product to be connected to the target serial port is determined according to the communication connection instruction;
[0056] In this embodiment, after the target parameters of the target serial port are configured, the instructions of the target serial port will be detected, and a monitoring thread will be established to detect the instructions of the target serial port through the monitoring thread. When the input instruction is detected, the instruction will be judged to detect whether the instruction matches the preset communication connection instruction. If it does not match, the detection will continue. When the instruction matches the preset communication connection instruction, the instruction will be used as the input communication connection instruction, and the target product to be connected to the target serial port will be determined based on the communication connection instruction, wherein the input communication connection instruction refers to the instruction input by the user to connect the serial port and the product, and the product refers to the target product. The step of determining the target product to be connected to the target serial port based on the communication connection instruction includes:
[0057] Step C21 , determining the product file path information in the communication connection instruction, and establishing serial port communication between the target serial port and the target product according to the product file path information.
[0058] In this embodiment, after receiving the input communication connection instruction, the product file path information in the communication connection instruction is determined, and serial communication between the target serial port and the target product is established based on the product file path information. The product file path information refers to the product path in the communication connection instruction. For example, to establish serial communication, the relevant instructions of the communication connection instruction are as follows:
[0059] fd = open(" / dev / ttyUSB0", O_RDWR | O_NOCTTY | O_NDELAY), where the parameters are described as follows:
[0060] (1) / dev / ttyUSB0: the path to the device file;
[0061] (2) O_RDWR: (read and write);
[0062] (3) O_NOCTTY: tells Linux that "this program does not act as a 'control terminal' for the serial port." If this option is not used, some input characters may affect the process (such as keyboard input characters that generate interrupt signals, etc.);
[0063] (4) O_NDELAY: The flag tells Linux that this program does not care about the status of the DCD signal line - that is, it does not care whether the other end of the port is connected.
[0064] In this embodiment, if an input communication connection instruction is obtained, the product file path information in the communication connection instruction is determined, and serial communication between the target serial port and the target product is established based on the product file path information. Serial communication can be accurately performed after the target product is accurately connected.
[0065] Step S30, determining an interrupt instruction according to the target product, and binding a corresponding interrupt controller according to the interrupt instruction;
[0066] In this embodiment, after the target product is connected, an interrupt instruction operation will be performed on the target product. The step of determining the interrupt instruction according to the target product includes:
[0067] Step C31, obtaining the configuration conditions inside the target product and detecting whether the configuration conditions match the preset configuration conditions;
[0068] After establishing serial port communication with the target product, the target product's internal configuration conditions will be determined, and the configuration conditions will be used to test whether they match the preset configuration conditions. Configuration conditions refer to the functions and internal configurations that the target product can support. The preset configuration conditions refer to the need to support SMP (multi-CPU control products). By testing the configuration conditions, it can be determined whether the target product can be optimized for serial port instructions. When the set conditions do not match the preset configuration conditions, the optimization control will be terminated directly. By testing the configuration conditions, the accurate implementation of the technical solution for serial port instruction optimization can be guaranteed. The configuration conditions of the target product can be tested to reduce unnecessary operations and save resources.
[0069] Step C32: If a match is found, the product number of the target product is determined, and all interrupt instructions in the product number are determined.
[0070] When the configuration conditions match the preset configuration conditions, the product number of the target product is determined, and all interrupt instructions for the product are determined based on the product number. The product number refers to the flag number of the target product, which indicates the flag of the product, and the interrupt instructions refer to the instructions contained under the product number. For example, starting with the 2.4 kernel, Linux includes the ability to assign specific interrupt requests (IRQs) to a specific core (or a group of cores). This feature is called SMP IRQ AFFINITY. It allows control over which core will handle different interrupts. For each IRQ in the Linux kernel, there is a corresponding directory in / proc / irq. Each directory contains the smp_affinity file, in which the processor affinity of the IRQ can be changed by modifying the bit mask. Therefore, we can prevent one core of the system (the isolated core) from servicing most interrupts. The following information needs to be confirmed:
[0071] (1) Use uname -a to check whether SMP is supported;
[0072] (2) Query the serial port device number in the / dev / tty* directory;
[0073] (3) Get the interrupt irq number of the serial port device and assign it to a shell variable.
[0074] After obtaining all the interrupt instructions under the product number, the interrupt instruction will be bound to the corresponding interrupt controller, where the interrupt controller refers to a specific CPU. The interrupt instruction can be bound according to the user and actual needs. By binding the interrupt instruction to a specific CPU, not only can the load be distributed to the CPU, but the load of other interrupts on the CPU can also be transferred by using CPU isolation, thereby improving the real-time performance of serial port communication. It can also be better portable between various products by simply adjusting the configuration.
[0075] Step S40: Control the target serial port based on the interrupt controller to optimize serial port instructions.
[0076] In this embodiment, after obtaining an interrupt controller, the target serial port's instructions are accurately interrupted based on the interrupt controller to optimize serial port instructions. This primarily refers to interrupt instructions, but other serial port instructions can also be optimized by assigning specific CPUs based on user needs. This optimization method can bind the disk controller to one CPU and the serial port to another, improving the response time and performance of serial port instruction processing. The TV end loops through read(fd, buff, 8); to read data sent by the host computer. The parameters are: the serial port file handle; the array of buffered data; and the length of the data to be read. Properly balancing IRQ interrupts based on the specific production environment and application characteristics can help improve overall system throughput and performance. When the target serial port detects that an interrupt is required, the system detects the data transfer instruction requiring an interrupt. The interrupt controller determines the corresponding data interrupt instruction and sends the data interrupt instruction to the data transfer instruction, accurately interrupting the data transfer instruction to prevent other data from being interrupted, thus ensuring accurate interrupt control.
[0077] Furthermore, a serial port instruction optimization technical solution is provided for this embodiment. Figure 4 In this embodiment, the controller will first set the serial port parameters for the required serial port. After the serial port is set, the serial port will be opened and serial communication will be performed on the target product according to the input connection instruction. After determining the target product for serial communication, the configuration conditions inside the target product will be detected to see if they support the preset configuration conditions SMP. If SMP is not supported, the serial port instruction optimization will be terminated directly, because this technical solution is a solution that requires products that support SMP to implement serial port instruction optimization. When the product supports SMP, the product number for establishing a connection with the serial port will be obtained, and the interrupt instruction in the product will be determined based on the product number. At the same time, the interrupt instruction will be bound to a specific CPU based on the interrupt instruction number. Finally, the serial port communication will be controlled according to the specific CPU to read or send serial port data to the serial port. In order to avoid the phenomenon that when the interrupt instruction is on the same CPU, as the amount of data to be transmitted continues to increase, the data transmission is easily interfered with by other interrupts, affecting the complete transmission of data, the interrupt instruction is accurately controlled by the specific CPU to improve the accuracy of product testing.
[0078] After determining the preset serial port that needs to be processed, this embodiment obtains the target serial port by obtaining the input target parameters and configuring the parameters of the preset serial port according to the target parameters, wherein the target parameters include serial port attributes such as transmission rate, character size, parity, and stop bits; if the input communication connection instruction is obtained, the target product to which the target serial port establishes a connection is determined according to the communication connection instruction, and various definition relationships of the target serial port are determined according to the communication connection instruction; at the same time, the interrupt instruction is also determined according to the target product, and whether the internal configuration conditions of the target product support the preset configuration conditions SMP is first judged. After the judgment is made, SMP refers to support for symmetric multi-processing, which in this embodiment refers to support for multi-CPU processing, and after obtaining the product number of the target product, all interrupt instructions are obtained according to the product, and the corresponding interrupt controller is bound according to the interrupt instruction and the internally defined binding rules; the target serial port is controlled based on the interrupt controller to optimize the serial port instructions. Through interrupt instructions and internally defined binding rules, the serial port instruction-related instructions in the product are bound to the corresponding interrupt controller, thereby avoiding the phenomenon in the existing technology that as the test items in the same CPU increase, the amount of data required to be transmitted also increases continuously, resulting in data transmission being easily interfered with by other interrupts, affecting the complete transmission of data. This product testing method not only reduces the CPU load by binding a specific CPU that processes serial port instructions, but also improves the accuracy of product testing because the specific CPU accurately controls serial port communication for interrupt instructions.
[0079] Furthermore, based on the first embodiment of the serial port instruction optimization method of the present invention, a second embodiment of the serial port instruction optimization method of the present invention is proposed. The serial port instruction optimization method includes:
[0080] Furthermore, after the step of determining the interrupt instruction according to the target product, the method further includes:
[0081] Step a, determining all automatic adjustment instructions corresponding to each interrupt instruction, and detecting each automatic adjustment instruction;
[0082] In this embodiment, after receiving the interruption instruction, all the automatic adjustment instructions corresponding to all the interruption instructions will be determined and the automatic adjustment instructions will be tested. The automatic adjustment instruction refers to the instruction that automatically adjusts the interruption instruction. For example, when the interruption instruction is modified, the automatic adjustment instruction will adjust it according to the instructions inside. If the modified content is the content of the automatic adjustment, it will be overwritten by the automatic adjustment instruction after adjustment, and the effect of the modification will not be achieved.
[0083] Step b, if it is detected that each of the automatic adjustment instructions has been turned off, then executing the step of binding the corresponding interrupt controller according to the interrupt instruction;
[0084] Step c: If it is detected that each of the automatic adjustment instructions is not closed, then close each of the automatic adjustment instructions.
[0085] When it is detected that the automatic adjustment instruction has been turned off, the step of binding the corresponding interrupt controller according to the interrupt instruction is executed, that is, the subsequent operations on the interrupt instruction will not be overwritten, and the subsequent steps of the interrupt instruction can be performed normally. When it is detected that the automatic adjustment instruction is not turned off, the automatic adjustment instruction is turned off, and the subsequent steps will be executed when it is confirmed that it has been turned off during subsequent detection. That is to say, to bind the IRQ (interrupt instruction) to the specified CPU, the service process of the IRQ automatic adjustment needs to be stopped first, otherwise the changes made by manual binding will be overwritten by the automatic adjustment process. The specific information of the cpu is mainly viewed by accessing the information of / proc / cpuinfo, cat / proc / cpuinfo|grep
[0086] "processor"|wc-l8, then turn off the irqbalance automatic allocation service to facilitate manual allocation of interrupt requests.
[0087] In this embodiment, all automatic adjustment instructions corresponding to each interrupt instruction are determined, and each automatic adjustment instruction is tested. If it is detected that each automatic adjustment instruction is disabled, the step of binding the corresponding interrupt controller according to the interrupt instruction is performed; if it is detected that each automatic adjustment instruction is not disabled, each automatic adjustment instruction is disabled. This ensures that changes to the binding of the interrupt instruction will not be overwritten by adjustments to the automatic adjustment instruction, thereby ensuring the accuracy of the interrupt instruction binding.
[0088] Furthermore, binding a corresponding interrupt controller according to the interrupt instruction includes:
[0089] Step e: determining an interrupt instruction number corresponding to the interrupt instruction, and obtaining an input affinity setting value corresponding to the interrupt instruction number;
[0090] In this embodiment, after the automatic adjustment instruction is disabled, the interrupt instruction is bound by determining the interrupt instruction number corresponding to the interrupt instruction and simultaneously obtaining the input affinity setting value corresponding to the interrupt instruction number. The interrupt instruction number is the identifier of the interrupt instruction, which can be a numeric value, a letter, or other symbol. The input affinity setting value is a numeric value entered by the user based on their needs or other reasons. Obtaining the input affinity setting value corresponding to the interrupt instruction number provides a binding basis for binding the interrupt instruction.
[0091] Step f: obtaining a preset controller sequence value, and binding the interrupt controller corresponding to the interrupt instruction according to the controller sequence value and the input affinity setting value.
[0092] After determining the input affinity setting value, the controller sequence value is obtained, and finally the interrupt instruction is bound to the corresponding interrupt controller based on the controller sequence value and the input affinity setting value. The controller sequence value is an internal reference to the controller. By comparing the input affinity setting value and the controller sequence value, the interrupt controller to which the interrupt instruction needs to be bound can be determined. The interrupt instruction is then bound to the interrupt controller, and the previously set target serial port interrupt configuration parameters are also bound to the interrupt controller.
[0093] In this embodiment, the interrupt instruction number corresponding to the interrupt instruction is determined, the input affinity setting value corresponding to the interrupt instruction number is obtained, and a preset controller sequence value is obtained. Then, the interrupt controller corresponding to the interrupt instruction is bound according to the controller sequence value and the input affinity setting value. This provides a binding basis for the interrupt controller binding.
[0094] Furthermore, the step of binding the interrupt controller corresponding to the interrupt instruction according to the controller sequence value and the input affinity setting value includes:
[0095] Step g, determining a first binary value corresponding to the controller sequence value, and determining a second binary value corresponding to the input affinity setting value;
[0096] In this embodiment, after the input affinity setting value and the controller sequence value are determined, the corresponding binary values of the two values are determined respectively, where the first binary value refers to the binary corresponding to the controller sequence value, and the second binary value refers to the binary corresponding to the input affinity setting value.
[0097] Step h: performing AND operation on the first binary value and the second binary value to obtain an affinity control number, and binding a corresponding interrupt controller according to the affinity control number.
[0098] After determining the binary value, the two binary values are ANDed together to obtain an affinity control number, which is then used to bind the corresponding interrupt controller. The affinity control number is a decimal value obtained by ANDing the two binary values. This value is then used to find the corresponding CPU and bind the interrupt instruction. This is done by modifying the serial port interrupt's affinity value (entering the affinity setting value). The smp_affinity file in the / proc / irq / {IRQ} / directory lists the CPU cores in hexadecimal. The smp_affinity value is a hexadecimal bitmask. ANDing it with the CPU number sequence determines the CPU(s) to which affinity is set. (That is, the bits set to 1 in smp_affinity represent the CPU numbers.) For example, if there are eight logical cores, the CPU# sequence (controller sequence value) is 11111111 (CPU0 to CPU7 from right to left).
[0099] (1) View the default smp affinitycat for each IRQ, / proc / irq / default_smp_affinity;
[0100] (2) Specify CPU02 to handle the interrupt request of the corresponding serial port, echo 4> / proc / irq / 36 / smp_affinity;
[0101] (3) Use watch to check the effect after switching.
[0102] For example, if the first binary value corresponding to the controller sequence value is 11111111, and the second binary value corresponding to the input affinity setting value of interrupt instruction R is 11000000, then 11111111 and 11000000 can be ANDed to obtain 11000000. 11000000 is used as the interrupt controller judgment, that is, the first and third interrupt controllers. In other words, the interrupt controller that interrupt instruction R needs to be bound to is CPU3 or CPU1. The controller will select one between CPU3 and CPU1 as the interrupt controller to be bound, or the user can select it. If only one of CPU3 and CPU1 is working, the working CPU will be directly selected. If no CPU exists or no CPU is working properly, an alarm message will be generated to prompt the user.
[0103] In this embodiment, by determining a first binary value corresponding to the controller sequence value and a second binary value corresponding to the input affinity setting value, the first and second binary values are ANDed to obtain an affinity control number, and the corresponding interrupt controller is bound according to the affinity control number. Accurate binding can be achieved for a specific interrupt controller.
[0104] The present invention also provides a device module schematic diagram for serial port instruction optimization, referring to Figure 3 , the serial port instruction optimization device includes:
[0105] The acquisition module A01 is used to obtain input target parameters and configure the preset serial port parameters according to the target parameters to obtain the target serial port;
[0106] The connection module A02 is configured to determine the target product to be connected to the target serial port according to the communication connection instruction if an input communication connection instruction is obtained;
[0107] A first processing module A03 is configured to determine an interrupt instruction according to the target product and bind a corresponding interrupt controller according to the interrupt instruction;
[0108] The second processing module A04 is configured to control the target serial port based on the interrupt controller to optimize serial port instructions.
[0109] Optionally, the acquisition module A01 is further configured to:
[0110] Determine the serial port attribute parameters in the target parameters, and configure the parameters of the preset serial port according to the serial port instruction parameters to obtain the target serial port;
[0111] A preset activation instruction is obtained, and the target serial port is activated according to the activation instruction to obtain the target serial port.
[0112] Optionally, the connection module A02 is further configured to:
[0113] Determine the product file path information in the communication connection instruction, and establish serial port communication between the target serial port and the target product according to the product file path information.
[0114] Optionally, the first processing module A03 is further configured to:
[0115] Obtaining configuration conditions within the target product and detecting whether the configuration conditions match preset configuration conditions;
[0116] If a match is found, the product number of the target product is determined, and all interrupt instructions in the product number are determined.
[0117] Optionally, the first processing module A03 is further configured to:
[0118] Determining all automatic adjustment instructions corresponding to each of the interrupt instructions, and detecting each of the automatic adjustment instructions;
[0119] If it is detected that each of the automatic adjustment instructions has been turned off, executing the step of binding the corresponding interrupt controller according to the interrupt instruction;
[0120] If it is detected that there is an unclosed automatic adjustment instruction in the automatic adjustment instructions, the unclosed automatic adjustment instruction is closed.
[0121] Optionally, the first processing module A03 is further configured to:
[0122] Determine an interrupt instruction number corresponding to the interrupt instruction, and obtain an input affinity setting value corresponding to the interrupt instruction number;
[0123] A preset controller sequence value is obtained, and an interrupt controller corresponding to the interrupt instruction is bound according to the controller sequence value and the input affinity setting value.
[0124] Optionally, the first processing module A03 is further configured to:
[0125] determining a first binary value corresponding to the controller sequence value, and determining a second binary value corresponding to the input affinity setting value;
[0126] The first binary value and the second binary value are ANDed to obtain an affinity control number, and a corresponding interrupt controller is bound according to the affinity control number.
[0127] The methods executed by the above program modules can refer to the various embodiments of the serial port instruction optimization method of the present invention, and will not be described in detail here.
[0128] The invention also provides a serial port instruction optimization device.
[0129] The device of the present invention comprises: a memory, a processor and a serial port instruction optimization program stored in the memory and operable on the processor. When the serial port instruction optimization program is executed by the processor, the steps of the serial port instruction optimization method described above are implemented.
[0130] The present invention also provides a computer storage medium.
[0131] The computer storage medium of the present invention stores a serial port instruction optimization program, and when the serial port instruction optimization program is executed by a processor, the steps of the serial port instruction optimization method described above are implemented.
[0132] The method implemented when the serial port instruction optimization program running on the processor is executed can refer to the various embodiments of the serial port instruction optimization method of the present invention, and will not be described in detail here.
[0133] It should be noted that, in this document, the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, article, or system comprising a series of elements includes not only those elements but also other elements not explicitly listed, or elements inherent to such process, method, article, or system. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, method, article, or system comprising the element.
[0134] The serial numbers of the above embodiments of the present invention are for description only and do not represent the advantages or disadvantages of the embodiments.
[0135] Through the description of the above embodiments, those skilled in the art can clearly understand that the above embodiment methods can be implemented by means of software plus the necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is a better embodiment. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a computer storage medium (such as ROM / RAM, magnetic disk, optical disk) as described above, and includes a number of instructions for enabling a terminal device (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods described in each embodiment of the present invention.
[0136] The above are only preferred embodiments of the present invention and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention description and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. A serial port instruction optimization method, characterized in that: The serial port instruction optimization method comprises the following steps: Obtain input target parameters, and configure the preset serial port parameters according to the target parameters to obtain the target serial port; If an input communication connection instruction is obtained, a target product to be connected to the target serial port is determined according to the communication connection instruction, wherein the step of determining the target product to be connected to the target serial port according to the communication connection instruction includes: Determining product file path information in the communication connection instruction, and establishing serial port communication between the target serial port and the target product according to the product file path information; When the configuration condition in the target product supports a preset configuration condition SMP, determining an interrupt instruction according to the target product, and binding a corresponding interrupt controller according to the interrupt instruction, wherein the configuration condition SMP refers to supporting symmetric multi-processing; The target serial port is controlled based on the interrupt controller to optimize serial port instructions.
2. The method for optimizing serial port instructions according to claim 1, wherein: The step of configuring parameters of a preset serial port according to the target parameters to obtain a target serial port includes: Determine the serial port attribute parameters in the target parameters, and configure the parameters of the preset serial port according to the serial port instruction parameters to obtain the target serial port; A preset activation instruction is obtained, and the target serial port is activated according to the activation instruction to obtain the target serial port.
3. The method for optimizing serial port instructions according to claim 1, wherein: The step of determining an interrupt instruction according to the target product includes: Obtaining configuration conditions within the target product and detecting whether the configuration conditions match preset configuration conditions; If a match is found, the product number of the target product is determined, and all interrupt instructions in the product number are determined.
4. The method for optimizing serial port instructions according to claim 1, wherein: After the step of determining the interrupt instruction according to the target product, the method further includes: Determining all automatic adjustment instructions corresponding to each of the interrupt instructions, and detecting each of the automatic adjustment instructions; If it is detected that each of the automatic adjustment instructions has been turned off, executing the step of binding the corresponding interrupt controller according to the interrupt instruction; If it is detected that there is an unclosed automatic adjustment instruction in the automatic adjustment instructions, the unclosed automatic adjustment instruction is closed.
5. The serial port instruction optimization method according to claim 1, wherein: The step of binding the corresponding interrupt controller according to the interrupt instruction includes: Determine an interrupt instruction number corresponding to the interrupt instruction, and obtain an input affinity setting value corresponding to the interrupt instruction number; A preset controller sequence value is obtained, and an interrupt controller corresponding to the interrupt instruction is bound according to the controller sequence value and the input affinity setting value.
6. The method for optimizing serial port instructions according to claim 5, wherein: The step of binding the interrupt controller corresponding to the interrupt instruction according to the controller sequence value and the input affinity setting value includes: determining a first binary value corresponding to the controller sequence value, and determining a second binary value corresponding to the input affinity setting value; The first binary value and the second binary value are ANDed to obtain an affinity control number, and a corresponding interrupt controller is bound according to the affinity control number.
7. A serial port instruction optimization device, characterized in that: The serial port instruction optimization device comprises: An acquisition module is used to acquire input target parameters and configure the preset serial port parameters according to the target parameters to obtain the target serial port; a connection module configured to, upon obtaining an input communication connection instruction, determine a target product to be connected to the target serial port according to the communication connection instruction, wherein the step of determining the target product to be connected to the target serial port according to the communication connection instruction comprises: determining product file path information in the communication connection instruction, and establishing serial port communication between the target serial port and the target product according to the product file path information; a first processing module configured to, when a configuration condition in the target product supports a preset configuration condition SMP, determine an interrupt instruction according to the target product and bind a corresponding interrupt controller according to the interrupt instruction, wherein the configuration condition SMP refers to support for symmetric multi-processing; The second processing module is configured to control the target serial port based on the interrupt controller to optimize serial port instructions.
8. A serial port instruction optimization device, characterized in that: The serial port instruction optimization device includes: a memory, a processor, and a serial port instruction optimization program stored in the memory and executable on the processor. When the serial port instruction optimization program is executed by the processor, the steps of the serial port instruction optimization method according to any one of claims 1 to 6 are implemented.
9. A computer storage medium, characterized in that The computer storage medium stores a serial port instruction optimization program, which, when executed by a processor, implements the steps of the serial port instruction optimization method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Method and apparatus for interrupting load equilibrium of multi-core processor
CN101354664A