Input and output request processing method and device and electronic equipment

By creating a worker thread pool in the first execution environment and using the task queue and the result queue to communicate with the second execution environment, the problem of low efficiency of TEE in execution of IO requests through REE is solved, and efficient IO request processing and resource savings are achieved.

CN120029754APending Publication Date: 2025-05-23HUAWEI TECH CO LTD
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202311574759.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-11-22
Publication Date
2025-05-23

AI Technical Summary

Technical Problem

In the prior art, TEE is inefficient when executing IO requests through REE, and frequent switching of execution environments leads to high resource overhead.

Method used

By creating a worker thread pool in the first execution environment, communicating with the second execution environment using the task queue and the result queue, multiple worker threads concurrently process IO requests, reducing execution environment switching.

Benefits of technology

The efficiency of the application in the second execution environment to process IO requests through the first execution environment is improved, the resource overhead required for executing the environment switching is saved, and the performance of the electronic device is improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120029754A_ABST
    Figure CN120029754A_ABST
Patent Text Reader

Abstract

The invention discloses an input and output request processing method and device and electronic equipment, and belongs to the technical field of electronic equipment. The method is applied to the electronic equipment, a first execution environment of the electronic equipment comprises a first working thread pool, and the first working thread pool communicates with a first application running in a second execution environment of the electronic equipment through a first task queue and a first result queue. The first working thread pool comprises a plurality of working threads used for processing IO requests in the first task queue. The method comprises the following steps: working threads in a first working thread pool respectively obtain IO requests from a first task queue; and for a first IO request obtained by the first working thread in the first working thread pool, the first working thread executes the first IO request, and writes an obtained first request result into a first result queue. Through the method, the efficiency of processing the IO request through the first execution environment by the first application in the second execution environment of the electronic equipment can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of electronic equipment, and in particular to a method and device for processing input and output requests, and an electronic device. Background Art

[0002] With the development and application of Internet technology, user data faces more and more security threats (such as network attacks, etc.). In view of this, current electronic devices generally support running trusted execution environment (TEE). By loading important data in TEE and performing operations, the security of user data in the initial state can be guaranteed, as well as the security of legitimate applications that operate important data during runtime.

[0003] Among them, TEE is an execution environment isolated from a rich execution environment (REE) in an electronic device. REE is also called a normal operating environment, which generally has rich functions but generally has low security. It is usually used to run operating systems and client applications (CA) (such as social applications, etc.) of electronic devices. Compared with REE, TEE has relatively fewer functions but a high security level. It is generally used as an execution environment for operations that require confidentiality (such as fingerprint recognition, password processing, data encryption and decryption, security authentication, etc.). Therefore, applications running in TEE are called legitimate applications or trusted applications (TA).

[0004] Currently, in electronic devices that support TEE and REE, REE generally directly accesses and uses the input / output (IO) resources (such as disks, network cards, etc.) of electronic devices, while the TA in TEE needs to execute the IO request through REE when executing the IO request. Therefore, how to improve the efficiency of TEE when executing IO requests through REE has become a technical problem that needs to be solved urgently. Summary of the invention

[0005] The present application provides a method, device and electronic device for processing input and output requests. The method provided by the present application can improve the efficiency of an application in a second execution environment of an electronic device in processing IO requests through a first execution environment.

[0006] The technical solutions provided by this application are as follows:

[0007] In the first aspect, the present application provides a method for processing an input / output (IO) request, which is applied to an electronic device, wherein the first execution environment of the electronic device includes a first work thread pool, the first work thread pool communicates with a first application running in a second execution environment of the electronic device through a first task queue and a first result queue, the first task queue is used to store the IO request of the first application, the first result queue is used to store the request result of the IO request, and the first work thread pool includes a plurality of work threads for processing the IO request in the first task queue. The method includes: the work threads in the first work thread pool respectively obtain IO requests from the first task queue; for the first IO request obtained by the first work thread in the first work thread pool from the first task queue, the first work thread executes the first IO request to obtain the first request result; the first work thread writes the first request result into the first result queue. Wherein, the first work thread is any work thread in the first work thread pool that obtains the IO request.

[0008] Through the method provided by the present application, multiple working threads of the first working thread pool in the first execution environment of the electronic device are used to process the IO request of the first application running in the second execution environment of the electronic device, so that the efficiency of the first application in the second execution environment processing the IO request through the first execution environment can be improved. In addition, since the first execution environment and the second execution environment are running in the electronic device at the same time, during the execution of the method provided by the present application, the electronic device does not need to frequently call instructions to switch the first execution environment and the second execution environment, so that the resource overhead required for switching the execution environment can be saved, thereby ensuring the performance of the electronic device.

[0009] In one possible design, the first execution environment of the electronic device also includes a second working thread pool, which communicates with a second application in the second execution environment through a second task queue and a second result queue. The second task queue is used to store IO requests of the second application, and the second result queue is used to store request results of the IO requests of the second task queue. The second working thread pool includes multiple working threads, and the working threads in the second working thread pool are used to process IO requests in the second task queue and write the obtained results into the second result queue.

[0010] Through this possible design, the method provided by the present application creates corresponding work thread pools in the first execution environment for different applications (e.g., the first application and the second application) in the second execution environment. In this way, multiple work threads corresponding to each application in the second execution environment and located in the work thread pool in the first execution environment can concurrently process the IO requests of each application. In other words, the present application supports concurrent processing of IO requests of multiple applications in the second execution environment in the first execution environment, so that the method provided by the present application improves the processing efficiency of IO requests of multiple applications in the second execution environment by the first execution environment.

[0011] In another possible design, the first execution environment of the electronic device also includes a detection thread corresponding to the first work thread pool. Before the work threads in the first work thread pool respectively obtain IO requests from the first task queue, the method also includes: the work threads in the first work thread pool in a dormant state receive a wake-up instruction sent by the detection thread; in response to the wake-up instruction, the work threads in the first work thread pool in a dormant state switch from a dormant state to a ready state. In this case, the work threads in the first work thread pool obtain IO requests from the first task queue respectively, including: the work threads in the first work thread pool whose states switch from a dormant state to a ready state obtain IO requests from the first task queue respectively. Among them, the detection thread is used to detect whether the first task queue is empty, and to determine whether there are dormant work threads in the first work thread pool when it is detected that the first task queue is not empty, and to send a wake-up instruction to the dormant work threads in the first work thread pool when it is determined that there are dormant work threads in the first work thread pool.

[0012] This possible design indicates that the working thread for processing IO requests in the first execution environment is in a dormant state when not executing an IO request, thereby achieving the purpose of saving resources in the electronic device when the working thread is idle.

[0013] In another possible design, when there is no worker thread in a dormant state in the first worker thread pool, the detection thread is further used to create a first preset number of worker threads in the first worker thread pool. In this case, the worker threads in the first worker thread pool respectively obtain IO requests from the first task queue, including: the newly created worker threads in the first worker thread pool respectively obtain IO requests from the first task queue.

[0014] Through this possible design, when the number of IO requests of the first application in the second execution environment is large, a new working thread is timely created in the first execution environment, thereby improving the processing efficiency of the IO requests of the first application in the second execution environment.

[0015] In another possible design, when the above-mentioned detection thread is used to periodically detect whether the first task queue is empty, the detection thread is also used to detect the frequency of writing IO requests to the first task queue in each cycle to obtain the detection result of each cycle, and the detection result is used to adjust the cycle duration of the detection thread to detect whether the first task queue is empty.

[0016] By this possible design, it is possible to realize timely according to the frequency of writing IO request to the first task queue, adjusting the cycle duration of detecting whether the first task queue is empty. For example, when the frequency of writing IO request to the first task queue is higher, shorten the cycle duration of detecting whether the first task queue is empty. For another example, when the frequency of writing IO request to the first task queue is lower, increase the cycle duration of detecting whether the first task queue is empty. In this way, it is possible to effectively save the occupation of the detection thread for detecting whether the first task queue is empty to the electronic equipment resources on the basis of ensuring the efficiency of processing IO request in the first task queue.

[0017] In yet another possible design, the detection thread is further configured to destroy a second preset number of dormant worker threads in the first worker thread pool when it is detected that the first task queue is empty.

[0018] Through this possible design, when there is no IO request in the first task queue, the redundant working threads in the first working thread pool can be destroyed in time, which can effectively reduce the occupation of resources in the electronic device by the working threads.

[0019] In another possible design, after the first working thread writes the first request result into the first result queue, or after the first working thread writes the first request result into the first result queue and when the first working thread again obtains the IO request from the first task queue and receives the queue empty status information returned by the first task queue, the method further includes: the first working thread sets its own status to a sleep state.

[0020] Through this possible design, it is possible to put the idle working threads that have processed the IO requests into a dormant state, which can reduce the occupation of electronic device resources by these working threads.

[0021] In another possible design, the IO request of the first application includes a disk IO request. In this case, the first task queue is used to store the disk IO request of the first application.

[0022] In another possible design, the IO request of the first application also includes a network IO request. In this case, the first execution environment of the electronic device also includes a third work thread pool, the third work thread pool communicates with the first application through a third task queue and a third result queue, the third task queue is used to store the network IO request of the first application, the third result queue is used to store the request results of the network IO request in the third task queue, the third work thread pool includes multiple work threads, and the work threads in the third work thread pool are used to process the network IO request in the third task queue and write the obtained request results into the third result queue.

[0023] Through the above two possible designs, the processing efficiency of processing the disk IO requests and network IO requests of the application in the second execution environment by the working thread in the first execution environment can be improved.

[0024] In yet another possible design, a security level of the first execution environment in the electronic device is different from a security level of the second execution environment.

[0025] In another possible design, the first execution environment in the electronic device is a rich execution environment (REE), and the second execution environment is a trusted execution environment (TEE).

[0026] In the second aspect, the present application provides a method for processing IO requests, which is applied to an electronic device, wherein a first application is running in a second execution environment of the electronic device, and the first application communicates with the first execution environment of the electronic device through a first task queue and a first result queue, wherein the first task queue is used to store the IO requests of the first application, and the first result queue is used to store the request results of the IO requests in the first task queue. The method includes: the first application writes a first IO request to the first task queue; the first application obtains a first request result of the first IO request from the first result queue. The first IO request is any IO request written by the first application to the first task queue, and the first request result is the request result obtained after the working thread in the working thread pool corresponding to the first application in the first execution environment processes the first IO request.

[0027] In one possible design, a second application is also running in the second execution environment of the electronic device. The second application communicates with the first execution environment through a second task queue and a second result queue. The second task queue is used to store IO requests of the second application, and the second result queue is used to store request results of the IO requests in the second task queue. The request result is the request result obtained after the working thread in the working thread pool corresponding to the second application in the first execution environment processes the IO request in the second task queue.

[0028] In another possible design, the IO request of the first application includes a disk IO request. In this case, the first task queue is used to store the disk IO request of the first application.

[0029] In another possible design, the IO request of the first application also includes a network IO request. In this case, the first application also communicates with the first execution environment through a third task queue and a third result queue, the third task queue is used to store the network IO request of the first application, and the third result queue is used to store the request result of the network IO request in the third task queue, which is the request result obtained after the worker thread in the worker thread pool corresponding to the first application in the first execution environment processes the IO request in the third task queue.

[0030] In yet another possible design, the security level of the first execution environment in the electronic device is different from the security level of the second execution environment.

[0031] In yet another possible design, the first execution environment in the electronic device is REE, and the second execution environment is TEE.

[0032] In another possible design, after the first application writes the first IO request to the first task queue, the method further includes: receiving a first identifier (ID) of the first IO request returned by the first task queue. In this case, the first application obtains the first request result of the first IO request from the first result queue, including: determining the request result including the first ID in the request results obtained from the first result queue as the first request result. Each request result of the first result queue includes the ID of the IO request that obtains each request result.

[0033] It should be understood that the description of the beneficial effects of any method provided in the second aspect can refer to the description of the beneficial effects of the corresponding method provided in the first aspect, and no further details will be given.

[0034] In a third aspect, the present application provides a device for processing IO requests.

[0035] In a possible design, the processing device is used to execute any one of the methods provided in the first aspect above. The present application may divide the functional modules of the processing device according to any one of the methods provided in the first aspect above. For example, each functional module may be divided according to each function, or two or more functions may be integrated into one processing module. Exemplarily, the present application may divide the processing device into an acquisition unit, an execution unit, and a writing unit, etc. according to the function. The description of the possible technical solutions and beneficial effects executed by each of the functional modules divided above can refer to the technical solutions provided by the first aspect or its corresponding possible design, which will not be repeated here.

[0036] In another possible design, the processing device is used to execute any of the methods provided in the second aspect above. The present application may divide the processing device into functional modules according to any of the methods provided in the second aspect above. For example, each functional module may be divided according to each function, or two or more functions may be integrated into one processing module. Exemplarily, the present application may divide the processing device into a writing unit and an acquisition unit, etc. according to the function. The description of the possible technical solutions and beneficial effects executed by each of the divided functional modules can refer to the technical solutions provided by the second aspect or its corresponding possible design, which will not be repeated here.

[0037] In another possible design, the processing device includes: a first processing unit and a second processing unit. The first processing unit is used to run a first execution environment and to execute any method provided in any possible design of the first aspect. The second processing unit is used to run a second execution environment and to execute any method provided in any possible design of the second aspect.

[0038] In another possible design, the processing device includes: one or more processors, a memory and a communication interface, the one or more processors receive or send data through the communication interface, and the one or more processors are configured to call program instructions stored in the memory so that the processing device executes any method provided in any possible design method in the first aspect and / or the second aspect.

[0039] In a fourth aspect, the present application provides an electronic device, comprising one or more processors and a memory, wherein the one or more processors are configured to read a first program instruction in the memory to run a first execution environment and execute any method provided by any possible design method in the first aspect. The one or more processors are also configured to read a second program instruction in the memory to run a second execution environment and execute any method provided by any possible design method in the second aspect.

[0040] In a fifth aspect, the present application provides a computer-readable storage medium, which is a non-volatile computer-readable storage medium, and the computer-readable storage medium includes program instructions. When the program instructions are executed on a computer or a processor, the computer or the processor executes a method provided in any possible implementation manner in the first aspect and / or the second aspect of the present application.

[0041] In a sixth aspect, the present application provides a computer program product comprising instructions, which, when the computer program product runs on a computer or a processor, enables the computer or the processor to execute the method provided in any possible implementation of the first aspect and / or the second aspect of the present application.

[0042] In the seventh aspect, the present application provides a chip, comprising a processor, in which a first execution environment and a second execution environment are running, and the processor is used to execute a method provided in any possible implementation of the first aspect in the first execution environment, and to execute a method provided in any possible implementation of the second aspect in the second execution environment.

[0043] Exemplarily, the chip further includes: an input interface, an output interface, and a memory, etc. The input interface, the output interface, the processor, and the memory are connected via an internal connection path, and the memory is used to store program instructions or codes for implementing the method provided in any possible implementation manner in the first aspect and / or the second aspect, and is used to store IO requests and request results of IO requests.

[0044] It can be understood that any of the above-mentioned devices, electronic devices, computer-readable storage media, computer program products, etc. can be applied to the corresponding methods provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding methods and will not be repeated here.

[0045] In this application, the name of the above-mentioned IO request processing device does not limit the device or functional module itself. In actual implementation, these devices or functional modules may appear with other names. As long as the functions of each device or functional module are similar to those of this application, they all fall within the protection scope of this application. BRIEF DESCRIPTION OF THE DRAWINGS

[0046] Figure 1 It is a schematic diagram of a process in which a TA in a TEE executes an IO request through a REE;

[0047] Figure 2 It is a real-time environment schematic diagram of the method provided in the embodiment of the present application;

[0048] Figure 3It is a schematic diagram of a software framework of an electronic device provided in an embodiment of the present application;

[0049] Figure 4 is another software framework schematic diagram of the electronic device provided in the embodiment of the present application;

[0050] Figure 5 It is another software framework schematic diagram of the electronic device provided in the embodiment of the present application;

[0051] Figure 6 This is a flowchart of a method for processing IO requests provided in an embodiment of the present application;

[0052] Figure 7 It is another flowchart of the method for processing IO requests provided in an embodiment of the present application;

[0053] Figure 8 This is a schematic diagram of a process in which a working thread obtains an IO request from a first task queue provided in an embodiment of the present application;

[0054] Fig. 9 It is a structural diagram of an IO request processing device provided in an embodiment of the present application;

[0055] Fig.10 It is a structural diagram of another IO request processing device provided in an embodiment of the present application;

[0056] Fig.11 It is a structural diagram of another IO request processing device provided in an embodiment of the present application;

[0057] Fig.12 It is a structural schematic diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0058] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below with reference to the accompanying drawings.

[0059] To facilitate understanding, the technology and background involved in the embodiments of the present application are first explained below.

[0060] 1) Shared memory (SHM)

[0061] Shared memory is a very effective way to share and transfer data between multiple running processes (or threads), and is one of the simple ways of inter-process communication. Shared memory allows multiple processes (or threads) to access the same memory block. Specifically, multiple processes (or threads) map the physical address of the same memory block to their respective logical address spaces, so that the multiple processes (or threads) can access the memory block, which is the shared memory used to implement communication between the multiple processes (or threads).

[0062] 2) Daemon process

[0063] A daemon is a special type of process that runs in the background to perform specific system tasks. Some daemons are started when the system boots and run until the system shuts down. Other daemons are started only when needed and terminate automatically after completing their tasks.

[0064] 3) Disk input / output (IO), network IO

[0065] Disk IO refers to the operation of reading and writing to the disk. Network IO refers to the operation of sending and receiving data through the network interface / communication interface.

[0066] 4) Client application (CA) and trusted application (TA)

[0067] CA is some upper-layer applications of rich execution environment (REE), such as social applications, e-commerce applications, etc. TA is an application that completes specific tasks in trusted execution environment (TEE), such as fingerprint recognition, password processing, data encryption and decryption, security authentication, etc. Since the security level of TEE is higher than that of REE, the TA that completes the calculation in TEE has a higher security level.

[0068] In one example, each TA in TEE has one or more corresponding CAs in REE. For example, for social applications (recorded as CA 1) and e-commerce applications (recorded as CA2) that support payment functions in REE, payment operations need to be performed, and the payment password processing (recorded as TA1) when performing payment operations is generally performed in TEE. That is, two CAs (CA 1 and CA 2) in REE correspond to one TA (TA1) in TEE.

[0069] In another example, each CA in REE has one or more corresponding TAs in TEE. For example, for a social application (referred to as CA 1) that supports payment functions in REE, the payment password processing (referred to as TA 1) of the social application when performing payment operations is executed in TEE, and the security authentication (referred to as TA 2) of the social application when logging into the user account is also executed in TEE. That is, one CA (CA 1) in REE corresponds to two TAs (TA 1 and TA2) in TEE.

[0070] In another example, when the CA in REE needs to perform certain specific operations / tasks (such as fingerprint recognition, password processing, data encryption and decryption, security authentication, etc.) through TEE during operation, it can instruct the TEE operating system (operating system, OS) (referred to as TEE OS) to create a process (or thread) in TEE to perform the specific operation / task by calling a command word. The process (or thread) is the TA running in TEE. In other words, during the operation of the CA in REE, TA can be initiated in TEE at any time to perform specific operations / tasks (such as fingerprint recognition, password processing, data encryption and decryption, security authentication, etc.) that require a high-security execution environment.

[0071] At present, in electronic devices that support TEE and REE, REE generally directly accesses and uses the IO resources of the electronic device (such as hard disk, network card, etc.), while TEE cannot directly access the IO resources of the electronic device. Therefore, the TA in TEE needs to be implemented through REE when executing IO requests.

[0072] refer to Figure 1 , Figure 1 FIG. 1 shows a schematic diagram of a process in which a TA in a TEE executes an IO request through a REE. Figure 1 As shown in the figure, in an electronic device that supports TEE and REE, the REE operating system (OS) (denoted as REEOS) creates and starts a daemon process (denoted as daemon server) as a server during the initialization phase. The daemon server then applies for a section of memory to serve as the SHM for communication between the daemon server and TEE.

[0073] For example, for each TA that performs specific tasks (such as fingerprint recognition, password processing, data encryption and decryption, security authentication, etc.) for the CA in REE on the TEE side, the TEE OS can create a daemon process as a client for each TA (referred to as a daemon process client). Figure 1As shown, TEE OS creates daemon client 1 for TA 1, daemon client 2 for TA 2, and so on. In this way, for a TA that performs a specific task for CA, such as TA 1, when TA 1 needs to execute an IO request (the IO request is, for example, a disk IO request to read data from the local disk of the electronic device), TA 1 can write the IO request to SHM through daemon client 1, and switch the execution environment of the electronic device to REE by calling the secure monitor call (smc) instruction and supervisor call instruction (svc) in the trusted firmware (ATF). It should be understood that the TEE and REE here are operated by time-sharing multiplexing the physical resources of the electronic device, so when it is necessary to execute a task in REE, the execution environment needs to be switched to REE.

[0074] Furthermore, the daemon server in REE obtains the IO request from SHM, responds to and executes the IO request, and writes the request result obtained after executing the IO request (such as the data read after executing the disk IO request) into SHM. Then, the daemon server of REE switches the execution environment of the electronic device to TEE by calling the smc, svc and other instructions in ATF. In this way, TA1 in TEE can obtain the request result from SHM. In this way, the purpose of TA in TEE executing IO request through REE is achieved.

[0075] However, in the current technology, the daemon server in REE is globally unique. Therefore, when multiple TAs in TEE or multiple threads in a single TA write IO requests to SHM, the daemon server in REE can only process the IO requests written to SHM one by one in serial, which will result in low efficiency of TA in TEE executing IO requests through REE. In addition, the current technology involves multiple calls to smc and svc instructions to switch TEE and REE, so the switching overhead is relatively large, which has a certain impact on the performance of electronic devices.

[0076] Based on this, an embodiment of the present application provides a method for processing IO requests, in which a first execution environment and a second execution environment are simultaneously running in an electronic device. A first application is running in the second execution environment. When the first application needs to execute an IO request, the first execution environment configures a first working thread pool for the first application, and configures the first working thread pool to communicate with the first application through a first SHM. The first SHM includes a first task queue and a first result queue. The first task queue is used to store the IO requests of the first application, and the first result queue is used to store the request results of the IO requests of the first application. The first working thread pool includes multiple working threads for processing IO requests in the first task queue. In this way, the first application can write IO requests in the first task queue, and the working threads in the first working thread pool can obtain IO requests from the first task queue and process them respectively, and write the obtained request results into the first result queue. Then, the first application obtains the request result from the first result queue.

[0077] Through the method provided in the embodiment of the present application, it is realized that multiple working threads of the first working thread pool in the first execution environment are used to process the IO request of the first application running in the second execution environment, so that the efficiency of the first application in the second execution environment processing the IO request through the first execution environment can be improved. In addition, since the first execution environment and the second execution environment are running in the electronic device at the same time, during the execution of the method provided in the embodiment of the present application, the electronic device does not need to frequently call smc, svc and other instructions to switch the first execution environment and the second execution environment, so that the resource overhead required for switching the execution environment can be saved, thereby ensuring the performance of the electronic device.

[0078] Optionally, the security level of the first execution environment is different from the security level of the second execution environment. The first application is used to execute a specific task of the application in the first execution environment, and the specific task is a business that needs to be processed in the second execution environment.

[0079] In some examples, the first execution environment is REE and the second execution environment is TEE. In this case, the first application is used to perform a specific task of any CA in REE, which generally has a high security level and therefore needs to be processed in TEE. For example, the specific task is fingerprint recognition, password processing, data encryption and decryption, security authentication, and other tasks.

[0080] Optionally, the electronic device may be any terminal device, computing platform or service platform running the first execution environment and the second execution environment, without limitation. For example, the electronic device may be a mobile phone, tablet, laptop, vehicle-mounted computer, general-purpose computer, wearable device or other terminal device running the first execution environment and the second execution environment, without limitation. For another example, the electronic device may be a cloud computing device, server or the like running the first execution environment and the second execution environment, without limitation.

[0081] For the sake of simplicity, the embodiments of the present application are described below using the example that the first execution environment is REE and the second execution environment is TEE.

[0082] refer to Figure 2 , Figure 2 A real-time environment schematic diagram of the method provided in the embodiment of the present application is shown. Figure 2 As shown, there are two execution environments running in the electronic device, namely REE and TEE. In the REE, at least one CA runs, for example Figure 2 CA 1 and CA 2 are shown. In TEE, there is at least one TA running that performs specific tasks for CA in REE, such as Figure 2 TA 1 and TA 2 are shown. The description of specific tasks can refer to the above and will not be repeated. It should be understood that when TA 1 and TA 2 in TEE need to execute IO requests, the IO request processing method provided in the embodiment of the present application can be used to complete the IO request processing.

[0083] In one example, TA 1 and / or TA 2 are trusted applications preset in TEE, so as to be called when the CA in REE needs to perform a specific task (such as a data encryption service with a high security level requirement).

[0084] In another example, TA1 and / or TA 2 are modules with high security level requirements installed in TEE in an application (APP) when the electronic device installs the application. It should be understood that modules in the APP that do not require a high security level are installed in the REE of the electronic device. For example, for an electronic mall APP, the module for implementing product retrieval and browsing in the electronic mall APP is installed in the REE of the electronic device, and the module for implementing user account login and product payment in the electronic mall APP is installed in the TEE of the electronic device.

[0085] In another example, TA1 and / or TA 2 are TAs created by the CA in the electronic device REE to perform specific tasks (such as fingerprint recognition, password processing, data encryption and decryption, security authentication, etc. with high security requirements) when the CA in the electronic device REE needs to perform the specific tasks. For example, for an e-commerce APP, when the e-commerce CA running on the electronic device REE responds to the user's operation and needs to log in to the user account, the e-commerce CA can instruct the TEE of the electronic device to create a TA for identity security authentication.

[0086] It should be understood that the above content is an illustrative description of the implementation environment of the method provided in the embodiment of the present application, and does not constitute a limitation on the implementation environment of the method. A person of ordinary skill in the art can know that as business needs change, the implementation environment can be adjusted according to application requirements, and the embodiments of the present application do not list them one by one.

[0087] The embodiment of the present application also provides a device for processing IO requests, which is applied to any electronic device running REE and TEE, and the device is used to execute the method for processing IO requests provided in the embodiment of the present application. Optionally, the device can be any electronic device running REE and TEE, or a functional module of an electronic device running REE and TEE, without limitation. The description of the electronic device can refer to the above description and will not be repeated.

[0088] refer to Figure 3 , Figure 3 A schematic diagram of a software framework of an electronic device provided in an embodiment of the present application is shown.

[0089] like Figure 3 As shown, in the REE OS of the electronic device, a resident scheduling thread is included. For any TA running in the TEE OS of the electronic device, such as the first application, in the process of the first application executing a specific task of any CA in the REE, when the first application needs to execute an IO request, the first application sends a communication request carrying the identifier (identifier, ID) of the first application to the scheduling thread in the REE OS. For example, the first application calls the command word in the notification data (notify data) through the TEE OS to send a communication request to the scheduling thread of the first application. Among them, the ID of the first application can be the process ID of the process used to implement the first application, or the thread ID of the thread used to implement the first application, but is not limited to this.

[0090] After the scheduling thread in the REE OS receives the communication request, in response, the scheduling thread creates a first working thread pool including a preset number of working threads for the first application in the REE, applies for a section of memory of the electronic device (recorded as the first memory), and creates a first task queue and a first result queue on the first memory. Among them, the first task queue is used to store the IO request of the first application. The working threads in the first working thread pool are used to process the IO requests in the first task queue, and write the obtained request results into the first result queue. That is, the first result queue is used to store the request results of the IO requests in the first task queue. Among them, the embodiment of the present application does not specifically limit the value of the aforementioned preset number, and does not specifically limit the specific structure of the first task queue and / or the first result queue. For example, the first task queue and / or the first result queue can be a linear queue, a circular queue, etc., and are not limited thereto. In addition, when creating the first task queue and the first result queue on the first memory, the embodiment of the present application does not limit the specific proportion of the storage space corresponding to the first task queue and the storage space corresponding to the first result queue divided in the first memory. For example, when the scheduling thread creates the first task queue and the first result queue in the first memory, half of the storage space of the first memory is used as the storage space corresponding to the first task queue, and the other half of the storage space of the first memory is used as the storage space of the first result queue, but is not limited thereto.

[0091] Then, the scheduling thread sends the address of the first memory with the first task queue and the first task queue created to each working thread and the first application in the first working thread pool. In response, the working threads and the first application in the first working thread pool receive the address of the first memory. In this way, the first memory with the first task queue and the first result queue created can be used as the SHM for the first working thread pool and the first application to communicate, and is recorded as the first SHM. In this way, the address of the first memory with the first task queue and the first result queue created is the address of the first SHM. As an example, the scheduling thread can send the address of the first memory to each thread in the first working thread pool by calling the POSIX thread standard library (posix threads, pthread) function. Wherein, POSIX refers to the portable operating system interface (portable operating system interface). As another example, the scheduling thread can send the address of the first memory to the first application based on the ID of the first application and call the command word in the notify data through REE OS.

[0092] In some embodiments, the scheduling thread in the REE OS also creates a corresponding first detection thread (corresponding to the detection thread in the present application) for the first SHM in the REE, and the first detection thread is used to detect the state of the first task queue and the state of the first result queue in the first SHM. For example, the first detection thread is used to detect whether the first task queue in the first SHM is empty, and to detect whether the first result queue in the first SHM is not full. In some examples, the first detection thread includes a first thread and a second thread, wherein the first thread is used to detect whether the first task queue in the first SHM is empty, and the second thread is used to detect whether the first result queue in the first SHM is not full. Among them, the detailed description of the first detection thread detecting the state of the first task queue and the state of the first result queue can refer to the description in the method below and will not be repeated.

[0093] In other embodiments, after the first application sends a communication request carrying the ID of the first application to the scheduling thread in the REE OS, it also creates a second detection thread in the TEE. And after receiving the address of the first SHM (i.e., the first memory), the first application sends the address of the first SHM to the second detection thread. In response, the second detection thread receives the address of the first SHM. Furthermore, the second detection thread can be used to detect the state of the first task queue and the state of the first result queue in the first SHM. For example, the second detection thread is used to detect whether the first task queue in the first SHM is not full, and to detect whether the first result queue in the first SHM is not empty. In some examples, the second detection thread includes a third thread and a fourth thread, wherein the third thread is used to detect whether the first task queue in the first SHM is not full, and the fourth thread is used to detect whether the first result queue in the first SHM is not empty. Among them, the detailed description of the second detection thread detecting the state of the first task queue and the state of the first result queue can refer to the description in the method below and will not be repeated.

[0094] Through the above process, it is possible to associate the first application and the second detection thread in the TEE, and the first working thread pool and the first detection thread in the REE through the first SHM. In this way, there is a corresponding relationship between the first application and the second detection thread in the TEE, and the first working thread pool and the first detection thread in the REE, which are associated through the first SHM.

[0095] In an embodiment of the present application, the SHM, the TA and detection thread in the TEE associated with the SHM, and the working thread pool and detection thread in the REE can be referred to as a cross-domain and cross-process trust (cross tasklet, xtasklet) framework. For example, the first SHM, the first application and the second detection thread in the TEE associated with the first SHM, and the first working thread pool and the first detection thread in the REE can be recorded as the first xtasklet framework. Applying the method provided by the embodiment of the present application in the first xtasklet framework can achieve the purpose of concurrently processing the IO requests of the first application in the TEE through the working threads in the first working thread pool in the REE, thereby improving the efficiency of processing the IO requests of the first application in the TEE. The specific process of implementing the method provided by the embodiment of the present application in the first xtasklet framework can refer to the method description below and will not be repeated.

[0096] Continue to refer Figure 3 Similarly, for any other TA running in the TEE OS of the electronic device, such as the second application, the embodiment of the present application can apply for a second SHM in the electronic device for the second application, create a second working thread pool and a third detection thread in the REE, and create a fourth detection thread in the TEE when the second application needs to execute an IO request, and associate the second application and the fourth detection thread in the TEE, and the second working thread pool and the third detection thread in the REE through the second SHM, thereby obtaining a second xtasklet framework. In this way, there is a corresponding relationship between the second application and the fourth detection thread in the TEE, and the second working thread pool and the third detection thread in the REE, which are associated through the second SHM. Among them, the second SHM includes a second task queue and a second result queue. The second task queue is used to store the IO requests of the second application. The second working thread pool includes a plurality of working threads, which are used to process the IO requests in the second task queue and write the obtained request results into the second result queue. That is, the second result queue is used to store the request results of the IO requests of the second application.

[0097] It should be understood that by applying the method provided by the embodiment of the present application in the second xtasklet framework, it is possible to achieve the purpose of concurrently processing the IO requests of the second application in the TEE through the worker threads in the second worker thread pool in the REE, thereby improving the efficiency of processing the IO requests of the second application in the TEE. And it can be seen that the embodiment of the present application can create corresponding xtasklet frameworks for different TAs in the TEE, and by applying the method provided by the embodiment of the present application in the xtasklet framework corresponding to each TA, the efficiency of each TA in processing its own IO requests can be improved. In other words, the embodiment of the present application supports concurrent processing of the IO requests of each TA in the TEE in the REE, so that the method provided by the embodiment of the present application improves the processing efficiency of the IO requests of the TA in the TEE through the REE.

[0098] It should also be understood that the detailed instructions for creating the second working thread pool and the second working thread pool can refer to the relevant description of the first working thread pool above, the detailed instructions for creating the third detection thread and the third detection thread can refer to the relevant description of the first detection thread above, the detailed instructions for creating the fourth detection thread and the fourth detection thread can refer to the relevant description of the second detection thread above, and the detailed instructions for applying for the second SHM and associating the second application and the fourth detection thread in the TEE, and the second working thread pool and the third detection thread in the REE through the second SHM can refer to the above description of applying for the first SHM and associating the first application and the second detection thread in the TEE, and the first working thread pool and the first detection thread in the REE through the first SHM, and no further details will be given.

[0099] refer to Figure 4 , Figure 4 Another software framework schematic diagram of the electronic device provided in the embodiment of the present application is shown. Figure 3 ,like Figure 4 As shown, when the IO request of the first application includes a disk IO request, the first task queue described above is used to store the disk IO request of the first application. The worker threads in the first worker thread pool are used to process the disk IO request in the first task queue and write the obtained request results into the first result queue. That is, the first result queue is used to store the request results of the disk IO request of the first application.

[0100] like Figure 4As shown, when the IO request of the first application also includes a network IO request, a third SHM can be applied for the first application in the electronic device, a third working thread pool and a fifth detection thread can be created in the REE, and a sixth detection thread can be created in the TEE, and the first application and the sixth detection thread in the TEE, and the third working thread pool and the fifth detection thread in the REE can be associated through the third SHM, thereby obtaining a third xtasklet framework. In this way, the first application and the sixth detection thread in the TEE, and the third working thread pool and the fifth detection thread bracket in the REE, which are associated through the third SHM, have a corresponding relationship. Among them, the third SHM includes a third task queue and a third result queue. The third task queue is used to store the network IO request of the first application. The third working thread pool includes multiple working threads, which are used to process the network IO request in the third task queue, and write the obtained request results into the third result queue. That is, the third result queue is used to store the request results of the network IO request of the first application.

[0101] It should be understood that the application of the method provided by the embodiment of the present application in the third xtasklet framework can improve the efficiency of processing the network IO request of the first application. It should also be understood that the creation of the third working thread pool and the detailed description of the third working thread pool can refer to the relevant description of the first working thread pool above, the creation of the fifth detection thread and the fifth detection thread can refer to the relevant description of the first detection thread above, the creation of the sixth detection thread and the sixth detection thread can refer to the relevant description of the second detection thread above, and the application of the third SHM and the association of the first application and the sixth detection thread in the TEE through the third SHM, and the third working thread pool and the fifth detection thread in the REE can refer to the above application of the first SHM and the association of the first application and the second detection thread in the TEE through the first SHM, and the first working thread pool and the first detection thread in the REE. The description is not repeated here.

[0102] It should also be understood that Figure 3 For the second application shown in FIG. 1 , when the IO request of the second application includes a disk IO request and a network IO request, then similarly Figure 4 As described above, the embodiment of the present application can create two xtasklet frameworks for the second application. The two xtasklet frameworks include Figure 3 The second xtasklet frame and another xtasklet frame (recorded as the fourth xtasklet frame).

[0103] Among them, the second task queue in the second xtasklet framework is used to store the disk IO requests of the second application. The working threads in the second working thread pool in the second xtasklet framework are used to process the disk IO requests in the second task queue, and write the obtained request results into the second result queue. That is, the second result queue in the second xtasklet framework is used to store the request results of the disk IO requests of the second application. In this way, applying the method provided in the embodiment of the present application in the second xtasklet framework can improve the efficiency of processing the disk IO requests of the second application in the TEE through REE.

[0104] The fourth xtasklet framework includes a fourth SHM and a fourth work thread pool in the REE. Among them, the fourth SHM includes a fourth task queue and a fourth result queue, and the fourth task queue is used to store the network IO requests of the second application. The fourth work thread pool includes multiple work threads, and the multiple work threads are used to process the network IO requests in the fourth task queue, and write the obtained request results into the fourth result queue. That is, the fourth result queue is used to store the request results of the network IO requests of the second application. In this way, applying the method provided in the embodiment of the present application in the fourth xtasklet framework can improve the efficiency of processing the network IO requests of the second application in the TEE through the REE.

[0105] It can be understood that by establishing xtasklet frameworks for different types of IO requests of each TA in the TEE, the processing efficiency of processing different types of IO requests of the TA in the TEE through REE can be achieved.

[0106] refer to Figure 5 , Figure 5 Another software framework diagram of the electronic device provided in the embodiment of the present application is shown. Figure 3 and / or Figure 4 ,when Figure 3 and / or Figure 4 The first application shown creates sub-applications according to business needs when processing business, such as Figure 5 The first sub-application shown. Figure 5As shown, in the embodiment of the present application, when the first sub-application needs to execute an IO request during the process of processing the business, the fifth SHM can be applied for the first sub-application in the electronic device, the fifth working thread pool and the seventh detection thread can be created in the REE, and the eighth detection thread can be created in the TEE, and the first sub-application and the eighth detection thread in the TEE, and the fifth working thread pool and the seventh detection thread in the REE can be associated through the fourth SHM, thereby obtaining the fifth xtasklet framework. In this way, there is a corresponding relationship between the first sub-application and the eighth detection thread in the TEE, and the fifth working thread pool and the seventh detection thread in the REE, which are associated through the fourth SHM. Among them, the fifth SHM includes a fifth task queue and a fifth result queue. The fifth task queue is used to store the IO request of the first sub-application. The fifth working thread pool includes multiple working threads, which are used to process the IO request in the fifth task queue and write the obtained request results into the fifth result queue. That is, the fifth result queue is used to store the request results of the IO request of the first sub-application.

[0107] It should be understood that the application of the method provided by the embodiment of the present application in the fifth xtasklet framework can improve the efficiency of processing the IO request of the first sub-application of the first application in the TEE through the REE. It should also be understood that the creation of the fifth working thread pool and the detailed description of the fifth working thread pool can refer to the relevant description of the first working thread pool above, the creation of the seventh detection thread and the seventh detection thread can refer to the relevant description of the first detection thread above, the creation of the eighth detection thread and the eighth detection thread can refer to the relevant description of the second detection thread above, and the application of the fifth SHM and the association of the first sub-application and the eighth detection thread in the TEE through the fifth SHM, as well as the fifth working thread pool and the seventh detection thread in the REE, can refer to the above application of the first SHM and the association of the first application and the second detection thread in the TEE through the first SHM, the first working thread pool and the first detection thread in the REE, and will not be repeated.

[0108] It can be understood that through the software framework provided in the embodiment of the present application, the above-mentioned xtasklet framework can be established for each sub-application of any TA in the TEE of the electronic device, so that the IO requests of each sub-application of any TA in the TEE can be processed concurrently in the REE, thereby improving the processing efficiency of the IO requests of each sub-application.

[0109] It should also be understood that after the TA in the TEE has completed a specific task for the CA in the REE, the electronic device can delete or destroy the xtasklet framework created for the TA. Figure 3 , Figure 4 or Figure 5Taking the first application in as an example, after the first application in TEE completes the specific task for the CA in REE, it deletes the detection thread used to detect the task queue status and result queue status corresponding to the first application, and automatically exits or destroys. When TEE OS detects that the first application exits / is destroyed, it sends a destruction instruction carrying the first application ID to the scheduling thread in REE (such as TEE OS sends a destruction instruction to the scheduling thread in REE by calling the command word in notify data) to instruct the scheduling thread in REE to destroy / delete the detection thread and work thread pool created for the first application, and release the SHM applied for the first application. In response, after receiving the destruction instruction carrying the first application ID, the scheduling thread in REE responds to the destruction instruction, deletes or destroys the detection thread and work thread pool created for the first application, and releases the SHM applied for the first application. In this way, the corresponding resources of the electronic device can be released in time after the first application completes the specific task.

[0110] It should be understood that the above content is an exemplary description of the software framework of the method provided in the embodiment of the present application, and does not constitute a limitation on the software framework of the method. A person of ordinary skill in the art will know that as business needs change, the software framework can be adjusted according to application requirements, and the embodiments of the present application do not list them one by one.

[0111] The implementation process of the method provided in the embodiment of the present application is described below.

[0112] refer to Figure 6 , Figure 6 A schematic diagram of a process flow of an IO request processing method provided in an embodiment of the present application is shown, and the method can be applied to Figure 3 , Figure 4 or Figure 5 In the software framework shown.

[0113] For the sake of simplicity, the following TA is used to perform specific tasks for the CA in the electronic device REE. Figure 3 , Figure 4 or Figure 5 The method provided in the embodiment of the present application is described by taking the first application in the TEE as an example, and the electronic device has established the first xtasklet framework for the first application as described above. Figure 6 As shown, the method includes the following steps.

[0114] Step 101: A first application writes an IO request to a first task queue.

[0115] When the first application in the TEE of the electronic device executes a specific task (refer to the above description) for the CA in the REE, when an IO request needs to be executed, the first application writes the IO request to be executed to the first task queue. The first application communicates with the REE of the electronic device through the first task queue and the first result queue in the first SHM, and the first task queue is used to store the IO request of the first application, and the first result queue is used to store the request result of the IO request in the first task queue.

[0116] Optional, combined Figure 4 When the IO request of the first application includes a disk IO request, the first application writes the disk IO request to the first task queue. When the IO request of the first application also includes a network IO request, the first application writes the network IO request to the third task queue.

[0117] Taking any IO request that the first application needs to execute as a disk IO request (recorded as the first IO request) as an example, in one case, during the process of the first application writing the first IO request to the first task queue, when the first task queue is not full and the storage space size corresponding to the empty element in the first task queue is larger than the size of the first IO request, the first application normally writes the first IO request to the first task queue. It is understandable that the first task queue includes multiple elements, each of which may correspond to storage spaces of the same size or different sizes, which is not described in detail in the embodiments of the present application.

[0118] In another case, during the process of the first application writing the first IO request to the first task queue, when the first task queue is full, after the first application executes the operation of writing the first IO request to the first task queue, the first task queue returns to the first application the status information indicating that the first task queue is full. In a possible implementation, the first application responds to the status information indicating that the first task queue is full, and re-executes the operation of writing the first IO request to the first task queue after a preset time length. The embodiment of the present application does not specifically limit the value of the preset time length. In another possible implementation, the first application responds to the status information indicating that the first task queue is full, and sends a first indication to the second detection thread to indicate whether the second detection thread continuously or periodically detects whether the first task queue is not full. Optionally, the first indication includes the size of the IO request that the first application needs to write to the first task queue. Furthermore, when the second detection thread detects that the first task queue is not full and the storage space corresponding to the empty element in the first task queue is greater than the size of the IO request that the first application needs to write to the first task queue, it sends a second indication to the first application to indicate that the first application continues to write IO requests to the first task queue. Here, the IO requests that the first application needs to write into the first task queue include but are not limited to the first IO requests. It should be understood that, by having the second detection thread detect whether the first task queue is not full when the first task queue is full, and notifying the first application to continue writing IO requests into the first task queue when it is detected that the first task queue is not full, the process / thread in the first application used to execute the writing of IO requests into the first task queue can process other tasks in the process of the second detection detecting whether the first task queue is not full, without suspending and waiting, which can improve the working efficiency of the process / thread in the first application.

[0119] Exemplary, the second detection thread can detect whether the first task queue is not full according to the position of the head pointer and the tail pointer in the first task queue. For example, when the first task queue is a linear queue, if the difference between the head pointer and the tail pointer of the first task queue is equal to the maximum length of the first task queue, it means that the first task queue is full. If the difference between the head pointer and the tail pointer of the first task queue is less than the maximum length of the first task queue, it means that the first task queue is not full, and the element between the maximum length and the tail pointer in the first task queue is the element that is empty in the first task queue. For another example, when the first task queue is a circular queue, if the difference between the head pointer and the tail pointer of the first task queue is equal to the maximum length of the first task queue, it means that the first task queue is full. If the difference between the head pointer and the tail pointer of the first task queue is not equal to the maximum length of the first task queue, it means that the first task queue is not full, and the element between the head pointer and the tail pointer in the reverse direction of the first task queue is the element that is empty in the first task queue. The reverse direction of the first task queue refers to the reverse direction of the head pointer's advance direction during the process of writing data to the first task queue, or the reverse direction of the first task queue refers to the reverse direction of the tail pointer's advance direction during the process of consuming data in the first task queue. Furthermore, based on the size of the storage space corresponding to each empty element in the first task queue, the second detection thread can determine whether the size of the storage space corresponding to the empty element in the first task queue is greater than the size of the IO request that the first application needs to write to the first task queue, and then determine whether it is necessary to send a second instruction to the first application to instruct the first application to continue writing IO requests to the first task queue.

[0120] Step 102: The working threads in the first working thread pool respectively obtain IO requests from the first task queue.

[0121] On the REE side of the electronic device, based on the position pointed to by the head pointer of the first task queue, the working threads in the first working thread pool respectively read the IO requests from the first task queue to obtain the IO requests from the first task queue.

[0122] In one possible implementation, the worker threads in the first worker thread pool are configured to be in a ready state. In this case, when the first task queue is not empty, the worker threads in the first worker thread pool read IO requests from the first task queue normally. When the first task queue is empty, after the worker threads in the first worker thread pool execute the operation of reading IO requests from the first task queue, the first task queue returns status information indicating that the first task queue is empty to the worker threads that read the IO requests. In response to the status information, the worker threads that read the IO requests read the IO requests from the first task queue again after a preset duration. The embodiment of the present application does not specifically limit the value of the preset duration.

[0123] In another possible implementation, the worker threads in the first worker thread pool are configured to enter a dormant state when not obtaining IO requests from the first task queue and processing IO requests. That is, the worker threads in the first worker thread pool will enter a dormant state when idle, which can save the occupation of electronic device resources (such as CPU resources, memory resources, etc.). In this case, the scheduling thread in the electronic device REE starts the first detection thread after creating the first xtasklet framework. Then the first detection thread detects whether the first task queue is empty, and instructs the worker threads in the first worker thread pool to obtain IO requests from the first task queue based on the detection results. The detailed process refers to the description of steps 201 to 205 below, which will not be repeated here.

[0124] Step 103: For a first IO request obtained by a first working thread in the first working thread pool from the first task queue, the first working thread executes the first IO request to obtain a first request result.

[0125] Among them, the first working thread is any working thread in the first working thread pool corresponding to the first application that obtains the IO request, the first IO request is the IO request read by the first working thread, and the first request result is the request result obtained after the first working thread executes the first IO request.

[0126] Optionally, the first IO request may be executed by a working thread. In this case, the first working thread executes the first IO request after acquiring the first IO request.

[0127] As an example, when the first IO request is a disk IO request to write data to a disk (such as a hard disk) of an electronic device, the first worker thread performs an operation of writing data to the disk of the electronic device. In this case, the first request result can be a message of success or failure of data writing.

[0128] As another example, when the first IO request is a disk IO request to read data from a disk (such as a hard disk) of an electronic device, the first worker thread performs an operation of reading data from the disk of the electronic device. In this case, the first request result is the data read from the disk of the electronic device.

[0129] As another example, when the first IO request is a network IO request to send data to a remote device, the first working thread sends the data to be sent to the communication interface / network interface of the electronic device to send the data through the communication interface / network interface of the electronic device. In this case, the first request result can be a response message received by the communication interface / network interface of the electronic device after sending the data, or a message indicating that the communication interface / network interface of the electronic device successfully or failed to send the data, which is not limited to this.

[0130] Optionally, when the first IO request includes more IO subtasks, the first IO request may also be executed by multiple worker threads. In this case, when the first worker thread obtains the first IO request and executes the first IO request, it may call at least one idle worker thread in the first worker thread pool to execute the subtask of the first IO request, or create a new worker thread in the first worker thread pool to execute the subtask of the first IO request, so as to obtain the request result of the first IO request, which is not limited to this.

[0131] Step 104: The first working thread writes the first request result into the first result queue.

[0132] After obtaining the first request result, the first working thread writes the first request result to the first result queue.

[0133] Optional, combined Figure 4 When the first IO request is a disk IO request, the first worker thread writes the first request result to the first result queue for storing the request result of the disk IO request. When the first IO request is a network IO request, the first worker thread writes the first request result to the third result queue for storing the request result of the network IO request.

[0134] Taking the first working thread writing the first request result to the first result queue as an example, in one case, during the process of the first working thread writing the first request result to the first result queue, when the first result queue is not full and the storage space size corresponding to the empty element in the first result queue is larger than the size of the first request result, the first working thread writes the first result request to the first result queue normally. It should be understood that the first result queue includes multiple elements, each of which may correspond to storage spaces of the same size or different sizes, which is not described in detail in the embodiments of the present application.

[0135] In another case, during the process of the first working thread writing the first request result to the first result queue, when the first result queue is full, after the first working process executes the operation of writing the first request result to the first result queue, the first result queue returns to the first working thread the status information indicating that the first result queue is full. In a possible implementation, the first working thread responds to the status information indicating that the first result queue is full, and re-executes the operation of writing the first request result to the first result queue after a preset time length. The embodiment of the present application does not specifically limit the value of the preset time length. In another possible implementation, the first working thread responds to the status information indicating that the first result queue is full, and sends a third indication to the detection thread to indicate that the detection thread continuously or periodically detects whether the first result queue is not full. Optionally, the third indication includes the size of the first request result. Further, when the detection thread detects that the first result queue is not full and the storage space corresponding to the empty element in the first result queue is larger than the size of the first request result, the fourth indication is sent to the first working process to instruct the first working process to re-write the first request result to the first result queue. For a detailed description of how the detection thread detects whether the first result queue is not full, please refer to the description of how the second detection thread detects whether the first task queue is not full in step 101, which will not be repeated here.

[0136] It should be understood that when the first detection thread periodically detects whether the first task queue is empty in step 102, the detection thread used to periodically detect whether the first result queue is not full in step 104 may also be the first detection thread. In this case, the detection period for periodically detecting whether the first result queue is not full only needs to be staggered with the detection period for the first detection thread to detect the first task queue.

[0137] In some examples, the first detection thread may include a first thread and a second thread. Thus, the first thread may be used to detect whether the first task queue is empty at step 102, and the second thread may be used to detect whether the first result queue is not full at step 104.

[0138] Step 105: The first application obtains a first request result of the first IO request from the first result queue.

[0139] The process of the first application obtaining the first request result of the first IO request from the first result queue includes steps 1051 to 1053 .

[0140] Step 1051: The first application receives the first ID of the first IO request returned by the first task queue.

[0141] The ID of the IO request written into the first task queue is generated by the first task queue and returned to the first application. The ID of the IO request is used by the first application to determine the request result of the IO request from the request result obtained from the first result queue.

[0142] It is understandable that after the first application writes the first IO request to the first task queue in step 101, the first task queue generates a first ID for the first IO request and returns the first ID to the first application. In response, the first application receives the first ID returned by the first task queue. Therefore, the IO request written by the first application to the first task queue includes the request ID generated by the first task queue for the IO request.

[0143] Step 1052: The first application obtains the request result from the first result queue.

[0144] On the TEE side of the electronic device, the first application reads the request result from the first result queue based on the position pointed to by the head pointer in the first result queue, so as to achieve the purpose of obtaining the request result from the first result queue.

[0145] It should be understood that when the first application corresponds to multiple xtasklet frames, the first application reads the request result from each result queue according to the position pointed to by the head pointer of the result queue in each xtasklet frame. Figure 4 The first application corresponds to the first xtasklet frame and the third xtasklet frame, so the first application reads the request result from the first result queue according to the position pointed to by the head pointer of the first result queue in the first xtasklet frame, and the first application reads the request result from the third result queue according to the position pointed to by the head pointer of the third result queue in the third xtasklet frame.

[0146] For the sake of simplicity, the following description is given by taking the example of the first working thread obtaining the first request result from the first result queue.

[0147] In one case, when the first result queue is not empty, the first application reads the request result from the first result queue normally.

[0148] In another case, when the first result queue is empty, in a possible implementation, after the first application performs the operation of reading the request result from the first result queue, the first result queue returns to the first application status information indicating that the first result queue is empty. In response to the status information, the first application reads the request result from the first result queue again after a preset time length. The embodiment of the present application does not specifically limit the value of the preset time length. In another possible implementation, the first application sends a fifth indication to the detection process in response to the status information indicating that the first result queue is empty, to indicate that the detection thread continuously or periodically detects whether the first result queue is not empty. Furthermore, the detection continuously or periodically detects whether the first result queue is not empty, and when it is detected that the first result queue is not empty, a sixth indication is sent to the first application to indicate that the first application continues to read the request result from the first result queue. It should be understood that, by having the detection thread detect whether the first result queue is not empty when the first result queue is empty, and notifying the first application to continue reading the request results from the first result queue when it is detected that the first result queue is not empty, the process / thread in the first application used to execute the reading of the request results from the first result queue can handle other tasks while the detection thread is detecting whether the first result queue is not empty, without suspending and waiting, thereby improving the working efficiency of the process / thread in the first application.

[0149] As an example, the detection thread can detect whether the first result queue is not empty according to the positions of the head pointer and the tail pointer in the first result queue. For example, if the head pointer of the first result queue is not equal to the tail pointer, it means that the first result queue is not empty. If the head pointer of the first task queue is equal to the tail pointer, it means that the first result queue is empty.

[0150] It should be understood that when the second detection thread periodically detects whether the first task queue is not full in step 101, the detection thread used to periodically detect whether the first result queue is not empty in step 1052 may also be the second detection thread. In this case, the detection period for periodically detecting whether the first result queue is not empty only needs to be staggered with the detection period for the second detection thread to detect the first task queue.

[0151] In some examples, the second detection thread may include a third thread and a fourth thread. Thus, the third thread may be used to detect whether the first task queue is not full in step 101, and the fourth thread may be used to detect whether the first result queue is not empty in step 1052.

[0152] Step 1053: The first application determines the first request result from the request results obtained from the first result queue according to the first ID of the first IO request.

[0153] When the first IO request is written into the first task queue of the first xtasklet framework, the first application determines the first request result from the request results obtained from the first result queue in the first xtasklet framework according to the first ID.

[0154] Each request result in the first result queue includes the ID of the IO request that obtained each request result. It should be understood that in step 103, after the first working thread obtains any request result, it adds the ID of the IO request that obtained the request result to the request result, and writes the request result including the ID to the first result queue.

[0155] Furthermore, when the first application determines that a certain request result obtained from the first result queue includes the first ID, the first application determines that the request result is a request result of the first IO request, that is, the first request result.

[0156] Then, the first application may execute a subsequent process of the specific task executed by the first application according to the first request result, which is not described in detail in the embodiment of the present application.

[0157] So far, through the method described in steps 101 to 105, the purpose of processing the IO request of the TA in the TEE in the xtasklet framework created in the electronic device REE and TEE is achieved. In this way, when the TA needs to execute multiple IO requests, the working thread pool on the REE side in the xtasklet framework can process these IO requests in parallel, thereby improving the efficiency of processing the IO request of the TA on the TEE side through the RER.

[0158] In some embodiments, in order to save the occupation of electronic device resources (such as CPU resources, memory resources, etc.) by the REE side work thread pool in the xtasklet framework, Figure 6 ,refer to Figure 7 , after step 4, the above method further includes step 106.

[0159] Step 106: The first working thread sets its own state to a sleep state.

[0160] The first working process sets its own state to a dormant state, indicating that the first working process has entered a dormant state. As an example, the first working process can enter a dormant state by calling a sleep() function.

[0161] In a possible implementation, after writing the first request result into the first result queue, the first working thread immediately sets its own state to a dormant state.

[0162] In another possible implementation, after writing the first request result into the first result queue, the first working thread repeats steps 102 to 104 until the first task queue returns status information that the first task queue is empty to the first working process when the first working thread executes step 102, and then the first working thread immediately sets its own status to sleep status.

[0163] In this way, for idle working threads that have processed IO requests, the method of the embodiment of the present application puts these working threads into a dormant state, which can reduce the occupation of electronic device resources (such as CPU resources, memory resources, etc.) by the working threads.

[0164] The following describes the detailed process of "the first detection thread detects whether the first task queue is empty, and instructs the working thread in the first working thread pool to obtain the IO request from the first task queue according to the detection result". Figure 8 , Figure 8 A schematic diagram of a process in which a working thread obtains an IO request from a first task queue provided in an embodiment of the present application is shown, and the process includes the following steps.

[0165] Step 201: The first detection thread detects whether the first task queue is empty.

[0166] Optionally, the first detection thread can continuously or periodically detect whether the first task queue is empty after starting. For example, the first detection thread can periodically detect whether the first task queue is empty with 100 milliseconds as the cycle duration after starting. During the process of the first detection thread periodically detecting whether the first task queue is empty, the first detection thread can be in a dormant state during the interval of detecting whether the first task queue is empty in two adjacent cycles, which can save the occupation of electronic equipment resources (such as CPU resources, memory resources, etc.).

[0167] Among them, the detailed description of the first detection thread detecting whether the first task queue is empty can refer to the description of the detection thread detecting whether the first result queue is not empty in step 1052, which will not be repeated here.

[0168] When the first detection thread detects that the first task queue is empty, the first detection thread repeatedly continues to execute step 201. Optionally, when the first detection thread detects that the first task queue is empty, the first detection thread further executes step 205.

[0169] When the first detection thread detects that the first task queue is not empty, the first detection thread executes steps 202 to 204 .

[0170] Step 202: When the first detection thread detects that the first task queue is not empty, it determines whether there is a dormant worker thread in the first worker thread pool.

[0171] When the first detection thread detects that the first task queue is not empty, it indicates that there are IO requests to be processed in the first task queue.

[0172] From step 106, it can be known that the worker threads in the first worker thread pool will enter a dormant state after processing the IO request or when the IO request cannot be obtained from the first task queue, that is, the worker threads in the first worker thread pool are configured to be in a dormant state when the IO request is not obtained from the first task queue and the IO request is not processed. Therefore, the first worker thread pool includes worker threads in two states: worker threads in a dormant state and worker threads that are processing IO requests. In this case, after determining that there are pending IO requests in the first task queue, the first detection thread also needs to determine whether there are worker threads in a dormant state in the first worker thread pool.

[0173] Specifically, the first detection thread may query the status information of each worker thread in the first worker thread pool to determine whether there is a worker thread in a dormant state in the first worker thread pool.

[0174] For example, for the first worker thread in the first worker thread pool, the first detection thread queries that the element value for indicating the ready state in the state information of the first worker thread is 1, and then determines that the state of the first worker thread is the ready state.

[0175] For another example, for the second worker thread in the first worker thread pool, the first detection thread queries that the element value for indicating the sleep state in the state information of the second worker thread is 1, and then determines that the state of the second worker thread is the sleep state.

[0176] When the first detection thread determines that there is a worker thread in a dormant state in the first worker thread pool, the first detection thread executes step 203 .

[0177] When the first detection thread determines that there is no worker thread in the first worker thread pool in the dormant state, the first detection thread executes step 204 .

[0178] Step 203: When it is determined that there is a dormant thread in the first work thread pool, the first detection thread sends a wake-up instruction to the dormant work thread in the first work thread pool to instruct the dormant work thread in the first work thread pool to switch the state from the dormant state to the ready state.

[0179] As an example, the first detection thread may send a wake-up instruction to a worker thread in a dormant state in the first worker thread pool through a pthread function to instruct the worker thread in a dormant state in the first worker thread pool to switch the state from the dormant state to the ready state.

[0180] In response, the worker thread in the first worker thread pool in a dormant state receives the wake-up instruction sent by the first detection thread, and in response to the wake-up instruction, switches its own state from the dormant state to the ready state. Then, the worker thread whose state is switched to the ready state executes the above steps 102 to 104 and step 106.

[0181] Exemplarily, for the first worker thread in the first worker thread pool that is in a dormant state, the first worker thread receives a wake-up instruction sent by the first detection thread, and in response to the wake-up instruction, switches its own state from the dormant state to the ready state. Then, the first worker thread executes the above steps 102 to 104 and step 106.

[0182] Step 204: When it is determined that there is no thread in the dormant state in the first working thread pool, the first detection thread creates a first preset number of working threads in the first working thread pool.

[0183] The first detection thread determines that there are no threads in a dormant state in the first work pool, indicating that all work threads in the current first work thread pool are executing operations to process IO requests. In this case, in order to improve the processing efficiency of the IO requests of the first application in the first task queue, the first detection thread creates a first preset number of work threads in the first work thread pool. Then, the work thread newly created by the first detection thread executes the above-mentioned steps 102 to 104 and step 106. For example, when the first work thread described above is one of the work threads newly created by the first detection thread, after the first work thread is created, the above-mentioned steps 102 to 104 and step 106 are executed.

[0184] As an example, assuming that the first work thread pool originally includes X work threads, X is a positive integer, then when the first detection thread determines that there is no thread in the first work pool that is in a dormant state, it means that at this time, the X work threads in the first work thread pool are all executing operations to process IO requests in the first task queue. In this case, the first detection thread creates Z work threads in the first work thread pool, where Z is a positive integer. In this case, the first work thread pool includes X+Z=Y work threads, and the Y work threads can all be used to execute the above steps 102 to 104 and step 106 to improve the processing efficiency of IO requests.

[0185] Step 205: When the first detection thread detects that the first task queue is empty, a second preset number of working threads in the first working thread pool is destroyed.

[0186] When the first detection thread detects that the first task queue is empty, or when the first detection thread detects that the first task queue is empty in a preset number of consecutive detection cycles, it indicates that the first application has no recent IO request to write into the first task queue. Here, the embodiment of the present application does not specifically limit the preset number.

[0187] In this case, the first detection thread destroys the second preset number of working threads in the first working thread pool to release resources of the electronic device (such as CPU resources, memory resources, etc.). The embodiment of the present application does not specifically limit the value of the second preset number, and the second preset number only needs to be less than the number of working threads currently included in the first working thread pool.

[0188] Through steps 201 to 205, the embodiment of the present application can timely destroy the redundant working threads in the first working thread pool when there is no IO request in the first task queue, and can wake up the working threads in the first working thread pool in a dormant state to process the IO request in the first task queue when the first detection thread detects that there is an IO request in the first task queue. Through this method, the occupation of resources (such as CPU resources, memory resources, etc.) in the electronic device by working threads can be effectively reduced.

[0189] In some other embodiments, since the frequency of the first application writing IO requests to the first task queue varies over time, in order to save the occupation of electronic equipment resources by the first detection thread, the first detection thread can adjust the cycle length of detecting whether the first task queue is empty according to the frequency of the first application writing IO requests to the first task queue during the periodic detection of whether the first task queue is empty. For example, the first detection thread detects the frequency of the first application writing IO requests to the first task queue, obtains the detection result, and adjusts the cycle length of its own detection of the first task queue according to the detection result.

[0190] Optionally, in any detection cycle of periodically detecting whether the first task queue is empty, the first detection thread can detect whether the first task queue is empty by a third preset number of consecutive times, and obtain a third preset number of detection results, which can be used to characterize the frequency of the first application writing IO requests to the first task queue. Then, the first detection thread adjusts the cycle duration of its own detection of the first task queue according to the third preset number of detection results. It should be understood that the present application does not specifically limit the value of the third preset number (for example, the third preset number is 1000), but the time required for the first detection thread to detect whether the first task queue is empty for the third preset number of consecutive times is much less than the duration of a detection cycle in which the first detection thread detects whether the first task queue is empty.

[0191] In one example, when the number of detection results indicating that the first task queue is not empty in the third preset number of detection results exceeds the first threshold, it indicates that the frequency of the first application writing IO requests to the first task queue is high, so the first detection thread shortens its own cycle duration for detecting whether the first task queue is empty, for example, the first detection thread shortens its own cycle duration for detecting whether the first task queue is empty with a first preset step length. Among them, the embodiment of the present application does not specifically limit the value of the first threshold. For example, the first threshold can be a natural number less than the third preset number, or the first threshold is a preset percentage of the third preset number, such as the first threshold is 5% of the third preset number, etc., but is not limited to this. In addition, the embodiment of the present application does not specifically limit the value of the first preset step length, for example, the first preset step length is 1 millisecond, 2 milliseconds, 10 milliseconds, etc., but is not limited to this.

[0192] In another example, when the number of detection results indicating that the first task queue is empty in the third preset number of detection results exceeds the second threshold, the first detection thread increases the cycle duration of its own detection of whether the first task queue is empty, for example, the first detection thread increases the cycle duration of its own detection of whether the first task queue is empty with the second preset step length. Among them, the embodiment of the present application does not specifically limit the value of the second threshold. For example, the second threshold can be a natural number less than the third preset number, or the second threshold is a preset percentage of the third preset number, such as the second threshold is 98% of the third preset number, etc., but is not limited to this. In addition, the embodiment of the present application does not specifically limit the value of the second preset step length, for example, the second preset step length is 1 millisecond, 2 milliseconds, 10 milliseconds, etc., but is not limited to this.

[0193] It should be understood that the first preset step size and the second preset step size may be the same or different, and the embodiment of the present application does not limit this.

[0194] It should also be understood that, in order to ensure the detection of the first task queue by the first detection thread, when the first detection thread adjusts the duration of the detection cycle of itself detecting whether the first task queue is empty according to the frequency of writing IO requests to the first task queue, the first detection thread is set with a maximum cycle duration (such as 100 milliseconds). When the detection cycle duration adjusted by the first detection thread is equal to the maximum cycle duration, the adjustment of the duration of the detection cycle of the first detection thread detecting whether the first task queue is empty is stopped.

[0195] In this way, by adjusting the cycle duration of the first detection thread detecting whether the first task queue is empty according to the frequency of writing IO requests to the first task queue, it is possible to achieve that when the frequency of writing IO requests to the first task queue is high, the cycle duration of the first detection thread detecting whether the first task queue is empty is shortened, that is, the detection frequency of the first detection thread detecting whether the first task queue is empty is improved. And, by adjusting the cycle duration of the first detection thread detecting whether the first task queue is empty according to the frequency of writing IO requests to the first task queue, it is possible to achieve that when the frequency of writing IO requests to the first task queue is low, the cycle duration of the first detection thread detecting whether the first task queue is empty is increased, that is, the detection frequency of the first detection thread detecting whether the first task queue is empty is reduced. In this way, it is possible to effectively save the occupation of electronic equipment resources by the first detection thread on the basis of ensuring the efficiency of processing IO requests in the first task queue.

[0196] It should be noted that the sequence of steps of the method provided in the embodiment of the present application can be adjusted appropriately, and the steps can be increased or decreased accordingly according to the situation. Any person skilled in the art who is familiar with the technical field can easily think of a method of variation within the technical scope disclosed in the present application, which should be included in the protection scope of the present application, so it will not be repeated.

[0197] The above mainly introduces the solution provided in the embodiment of the present application from the perspective of method.

[0198] In order to achieve the above functions, Fig. 9 As shown, Fig. 9 A schematic diagram of the structure of an IO request processing device 900 provided in an embodiment of the present application is shown. The processing device 900 is applied to an electronic device, wherein a first execution environment of the electronic device includes a first working thread pool, and the first working thread pool communicates with a first application running in a second execution environment of the electronic device through a first task queue and a first result queue, wherein the first task queue is used to store IO requests of the first application, and the first result queue is used to store request results of the IO requests, and the first working thread pool includes a plurality of working threads for processing IO requests in the first task queue. The processing device 900 is used to execute the above-mentioned IO request processing method, for example, for executing Figure 6 , Figure 7 or Figure 8 The part of the method shown is executed in the first execution environment of the electronic device. The processing device 900 may include an acquisition unit 901, an execution unit 902 and a writing unit 903.

[0199] The acquisition unit 901 is used to obtain IO requests from the first task queue respectively through the worker threads in the first worker thread pool. For the first IO request obtained by the first worker thread from the first task queue, the execution unit 902 is used to execute the first IO request through the first worker thread to obtain the first request result. The first worker thread is any worker thread in the first worker thread pool that obtains the IO request. The writing unit 9003 is used to write the first request result into the first result queue through the first worker thread.

[0200] As an example, combining Figure 6 or Figure 7 , the acquisition unit 901 can be used to execute step 102, the execution unit 902 can be used to execute step 103, and the writing unit 903 can be used to execute step 104.

[0201] Optionally, the first execution environment of the electronic device also includes a second work thread pool, and the second work thread pool communicates with the second application in the second execution environment through a second task queue and a second result queue. The second task queue is used to store the IO requests of the second application, and the second result queue is used to store the request results of the IO requests of the second task queue. The second work thread pool includes multiple work threads, and the work threads in the second work thread pool are used to process the IO requests in the second task queue and write the obtained results into the second result queue.

[0202] Optionally, the first execution environment of the electronic device also includes a detection thread corresponding to the first work thread pool. In this case, before the acquisition unit 901 obtains IO requests from the first task queue respectively through the work threads in the first work thread pool, the processing device 900 also includes: a receiving unit 904, which is used to receive the wake-up instruction sent by the detection thread through the work thread in the first work thread pool that is in a dormant state. A switching unit 905 is used to respond to the wake-up instruction and switch the work thread in the first work thread pool that is in a dormant state from the dormant state to the ready state. Among them, the detection thread is used to detect whether the first task queue is empty, and to determine whether there is a dormant work thread in the first work thread pool when it is detected that the first task queue is not empty, and to send a wake-up instruction to the dormant work thread in the first work thread pool when it is determined that there is a dormant work thread in the first work thread pool. The acquisition unit 901 is specifically used to obtain IO requests from the first task queue respectively through the work threads in the first work thread pool whose state is switched from the dormant state to the ready state.

[0203] As an example, combining Figure 8 , the receiving unit 904 and the switching unit 905 can be used to respond to step 203.

[0204] Optionally, when there is no dormant worker thread in the first worker thread pool, the detection thread is further used to create a first preset number of worker threads in the first worker thread pool. The acquisition unit 901 is specifically used to acquire IO requests from the first task queue respectively through the newly created worker threads in the first worker thread pool.

[0205] Optionally, when the above-mentioned detection thread is used to periodically detect whether the first task queue is empty, the detection thread is also used to detect the frequency of writing IO requests to the first task queue in each cycle to obtain the detection result of each cycle, and the detection result is used to adjust the cycle duration of the detection thread to detect whether the first task queue is empty.

[0206] Optionally, the detection thread is further used to destroy a second preset number of dormant worker threads in the first worker thread pool when it is detected that the first task queue is empty.

[0207] Optionally, after the writing unit 903 writes the first request result to the first result queue through the first working thread, or after the writing unit 903 writes the first request result to the first result queue through the first working thread, and when the acquiring unit 901 again executes to acquire the IO request from the first task queue through the first working thread, when the first working thread receives status information indicating that the queue is empty returned by the first task queue, the switching unit 905 is also used to set the status of the first working thread to a sleep state through the first working thread.

[0208] As an example, combining Figure 7 , the switching unit 905 can be used to execute step 106.

[0209] Optionally, the IO request of the first application includes a disk IO request. In this case, the first task queue is used to store the disk IO request of the first application.

[0210] Optionally, the IO request of the first application also includes a network IO request. In this case, the first execution environment of the electronic device also includes a third work thread pool. The third work thread pool communicates with the first application through a third task queue and a third result queue, the third task queue is used to store the network IO request of the first application, the third result queue is used to store the request results of the network IO request in the third task queue, the third work thread pool includes a plurality of work threads, and the work threads in the third work thread pool are used to process the network IO request in the third task queue, and are used to write the obtained request results into the third result queue.

[0211] Optionally, the security level of the first execution environment in the electronic device is different from the security level of the second execution environment.

[0212] Optionally, the first execution environment of the electronic device is REE, and the second execution environment is TEE.

[0213] For the detailed description of the above optional methods, please refer to the above method embodiments, which will not be repeated here. In addition, the explanation of any of the processing devices 900 provided above and the description of the beneficial effects can refer to the above corresponding method embodiments, which will not be repeated here.

[0214] As an example, in combination with the following Fig.12 The functions implemented by the acquisition unit 901, the execution unit 902, the writing unit 903 and the switching unit 905 in the processing device 900 can be realized by Fig.12 Processor 1201 in the Fig.12 The functions implemented by the receiving unit 904 can be implemented by the program code in the memory 1202 in the receiving unit 904. Fig.12 The internal interface implementation in the communication interface 1203 is shown.

[0215] like Fig.10 As shown, Fig.10 The schematic diagram of the structure of another IO request processing device 1000 provided in an embodiment of the present application is shown. The processing device 1000 is applied to an electronic device, and a first application is running in a second execution environment of the electronic device. The first application communicates with the first execution environment of the electronic device through a first task queue and a first result queue. The first task queue is used to store the IO requests of the first application, and the first result queue is used to store the request results of the IO requests in the first task queue. The processing device 1000 is used to execute the above-mentioned IO request processing method, for example, to execute Figure 6 , Figure 7 or Figure 8 The part of the method shown is executed in the second execution environment of the electronic device. The processing device 1000 may include a writing unit 1001 and an acquiring unit 1002.

[0216] The writing unit 1001 is used to write a first IO request to the first task queue through the first application, and the first IO request is any IO request written by the first application to the first task queue. The obtaining unit 1002 is used to obtain a first request result of the first IO request from the first result queue through the first application, and the first request result is a request result obtained after a worker thread in a worker thread pool corresponding to the first application in the first execution environment processes the first IO request.

[0217] As an example, combining Figure 6 or Figure 7 , the writing unit 1001 can be used to execute step 101, and the acquiring unit 1002 can be used to execute step 105.

[0218] Optionally, a second application is also running in the second execution environment of the electronic device. The second application communicates with the first execution environment through a second task queue and a second result queue, the second task queue is used to store IO requests of the second application, and the second result queue is used to store request results of the IO requests in the second task queue, which are request results obtained after a worker thread in a worker thread pool corresponding to the second application in the first execution environment processes the IO request in the second task queue.

[0219] Optionally, the IO request of the first application includes a disk IO request. In this case, the first task queue is used to store the disk IO request of the first application.

[0220] Optionally, the IO request of the first application also includes a network IO request. In this case, the first application also communicates with the first execution environment through the third task queue and the third result queue. The third task queue is used to store the network IO request of the first application, and the third result queue is used to store the request result of the network IO request in the third task queue, which is the request result obtained after the working thread in the working thread pool corresponding to the first application in the first execution environment processes the IO request in the third task queue.

[0221] Optionally, the security level of the first execution environment in the electronic device is different from the security level of the second execution environment.

[0222] Optionally, the first execution environment of the electronic device is REE, and the second execution environment is TEE.

[0223] Optionally, after the writing unit 1001 writes the first IO request to the first task queue through the first application, the processing device 1000 further includes: a receiving unit 1003, configured to receive the first ID of the first IO request returned by the first task queue. A determining unit 1004, configured to determine the request result including the first ID from the request results obtained from the first result queue as the first request result. Each request result of the first result queue includes the ID of the IO request for obtaining each request result.

[0224] As an example, combining Figure 6 , the receiving unit 1003 can be used to execute step 1051, and the determining unit 1004 can be used to execute step 1053.

[0225] For the detailed description of the above optional methods, please refer to the above method embodiments, which will not be repeated here. In addition, the explanation of any of the processing devices 1000 provided above and the description of the beneficial effects can refer to the above corresponding method embodiments, which will not be repeated here.

[0226] As an example, in combination with the following Fig.12The functions implemented by the writing unit 1001, the obtaining unit 1002 and the determining unit 1004 in the processing device 1000 can be realized by Fig.12 Processor 1201 in the Fig.12 The functions implemented by the receiving unit 1003 can be implemented by the program code in the memory 1202 in the receiving unit 1003. Fig.12 The internal interface implementation in the communication interface 1203 is shown.

[0227] like Fig.11 As shown, Fig.11 FIG. 1 is a schematic diagram showing a structure of another IO request processing device 1100 provided in an embodiment of the present application. The processing device 1100 is used to execute the above-mentioned IO request processing method, for example, to execute Figure 6 , Figure 7 or Figure 8 The processing device 1100 includes a first processing unit 1101 and a second processing unit 1102.

[0228] The first processing unit 1101 is used to run the first execution environment and to execute the above-mentioned IO request processing method, for example, to execute the following Figure 6 , Figure 7 or Figure 8 The second processing unit 1102 is used to run the second execution environment and to execute the IO request processing method described above, for example, to execute Figure 6 , Figure 7 or Figure 8 The portion of the illustrated method that is executed in a second execution environment.

[0229] Optionally, the security level of the first execution environment in the electronic device is different from the security level of the second execution environment.

[0230] Optionally, the first execution environment of the electronic device is REE, and the second execution environment is TEE.

[0231] For the detailed description of the above optional methods, please refer to the above method embodiments, which will not be repeated here. In addition, the explanation of any of the processing devices 1100 provided above and the description of the beneficial effects can refer to the above corresponding method embodiments, which will not be repeated here.

[0232] Those skilled in the art should easily realize that, in combination with the units and algorithm steps of each example described in the embodiments disclosed herein, the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0233] It should be noted that Fig. 9 , Fig.10 as well as Fig.11 The division of modules / units in the above is schematic and is only a logical function division. There may be other division methods in actual implementation. For example, two or more functions may be integrated into one processing module. The above integrated modules may be implemented in the form of hardware or software function modules.

[0234] An embodiment of the present application provides an electronic device. The electronic device is used to implement some or all of the functions in the method provided in the embodiment of the present application. In the embodiment of the present application, a first execution environment and a second execution environment are running in the electronic device, wherein the security level of the first execution environment is different from the security level of the second execution environment. In some examples, the first execution environment is REE and the second execution environment is TEE. By executing the method described above in the embodiment of the present application by an electronic device running the first execution environment and the second execution environment, the efficiency of the application in the second execution environment of the electronic device in processing IO requests through the first execution environment can be improved.

[0235] Fig.12 FIG. 1 is a schematic diagram showing the structure of an electronic device provided by an embodiment of the present application. Fig.12 As shown, the electronic device 1200 includes a processor 1201, a memory 1202, a communication interface 1203 and a bus 1204. The processor 1201, the memory 1202 and the communication interface 1203 are connected to each other through the bus 1204.

[0236] Processor 1201 may include a general-purpose processor and / or a dedicated hardware chip. A general-purpose processor may include: a central processing unit (CPU), a microprocessor or a graphics processing unit (GPU). The CPU is, for example, a single-core processor (single-CPU), or a multi-core processor (multi-CPU). A dedicated hardware chip is a hardware module for high-performance processing. A dedicated hardware chip includes at least one of a digital signal processor, an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or a network processor (NP). Processor 1201 may also be an integrated circuit chip with signal processing capabilities. In the implementation process, some or all of the functions of the method of the present application may be completed by an integrated logic circuit of hardware in processor 1201 or instructions in software form.

[0237] The memory 1202 is used to store computer programs, which include an operating system 1202a and executable codes (i.e., program instructions) 1202b. The memory 1202 is, for example, a read-only memory or other types of static storage devices that can store static information and instructions, or a random access memory or other types of dynamic storage devices that can store information and instructions, or an electrically erasable programmable read-only memory, a read-only optical disc or other optical disc storage, an optical disc storage (including a compressed optical disc, a laser disc, an optical disc, a digital versatile disc, a Blu-ray disc, etc.), a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store the desired executable code in the form of an instruction or data structure and can be accessed by a computer, but is not limited thereto. For example, the memory 1202 is used to store IO requests and request results of IO requests, etc. The memory 1202 is, for example, independent and connected to the processor 1201 via a bus 1204. Or the memory 1202 and the processor 1201 are integrated together. The memory 1202 can store executable code. When the executable code stored in the memory 1202 is executed by the processor 1201, the processor 1201 is used to perform part or all of the functions of the method provided in the embodiment of the present application. For the implementation of the processor 1201 to execute the process, please refer to the relevant description in the aforementioned embodiment. The memory 1202 may also include software modules and data required for other running processes such as an operating system.

[0238] The communication interface 1203 uses a transceiver module such as, but not limited to, a transceiver to achieve communication with other devices or communication networks. For example, the communication interface 1203 can be any one or any combination of the following devices: a network interface (such as an Ethernet interface), a wireless network card, and other devices with network access functions.

[0239] The communication interface 1203 also includes a hardware or software interface for implementing communication between various device modules inside the electronic device 1200. This type of interface can be called an internal interface for communication in the electronic device 1200.

[0240] The bus 1204 is any type of communication bus for interconnecting the internal devices of the electronic device (e.g., the memory 1202, the processor 1201, and the communication interface 1203). For example, a system bus. The embodiment of the present application takes the interconnection of the above-mentioned devices inside the electronic device through the bus 1204 as an example. Optionally, the above-mentioned devices inside the electronic device 1200 can also be connected to each other in communication with each other using other connection methods other than the bus 1204. For example, the above-mentioned devices inside the electronic device 1200 are interconnected through an internal logical interface.

[0241] It should be noted that the above-mentioned multiple devices can be respectively arranged on independent chips, or at least partially or completely arranged on the same chip. Whether to independently arrange each device on different chips or to integrate and arrange it on one or more chips often depends on the needs of product design. The embodiments of the present application do not limit the specific implementation form of the above-mentioned devices. The descriptions of the processes corresponding to the above-mentioned figures have different focuses. For the parts not described in detail in a certain process, please refer to the relevant descriptions of other processes.

[0242] In the above embodiments, all or part of the embodiments may be implemented by software, hardware, firmware, or any combination thereof. When implemented by software, all or part of the embodiments may be implemented in the form of a computer program product. The computer program product providing a program development platform includes one or more computer instructions, and when these computer program instructions are loaded and executed on an electronic device, all or part of the functions of the method provided in the embodiments of the present application are implemented in whole or in part.

[0243] Furthermore, computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, computer instructions may be transmitted from one website, computer, server or data center to another website, computer, server or data center via wired (e.g., coaxial cable, optical fiber, digital subscriber line) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium stores computer program instructions that provide a program development platform.

[0244] An embodiment of the present application also provides a computer-readable storage medium, which is a non-volatile computer-readable storage medium. The computer-readable storage medium includes program instructions. When the program instructions are executed on a computer, a computer system or a processor, the computer, the computer system or the processor implements the method provided in the embodiment of the present application.

[0245] The embodiments of the present application also provide a computer program product comprising instructions, which, when executed on a computer, a computer system or a processor, enables the computer, the computer system or the processor to implement the method provided by the embodiments of the present application.

[0246] A person skilled in the art will understand that all or part of the steps to implement the above embodiments may be accomplished by hardware, or may be accomplished by instructing the relevant hardware through a program, and the program may be stored in a computer-readable storage medium, and the above-mentioned storage medium may be a read-only memory, a disk or an optical disk, etc.

[0247] It should be noted that the information (including but not limited to user device information, user personal information, etc.), data (including but not limited to data used for analysis, stored data, displayed data, etc.) and signals involved in this application are all authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards of relevant countries and regions.

[0248] The embodiment of the present application further provides a chip, which includes a processor, in which the first execution environment and the second execution environment described above are run, and is used to execute the IO request processing method described above, for example Figure 6 , Figure 7 or Figure 8 The method shown.

[0249] Exemplarily, the chip further includes: an input interface, an output interface, and a memory, etc. The input interface, the output interface, the processor, and the memory are connected via an internal connection path, and the memory is used to store the above-mentioned program instructions or codes, and to store the above-mentioned IO requests and the request results of the IO requests.

[0250] In the embodiments of the present application, the terms "first", "second" and "third" are used for descriptive purposes only and should not be understood as indicating or implying relative importance. The term "at least one" means one or more, and the term "plurality" means a plurality, unless otherwise expressly defined.

[0251] The term "and / or" in this application is only a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship.

[0252] It should be understood that the terms used in the description of the various examples herein are only for describing specific examples and are not intended to be limiting. As used in the description of the various examples and the appended claims, the singular forms "a", "an", and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise.

[0253] It should be understood that determining B based on A does not mean determining B only based on A. B can also be determined based on A and / or other information.

[0254] It should also be understood that the term “comprise” (also known as “includes,” “including,” “comprises” and / or “comprising”) when used in this specification specifies the presence of stated features, integers, steps, operations, elements, and / or components, but does not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and / or groups thereof.

[0255] It should also be understood that in the various embodiments of the present application, the size of the serial number of each process does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.

[0256] The above description is only an optional embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the concept and principle of the present application shall be included in the protection scope of the present application.

Claims

1. A method for processing input and output IO requests, It is characterized in that Applied to an electronic device, wherein a first execution environment of the electronic device includes a first working thread pool, the first working thread pool communicates with a first application running in a second execution environment of the electronic device through a first task queue and a first result queue, the first task queue is used to store IO requests of the first application, the first result queue is used to store request results of the IO requests, and the first working thread pool includes a plurality of working threads for processing IO requests in the first task queue; the method includes: The worker threads in the first worker thread pool respectively obtain IO requests from the first task queue; For a first IO request obtained by a first worker thread from the first task queue, the first worker thread executes the first IO request to obtain a first request result; wherein the first worker thread is any worker thread in the first worker thread pool that obtains the IO request; The first working thread writes the first request result into the first result queue.

2. The method according to claim 1, It is characterized in that The first execution environment also includes a second work thread pool, which communicates with a second application in the second execution environment through a second task queue and a second result queue. The second task queue is used to store IO requests of the second application, and the second result queue is used to store request results of the IO requests of the second task queue. The second work thread pool includes multiple work threads, and the work threads in the second work thread pool are used to process IO requests in the second task queue and write the obtained results into the second result queue.

3. The method according to claim 1 or 2, It is characterized in that The first execution environment further includes a detection thread corresponding to the first working thread pool. Before the working threads in the first working thread pool respectively obtain IO requests from the first task queue, the method further includes: A worker thread in a dormant state in the first worker thread pool receives a wake-up instruction sent by the detection thread; In response to the wake-up instruction, the worker thread in the first worker thread pool that is in a dormant state switches from the dormant state to the ready state; The detection thread is used to detect whether the first task queue is empty, and to determine whether there is a dormant worker thread in the first worker thread pool when it is detected that the first task queue is not empty, and to send the wake-up instruction to the dormant worker thread in the first worker thread pool when it is determined that there is a dormant worker thread in the first worker thread pool; The worker threads in the first worker thread pool respectively obtain IO requests from the first task queue, including: The worker threads in the first worker thread pool whose states are switched from the sleep state to the ready state respectively obtain IO requests from the first task queue.

4. The method according to claim 3, It is characterized in that In the case that there is no worker thread in a dormant state in the first worker thread pool, the detection thread is further used to create a first preset number of worker threads in the first worker thread pool; the worker threads in the first worker thread pool respectively obtain IO requests from the first task queue, including: The newly created worker threads in the first worker thread pool respectively obtain IO requests from the first task queue.

5. The method according to claim 3 or 4, It is characterized in that In the case where the detection thread is used to periodically detect whether the first task queue is empty, the detection thread is also used to detect the frequency of writing IO requests to the first task queue in each cycle to obtain the detection result of each cycle, and the detection result is used to adjust the cycle duration of the detection thread to detect whether the first task queue is empty.

6. The method according to claim 3, It is characterized in that The detection thread is also used to destroy a second preset number of dormant worker threads in the first worker thread pool when detecting that the first task queue is empty.

7. The method according to any one of claims 1 to 6, It is characterized in that After the first worker thread writes the first request result into the first result queue, or after the first worker thread writes the first request result into the first result queue, when the queue is empty when obtaining the IO request from the first task queue again, the method further includes: The first worker thread sets the state of the first worker thread to a sleep state.

8. The method according to any one of claims 1 to 7, It is characterized in that The IO request of the first application includes a disk IO request, and the first task queue is used to store the disk IO request.

9. The method according to claim 8, It is characterized in that The IO requests of the first application also include network IO requests. The first execution environment also includes a third work thread pool. The third work thread pool communicates with the first application through a third task queue and a third result queue. The third task queue is used to store the network IO requests. The third result queue is used to store the request results of the network IO requests in the third task queue. The third work thread pool includes multiple work threads. The work threads in the third work thread pool are used to process the network IO requests in the third task queue and write the obtained request results into the third result queue.

10. The method according to any one of claims 1 to 9, It is characterized in that The security level of the first execution environment is different from the security level of the second execution environment.

11. The method according to any one of claims 1 to 10, It is characterized in that The first execution environment is a rich execution environment (REE), and the second execution environment is a trusted execution environment (TEE).

12. A method for processing input and output IO requests, It is characterized in that The method is applied to an electronic device, wherein a first application is running in a second execution environment of the electronic device, the first application communicates with the first execution environment of the electronic device through a first task queue and a first result queue, the first task queue is used to store IO requests of the first application, and the first result queue is used to store request results of the IO requests in the first task queue; the method comprises: The first application writes a first IO request to the first task queue, where the first IO request is any IO request written by the first application to the first task queue; The first application obtains a first request result of the first IO request from the first result queue, where the first request result is a request result obtained after a worker thread in a worker thread pool corresponding to the first application in the first execution environment processes the first IO request.

13. The method according to claim 12, It is characterized in that A second application is also running in the second execution environment. The second application communicates with the first execution environment through a second task queue and a second result queue. The second task queue is used to store IO requests of the second application. The second result queue is used to store request results of the IO requests in the second task queue. The request result is the request result obtained after the working thread in the working thread pool corresponding to the second application in the first execution environment processes the IO request in the second task queue.

14. The method according to claim 12 or 13, It is characterized in that The IO request of the first application includes a disk IO request, and the first task queue is used to store the disk IO request.

15. The method of claim 14, It is characterized in that The IO request of the first application also includes a network IO request. The first application also communicates with the first execution environment through a third task queue and a third result queue. The third task queue is used to store the network IO request, and the third result queue is used to store the request result of the network IO request in the third task queue. The request result is the request result obtained after the working thread in the working thread pool corresponding to the first application in the first execution environment processes the IO request in the third task queue.

16. The method according to any one of claims 12 to 15, It is characterized in that The security level of the first execution environment is different from the security level of the second execution environment.

17. The method according to any one of claims 12 to 16, It is characterized in that The first execution environment is a rich execution environment (REE), and the second execution environment is a trusted execution environment (TEE).

18. The method according to any one of claims 12 to 17, It is characterized in that After the first application writes the first IO request to the first task queue, the method further includes: Receive a first identifier ID of the first IO request returned by the first task queue; The first application obtains the first request result of the first IO request from the first result queue, including: The request results including the first ID among the request results obtained from the first result queue are determined as the first request results; wherein each request result of the first result queue includes the ID of the IO request for obtaining each request result.

19. A device for processing input and output IO requests, It is characterized in that include: A first processing unit, configured to run a first execution environment, and to execute the method according to any one of claims 1 to 11; The second processing unit is configured to run a second execution environment and to execute the method as claimed in any one of claims 12 to 18.

20. The device according to any one of claims 19, It is characterized in that The security level of the first execution environment is different from the security level of the second execution environment.

21. The device according to claim 19 or 20, It is characterized in that The first execution environment is a rich execution environment (REE), and the second execution environment is a trusted execution environment (TEE).

22. An electronic device, It is characterized in that include: One or more processors and a memory, wherein the one or more processors are configured to read a first program instruction in the memory to run a first execution environment and execute the method as described in any one of claims 1 to 11; the one or more processors are also configured to read a second program instruction in the memory to run a second execution environment and execute the method as described in any one of claims 12 to 18.

23. A computer-readable storage medium, It is characterized in that The computer-readable storage medium includes program instructions. When the program instructions are executed on a computer or a processor, the computer or the processor is caused to perform the method according to any one of claims 1 to 18.

24. A computer program product comprising instructions, It is characterized in that When the instructions are executed by a computing device, the computing device is caused to perform the method according to any one of claims 1 to 18.

Citation Information

Cited By

  • Method and apparatus for processing input / output request, and electronic device

    EP4804025A1

  • Method and apparatus for processing input / output request, and electronic device

    WO2025107610A1