WO2023274376A1 - Device drive method and apparatus for micro-kernel architecture, and electronic device and storage medium - Google Patents

Device drive method and apparatus for micro-kernel architecture, and electronic device and storage medium Download PDF

Info

Publication number
WO2023274376A1
WO2023274376A1 PCT/CN2022/102981 CN2022102981W WO2023274376A1 WO 2023274376 A1 WO2023274376 A1 WO 2023274376A1 CN 2022102981 W CN2022102981 W CN 2022102981W WO 2023274376 A1 WO2023274376 A1 WO 2023274376A1
Authority
WO
WIPO (PCT)
Prior art keywords
thread
rpc
sub
node
main
Prior art date
Application number
PCT/CN2022/102981
Other languages
French (fr)
Chinese (zh)
Inventor
梁超众
童武胜
刘勇锋
毛熠璐
Original Assignee
阿里巴巴(中国)有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 阿里巴巴(中国)有限公司 filed Critical 阿里巴巴(中国)有限公司
Publication of WO2023274376A1 publication Critical patent/WO2023274376A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/4401Bootstrapping
    • G06F9/4411Configuring for operating with peripheral devices; Loading of device drivers
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/4401Bootstrapping
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating
    • G06F9/44505Configuring for program initiating, e.g. using registry, configuration files

Definitions

  • the embodiments of the present disclosure relate to the field of computer technology, and in particular to a device driving method, device, electronic device and non-transitory computer-readable storage medium of a microkernel architecture.
  • An operating system is a computer program that manages computer hardware and software resources.
  • a system call is the smallest functional unit of the operating system.
  • the system call divides the operating system into a kernel state (which can be understood as kernel space) and a user state (which can be understood as user space).
  • the kernel is a special software program of the operating system that runs directly on the hardware. It can be understood as a bridge connecting the application program and the hardware, and is used to control the hardware resources of the computer, such as coordinating the Central Processing Unit (Central Processing Unit, CPU) resources. , allocate memory resources and provide a stable environment for the application to run.
  • User mode can be understood as providing space for applications to run.
  • the kernel needs to provide a set of common access interfaces, which are system calls.
  • FIG. 1 shows a schematic diagram of the architecture of the macrokernel and a schematic diagram of the architecture of the microkernel. It can be seen from Figure 1 that in the macrokernel architecture, components, applications and device drivers run in the kernel mode, so components and applications can directly call device drivers. However, in the microkernel architecture, device drivers run in user mode, such as process 1, and components and applications run in user mode process 2. In this way, components and applications cannot directly call device drivers. Therefore, it is urgent to provide A device driver scheme for microkernel architecture.
  • At least one embodiment of the present disclosure provides a device driving method, device, electronic device and non-transitory computer-readable storage medium of a microkernel architecture.
  • the embodiment of the present disclosure proposes a device driving method of a microkernel architecture, wherein the operating system starts the driving main thread in response to the startup command, and does not start the device sub-thread.
  • the device driving method includes:
  • the main thread of the driver determines that the first RPC message is a device start request, start the device sub-thread of the corresponding device node;
  • the device sub-thread After the device sub-thread is started, it receives the second RPC message through the RPC service;
  • the device sub-thread After the device sub-thread determines that the second RPC message is a device operation request, it performs a corresponding device operation on the device node.
  • the device driver method before the driver main thread receives the first RPC message through the RPC service, the device driver method further includes:
  • the main thread of the driver After the main thread of the driver starts the RPC service of the main thread, it registers the RPC service of one or more device nodes and registers each device node.
  • start the device sub-thread of the corresponding device node including:
  • the driving main thread determines that the first RPC message is a device startup request, open the device node corresponding to the device startup request;
  • start the device sub-thread of the corresponding device node including:
  • the driving main thread After determining that the first RPC message is a device startup request, the driving main thread invokes a thread creation API provided by the operating system to create a device sub-thread of a device node corresponding to the device startup request.
  • the device driving method also includes:
  • the device sub-thread opens the corresponding device node after startup
  • the device sub-thread After the device sub-thread opens the device node and determines that the second RPC message is a device operation request, it performs a corresponding device operation on the device node.
  • registering the RPC service of one or more device nodes and registering each device node includes:
  • the driver main thread scans the driver list to obtain one or more device types and the device nodes corresponding to each device type;
  • the driver main thread registers each device node after registering the RPC service of each device node.
  • registering each device node includes:
  • the device start request is sent by the application process in the following manner:
  • the application process searches whether the device node to be started is registered in the second VFS library, wherein the second VFS library is the VFS library of the application process; if not registered, the application process searches for the main thread RPC service;
  • the application process sends a device startup request to the driver main thread based on the main thread RPC service.
  • the application process searches for the RPC service of the main thread RPC service while also searching for the RPC service of the device node to be started;
  • the application process After the application process receives the device startup result fed back by the driver main thread, if the device startup result is successful, the application process sends a device operation request to the device sub-thread based on the RPC service of the device node to be started.
  • the driver main thread registers in the PM process and starts the main thread RPC service; the application process searches for the main thread RPC service in the PM process.
  • the device driving method also includes:
  • the device sub-thread of the corresponding device node is terminated;
  • the driver main thread closes the device node after ending the device sub-thread of the corresponding device node.
  • the embodiment of the present disclosure also proposes a device driving device with a microkernel architecture, wherein the device driving device includes: a driving main thread and a device sub-thread; the operating system starts the driving main thread in response to a start command, and does not start Device sub-thread;
  • Driving the main thread used to receive the first RPC message through the RPC service, and after determining that the first RPC message is a device startup request, start the device sub-thread of the corresponding device node;
  • the device sub-thread is configured to receive a second RPC message through the RPC service after startup, and perform a corresponding device operation on the device node after determining that the second RPC message is a device operation request.
  • the embodiment of the present disclosure also proposes an electronic device, including: a processor and a memory; the processor is used to execute the microkernel architecture described in the first aspect by calling the program or instruction stored in the memory. The steps of a device driver method.
  • the embodiments of the present disclosure also provide a non-transitory computer-readable storage medium for storing programs or instructions, and the programs or instructions cause the computer to execute the device driving method of the microkernel architecture as described in the first aspect. step.
  • the master-slave thread architecture mode of the driver main thread and the device sub-thread is adopted.
  • the operating system is started, only the driver main thread is started, and the device sub-thread is not started, reducing the impact of the device sub-thread.
  • the driver main thread and the device sub-thread provide device driver services through RPC, specifically, when the first RPC message received by the driver main thread is a device start request, the driver main thread restarts the device node The device sub-thread, and then the device sub-thread determines that the received second RPC message is a device operation request, and then performs corresponding operations on the device node, so as to solve the problem that the application cannot directly call the device driver in the current microkernel architecture.
  • Fig. 1 is a schematic diagram of a macro kernel architecture and a schematic diagram of a micro kernel architecture
  • FIG. 2 is a flowchart of a device driving method of a microkernel architecture provided by an embodiment of the present disclosure
  • Fig. 3 is a flow chart of starting a device sub-thread provided by an embodiment of the present disclosure
  • FIG. 4 is a flow chart of another startup device sub-thread provided by an embodiment of the present disclosure.
  • FIG. 5 is an interaction diagram of a device driving method of a microkernel architecture provided by an embodiment of the present disclosure
  • FIG. 6 is an exemplary block diagram of a device driver device of a microkernel architecture provided by an embodiment of the present disclosure
  • Fig. 7 is an exemplary block diagram of an electronic device provided by an embodiment of the present disclosure.
  • a microkernel is an operating system kernel capable of providing necessary services, including but not limited to tasks, threads, Inter-Process Communication (IPC, Inter-Process Communication) and memory management. All services (including device drivers) run in user mode, and handling these services is the same as handling any other program, because each service only runs in its own address space.
  • IPC Inter-Process Communication
  • IPC Inter-Process Communication
  • At least one embodiment of the present disclosure provides a device driver method, device, electronic device, and non-transitory computer-readable storage medium of a microkernel architecture, using a master-slave thread architecture
  • the pattern designs the device driver loading method and the application programming interface (Application Programming Interface, API) that the device driver provides external services in detail.
  • the loading of the device driver includes: RPC service registration of the device node and registration of the device node.
  • the external services provided by the device driver include: device start request (open), device close request (close) and device operation request, wherein the device operation request includes but not limited to: write request (write), read request (read), input/ Output requests (ioctl), etc.
  • the master-slave thread architecture mode of the driver main thread and the device sub-thread is adopted.
  • the operating system is started, only the driver main thread is started, and the device sub-thread is not started, reducing the impact of the device sub-thread on system resources.
  • the driving main thread and the device sub-thread provide device driver services through RPC, specifically, when the first RPC message received by the driving main thread is a device startup request, the driving main thread restarts the device sub-thread of the device node thread, and then the device sub-thread determines that the received second RPC message is a device operation request, and then performs corresponding operations on the device node, so as to solve the problem that the application cannot directly call the device driver in the current microkernel architecture.
  • Fig. 2 is a flowchart of a device driving method of a microkernel architecture provided by an embodiment of the present disclosure.
  • the operating system using the microkernel architecture receives a start command, such as the command generated by the user pressing the power button.
  • a start command such as the command generated by the user pressing the power button.
  • the consumption of hardware and software resources of the operating system by device sub-threads.
  • step 201 the driving main thread receives a first RPC message through the RPC service.
  • the RPC (Remote Procedure Call, remote procedure call) service is a way of interaction between different processes in the microservice architecture.
  • the application in the microservice architecture cannot directly call the device driver, the application process can communicate with the device through RPC.
  • the process where the driver is located sends the first RPC message, so that the main thread of the driver can provide the device driver service through RPC.
  • step 202 after determining that the first RPC message is a device start request, the driving main thread starts the device sub-thread of the corresponding device node.
  • the device driver service provided by the driver main thread through RPC includes a device start request (open), so that the application process can send a device start request to the driver main thread through RPC, and the device start request carries the information of the device node to be started .
  • the driver main thread After the driver main thread determines that the received first RPC message is a device start request, it can determine the device node corresponding to the device start request based on the information of the device node carried in the device start request, and then start the device subclass of the corresponding device node. thread.
  • the startup of the device sub-thread is controlled by the driver main thread.
  • the driver main thread will start the device sub-thread of the device node. In this way, the unused device node can be reduced. , the consumption of hardware and software resources of the operating system by device sub-threads.
  • step 203 the device sub-thread receives the second RPC message through the RPC service after being started.
  • Device driver services are, for example, device operation requests.
  • Device operation requests include but are not limited to: write requests (write), read requests (read), input/output requests ( ioctl) etc.
  • the application process can send a device operation request to the device sub-thread through RPC.
  • the second RPC messages received are all directed at the device node corresponding to the device sub-thread.
  • step 204 after the device sub-thread determines that the second RPC message is a device operation request, it performs a corresponding device operation on the device node.
  • the device sub-thread performs a write operation on the device node; if the device operation request is a read request, the device sub-thread performs a write operation on the device node; if the device operation request is an input/output request, the device The child thread performs input/output operations on the device node.
  • the embodiment adopts the master-slave thread architecture mode of driving the main thread and the device sub-thread.
  • the operating system is started, only the driving main thread is started, and the device sub-thread is not started, so as to reduce the consumption of system resources by the device sub-thread; and , the driver main thread and the device sub-thread provide device driver services through RPC.
  • the driver main thread restarts the device sub-thread of the device node, and then the After the device sub-thread determines that the received second RPC message is a device operation request, it performs a corresponding operation on the device node to solve the problem that the application cannot directly call the device driver in the current microkernel architecture.
  • the driving main thread before the driving main thread receives the first RPC message through the RPC service, the driving main thread needs to register and start the main thread RPC service first, and then receive the first RPC message through the main thread RPC service.
  • the main thread of the driver After the main thread of the driver registers and starts the RPC service of the main thread, it can register the RPC service of one or more device nodes and register each device node.
  • the driver main thread can scan the driver list to obtain one or more device types and the device nodes corresponding to each device type, and then register the RPC service of each device node and register each device node. In this way, any device sub-thread may receive the second RPC message through the RPC service of the device node corresponding to the device sub-thread after being started.
  • the main driver thread determines that the first RPC message is a device start request, there are multiple ways to start the device sub-thread of the corresponding device node.
  • FIG. 3 is a flow chart of starting a device sub-thread provided by an embodiment of the present disclosure.
  • the driving main thread receives a device startup request.
  • the main driving thread waits to receive the first RPC message, and after the main driving thread determines that the received first RPC message is a device startup request, step 302 is executed.
  • the driving main thread opens the device node corresponding to the device start request.
  • the main driving thread may determine the corresponding device node based on the device node information (such as the name of the device node) carried in the device startup request, and then open the device node.
  • the main thread of the driver opens the device node by pointing the ops (operation method) pointer to the member of the ops structure: open, that is, ops->open.
  • step 303 after opening the device node, the driving main thread starts the device sub-thread of the device node. Since the device sub-thread is started after the device node is opened, the device sub-thread can receive the second RPC message directly through the RPC service after being started.
  • FIG. 4 is another flowchart of starting a device sub-thread provided by an embodiment of the present disclosure.
  • Step 401 is the same as step 301 in FIG. 3 and will not be repeated here.
  • the driving main thread calls the create thread API ( ) provided by the operating system to create a device sub-thread of the device node corresponding to the device start request.
  • the main driver thread after receiving the device start request, does not open the device node first and then start the device sub-thread of the device node, but directly calls the create thread API to create the device node The device child thread.
  • the device sub-thread opens the corresponding device node after being started.
  • the device node is not opened by the main thread of the driver, but by the sub-thread of the device.
  • the device sub-line opens the device node by pointing the ops (operation method) pointer to the member of the ops structure: open, that is, ops->open.
  • the device sub-thread After the device sub-thread opens the device node and determines that the second RPC message is a device operation request, it performs a corresponding device operation on the device node.
  • each device node when driving the main thread to register each device node, can be registered with the first VFS (Virtual File System, virtual file system) library, wherein the first VFS library is the process where the main thread is driven VFS library;
  • the driver main thread can register each device node with the PM (Pass Manager, path management) process.
  • the application process checks whether the device node to be started is registered in the second VFS library, wherein the second VFS library is the VFS library of the application process; if not registered, the application process searches for the main thread RPC service.
  • the main thread RPC service is registered and started by the driver main thread in the PM process. Therefore, the application process searches the main thread RPC service in the PM process, and the PM process feeds back the query result to the application process.
  • the application process finds the main thread RPC service, it can send a device startup request to the driver main thread based on the main thread RPC service.
  • the application process may also search for the RPC service of the device node to be started while searching for the RPC service of the main thread.
  • the main thread RPC service is registered and started in the PM process by the driver main thread, and the RPC service of the device node is also registered in the PM process by the driver main thread. Therefore, the application process searches for the main thread RPC service in the PM process. service and the RPC service of the device node to be started, and the PM process feeds back the query result to the application process.
  • the application process After the application process receives the device startup result fed back by the driver main thread, if the device startup result is successful, the application process sends a device operation request to the device sub-thread based on the RPC service of the device node to be started.
  • the device driver service provided by the main driver thread through RPC includes a device shutdown request (open).
  • the application process can send a device shutdown request to the driver main thread through RPC, and the device startup request carries the device shutdown request.
  • the main driving thread After the main driving thread determines that the first RPC message is a device close request, it terminates the device sub-thread of the corresponding device node.
  • the driver main thread closes the device node after ending the device sub-thread of the corresponding device node.
  • the driving main thread closes the device node by pointing the ops (operation method) pointer to the member of the ops structure: close, that is, ops->close.
  • FIG. 5 is an interaction diagram of a device driving method of a microkernel architecture provided by an embodiment of the present disclosure. It should be noted that FIG. 5 is only some embodiments of the present disclosure, not all of them. Example.
  • FIG. 5 for ease of description, only one device sub-thread is shown. Those skilled in the art can understand that there may be multiple device sub-threads, and the interaction process is similar.
  • the operating system when the operating system using the microkernel architecture is started, for example, the operating system receives a start command, such as the command generated by the user pressing the power button, the operating system responds to the start command and only starts the main thread of the driver, not the Device sub-threads reduce the consumption of operating system software and hardware resources by device sub-threads.
  • a start command such as the command generated by the user pressing the power button
  • the driver main thread can wait for the RPC message.
  • the application process searches whether the device node to be started is registered in the second VFS library, wherein the second VFS library is the VFS library of the application process; if not registered, the application process performs RPC service in the PM process Query, the RPC service query includes finding the main thread RPC service and the RPC service of the device node to be started.
  • the PM process feeds back the query result to the application process, wherein the query result includes: main thread RPC service information and service information of the device node to be started.
  • the application process obtains the query result, it sends a device startup request to the driver main thread based on the main thread RPC service, and the device startup request carries the information of the device node (such as the name of the device node).
  • the main driver thread opens the device node, it starts the device sub-thread of the device node, and feeds back the device startup result to the application process. Since the device sub-thread is started after the device node is opened, the device sub-thread can directly wait for the RPC message after starting.
  • the device sub-thread After the device sub-thread receives the device operation request, it performs the corresponding device operation on the device node. If the device operation request is a write request, the device sub-thread performs a write operation on the device node; if the device operation request is a read request, the device sub-thread performs a write operation on the device node; if the device operation request is an input/output request, the device The child thread performs input/output operations on the device node.
  • the application process can send a device shutdown request to the main driver thread, and the device startup request carries the information of the device node to be shutdown or the device startup result, so that the driver main thread can determine the device node corresponding to the device shutdown request.
  • the driver main thread After receiving the device close request, the driver main thread ends the device sub-thread of the corresponding device node. After the main thread of the driver finishes the device sub-thread of the corresponding device node, it closes the device node by pointing the ops (operation method) pointer to the member of the ops structure: close, that is, ops->close.
  • the interaction process of the device driver method of the microkernel architecture shown in Figure 5 adopts the master-slave thread architecture mode of the driver main thread and the device sub-thread.
  • the operating system starts, only the driver main thread is started, and the device sub-thread is not started.
  • the main driver thread and device sub-threads provide device driver services through RPC, specifically, when the main driver thread receives a device start request, the main driver thread restarts the device node The device sub-thread, and then the device sub-thread performs corresponding operations on the device node based on the received device operation request, so as to solve the problem that the application cannot directly call the device driver in the current microkernel architecture.
  • FIG. 6 is a device driver of a microkernel architecture provided by an embodiment of the present disclosure.
  • the device driver includes: a driving main thread 61 and a device sub-thread 62 .
  • the operating system that adopts the microkernel architecture responds to the startup command and starts the driver main thread 61, and does not start the device sub-thread 62.
  • the device driver may include multiple device sub-threads 62, and each device sub-thread 62 corresponds to a device node.
  • the main thread 61 is driven to receive the first RPC message through the RPC service, and after determining that the first RPC message is a device start request, start the device sub-thread 62 of the corresponding device node.
  • the device sub-thread 62 is configured to receive the second RPC message through the RPC service after being started, and after determining that the second RPC message is a device operation request, perform a corresponding device operation on the device node.
  • driving the main thread 61 is also used to register and start the main thread RPC service before receiving the first RPC message through the RPC service, and after starting the main thread RPC service, register the RPC of one or more device nodes service and will register each device node.
  • the main driver thread 61 determines that the first RPC message is a device start request, it starts the device sub-thread 62 of the corresponding device node, which specifically includes: after determining that the first RPC message is a device start request, opening the device start request The corresponding device node; after opening the device node, start the device sub-thread 62 of the device node.
  • the main driver thread 61 after the main driver thread 61 determines that the first RPC message is a device start request, it starts the device sub-thread 62 of the corresponding device node, which specifically includes: after determining that the first RPC message is a device start request, calling the operating system to provide Create a thread API to create the device sub-thread 62 of the device node corresponding to the device start request.
  • the device sub-thread 62 opens the corresponding device node after being started, and after opening the device node and determining that the second RPC message is a device operation request, performs a corresponding device operation on the device node.
  • the driver main thread 61 registers the RPC service of one or more device nodes and registers each device node, specifically including: scanning the driver list to obtain one or more device types and the corresponding device of each device type node; register the RPC service of each device node; and register each device node after registering the RPC service of each device node.
  • driving the main thread 61 to register each device node specifically includes: registering each device node with the first VFS library, wherein the first VFS library is the VFS library of the process where the main thread is driven; or, registering each device node with the PM A process registers each device node.
  • the device start request is sent by the application process in the following manner:
  • the application process searches whether the device node to be started is registered in the second VFS library, wherein the second VFS library is the VFS library of the application process; if it is not registered, the application process searches for the main thread RPC service; the application process is based on the main thread RPC
  • the service sends a device start request to the driver main thread.
  • the application process searches for the RPC service of the main thread, it also searches for the RPC service of the device node to be started. After the application process receives the device startup result fed back by the driver main thread, if the device startup result is successful, the application process sends a device operation request to the device sub-thread based on the RPC service of the device node to be started.
  • the driving main thread 61 registers in the PM process and starts the main thread RPC service.
  • the application process looks for the main thread RPC service in the PM process.
  • the driving main thread 61 is also used to end the device sub-thread 62 of the corresponding device node after determining that the first RPC message is a device closing request; the driving main thread 61 ends the device sub-thread 62 of the corresponding device node After that, close the device node.
  • Fig. 7 is a schematic structural diagram of an electronic device provided by an embodiment of the present disclosure.
  • the electronic device includes: at least one processor 71 , at least one memory 72 and at least one communication interface 73 .
  • Various components in the electronic device are coupled together via a bus system 74 .
  • the communication interface 73 is used for information transmission with external devices. Understandably, the bus system 74 is used to realize connection communication between these components.
  • the bus system 74 also includes a power bus, a control bus and a status signal bus. However, for clarity of illustration, the various buses are labeled as bus system 74 in FIG.
  • the memory 72 in this embodiment may be a volatile memory or a non-volatile memory, or may include both volatile and non-volatile memories.
  • memory 72 stores the following elements, executable units or data structures, or subsets thereof, or extensions thereof: operating system and application programs.
  • the operating system includes various system programs, such as framework layer, core library layer, driver layer, etc., for realizing various basic tasks and processing hardware-based tasks.
  • the application program includes various application programs, such as a media player (Media Player), a browser (Browser), etc., and is used to implement various application tasks.
  • the program for implementing the device driving method of the microkernel architecture provided by the embodiments of the present disclosure may be included in an application program or an operating system.
  • the processor 71 calls the program or instruction stored in the memory 72, specifically, the program or instruction stored in the application program, and the processor 71 is used to execute the microkernel architecture provided by the embodiment of the present disclosure. The steps of each embodiment of the device driving method.
  • the device driving method of the microkernel architecture may be applied to the processor 71 or implemented by the processor 71 .
  • the processor 71 may be an integrated circuit chip, which has a signal processing capability. In the implementation process, each step of the above method can be completed by an integrated logic circuit of hardware in the processor 71 or instructions in the form of software.
  • the above-mentioned processor 71 can be a general-purpose processor, a digital signal processor (Digital Signal Processor, DSP), an application specific integrated circuit (Application Specific Integrated Circuit, ASIC), a ready-made programmable gate array (Field Programmable Gate Array, FPGA) or other Programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
  • a general-purpose processor may be a microprocessor, or the processor may be any conventional processor, or the like.
  • the steps of the device driving method of the microkernel architecture provided by the embodiments of the present disclosure may be directly implemented by a hardware decoding processor, or executed by a combination of hardware and software units in the decoding processor.
  • the software unit may be located in a mature storage medium in the field such as random access memory, flash memory, read-only memory, programmable read-only memory or electrically erasable programmable memory, register.
  • the storage medium is located in the memory 72, and the processor 71 reads the information in the memory 72, and completes the steps of the method in combination with its hardware.
  • the embodiment of the present disclosure also proposes a non-transitory computer-readable storage medium, the non-transitory computer-readable storage medium stores programs or instructions, and the programs or instructions cause the computer to execute various implementations of the device driver method such as the microkernel architecture. In order to avoid repeated description, the steps of the example are not repeated here.

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Security & Cryptography (AREA)
  • Stored Programmes (AREA)

Abstract

The embodiments of the present disclosure relate to a device drive method and apparatus for a micro-kernel architecture, and an electronic device and a storage medium. In at least one embodiment of the present disclosure, a master-slave thread architecture mode including a drive master thread and a device sub-thread is used; when an operation system is started, only the drive master thread is started, and the device sub-thread is not started, such that system resources consumed by the device sub-thread are reduced; in addition, the drive master thread and the device sub-thread provide a device drive service by means of RPC; and specifically, when a first RPC message received by the drive master thread is a device start request, the drive master thread starts the device sub-thread of a device node, and then after determining that a received second RPC message is a device operation request, the device sub-thread performs a corresponding operation on the device node, thereby solving the problem of an application being unable to directly call a device driver in the current micro-kernel architecture.

Description

微内核架构的设备驱动方法、装置、电子设备和存储介质Device driver method, device, electronic device and storage medium of microkernel architecture
本申请要求2021年06月30日递交的申请号为202110734252.7、发明名称为“微内核架构的设备驱动方法、装置、电子设备和存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims the priority of the Chinese patent application with the application number 202110734252.7 and the title of the invention "microkernel architecture device driving method, device, electronic device and storage medium" submitted on June 30, 2021, the entire content of which is incorporated by reference in this application.
技术领域technical field
本公开实施例涉及计算机技术领域,具体涉及一种微内核架构的设备驱动方法、装置、电子设备和非暂态计算机可读存储介质。The embodiments of the present disclosure relate to the field of computer technology, and in particular to a device driving method, device, electronic device and non-transitory computer-readable storage medium of a microkernel architecture.
背景技术Background technique
操作系统(Operation System,OS)是管理计算机硬件与软件资源的计算机程序。系统调用是操作系统的最小功能单位,系统调用将操作系统分为内核态(可以理解为内核空间)和用户态(可以理解为用户空间)。内核是操作系统的一种特殊的软件程序,直接运行在硬件上,可以理解为连接应用程序和硬件的桥梁,用于控制计算机的硬件资源,例如协调中央处理单元(Central Processing Unit,CPU)资源、分配内存资源并提供稳定的环境供应用程序运行。用户态可以理解为提供应用程序运行的空间。为了使应用程序访问到内核管理的资源,例如CPU资源、内存资源、I/O(Input/Output,输入/输出)资源,内核需提供一组通用的访问接口,这些接口即为系统调用。An operating system (Operation System, OS) is a computer program that manages computer hardware and software resources. A system call is the smallest functional unit of the operating system. The system call divides the operating system into a kernel state (which can be understood as kernel space) and a user state (which can be understood as user space). The kernel is a special software program of the operating system that runs directly on the hardware. It can be understood as a bridge connecting the application program and the hardware, and is used to control the hardware resources of the computer, such as coordinating the Central Processing Unit (Central Processing Unit, CPU) resources. , allocate memory resources and provide a stable environment for the application to run. User mode can be understood as providing space for applications to run. In order for applications to access resources managed by the kernel, such as CPU resources, memory resources, and I/O (Input/Output, input/output) resources, the kernel needs to provide a set of common access interfaces, which are system calls.
目前,操作系统的内核架构有两种:宏内核架构和微内核架构。图1示出了宏内核的架构示意图和微内核架构示意图,由图1可见,在宏内核架构中组件、应用和设备驱动运行于内核态,因此,组件和应用可以直接调用设备驱动。而在微内核架构中,设备驱动运行于用户态,例如运行于进程1中,组件和应用运行于用户态的进程2中,这样,组件和应用无法直接调用设备驱动,为此,亟需提供一种微内核架构的设备驱动方案。Currently, there are two types of kernel architectures of operating systems: a macrokernel architecture and a microkernel architecture. Figure 1 shows a schematic diagram of the architecture of the macrokernel and a schematic diagram of the architecture of the microkernel. It can be seen from Figure 1 that in the macrokernel architecture, components, applications and device drivers run in the kernel mode, so components and applications can directly call device drivers. However, in the microkernel architecture, device drivers run in user mode, such as process 1, and components and applications run in user mode process 2. In this way, components and applications cannot directly call device drivers. Therefore, it is urgent to provide A device driver scheme for microkernel architecture.
发明内容Contents of the invention
为了解决现有技术存在的至少一个问题,本公开的至少一个实施例提供了一种微内核架构的设备驱动方法、装置、电子设备和非暂态计算机可读存储介质。In order to solve at least one problem in the prior art, at least one embodiment of the present disclosure provides a device driving method, device, electronic device and non-transitory computer-readable storage medium of a microkernel architecture.
第一方面,本公开实施例提出一种微内核架构的设备驱动方法,其中,操作系统响应启动指令而启动驱动主线程,且不启动设备子线程,该设备驱动方法包括:In the first aspect, the embodiment of the present disclosure proposes a device driving method of a microkernel architecture, wherein the operating system starts the driving main thread in response to the startup command, and does not start the device sub-thread. The device driving method includes:
驱动主线程通过RPC服务接收第一RPC消息;Drive the main thread to receive the first RPC message through the RPC service;
驱动主线程确定第一RPC消息为设备启动请求后,启动对应的设备节点的设备子线程;After the main thread of the driver determines that the first RPC message is a device start request, start the device sub-thread of the corresponding device node;
设备子线程在启动后通过RPC服务接收第二RPC消息;After the device sub-thread is started, it receives the second RPC message through the RPC service;
设备子线程确定第二RPC消息为设备操作请求后,对设备节点进行对应的设备操作。After the device sub-thread determines that the second RPC message is a device operation request, it performs a corresponding device operation on the device node.
在一些实施例中,驱动主线程通过RPC服务接收第一RPC消息之前,该设备驱动方法还包括:In some embodiments, before the driver main thread receives the first RPC message through the RPC service, the device driver method further includes:
驱动主线程注册并启动主线程RPC服务;Drive the main thread to register and start the main thread RPC service;
驱动主线程在启动主线程RPC服务后,注册一个或多个设备节点的RPC服务并将注册每个设备节点。After the main thread of the driver starts the RPC service of the main thread, it registers the RPC service of one or more device nodes and registers each device node.
在一些实施例中,驱动主线程确定第一RPC消息为设备启动请求后,启动对应的设备节点的设备子线程,包括:In some embodiments, after the main thread of the driver determines that the first RPC message is a device start request, start the device sub-thread of the corresponding device node, including:
驱动主线程确定第一RPC消息为设备启动请求后,打开设备启动请求对应的设备节点;After the driving main thread determines that the first RPC message is a device startup request, open the device node corresponding to the device startup request;
驱动主线程在打开设备节点后,启动设备节点的设备子线程。After the main thread of the driver opens the device node, it starts the device sub-thread of the device node.
在一些实施例中,驱动主线程确定第一RPC消息为设备启动请求后,启动对应的设备节点的设备子线程,包括:In some embodiments, after the main thread of the driver determines that the first RPC message is a device start request, start the device sub-thread of the corresponding device node, including:
驱动主线程确定第一RPC消息为设备启动请求后,调用操作系统提供的创建线程API,以创建设备启动请求对应的设备节点的设备子线程。After determining that the first RPC message is a device startup request, the driving main thread invokes a thread creation API provided by the operating system to create a device sub-thread of a device node corresponding to the device startup request.
在一些实施例中,该设备驱动方法还包括:In some embodiments, the device driving method also includes:
设备子线程在启动后打开对应的设备节点;The device sub-thread opens the corresponding device node after startup;
设备子线程在打开设备节点后,且确定第二RPC消息为设备操作请求后,对设备节点进行对应的设备操作。After the device sub-thread opens the device node and determines that the second RPC message is a device operation request, it performs a corresponding device operation on the device node.
在一些实施例中,注册一个或多个设备节点的RPC服务并将注册每个设备节点,包括:In some embodiments, registering the RPC service of one or more device nodes and registering each device node includes:
驱动主线程扫描驱动列表,得到一个或多个设备类型以及每个设备类型对应的设备节点;The driver main thread scans the driver list to obtain one or more device types and the device nodes corresponding to each device type;
驱动主线程注册每个设备节点的RPC服务;Drive the main thread to register the RPC service of each device node;
驱动主线程在注册每个设备节点的RPC服务后注册每个设备节点。The driver main thread registers each device node after registering the RPC service of each device node.
在一些实施例中,注册每个设备节点包括:In some embodiments, registering each device node includes:
向第一VFS库注册每个设备节点,其中,第一VFS库为驱动主线程所在进程的VFS库;或,向PM进程注册每个设备节点。Register each device node with the first VFS library, where the first VFS library is the VFS library that drives the process where the main thread resides; or, register each device node with the PM process.
在一些实施例中,设备启动请求由应用进程通过如下方式发送:In some embodiments, the device start request is sent by the application process in the following manner:
应用进程在第二VFS库中查找待启动的设备节点是否已注册,其中,第二VFS库为应用进程的VFS库;若未注册,则应用进程查找主线程RPC服务;The application process searches whether the device node to be started is registered in the second VFS library, wherein the second VFS library is the VFS library of the application process; if not registered, the application process searches for the main thread RPC service;
应用进程基于主线程RPC服务向驱动主线程发送设备启动请求。The application process sends a device startup request to the driver main thread based on the main thread RPC service.
在一些实施例中,应用进程查找主线程RPC服务的同时还查找待启动的设备节点的RPC服务;In some embodiments, the application process searches for the RPC service of the main thread RPC service while also searching for the RPC service of the device node to be started;
应用进程接收到驱动主线程反馈的设备启动结果后,若设备启动结果为成功,则应 用进程基于待启动的设备节点的RPC服务向设备子线程发送设备操作请求。After the application process receives the device startup result fed back by the driver main thread, if the device startup result is successful, the application process sends a device operation request to the device sub-thread based on the RPC service of the device node to be started.
在一些实施例中,驱动主线程在PM进程中注册并启动主线程RPC服务;应用进程在PM进程中查找主线程RPC服务。In some embodiments, the driver main thread registers in the PM process and starts the main thread RPC service; the application process searches for the main thread RPC service in the PM process.
在一些实施例中,该设备驱动方法还包括:In some embodiments, the device driving method also includes:
驱动主线程确定第一RPC消息为设备关闭请求后,结束对应的设备节点的设备子线程;After the main thread is driven to determine that the first RPC message is a device shutdown request, the device sub-thread of the corresponding device node is terminated;
驱动主线程在结束对应的设备节点的设备子线程后,关闭设备节点。The driver main thread closes the device node after ending the device sub-thread of the corresponding device node.
第二方面,本公开实施例还提出一种微内核架构的设备驱动装置,其中,该设备驱动装置包括:驱动主线程和设备子线程;操作系统响应启动指令而启动驱动主线程,且不启动设备子线程;In the second aspect, the embodiment of the present disclosure also proposes a device driving device with a microkernel architecture, wherein the device driving device includes: a driving main thread and a device sub-thread; the operating system starts the driving main thread in response to a start command, and does not start Device sub-thread;
驱动主线程,用于通过RPC服务接收第一RPC消息,并确定第一RPC消息为设备启动请求后,启动对应的设备节点的设备子线程;Driving the main thread, used to receive the first RPC message through the RPC service, and after determining that the first RPC message is a device startup request, start the device sub-thread of the corresponding device node;
设备子线程,用于在启动后通过RPC服务接收第二RPC消息,并确定第二RPC消息为设备操作请求后,对设备节点进行对应的设备操作。The device sub-thread is configured to receive a second RPC message through the RPC service after startup, and perform a corresponding device operation on the device node after determining that the second RPC message is a device operation request.
第三方面,本公开实施例还提出一种电子设备,包括:处理器和存储器;所述处理器通过调用所述存储器存储的程序或指令,用于执行如第一方面所述微内核架构的设备驱动方法的步骤。In the third aspect, the embodiment of the present disclosure also proposes an electronic device, including: a processor and a memory; the processor is used to execute the microkernel architecture described in the first aspect by calling the program or instruction stored in the memory. The steps of a device driver method.
第四方面,本公开实施例还提出一种非暂态计算机可读存储介质,用于存储程序或指令,所述程序或指令使计算机执行如第一方面所述微内核架构的设备驱动方法的步骤。In the fourth aspect, the embodiments of the present disclosure also provide a non-transitory computer-readable storage medium for storing programs or instructions, and the programs or instructions cause the computer to execute the device driving method of the microkernel architecture as described in the first aspect. step.
可见,本公开的至少一个实施例中,采用驱动主线程和设备子线程的主从线程架构模式,在操作系统启动时,仅启动驱动主线程,而不启动设备子线程,减少设备子线程对系统资源的消耗;并且,驱动主线程和设备子线程通过RPC方式提供设备驱动服务,具体地,当驱动主线程接收到的第一RPC消息为设备启动请求后,驱动主线程再启动设备节点的设备子线程,进而由设备子线程确定接收到的第二RPC消息为设备操作请求后,对设备节点进行对应的操作,解决目前的微内核架构中,应用无法直接调用设备驱动的问题。It can be seen that in at least one embodiment of the present disclosure, the master-slave thread architecture mode of the driver main thread and the device sub-thread is adopted. When the operating system is started, only the driver main thread is started, and the device sub-thread is not started, reducing the impact of the device sub-thread. consumption of system resources; and, the driver main thread and the device sub-thread provide device driver services through RPC, specifically, when the first RPC message received by the driver main thread is a device start request, the driver main thread restarts the device node The device sub-thread, and then the device sub-thread determines that the received second RPC message is a device operation request, and then performs corresponding operations on the device node, so as to solve the problem that the application cannot directly call the device driver in the current microkernel architecture.
附图说明Description of drawings
为了更清楚地说明本公开实施例的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本公开的一些实施例,对于本领域普通技术人员来讲,还可以根据这些附图获得其他的附图。In order to more clearly illustrate the technical solutions of the embodiments of the present disclosure, the following will briefly introduce the drawings that need to be used in the embodiments or the description of the prior art. Obviously, the drawings in the following description are only some of the present disclosure. Embodiments, those of ordinary skill in the art can also obtain other drawings based on these drawings.
图1是宏内核的架构示意图和微内核架构示意图;Fig. 1 is a schematic diagram of a macro kernel architecture and a schematic diagram of a micro kernel architecture;
图2是本公开实施例提供的一种微内核架构的设备驱动方法的流程图;FIG. 2 is a flowchart of a device driving method of a microkernel architecture provided by an embodiment of the present disclosure;
图3是本公开实施例提供的一种启动设备子线程的流程图;Fig. 3 is a flow chart of starting a device sub-thread provided by an embodiment of the present disclosure;
图4是本公开实施例提供的另一种启动设备子线程的流程图;FIG. 4 is a flow chart of another startup device sub-thread provided by an embodiment of the present disclosure;
图5是本公开实施例提供的一种微内核架构的设备驱动方法的交互图;FIG. 5 is an interaction diagram of a device driving method of a microkernel architecture provided by an embodiment of the present disclosure;
图6是本公开实施例提供的一种微内核架构的设备驱动装置的示例性框图;FIG. 6 is an exemplary block diagram of a device driver device of a microkernel architecture provided by an embodiment of the present disclosure;
图7是本公开实施例提供的一种电子设备的示例性框图。Fig. 7 is an exemplary block diagram of an electronic device provided by an embodiment of the present disclosure.
具体实施方式detailed description
为了能够更清楚地理解本公开的上述目的、特征和优点,下面结合附图和实施例对本公开作进一步的详细说明。可以理解的是,所描述的实施例是本公开的一部分实施例,而不是全部的实施例。此处所描述的具体实施例仅仅用于解释本公开,而非对本公开的限定。基于所描述的本公开的实施例,本领域普通技术人员所获得的所有其他实施例,都属于本公开保护的范围。In order to more clearly understand the above objects, features and advantages of the present disclosure, the present disclosure will be further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the described embodiments are some of the embodiments of the present disclosure, but not all of the embodiments. The specific embodiments described here are only used to explain the present disclosure, but not to limit the present disclosure. All other embodiments obtained by persons of ordinary skill in the art based on the described embodiments of the present disclosure belong to the protection scope of the present disclosure.
需要说明的是,在本文中,诸如“第一”和“第二”等之类的关系术语仅仅用来将一个实体或者操作与另一个实体或操作区分开来,而不一定要求或者暗示这些实体或操作之间存在任何这种实际的关系或者顺序。It should be noted that in this article, relative terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply these No such actual relationship or order exists between entities or operations.
微内核是一种能够提供必要服务的操作系统内核,其中,必要服务包括但不限于任务、线程、交互进程通信(IPC,Inter-Process Communication)以及内存管理等。所有服务(包括设备驱动)运行于用户态,而处理这些服务同处理其他的任何一个程序一样,因为每个服务只是在自己的地址空间运行。A microkernel is an operating system kernel capable of providing necessary services, including but not limited to tasks, threads, Inter-Process Communication (IPC, Inter-Process Communication) and memory management. All services (including device drivers) run in user mode, and handling these services is the same as handling any other program, because each service only runs in its own address space.
为了解决现有技术存在的至少一个问题,本公开的至少一个实施例提供了一种微内核架构的设备驱动方法、装置、电子设备和非暂态计算机可读存储介质,采用主从线程的架构模式对设备驱动加载方式及设备驱动对外提供服务的应用程序编程接口(Application Programming Interface,API)进行了详细的设计。其中,设备驱动加载包括:设备节点的RPC服务注册和设备节点的注册。设备驱动对外提供的服务包括:设备启动请求(open)、设备关闭请求(close)和设备操作请求,其中,设备操作请求包括但不限于:写请求(write)、读请求(read)、输入/输出请求(ioctl)等。In order to solve at least one problem in the prior art, at least one embodiment of the present disclosure provides a device driver method, device, electronic device, and non-transitory computer-readable storage medium of a microkernel architecture, using a master-slave thread architecture The pattern designs the device driver loading method and the application programming interface (Application Programming Interface, API) that the device driver provides external services in detail. Wherein, the loading of the device driver includes: RPC service registration of the device node and registration of the device node. The external services provided by the device driver include: device start request (open), device close request (close) and device operation request, wherein the device operation request includes but not limited to: write request (write), read request (read), input/ Output requests (ioctl), etc.
本公开的至少一个实施例中,采用驱动主线程和设备子线程的主从线程架构模式,在操作系统启动时,仅启动驱动主线程,而不启动设备子线程,减少设备子线程对系统资源的消耗;并且,驱动主线程和设备子线程通过RPC方式提供设备驱动服务,具体地,当驱动主线程接收到的第一RPC消息为设备启动请求后,驱动主线程再启动设备节点的设备子线程,进而由设备子线程确定接收到的第二RPC消息为设备操作请求后,对设备节点进行对应的操作,解决目前的微内核架构中,应用无法直接调用设备驱动的问题。In at least one embodiment of the present disclosure, the master-slave thread architecture mode of the driver main thread and the device sub-thread is adopted. When the operating system is started, only the driver main thread is started, and the device sub-thread is not started, reducing the impact of the device sub-thread on system resources. consumption; and, the driving main thread and the device sub-thread provide device driver services through RPC, specifically, when the first RPC message received by the driving main thread is a device startup request, the driving main thread restarts the device sub-thread of the device node thread, and then the device sub-thread determines that the received second RPC message is a device operation request, and then performs corresponding operations on the device node, so as to solve the problem that the application cannot directly call the device driver in the current microkernel architecture.
图2是本公开实施例提供的一种微内核架构的设备驱动方法的流程图。采用微内核架构的操作系统在启动时,例如操作系统接收到启动指令,启动指令例如用户按压开机按键而产生的指令,操作系统响应启动指令仅启动驱动主线程,而不启动设备子线程, 减少设备子线程对操作系统软硬件资源的消耗。在一些实施例中,设备子线程可以有多个,每个设备子线程与一个设备节点对应,不论设备子线程有多少个,操作系统在启动时,均不启动这些设备子线程。Fig. 2 is a flowchart of a device driving method of a microkernel architecture provided by an embodiment of the present disclosure. When the operating system using the microkernel architecture is started, for example, the operating system receives a start command, such as the command generated by the user pressing the power button. The consumption of hardware and software resources of the operating system by device sub-threads. In some embodiments, there may be multiple device sub-threads, and each device sub-thread corresponds to a device node. No matter how many device sub-threads there are, these device sub-threads are not started when the operating system is started.
在操作系统启动驱动主线程后,在步骤201中,驱动主线程通过RPC服务接收第一RPC消息。After the operating system starts the driving main thread, in step 201, the driving main thread receives a first RPC message through the RPC service.
其中,RPC(Remote Procedure Call,远程过程调用)服务是微服务架构中不同进程之间进行交互的一种方式,虽然微服务架构中应用无法直接调用设备驱动,但是应用进程可以通过RPC方式向设备驱动所处的进程发送第一RPC消息,这样,驱动主线程可以通过RPC方式提供设备驱动服务。Among them, the RPC (Remote Procedure Call, remote procedure call) service is a way of interaction between different processes in the microservice architecture. Although the application in the microservice architecture cannot directly call the device driver, the application process can communicate with the device through RPC. The process where the driver is located sends the first RPC message, so that the main thread of the driver can provide the device driver service through RPC.
在步骤202中,驱动主线程确定第一RPC消息为设备启动请求后,启动对应的设备节点的设备子线程。In step 202, after determining that the first RPC message is a device start request, the driving main thread starts the device sub-thread of the corresponding device node.
驱动主线程通过RPC方式提供的设备驱动服务包括设备启动请求(open),这样,应用进程可以通过RPC方式向驱动主线程发送设备启动请求,在该设备启动请求中携带待启动的设备节点的信息。The device driver service provided by the driver main thread through RPC includes a device start request (open), so that the application process can send a device start request to the driver main thread through RPC, and the device start request carries the information of the device node to be started .
驱动主线程确定接收到的第一RPC消息为设备启动请求后,可以基于该设备启动请求中携带的设备节点的信息,确定该设备启动请求对应的设备节点,进而启动对应的设备节点的设备子线程。After the driver main thread determines that the received first RPC message is a device start request, it can determine the device node corresponding to the device start request based on the information of the device node carried in the device start request, and then start the device subclass of the corresponding device node. thread.
可见,设备子线程的启动是由驱动主线程来控制,当有应用进程需要使用某个设备节点时,驱动主线程才会启动该设备节点的设备子线程,这样,可以减少设备节点未被使用时,设备子线程对操作系统软硬件资源的消耗。It can be seen that the startup of the device sub-thread is controlled by the driver main thread. When an application process needs to use a certain device node, the driver main thread will start the device sub-thread of the device node. In this way, the unused device node can be reduced. , the consumption of hardware and software resources of the operating system by device sub-threads.
在步骤203中,设备子线程在启动后通过RPC服务接收第二RPC消息。In step 203, the device sub-thread receives the second RPC message through the RPC service after being started.
设备子线程在启动后,可以通过RPC方式提供设备驱动服务,设备驱动服务例如为设备操作请求,设备操作请求包括但不限于:写请求(write)、读请求(read)、输入/输出请求(ioctl)等。这样,应用进程可以通过RPC方式向设备子线程发送设备操作请求。After the device sub-thread is started, it can provide device driver services through RPC. Device driver services are, for example, device operation requests. Device operation requests include but are not limited to: write requests (write), read requests (read), input/output requests ( ioctl) etc. In this way, the application process can send a device operation request to the device sub-thread through RPC.
需要说明的是,设备子线程在启动后所接收的第二RPC消息均是针对该设备子线程所对应的设备节点。It should be noted that, after the device sub-thread is started, the second RPC messages received are all directed at the device node corresponding to the device sub-thread.
在步骤204中,设备子线程确定第二RPC消息为设备操作请求后,对设备节点进行对应的设备操作。In step 204, after the device sub-thread determines that the second RPC message is a device operation request, it performs a corresponding device operation on the device node.
若设备操作请求为写请求,则设备子线程对设备节点进行写操作;若设备操作请求为读请求,则设备子线程对设备节点进行写操作;若设备操作请求为输入/输出请求,则设备子线程对设备节点进行输入/输出操作。If the device operation request is a write request, the device sub-thread performs a write operation on the device node; if the device operation request is a read request, the device sub-thread performs a write operation on the device node; if the device operation request is an input/output request, the device The child thread performs input/output operations on the device node.
可见,实施例中采用驱动主线程和设备子线程的主从线程架构模式,在操作系统启动时,仅启动驱动主线程,而不启动设备子线程,减少设备子线程对系统资源的消耗; 并且,驱动主线程和设备子线程通过RPC方式提供设备驱动服务,具体地,当驱动主线程接收到的第一RPC消息为设备启动请求后,驱动主线程再启动设备节点的设备子线程,进而由设备子线程确定接收到的第二RPC消息为设备操作请求后,对设备节点进行对应的操作,解决目前的微内核架构中,应用无法直接调用设备驱动的问题。It can be seen that the embodiment adopts the master-slave thread architecture mode of driving the main thread and the device sub-thread. When the operating system is started, only the driving main thread is started, and the device sub-thread is not started, so as to reduce the consumption of system resources by the device sub-thread; and , the driver main thread and the device sub-thread provide device driver services through RPC. Specifically, when the first RPC message received by the driver main thread is a device startup request, the driver main thread restarts the device sub-thread of the device node, and then the After the device sub-thread determines that the received second RPC message is a device operation request, it performs a corresponding operation on the device node to solve the problem that the application cannot directly call the device driver in the current microkernel architecture.
在一些实施例中,驱动主线程通过RPC服务接收第一RPC消息之前,驱动主线程需要先注册并启动主线程RPC服务,进而才能通过主线程RPC服务接收第一RPC消息。In some embodiments, before the driving main thread receives the first RPC message through the RPC service, the driving main thread needs to register and start the main thread RPC service first, and then receive the first RPC message through the main thread RPC service.
驱动主线程在注册并启动主线程RPC服务后,可以注册一个或多个设备节点的RPC服务并注册每个设备节点。在一些实施例中,驱动主线程可以扫描驱动列表,得到一个或多个设备类型以及每个设备类型对应的设备节点,进而注册每个设备节点的RPC服务并注册每个设备节点。这样,任一设备子线程在启动后可以通过该设备子线程对应的设备节点的RPC服务接收第二RPC消息。After the main thread of the driver registers and starts the RPC service of the main thread, it can register the RPC service of one or more device nodes and register each device node. In some embodiments, the driver main thread can scan the driver list to obtain one or more device types and the device nodes corresponding to each device type, and then register the RPC service of each device node and register each device node. In this way, any device sub-thread may receive the second RPC message through the RPC service of the device node corresponding to the device sub-thread after being started.
在一些实施例中,驱动主线程确定第一RPC消息为设备启动请求后,有多种方式启动对应的设备节点的设备子线程。In some embodiments, after the main driver thread determines that the first RPC message is a device start request, there are multiple ways to start the device sub-thread of the corresponding device node.
例如,图3为本公开实施例提供的一种启动设备子线程的流程图。在步骤301中,驱动主线程接收设备启动请求。该步骤中,驱动主线程等待接收第一RPC消息,当驱动主线程确定接收的第一RPC消息为设备启动请求后,执行步骤302。For example, FIG. 3 is a flow chart of starting a device sub-thread provided by an embodiment of the present disclosure. In step 301, the driving main thread receives a device startup request. In this step, the main driving thread waits to receive the first RPC message, and after the main driving thread determines that the received first RPC message is a device startup request, step 302 is executed.
在步骤302中,驱动主线程打开设备启动请求对应的设备节点。该步骤中,驱动主线程可以基于设备启动请求中携带的设备节点的信息(例如设备节点的名称),确定对应的设备节点,进而打开该设备节点。在一些实施例中,驱动主线程通过将ops(操作方法)指针指向ops结构体的成员:open,也即ops->open,以打开该设备节点。In step 302, the driving main thread opens the device node corresponding to the device start request. In this step, the main driving thread may determine the corresponding device node based on the device node information (such as the name of the device node) carried in the device startup request, and then open the device node. In some embodiments, the main thread of the driver opens the device node by pointing the ops (operation method) pointer to the member of the ops structure: open, that is, ops->open.
在步骤303中,驱动主线程在打开设备节点后,启动设备节点的设备子线程。由于设备子线程是在设备节点打开后才启动,因此,设备子线程在启动后可以直接通过RPC服务接收第二RPC消息。In step 303, after opening the device node, the driving main thread starts the device sub-thread of the device node. Since the device sub-thread is started after the device node is opened, the device sub-thread can receive the second RPC message directly through the RPC service after being started.
又例如,图4为本公开实施例提供的另一种启动设备子线程的流程图。步骤401与图3中的步骤301相同,不再赘述。As another example, FIG. 4 is another flowchart of starting a device sub-thread provided by an embodiment of the present disclosure. Step 401 is the same as step 301 in FIG. 3 and will not be repeated here.
在步骤402中,驱动主线程调用操作系统提供的创建线程API(),以创建设备启动请求对应的设备节点的设备子线程。本实施例中,与图3实施例不同的是,驱动主线程在接收到设备启动请求后,不是先打开设备节点再启动设备节点的设备子线程,而是直接调用创建线程API来创建设备节点的设备子线程。In step 402, the driving main thread calls the create thread API ( ) provided by the operating system to create a device sub-thread of the device node corresponding to the device start request. In this embodiment, different from the embodiment in FIG. 3 , after receiving the device start request, the main driver thread does not open the device node first and then start the device sub-thread of the device node, but directly calls the create thread API to create the device node The device child thread.
在步骤403中,设备子线程在启动后打开对应的设备节点。与图3实施例不同的是,设备节点并非由驱动主线程打开,而是由设备子线程打开。具体地,设备子线通过将ops(操作方法)指针指向ops结构体的成员:open,也即ops->open,以打开该设备节点。In step 403, the device sub-thread opens the corresponding device node after being started. The difference from the embodiment in FIG. 3 is that the device node is not opened by the main thread of the driver, but by the sub-thread of the device. Specifically, the device sub-line opens the device node by pointing the ops (operation method) pointer to the member of the ops structure: open, that is, ops->open.
设备子线程在打开设备节点后,且确定第二RPC消息为设备操作请求后,对设备节点进行对应的设备操作。After the device sub-thread opens the device node and determines that the second RPC message is a device operation request, it performs a corresponding device operation on the device node.
在一些实施例中,驱动主线程注册每个设备节点时,可以向第一VFS(Virtual File System,虚拟文件系统)库注册每个设备节点,其中,第一VFS库为驱动主线程所在进程的VFS库;或者,驱动主线程可以向PM(Pass Manager,路径管理)进程注册每个设备节点。In some embodiments, when driving the main thread to register each device node, each device node can be registered with the first VFS (Virtual File System, virtual file system) library, wherein the first VFS library is the process where the main thread is driven VFS library; Alternatively, the driver main thread can register each device node with the PM (Pass Manager, path management) process.
在一些实施例中,应用进程在第二VFS库中查找待启动的设备节点是否已注册,其中,第二VFS库为应用进程的VFS库;若未注册,则应用进程查找主线程RPC服务。在一些实施例中,主线程RPC服务由驱动主线程在PM进程中注册并启动,因此,应用进程在PM进程中查找主线程RPC服务,PM进程将查询结果反馈给应用进程。In some embodiments, the application process checks whether the device node to be started is registered in the second VFS library, wherein the second VFS library is the VFS library of the application process; if not registered, the application process searches for the main thread RPC service. In some embodiments, the main thread RPC service is registered and started by the driver main thread in the PM process. Therefore, the application process searches the main thread RPC service in the PM process, and the PM process feeds back the query result to the application process.
应用进程查找到主线程RPC服务后,可以基于主线程RPC服务向驱动主线程发送设备启动请求。After the application process finds the main thread RPC service, it can send a device startup request to the driver main thread based on the main thread RPC service.
在一些实施例中,应用进程查找主线程RPC服务的同时还可以查找待启动的设备节点的RPC服务。在一些实施例中,主线程RPC服务由驱动主线程在PM进程中注册并启动,设备节点的RPC服务也由驱动主线程在PM进程中注册,因此,应用进程在PM进程中查找主线程RPC服务以及待启动的设备节点的RPC服务,PM进程将查询结果反馈给应用进程。In some embodiments, the application process may also search for the RPC service of the device node to be started while searching for the RPC service of the main thread. In some embodiments, the main thread RPC service is registered and started in the PM process by the driver main thread, and the RPC service of the device node is also registered in the PM process by the driver main thread. Therefore, the application process searches for the main thread RPC service in the PM process. service and the RPC service of the device node to be started, and the PM process feeds back the query result to the application process.
应用进程接收到驱动主线程反馈的设备启动结果后,若设备启动结果为成功,则应用进程基于待启动的设备节点的RPC服务向设备子线程发送设备操作请求。After the application process receives the device startup result fed back by the driver main thread, if the device startup result is successful, the application process sends a device operation request to the device sub-thread based on the RPC service of the device node to be started.
在一些实施例中,驱动主线程通过RPC方式提供的设备驱动服务包括设备关闭请求(open),这样,应用进程可以通过RPC方式向驱动主线程发送设备关闭请求,在该设备启动请求中携带待关闭的设备节点的信息或者设备启动结果,以便驱动主线程可以确定设备关闭请求对应的设备节点。In some embodiments, the device driver service provided by the main driver thread through RPC includes a device shutdown request (open). In this way, the application process can send a device shutdown request to the driver main thread through RPC, and the device startup request carries the device shutdown request. The information of the closed device node or the result of device startup, so that the main thread of the driver can determine the device node corresponding to the device shutdown request.
驱动主线程确定第一RPC消息为设备关闭请求后,结束对应的设备节点的设备子线程。驱动主线程在结束对应的设备节点的设备子线程后,关闭设备节点。在一些实施例中,驱动主线程通过将ops(操作方法)指针指向ops结构体的成员:close,也即ops->close,以关闭该设备节点。After the main driving thread determines that the first RPC message is a device close request, it terminates the device sub-thread of the corresponding device node. The driver main thread closes the device node after ending the device sub-thread of the corresponding device node. In some embodiments, the driving main thread closes the device node by pointing the ops (operation method) pointer to the member of the ops structure: close, that is, ops->close.
结合以上各方法实施例的描述,图5是本公开实施例提供的一种微内核架构的设备驱动方法的交互图,需要说明的是,图5仅为本公开的一些实施例,而非全部实施例。In combination with the descriptions of the above method embodiments, FIG. 5 is an interaction diagram of a device driving method of a microkernel architecture provided by an embodiment of the present disclosure. It should be noted that FIG. 5 is only some embodiments of the present disclosure, not all of them. Example.
在图5中,为了便于描述,仅示出一个设备子线程,本领域技术人员可以理解,设备子线程可以有多个,且交互流程类似。In FIG. 5 , for ease of description, only one device sub-thread is shown. Those skilled in the art can understand that there may be multiple device sub-threads, and the interaction process is similar.
在图5中,采用微内核架构的操作系统在启动时,例如操作系统接收到启动指令,启动指令例如用户按压开机按键而产生的指令,操作系统响应启动指令仅启动驱动主线程,而不启动设备子线程,减少设备子线程对操作系统软硬件资源的消耗。In Figure 5, when the operating system using the microkernel architecture is started, for example, the operating system receives a start command, such as the command generated by the user pressing the power button, the operating system responds to the start command and only starts the main thread of the driver, not the Device sub-threads reduce the consumption of operating system software and hardware resources by device sub-threads.
在图5中,驱动主线程启动后,在PM进程中注册并启动主线程RPC服务,并且在PM进程中注册设备节点的RPC服务以及注册设备节点。在完成以上注册工作后,驱动 主线程可以等待RPC消息。In FIG. 5 , after the main thread of the driver is started, the RPC service of the main thread is registered and started in the PM process, and the RPC service of the device node and the device node are registered in the PM process. After completing the above registration work, the driver main thread can wait for the RPC message.
在图5中,应用进程在第二VFS库中查找待启动的设备节点是否已注册,其中,第二VFS库为应用进程的VFS库;若未注册,则应用进程在PM进程中进行RPC服务查询,RPC服务查询包括查找主线程RPC服务和待启动的设备节点的RPC服务。In Fig. 5, the application process searches whether the device node to be started is registered in the second VFS library, wherein the second VFS library is the VFS library of the application process; if not registered, the application process performs RPC service in the PM process Query, the RPC service query includes finding the main thread RPC service and the RPC service of the device node to be started.
PM进程将查询结果反馈给应用进程,其中,查询结果中包括:主线程RPC服务信息和待启动的设备节点的服务信息。应用进程在获取到查询结果后,基于主线程RPC服务向驱动主线程发送设备启动请求,设备启动请求中携带设备节点的信息(例如设备节点的名称)。The PM process feeds back the query result to the application process, wherein the query result includes: main thread RPC service information and service information of the device node to be started. After the application process obtains the query result, it sends a device startup request to the driver main thread based on the main thread RPC service, and the device startup request carries the information of the device node (such as the name of the device node).
在图5中,驱动主线程接收到设备启动请求后,基于设备启动请求中携带的设备节点的信息,确定对应的设备节点,进而通过将ops(操作方法)指针指向ops结构体的成员:open,也即ops->open,以打开该设备节点。In Figure 5, after the main thread of the driver receives the device startup request, it determines the corresponding device node based on the device node information carried in the device startup request, and then points the ops (operation method) pointer to the member of the ops structure: open , that is, ops->open, to open the device node.
驱动主线程在打开设备节点后,启动设备节点的设备子线程,并将设备启动结果反馈给应用进程。由于设备子线程是在设备节点打开后才启动,因此,设备子线程在启动后可以直接等待RPC消息。After the main driver thread opens the device node, it starts the device sub-thread of the device node, and feeds back the device startup result to the application process. Since the device sub-thread is started after the device node is opened, the device sub-thread can directly wait for the RPC message after starting.
在图5中,应用进程接收到驱动主线程反馈的设备启动结果后,若设备启动结果为成功,则应用进程基于待启动的设备节点的RPC服务向设备子线程发送设备操作请求。In Figure 5, after the application process receives the device startup result fed back from the main thread, if the device startup result is successful, the application process sends a device operation request to the device sub-thread based on the RPC service of the device node to be started.
设备子线程接收到设备操作请求后,对设备节点进行对应的设备操作。若设备操作请求为写请求,则设备子线程对设备节点进行写操作;若设备操作请求为读请求,则设备子线程对设备节点进行写操作;若设备操作请求为输入/输出请求,则设备子线程对设备节点进行输入/输出操作。After the device sub-thread receives the device operation request, it performs the corresponding device operation on the device node. If the device operation request is a write request, the device sub-thread performs a write operation on the device node; if the device operation request is a read request, the device sub-thread performs a write operation on the device node; if the device operation request is an input/output request, the device The child thread performs input/output operations on the device node.
在图5中,应用进程可以向驱动主线程发送设备关闭请求,在该设备启动请求中携带待关闭的设备节点的信息或者设备启动结果,以便驱动主线程可以确定设备关闭请求对应的设备节点。In FIG. 5 , the application process can send a device shutdown request to the main driver thread, and the device startup request carries the information of the device node to be shutdown or the device startup result, so that the driver main thread can determine the device node corresponding to the device shutdown request.
驱动主线程接收到设备关闭请求后,结束对应的设备节点的设备子线程。驱动主线程在结束对应的设备节点的设备子线程后,通过将ops(操作方法)指针指向ops结构体的成员:close,也即ops->close,以关闭该设备节点。After receiving the device close request, the driver main thread ends the device sub-thread of the corresponding device node. After the main thread of the driver finishes the device sub-thread of the corresponding device node, it closes the device node by pointing the ops (operation method) pointer to the member of the ops structure: close, that is, ops->close.
可见,图5所示的微内核架构的设备驱动方法的交互流程,采用驱动主线程和设备子线程的主从线程架构模式,在操作系统启动时,仅启动驱动主线程,而不启动设备子线程,减少设备子线程对系统资源的消耗;并且,驱动主线程和设备子线程通过RPC方式提供设备驱动服务,具体地,当驱动主线程接收到设备启动请求后,驱动主线程再启动设备节点的设备子线程,进而由设备子线程基于接收到的设备操作请求,对设备节点进行对应的操作,解决目前的微内核架构中,应用无法直接调用设备驱动的问题。It can be seen that the interaction process of the device driver method of the microkernel architecture shown in Figure 5 adopts the master-slave thread architecture mode of the driver main thread and the device sub-thread. When the operating system starts, only the driver main thread is started, and the device sub-thread is not started. threads, reducing the consumption of system resources by device sub-threads; and, the main driver thread and device sub-threads provide device driver services through RPC, specifically, when the main driver thread receives a device start request, the main driver thread restarts the device node The device sub-thread, and then the device sub-thread performs corresponding operations on the device node based on the received device operation request, so as to solve the problem that the application cannot directly call the device driver in the current microkernel architecture.
图6是本公开实施例提供的一种微内核架构的设备驱动装置,该设备驱动装置包括:驱动主线程61和设备子线程62。采用微内核架构的操作系统响应启动指令而启动驱动 主线程61,且不启动设备子线程62。该设备驱动装置可以包括多个设备子线程62,每个设备子线程62与一个设备节点对应。FIG. 6 is a device driver of a microkernel architecture provided by an embodiment of the present disclosure. The device driver includes: a driving main thread 61 and a device sub-thread 62 . The operating system that adopts the microkernel architecture responds to the startup command and starts the driver main thread 61, and does not start the device sub-thread 62. The device driver may include multiple device sub-threads 62, and each device sub-thread 62 corresponds to a device node.
驱动主线程61,用于通过RPC服务接收第一RPC消息,并确定第一RPC消息为设备启动请求后,启动对应的设备节点的设备子线程62。The main thread 61 is driven to receive the first RPC message through the RPC service, and after determining that the first RPC message is a device start request, start the device sub-thread 62 of the corresponding device node.
设备子线程62,用于在启动后通过RPC服务接收第二RPC消息,并确定第二RPC消息为设备操作请求后,对设备节点进行对应的设备操作。The device sub-thread 62 is configured to receive the second RPC message through the RPC service after being started, and after determining that the second RPC message is a device operation request, perform a corresponding device operation on the device node.
在一些实施例中,驱动主线程61,还用于通过RPC服务接收第一RPC消息之前,注册并启动主线程RPC服务,并在启动主线程RPC服务后,注册一个或多个设备节点的RPC服务并将注册每个设备节点。In some embodiments, driving the main thread 61 is also used to register and start the main thread RPC service before receiving the first RPC message through the RPC service, and after starting the main thread RPC service, register the RPC of one or more device nodes service and will register each device node.
在一些实施例中,驱动主线程61确定第一RPC消息为设备启动请求后,启动对应的设备节点的设备子线程62,具体包括:确定第一RPC消息为设备启动请求后,打开设备启动请求对应的设备节点;在打开设备节点后,启动设备节点的设备子线程62。In some embodiments, after the main driver thread 61 determines that the first RPC message is a device start request, it starts the device sub-thread 62 of the corresponding device node, which specifically includes: after determining that the first RPC message is a device start request, opening the device start request The corresponding device node; after opening the device node, start the device sub-thread 62 of the device node.
在一些实施例中,驱动主线程61确定第一RPC消息为设备启动请求后,启动对应的设备节点的设备子线程62,具体包括:确定第一RPC消息为设备启动请求后,调用操作系统提供的创建线程API,以创建设备启动请求对应的设备节点的设备子线程62。In some embodiments, after the main driver thread 61 determines that the first RPC message is a device start request, it starts the device sub-thread 62 of the corresponding device node, which specifically includes: after determining that the first RPC message is a device start request, calling the operating system to provide Create a thread API to create the device sub-thread 62 of the device node corresponding to the device start request.
在一些实施例中,设备子线程62在启动后打开对应的设备节点,在打开设备节点后,且确定第二RPC消息为设备操作请求后,对设备节点进行对应的设备操作。In some embodiments, the device sub-thread 62 opens the corresponding device node after being started, and after opening the device node and determining that the second RPC message is a device operation request, performs a corresponding device operation on the device node.
在一些实施例中,驱动主线程61注册一个或多个设备节点的RPC服务并将注册每个设备节点,具体包括:扫描驱动列表,得到一个或多个设备类型以及每个设备类型对应的设备节点;注册每个设备节点的RPC服务;并在注册每个设备节点的RPC服务后注册每个设备节点。In some embodiments, the driver main thread 61 registers the RPC service of one or more device nodes and registers each device node, specifically including: scanning the driver list to obtain one or more device types and the corresponding device of each device type node; register the RPC service of each device node; and register each device node after registering the RPC service of each device node.
在一些实施例中,驱动主线程61注册每个设备节点,具体包括:向第一VFS库注册每个设备节点,其中,第一VFS库为驱动主线程所在进程的VFS库;或,向PM进程注册每个设备节点。In some embodiments, driving the main thread 61 to register each device node specifically includes: registering each device node with the first VFS library, wherein the first VFS library is the VFS library of the process where the main thread is driven; or, registering each device node with the PM A process registers each device node.
在一些实施例中,设备启动请求由应用进程通过如下方式发送:In some embodiments, the device start request is sent by the application process in the following manner:
应用进程在第二VFS库中查找待启动的设备节点是否已注册,其中,第二VFS库为应用进程的VFS库;若未注册,则应用进程查找主线程RPC服务;应用进程基于主线程RPC服务向驱动主线程发送设备启动请求。The application process searches whether the device node to be started is registered in the second VFS library, wherein the second VFS library is the VFS library of the application process; if it is not registered, the application process searches for the main thread RPC service; the application process is based on the main thread RPC The service sends a device start request to the driver main thread.
在一些实施例中,应用进程查找主线程RPC服务的同时还查找待启动的设备节点的RPC服务。应用进程接收到驱动主线程反馈的设备启动结果后,若设备启动结果为成功,则应用进程基于待启动的设备节点的RPC服务向设备子线程发送设备操作请求。In some embodiments, while the application process searches for the RPC service of the main thread, it also searches for the RPC service of the device node to be started. After the application process receives the device startup result fed back by the driver main thread, if the device startup result is successful, the application process sends a device operation request to the device sub-thread based on the RPC service of the device node to be started.
在一些实施例中,驱动主线程61在PM进程中注册并启动主线程RPC服务。应用进程在PM进程中查找主线程RPC服务。In some embodiments, the driving main thread 61 registers in the PM process and starts the main thread RPC service. The application process looks for the main thread RPC service in the PM process.
在一些实施例中,驱动主线程61还用于确定第一RPC消息为设备关闭请求后,结 束对应的设备节点的设备子线程62;驱动主线程61在结束对应的设备节点的设备子线程62后,关闭设备节点。In some embodiments, the driving main thread 61 is also used to end the device sub-thread 62 of the corresponding device node after determining that the first RPC message is a device closing request; the driving main thread 61 ends the device sub-thread 62 of the corresponding device node After that, close the device node.
以上各装置实施例的细节可参考各方法实例的细节,为避免重复,不再赘述。For the details of the above device embodiments, reference may be made to the details of the method examples, and details are not repeated here to avoid repetition.
图7是本公开实施例提供的一种电子设备的结构示意图。如图7所示,电子设备包括:至少一个处理器71、至少一个存储器72和至少一个通信接口73。电子设备中的各个组件通过总线系统74耦合在一起。通信接口73,用于与外部设备之间的信息传输。可理解地,总线系统74用于实现这些组件之间的连接通信。总线系统74除包括数据总线之外,还包括电源总线、控制总线和状态信号总线。但为了清楚说明起见,在图7中将各种总线都标为总线系统74。Fig. 7 is a schematic structural diagram of an electronic device provided by an embodiment of the present disclosure. As shown in FIG. 7 , the electronic device includes: at least one processor 71 , at least one memory 72 and at least one communication interface 73 . Various components in the electronic device are coupled together via a bus system 74 . The communication interface 73 is used for information transmission with external devices. Understandably, the bus system 74 is used to realize connection communication between these components. In addition to the data bus, the bus system 74 also includes a power bus, a control bus and a status signal bus. However, for clarity of illustration, the various buses are labeled as bus system 74 in FIG.
可以理解,本实施例中的存储器72可以是易失性存储器或非易失性存储器,或可包括易失性和非易失性存储器两者。It can be understood that the memory 72 in this embodiment may be a volatile memory or a non-volatile memory, or may include both volatile and non-volatile memories.
在一些实施方式中,存储器72存储了如下的元素,可执行单元或者数据结构,或者他们的子集,或者他们的扩展集:操作系统和应用程序。In some embodiments, memory 72 stores the following elements, executable units or data structures, or subsets thereof, or extensions thereof: operating system and application programs.
其中,操作系统,包含各种系统程序,例如框架层、核心库层、驱动层等,用于实现各种基础任务以及处理基于硬件的任务。应用程序,包含各种应用程序,例如媒体播放器(Media Player)、浏览器(Browser)等,用于实现各种应用任务。实现本公开实施例提供的微内核架构的设备驱动方法的程序可以包含在应用程序或操作系统中。Among them, the operating system includes various system programs, such as framework layer, core library layer, driver layer, etc., for realizing various basic tasks and processing hardware-based tasks. The application program includes various application programs, such as a media player (Media Player), a browser (Browser), etc., and is used to implement various application tasks. The program for implementing the device driving method of the microkernel architecture provided by the embodiments of the present disclosure may be included in an application program or an operating system.
在本公开实施例中,处理器71通过调用存储器72存储的程序或指令,具体的,可以是应用程序中存储的程序或指令,处理器71用于执行本公开实施例提供的微内核架构的设备驱动方法各实施例的步骤。In the embodiment of the present disclosure, the processor 71 calls the program or instruction stored in the memory 72, specifically, the program or instruction stored in the application program, and the processor 71 is used to execute the microkernel architecture provided by the embodiment of the present disclosure. The steps of each embodiment of the device driving method.
本公开实施例提供的微内核架构的设备驱动方法可以应用于处理器71中,或者由处理器71实现。处理器71可以是一种集成电路芯片,具有信号的处理能力。在实现过程中,上述方法的各步骤可以通过处理器71中的硬件的集成逻辑电路或者软件形式的指令完成。上述的处理器71可以是通用处理器、数字信号处理器(Digital Signal Processor,DSP)、专用集成电路(Application Specific Integrated Circuit,ASIC)、现成可编程门阵列(Field Programmable Gate Array,FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件。通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等。The device driving method of the microkernel architecture provided by the embodiment of the present disclosure may be applied to the processor 71 or implemented by the processor 71 . The processor 71 may be an integrated circuit chip, which has a signal processing capability. In the implementation process, each step of the above method can be completed by an integrated logic circuit of hardware in the processor 71 or instructions in the form of software. The above-mentioned processor 71 can be a general-purpose processor, a digital signal processor (Digital Signal Processor, DSP), an application specific integrated circuit (Application Specific Integrated Circuit, ASIC), a ready-made programmable gate array (Field Programmable Gate Array, FPGA) or other Programmable logic devices, discrete gate or transistor logic devices, discrete hardware components. A general-purpose processor may be a microprocessor, or the processor may be any conventional processor, or the like.
本公开实施例提供的微内核架构的设备驱动方法的步骤可以直接体现为硬件译码处理器执行完成,或者用译码处理器中的硬件及软件单元组合执行完成。软件单元可以位于随机存储器,闪存、只读存储器,可编程只读存储器或者电可擦写可编程存储器、寄存器等本领域成熟的存储介质中。该存储介质位于存储器72,处理器71读取存储器72中的信息,结合其硬件完成方法的步骤。The steps of the device driving method of the microkernel architecture provided by the embodiments of the present disclosure may be directly implemented by a hardware decoding processor, or executed by a combination of hardware and software units in the decoding processor. The software unit may be located in a mature storage medium in the field such as random access memory, flash memory, read-only memory, programmable read-only memory or electrically erasable programmable memory, register. The storage medium is located in the memory 72, and the processor 71 reads the information in the memory 72, and completes the steps of the method in combination with its hardware.
需要说明的是,对于前述的各方法实施例,为了简单描述,故将其都表述为一系列 的动作组合,但是本领域技术人员能够理解,本公开实施例并不受所描述的动作顺序的限制,因为依据本公开实施例,某些步骤可以采用其他顺序或者同时进行。另外,本领域技术人员能够理解,说明书中所描述的实施例均属于可选实施例。It should be noted that, for the sake of simple description, the aforementioned method embodiments are expressed as a series of action combinations, but those skilled in the art can understand that the embodiments of the present disclosure are not limited by the described action sequence. limitations, because certain steps may be performed in other orders or simultaneously according to embodiments of the present disclosure. In addition, those skilled in the art can understand that the embodiments described in the specification are all optional embodiments.
本公开实施例还提出一种非暂态计算机可读存储介质,所述非暂态计算机可读存储介质存储程序或指令,所述程序或指令使计算机执行如微内核架构的设备驱动方法各实施例的步骤,为避免重复描述,在此不再赘述。The embodiment of the present disclosure also proposes a non-transitory computer-readable storage medium, the non-transitory computer-readable storage medium stores programs or instructions, and the programs or instructions cause the computer to execute various implementations of the device driver method such as the microkernel architecture. In order to avoid repeated description, the steps of the example are not repeated here.
需要说明的是,在本文中,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者装置不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者装置所固有的要素。在没有更多限制的情况下,由语句“包括……”限定的要素,并不排除在包括该要素的过程、方法、物品或者装置中还存在另外的相同要素。It should be noted that, in this document, the term "comprising", "comprising" or any other variation thereof is intended to cover a non-exclusive inclusion such that a process, method, article or apparatus comprising a set of elements includes not only those elements, It also includes other elements not expressly listed, or elements inherent in the process, method, article, or device. Without further limitations, an element defined by the phrase "comprising..." does not exclude the presence of additional same elements in the process, method, article or apparatus comprising the element.
本领域的技术人员能够理解,尽管在此所述的一些实施例包括其它实施例中所包括的某些特征而不是其它特征,但是不同实施例的特征的组合意味着处于本公开的范围之内并且形成不同的实施例。Those skilled in the art will appreciate that although some of the embodiments described herein include some features included in other embodiments but not others, combinations of features from different embodiments are meant to be within the scope of the present disclosure. And form different embodiments.
本领域的技术人员能够理解,对各个实施例的描述都各有侧重,某个实施例中没有详述的部分,可以参见其他实施例的相关描述。Those skilled in the art can understand that the description of each embodiment has its own emphases, and for parts not described in detail in a certain embodiment, reference may be made to the relevant descriptions of other embodiments.
虽然结合附图描述了本公开的实施方式,但是本领域技术人员可以在不脱离本公开的精神和范围的情况下做出各种修改和变型,这样的修改和变型均落入由所附权利要求所限定的范围之内。Although the embodiments of the present disclosure have been described in conjunction with the accompanying drawings, those skilled in the art can make various modifications and variations without departing from the spirit and scope of the present disclosure. within the bounds of the requirements.

Claims (12)

  1. 一种微内核架构的设备驱动方法,其中,操作系统响应启动指令而启动驱动主线程,且不启动设备子线程,所述方法包括:A device driving method of a microkernel architecture, wherein the operating system starts a driving main thread in response to a start instruction, and does not start a device sub-thread, and the method includes:
    所述驱动主线程通过RPC服务接收第一RPC消息;The main thread of the drive receives the first RPC message through the RPC service;
    所述驱动主线程确定所述第一RPC消息为设备启动请求后,启动对应的设备节点的设备子线程;After the main driving thread determines that the first RPC message is a device start request, start the device sub-thread of the corresponding device node;
    所述设备子线程在启动后通过RPC服务接收第二RPC消息;After the device sub-thread is started, it receives the second RPC message through the RPC service;
    所述设备子线程确定所述第二RPC消息为设备操作请求后,对所述设备节点进行对应的设备操作。After the device sub-thread determines that the second RPC message is a device operation request, it performs a corresponding device operation on the device node.
  2. 根据权利要求1所述的方法,其中,所述驱动主线程通过RPC服务接收第一RPC消息之前,所述方法还包括:The method according to claim 1, wherein, before the driving main thread receives the first RPC message through the RPC service, the method further comprises:
    所述驱动主线程注册并启动主线程RPC服务;The driver main thread registers and starts the main thread RPC service;
    所述驱动主线程在启动所述主线程RPC服务后,注册一个或多个设备节点的RPC服务并将注册每个所述设备节点。After the main thread of the driver starts the RPC service of the main thread, it registers the RPC service of one or more device nodes and registers each of the device nodes.
  3. 根据权利要求1所述的方法,其中,所述驱动主线程确定所述第一RPC消息为设备启动请求后,启动对应的设备节点的设备子线程,包括:The method according to claim 1, wherein after the main driving thread determines that the first RPC message is a device startup request, starting the device sub-thread of the corresponding device node includes:
    所述驱动主线程确定所述第一RPC消息为设备启动请求后,打开所述设备启动请求对应的设备节点;After the main driving thread determines that the first RPC message is a device startup request, it opens a device node corresponding to the device startup request;
    所述驱动主线程在打开所述设备节点后,启动所述设备节点的设备子线程。After the main driver thread opens the device node, it starts the device sub-thread of the device node.
  4. 根据权利要求1所述的方法,其中,所述驱动主线程确定所述第一RPC消息为设备启动请求后,启动对应的设备节点的设备子线程,包括:The method according to claim 1, wherein after the main driving thread determines that the first RPC message is a device startup request, starting the device sub-thread of the corresponding device node includes:
    所述驱动主线程确定所述第一RPC消息为设备启动请求后,调用所述操作系统提供的创建线程API,以创建所述设备启动请求对应的设备节点的设备子线程。After the main driver thread determines that the first RPC message is a device startup request, it invokes a thread creation API provided by the operating system to create a device sub-thread of a device node corresponding to the device startup request.
  5. 根据权利要求4所述的方法,其中,所述方法还包括:The method according to claim 4, wherein the method further comprises:
    所述设备子线程在启动后打开对应的设备节点;The device sub-thread opens the corresponding device node after starting;
    所述设备子线程在打开所述设备节点后,且确定所述第二RPC消息为设备操作请求后,对所述设备节点进行对应的设备操作。After the device sub-thread opens the device node and determines that the second RPC message is a device operation request, it performs a corresponding device operation on the device node.
  6. 根据权利要求2所述的方法,其中,所述注册一个或多个设备节点的RPC服务并将注册每个所述设备节点,包括:The method according to claim 2, wherein said registering the RPC service of one or more device nodes and registering each of said device nodes comprises:
    所述驱动主线程扫描驱动列表,得到一个或多个设备类型以及每个所述设备类型对应的设备节点;The driver main thread scans the driver list to obtain one or more device types and device nodes corresponding to each device type;
    所述驱动主线程注册每个所述设备节点的RPC服务;The driving main thread registers the RPC service of each of the device nodes;
    所述驱动主线程在注册每个所述设备节点的RPC服务后注册每个所述设备节点。The driver main thread registers each of the device nodes after registering the RPC service of each of the device nodes.
  7. 根据权利要求2所述的方法,其中,所述设备启动请求由应用进程通过如下方式发送:The method according to claim 2, wherein the device startup request is sent by the application process in the following manner:
    所述应用进程在第二VFS库中查找待启动的设备节点是否已注册,其中,所述第二VFS库为所述应用进程的VFS库;若未注册,则所述应用进程查找主线程RPC服务;The application process searches whether the device node to be started is registered in the second VFS storehouse, wherein the second VFS storehouse is the VFS storehouse of the application process; if not registered, the application process searches for the main thread RPC Serve;
    所述应用进程基于所述主线程RPC服务向所述驱动主线程发送所述设备启动请求。The application process sends the device startup request to the driver main thread based on the main thread RPC service.
  8. 根据权利要求7所述的方法,其中,所述应用进程查找主线程RPC服务的同时还查找所述待启动的设备节点的RPC服务;The method according to claim 7, wherein, while the application process searches for the RPC service of the main thread, it also searches for the RPC service of the device node to be started;
    所述应用进程接收到所述驱动主线程反馈的设备启动结果后,若所述设备启动结果为成功,则所述应用进程基于所述待启动的设备节点的RPC服务向所述设备子线程发送所述设备操作请求。After the application process receives the device startup result fed back by the driving main thread, if the device startup result is successful, the application process sends the device sub-thread based on the RPC service of the device node to be started The device operation request.
  9. 根据权利要求1所述的方法,其中,所述方法还包括:The method according to claim 1, wherein the method further comprises:
    所述驱动主线程确定所述第一RPC消息为设备关闭请求后,结束对应的设备节点的设备子线程;After the main driving thread determines that the first RPC message is a device closing request, end the device sub-thread of the corresponding device node;
    所述驱动主线程在结束对应的设备节点的设备子线程后,关闭所述设备节点。The main driving thread closes the device node after finishing the device sub-thread of the corresponding device node.
  10. 一种微内核架构的设备驱动装置,其中,所述装置包括:驱动主线程和设备子线程;操作系统响应启动指令而启动所述驱动主线程,且不启动所述设备子线程;A device driving device with a microkernel architecture, wherein the device includes: a driving main thread and a device sub-thread; the operating system starts the driving main thread in response to a start command, and does not start the device sub-thread;
    所述驱动主线程,用于通过RPC服务接收第一RPC消息,并确定所述第一RPC消息为设备启动请求后,启动对应的设备节点的设备子线程;The driving main thread is used to receive the first RPC message through the RPC service, and after determining that the first RPC message is a device startup request, start the device sub-thread of the corresponding device node;
    所述设备子线程,用于在启动后通过RPC服务接收第二RPC消息,并确定所述第二RPC消息为设备操作请求后,对所述设备节点进行对应的设备操作。The device sub-thread is configured to receive a second RPC message through the RPC service after startup, and perform a corresponding device operation on the device node after determining that the second RPC message is a device operation request.
  11. 一种电子设备,包括:处理器和存储器;An electronic device comprising: a processor and a memory;
    所述处理器通过调用所述存储器存储的程序或指令,用于执行如权利要求1至9任一项所述方法的步骤。The processor is used to execute the steps of the method according to any one of claims 1 to 9 by invoking the programs or instructions stored in the memory.
  12. 一种非暂态计算机可读存储介质,所述非暂态计算机可读存储介质存储程序或指令,所述程序或指令使计算机执行如权利要求1至9任一项所述方法的步骤。A non-transitory computer-readable storage medium, the non-transitory computer-readable storage medium stores a program or an instruction, and the program or instruction causes a computer to execute the steps of the method according to any one of claims 1 to 9.
PCT/CN2022/102981 2021-06-30 2022-06-30 Device drive method and apparatus for micro-kernel architecture, and electronic device and storage medium WO2023274376A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202110734252.7 2021-06-30
CN202110734252.7A CN115562731A (en) 2021-06-30 2021-06-30 Device driving method and device of micro-kernel architecture, electronic device and storage medium

Publications (1)

Publication Number Publication Date
WO2023274376A1 true WO2023274376A1 (en) 2023-01-05

Family

ID=84692553

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/102981 WO2023274376A1 (en) 2021-06-30 2022-06-30 Device drive method and apparatus for micro-kernel architecture, and electronic device and storage medium

Country Status (2)

Country Link
CN (1) CN115562731A (en)
WO (1) WO2023274376A1 (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5675795A (en) * 1993-04-26 1997-10-07 International Business Machines Corporation Boot architecture for microkernel-based systems
CN101980170A (en) * 2010-10-20 2011-02-23 北京星网锐捷网络技术有限公司 Communication method, system and device for software module in microkernel system
CN107368342A (en) * 2017-08-10 2017-11-21 北京元心科技有限公司 Method and device for driving hardware extension module and terminal equipment
CN109117253A (en) * 2017-06-26 2019-01-01 阿里巴巴集团控股有限公司 A kind of method and apparatus of micro-kernel scheduling
CN110764825A (en) * 2018-07-27 2020-02-07 华为技术有限公司 Starting method and terminal equipment

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5675795A (en) * 1993-04-26 1997-10-07 International Business Machines Corporation Boot architecture for microkernel-based systems
CN101980170A (en) * 2010-10-20 2011-02-23 北京星网锐捷网络技术有限公司 Communication method, system and device for software module in microkernel system
CN109117253A (en) * 2017-06-26 2019-01-01 阿里巴巴集团控股有限公司 A kind of method and apparatus of micro-kernel scheduling
CN107368342A (en) * 2017-08-10 2017-11-21 北京元心科技有限公司 Method and device for driving hardware extension module and terminal equipment
CN110764825A (en) * 2018-07-27 2020-02-07 华为技术有限公司 Starting method and terminal equipment

Also Published As

Publication number Publication date
CN115562731A (en) 2023-01-03

Similar Documents

Publication Publication Date Title
WO2020151306A1 (en) Self-adaptive scaling method for container, and server and storage medium
WO2018176960A1 (en) Network picture displaying method, device and user terminal
US9152523B2 (en) Batching and forking resource requests in a portable computing device
WO2019019380A1 (en) Hybrid app page navigation method and apparatus, terminal and storage medium
TWI783034B (en) System and method for implementing drive
US20120158794A1 (en) Techniques to discover object interfaces
WO2022199283A1 (en) Method and apparatus for determining object of call stack frame, device, and medium
US20190227918A1 (en) Method for allocating memory resources, chip and non-transitory readable medium
WO2022199284A1 (en) Call stack backtrace method and apparatus, and device and medium
US10223163B2 (en) Workflow-based object destruction
US7552434B2 (en) Method of performing kernel task upon initial execution of process at user level
US20110066836A1 (en) Operating system booting method, computer, and computer program product
WO2023044877A1 (en) Render pass processing method and apparatus, electronic device, and storage medium
US8627434B2 (en) Cross security-domain identity context projection within a computing environment
WO2023274376A1 (en) Device drive method and apparatus for micro-kernel architecture, and electronic device and storage medium
CN116414377A (en) Interaction method of web page and native application, electronic equipment and storage medium
JP2001290665A (en) Processor system
WO2015184902A1 (en) Concurrent processing method for intelligent split-screen and corresponding intelligent terminal
WO2023093588A1 (en) Resource sharing method, terminal and computer readable medium
CN114817107B (en) PCIE equipment switching system, method and device, computer equipment and storage medium
CN110249305B (en) Shell operation browser extension when browser crashes or hangs
WO2023044876A1 (en) Multi-thread rendering method and apparatus, electronic device and storage medium
WO2022198989A1 (en) Method and apparatus for realizing virtual peripheral sharing of internet-of-things module, and computer device
JP7427775B2 (en) Stored procedure execution method, device, database system, and storage medium
US9317324B2 (en) Automatic service lifecycle management

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 22832188

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 22832188

Country of ref document: EP

Kind code of ref document: A1