An asynchronous system call system based on coroutines

By introducing recording, execution and return modules into the asynchronous system call system, and utilizing lock-free queues and kernel modules, the problem of asynchronous system calls not supporting coroutine scheduling and Linux kernel version compatibility is solved, and efficient execution of asynchronous system calls is achieved. , improving system performance.

CN111767159BActive Publication Date: 2024-10-08ZHEJIANG UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202010589213.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-06-24
Publication Date
2024-10-08
Estimated Expiration
2040-06-24

AI Technical Summary

Technical Problem

In the existing technology, asynchronous system calls do not support coroutine scheduling and are not compatible with the Linux kernel version 2.6 or above, and the NPTL thread library lacks user-mode scheduling capabilities, resulting in performance differences and compatibility issues with asynchronous system calls in application scenarios.

Method used

Design an asynchronous system call system based on coroutines, including a recording module, an execution module and a return module. The asynchronous system call function is implemented through the call queue and the return queue, and the lock-free queue is used for inter-module communication across the kernel mode and user mode. , supports asynchronous system calls in the Go language scheduler, adds a kernel module to export the system call table, and applies for auxiliary threads in user mode to execute system calls.

Benefits of technology

It implements batch processing of asynchronous system calls, improves kernel performance by up to 60%, improves overall program performance by 13%, and improves net/http package performance by up to 4.4% in actual applications.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN111767159B_ABST
    Figure CN111767159B_ABST
Patent Text Reader

Abstract

The invention discloses an asynchronous system call system based on coroutine, comprising a recording module, an execution module and a return module, wherein a call queue is arranged between the recording module and the execution module, and a return queue is arranged between the execution module and the return module; the recording module is used to receive a system call request initiated by a coroutine, record the system call parameters and coroutine information contained in the system call request, and save the system call parameters and coroutine information in a call queue, while pausing the coroutine that initiates the system call, and then judging whether to start executing the system call; the execution module is used to use an auxiliary thread to execute the system call transmitted from the call queue, and after the system call is executed, the system call return value and the coroutine information are stored in the return queue; the return module is used to read the system call return value from the return queue and add the coroutine to the running queue according to the coroutine information to resume the coroutine operation. In this way, the problem of asynchronous execution of system calls based on coroutines is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the field of operating systems, and in particular relates to an asynchronous system call system based on coroutines. Background Art

[0002] System calls are the interface between applications and operating systems, and are the main way for operating systems to provide services to applications. Common operating systems provide hundreds of different system calls, which provide functions necessary for program operation, such as process management, memory management, file reading and writing, and network management.

[0003] Although modern processors provide various functions to accelerate the execution of system calls, the overhead of system calls cannot be ignored. For programs such as databases and network servers that require a large number of system calls, the efficiency of system calls has a significant impact on the performance of the computer system. The operating system kernel provides services to user-mode applications through system calls, so the overhead of system calls affects the running speed of applications. In order to ensure the security of the kernel, many checks and state switches are required before executing system calls, which affect the running speed of system calls. Executing system calls will also affect the locality of the application, further reducing the running speed of the program.

[0004] In order to improve the execution efficiency of system calls and reduce the impact of system calls on program performance, researchers have proposed and implemented an asynchronous system call mechanism. Similar to asynchronous IO, the initiator of an asynchronous system call will not be blocked. The execution of the system call is performed by a dedicated thread, so the execution efficiency can be improved through batch processing and other methods. However, there are currently few applications designed for asynchronous system calls. In order to be compatible with existing programs, the existing technical solution implements a user-mode scheduler in the C language runtime library, which simulates traditional synchronous system calls by pausing thread execution. Currently, researchers use a user-mode thread scheduler to achieve compatibility with existing programming interfaces. The thread that initiates the system call will be suspended and resumed after the execution of the system call is completed.

[0005] Existing research on asynchronous system calls is based on the NPTL thread library (Native POSIX Threading Library) commonly used in C language, but this NPTL thread library does not have the ability of user-mode scheduling. Therefore, the original thread library must be modified significantly to use asynchronous system calls. The asynchronous system calls implemented by different researchers may have performance differences due to different modifications to the runtime library, making it difficult to make a unified comparison. For example, a one-to-one thread library can be modified to a one-to-many thread library, and the running thread will be paused and switched to other threads when initiating a system call. It is also possible to increase the kernel's support for asynchronous system calls by adding additional system calls. However, these existing technologies will have the following problems in application scenarios:

[0006] Problem 1: No support for coroutine scheduling. The NPTL thread library itself does not provide coroutine functionality, nor does it add a programming interface for creating and managing coroutines.

[0007] Problem 2: It does not support Linux kernel versions 2.6 and above. New system calls are added to enable the kernel to support asynchronous system calls, but the newly added system call numbers conflict with Linux kernel versions 2.6 and above.

[0008] With the widespread application of coroutine programming in recent years, more and more applications use coroutine technology to provide higher concurrency. Go language is one of the most widely used programming languages ​​that provides coroutine mechanism. There is an urgent need for a function that uses the internal function of the Go language scheduler to call the asynchronous system. Summary of the invention

[0009] The purpose of the present invention is to provide an asynchronous system call system based on coroutines to solve the problem of asynchronous execution of system calls in a programming language based on coroutines.

[0010] In order to achieve the above-mentioned purpose of the invention, the technical solution provided by the present invention is:

[0011] An asynchronous system call system based on coroutines, comprising a recording module, an execution module, and a return module, wherein a call queue is provided between the recording module and the execution module, and a return queue is provided between the execution module and the return module;

[0012] The recording module is used to receive a system call request initiated by a coroutine, record the system call parameters and coroutine information contained in the system call request, save the system call parameters and coroutine information in a call queue, and pause the coroutine that initiated the system call, and then determine whether to start executing the system call;

[0013] The execution module is used to use an auxiliary thread to execute the system call transmitted from the call queue, and after the system call is executed, the system call return value and coroutine information are stored in the return queue;

[0014] The return module is used to read the system call return value from the return queue and add the coroutine to the running queue according to the coroutine information to resume the coroutine running.

[0015] Compared with the prior art, the present invention has at least the following advantages:

[0016] The coroutine-based asynchronous system call system provided in the embodiment realizes the function of asynchronous system call through the cooperation of recording module, execution module and return module. Asynchronous system call can process multiple system calls in batches to improve the performance of the program. Experiments show that this system can improve the kernel performance by 60%, thereby bringing 13% overall performance improvement. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0018] Figure 1 It is a structural diagram of an asynchronous system call system based on coroutines provided in an embodiment of the present invention;

[0019] Figure 2 It is a schematic diagram of the structure of a lock-free queue provided by an embodiment of the present invention;

[0020] Figure 3 is a workflow diagram of a recording model provided by an embodiment of the present invention;

[0021] Figure 4 It is a workflow diagram of the auxiliary thread provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0022] To make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific implementation methods described herein are only used to explain the present invention and do not limit the scope of protection of the present invention.

[0023] The embodiment provides an asynchronous system call system based on coroutines. This system needs to meet the requirements of compatibility and performance and minimize the impact on the original Go language runtime and the Linux operating system kernel. In terms of compatibility, the design purpose of this system is to implement asynchronous system calls based on Go coroutines without changing the system call interface of the user code, and to complete the recording, execution and return functions required for asynchronous system calls by modifying its implementation method.

[0024] In terms of performance, the system needs to support multi-core processors to execute system calls in parallel. Since the Go language scheduler will try to occupy all available physical parallelism, the impact of executing system calls on the original scheduling algorithm needs to be considered when designing the system. The system should be able to adjust the operation strategy in time according to the current load, while fully utilizing the computer performance and reducing the scheduling overhead caused by too many threads.

[0025] The parts of this system that involve the operating system kernel include the application of system call execution threads and the way to modify the kernel code. The thread that actually executes the system call can be implemented by the kernel thread in the kernel, or an additional thread can be added to the runtime library for processing. Since the use of kernel threads is subject to many restrictions and it is difficult for user-mode programs to control them, this system chooses to apply for new threads in user mode. This method is transparent to the kernel and does not require any modifications to its scheduling code. The original Go language scheduler also implements system calls in a similar way, so this implementation has little impact on the Go language scheduler.

[0026] The modification of the kernel can be achieved by directly modifying the kernel source code or adding a kernel module. In this embodiment, the system only adds a line of source code to export the system call table. In addition to exporting the system call table, all the required kernel state functions of the system are implemented in the form of kernel modules. When using it, you only need to compile the kernel module according to the kernel version running in the system.

[0027] like Figure 1 As shown in the figure, the asynchronous system call system based on coroutine includes a recording module, an execution module, and a return module. The queue between the recording module and the execution module is called a call queue, and the queue between the execution module and the return module is called a return queue. The asynchronous system call system is designed based on the Go language. Each part is introduced in detail below.

[0028] In this system, queues are used for communication between modules, and they need to cross kernel state and user state. Therefore, the performance of queues is crucial to the operation of asynchronous system calls. The call queue and return queue use lock-free queues, and the lock-free queues use atomic operations to synchronize data in the call queue and return queue in a multi-threaded environment.

[0029] The call queue and return queue in this system are different from the local and global run queues in the Go language scheduler, which will involve the operating system kernel. Therefore, a high-performance lock-free queue is re-implemented in this system as needed. The lock-free queue uses atomic operations to solve synchronization problems. Common atomic operations include reading variables, increasing variable values, and comparing and exchanging. The compare and exchange operation requires three parameters: the address of the atomic variable, the old value, and the new value. The operation first compares the value in the atomic variable with the old value. If they are different, false is directly returned. If they are the same, it is replaced with the new value and true is returned. The whole process is atomic to the caller. With this operation, the user can first read the value of a variable as the old value, and then try to compare and exchange the new value after calculating it. The successful completion of the operation indicates that there is no competition with other threads during the operation, and subsequent operations can continue. If the operation fails, it means that other threads have completed the operation on this variable when calculating the new value, so it is necessary to re-read, calculate, and try to modify the variable.

[0030] The atomicity of atomic operations is guaranteed by the processor, so atomic operations are generally provided by the processor instruction set and need to be operated in assembly language. In programming languages, assembly instructions are generally packaged in the form of functions, so the same atomic operation may have different names in different programming languages. Since the implementation of lock-free queues in this system involves the Linux kernel and the Go language, it is necessary to first understand the atomic operation functions in these two programming environments. In the Go language, atomic operations are provided by the atomic package.

[0031] The basic operations of the queue include enqueue and dequeue. The implementation of the lock-free queue needs to ensure that there is no conflict when multiple threads are enqueued or dequeued at the same time, and the dequeue operation needs to be performed after the enqueue operation is completed. In order to meet this requirement, the lock-free queue is provided with sequence numbers and labels for enqueue and dequeue. The thread operating the queue can only start the read and write operations of the corresponding data entries after successfully modifying these auxiliary variables through atomic operations. Figure 2 It is the data structure of a lock-free queue.

[0032] The queue entry number and the queue exit number are used to synchronize different producers or consumers. The entire queue only needs one queue entry number and one queue exit number. Before the queue entry operation, the producer obtains the queue entry number through atomic instructions and increments it. Successful modification of the queue entry number indicates that there is no queue entry conflict at this time, and the queue entry operation can continue.

[0033] In a circular queue, different producers will correspond to the same data when the sequence number difference is equal to the buffer length. Therefore, the enqueue number and the dequeue number are used to protect the atomicity of the corresponding data entry operation. Each data entry corresponds to a pair of enqueue and dequeue numbers.

[0034] When the user operates the queue, it may be scheduled by the operating system or by the Go runtime due to function calls. Due to the limited length of the buffer, a long queue operation time will cause subsequent threads that need the same data entry to fail to execute, and a thread jam may cause multiple threads to wait. Therefore, before performing queue operations, all forms of preemptive scheduling should be turned off as much as possible to ensure the smooth execution of queue operations.

[0035] In addition to the earlier threads being executed should try to avoid affecting the subsequent threads, the subsequent threads also need to promptly detect and try to handle the jams of other threads. Queue operations will not modify the enqueue and dequeue marks before completion, and under normal circumstances, the read and write speed of queue data is very fast, and there will almost be no mismatch in the labels. Therefore, the wrong label can indicate that the running thread may have jammed. Since the thread that has obtained the enqueue or dequeue sequence number must complete all the work to avoid further jams, for enqueue and dequeue, the label in the queue entry to be used can be read and checked before obtaining the sequence number. If the label of the entry does not match the sequence number, the execution can be abandoned immediately. When the label is correct and the sequence number is successfully modified, the data of the entry can be directly operated without additional checks.

[0036] The recording module is used to receive a system call request initiated by a coroutine, record the system call parameters and coroutine information contained in the system call request, save the system call parameters and coroutine information to a call queue, and pause the coroutine that initiated the system call, and then determine whether to start executing the system call. Specifically, the process of the recording module is as follows: Figure 3 As shown, the following steps are included:

[0037] For the initiated system call, determine whether the coroutine is locked. If the coroutine is locked, execute the traditional system call method; if the coroutine is not locked, record the coroutine in the call queue, suspend the coroutine, modify the queue number, schedule other coroutines to run, and wait for the system call to end.

[0038] Since asynchronous system calls need to schedule other coroutines to run after they are initiated, locked coroutines cannot use asynchronous system calls because they will not be scheduled. This situation requires special handling. The locking function is implemented by the lockedg variable in the g structure.

[0039] For a normally running coroutine, the recording module can put the relevant parameters into the call queue at this time, and then suspend the coroutine operation through the gopark function to let the thread go. However, there is a hidden synchronization problem here. The modification of the coroutine state is in the gopark function, and the queue state is modified by the recording module. Therefore, after the enqueue number is modified, the system call execution module believes that the enqueue operation has been completed, but in fact the coroutine is still in the running state. If the execution module and the return module complete the corresponding tasks, the problem of inconsistent state will be encountered when the coroutine is added to the return queue. In the scheduler, the modification of the coroutine state is completed by the CAS atomic instruction. If the value in the variable is inconsistent with the expected value, busy waiting is performed. If they are in the same logical processor, since the preemptive scheduling of the Go language is invalid for the busy waiting state that does not execute function calls, this thread cannot continue to run. Therefore, the modification of the enqueue number should be after the modification of the coroutine state, and this purpose can be achieved by using the unlockf parameter provided by the gopark function. In addition, since the function call to gopark may trigger preemptive scheduling, the acquirem and releasem functions need to be called before and after the enqueue operation to suspend preemptive scheduling.

[0040] In one embodiment, in order to implement batch processing of system calls to reduce the number of switches to the kernel, a threshold is set in the recording module, and when the number of system calls reaches the threshold, the execution module is notified to start executing the system call. Although the execution of the system call does not require coroutine-related information for the operating system kernel, this coroutine information needs to be passed to the return module for resuming the operation of the coroutine after the system call is completed. Therefore, the entry in the call queue also contains the coroutine information in addition to the system call number and parameters.

[0041] In one embodiment, the recording module wakes up the auxiliary thread in the execution module to execute the system call when there is an idle logical processor or the number of system calls reaches a threshold. When there is an idle logical processor, the execution module can use the idle processor resources to execute the system call. Considering that for asynchronous system calls, there should be no idle logical processors in the ideal application scenario (otherwise the original thread can only wait when executing the system call), this system does not study how to control the number of auxiliary threads running simultaneously at this time during the design process. When there is an idle processor, the auxiliary thread is directly woken up to execute the system call.

[0042] In order to prevent multiple coroutines from waking up the auxiliary thread at the same time, the wakeup is locked here. The recording module needs to obtain the lock before waking up the auxiliary thread, and the auxiliary function releases the lock after waking up. Unlike ordinary spin locks or mutex locks, the coroutine that has not obtained the lock does not wait for the lock to be released but directly skips the wakeup step. The judgment and execution of the wakeup are executed immediately after the system call parameters are queued and the preemptive call is restored;

[0043] In addition to waking up the auxiliary thread when a system call is initiated, it is also necessary to check whether the call queue is empty before the thread sleeps. If there is an unexecuted system call, the auxiliary thread is woken up. Since the execution of the system call takes time and may be blocked, the thread still executes the original sleep operation after waking up the auxiliary thread. Similar to the operation of the logical processor during normal sleep, the call queue is also checked after the logical processor is released.

[0044] The execution module is used to use an auxiliary thread to execute the system call transmitted from the call queue, and after the system call is executed, the system call return value and the coroutine information are stored in the return queue. In the execution module, since the system call is stored in the form of a queue, as many system calls as possible can be executed without worrying about the start threshold. After the system call is executed, the execution module stores the return value and the coroutine information in the return queue. It should be noted that since the time required to execute different system calls is different, when multi-threaded system calls are processed, the position of the same coroutine in the return queue may be different from that in the call queue. When the execution module is exited by the kernel, the coroutine information and return value data of the system call are located in the return queue. At this time, since the auxiliary thread does not obtain the logical processor, the coroutine cannot be added to the local run queue. If the coroutine is placed in the global run queue, the competition for the global scheduling lock will be intensified. Therefore, the execution module does not process these coroutines, and the coroutine scheduler processes them in the appropriate actual call return module. The execution module only needs to ensure that there is a running thread that can trigger the scheduler.

[0045] The thread that actually runs the system call in the execution module is created by the scheduler in the user state. The kernel module provides an interface to the user state in the form of a device driver, does not generate new threads, and is handled by the scheduler when the system call is blocked.

[0046] Among them, the execution module includes an interface provided to the recording module, an auxiliary thread for executing system calls, and a blocking processing thread; when the interface function determines that a system call needs to be executed, it will wake up the auxiliary thread to enter the kernel state to complete the system call, and the blocking processing thread is responsible for waking up additional auxiliary threads when blocking occurs.

[0047] The runtime library using asynchronous system calls creates multiple auxiliary threads at startup. These threads are similar to sysmon monitoring threads and do not occupy logical processors. After startup, auxiliary threads go directly to sleep and wait to be awakened. In order to determine whether there are auxiliary threads running, the system sets a variable to count the number of sleeping auxiliary threads, which they modify before sleeping and after being awakened.

[0048] Figure 4 This is the workflow diagram of the auxiliary thread, such as Figure 4As shown, the working process of the auxiliary thread includes: the auxiliary thread is awakened and enters the kernel state. When the call queue is not empty, it returns to the user state and tries to wake up the execution thread. At this time, the auxiliary thread is dormant; when the call queue is empty, it reads and executes the system call, writes the system call result to the return queue, and then returns to the user state and tries to wake up the execution thread. At this time, the auxiliary thread is dormant.

[0049] After the auxiliary thread in the recording module switches to kernel state, in order to spread the switching overhead and improve locality, the auxiliary thread continuously processes the system calls in the call queue until the call queue is empty, which is not affected by the execution module startup threshold. When processing a system call, the auxiliary thread first obtains the corresponding system call number, parameters, and coroutine information from the call queue. If the call queue is empty, it returns directly to user state. The auxiliary thread does not need to repeatedly check to confirm that the call queue is empty before returning. At this time, the newly initiated system call can remain in the call queue until the number reaches the threshold and the recording module wakes up the execution module again.

[0050] After the auxiliary thread saves the parameters to the appropriate variables, it calls the function at the corresponding position in the system call table sys_call_table according to the system call number and obtains the system call return value. The auxiliary thread then writes the return value and the corresponding coroutine information into the return queue and returns to the user state.

[0051] After executing the recorded system call and returning to the user state, the auxiliary thread needs to determine whether to wake up the thread to execute these coroutines, because the coroutines that have completed the system call are in the return queue, and the function of reading the return queue is in the return module and is controlled by the scheduler. The auxiliary thread goes back to sleep after completing the system call.

[0052] Executing system calls may cause thread blocking, and in certain cases may cause system operation to stagnate. This phenomenon may occur when the number of system calls is lower than the threshold but higher than the number of logical processors. If blocking occurs in these system calls, the auxiliary threads will not be woken up during recording due to the small number, and the number of auxiliary threads woken up when releasing logical processors will not exceed the number of logical processors. If no other threads wake up the auxiliary threads, the program may not be able to run because all threads are blocked in system calls. In order to prevent this phenomenon from occurring, this system adds a check for the dequeue number of the call queue in the monitoring thread sysmon. If the dequeue number observed during two consecutive wake-ups does not change and is less than the enqueue number, it is considered that the system call being executed is blocked and the auxiliary thread needs to be woken up.

[0053] The return module is used to read the system call return value from the return queue and add the coroutine to the run queue according to the coroutine information to resume the coroutine operation. Since the operation of the coroutine needs to be resumed, some functions of the return module are implemented in the scheduling function. For the scheduling function, the return queue is similar to an additional global run queue. The scheduler needs to call the return module to process this queue when looking for available coroutines.

[0054] In an asynchronous system call, since the coroutine that initiates the system call does not directly call the system call instruction, the result of the system call cannot be directly obtained in the form of a return value. In order to solve the problem of return value storage, additional storage space is required in the implementation of asynchronous system calls to store the return value. The storage method of the system call return value is: applying for additional memory space in the recording module to store the return value; or recording the return value at a fixed position relative to each coroutine.

[0055] In order to apply for additional memory space to store the return value, Go language will perform variable escape analysis during compilation and prohibit passing the pointer to the stack to other functions, so only additional heap memory can be applied. However, when the number of system calls in user code is large, frequent application and release of small blocks of memory will have a greater impact on performance.

[0056] The return value is recorded at a fixed position relative to each coroutine. Since each coroutine has a corresponding g structure to store its related scheduling information, a new member variable can be added to it to store the result of the most recent system call. Since the pointer to the coroutine has been used as an additional parameter in the information transmission of the asynchronous system call, the return value can be directly written to the corresponding variable in the coroutine data structure using this pointer.

[0057] New runnable coroutines can only be put into the run queue of the corresponding logical processor P or the global queue by the thread that is already running. Since the modification of the global run queue requires obtaining the global scheduling lock sched.lock, which may affect system performance, this system chooses to have the running thread read the return queue and put the coroutine that has completed the system call into the run queue of the corresponding logical processor.

[0058] Since there is no restriction on access to the run queue, any part of the scheduler code can do this work. In order to reduce the overall impact on the scheduler, this system chooses to process the completed system call before reading the local run queue, so that the scheduler can get the executable coroutine normally without doing additional checks.

[0059] In another embodiment, the asynchronous system call system further includes an initialization module, which is used to apply for a shared memory from the memory manager for data transfer and execution of system calls when the application is started.

[0060] Before using asynchronous system calls, user-mode programs need to open device nodes through the open system call. When the kernel module executes the mydev_open function, it can be considered that the user-mode application is in the initialization phase and attempts to use the asynchronous system call technology. Therefore, the kernel module needs to complete the corresponding preparations. At this time, the kernel module applies to the memory manager for a fixed-size memory for data transfer through the kzalloc function. The size of the memory will not affect the smooth execution of the asynchronous system call, but a larger memory means a longer queue, which can reduce the performance impact caused by competition when the load is high. The kernel module can apply for an appropriate memory size based on the system operation status.

[0061] After successfully applying for the memory, write its address to the private_data member in the file structure. This member variable is provided by the Linux kernel for the convenience of device drivers to save their own additional information. Next, the user-mode program can map the memory to its own process address space through the mmap system call. This work is implemented by calling the remap_pfn_range function and passing the address in private_data to this function. When mmap returns successfully, the user-mode program successfully obtains a piece of available shared memory. At this time, the system kernel and the application can transfer data through shared memory, so the initialization of the data structure in the shared memory can be completed by the user-mode program.

[0062] When the system call is actually executed, the execution module enters the kernel module through the ioctl system call, then obtains the address of the shared memory through private_data and executes the corresponding system call. The result of the system call is also written back to the shared memory.

[0063] The test results of the coroutine-based asynchronous system call system under a given test environment and test program show that asynchronous system calls can bring enough performance improvement to offset the scheduling overhead in appropriate scenarios, increasing the kernel state operation efficiency by up to 60% and the overall program operation speed by up to 13%. In actual applications, the performance of net / http packages can be improved by up to 4.4%.

[0064] The specific implementation methods described above provide a detailed description of the technical solutions and beneficial effects of the present invention. It should be understood that the above is only the most preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, supplements and equivalent substitutions made within the scope of the principles of the present invention should be included in the protection scope of the present invention.

Claims

1. A coroutine-based asynchronous system call system, characterized in that: It includes a recording module, an execution module, and a return module. A call queue is provided between the recording module and the execution module, and a return queue is provided between the execution module and the return module. The recording module is used to receive a system call request initiated by a coroutine, record the system call parameters and coroutine information contained in the system call request, save the system call parameters and coroutine information in a call queue, and pause the coroutine that initiated the system call, and then determine whether to start executing the system call; The execution module is used to use an auxiliary thread to execute the system call transmitted from the call queue, and after the system call is executed, the system call return value and coroutine information are stored in the return queue; The return module is used to read the system call return value from the return queue and add the coroutine to the running queue according to the coroutine information to resume the coroutine running; The calling queue and the return queue adopt a lock-free queue. The lock-free queue adopts atomic operations to realize the synchronization of data in the calling queue and the return queue in a multi-threaded environment. The lock-free queue is provided with sequence numbers and labels for enqueuing and dequeuing. The enqueuing sequence number and the dequeuing sequence number are used to synchronize different producers or consumers. The entire queue only needs one enqueuing sequence number and one dequeuing sequence number. Before the enqueuing operation, the producer obtains the enqueuing sequence number through atomic instructions and increments it. Successful modification of the enqueuing sequence number indicates that no enqueuing conflict occurs at this time, and the enqueuing operation can continue. The enqueuing label and the dequeuing label are used to protect the atomicity of the corresponding data entry operation, and each data entry corresponds to a pair of enqueuing and dequeuing labels. For enqueuing and dequeuing, the label in the queue entry to be used can be read and checked before obtaining the sequence number. If the label of the entry does not match the sequence number, the execution can be abandoned immediately. When the label is correct and the sequence number is successfully modified, the data of the entry is directly operated without additional checks.

2. The coroutine-based asynchronous system call system according to claim 1, characterized in that: The asynchronous system call system also includes an initialization module, which is used to apply for a shared memory from the memory manager for data transmission and execution of system calls when the application is started.

3. The coroutine-based asynchronous system call system according to claim 1, characterized in that: The recording module is provided with a threshold value, and when the number of system calls reaches the threshold value, the execution module is notified to start executing the system calls.

4. The coroutine-based asynchronous system call system according to claim 1, characterized in that: The recording module wakes up the auxiliary thread in the execution module to execute the system call when there is an idle logical processor or the number of system calls reaches a threshold; In order to prevent multiple coroutines from waking up the auxiliary thread at the same time, the wakeup is locked here. The judgment and execution of the wakeup are executed immediately after the system call parameters are queued and the preemptive call is restored; In addition to waking up the auxiliary thread when a system call is initiated, it is also necessary to check whether the call queue is empty before the thread sleeps, and wake up the auxiliary thread if there is an unexecuted system call; After waking up the auxiliary thread, the thread still executes the original sleep operation.

5. The coroutine-based asynchronous system call system according to claim 1, characterized in that: The execution module includes an interface provided to the recording module, an auxiliary thread for executing system calls, and a blocking processing thread; when the interface function determines that a system call needs to be executed, it will wake up the auxiliary thread to enter the kernel state to complete the system call, and the blocking processing thread is responsible for waking up additional auxiliary threads when blocking occurs.

6. The coroutine-based asynchronous system call system according to claim 1, characterized in that: The storage method of the system call return value is: Allocate additional memory space in the recording module to store the return value; or record the return value at a fixed location relative to each coroutine.

7. The coroutine-based asynchronous system call system according to claim 1, characterized in that: The asynchronous system call system is designed based on the Go language.