[0060] In order to make the objectives, technical solutions, and advantages of the present invention clearer, the following describes the multi-processor and/or multi-core processor-based operating system and operating method of the present invention in further detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described here are only used to explain the present invention, but not to limit the present invention.
[0061] The rapid development of multi-core processors has resulted in more and more multi-processor platforms, and more and more processors or processor cores. Due to the use of context switching and locking mechanisms, existing operating systems have certain limitations in performance and scalability in a multi-processor or processor core (especially more than 8) environment.
[0062] As a specific implementation, the present invention provides an operating system, which runs on a multi-processor and/or a multi-core processor and is used to manage application programs, including:
[0063] A plurality of kernel service modules corresponding to the system call type running in the kernel mode are distributed on at least one processor and/or processor core;
[0064] Multiple application management modules for managing application programs and application processes are distributed on processors and/or processor cores different from the core service module, and are used to manage and run on these processors and/or processor cores Applications and application processes.
[0065] The kernel service module communicates with the application management module through system call messages.
[0066] The present invention deploys multiple kernel service modules running in the kernel mode asymmetrically and distributedly on at least one processor or core, as an implementable way, such as deploying one kernel service module on one processor or core . Splitting the operating system kernel of the prior art into multiple kernel service modules is a technique well known to those skilled in the art. For example, as shown in Figure 3, the system call is split according to the system call (Syscall): the system call is classified into process management, memory Management, device management, file system, etc., aggregate related system calls into a kernel service module; for example, as shown in Figure 4, split according to the use of locks: divide the operating system kernel of the prior art into two parts One part is the kernel service module that does not depend on locks, which can be called by multiple applications at the same time without affecting each other; the other part is the kernel service module that relies on locks. These modules have many critical resources and require mutually exclusive access.
[0067] As shown in Figure 5, the distribution means that the kernel service module of the operating system is deployed to each processor or processor core, and initially it is deployed to each processor or processor core in a set manner. In a multi-processor or core environment, for the convenience of description, the processors or cores can be divided into a master processor and a slave processor. The core service module is distributed on the main processor to perform operating system functions; the application program is distributed on the slave processor to execute the application program. The advantage of this is that the operating system kernel service module and application program are respectively bound to the processor or core during the execution process, and context switching does not occur, thereby improving the performance of the operating system. As shown in Figure 6, because context switching is not required, the operating system of the present invention can implement asynchronous system calls, that is, when an application sends a system call message to a kernel service module on another processor or core, the application can Continue to execute the code that is not dependent on the system call result, and when the system call result is received, execute the code that is dependent on the system call result. The operation method of this asynchronous system call will be described in detail later.
[0068] Preferably, the kernel service module includes: a system call receiving and sending module for receiving system call messages sent by the application program and sending the execution result of the system call to the application management module to which the application program belongs; and The listening module, when it listens to the system call message sent by the application program, informs the system call receiving and sending module to receive the system call message.
[0069] Preferably, the application management module further includes a system call sending and receiving module, which is used to send a system call message to the kernel service module and receive a system call result sent by the kernel service module.
[0070] Preferably, the application management module further includes a system call routing table, which converts the system call request of the application program into a message according to the system call type and sends it to the corresponding service module. The application management module receives the system call request of the application program, then converts it into a system call message, and sends it to the corresponding kernel service module according to the system call routing table; it also receives the system call result sent by the kernel service module and forwards it to application.
[0071] Preferably, the core service module refers to a process management service module, a memory management service module, a device management service module, a file operation service module, or a combination thereof. For example, applying or releasing memory space (brk), establishing page mapping (mmap), releasing page mapping (munmap), protecting memory space (mprotect), and establishing page mapping (mmap2) related to memory management in the existing technology operating system kernel ) And other system calls are divided into memory management service modules; system calls such as opening files (open), reading files (read), writing files (write), and locating to a certain position of the file (lseek) are divided into file operation service modules; System calls such as getting process number (getpid) and exit (exit) are divided into process management service modules; system calls such as controlling equipment (ioctl) are divided into device management service modules.
[0072] In the present invention, if the processor or processor core needs load balancing, the number of master/slave processors can be dynamically changed according to the load: when the application program calls the operating system kernel service module frequently, multiple The kernel service module runs on a main processor; when the application is operating system-intensive, multiple main processors can be used to run the kernel service module. This load balancing method will be described in detail below.
[0073] Preferably, the process management service module further includes a processor vector table for recording the current state of each processor or processor core: the processor or processor core running the kernel service module is marked as a kernel (Kernel) state , The processor or core running the application program is in the user state, and the processor or core in the idle state is in the idle state.
[0074] Preferably, the kernel service module further includes a load balancing sub-module, configured to count the frequency of receiving system call messages, and when the frequency is greater than a set first value, send load balancing to the process management service module Request; The process management service module creates the same kernel service module as the kernel service module that issued the load balancing request on other processors or processor cores in the kernel state to achieve load balancing. Specifically, the process management service module queries the processor vector table after receiving the load balancing request, and if there is a processor or processor core in an idle state in the processor vector table, Then the process management service module causes the idle state processor to create the same kernel service module as the kernel service module that issued the load balancing request; if there is no idle processor in the processor vector table, then Send a message querying the frequency of system call messages to other kernel service modules. When receiving system call message frequency information returned by other kernel service modules, the process management service module selects a processor so that load balances are created and issued on the processor The requested kernel service module is the same as the kernel service module, and at the same time, the process management service module modifies the processor state in the processor vector table, and sends a message for updating the system call routing table to the application management module. The method for determining the first value is: if the average processing time of the kernel service module for a system call request is T, if the frequency of the system call request message is greater than k 1 /T, a load balancing request will be issued, that is, the first value is set to k 1 /T, where k 1The coefficients determined through experiments can be adjusted according to different situations.
[0075] Preferably, the process management service module selects the processor, which means that if the system call frequency on the processor or the processor core is lower than the set second value, then the processor is selected, if a suitable processor cannot be selected , The load balancing operation does not occur. The method for determining the second value is: the second value is equal to k 2 /T, where T is the average processing time of the kernel service module for a system call request, k 2 The coefficients determined through experiments can be adjusted according to different situations.
[0076] Preferably, the load balancing submodule is also used to count the frequency of receiving system call messages, and when the number of system calls is less than a set third value, send a load balancing request to the process management service module; The process management service module merges the current kernel service module and other kernel service modules into one of the processors or processor cores to run, and cancels the merged processor or the kernel service module on the processor core. Run applications on the processor or processor core to achieve load balancing. Specifically, when the process management service module receives the load balancing request, it queries the processor vector table, and executes the load balancing operation if the following conditions are met: (a) There is at least one user (User) state processor Or two or more application programs are executed on the processor core; (b) there is at least another processor in the kernel state and its system call message frequency is also less than the set third value; The load balancing operation includes: merging the current kernel service module and the kernel service module running on the at least another processor that processes the state of the kernel into one of the processors or processor cores to run, and canceling the merged processor or The kernel service module on the processor core simultaneously sends a message to update the system call routing table to the application management module; selects a user state processor that meets the condition a, saves the context of some applications on the processor and Suspend them and notify the processor that has just cancelled the kernel service module to execute these applications; the process management service module then updates the processor vector table. The method for determining the third value is: the third value is equal to k 3 /T, where T is the average processing time of the kernel service module for a system call request, k 3 The coefficients determined through experiments can be adjusted according to different situations.
[0077] An operating system management method, which is used to manage applications running on a multi-processor and/or a multi-core processor, and includes the following steps:
[0078] Step S1: The application program sends a system call message, and after sending the message, continues to execute code that has no dependency on the system call result;
[0079] Step S2, the kernel service module receives the system call message, and sends the system call result back to the application program;
[0080] Step S3, the application program receives the system call result, and continues to execute the code related to the system call result.
[0081] It can be seen from the above method that the operating method of the present invention includes two important features: message communication and asynchronous processing. These two features can be called asynchronous system calls. Specifically:
[0082] Message communication means that when the application makes a system call, the parameters and return address space required by the system call are sent to the operating system kernel service module in the form of a message packet. After the kernel service module is processed, it will also be processed The result is sent to the application in the form of a message packet.
[0083] As shown in Figure 6, asynchronous processing means that after the application sends a system call message to the operating system kernel service module, it can continue to execute the following code without the need for context switching like the existing operating system, and convert to the kernel mode to execute the kernel code. . The kernel service module is executed on a dedicated processor, and no context switching occurs. When a message packet is received, it is processed, and after the processing is completed, it is sent to the application in a message packet format. After the application receives the message packet, it will get an identification reminder, and you can directly extract the data from the message packet when needed. Therefore, the context switch between the master processor and the slave processor will not occur in the whole process. And the operating system kernel service module and application program can be executed concurrently.
[0084] Preferably, the kernel service module in the step S2 also adopts a load balancing method to achieve load balancing of the processor or processor core where the kernel service module is located, and the load balancing method specifically includes the following steps:
[0085] Step S201: The load balancing sub-module counts the frequency of receiving system call messages.
[0086] Step S202: When the number of system calls is greater than the set first value, send a load balancing request to the process management service module.
[0087] Step S203: The process management service module queries the processor vector table after receiving the load balancing request.
[0088] Step S204: If there is a processor or a processor core in the idle state in the processor vector table, the process management service module causes the idle state processor to create and issue the core of the load balancing request The same kernel service module with the same service module;
[0089] Step S205: If there is no idle processor in the processor vector table, send a message for querying system call message frequency to other kernel service modules, and when receiving system call message frequency information returned by other kernel service modules , The process management service module selects a processor.
[0090] In step S206, a kernel service module that is the same as the kernel service module that issued the load balancing request is created on the selected processor, and is combined.
[0091] Step S207: The process management service module modifies the processor state in the processor vector table.
[0092] Step S208: Send a message for updating the system call routing table to the application management module.
[0093] Preferably, in the step 205, the process management service module selects the processor, which means that if the system call frequency on the processor or the processor core is lower than the set second value, then the processor is selected. If a suitable processor is selected, no load balancing operation will occur. The method for determining the second value is: the second value is equal to k 2 /T, where T is the processing time of the kernel service module for a system call request, k 2 The coefficients determined through experiments can be adjusted according to different situations.
[0094] Preferably, the operating system operation method further includes:
[0095] Step S4, balance the load of the processor where the application program is located.
[0096] Preferably. The step S4 specifically includes the following steps:
[0097] Step S401, the load balancing sub-module of the kernel service module counts the frequency of receiving system call messages.
[0098] Step S402: When the number of system calls is less than the set third value, send a load balancing request to the process management service module.
[0099] Step S403: When the process management service module receives the load balancing request, it queries the processor vector table, and if the following conditions are met, step S404 is executed, otherwise it stops: (a) There is at least one user (User) state processing Two or more application programs are executed on the processor or processor core; (b) there is at least another processor in the kernel state and its system call message frequency is also less than the set third value;
[0100] Step S404, merge the current kernel service module and the kernel service module running on the at least another processor processing the kernel state into one of the processors or processor cores, and cancel the merged processor or processor The kernel service module on the core;
[0101] Step S405: Send a message for updating the system call routing table to the application management module.
[0102] Step S406: Select a user (User) state processor that satisfies the condition a, save the context of some applications on the processor and suspend them.
[0103] In step S407, the process management service module notifies the processor that has just cancelled the kernel service module to execute the part of the application program.
[0104] In step S408, the process management service module then updates the processor vector table.
[0105] As can be clearly seen from the above specific embodiments, the advantages of the present invention include:
[0106] The operating system and operating method of the present invention adopt asymmetrical distribution of multiple core service modules on multiple processors or cores, and adopt an asynchronous system call method, which better solves the problem that the prior art operating system adopts context switching. And the limitations of the lock mechanism. Specifically:
[0107] The operating system kernel of the prior art of the present invention is split into different kernel service modules (Service) to reduce the dependence on the critical section/lock mechanism; the kernel service modules are deployed asymmetrically on some or all processors or cores, and Make the kernel service module have load balancing ability, and make the operating system have good scalability.
[0108] The invention adopts asynchronous system call, defines the Syscall request as a message, and forwards it to the corresponding kernel service module for processing, avoiding context switching; through the Syscall request asynchronous processing mechanism, each kernel service module of the operating system is executed concurrently with the application program, which improves the operation System performance.
[0109] The above are only specific implementations of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed by the present invention. , Should be covered in the protection scope of the present invention.