WO2016033755A1 - Task handling apparatus and method, and electronic device - Google Patents

Task handling apparatus and method, and electronic device Download PDF

Info

Publication number
WO2016033755A1
WO2016033755A1 PCT/CN2014/085834 CN2014085834W WO2016033755A1 WO 2016033755 A1 WO2016033755 A1 WO 2016033755A1 CN 2014085834 W CN2014085834 W CN 2014085834W WO 2016033755 A1 WO2016033755 A1 WO 2016033755A1
Authority
WO
WIPO (PCT)
Prior art keywords
task
interrupt
operating system
thread
user
Prior art date
Application number
PCT/CN2014/085834
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 华为技术有限公司
Priority to PCT/CN2014/085834 priority Critical patent/WO2016033755A1/en
Priority to CN201480034730.1A priority patent/CN105579963B/en
Publication of WO2016033755A1 publication Critical patent/WO2016033755A1/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/46Multiprogramming arrangements
    • G06F9/48Program initiating; Program switching, e.g. by interrupt

Definitions

  • the present invention relates to the field of operating systems, and in particular, to a task processing apparatus, an electronic device, and a method.
  • the Linux operating system is increasingly being used to implement processing of high real-time services.
  • FIG. 1 shows a schematic diagram of an architecture using a Linux operating system to process high real-time services.
  • the architecture includes a hardware layer 120, a Linux kernel layer 140, and a user layer 160.
  • User layer 160 can run at least one thread 162, each thread 162 for processing tasks.
  • the task scheduling process and interrupt response process for each thread 162 is primarily implemented by the Linux kernel layer 140.
  • the inventors have found that the prior art has at least the following problems: since the task scheduling process and the interrupt response process are mainly implemented by the Linux kernel layer 140, multiple switching is required in a single task scheduling process or an interrupt response process. Processing in the Linux kernel layer 140 may result in a large delay in a single task scheduling process or an interrupt response process, which affects the real-time nature of the task processing process.
  • Embodiments of the present invention provide a task processing apparatus, method, and electronic device. The technical solution is as follows:
  • a task processing apparatus comprising:
  • a first running module configured to run at least one thread at a user layer
  • a second running module configured to run an operating system in the thread, where the operating system is used to process a task
  • a task processing module configured to perform an interrupt response and/or task scheduling by the operating system in the thread during processing of the task.
  • the task processing module includes:
  • a request receiving unit configured to receive an interrupt request of an interrupt source through a kernel layer
  • a requesting transmission unit configured to transmit, by the kernel layer, the interrupt request to an operating system of a corresponding thread in the user layer;
  • a request response unit configured to perform an interrupt response to the interrupt request by an interrupt processing program of an operating system of a corresponding thread in the user layer.
  • the request transmission unit includes:
  • a first saving subunit configured to save an operating site of the interrupted thread in a core stack of the kernel layer, where the running site includes a first user state instruction location;
  • a transfer subunit configured to transfer the first user state instruction location from a first storage location in the core stack to a second storage location in a shared storage area, and store the interrupt request to the a third storage location in the shared storage area, where the shared storage area is a storage area accessible by both the kernel layer and the user layer;
  • An interrupt storage subunit configured to store, in a first storage location in the core stack, a start instruction location of an interrupt handler in the operating system of the interrupted thread;
  • the subunit is exited for exiting the kernel layer response to the interrupt request.
  • the request response unit includes:
  • a first recovery subunit configured to: when recovering the interrupted thread, read a start instruction position of an interrupt handler of the operating system from a first storage location of the core stack;
  • a second saving subunit configured to save an operation site of the interrupted task in a user stack of the thread, where the running site includes a second user state instruction location;
  • a stack switching subunit configured to switch from the user stack to an interrupt stack
  • An interrupt response subunit configured to read the interrupt request from the shared memory area, and perform an interrupt response based on the interrupt stack
  • a second recovery subunit configured to resume the interrupted task or another task that needs to be scheduled after the end of the interrupt response.
  • the request response unit further includes:
  • a replacement subunit configured to replace the second user state instruction location saved in the user stack The first user state instruction location saved in the second storage location of the shared storage area
  • the second recovery subunit is configured to recover the interrupted task by using the running site saved in the user stack.
  • the task processing module includes:
  • a task switching unit configured to save, by the operating system, an operation site of the interrupted first task when switching from the first task to the second task, where the operation site of the first task includes register information, and a third a user state instruction location and a lock interruption information of the first task;
  • a first acquiring unit configured to acquire, by using the operating system, an operating site of the second task, where the operating site of the second task includes register information, a fourth user state command location, and a lock interruption information of the second task ;
  • the first recovery unit recovers the second task and processes according to the operating site of the second task by the operating system.
  • the task processing module includes:
  • a task detecting unit configured to detect, by the operating system, whether there is a third task that needs to be preferentially scheduled when an interrupt response ends;
  • a second obtaining unit configured to acquire, by the operating system, an operation site of the third task when the third task exists, where the running site of the third task includes a register information, a fifth user state instruction location, and The lock interruption information of the third task;
  • a second recovery unit configured to recover the third task and process according to the operating site of the third task by using the operating system.
  • an electronic device comprising: a processor and a memory;
  • the memory is configured to store one or more instructions for implementing a task processing method
  • the method order includes:
  • the processor is operative to execute the instructions.
  • instructions for performing the following operations are also stored:
  • the processor is operative to execute the instructions.
  • instructions for performing the following operations are also stored:
  • the processor is operative to execute the instructions.
  • the memory further stores instructions for performing the following operations:
  • a user site of the thread saves an operation site of the interrupted task, the operation site including a second user state instruction location;
  • the processor is operative to execute the instructions.
  • an instruction for performing the following operations is also stored:
  • the processor is operative to execute the instructions.
  • an instruction for performing the following operations is also stored:
  • the operating site of the interrupted first task is saved by the operating system, and the running site of the first task includes register information, a third user state command location, and a location The lock interrupt information of the first task;
  • the processor is also operative to execute the instructions.
  • an instruction for performing the following operations is also stored:
  • the operating system detects whether there is a third task requiring priority scheduling
  • the operating site of the third task is acquired by the operating system, and the running site of the third task includes register information, a fifth user state command location, and a lock of the third task.
  • Interrupt information
  • the processor is also operative to execute the instructions.
  • a task processing method comprising:
  • an interrupt response and/or task scheduling is performed by the operating system in the thread.
  • performing an interrupt response by using the operating system in the thread including:
  • the interrupt request is interrupted by an interrupt handler of an operating system of a corresponding thread in the user layer.
  • the transmitting, by the kernel layer, the interrupt request to the corresponding one of the user layers Operating system including:
  • the interrupt request is interrupted by an interrupt processing program in the operating system, including:
  • a user site of the thread saves an operation site of the interrupted task, the operation site including a second user state instruction location;
  • the method before the switching from the user stack to the interrupt stack, the method further includes:
  • Recovering the interrupted task after the interrupt response ends including:
  • the interrupted task is resumed by the running site saved in the user stack.
  • the operating site of the interrupted first task is saved by the operating system, and the running site of the first task includes register information, a third user state command location, and a location The lock interrupt information of the first task;
  • performing task scheduling by using the operating system in the thread including:
  • the operating system detects whether there is a third task requiring priority scheduling
  • the operation site of the third task includes register information, a fifth user state instruction location, and lock interruption information of the third task;
  • FIG. 1 is a schematic diagram of an architecture using a Linux operating system to process high real-time services
  • FIG. 2 is a block diagram showing the structure of a task processing apparatus according to an embodiment of the present invention.
  • FIG. 3 is a block diagram showing the structure of a task processing apparatus according to another embodiment of the present invention.
  • FIG. 3B is a block diagram showing the structure of the request transmission unit provided in FIG. 3A;
  • FIG. 3C is a structural block diagram of the request response unit provided in FIG. 3A; FIG.
  • FIG. 4 is a block diagram showing the structure of a task processing apparatus according to still another embodiment of the present invention.
  • FIG. 5 is a block diagram showing the structure of an electronic device according to an embodiment of the present invention.
  • FIG. 5B is a structural block diagram of an electronic device according to another embodiment of the present invention.
  • FIG. 6A and FIG. 6B are schematic diagrams showing the structure of an electronic device according to the task processing method provided by the embodiment of the present invention.
  • FIG. 7 is a flowchart of a method for processing a task according to an embodiment of the present invention.
  • FIG. 8 is a flowchart of a method for processing a task according to another embodiment of the present invention.
  • FIG. 9 is a flow chart showing the sub-steps of the task processing method provided in the embodiment shown in FIG. 8;
  • FIG. 10 is a flow chart of sub-steps of the task processing method provided in the embodiment shown in FIG.
  • FIG. 11 is a flowchart of a method for processing a task according to still another embodiment of the present invention.
  • Figure 12 is a flow chart showing the sub-steps of the task processing method provided in the embodiment shown in Figure 11;
  • FIG. 13 is a flow chart showing the sub-steps of the task processing method provided in the embodiment shown in FIG.
  • the hardware layer is the hardware foundation in the electronic device. It usually includes a processor (Central: Central Processing Unit, CPU) and memory.
  • the processor can be a single core processor or a multi-core processor.
  • the electronic device may be an electronic device that has certain requirements for real-time processing of tasks, such as a base station device, a transmission device, and an industrial robot.
  • the base station equipment can be a base transceiver station (English: Base Transmitter Station, abbreviation: BTS); in the third generation (English: 3rd- Generation, abbreviation: 3G) In mobile communication technology, the base station equipment can be Node B (English: Node Base station, abbreviation: Node B); in the fourth generation (English: the 4Generation, abbreviation: 4G) mobile communication technology, the base station The device may be an evolved Node B (English: Evolved Node Base station, abbreviation: eNB).
  • Kernel and User Layers The kernel layer is the operating system kernel, virtual storage space, and the layer that drives the application to run; the user layer is the layer in which normal applications run.
  • Interrupt refers to any unusual or unexpected urgent need to be processed in the system during the execution of the computer, so that the processor temporarily interrupts the currently executing program and then goes to execute the corresponding event handler. After the processing is completed, Returns the process of continuing execution or scheduling a new process execution.
  • the event that caused the interrupt to occur is called the interrupt source.
  • the request interrupt processing signal sent by the interrupt source to the processor is called an interrupt request.
  • the process by which a processor processes an interrupt request is called an interrupt response.
  • Core stack The stack used by the operating system kernel.
  • Each thread has a user stack used by itself, which can be a real-time thread or a normal thread.
  • FIG. 2 is a structural block diagram of a task processing apparatus according to an embodiment of the present invention.
  • the task processing device can be implemented as an electronic device by software, hardware, or a combination of both All or part.
  • the task processing device includes a first running module 220, a second running module 240, and a task processing module 260.
  • the first running module 220 is configured to run at least one thread at the user layer.
  • the second running module 240 is configured to run an operating system in the thread, where the operating system is used to process the task.
  • the operating system needs to have the ability to independently perform interrupt response and/or task scheduling. Different types of threads can run the same type of operating system, and different types of operating systems can be run in different threads.
  • the type of the above operating system is not particularly limited in the embodiment of the present invention.
  • Tasks are generic tasks that the operating system can handle.
  • the task may be a task of issuing a scheduling instruction, a task of allocating a channel resource, a task of processing an access request, and the like.
  • the task processing module 260 is configured to perform an interrupt response and/or task scheduling by an operating system in the thread during the processing of the task.
  • the task processing apparatus performs interrupt response and/or task scheduling through an operating system in a thread; and solves the interrupt response process and the task scheduling process, which requires multiple switching to the Linux kernel layer for processing.
  • the delay of the single interrupt response process and the task scheduling process is large, which affects the real-time behavior of the task processing; the interrupt response and/or task scheduling are directly completed in the user layer, and it is not necessary to switch to the kernel layer multiple times. Processing, reducing the time consuming of interrupt response and/or task scheduling, improves the real-time effect of task processing.
  • the load of the kernel layer is high, and the task processing method provided in this embodiment can also achieve the effect of reducing the load of the kernel layer.
  • FIG. 3A is a structural block diagram of a task processing apparatus according to another embodiment of the present invention.
  • the task processing device can be implemented as all or part of an electronic device by software, hardware, or a combination of both.
  • the task processing apparatus includes a first execution module 220 for running at least one thread at the user layer.
  • the first running module 220 is configured to run at least one thread at the user layer.
  • the second running module 240 is configured to run an operating system in a thread running by the first running module 220, where the operating system is used to process a task.
  • the task processing module 260 is configured to perform an interrupt response by the operating system running in the thread by the second running module 240 during the processing of the task.
  • the task processing module 260 includes:
  • the request receiving unit 261 is configured to receive an interrupt request of the interrupt source through the kernel layer.
  • the request transmission unit 262 is configured to transmit, by the kernel layer, the interrupt request received by the request receiving unit 261 to the operating system of the corresponding thread in the user layer run by the second running module 240.
  • the request response unit 263 is configured to perform an interrupt response to the interrupt request received by the request transmission unit 262 by an interrupt processing program of an operating system of a corresponding thread in the user layer.
  • the request transmission unit 262 may include:
  • the first save subunit 262a is configured to save an operation site of the interrupted thread in a core stack of the kernel layer, where the run site includes a first user state instruction location.
  • the transfer subunit 262b is configured to transfer the first user state instruction location saved by the first save subunit 262a from the first storage location in the core stack to the second storage location in the shared storage area for storage, and the request receiving unit
  • the received interrupt request is stored in a third storage location in the shared storage area, and the shared storage area is a storage area accessible by both the kernel layer and the user layer.
  • the interrupt storage sub-unit 262c is configured to transfer the first user state instruction position from the first storage location in the core stack to the second storage location in the shared storage area after the transfer sub-unit 262b is stored, in the core stack
  • the starting instruction location of the interrupt handler in the operating system that stores the interrupted thread in a storage location.
  • the exit sub-unit 262d is configured to exit the kernel layer response to the interrupt request after the interrupt storage sub-unit 262c stores the start instruction position in the first storage location in the core stack.
  • the request response unit 263 may include:
  • the first recovery subunit 263a is configured to: after the exit subunit 262d exits the kernel layer response to the interrupt request, read the interrupt handler of the operating system from the first storage location of the core stack when restoring the interrupted thread Start command position.
  • the second save subunit 263b the user stack of the thread for recovery at the first recovery subunit 263a saves the run site of the interrupted task, the run site including the second user state command location.
  • the stack switching sub-unit 263c is configured to switch from the user stack used by the second saving sub-unit 263b to the interrupt stack.
  • the interrupt response sub-unit 263d is configured to read an interrupt request from the shared memory area and perform an interrupt response based on the interrupt stack to which the stack switching sub-unit 263c is switched.
  • the second recovery sub-unit 263e is configured to resume the interrupted task or another task requiring priority scheduling after the interrupt response sub-unit 263d interrupts the response.
  • the request response unit 263 may further include:
  • a replacement subunit 263f configured to replace the second user state instruction location saved in the user stack by the second save subunit 263b with the first user state instruction location saved in the second storage location of the shared storage area;
  • the second recovery subunit 263e is configured to recover the interrupted task by using the running scene saved in the user stack, the running scene is saved by the second saving subunit 263b, and the second user state instruction is replaced by the replacing subunit 263f.
  • the position is replaced with the first user mode command position.
  • the task processing apparatus performs interrupt processing by using an operating system in a thread by running an operating system in a thread; and the interrupt processing process needs to be switched to the Linux kernel layer multiple times, resulting in a single operation.
  • the delay of the interrupt processing process is large, which affects the real-time problem of the task processing process; the interrupt processing is completed directly in the user layer, and it is not necessary to switch to the kernel layer for processing, reducing the time-consuming processing of the interrupt processing and improving The real-time nature of the task processing.
  • the task processing apparatus provided in this embodiment can also achieve the effect of reducing the load of the kernel layer.
  • the task processing apparatus provided by the embodiment further stores the interrupt request in the shared storage area through the kernel layer, and after the thread of the user layer is restored, acquires the interrupt request from the shared storage area, so that the kernel layer can report the interrupt request to the thread.
  • the interrupt request is processed by the operating system in the thread.
  • the task processing apparatus provided in this embodiment further replaces the first user state instruction position in the core stack with the start instruction position of the interrupt processing program of the operating system, so that the thread of the user layer is restored, and the entry is not interrupted.
  • the first user state instruction position continues to run, but forcibly jumps to the interrupt handler in the operating system, and enters the interrupt response process without delay, realizing the effect of fast reporting and response of the interrupt request.
  • the task processing apparatus provided in this embodiment also independently completes the interrupt response by the interrupt processing program of the operating system, and does not need to switch to the kernel layer for processing in the process, and the time required to complete the complete interrupt response process is very small. Effect.
  • FIG. 4 is a structural block diagram of a task processing apparatus according to another embodiment of the present invention.
  • the task processing device can be implemented as all or part of an electronic device by software, hardware, or a combination of both.
  • the task processing device can include:
  • the first running module 220 is configured to run at least one thread at the user layer.
  • a second running module 240 configured to run an operating system in a thread running by the first running module 220, This operating system is used to process tasks.
  • the task processing module 260 is configured to perform task scheduling by the operating system running in the thread by the second running module 240 during the processing of the task.
  • the task processing module 260 may include:
  • the task switching unit 264 is configured to: when the first task is switched to the second task, the operating system running by the second running module 240 saves the running site of the interrupted first task, where the running site of the first task includes register information, The third user mode instruction location and the lock interruption information of the first task.
  • the first obtaining unit 265 is configured to obtain, after the task switching unit 264 saves the running site of the interrupted first task, the operating site of the second task by using the operating system, where the running site of the second task includes the register information and the fourth user state. The command position and the lock interrupt information of the second task.
  • the first recovery unit 266 restores the second task and processes it according to the operating site of the second task saved by the first obtaining unit 265 by the operating system.
  • the task processing module 260 may further include:
  • the task detecting unit 267 is configured to detect, by the operating system running by the second running module 240, whether there is a third task that needs to be preferentially scheduled when the interrupt response ends.
  • the second obtaining unit 268 is configured to acquire, by the operating system, the running site of the third task when the task detecting unit 267 detects that the third task exists, where the running site of the third task includes the register information, the fifth user state command position, and the Three task lock interrupt information.
  • the second recovery unit 269 is configured to recover and process the third task according to the operating site of the third task acquired by the second obtaining unit 268 by the operating system.
  • the task processing apparatus performs task scheduling by running an operating system in a thread through an operating system in a thread; and solves the problem that the task scheduling process needs to be switched to the Linux kernel layer multiple times, resulting in a single operation.
  • the delay of the task scheduling process is large, which affects the real-time problem of the task processing process. It achieves the task scheduling directly in the user layer, does not need to switch to the kernel layer multiple times, reduces the time-consuming task scheduling, and improves the task. The effect of real-time processing.
  • the task scheduling in the background technology is performed by the kernel layer, the load of the kernel layer is high, and the task processing apparatus provided in this embodiment can also achieve the effect of reducing the load of the kernel layer.
  • FIG. 5A is a structural block diagram of an electronic device according to an embodiment of the present invention.
  • the electronic device 500 includes a processor 520 and a memory 540.
  • the processor 520 and the memory 540 can be connected by a communication bus.
  • the memory 540 can be an instruction memory, a memory, a register, and the like.
  • the memory 540 is configured to store one or more instructions for implementing a task processing method, the instructions including:
  • Interrupt response and/or task scheduling is performed by the operating system in the thread during the processing of the task.
  • the processor 520 is configured to execute the above instructions.
  • each thread can run an operating system, which is used to process tasks.
  • the operating system needs to have the ability to independently perform interrupt response and/or task scheduling.
  • Different types of threads can run the same type of operating system, and different types of operating systems can be run in different threads.
  • the type of the above operating system is not particularly limited in the embodiment of the present invention.
  • Tasks are generic tasks that the operating system can handle.
  • the task may be a task of issuing a scheduling instruction, a task of allocating a channel resource, a task of processing an access request, and the like.
  • the electronic device performs interrupt response and/or task scheduling through an operating system in a thread; the interrupt response process and the task scheduling process need to be switched to the Linux kernel layer for processing, resulting in processing.
  • the delay of the single interrupt response process and the task scheduling process is large, which affects the real-time performance of the task processing process; the interrupt response and/or task scheduling are directly completed in the user layer, and it is not necessary to switch to the kernel layer multiple times. Processing, reducing the time consuming of interrupt response and/or task scheduling, improves the real-time effect of task processing.
  • the load of the kernel layer is high, and the task processing method provided in this embodiment can also achieve the effect of reducing the load of the kernel layer.
  • the memory 540 also stores instructions for performing the following operations:
  • the interrupt request of the interrupt source is received through the kernel layer.
  • the interrupt request is transmitted through the kernel layer to the operating system of the corresponding thread in the user layer.
  • the interrupt request is interrupted by an interrupt handler of an operating system of a corresponding thread in the user layer;
  • the processor 520 is also operative to execute the above instructions.
  • the processor 520 typically receives an interrupt request for the interrupt source via an interrupt line on the bus 560.
  • the memory 540 also stores instructions for performing the following operations:
  • the running site of the interrupted thread is saved in the core stack of the kernel layer, which includes the first user state instruction location.
  • the first user state instruction location is transferred from the first storage location in the core stack to the second storage location in the shared storage area for storage, and the interrupt request is stored to a third storage location in the shared storage area.
  • the processor 520 is also operative to execute the above instructions.
  • the core stack and the shared storage area may be a logical location in physical memory. This physical memory can belong to the memory 540.
  • the memory 540 also stores instructions for performing the following operations:
  • the user stack of the thread saves the running site of the interrupted task, the running site including the second user state command location;
  • the processor 520 is also operative to execute the above instructions.
  • the interrupt stack and the user stack corresponding to each thread may be a logical location in physical memory. This physical memory can belong to the memory 540.
  • the memory 540 also stores instructions for performing the following operations:
  • the processor 520 is also operative to execute the above instructions.
  • the electronic device provided by the embodiment further stores the interrupt request in the shared storage area through the kernel layer, and after the thread of the user layer recovers, acquires the interrupt request from the shared storage area, so that the kernel layer can request the interrupt. Reported to the thread, the interrupt request is processed by the operating system in the thread.
  • the electronic device provided by the embodiment further replaces the first user state instruction position in the core stack with the start instruction position of the interrupt handler of the operating system, so that the thread of the user layer is restored, and the entry is not interrupted.
  • the first user mode instruction position continues to run, but the forced jump to the operating system
  • the interrupt handler in the program directly enters the interrupt response process without delay, and achieves the effect of fast reporting and response of the interrupt request.
  • the electronic device provided in this embodiment also independently completes the interrupt response by the interrupt processing program of the operating system, and does not need to switch to the kernel layer for processing in the process, and the time required to complete the complete interrupt response process is very small. effect.
  • the memory 540 also stores instructions for performing the following operations:
  • the operating site of the interrupted first task is saved by the operating system, and the running site of the first task includes the register information, the third user state instruction position, and the lock interruption information of the first task. .
  • the processor 520 is also operative to execute the above instructions.
  • the memory 540 also stores instructions for performing the following operations:
  • the operating system detects whether there is a third task requiring priority scheduling.
  • the operating site of the third task is acquired by the operating system, and the running site of the third task includes the register information, the fifth user state instruction location, and the lock interruption information of the third task.
  • the third task is resumed and processed by the operating system according to the operation site of the third task;
  • the processor 520 is also operative to execute the above instructions.
  • the electronic device performs task scheduling through an operating system in a thread by running an operating system in a thread.
  • the task scheduling process needs to be switched to the Linux kernel layer multiple times, resulting in a single task.
  • the delay of the scheduling process is large, which affects the real-time problem of the task processing process. It achieves the task scheduling directly in the user layer, does not need to switch to the kernel layer multiple times, reduces the time-consuming task scheduling, and improves the task processing. The effect of real time.
  • the task scheduling in the background technology is performed by the kernel layer, the load of the kernel layer is high, and the task processing apparatus provided in this embodiment can also achieve the effect of reducing the load of the kernel layer.
  • the electronic device 500 may further include a communication bus 530 and transmitting power. Path 552 and receiving circuit 554 and the like.
  • the processor 520 controls the operation of the electronic device 500.
  • the processor 520 may also be referred to as a central processing unit (English: Central Processing Unit, abbreviated CPU).
  • Memory 540 can include read only memory and random access memory and provides instructions and data to processor 520.
  • a portion of the memory 540 may also include a non-volatile random access memory (Non-Volatile Random Access Memory, abbreviated as NVRAM).
  • transmit circuitry 552 and receive circuitry 554 can be coupled to transceiver 550.
  • communication bus 530 which may include, in addition to the data bus, a power bus, a control bus, interrupt lines, and other status signal buses. However, for clarity of description, various buses are labeled as communication bus 530 in the figure.
  • FIG. 6A is a schematic structural diagram of an electronic device involved in a task processing method according to an embodiment of the present invention.
  • the electronic device includes a hardware layer 620, a kernel layer 640, and a user layer 660.
  • the hardware layer 620 includes a processor, which may have a processor core 622, ie, the processor is a single core processor.
  • the kernel layer 640 includes an operating system kernel 642 and a driver application (not shown), which may be a Linux kernel.
  • the user layer 660 can run a thread (English: thread) 662, and each thread 662 runs an operating system (English: operation system, abbreviation: os), which can be a real-time thread and/or a user thread.
  • the operating system can monopolize the processor core 622 to form an Asymmetric Multi-Processing (abbreviation: AMP) structure.
  • FIG. 6B is a schematic structural diagram of still another electronic device involved in the task processing method provided by the embodiment of the present invention.
  • the electronic device includes a hardware layer 620, a kernel layer 640, and a user layer 660.
  • the hardware layer 620 includes a processor, which may include two or more processor cores 622 (illustrated by two processor cores in the figure), that is, a multi-core processor.
  • the kernel layer 640 includes an operating system kernel 642 and a driver application (not shown), which may be a Linux kernel.
  • User layer 660 can run with threads 662, each of which runs an operating system for processing tasks.
  • the thread 662 can be a real-time thread and/or a user thread.
  • Each operating system can monopolize a processor core 622 to form a Symmetric Multi-Processing (SMP) structure.
  • SMP Symmetric Multi-Processing
  • FIG. 7 is a flowchart of a method for processing a task according to an embodiment of the present invention. This embodiment is exemplified by applying the task processing method to the electronic device shown in FIG. 6A or FIG. 6B.
  • the method includes:
  • Step 701 running at least one thread in the user layer
  • Step 702 running an operating system in a thread, the operating system can be used to process a task
  • the operating system needs to have the ability to independently perform interrupt response and/or task scheduling. Different types of threads can run the same type of operating system, and different types of operating systems can be run in different threads.
  • the type of the above operating system is not particularly limited in the embodiment of the present invention.
  • the task is generally referred to as a task that the operating system can process.
  • the task may be a task of issuing a scheduling instruction, a task of allocating a channel resource, a task of processing an access request, and the like.
  • step 703 during the execution of the task, the interrupt response and/or task scheduling is performed by the operating system in the thread.
  • the task processing method performs interrupt response and/or task scheduling through an operating system in a thread; and the interrupt response process and the task scheduling process need to be switched to the Linux kernel layer for processing.
  • the delay of the single interrupt response process and the task scheduling process is large, which affects the real-time behavior of the task processing; the interrupt response and/or task scheduling are directly completed in the user layer, and it is not necessary to switch to the kernel layer multiple times. Processing, reducing the time consuming of interrupt response and/or task scheduling, improves the real-time effect of task processing.
  • the load of the kernel layer is high, and the task processing method provided in this embodiment can also achieve the effect of reducing the load of the kernel layer.
  • FIG. 8 illustrates a method flow of a task processing method according to another embodiment of the present invention. Cheng Tu. This embodiment is exemplified by applying the task processing method to the electronic device shown in FIG. 6A or FIG. 6B.
  • the method includes:
  • Step 801 running at least one thread in the user layer
  • the electronic device runs at least one thread in the user layer, which may be a real-time thread for processing a real-time task, or a normal thread for processing a normal task.
  • Step 802 running an operating system in a thread
  • the electronic device runs the operating system in a thread.
  • An operating system can be run separately in each thread.
  • the electronic device processes the task through the operating system.
  • the operating system needs to have the ability to independently perform interrupt response and/or task scheduling. Different types of threads can run the same type of operating system, and different types of operating systems can be run in different threads.
  • the type of the above operating system is not particularly limited in the embodiment of the present invention.
  • the task is generally referred to as a task that the operating system can process.
  • the task may be a task of issuing a scheduling instruction, a task of allocating a channel resource, a task of processing an access request, and the like.
  • Step 803 receiving an interrupt request of an interrupt source through a kernel layer
  • the electronic device receives an interrupt request of the interrupt source through the kernel layer, and the interrupt source may be an external hardware device, and the external hardware device may be a hardware device such as a mouse, a keyboard, a network card, or a graphics card.
  • the interrupt source may be an external hardware device
  • the external hardware device may be a hardware device such as a mouse, a keyboard, a network card, or a graphics card.
  • an interrupt fast processing program can be implemented in the kernel layer, the interrupt fast processing program is configured to receive an interrupt request in the kernel layer, and report the interrupt request to an operating system in the corresponding thread, so that the operating system in the thread Respond to the interrupt request.
  • the electronic device receives an interrupt request of the interrupt source through the interrupt fast processing program.
  • the electronic device After the interrupt fast processing program receives the interrupt request, the electronic device enters the lock interrupt state by interrupting the fast processing program.
  • the lock interrupt status is used to prevent the processor from receiving another interrupt request during the processing of an interrupt request, thereby causing the interrupt request processing to be interrupted.
  • the implementation of the lock interrupt status can be either a hardware lock interrupt or a software lock interrupt.
  • the kernel layer When the hardware lock is interrupted, the kernel layer will no longer receive other interrupt requests during the processing of this interrupt request.
  • the kernel layer still receives other interrupt requests during the processing of the interrupt request, but does not interrupt the processing of the interrupt request, but stores the subsequently received interrupt request in the kernel layer.
  • the interrupt request queue After the processing of the interrupt request is completed, other interrupt requests are sequentially processed from the interrupt request queue.
  • Step 804 the interrupt request is transmitted to the operating system of the corresponding thread in the user layer through the kernel layer;
  • step 804 can include the following sub-steps, as shown in FIG.
  • the electronic device saves an operation site of the interrupted thread in a core stack of the kernel layer, where the operation site includes a first user state instruction location;
  • the processor can only process one program fragment per unit time, for example, the processor is currently processing one thread, it cannot process other threads or program fragments belonging to the kernel layer.
  • the interrupt request interrupts the currently running thread of the processor, and the processor will respond to the interrupt request.
  • the electronic device saves the running site of the interrupted thread in the kernel stack of the kernel layer by interrupting the fast processing program, and the running site includes various register values of the thread when interrupted. The first user mode instruction location.
  • the first user state instruction location is also referred to as a first user state PC (English: program counter, Chinese: program counter) pointer, and the first user state PC pointer refers to the next instruction that the interrupted thread originally planned to run before the interruption. s position.
  • the processor can resume the operation of the thread by running a program instruction corresponding to the location of the first user state instruction.
  • the core stack is the stack in the kernel layer.
  • the electronic device saves the running site of the thread in the core stack by interrupting the fast processing program.
  • the first user state instruction location is stored in a first storage location of the core stack.
  • the electronic device moves the first user state instruction location from the first storage location in the core stack to the second storage location in the shared storage area for storage, and stores the interrupt request in a third storage location in the shared storage area.
  • the shared storage area is a storage area accessible by both the kernel layer and the user layer;
  • the electronic device can move the first user state instruction location from the first storage location in the core stack to the second storage location in the shared storage area by an interrupt fast handler in the kernel layer.
  • the electronic device stores a starting instruction position of an interrupt processing program of the operating system in a first storage location in the core stack.
  • the operating system in the thread provided by the embodiment of the present invention has the function of independently completing the interrupt response.
  • an interrupt handler can be implemented in the operating system of the thread, the interrupt handler being responsive to an interrupt request reported by the kernel layer to an operating system in the thread.
  • the electronic device stores the starting instruction position of the operating system interrupt processing program in the first storage location in the core stack through the interrupt fast processing program in the kernel layer, the operating system is the interrupted thread The operating system in .
  • the processor will read the interrupt handler of the operating system in the thread instead of the program instruction corresponding to the first user state instruction position.
  • the electronic device exits the processing of the interrupt request through the kernel layer.
  • the interrupt request is stored in the shared memory area waiting for the operating system in the thread in the user layer to process.
  • steps 804a to 804d are all implemented by the electronic device through the kernel layer.
  • step 805 the interrupt request is interrupted by an interrupt handler in the operating system.
  • Step 805 includes the following sub-steps, as shown in FIG. 10:
  • the electronic device reads the starting instruction position of the operating system interrupt processing program from the first storage location of the core stack when restoring the interrupted thread;
  • the first user state instruction location stored by the first storage location in the core stack is replaced with the starting instruction location of the operating system's interrupt handler.
  • the program instruction read by the processor according to the first storage location in the core stack is a program instruction corresponding to the interrupt processing program of the operating system in the thread. . Thereafter, the operating system in the thread interrupts the interrupt request through the interrupt handler.
  • the electronic device saves an operation site of the interrupted task in a thread user stack, and the operation site includes a second user state instruction location;
  • the operating system in the thread is a separate operating system, and the operating system in the thread is used to process the task.
  • the interrupt request interrupts the running task in the operating system, and the electronic device first saves the running site of the interrupted task in the user stack of the thread through the interrupt handler, and the running site includes the task.
  • the second user state instruction location is also referred to as a second user state PC pointer, and the second user state PC pointer is the pointer location corresponding to the next instruction that the interrupted task was scheduled to run before the interruption.
  • the second user state instruction location is typically the same as the first user state instruction location in step 804a. For example, if the thread in step 804a is interrupted when it is going to run to the A position in the program code corresponding to a certain task, then the program instruction position of the task to be interrupted in the thread in step 805b should also be the A position, and No change.
  • Each thread has its own user stack, and the electronic device runs the task through an interrupt handler.
  • the scene is saved in the user stack.
  • the second user mode instruction location is saved in a fourth storage location in the user stack.
  • Step 805c The electronic device replaces the second user state instruction location saved in the user stack with the first user state instruction location saved in the second storage location of the shared storage area;
  • the second user state instruction position stored in step 805b may save an error
  • the second user state instruction position of the saved error may be different from the first user state instruction position, in order to ensure the correctness of the task when the operation is resumed
  • the electronic device replaces the second user state instruction position saved in the user stack in step 805b with the first user state instruction position saved in the second storage location of the shared storage area by the interrupt processing program, that is, the step 804b is replaced.
  • the first user mode instruction location is transferred to the shared memory area.
  • Step 805d the electronic device switches from the user stack to the interrupt stack
  • the interrupt stack is used to store data during the interrupt response process.
  • Step 805e The electronic device reads the interrupt request from the shared storage area, and performs an interrupt response based on the interrupt stack.
  • the electronic device reads the interrupt request from the shared memory by the interrupt handler, and the interrupt request may specifically be an interrupt number, and then the interrupt handler interrupts the interrupt request based on the interrupt stack.
  • Step 805f After the interrupt response ends, the electronic device resumes the interrupted task or another task that needs to be scheduled preferentially;
  • the electronic device restores the interrupted task according to the running scene saved in the user stack through the interrupt handler.
  • the electronic device resumes another task that needs to be scheduled according to the running site saved in the user stack through the interrupt handler.
  • the electronic device may also change the lock interrupt status in the kernel layer to the unlock interrupt status through the interrupt handler when the interrupted task or the task requiring priority scheduling is resumed. When in the unlocked interrupt state, the electronic device can continue to receive the interrupt request.
  • step 804d the electronic device needs to remain in the lock interrupt state. Due to the difference between the hardware lock interrupt and the software lock interrupt, if the hardware lock is interrupted, as long as the electronic device continues to maintain the lock interrupt state, if If the software lock is interrupted, the electronic device needs to exit the interrupt request processing at the kernel layer and restore the interrupted thread. Check whether the state of the software lock interrupt is the lock interrupt status. If not, the software lock interrupt status needs to be updated. Interrupt state and keep.
  • step 805f if the electronic device changes the state of the software lock interrupt from the lock interrupt state to the unlock interrupt state, it is also necessary to detect whether there is another interrupt request in the interrupt request queue, and if there are other interrupt requests, the electronic device re-executes The interrupt response process shown in step 804 and step 805 in the above embodiment.
  • the task processing method performs interrupt processing by running an operating system in a thread through an operating system in a thread; and solves the problem that the interrupt processing process needs to be switched to the Linux kernel layer multiple times, resulting in a single operation.
  • the delay of the interrupt processing process is large, which affects the real-time problem of the task processing process; the interrupt processing is completed directly in the user layer, and it is not necessary to switch to the kernel layer for processing, reducing the time-consuming processing of the interrupt processing and improving The real-time nature of the task processing.
  • the load of the kernel layer is high, and the task processing method provided in this embodiment can also achieve the effect of reducing the load of the kernel layer.
  • the task processing method provided by the embodiment further stores the interrupt request in the shared storage area through the kernel layer, and after the thread of the user layer is restored, acquires the interrupt request from the shared storage area, so that the kernel layer can report the interrupt request to the thread.
  • the interrupt request is processed by the operating system in the thread.
  • the task processing method provided in this embodiment further replaces the first user state instruction position in the core stack with the start instruction position of the operating system interrupt processing program, so that the user layer thread is restored, and the entry is not interrupted.
  • the first user state instruction position continues to run, but forcibly jumps to the interrupt handler in the operating system, and enters the interrupt response process without delay, realizing the effect of fast reporting and response of the interrupt request.
  • the task processing method provided in this embodiment also completes the interrupt response independently by the interrupt processing program of the operating system, and does not need to switch to the kernel layer for processing in the process, and the time required to complete the complete interrupt response process is very small. Effect.
  • FIG. 11 is a flowchart of a method for processing a task according to still another embodiment of the present invention. This embodiment is exemplified by applying the task processing method to the electronic device shown in FIG. 6A or FIG. 6B.
  • the method includes:
  • Step 1101 running at least one thread in the user layer
  • the electronic device runs at least one thread in the user layer.
  • This thread can be a real-time thread for processing real-time tasks or a normal thread for handling common tasks.
  • Step 1102 Run an operating system in a thread, where the operating system is used to process a task;
  • the electronic device runs the operating system in a thread.
  • An operating system can be run separately in each thread.
  • the electronic device processes the task through the operating system.
  • the operating system needs to have the ability to independently perform interrupt response and/or task scheduling. Different types of threads can run the same type of operating system, and different types of operating systems can be run in different threads.
  • the type of the above operating system is not particularly limited in the embodiment of the present invention.
  • the task is generally referred to as a task that the operating system can process.
  • the task may be a task of issuing a scheduling instruction, a task of allocating a channel resource, a task of processing an access request, and the like.
  • Step 1103 During the processing of the task, the task scheduling is performed by the operating system in the thread.
  • the electronic device does not perform task scheduling on the tasks in the thread through the kernel layer, but performs task scheduling on the tasks in the thread by the operating system in the thread.
  • the interrupt response logic of the kernel layer is not needed, and it is not affected by the task scheduling of the kernel layer, and the task scheduling is completed independently.
  • the scheduling policy at the time of scheduling can adopt an existing task scheduling policy.
  • the first one takes the example of switching from the first task to the second task.
  • This step includes the following sub-steps, as shown in FIG. 12:
  • the electronic device when switching from the first task to the second task, saves the running scene of the interrupted first task by using an operating system in the thread, where the running field of the first task includes the register information, the third user state instruction position, and Lock interrupt information for the first task;
  • the operating system in the thread provided by this embodiment has the function of independently completing task scheduling.
  • a task scheduler can be implemented in the thread's operating system, and the task scheduler is used to perform task scheduling for each task processed in the operating system.
  • switching from the first task to the second task may be triggered by an interrupt request or may be actively triggered by a task scheduler in the operating system.
  • the second task will enable one timer after the suspension, and the timer generates an interrupt request after the delay of n milliseconds, and the interrupt request is used to request that the interrupt is being processed.
  • the first task is run, and the first task that is running is switched to the second task to resume the running of the second task.
  • the task scheduler may switch the running first task to the second task when the priority of the second task reaches a preset condition.
  • the electronic device saves the running site of the interrupted first task by using a task scheduler in the operating system, where the running site of the first task includes the register information, the third user state command position, and the first The lock of the task is interrupted.
  • the lock interrupt information means that because task A may be interrupted by task B, task B may be interrupted by task C, and interrupt nesting is formed at this time.
  • Lock interrupt information refers to the level of an interrupt request in interrupt nesting. .
  • the electronic device acquires a running site of the second task by using an operating system in the thread, where the running site of the second task includes the register information, the fourth user state command position, and the lock interruption information of the second task;
  • the electronic device can acquire the running site of the second task through the task scheduler in the operating system.
  • the electronic device restores the second task and processes according to the operating site of the second task by using an operating system in the thread.
  • the electronic device can restore the second task according to the register information in the running field and the fourth user state command position by the task scheduler in the operating system.
  • the electronic device switches the unlocking interrupt state according to the lock interrupt information of the second task by the task scheduler, and then processes the second task.
  • the electronic device is scheduled to a third task that needs priority scheduling, and the third task may be a new task.
  • This step includes the following sub-steps, as shown in Figure 13:
  • the electronic device detects, by the operating system in the thread, whether there is a third task that needs to be scheduled preferentially;
  • the electronic device detects whether there is a third task requiring priority scheduling through a task scheduler in the operating system.
  • an interrupt request is also generated at this time, and the interrupt request is used to request processing of the data packet, and the interrupt request is generated to be processed for processing the data packet.
  • the electronic device acquires a running site of the third task by using an operating system in the thread, where the running site of the third task includes the register information, the fifth user state command location, and the lock interruption information of the third task;
  • the electronic device acquires the running site of the third task through the task scheduler in the operating system.
  • the electronic device restores the third task and processes according to the operating site of the third task by using an operating system in the thread.
  • the electronic device can resume the third task according to the register information according to the operation site and the fifth user state command position.
  • the electronic device switches the lock interruption state in the kernel layer to the unlock interruption state according to the lock interruption information of the third task by the task scheduler, and then processes the third task.
  • the task processing method performs task scheduling by running an operating system in a thread through an operating system in a thread; and the task scheduling process needs to be switched to the Linux kernel layer multiple times, resulting in a single operation.
  • the delay of the task scheduling process is large, which affects the real-time problem of the task processing process. It achieves the task scheduling directly in the user layer, does not need to switch to the kernel layer multiple times, reduces the time-consuming task scheduling, and improves the task. The effect of real-time processing.
  • the load of the kernel layer is high, and the task processing method provided in this embodiment can also achieve the effect of reducing the load of the kernel layer.
  • the task processing apparatus provided in any of the embodiments of FIG. 2 or FIG. 4 or the electronic apparatus provided in the embodiment of FIG. 5A or FIG. 5B can perform the task processing method provided in any of the embodiments of FIG. 7 to FIG.
  • the specific functions and working procedures of the various units or modules of the device embodiments may be referred to the related parts of the method embodiments, and the descriptions of the various embodiments provided by the present invention may also be referred to each other.
  • a person skilled in the art may understand that all or part of the steps of implementing the above embodiments may be completed by hardware, or may be instructed by a program to execute related hardware, and the program may be stored in a computer readable storage medium.
  • the storage medium mentioned may be a read only memory, a magnetic disk or an optical disk or the like.

Abstract

A task handling apparatus and method, and an electronic device. The method comprises: running at least one thread in a user layer (701); running an operating system in the thread, the operating system being used for handling a task (702); and in a task execution process, performing interrupt handling and/or task scheduling by means of the operating system in the thread (703). The problem of influence on the timeliness of a task handling process due to a larger delay for a single-time interrupt handling process and a task scheduling process caused by the fact that the interrupt handling process and the task scheduling process are implemented by repeated switching to a Linux kernel layer is solved. Effects of directly completing the interrupt handling and/or the task scheduling in the user layer without handling by the repeated switching to the kernel layer, shortening consumed time for the interrupt handling and/or the task scheduling and improving the timeliness of task handling are achieved.

Description

任务处理装置、电子设备及方法Task processing device, electronic device and method 技术领域Technical field
本发明涉及操作系统领域,特别涉及一种任务处理装置、电子设备及方法。The present invention relates to the field of operating systems, and in particular, to a task processing apparatus, an electronic device, and a method.
背景技术Background technique
在电信领域中,越来越多地采用Linux操作系统来实现高实时性业务的处理。In the field of telecommunications, the Linux operating system is increasingly being used to implement processing of high real-time services.
请参考图1,其示出了一种采用Linux操作系统来处理高实时性业务的架构示意图。该架构包括硬件层120、Linux内核层140和用户层160。用户层160可以运行有至少一个线程162,每个线程162用于处理任务。每个线程162的任务调度过程和中断响应过程主要由Linux内核层140实现。Please refer to FIG. 1, which shows a schematic diagram of an architecture using a Linux operating system to process high real-time services. The architecture includes a hardware layer 120, a Linux kernel layer 140, and a user layer 160. User layer 160 can run at least one thread 162, each thread 162 for processing tasks. The task scheduling process and interrupt response process for each thread 162 is primarily implemented by the Linux kernel layer 140.
在实现本发明的过程中,发明人发现现有技术至少存在以下问题:由于任务调度过程和中断响应过程主要由Linux内核层140实现,单次的任务调度过程或中断响应过程中需要多次切换至Linux内核层140中进行处理,会导致单次的任务调度过程或中断响应过程的延时较大,影响了任务处理过程的实时性。In the process of implementing the present invention, the inventors have found that the prior art has at least the following problems: since the task scheduling process and the interrupt response process are mainly implemented by the Linux kernel layer 140, multiple switching is required in a single task scheduling process or an interrupt response process. Processing in the Linux kernel layer 140 may result in a large delay in a single task scheduling process or an interrupt response process, which affects the real-time nature of the task processing process.
发明内容Summary of the invention
为了解决任务调度过程和中断响应过程需要多次切换至Linux内核层中进行处理,导致单次的任务调度过程或中断响应过程的延时较大,影响了任务处理过程的实时性的问题,本发明实施例提供了一种任务处理装置、方法及电子设备。所述技术方案如下:In order to solve the task scheduling process and the interrupt response process, it is necessary to switch to the Linux kernel layer for processing, resulting in a large delay of the single task scheduling process or the interrupt response process, which affects the real-time problem of the task processing process. Embodiments of the present invention provide a task processing apparatus, method, and electronic device. The technical solution is as follows:
根据本发明的第一方面,提供了一种任务处理装置,所述装置包括:According to a first aspect of the present invention, a task processing apparatus is provided, the apparatus comprising:
第一运行模块,用于在用户层运行至少一个线程;a first running module, configured to run at least one thread at a user layer;
第二运行模块,用于在所述线程中运行操作系统,所述操作系统用于处理任务;a second running module, configured to run an operating system in the thread, where the operating system is used to process a task;
任务处理模块,用于在处理所述任务的过程中,通过所述线程中的所述操作系统进行中断响应和/或任务调度。 a task processing module, configured to perform an interrupt response and/or task scheduling by the operating system in the thread during processing of the task.
在第一方面的第一种可能的实施方式中,所述任务处理模块,包括:In a first possible implementation manner of the first aspect, the task processing module includes:
请求接收单元,用于通过内核层接收中断源的中断请求;a request receiving unit, configured to receive an interrupt request of an interrupt source through a kernel layer;
请求传输单元,用于通过所述内核层将所述中断请求传输给所述用户层中对应的线程的操作系统;a requesting transmission unit, configured to transmit, by the kernel layer, the interrupt request to an operating system of a corresponding thread in the user layer;
请求响应单元,用于通过所述用户层中对应的线程的操作系统的中断处理程序对所述中断请求进行中断响应。And a request response unit, configured to perform an interrupt response to the interrupt request by an interrupt processing program of an operating system of a corresponding thread in the user layer.
结合第一方面的第一种可能的实施方式,在第二种可能的实施方式中,所述请求传输单元,包括:With reference to the first possible implementation manner of the first aspect, in the second possible implementation, the request transmission unit includes:
第一保存子单元,用于在所述内核层的核心栈中保存被中断的线程的运行现场,所述运行现场包括第一用户态指令位置;a first saving subunit, configured to save an operating site of the interrupted thread in a core stack of the kernel layer, where the running site includes a first user state instruction location;
转移子单元,用于将所述第一用户态指令位置从所述核心栈中的第一存储位置转移到共享存储区中的第二存储位置进行存储,并将所述中断请求存储到所述共享存储区中的第三存储位置,所述共享存储区为所述内核层和所述用户层均能访问的存储区;a transfer subunit, configured to transfer the first user state instruction location from a first storage location in the core stack to a second storage location in a shared storage area, and store the interrupt request to the a third storage location in the shared storage area, where the shared storage area is a storage area accessible by both the kernel layer and the user layer;
中断存储子单元,用于在所述核心栈中的第一存储位置中存储所述被中断的线程的所述操作系统中的中断处理程序的起始指令位置;An interrupt storage subunit, configured to store, in a first storage location in the core stack, a start instruction location of an interrupt handler in the operating system of the interrupted thread;
退出子单元,用于退出所述内核层对所述中断请求的响应。The subunit is exited for exiting the kernel layer response to the interrupt request.
结合第一方面的第二种可能的实施方式,在第三种可能的实施方式中,所述请求响应单元,包括:With reference to the second possible implementation manner of the first aspect, in a third possible implementation, the request response unit includes:
第一恢复子单元,用于在恢复所述被中断的线程时,从所述核心栈的第一存储位置读取所述操作系统的中断处理程序的起始指令位置;a first recovery subunit, configured to: when recovering the interrupted thread, read a start instruction position of an interrupt handler of the operating system from a first storage location of the core stack;
第二保存子单元,用于在所述线程的用户栈保存被中断的任务的运行现场,所述运行现场包括第二用户态指令位置;a second saving subunit, configured to save an operation site of the interrupted task in a user stack of the thread, where the running site includes a second user state instruction location;
栈切换子单元,用于从所述用户栈切换为中断栈;a stack switching subunit, configured to switch from the user stack to an interrupt stack;
中断响应子单元,用于从所述共享存储区中读取所述中断请求,并基于所述中断栈进行中断响应;An interrupt response subunit, configured to read the interrupt request from the shared memory area, and perform an interrupt response based on the interrupt stack;
第二恢复子单元,用于在所述中断响应结束后,恢复所述被中断的任务或另一个需要优先调度的任务。And a second recovery subunit, configured to resume the interrupted task or another task that needs to be scheduled after the end of the interrupt response.
结合第一方面的第三种可能的实施方式,在第四种可能的实施方式中,所述请求响应单元,还包括:In conjunction with the third possible implementation of the first aspect, in a fourth possible implementation, the request response unit further includes:
替换子单元,用于将所述用户栈中保存的所述第二用户态指令位置,替换 为所述共享存储区的第二存储位置中保存的所述第一用户态指令位置;a replacement subunit, configured to replace the second user state instruction location saved in the user stack The first user state instruction location saved in the second storage location of the shared storage area;
所述第二恢复子单元,用于通过所述用户栈中保存的所述运行现场,恢复所述被中断的任务。The second recovery subunit is configured to recover the interrupted task by using the running site saved in the user stack.
结合第一方面或第一方面的第一种可能的实施方式或第一方面的第二种可能的实施方式或第一方面的第三种可能的实施方式或第一方面的第四种可能的实施方式,在第五种可能的实施方式中,所述任务处理模块,包括:Combining the first aspect or the first possible implementation of the first aspect or the second possible implementation of the first aspect or the third possible implementation of the first aspect or the fourth possible implementation of the first aspect In an embodiment, in a fifth possible implementation, the task processing module includes:
任务切换单元,用于当从第一任务切换至第二任务时,通过所述操作系统保存被中断的所述第一任务的运行现场,所述第一任务的运行现场包括寄存器信息、第三用户态指令位置和所述第一任务的锁中断信息;a task switching unit, configured to save, by the operating system, an operation site of the interrupted first task when switching from the first task to the second task, where the operation site of the first task includes register information, and a third a user state instruction location and a lock interruption information of the first task;
第一获取单元,用于通过所述操作系统获取所述第二任务的运行现场,所述第二任务的运行现场包括寄存器信息、第四用户态指令位置和所述第二任务的锁中断信息;a first acquiring unit, configured to acquire, by using the operating system, an operating site of the second task, where the operating site of the second task includes register information, a fourth user state command location, and a lock interruption information of the second task ;
第一恢复单元,通过所述操作系统根据所述第二任务的运行现场恢复所述第二任务并处理。The first recovery unit recovers the second task and processes according to the operating site of the second task by the operating system.
结合第一方面或第一方面的第一种可能的实施方式或第一方面的第二种可能的实施方式或第一方面的第三种可能的实施方式或第一方面的第四种可能的实施方式,在第六种可能的实施方式中,所述任务处理模块,包括:Combining the first aspect or the first possible implementation of the first aspect or the second possible implementation of the first aspect or the third possible implementation of the first aspect or the fourth possible implementation of the first aspect In an embodiment, in a sixth possible implementation, the task processing module includes:
任务检测单元,用于在一次中断响应结束时,通过所述操作系统检测是否存在需要优先调度的第三任务;a task detecting unit, configured to detect, by the operating system, whether there is a third task that needs to be preferentially scheduled when an interrupt response ends;
第二获取单元,用于当存在所述第三任务时,通过所述操作系统获取所述第三任务的运行现场,所述第三任务的运行现场包括寄存器信息、第五用户态指令位置和所述第三任务的锁中断信息;a second obtaining unit, configured to acquire, by the operating system, an operation site of the third task when the third task exists, where the running site of the third task includes a register information, a fifth user state instruction location, and The lock interruption information of the third task;
第二恢复单元,用于通过所述操作系统根据所述第三任务的运行现场恢复所述第三任务并处理。And a second recovery unit, configured to recover the third task and process according to the operating site of the third task by using the operating system.
根据本发明的第二方面,提供了一种电子设备,所述电子设备包括:处理器和存储器;According to a second aspect of the present invention, an electronic device is provided, the electronic device comprising: a processor and a memory;
所述存储器用于存储一个或者一个以上的指令,所述指令用于实现一种任务处理方法;The memory is configured to store one or more instructions for implementing a task processing method;
所述方法令包括:The method order includes:
在用户层运行至少一个线程; Running at least one thread at the user level;
在所述线程中运行操作系统,所述操作系统用于处理任务;Running an operating system in the thread, the operating system for processing a task;
在处理所述任务的过程中,通过所述线程中的所述操作系统进行中断响应和/或任务调度;Interrupting response and/or task scheduling by the operating system in the thread during processing of the task;
所述处理器用于执行所述指令。The processor is operative to execute the instructions.
在第二方面的第一种可能的实施方式中,还存储有用于执行以下操作的指令:In a first possible implementation of the second aspect, instructions for performing the following operations are also stored:
通过内核层接收中断源的中断请求;Receiving an interrupt request of an interrupt source through a kernel layer;
通过所述内核层将所述中断请求传输给所述用户层中对应的线程的操作系统;Transmitting the interrupt request to an operating system of a corresponding thread in the user layer by the kernel layer;
通过所述用户层中对应的线程的操作系统的中断处理程序对所述中断请求进行中断响应;Interrupting the interrupt request by an interrupt processing program of an operating system of a corresponding thread in the user layer;
所述处理器用于执行所述指令。The processor is operative to execute the instructions.
结合第二方面的第一种可能的实施方式,在第二种可能的实施方式中,还存储有用于执行以下操作的指令:In conjunction with the first possible implementation of the second aspect, in a second possible implementation, instructions for performing the following operations are also stored:
在所述内核层的核心栈中保存被中断的线程的运行现场,所述运行现场包括第一用户态指令位置;Saving an operation site of the interrupted thread in a core stack of the kernel layer, the operation site including a first user state instruction location;
将所述第一用户态指令位置从所述核心栈中的第一存储位置转移到共享存储区中的第二存储位置进行存储,并将所述中断请求存储到所述共享存储区中的第三存储位置;Transferring the first user state instruction location from a first storage location in the core stack to a second storage location in a shared storage area for storage, and storing the interrupt request in the shared storage area Three storage locations;
在所述核心栈中的第一存储位置中存储所述被中断的线程的所述操作系统中的中断处理程序的起始指令位置;Storing a start instruction location of an interrupt handler in the operating system of the interrupted thread in a first storage location in the core stack;
退出所述内核层对所述中断请求的响应;Exiting the kernel layer's response to the interrupt request;
所述处理器用于执行所述指令。The processor is operative to execute the instructions.
结合第二方面的第二种可能的实施方式中,在第三种可能的实施方式中,所述存储器还存储有用于执行以下操作的指令:In conjunction with the second possible implementation of the second aspect, in a third possible implementation, the memory further stores instructions for performing the following operations:
在恢复所述被中断的线程时,从所述核心栈的第一存储位置读取所述操作系统的中断处理程序的起始指令位置;Reading the initial instruction location of the interrupt handler of the operating system from the first storage location of the core stack when the interrupted thread is restored;
在所述线程的用户栈保存被中断的任务的运行现场,所述运行现场包括第二用户态指令位置;A user site of the thread saves an operation site of the interrupted task, the operation site including a second user state instruction location;
从所述用户栈切换为中断栈;Switching from the user stack to an interrupt stack;
从所述共享存储区中读取所述中断请求,并基于所述中断栈进行中断响 应;Reading the interrupt request from the shared memory area and performing an interrupt based on the interrupt stack should;
在所述中断响应结束后,恢复所述被中断的任务或另一个需要优先调度的任务;After the interrupt response ends, recovering the interrupted task or another task requiring priority scheduling;
所述处理器用于执行所述指令。The processor is operative to execute the instructions.
结合第二方面的第三种可能的实施方式中,在第四种可能的实施方式中,还存储有用于执行以下操作的指令:In conjunction with the third possible implementation of the second aspect, in a fourth possible implementation, an instruction for performing the following operations is also stored:
将所述用户栈中保存的所述第二用户态指令位置,替换为所述共享存储区的第二存储位置中保存的所述第一用户态指令位置;Replacing the second user state instruction location saved in the user stack with the first user state instruction location saved in the second storage location of the shared storage area;
通过所述用户栈中保存的所述运行现场,恢复所述被中断的任务;Recovering the interrupted task by the running site saved in the user stack;
所述处理器用于执行所述指令。The processor is operative to execute the instructions.
结合第二方面或第二方面的第一种可能的实施方式或第二方面的第二种可能的实施方式或第二方面的第三种可能的实施方式或第二方面的第四种可能的实施方式,在第五种可能的实施方式中,还存储有用于执行以下操作的指令:Combining the second aspect or the first possible implementation of the second aspect or the second possible implementation of the second aspect or the third possible implementation of the second aspect or the fourth possible implementation of the second aspect Embodiments, in a fifth possible implementation, an instruction for performing the following operations is also stored:
当从第一任务切换至第二任务时,通过所述操作系统保存被中断的所述第一任务的运行现场,所述第一任务的运行现场包括寄存器信息、第三用户态指令位置和所述第一任务的锁中断信息;When the first task is switched to the second task, the operating site of the interrupted first task is saved by the operating system, and the running site of the first task includes register information, a third user state command location, and a location The lock interrupt information of the first task;
通过所述操作系统获取所述第二任务的运行现场,所述第二任务的运行现场包括寄存器信息、第四用户态指令位置和所述第二任务的锁中断信息;Obtaining, by the operating system, an operation site of the second task, where the operation site of the second task includes register information, a fourth user state instruction location, and lock interruption information of the second task;
通过所述操作系统根据所述第二任务的运行现场恢复所述第二任务并处理;Recovering and processing the second task according to the operating site of the second task by the operating system;
所述处理器还用于执行所述指令。The processor is also operative to execute the instructions.
结合第二方面或第二方面的第一种可能的实施方式或第二方面的第二种可能的实施方式或第二方面的第三种可能的实施方式或第二方面的第四种可能的实施方式,在第六种可能的实施方式中,还存储有用于执行以下操作的指令:Combining the second aspect or the first possible implementation of the second aspect or the second possible implementation of the second aspect or the third possible implementation of the second aspect or the fourth possible implementation of the second aspect Embodiments, in a sixth possible implementation, an instruction for performing the following operations is also stored:
在一次中断响应结束时,通过所述操作系统检测是否存在需要优先调度的第三任务;At the end of an interrupt response, the operating system detects whether there is a third task requiring priority scheduling;
当存在所述第三任务时,通过所述操作系统获取所述第三任务的运行现场,所述第三任务的运行现场包括寄存器信息、第五用户态指令位置和所述第三任务的锁中断信息; When the third task exists, the operating site of the third task is acquired by the operating system, and the running site of the third task includes register information, a fifth user state command location, and a lock of the third task. Interrupt information;
通过所述操作系统根据所述第三任务的运行现场恢复所述第三任务并处理;Recovering and processing the third task according to the operating site of the third task by the operating system;
所述处理器还用于执行所述指令。The processor is also operative to execute the instructions.
根据本发明实施例的第三方面,提供了一种任务处理方法,所述方法包括:According to a third aspect of the embodiments of the present invention, a task processing method is provided, the method comprising:
在用户层运行至少一个线程;Running at least one thread at the user level;
在所述线程中运行操作系统,所述操作系统用于处理任务;Running an operating system in the thread, the operating system for processing a task;
在处理所述任务的过程中,通过所述线程中的所述操作系统进行中断响应和/或任务调度。In the process of processing the task, an interrupt response and/or task scheduling is performed by the operating system in the thread.
在第三方面的第一种可能的实施方式中,所述在处理所述任务的过程中,通过所述线程中的所述操作系统进行中断响应,包括:In a first possible implementation manner of the third aspect, in the process of processing the task, performing an interrupt response by using the operating system in the thread, including:
通过内核层接收中断源的中断请求;Receiving an interrupt request of an interrupt source through a kernel layer;
通过所述内核层将所述中断请求传输给所述用户层中对应的线程的操作系统;Transmitting the interrupt request to an operating system of a corresponding thread in the user layer by the kernel layer;
通过所述用户层中对应的线程的操作系统的中断处理程序对所述中断请求进行中断响应。The interrupt request is interrupted by an interrupt handler of an operating system of a corresponding thread in the user layer.
结合第三方面的第一种可能的实施方式,在第二种可能的实施方式中,所述通过所述内核层将所述中断请求传输给所述用户层中对应的所述线程的所述操作系统,包括:In conjunction with the first possible implementation of the third aspect, in a second possible implementation, the transmitting, by the kernel layer, the interrupt request to the corresponding one of the user layers Operating system, including:
在所述内核层的核心栈中保存被中断的线程的运行现场,所述运行现场包括第一用户态指令位置;Saving an operation site of the interrupted thread in a core stack of the kernel layer, the operation site including a first user state instruction location;
将所述第一用户态指令位置从所述核心栈中的第一存储位置转移到共享存储区中的第二存储位置进行存储,并将所述中断请求存储到所述共享存储区中的第三存储位置,所述共享存储区为所述内核层和所述用户层均能访问的存储区;Transferring the first user state instruction location from a first storage location in the core stack to a second storage location in a shared storage area for storage, and storing the interrupt request in the shared storage area a storage location, where the shared storage area is a storage area accessible by both the kernel layer and the user layer;
在所述核心栈中的第一存储位置中存储所述被中断的线程的所述操作系统中的中断处理程序的起始指令位置;Storing a start instruction location of an interrupt handler in the operating system of the interrupted thread in a first storage location in the core stack;
退出所述内核层对所述中断请求的响应。Exiting the kernel layer's response to the interrupt request.
结合第三方面的第二种可能的实施方式,在第三种可能的实施方式中,所述通过所述操作系统中的中断处理程序对所述中断请求进行中断响应,包括:With the second possible implementation of the third aspect, in a third possible implementation, the interrupt request is interrupted by an interrupt processing program in the operating system, including:
在恢复所述被中断的线程时,从所述核心栈的第一存储位置读取所述操作系统的中断处理程序的起始指令位置; Reading the initial instruction location of the interrupt handler of the operating system from the first storage location of the core stack when the interrupted thread is restored;
在所述线程的用户栈保存被中断的任务的运行现场,所述运行现场包括第二用户态指令位置;A user site of the thread saves an operation site of the interrupted task, the operation site including a second user state instruction location;
从所述用户栈切换为中断栈;Switching from the user stack to an interrupt stack;
从所述共享存储区中读取所述中断请求,并基于所述中断栈进行中断响应;Reading the interrupt request from the shared storage area, and performing an interrupt response based on the interrupt stack;
在所述中断响应结束后,恢复所述被中断的任务或另一个需要优先调度的任务。After the interrupt response ends, the interrupted task or another task requiring prioritization is resumed.
结合第三方面的第三种可能的实施方式,在第四种可能的实施方式中,所述从所述用户栈切换为中断栈之前,还包括:In conjunction with the third possible implementation of the third aspect, in a fourth possible implementation, before the switching from the user stack to the interrupt stack, the method further includes:
将所述用户栈中保存的所述第二用户态指令位置,替换为所述共享存储区的第二存储位置中保存的所述第一用户态指令位置;Replacing the second user state instruction location saved in the user stack with the first user state instruction location saved in the second storage location of the shared storage area;
所述在所述中断响应结束后,恢复所述被中断的任务,包括:Recovering the interrupted task after the interrupt response ends, including:
通过所述用户栈中保存的所述运行现场,恢复所述被中断的任务。The interrupted task is resumed by the running site saved in the user stack.
结合第三方面或第三方面的第一种可能的实施方式或第三方面的第二种可能的实施方式或第三方面的第三种可能的实施方式或第三方面的第四种可能的实施方式,在第五种可能的实施方式中,所述在执行所述任务的过程中,通过所述线程中的所述操作系统进行任务调度,包括:Combining the third aspect or the first possible implementation of the third aspect or the second possible implementation of the third aspect or the third possible implementation of the third aspect or the fourth possible aspect of the third aspect Embodiments, in a fifth possible implementation manner, in the process of performing the task, performing task scheduling by using the operating system in the thread, including:
当从第一任务切换至第二任务时,通过所述操作系统保存被中断的所述第一任务的运行现场,所述第一任务的运行现场包括寄存器信息、第三用户态指令位置和所述第一任务的锁中断信息;When the first task is switched to the second task, the operating site of the interrupted first task is saved by the operating system, and the running site of the first task includes register information, a third user state command location, and a location The lock interrupt information of the first task;
通过所述操作系统获取所述第二任务的运行现场,所述第二任务的运行现场包括寄存器信息、第四用户态指令位置和所述第二任务的锁中断信息;Obtaining, by the operating system, an operation site of the second task, where the operation site of the second task includes register information, a fourth user state instruction location, and lock interruption information of the second task;
通过所述操作系统根据所述第二任务的运行现场恢复所述第二任务并处理。And recovering, by the operating system, the second task according to the running site of the second task and processing.
结合第三方面或第三方面的第一种可能的实施方式或第三方面的第二种可能的实施方式或第三方面的第三种可能的实施方式或第四种可能的实施方式,在第六种可能的实施方式中,所述在执行所述任务的过程中,通过所述线程中的所述操作系统进行任务调度,包括:With reference to the third aspect or the first possible implementation of the third aspect or the second possible implementation of the third aspect or the third possible implementation or the fourth possible implementation of the third aspect, In a sixth possible implementation manner, in the process of performing the task, performing task scheduling by using the operating system in the thread, including:
在一次中断响应结束时,通过所述操作系统检测是否存在需要优先调度的第三任务;At the end of an interrupt response, the operating system detects whether there is a third task requiring priority scheduling;
当存在所述第三任务时,通过所述操作系统获取所述第三任务的运行现 场,所述第三任务的运行现场包括寄存器信息、第五用户态指令位置和所述第三任务的锁中断信息;Obtaining, by the operating system, the running of the third task when the third task exists Field, the operation site of the third task includes register information, a fifth user state instruction location, and lock interruption information of the third task;
通过所述操作系统根据所述第三任务的运行现场恢复所述第三任务并处理。And recovering, by the operating system, the third task according to an operation site of the third task and processing.
本发明实施例提供的技术方案的有益效果是:The beneficial effects of the technical solutions provided by the embodiments of the present invention are:
通过在用户层的线程中运行操作系统,以进行中断响应和/或任务调度;解决了中断响应过程和任务调度过程需要多次切换至Linux内核层中进行处理,导致单次的中断响应过程和任务调度过程的延时较大,影响了任务处理过程的实时性;达到了在用户层中直接完成中断响应和/或任务调度,不需要多次切换至内核层进行处理,减少中断响应和/或任务调度的耗时,提高了任务处理时的实时性,同时还可以降低内核层的负载的效果。By running the operating system in the thread of the user layer for interrupt response and/or task scheduling; solving the interrupt response process and the task scheduling process need to switch to the Linux kernel layer for processing, resulting in a single interrupt response process and The delay of the task scheduling process is large, which affects the real-time behavior of the task processing. It achieves the interrupt response and/or task scheduling directly in the user layer. It does not need to switch to the kernel layer for processing, reducing the interrupt response and / Or the time-consuming task scheduling improves the real-time performance of the task processing, and also reduces the load of the kernel layer.
附图说明DRAWINGS
为了更清楚地说明现有技术或者本发明实施例中的技术方案,下面将对实施例描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to more clearly illustrate the prior art or the technical solutions in the embodiments of the present invention, the drawings used in the description of the embodiments will be briefly described below. It is obvious that the drawings in the following description are only the present invention. For some embodiments, other drawings may be obtained from those of ordinary skill in the art without departing from the drawings.
图1是一种采用Linux操作系统来处理高实时性业务的架构示意图;FIG. 1 is a schematic diagram of an architecture using a Linux operating system to process high real-time services;
图2是本发明一个实施例提供的任务处理装置的结构方框图;2 is a block diagram showing the structure of a task processing apparatus according to an embodiment of the present invention;
图3A是本发明另一实施例提供的任务处理装置的结构方框图;FIG. 3 is a block diagram showing the structure of a task processing apparatus according to another embodiment of the present invention; FIG.
图3B是图3A所提供的请求传输单元的结构方框图;FIG. 3B is a block diagram showing the structure of the request transmission unit provided in FIG. 3A; FIG.
图3C是图3A所提供的请求响应单元的结构方框图;FIG. 3C is a structural block diagram of the request response unit provided in FIG. 3A; FIG.
图4是本发明再一实施例提供的任务处理装置的结构方框图;4 is a block diagram showing the structure of a task processing apparatus according to still another embodiment of the present invention;
图5A是本发明一个实施例提供的电子设备的结构方框图;FIG. 5 is a block diagram showing the structure of an electronic device according to an embodiment of the present invention; FIG.
图5B是本发明另一个实施例提供的电子设备的结构方框图;FIG. 5B is a structural block diagram of an electronic device according to another embodiment of the present invention; FIG.
图6A和图6B分别示出了本发明实施例提供的任务处理方法所涉及的一种电子设备的结构示意图;6A and FIG. 6B are schematic diagrams showing the structure of an electronic device according to the task processing method provided by the embodiment of the present invention;
图7是本发明一个实施例提供的任务处理方法的方法流程图;7 is a flowchart of a method for processing a task according to an embodiment of the present invention;
图8是本发明另一个实施例提供的任务处理方法的方法流程图;FIG. 8 is a flowchart of a method for processing a task according to another embodiment of the present invention; FIG.
图9是图8所示实施例中提供的任务处理方法的子步骤流程图;9 is a flow chart showing the sub-steps of the task processing method provided in the embodiment shown in FIG. 8;
图10是图8所示实施例中提供的任务处理方法的子步骤流程图 10 is a flow chart of sub-steps of the task processing method provided in the embodiment shown in FIG.
图11是本发明再一个实施例提供的任务处理方法的方法流程图;11 is a flowchart of a method for processing a task according to still another embodiment of the present invention;
图12是图11所示实施例中提供的任务处理方法的子步骤流程图;Figure 12 is a flow chart showing the sub-steps of the task processing method provided in the embodiment shown in Figure 11;
图13是图11所示实施例中提供的任务处理方法的子步骤流程图。FIG. 13 is a flow chart showing the sub-steps of the task processing method provided in the embodiment shown in FIG.
具体实施方式detailed description
为使本发明的目的、技术方案和优点更加清楚,下面将结合附图对本发明实施方式作进一步地详细描述。The embodiments of the present invention will be further described in detail below with reference to the accompanying drawings.
首先对本发明实施例涉及的若干名词进行简介:Firstly, some nouns related to the embodiments of the present invention are introduced:
硬件层:硬件层是电子设备中的硬件基础,通常包括处理器(英文:Central Processing Unit,缩写:CPU)和存储器,处理器可以是单核心处理器,也可以是多核心处理器。该电子设备可以是基站设备、传输设备、工业机器人等对任务处理的实时性有一定要求的电子设备。在全球移动通信系统(英文:Global System for Mobile Communication,缩写:GSM)系统中,基站设备可以是基站收发信台(英文:Base Transmitter Station,缩写:BTS);在第三代(英文:3rd-Generation,缩写:3G)移动通信技术中,基站设备可以是节点B(英文:Node Base station,缩写:Node B);在第四代(英文:the 4Generation,缩写:4G)移动通信技术中,基站设备可以是演进型节点B(英文:Evolved Node Base station,缩写:eNB)。Hardware layer: The hardware layer is the hardware foundation in the electronic device. It usually includes a processor (Central: Central Processing Unit, CPU) and memory. The processor can be a single core processor or a multi-core processor. The electronic device may be an electronic device that has certain requirements for real-time processing of tasks, such as a base station device, a transmission device, and an industrial robot. In the Global System for Mobile Communication (GSM) system, the base station equipment can be a base transceiver station (English: Base Transmitter Station, abbreviation: BTS); in the third generation (English: 3rd- Generation, abbreviation: 3G) In mobile communication technology, the base station equipment can be Node B (English: Node Base station, abbreviation: Node B); in the fourth generation (English: the 4Generation, abbreviation: 4G) mobile communication technology, the base station The device may be an evolved Node B (English: Evolved Node Base station, abbreviation: eNB).
内核层和用户层:内核层是操作系统内核、虚拟存储空间和驱动应用程序运行的层;用户层是普通应用程序运行的层。Kernel and User Layers: The kernel layer is the operating system kernel, virtual storage space, and the layer that drives the application to run; the user layer is the layer in which normal applications run.
中断:中断是指计算机在执行期间,系统内发生任何非寻常的或非预期的急需处理事件,使得处理器暂时中断当前正在执行的程序而转去执行相应的事件处理程序,待处理完毕后又返回原来被中断处继续执行或调度新的进程执行的过程。引起中断发生的事件被称为中断源。中断源向处理器发出的请求中断处理信号称为中断请求。处理器对中断请求进行处理的过程称为中断响应。Interrupt: Interrupt refers to any unusual or unexpected urgent need to be processed in the system during the execution of the computer, so that the processor temporarily interrupts the currently executing program and then goes to execute the corresponding event handler. After the processing is completed, Returns the process of continuing execution or scheduling a new process execution. The event that caused the interrupt to occur is called the interrupt source. The request interrupt processing signal sent by the interrupt source to the processor is called an interrupt request. The process by which a processor processes an interrupt request is called an interrupt response.
核心栈:操作系统内核所使用的栈。Core stack: The stack used by the operating system kernel.
用户栈:每个线程有1个自身所使用的用户栈,该线程可以是实时线程或普通线程。User stack: Each thread has a user stack used by itself, which can be a real-time thread or a normal thread.
请参考图2,其示出了本发明一个实施例提供的任务处理装置的结构方框图。该任务处理装置可以通过软件、硬件或者两者的结合实现成为电子设备的 全部或部分。该任务处理装置包括:第一运行模块220、第二运行模块240和任务处理模块260。Please refer to FIG. 2, which is a structural block diagram of a task processing apparatus according to an embodiment of the present invention. The task processing device can be implemented as an electronic device by software, hardware, or a combination of both All or part. The task processing device includes a first running module 220, a second running module 240, and a task processing module 260.
第一运行模块220,用于在用户层运行至少一个线程。The first running module 220 is configured to run at least one thread at the user layer.
第二运行模块240,用于在线程中运行操作系统,该操作系统用于处理任务。每个线程中可以运行有一个操作系统,该操作系统用于处理任务。该操作系统需要具有独立完成中断响应和/或任务调度的功能。不同的线程中可以运行相同类型的操作系统,不同的线程中也可以运行不同类型的操作系统。本发明实施例对上述操作系统的类型不做特别限定。The second running module 240 is configured to run an operating system in the thread, where the operating system is used to process the task. There can be one operating system running in each thread, which is used to process tasks. The operating system needs to have the ability to independently perform interrupt response and/or task scheduling. Different types of threads can run the same type of operating system, and different types of operating systems can be run in different threads. The type of the above operating system is not particularly limited in the embodiment of the present invention.
任务是泛指操作系统可以处理的任务。在电子设备是基站设备时,任务可以是下发调度指令的任务、分配信道资源的任务、处理接入请求的任务等等。Tasks are generic tasks that the operating system can handle. When the electronic device is a base station device, the task may be a task of issuing a scheduling instruction, a task of allocating a channel resource, a task of processing an access request, and the like.
任务处理模块260,用于在处理任务的过程中,通过线程中的操作系统进行中断响应和/或任务调度。The task processing module 260 is configured to perform an interrupt response and/or task scheduling by an operating system in the thread during the processing of the task.
综上所述,本实施例提供的任务处理装置,通过线程中的操作系统进行中断响应和/或任务调度;解决了中断响应过程和任务调度过程需要多次切换至Linux内核层中进行处理,导致单次的中断响应过程和任务调度过程的延时较大,影响了任务处理过程的实时性;达到了在用户层中直接完成中断响应和/或任务调度,不需要多次切换至内核层进行处理,减少中断响应和/或任务调度的耗时,提高了任务处理时的实时性的效果。In summary, the task processing apparatus provided in this embodiment performs interrupt response and/or task scheduling through an operating system in a thread; and solves the interrupt response process and the task scheduling process, which requires multiple switching to the Linux kernel layer for processing. The delay of the single interrupt response process and the task scheduling process is large, which affects the real-time behavior of the task processing; the interrupt response and/or task scheduling are directly completed in the user layer, and it is not necessary to switch to the kernel layer multiple times. Processing, reducing the time consuming of interrupt response and/or task scheduling, improves the real-time effect of task processing.
同时,由于背景技术中的中断响应和/或任务调度都是由内核层来进行,所以内核层的负载较高,本实施例提供的任务处理方法还可以达到降低内核层的负载的效果。At the same time, since the interrupt response and/or task scheduling in the background technology are performed by the kernel layer, the load of the kernel layer is high, and the task processing method provided in this embodiment can also achieve the effect of reducing the load of the kernel layer.
请参考图3A,其示出了本发明另一实施例提供的任务处理装置的结构方框图。该任务处理装置可以通过软件、硬件或者两者的结合实现成为电子设备的全部或部分。该任务处理装置包括:第一运行模块220,用于在用户层运行至少一个线程。Please refer to FIG. 3A, which is a structural block diagram of a task processing apparatus according to another embodiment of the present invention. The task processing device can be implemented as all or part of an electronic device by software, hardware, or a combination of both. The task processing apparatus includes a first execution module 220 for running at least one thread at the user layer.
第一运行模块220,用于在用户层运行至少一个线程。The first running module 220 is configured to run at least one thread at the user layer.
第二运行模块240,用于在第一运行模块220运行的线程中运行操作系统,该操作系统用于处理任务。The second running module 240 is configured to run an operating system in a thread running by the first running module 220, where the operating system is used to process a task.
任务处理模块260,用于在处理任务的过程中,通过第二运行模块240在线程中运行的操作系统进行中断响应。 The task processing module 260 is configured to perform an interrupt response by the operating system running in the thread by the second running module 240 during the processing of the task.
在本实施例中,任务处理模块260,包括:In this embodiment, the task processing module 260 includes:
请求接收单元261,用于通过内核层接收中断源的中断请求。The request receiving unit 261 is configured to receive an interrupt request of the interrupt source through the kernel layer.
请求传输单元262,用于通过内核层将请求接收单元261接收到的中断请求传输给第二运行模块240运行的用户层中对应的线程的操作系统。The request transmission unit 262 is configured to transmit, by the kernel layer, the interrupt request received by the request receiving unit 261 to the operating system of the corresponding thread in the user layer run by the second running module 240.
请求响应单元263,用于通过用户层中对应的线程的操作系统的中断处理程序对请求传输单元262接收到的中断请求进行中断响应。The request response unit 263 is configured to perform an interrupt response to the interrupt request received by the request transmission unit 262 by an interrupt processing program of an operating system of a corresponding thread in the user layer.
结合图3B所示,请求传输单元262可以包括:As shown in FIG. 3B, the request transmission unit 262 may include:
第一保存子单元262a,用于在内核层的核心栈中保存被中断的线程的运行现场,该运行现场包括第一用户态指令位置。The first save subunit 262a is configured to save an operation site of the interrupted thread in a core stack of the kernel layer, where the run site includes a first user state instruction location.
转移子单元262b,用于将第一保存子单元262a保存的第一用户态指令位置从核心栈中的第一存储位置转移到共享存储区中的第二存储位置进行存储,并将请求接收单元261接收到的中断请求存储到共享存储区中的第三存储位置,共享存储区为内核层和用户层均能访问的存储区。The transfer subunit 262b is configured to transfer the first user state instruction location saved by the first save subunit 262a from the first storage location in the core stack to the second storage location in the shared storage area for storage, and the request receiving unit The received interrupt request is stored in a third storage location in the shared storage area, and the shared storage area is a storage area accessible by both the kernel layer and the user layer.
中断存储子单元262c,用于在转移子单元262b将第一用户态指令位置从核心栈中的第一存储位置转移到共享存储区中的第二存储位置进行存储之后,在核心栈中的第一存储位置中存储被中断的线程的操作系统中的中断处理程序的起始指令位置。The interrupt storage sub-unit 262c is configured to transfer the first user state instruction position from the first storage location in the core stack to the second storage location in the shared storage area after the transfer sub-unit 262b is stored, in the core stack The starting instruction location of the interrupt handler in the operating system that stores the interrupted thread in a storage location.
退出子单元262d,用于在中断存储子单元262c在核心栈中的第一存储位置中存储起始指令位置之后,退出内核层对中断请求的响应。The exit sub-unit 262d is configured to exit the kernel layer response to the interrupt request after the interrupt storage sub-unit 262c stores the start instruction position in the first storage location in the core stack.
结合图3C所示,请求响应单元263可以包括:As shown in FIG. 3C, the request response unit 263 may include:
第一恢复子单元263a,用于在退出子单元262d退出内核层对中断请求的响应后,在恢复被中断的线程时,从核心栈的第一存储位置读取操作系统的中断处理程序的起始指令位置。The first recovery subunit 263a is configured to: after the exit subunit 262d exits the kernel layer response to the interrupt request, read the interrupt handler of the operating system from the first storage location of the core stack when restoring the interrupted thread Start command position.
第二保存子单元263b,用于在第一恢复子单元263a恢复的线程的用户栈保存被中断的任务的运行现场,该运行现场包括第二用户态指令位置。The second save subunit 263b, the user stack of the thread for recovery at the first recovery subunit 263a saves the run site of the interrupted task, the run site including the second user state command location.
栈切换子单元263c,用于从第二保存子单元263b所使用的用户栈切换为中断栈。The stack switching sub-unit 263c is configured to switch from the user stack used by the second saving sub-unit 263b to the interrupt stack.
中断响应子单元263d,用于从共享存储区中读取中断请求,并基于栈切换子单元263c切换至的中断栈进行中断响应。The interrupt response sub-unit 263d is configured to read an interrupt request from the shared memory area and perform an interrupt response based on the interrupt stack to which the stack switching sub-unit 263c is switched.
第二恢复子单元263e,用于在中断响应子单元263d中断响应结束后,恢复被中断的任务或另一个需要优先调度的任务。 The second recovery sub-unit 263e is configured to resume the interrupted task or another task requiring priority scheduling after the interrupt response sub-unit 263d interrupts the response.
其中,请求响应单元263,还可以包括:The request response unit 263 may further include:
替换子单元263f,用于将第二保存子单元263b在用户栈中保存的第二用户态指令位置,替换为共享存储区的第二存储位置中保存的第一用户态指令位置;a replacement subunit 263f, configured to replace the second user state instruction location saved in the user stack by the second save subunit 263b with the first user state instruction location saved in the second storage location of the shared storage area;
第二恢复子单元263e,用于通过用户栈中保存的运行现场,恢复被中断的任务,该运行现场由第二保存子单元263b保存,并被替换子单元263f将其中的第二用户态指令位置替换为第一用户态指令位置。The second recovery subunit 263e is configured to recover the interrupted task by using the running scene saved in the user stack, the running scene is saved by the second saving subunit 263b, and the second user state instruction is replaced by the replacing subunit 263f. The position is replaced with the first user mode command position.
综上所述,本实施例提供的任务处理装置,通过在线程中运行操作系统,通过线程中的操作系统进行中断处理;解决了中断处理过程需要多次切换至Linux内核层实现,导致单次中断处理过程的延时较大,影响了任务处理过程的实时性的问题;达到了在用户层中直接完成中断处理,不需要多次切换至内核层进行处理,减少中断处理的耗时,提高了任务处理时的实时性。In summary, the task processing apparatus provided in this embodiment performs interrupt processing by using an operating system in a thread by running an operating system in a thread; and the interrupt processing process needs to be switched to the Linux kernel layer multiple times, resulting in a single operation. The delay of the interrupt processing process is large, which affects the real-time problem of the task processing process; the interrupt processing is completed directly in the user layer, and it is not necessary to switch to the kernel layer for processing, reducing the time-consuming processing of the interrupt processing and improving The real-time nature of the task processing.
同时,由于背景技术中的中断响应是由内核层来进行,所以内核层的负载较高,本实施例提供的任务处理装置还可以达到降低内核层的负载的效果。At the same time, since the interrupt response in the background art is performed by the kernel layer, the load of the kernel layer is high, and the task processing apparatus provided in this embodiment can also achieve the effect of reducing the load of the kernel layer.
本实施例提供的任务处理装置,还通过内核层将中断请求存储在共享存储区,在用户层的线程恢复后,从共享存储区获取该中断请求,使得内核层可以将中断请求上报给线程,由线程中的操作系统对该中断请求进行处理。The task processing apparatus provided by the embodiment further stores the interrupt request in the shared storage area through the kernel layer, and after the thread of the user layer is restored, acquires the interrupt request from the shared storage area, so that the kernel layer can report the interrupt request to the thread. The interrupt request is processed by the operating system in the thread.
本实施例提供的任务处理装置,还通过将核心栈中的第一用户态指令位置,替换为操作系统的中断处理程序的起始指令位置,使得用户层的线程恢复后,并不是进入被中断的第一用户态指令位置继续运行,而是强制跳转到了操作系统中的中断处理程序,没有延时就直接进入了中断响应过程,实现了中断请求的快速上报并响应的效果。The task processing apparatus provided in this embodiment further replaces the first user state instruction position in the core stack with the start instruction position of the interrupt processing program of the operating system, so that the thread of the user layer is restored, and the entry is not interrupted. The first user state instruction position continues to run, but forcibly jumps to the interrupt handler in the operating system, and enters the interrupt response process without delay, realizing the effect of fast reporting and response of the interrupt request.
本实施例提供的任务处理装置,还通过由操作系统的中断处理程序独立完成中断响应,该过程中不需要多次切换至内核层进行处理,达到了完整的一次中断响应过程的耗时非常小的效果。The task processing apparatus provided in this embodiment also independently completes the interrupt response by the interrupt processing program of the operating system, and does not need to switch to the kernel layer for processing in the process, and the time required to complete the complete interrupt response process is very small. Effect.
请参考图4,其示出了本发明另一实施例提供的任务处理装置的结构方框图。该任务处理装置可以通过软件、硬件或者两者的结合实现成为电子设备的全部或部分。该任务处理装置可以包括:Please refer to FIG. 4, which is a structural block diagram of a task processing apparatus according to another embodiment of the present invention. The task processing device can be implemented as all or part of an electronic device by software, hardware, or a combination of both. The task processing device can include:
第一运行模块220,用于在用户层运行至少一个线程。The first running module 220 is configured to run at least one thread at the user layer.
第二运行模块240,用于在第一运行模块220运行的线程中运行操作系统, 该操作系统用于处理任务。a second running module 240, configured to run an operating system in a thread running by the first running module 220, This operating system is used to process tasks.
任务处理模块260,用于在处理任务的过程中,通过第二运行模块240在线程中运行的操作系统进行任务调度。The task processing module 260 is configured to perform task scheduling by the operating system running in the thread by the second running module 240 during the processing of the task.
在本实施例中,任务处理模块260,可以包括:In this embodiment, the task processing module 260 may include:
任务切换单元264,用于当从第一任务切换至第二任务时,通过第二运行模块240运行的操作系统保存被中断的第一任务的运行现场,第一任务的运行现场包括寄存器信息、第三用户态指令位置和第一任务的锁中断信息。The task switching unit 264 is configured to: when the first task is switched to the second task, the operating system running by the second running module 240 saves the running site of the interrupted first task, where the running site of the first task includes register information, The third user mode instruction location and the lock interruption information of the first task.
第一获取单元265,用于在任务切换单元264保存被中断的第一任务的运行现场后,通过操作系统获取第二任务的运行现场,第二任务的运行现场包括寄存器信息、第四用户态指令位置和第二任务的锁中断信息。The first obtaining unit 265 is configured to obtain, after the task switching unit 264 saves the running site of the interrupted first task, the operating site of the second task by using the operating system, where the running site of the second task includes the register information and the fourth user state. The command position and the lock interrupt information of the second task.
第一恢复单元266,通过操作系统根据第一获取单元265保存的第二任务的运行现场恢复第二任务并处理。The first recovery unit 266 restores the second task and processes it according to the operating site of the second task saved by the first obtaining unit 265 by the operating system.
在本实施例中,任务处理模块260,还可以包括:In this embodiment, the task processing module 260 may further include:
任务检测单元267,用于在一次中断响应结束时,通过第二运行模块240运行的操作系统检测是否存在需要优先调度的第三任务。The task detecting unit 267 is configured to detect, by the operating system running by the second running module 240, whether there is a third task that needs to be preferentially scheduled when the interrupt response ends.
第二获取单元268,用于当任务检测单元267检测到存在第三任务时,通过操作系统获取第三任务的运行现场,第三任务的运行现场包括寄存器信息、第五用户态指令位置和第三任务的锁中断信息。The second obtaining unit 268 is configured to acquire, by the operating system, the running site of the third task when the task detecting unit 267 detects that the third task exists, where the running site of the third task includes the register information, the fifth user state command position, and the Three task lock interrupt information.
第二恢复单元269,用于通过操作系统根据第二获取单元268获取到的第三任务的运行现场恢复第三任务并处理。The second recovery unit 269 is configured to recover and process the third task according to the operating site of the third task acquired by the second obtaining unit 268 by the operating system.
综上所述,本实施例提供的任务处理装置,通过在线程中运行操作系统,通过线程中的操作系统进行任务调度;解决了任务调度过程需要多次切换至Linux内核层实现,导致单次任务调度过程的延时较大,影响了任务处理过程的实时性的问题;达到了在用户层中直接完成任务调度,不需要多次切换至内核层,减少任务调度的耗时,提高了任务处理时的实时性的效果。In summary, the task processing apparatus provided in this embodiment performs task scheduling by running an operating system in a thread through an operating system in a thread; and solves the problem that the task scheduling process needs to be switched to the Linux kernel layer multiple times, resulting in a single operation. The delay of the task scheduling process is large, which affects the real-time problem of the task processing process. It achieves the task scheduling directly in the user layer, does not need to switch to the kernel layer multiple times, reduces the time-consuming task scheduling, and improves the task. The effect of real-time processing.
同时,由于背景技术中的任务调度是由内核层来进行,所以内核层的负载较高,本实施例提供的任务处理装置还可以达到降低内核层的负载的效果。At the same time, since the task scheduling in the background technology is performed by the kernel layer, the load of the kernel layer is high, and the task processing apparatus provided in this embodiment can also achieve the effect of reducing the load of the kernel layer.
请参考图5A,其示出了本发明一个实施例提供的电子设备的结构方框图。该电子设备500包括:处理器520和存储器540,处理器520和存储器540可以通过通信总线相连,存储器540可以是指令存储器、内存和寄存器等。 Please refer to FIG. 5A, which is a structural block diagram of an electronic device according to an embodiment of the present invention. The electronic device 500 includes a processor 520 and a memory 540. The processor 520 and the memory 540 can be connected by a communication bus. The memory 540 can be an instruction memory, a memory, a register, and the like.
存储器540用于存储一个或者一个以上的指令,该指令用于实现一种任务处理方法,该指令包括:The memory 540 is configured to store one or more instructions for implementing a task processing method, the instructions including:
在用户层运行至少一个线程;Running at least one thread at the user level;
在线程中运行操作系统,该操作系统用于处理任务;Running an operating system in a thread that is used to process tasks;
在处理任务的过程中,通过线程中的操作系统进行中断响应和/或任务调度。Interrupt response and/or task scheduling is performed by the operating system in the thread during the processing of the task.
处理器520用于执行上述指令。The processor 520 is configured to execute the above instructions.
其中,每个线程中可以运行有一个操作系统,该操作系统用于处理任务。该操作系统需要具有独立完成中断响应和/或任务调度的功能。不同的线程中可以运行相同类型的操作系统,不同的线程中也可以运行不同类型的操作系统。本发明实施例对上述操作系统的类型不做特别限定。Among them, each thread can run an operating system, which is used to process tasks. The operating system needs to have the ability to independently perform interrupt response and/or task scheduling. Different types of threads can run the same type of operating system, and different types of operating systems can be run in different threads. The type of the above operating system is not particularly limited in the embodiment of the present invention.
任务是泛指操作系统可以处理的任务。在电子设备是基站设备时,任务可以是下发调度指令的任务、分配信道资源的任务、处理接入请求的任务等等。Tasks are generic tasks that the operating system can handle. When the electronic device is a base station device, the task may be a task of issuing a scheduling instruction, a task of allocating a channel resource, a task of processing an access request, and the like.
综上所述,本实施例提供的电子设备,通过线程中的操作系统进行中断响应和/或任务调度;解决了中断响应过程和任务调度过程需要多次切换至Linux内核层中进行处理,导致单次的中断响应过程和任务调度过程的延时较大,影响了任务处理过程的实时性;达到了在用户层中直接完成中断响应和/或任务调度,不需要多次切换至内核层进行处理,减少中断响应和/或任务调度的耗时,提高了任务处理时的实时性的效果。In summary, the electronic device provided in this embodiment performs interrupt response and/or task scheduling through an operating system in a thread; the interrupt response process and the task scheduling process need to be switched to the Linux kernel layer for processing, resulting in processing. The delay of the single interrupt response process and the task scheduling process is large, which affects the real-time performance of the task processing process; the interrupt response and/or task scheduling are directly completed in the user layer, and it is not necessary to switch to the kernel layer multiple times. Processing, reducing the time consuming of interrupt response and/or task scheduling, improves the real-time effect of task processing.
同时,由于背景技术中的中断响应和/或任务调度都是由内核层来进行,所以内核层的负载较高,本实施例提供的任务处理方法还可以达到降低内核层的负载的效果。At the same time, since the interrupt response and/or task scheduling in the background technology are performed by the kernel layer, the load of the kernel layer is high, and the task processing method provided in this embodiment can also achieve the effect of reducing the load of the kernel layer.
在基于图5A所示实施例提供的可选实施例中,存储器540还存储有用于执行以下操作的指令:In an alternative embodiment provided based on the embodiment illustrated in Figure 5A, the memory 540 also stores instructions for performing the following operations:
通过内核层接收中断源的中断请求。The interrupt request of the interrupt source is received through the kernel layer.
通过内核层将中断请求传输给用户层中对应的线程的操作系统。The interrupt request is transmitted through the kernel layer to the operating system of the corresponding thread in the user layer.
通过用户层中对应的线程的操作系统的中断处理程序对中断请求进行中断响应;The interrupt request is interrupted by an interrupt handler of an operating system of a corresponding thread in the user layer;
处理器520还用于执行上述指令。其中,处理器520通常通过总线560上的中断线接收中断源的中断请求。The processor 520 is also operative to execute the above instructions. The processor 520 typically receives an interrupt request for the interrupt source via an interrupt line on the bus 560.
可选地,存储器540还存储有用于执行以下操作的指令: Optionally, the memory 540 also stores instructions for performing the following operations:
在内核层的核心栈中保存被中断的线程的运行现场,该运行现场包括第一用户态指令位置。The running site of the interrupted thread is saved in the core stack of the kernel layer, which includes the first user state instruction location.
将第一用户态指令位置从核心栈中的第一存储位置转移到共享存储区中的第二存储位置进行存储,并将中断请求存储到共享存储区中的第三存储位置。The first user state instruction location is transferred from the first storage location in the core stack to the second storage location in the shared storage area for storage, and the interrupt request is stored to a third storage location in the shared storage area.
在核心栈中的第一存储位置中存储被中断的线程的操作系统中的中断处理程序的起始指令位置;Storing a start instruction location of an interrupt handler in an operating system of the interrupted thread in a first storage location in the core stack;
退出内核层对中断请求的响应;Exit the kernel layer's response to the interrupt request;
处理器520还用于执行上述指令。其中,核心栈、共享存储区可以是物理内存中的一块逻辑位置。该物理内存可以属于存储器540。The processor 520 is also operative to execute the above instructions. The core stack and the shared storage area may be a logical location in physical memory. This physical memory can belong to the memory 540.
可选地,存储器540还存储有用于执行以下操作的指令:Optionally, the memory 540 also stores instructions for performing the following operations:
在恢复被中断的线程时,从所述核心栈的第一存储位置读取所述操作系统的中断处理程序的起始指令位置;Reading the initial instruction location of the interrupt handler of the operating system from the first storage location of the core stack when restoring the interrupted thread;
在线程的用户栈保存被中断的任务的运行现场,该运行现场包括第二用户态指令位置;The user stack of the thread saves the running site of the interrupted task, the running site including the second user state command location;
从用户栈切换为中断栈;Switch from the user stack to the interrupt stack;
从共享存储区中读取中断请求,并基于中断栈进行中断响应;Reading an interrupt request from the shared memory and performing an interrupt response based on the interrupt stack;
在中断响应结束后,恢复被中断的任务或另一个需要优先调度的任务;After the interrupt response ends, the interrupted task or another task that needs to be scheduled is resumed;
处理器520还用于执行上述指令。其中,中断栈、和与每个线程对应的用户栈可以是物理内存中的一块逻辑位置。该物理内存可以属于存储器540。The processor 520 is also operative to execute the above instructions. The interrupt stack and the user stack corresponding to each thread may be a logical location in physical memory. This physical memory can belong to the memory 540.
可选地,存储器540还存储有用于执行以下操作的指令:Optionally, the memory 540 also stores instructions for performing the following operations:
将用户栈中保存的第二用户态指令位置,替换为共享存储区的第二存储位置中保存的第一用户态指令位置;Replacing the second user state instruction location saved in the user stack with the first user state instruction location saved in the second storage location of the shared storage area;
通过用户栈中保存的运行现场,恢复被中断的任务;Resume the interrupted task through the running site saved in the user stack;
处理器520还用于执行上述指令。The processor 520 is also operative to execute the above instructions.
综上所述,本实施例提供的电子设备,还通过内核层将中断请求存储在共享存储区,在用户层的线程恢复后,从共享存储区获取该中断请求,使得内核层可以将中断请求上报给线程,由线程中的操作系统对该中断请求进行处理。In summary, the electronic device provided by the embodiment further stores the interrupt request in the shared storage area through the kernel layer, and after the thread of the user layer recovers, acquires the interrupt request from the shared storage area, so that the kernel layer can request the interrupt. Reported to the thread, the interrupt request is processed by the operating system in the thread.
本实施例提供的电子设备,还通过将核心栈中的第一用户态指令位置,替换为操作系统的中断处理程序的起始指令位置,使得用户层的线程恢复后,并不是进入被中断的第一用户态指令位置继续运行,而是强制跳转到了操作系统 中的中断处理程序,没有延时就直接进入了中断响应过程,实现了中断请求的快速上报并响应的效果。The electronic device provided by the embodiment further replaces the first user state instruction position in the core stack with the start instruction position of the interrupt handler of the operating system, so that the thread of the user layer is restored, and the entry is not interrupted. The first user mode instruction position continues to run, but the forced jump to the operating system The interrupt handler in the program directly enters the interrupt response process without delay, and achieves the effect of fast reporting and response of the interrupt request.
本实施例提供的电子设备,还通过由操作系统的中断处理程序独立完成中断响应,该过程中不需要多次切换至内核层进行处理,达到了完整的一次中断响应过程的耗时非常小的效果。The electronic device provided in this embodiment also independently completes the interrupt response by the interrupt processing program of the operating system, and does not need to switch to the kernel layer for processing in the process, and the time required to complete the complete interrupt response process is very small. effect.
在基于图5A所示实施例提供的可选实施例中:In an alternative embodiment provided based on the embodiment shown in Figure 5A:
存储器540还存储有用于执行以下操作的指令:The memory 540 also stores instructions for performing the following operations:
当从第一任务切换至第二任务时,通过操作系统保存被中断的第一任务的运行现场,第一任务的运行现场包括寄存器信息、第三用户态指令位置和第一任务的锁中断信息。When the first task is switched to the second task, the operating site of the interrupted first task is saved by the operating system, and the running site of the first task includes the register information, the third user state instruction position, and the lock interruption information of the first task. .
通过操作系统获取第二任务的运行现场,该第二任务的运行现场包括寄存器信息、第四用户态指令位置和第二任务的锁中断信息;Obtaining, by the operating system, a running site of the second task, where the running site of the second task includes register information, a fourth user state command location, and a lock interruption information of the second task;
通过操作系统根据第二任务的运行现场恢复第二任务并处理;Recovering the second task and processing by the operating system according to the operation site of the second task;
处理器520还用于执行上述指令。The processor 520 is also operative to execute the above instructions.
可选地,存储器540还存储有用于执行以下操作的指令:Optionally, the memory 540 also stores instructions for performing the following operations:
在一次中断响应结束时,通过操作系统检测是否存在需要优先调度的第三任务。At the end of an interrupt response, the operating system detects whether there is a third task requiring priority scheduling.
当存在第三任务时,通过操作系统获取第三任务的运行现场,该第三任务的运行现场包括寄存器信息、第五用户态指令位置和第三任务的锁中断信息。When there is a third task, the operating site of the third task is acquired by the operating system, and the running site of the third task includes the register information, the fifth user state instruction location, and the lock interruption information of the third task.
通过操作系统根据第三任务的运行现场恢复第三任务并处理;The third task is resumed and processed by the operating system according to the operation site of the third task;
处理器520还用于执行上述指令。The processor 520 is also operative to execute the above instructions.
综上所述,本实施例提供的电子设备,通过在线程中运行操作系统,通过线程中的操作系统进行任务调度;解决了任务调度过程需要多次切换至Linux内核层实现,导致单次任务调度过程的延时较大,影响了任务处理过程的实时性的问题;达到了在用户层中直接完成任务调度,不需要多次切换至内核层,减少任务调度的耗时,提高了任务处理时的实时性的效果。In summary, the electronic device provided in this embodiment performs task scheduling through an operating system in a thread by running an operating system in a thread. The task scheduling process needs to be switched to the Linux kernel layer multiple times, resulting in a single task. The delay of the scheduling process is large, which affects the real-time problem of the task processing process. It achieves the task scheduling directly in the user layer, does not need to switch to the kernel layer multiple times, reduces the time-consuming task scheduling, and improves the task processing. The effect of real time.
同时,由于背景技术中的任务调度是由内核层来进行,所以内核层的负载较高,本实施例提供的任务处理装置还可以达到降低内核层的负载的效果。At the same time, since the task scheduling in the background technology is performed by the kernel layer, the load of the kernel layer is high, and the task processing apparatus provided in this embodiment can also achieve the effect of reducing the load of the kernel layer.
此外,请结合参考图5B,电子设备500还可以包括通信总线530、发射电 路552和接收电路554等。处理器520控制电子设备500的操作,处理器520还可以称为中央处理单元(英文:Central Processing Unit,缩写CPU)。存储器540可以包括只读存储器和随机存取存储器,并向处理器520提供指令和数据。存储器540的一部分还可以包括非易失性随机存取存储器(英文:Non-Volatile Random Access Memory,缩写NVRAM)。具体的应用中,发射电路552和接收电路554可以耦合到收发器550。电子设备500的各个组件通过通信总线530耦合在一起,其中通信总线530除包括数据总线之外,还可以包括电源总线、控制总线、中断线和其它状态信号总线等。但是为了清楚说明起见,在图中将各种总线都标为通信总线530。In addition, referring to FIG. 5B, the electronic device 500 may further include a communication bus 530 and transmitting power. Path 552 and receiving circuit 554 and the like. The processor 520 controls the operation of the electronic device 500. The processor 520 may also be referred to as a central processing unit (English: Central Processing Unit, abbreviated CPU). Memory 540 can include read only memory and random access memory and provides instructions and data to processor 520. A portion of the memory 540 may also include a non-volatile random access memory (Non-Volatile Random Access Memory, abbreviated as NVRAM). In a particular application, transmit circuitry 552 and receive circuitry 554 can be coupled to transceiver 550. The various components of electronic device 500 are coupled together via communication bus 530, which may include, in addition to the data bus, a power bus, a control bus, interrupt lines, and other status signal buses. However, for clarity of description, various buses are labeled as communication bus 530 in the figure.
下面是本发明的方法实施例,各个方法实施例与上面的装置实施例互相对应。The following are embodiments of the method of the present invention, each of which corresponds to the above apparatus embodiment.
请参考图6A,其示出了本发明实施例提供的任务处理方法所涉及的一种电子设备的结构示意图。该电子设备包括硬件层620、内核层640和用户层660。Please refer to FIG. 6A, which is a schematic structural diagram of an electronic device involved in a task processing method according to an embodiment of the present invention. The electronic device includes a hardware layer 620, a kernel layer 640, and a user layer 660.
硬件层620包括处理器,该处理器可以有一个处理器核心622,即该处理器为单核处理器。The hardware layer 620 includes a processor, which may have a processor core 622, ie, the processor is a single core processor.
内核层640包括有操作系统内核642以及驱动应用程序(图中未示出),该操作系统内核242可以是Linux内核。The kernel layer 640 includes an operating system kernel 642 and a driver application (not shown), which may be a Linux kernel.
用户层660可以运行线程(英文:thread)662,每个线程662中运行有一个操作系统(英文:operation system,缩写:os),该线程662可以是实时线程和/或用户线程。该操作系统可以独占该处理器核心622,组成非对称多处理(英文:Asymmetric Multi-Processing,缩写:AMP)结构。The user layer 660 can run a thread (English: thread) 662, and each thread 662 runs an operating system (English: operation system, abbreviation: os), which can be a real-time thread and/or a user thread. The operating system can monopolize the processor core 622 to form an Asymmetric Multi-Processing (abbreviation: AMP) structure.
请参考图6B,其示出了本发明实施例提供的任务处理方法所涉及的再一种电子设备的架构示意图。该电子设备包括硬件层620、内核层640和用户层660。Please refer to FIG. 6B, which is a schematic structural diagram of still another electronic device involved in the task processing method provided by the embodiment of the present invention. The electronic device includes a hardware layer 620, a kernel layer 640, and a user layer 660.
硬件层620包括处理器,该处理器可以包括有2个或者2个以上的处理器核心622(图中以2个处理器核心进行示意),也即多核处理器。The hardware layer 620 includes a processor, which may include two or more processor cores 622 (illustrated by two processor cores in the figure), that is, a multi-core processor.
内核层640包括有操作系统内核642以及驱动应用程序(图中未示出),该操作系统内核642可以是Linux内核。 The kernel layer 640 includes an operating system kernel 642 and a driver application (not shown), which may be a Linux kernel.
用户层660可以运行有线程662,每个线程662中运行有一个操作系统,该操作系统用于处理任务。该线程662可以是实时线程和/或用户线程。每个操作系统可以独占一个处理器核心622,组成对称多处理(英文:Symmetric Multi-Processing,缩写:SMP)结构。User layer 660 can run with threads 662, each of which runs an operating system for processing tasks. The thread 662 can be a real-time thread and/or a user thread. Each operating system can monopolize a processor core 622 to form a Symmetric Multi-Processing (SMP) structure.
请参考图7,其示出了本发明一个实施例提供的任务处理方法的方法流程图。本实施例以该任务处理方法应用于图6A或图6B所示的电子设备中来举例说明。该方法包括:Please refer to FIG. 7, which is a flowchart of a method for processing a task according to an embodiment of the present invention. This embodiment is exemplified by applying the task processing method to the electronic device shown in FIG. 6A or FIG. 6B. The method includes:
步骤701,在用户层运行至少一个线程; Step 701, running at least one thread in the user layer;
步骤702,在线程中运行操作系统,该操作系统可以用于处理任务; Step 702, running an operating system in a thread, the operating system can be used to process a task;
每个线程中可以运行有一个操作系统,该操作系统用于处理任务。There can be one operating system running in each thread, which is used to process tasks.
该操作系统需要具有独立完成中断响应和/或任务调度的功能。不同的线程中可以运行相同类型的操作系统,不同的线程中也可以运行不同类型的操作系统。本发明实施例对上述操作系统的类型不做特别限定。The operating system needs to have the ability to independently perform interrupt response and/or task scheduling. Different types of threads can run the same type of operating system, and different types of operating systems can be run in different threads. The type of the above operating system is not particularly limited in the embodiment of the present invention.
任务是泛指操作系统可以处理的任务,在电子设备是基站设备时,任务可以是下发调度指令的任务、分配信道资源的任务、处理接入请求的任务等等。The task is generally referred to as a task that the operating system can process. When the electronic device is a base station device, the task may be a task of issuing a scheduling instruction, a task of allocating a channel resource, a task of processing an access request, and the like.
步骤703,在执行任务的过程中,通过线程中的操作系统进行中断响应和/或任务调度。In step 703, during the execution of the task, the interrupt response and/or task scheduling is performed by the operating system in the thread.
综上所述,本实施例提供的任务处理方法,通过线程中的操作系统进行中断响应和/或任务调度;解决了中断响应过程和任务调度过程需要多次切换至Linux内核层中进行处理,导致单次的中断响应过程和任务调度过程的延时较大,影响了任务处理过程的实时性;达到了在用户层中直接完成中断响应和/或任务调度,不需要多次切换至内核层进行处理,减少中断响应和/或任务调度的耗时,提高了任务处理时的实时性的效果。In summary, the task processing method provided in this embodiment performs interrupt response and/or task scheduling through an operating system in a thread; and the interrupt response process and the task scheduling process need to be switched to the Linux kernel layer for processing. The delay of the single interrupt response process and the task scheduling process is large, which affects the real-time behavior of the task processing; the interrupt response and/or task scheduling are directly completed in the user layer, and it is not necessary to switch to the kernel layer multiple times. Processing, reducing the time consuming of interrupt response and/or task scheduling, improves the real-time effect of task processing.
同时,由于背景技术中的中断响应和/或任务调度都是由内核层来进行,所以内核层的负载较高,本实施例提供的任务处理方法还可以达到降低内核层的负载的效果。At the same time, since the interrupt response and/or task scheduling in the background technology are performed by the kernel layer, the load of the kernel layer is high, and the task processing method provided in this embodiment can also achieve the effect of reducing the load of the kernel layer.
下面分2个实施例分别对中断响应过程和任务调度过程进行阐述。The following is an explanation of the interrupt response process and the task scheduling process in two embodiments.
请参考图8,其示出了本发明另一个实施例提供的任务处理方法的方法流 程图。本实施例以该任务处理方法应用于图6A或图6B所示的电子设备中来举例说明。该方法包括:Please refer to FIG. 8 , which illustrates a method flow of a task processing method according to another embodiment of the present invention. Cheng Tu. This embodiment is exemplified by applying the task processing method to the electronic device shown in FIG. 6A or FIG. 6B. The method includes:
步骤801,在用户层运行至少一个线程; Step 801, running at least one thread in the user layer;
电子设备在用户层中运行至少一个线程,该线程可以是用于处理实时任务的实时线程,也可以是用于处理普通任务的普通线程。The electronic device runs at least one thread in the user layer, which may be a real-time thread for processing a real-time task, or a normal thread for processing a normal task.
步骤802,在线程中运行操作系统; Step 802, running an operating system in a thread;
电子设备在线程中运行操作系统。每个线程中可以单独运行一个操作系统。电子设备通过该操作系统对任务进行处理。The electronic device runs the operating system in a thread. An operating system can be run separately in each thread. The electronic device processes the task through the operating system.
该操作系统需要具有独立完成中断响应和/或任务调度的功能。不同的线程中可以运行相同类型的操作系统,不同的线程中也可以运行不同类型的操作系统。本发明实施例对上述操作系统的类型不做特别限定。The operating system needs to have the ability to independently perform interrupt response and/or task scheduling. Different types of threads can run the same type of operating system, and different types of operating systems can be run in different threads. The type of the above operating system is not particularly limited in the embodiment of the present invention.
任务是泛指操作系统可以处理的任务,在电子设备是基站设备时,任务可以是下发调度指令的任务、分配信道资源的任务、处理接入请求的任务等等。The task is generally referred to as a task that the operating system can process. When the electronic device is a base station device, the task may be a task of issuing a scheduling instruction, a task of allocating a channel resource, a task of processing an access request, and the like.
步骤803,通过内核层接收中断源的中断请求; Step 803, receiving an interrupt request of an interrupt source through a kernel layer;
电子设备通过内核层接收中断源的中断请求,该中断源可以是外部硬件设备,外部硬件设备可以是鼠标、键盘、网卡、显卡之类的硬件设备。The electronic device receives an interrupt request of the interrupt source through the kernel layer, and the interrupt source may be an external hardware device, and the external hardware device may be a hardware device such as a mouse, a keyboard, a network card, or a graphics card.
可选地,在内核层中可以实现一个中断快速处理程序,该中断快速处理程序用于在内核层中接收中断请求,并将中断请求上报至对应线程中的操作系统,以便线程中的操作系统对该中断请求进行响应。Optionally, an interrupt fast processing program can be implemented in the kernel layer, the interrupt fast processing program is configured to receive an interrupt request in the kernel layer, and report the interrupt request to an operating system in the corresponding thread, so that the operating system in the thread Respond to the interrupt request.
电子设备通过该中断快速处理程序接收中断源的中断请求。The electronic device receives an interrupt request of the interrupt source through the interrupt fast processing program.
在中断快速处理程序接收到中断请求后,电子设备通过中断快速处理程序入锁中断状态。After the interrupt fast processing program receives the interrupt request, the electronic device enters the lock interrupt state by interrupting the fast processing program.
锁中断状态用于避免处理器在处理一个中断请求的过程中再次接收到另外一个中断请求,从而导致本次中断请求的处理过程被打断。锁中断状态的实现可以有硬件锁中断和软件锁中断两种。The lock interrupt status is used to prevent the processor from receiving another interrupt request during the processing of an interrupt request, thereby causing the interrupt request processing to be interrupted. The implementation of the lock interrupt status can be either a hardware lock interrupt or a software lock interrupt.
当硬件锁中断时,内核层在本次中断请求的处理过程中将不再接收其它中断请求。When the hardware lock is interrupted, the kernel layer will no longer receive other interrupt requests during the processing of this interrupt request.
当软件锁中断时,内核层在本次中断请求的处理过程依然接收其它中断请求,但是并不打断本次中断请求的处理过程,而是将后续接收到的中断请求存储在位于内核层中的中断请求队列中,等本次中断请求的处理过程完毕后,再依次从中断请求队列中处理其它中断请求。 When the software lock is interrupted, the kernel layer still receives other interrupt requests during the processing of the interrupt request, but does not interrupt the processing of the interrupt request, but stores the subsequently received interrupt request in the kernel layer. In the interrupt request queue, after the processing of the interrupt request is completed, other interrupt requests are sequentially processed from the interrupt request queue.
步骤804,通过内核层将中断请求传输给用户层中对应线程的操作系统; Step 804, the interrupt request is transmitted to the operating system of the corresponding thread in the user layer through the kernel layer;
与背景技术不同的是,电子设备不在内核层中响应该中断请求,而是通过内核层将中断请求传输给用户层中对应的线程的操作系统中进行响应。与中断请求对应的线程通常是被该中断请求所打断的线程。也即,步骤804可以包括如下子步骤,如图9所示:Unlike the background art, the electronic device does not respond to the interrupt request in the kernel layer, but responds by transmitting the interrupt request to the operating system of the corresponding thread in the user layer through the kernel layer. The thread corresponding to the interrupt request is usually the thread that was interrupted by the interrupt request. That is, step 804 can include the following sub-steps, as shown in FIG.
804a,电子设备在内核层的核心栈中保存被中断的线程的运行现场,运行现场包括第一用户态指令位置;804a. The electronic device saves an operation site of the interrupted thread in a core stack of the kernel layer, where the operation site includes a first user state instruction location;
由于处理器在单位时间内只能处理1个程序片段,比如,处理器当前正在处理一个线程,则无法处理其它线程或者属于内核层的程序片段。处理器在内核层中接收到1个中断请求时,该中断请求会打断处理器当前正在运行的线程,此时处理器会转而对该中断请求进行响应。为了被中断的线程能够在后续时刻恢复运行,电子设备通过中断快速处理程序在内核层的核心栈中保存被中断的线程的运行现场,运行现场包括该线程在被中断时的各种寄存器值和第一用户态指令位置。第一用户态指令位置也称第一用户态PC(英文:program counter,中文:程序计数器)指针,第一用户态PC指针是指被中断的线程在中断前原计划将要运行的下一条指令所对应的位置。当该线程被恢复时,处理器可以通过运行该第一用户态指令位置所对应的程序指令,以恢复该线程的运行。Since the processor can only process one program fragment per unit time, for example, the processor is currently processing one thread, it cannot process other threads or program fragments belonging to the kernel layer. When the processor receives an interrupt request in the kernel layer, the interrupt request interrupts the currently running thread of the processor, and the processor will respond to the interrupt request. In order for the interrupted thread to resume operation at a later time, the electronic device saves the running site of the interrupted thread in the kernel stack of the kernel layer by interrupting the fast processing program, and the running site includes various register values of the thread when interrupted. The first user mode instruction location. The first user state instruction location is also referred to as a first user state PC (English: program counter, Chinese: program counter) pointer, and the first user state PC pointer refers to the next instruction that the interrupted thread originally planned to run before the interruption. s position. When the thread is restored, the processor can resume the operation of the thread by running a program instruction corresponding to the location of the first user state instruction.
核心栈是内核层中的栈。电子设备通过中断快速处理程序将该线程的运行现场保存在核心栈中。第一用户态指令位置保存在核心栈的第一存储位置。The core stack is the stack in the kernel layer. The electronic device saves the running site of the thread in the core stack by interrupting the fast processing program. The first user state instruction location is stored in a first storage location of the core stack.
804b,电子设备将第一用户态指令位置从核心栈中的第一存储位置移转移到共享存储区中的第二存储位置进行存储,并将中断请求存储到共享存储区中的第三存储位置,共享存储区为内核层和用户层均能访问的存储区;804b. The electronic device moves the first user state instruction location from the first storage location in the core stack to the second storage location in the shared storage area for storage, and stores the interrupt request in a third storage location in the shared storage area. The shared storage area is a storage area accessible by both the kernel layer and the user layer;
电子设备可以通过内核层中的中断快速处理程序将第一用户态指令位置从核心栈中的第一存储位置移动到共享存储区中的第二存储位置。The electronic device can move the first user state instruction location from the first storage location in the core stack to the second storage location in the shared storage area by an interrupt fast handler in the kernel layer.
804c,电子设备在核心栈中的第一存储位置中存储操作系统的中断处理程序的起始指令位置;804c. The electronic device stores a starting instruction position of an interrupt processing program of the operating system in a first storage location in the core stack.
本发明实施例提供的线程中的操作系统具有独立完成中断响应的功能。可选地,在线程的操作系统中可以实现一个中断处理程序,该中断处理程序用于对内核层上报至线程中的操作系统的中断请求进行响应。The operating system in the thread provided by the embodiment of the present invention has the function of independently completing the interrupt response. Optionally, an interrupt handler can be implemented in the operating system of the thread, the interrupt handler being responsive to an interrupt request reported by the kernel layer to an operating system in the thread.
电子设备通过内核层中的中断快速处理程序在核心栈中的第一存储位置中存储操作系统的中断处理程序的起始指令位置,该操作系统是被中断的线程 中的操作系统。The electronic device stores the starting instruction position of the operating system interrupt processing program in the first storage location in the core stack through the interrupt fast processing program in the kernel layer, the operating system is the interrupted thread The operating system in .
也即,被中断的线程在后续被恢复运行时,处理器读取到的将是该线程中操作系统的中断处理程序,而非第一用户态指令位置所对应的程序指令。That is, when the interrupted thread is resumed, the processor will read the interrupt handler of the operating system in the thread instead of the program instruction corresponding to the first user state instruction position.
804d,电子设备通过内核层退出中断请求的处理。804d, the electronic device exits the processing of the interrupt request through the kernel layer.
此时,中断请求被存储到共享存储区中等待用户层中的线程中的操作系统来处理。At this point, the interrupt request is stored in the shared memory area waiting for the operating system in the thread in the user layer to process.
需要说明的是,步骤804a至步骤804d都是电子设备通过内核层来实现的。It should be noted that steps 804a to 804d are all implemented by the electronic device through the kernel layer.
步骤805,通过操作系统中的中断处理程序对中断请求进行中断响应。In step 805, the interrupt request is interrupted by an interrupt handler in the operating system.
步骤805包括如下子步骤,如图10所示:Step 805 includes the following sub-steps, as shown in FIG. 10:
805a,电子设备在恢复被中断的线程时,从核心栈的第一存储位置读取操作系统的中断处理程序的起始指令位置;805a, the electronic device reads the starting instruction position of the operating system interrupt processing program from the first storage location of the core stack when restoring the interrupted thread;
由于核心栈中的第一存储位置所存储的第一用户态指令位置被替换为操作系统的中断处理程序的起始指令位置。当电子设备根据核心栈中保存的运行现场恢复被中断的线程时,处理器根据核心栈中的第一存储位置所读取到的程序指令是线程中操作系统的中断处理程序所对应的程序指令。此后,线程中操作系统通过该中断处理程序对中断请求进行中断响应。The first user state instruction location stored by the first storage location in the core stack is replaced with the starting instruction location of the operating system's interrupt handler. When the electronic device restores the interrupted thread according to the running scene saved in the core stack, the program instruction read by the processor according to the first storage location in the core stack is a program instruction corresponding to the interrupt processing program of the operating system in the thread. . Thereafter, the operating system in the thread interrupts the interrupt request through the interrupt handler.
805b,电子设备在线程的用户栈中保存被中断的任务的运行现场,运行现场包括第二用户态指令位置;805b, the electronic device saves an operation site of the interrupted task in a thread user stack, and the operation site includes a second user state instruction location;
由于线程中操作系统是一个独立的操作系统,并且线程中的操作系统用于处理任务。当存在一个中断请求需要处理时,该中断请求会打断操作系统中正在运行的任务,电子设备首先通过中断处理程序在线程的用户栈中保存被中断的任务的运行现场,运行现场包括该任务被中断时的各种寄存器值和第二用户态指令位置。第二用户态指令位置也称第二用户态PC指针,第二用户态PC指针是被中断的任务在中断前原计划将要运行的下一条指令所对应的指针位置。Because the operating system in the thread is a separate operating system, and the operating system in the thread is used to process the task. When there is an interrupt request to be processed, the interrupt request interrupts the running task in the operating system, and the electronic device first saves the running site of the interrupted task in the user stack of the thread through the interrupt handler, and the running site includes the task. The various register values and the second user mode command position when interrupted. The second user state instruction location is also referred to as a second user state PC pointer, and the second user state PC pointer is the pointer location corresponding to the next instruction that the interrupted task was scheduled to run before the interruption.
由于在步骤805a中线程恢复时,处理器直接读取到中断处理程序来运行,所以该第二用户态指令位置通常与步骤804a中的第一用户态指令位置是相同的。例如,步骤804a中线程在将要运行到某一任务对应的程序代码中的A位置时被中断,那么在步骤805b中线程中被中断的任务的将要运行的程序指令位置也应该是A位置,并未发生变化。Since the processor directly reads the interrupt handler to run when the thread resumes in step 805a, the second user state instruction location is typically the same as the first user state instruction location in step 804a. For example, if the thread in step 804a is interrupted when it is going to run to the A position in the program code corresponding to a certain task, then the program instruction position of the task to be interrupted in the thread in step 805b should also be the A position, and No change.
每个线程拥有各自的用户栈,电子设备通过中断处理程序将该任务的运行 现场保存在用户栈中。第二用户态指令位置保存在用户栈中的第四存储位置。Each thread has its own user stack, and the electronic device runs the task through an interrupt handler. The scene is saved in the user stack. The second user mode instruction location is saved in a fourth storage location in the user stack.
步骤805c,电子设备将用户栈中保存的第二用户态指令位置,替换为共享存储区的第二存储位置中保存的第一用户态指令位置;Step 805c: The electronic device replaces the second user state instruction location saved in the user stack with the first user state instruction location saved in the second storage location of the shared storage area;
由于步骤805b中存储的第二用户态指令位置有可能会保存错误,保存错误的第二用户态指令位置会与第一用户态指令位置不同,为了保证该任务在恢复运行时的正确性,所以电子设备通过中断处理程序将步骤805b中在用户栈中保存的第二用户态指令位置,替换为共享存储区的第二存储位置中保存的第一用户态指令位置,也即替换为步骤804b中被转移至共享存储区中的第一用户态指令位置。Since the second user state instruction position stored in step 805b may save an error, the second user state instruction position of the saved error may be different from the first user state instruction position, in order to ensure the correctness of the task when the operation is resumed, The electronic device replaces the second user state instruction position saved in the user stack in step 805b with the first user state instruction position saved in the second storage location of the shared storage area by the interrupt processing program, that is, the step 804b is replaced. The first user mode instruction location is transferred to the shared memory area.
步骤805d,电子设备从用户栈切换为中断栈; Step 805d, the electronic device switches from the user stack to the interrupt stack;
中断栈用于存储中断响应过程中的数据。The interrupt stack is used to store data during the interrupt response process.
步骤805e,电子设备从共享存储区中读取中断请求,并基于中断栈进行中断响应; Step 805e: The electronic device reads the interrupt request from the shared storage area, and performs an interrupt response based on the interrupt stack.
电子设备通过中断处理程序从共享存储区中读取中断请求,该中断请求具体可以是一个中断号,然后由该中断处理程序基于中断栈对该中断请求进行中断响应。The electronic device reads the interrupt request from the shared memory by the interrupt handler, and the interrupt request may specifically be an interrupt number, and then the interrupt handler interrupts the interrupt request based on the interrupt stack.
步骤805f,电子设备在中断响应结束后,恢复被中断的任务或另一需要优先调度的任务; Step 805f: After the interrupt response ends, the electronic device resumes the interrupted task or another task that needs to be scheduled preferentially;
在中断响应结束后,如果不存在需要优先调度的其它任务,则电子设备通过中断处理程序根据用户栈中保存的运行现场,恢复被中断的任务。After the interrupt response ends, if there are no other tasks that need to be scheduled preferentially, the electronic device restores the interrupted task according to the running scene saved in the user stack through the interrupt handler.
如果存在其它需要优先调度的其它任务,则电子设备通过中断处理程序根据用户栈中保存的运行现场,恢复另一需要优先调度的任务。If there are other tasks that need to be scheduled in priority, the electronic device resumes another task that needs to be scheduled according to the running site saved in the user stack through the interrupt handler.
在被中断的任务或需要优先调度的任务恢复时,电子设备还可以通过中断处理程序将内核层中的锁中断状态变更为解锁中断状态。当处于解锁中断状态时,电子设备可以继续接收中断请求。The electronic device may also change the lock interrupt status in the kernel layer to the unlock interrupt status through the interrupt handler when the interrupted task or the task requiring priority scheduling is resumed. When in the unlocked interrupt state, the electronic device can continue to receive the interrupt request.
需要补充说明的一点是,在步骤804d中电子设备需要保持在锁中断状态,由于硬件锁中断和软件锁中断的不同,如果是硬件锁中断,只要电子设备继续保持锁中断状态即可,如果是软件锁中断,则电子设备需要在内核层退出中断请求的处理,并恢复被中断的线程后,检查软件锁中断的状态是否为锁中断状态,如果不是,则需要更新软件锁中断的状态为锁中断状态并保持。It should be noted that in step 804d, the electronic device needs to remain in the lock interrupt state. Due to the difference between the hardware lock interrupt and the software lock interrupt, if the hardware lock is interrupted, as long as the electronic device continues to maintain the lock interrupt state, if If the software lock is interrupted, the electronic device needs to exit the interrupt request processing at the kernel layer and restore the interrupted thread. Check whether the state of the software lock interrupt is the lock interrupt status. If not, the software lock interrupt status needs to be updated. Interrupt state and keep.
还需要补充说明的另一点是,由于软件锁中断的状态为锁中断状态时,电 子设备中的内核层仍然接收中断源的中断请求,并将这些中断请求保存在内核层的中断请求队列中。所以步骤805f之后,如果电子设备将软件锁中断的状态从锁中断状态变更为解锁中断状态,则还需要检测中断请求队列中是否存在有其它中断请求,如果存在其它中断请求,则电子设备重新执行上述实施例中步骤804和步骤805所示出的中断响应过程。Another point that needs additional explanation is that since the state of the software lock interrupt is the lock interrupt state, The kernel layer in the child device still receives interrupt requests from the interrupt source and saves these interrupt requests in the kernel layer's interrupt request queue. Therefore, after step 805f, if the electronic device changes the state of the software lock interrupt from the lock interrupt state to the unlock interrupt state, it is also necessary to detect whether there is another interrupt request in the interrupt request queue, and if there are other interrupt requests, the electronic device re-executes The interrupt response process shown in step 804 and step 805 in the above embodiment.
综上所述,本实施例提供的任务处理方法,通过在线程中运行操作系统,通过线程中的操作系统进行中断处理;解决了中断处理过程需要多次切换至Linux内核层实现,导致单次中断处理过程的延时较大,影响了任务处理过程的实时性的问题;达到了在用户层中直接完成中断处理,不需要多次切换至内核层进行处理,减少中断处理的耗时,提高了任务处理时的实时性。In summary, the task processing method provided in this embodiment performs interrupt processing by running an operating system in a thread through an operating system in a thread; and solves the problem that the interrupt processing process needs to be switched to the Linux kernel layer multiple times, resulting in a single operation. The delay of the interrupt processing process is large, which affects the real-time problem of the task processing process; the interrupt processing is completed directly in the user layer, and it is not necessary to switch to the kernel layer for processing, reducing the time-consuming processing of the interrupt processing and improving The real-time nature of the task processing.
同时,由于背景技术中的中断响应是由内核层来进行,所以内核层的负载较高,本实施例提供的任务处理方法还可以达到降低内核层的负载的效果。At the same time, since the interrupt response in the background technology is performed by the kernel layer, the load of the kernel layer is high, and the task processing method provided in this embodiment can also achieve the effect of reducing the load of the kernel layer.
本实施例提供的任务处理方法,还通过内核层将中断请求存储在共享存储区,在用户层的线程恢复后,从共享存储区获取该中断请求,使得内核层可以将中断请求上报给线程,由线程中的操作系统对该中断请求进行处理。The task processing method provided by the embodiment further stores the interrupt request in the shared storage area through the kernel layer, and after the thread of the user layer is restored, acquires the interrupt request from the shared storage area, so that the kernel layer can report the interrupt request to the thread. The interrupt request is processed by the operating system in the thread.
本实施例提供的任务处理方法,还通过将核心栈中的第一用户态指令位置,替换为操作系统的中断处理程序的起始指令位置,使得用户层的线程恢复后,并不是进入被中断的第一用户态指令位置继续运行,而是强制跳转到了操作系统中的中断处理程序,没有延时就直接进入了中断响应过程,实现了中断请求的快速上报并响应的效果。The task processing method provided in this embodiment further replaces the first user state instruction position in the core stack with the start instruction position of the operating system interrupt processing program, so that the user layer thread is restored, and the entry is not interrupted. The first user state instruction position continues to run, but forcibly jumps to the interrupt handler in the operating system, and enters the interrupt response process without delay, realizing the effect of fast reporting and response of the interrupt request.
本实施例提供的任务处理方法,还通过由操作系统的中断处理程序独立完成中断响应,该过程中不需要多次切换至内核层进行处理,达到了完整的一次中断响应过程的耗时非常小的效果。The task processing method provided in this embodiment also completes the interrupt response independently by the interrupt processing program of the operating system, and does not need to switch to the kernel layer for processing in the process, and the time required to complete the complete interrupt response process is very small. Effect.
请参考图11,其示出了本发明再一个实施例提供的的任务处理方法的方法流程图。本实施例以该任务处理方法应用于图6A或图6B所示的电子设备中来举例说明。该方法包括:Please refer to FIG. 11 , which is a flowchart of a method for processing a task according to still another embodiment of the present invention. This embodiment is exemplified by applying the task processing method to the electronic device shown in FIG. 6A or FIG. 6B. The method includes:
步骤1101,在用户层运行至少一个线程; Step 1101, running at least one thread in the user layer;
电子设备在用户层中运行至少一个线程。该线程可以是用于处理实时任务的实时线程,也可以是用于处理普通任务的普通线程。The electronic device runs at least one thread in the user layer. This thread can be a real-time thread for processing real-time tasks or a normal thread for handling common tasks.
步骤1102,在线程中运行操作系统,该操作系统用于处理任务; Step 1102: Run an operating system in a thread, where the operating system is used to process a task;
电子设备在线程中运行操作系统。每个线程中可以单独运行一个操作系统。电子设备通过该操作系统对任务进行处理。The electronic device runs the operating system in a thread. An operating system can be run separately in each thread. The electronic device processes the task through the operating system.
该操作系统需要具有独立完成中断响应和/或任务调度的功能。不同的线程中可以运行相同类型的操作系统,不同的线程中也可以运行不同类型的操作系统。本发明实施例对上述操作系统的类型不做特别限定。The operating system needs to have the ability to independently perform interrupt response and/or task scheduling. Different types of threads can run the same type of operating system, and different types of operating systems can be run in different threads. The type of the above operating system is not particularly limited in the embodiment of the present invention.
任务是泛指操作系统可以处理的任务,在电子设备是基站设备时,任务可以是下发调度指令的任务、分配信道资源的任务、处理接入请求的任务等等。The task is generally referred to as a task that the operating system can process. When the electronic device is a base station device, the task may be a task of issuing a scheduling instruction, a task of allocating a channel resource, a task of processing an access request, and the like.
步骤1103,在处理任务的过程中,通过线程中的操作系统进行任务调度。Step 1103: During the processing of the task, the task scheduling is performed by the operating system in the thread.
与背景技术不同的是,电子设备不通过内核层来对线程中的任务进行任务调度,而是由线程中的操作系统来对线程中的任务进行任务调度。既不需要内核层的中断响应逻辑,也不受内核层的任务调度的影响,独立来完成任务调度。调度时的调度策略可以采用已有的任务调度策略。Different from the background art, the electronic device does not perform task scheduling on the tasks in the thread through the kernel layer, but performs task scheduling on the tasks in the thread by the operating system in the thread. The interrupt response logic of the kernel layer is not needed, and it is not affected by the task scheduling of the kernel layer, and the task scheduling is completed independently. The scheduling policy at the time of scheduling can adopt an existing task scheduling policy.
常见的任务调度包括如下2种:Common task schedules include the following two types:
第一种,以需要从第一任务切换至第二任务为例,本步骤包括如下子步骤,如图12所示:The first one takes the example of switching from the first task to the second task. This step includes the following sub-steps, as shown in FIG. 12:
1103A,当从第一任务切换至第二任务时,电子设备通过线程中的操作系统保存被中断的第一任务的运行现场,第一任务的运行现场包括寄存器信息、第三用户态指令位置和第一任务的锁中断信息;1103A, when switching from the first task to the second task, the electronic device saves the running scene of the interrupted first task by using an operating system in the thread, where the running field of the first task includes the register information, the third user state instruction position, and Lock interrupt information for the first task;
本实施例提供给的线程中的操作系统具有独立完成任务调度的功能。在线程的操作系统中可以实现一个任务调度程序,该任务调度程序用于对操作系统中处理的各个任务进行任务调度。The operating system in the thread provided by this embodiment has the function of independently completing task scheduling. A task scheduler can be implemented in the thread's operating system, and the task scheduler is used to perform task scheduling for each task processed in the operating system.
可选地,从第一任务切换至第二任务可以由中断请求触发,也可以由操作系统中的任务调度程序主动触发。Alternatively, switching from the first task to the second task may be triggered by an interrupt request or may be actively triggered by a task scheduler in the operating system.
比如,第二任务需要延时n毫秒,则该第二任务在挂起后会启用1个定时器,该定时器在延时n毫秒后产生1个中断请求,该中断请求用于请求中断正在运行的第一任务,并将正在运行的第一任务切换为第二任务,以恢复第二任务的运行。For example, if the second task needs to be delayed by n milliseconds, the second task will enable one timer after the suspension, and the timer generates an interrupt request after the delay of n milliseconds, and the interrupt request is used to request that the interrupt is being processed. The first task is run, and the first task that is running is switched to the second task to resume the running of the second task.
又比如,任务调度程序可以在第二任务的优先级达到预设条件时,将正在运行的第一任务切换为第二任务。For another example, the task scheduler may switch the running first task to the second task when the priority of the second task reaches a preset condition.
此时,电子设备通过操作系统中的任务调度程序保存被中断的第一任务的运行现场,第一任务的运行现场包括寄存器信息、第三用户态指令位置和第一 任务的锁中断信息。At this time, the electronic device saves the running site of the interrupted first task by using a task scheduler in the operating system, where the running site of the first task includes the register information, the third user state command position, and the first The lock of the task is interrupted.
其中,锁中断信息是指:由于任务A可能会被任务B中断,任务B可能又被任务C中断,此时会形成中断嵌套,锁中断信息是指一个中断请求在中断嵌套中的层级。The lock interrupt information means that because task A may be interrupted by task B, task B may be interrupted by task C, and interrupt nesting is formed at this time. Lock interrupt information refers to the level of an interrupt request in interrupt nesting. .
1103B,电子设备通过线程中的操作系统获取第二任务的运行现场,第二任务的运行现场包括寄存器信息、第四用户态指令位置和第二任务的锁中断信息;1103B, the electronic device acquires a running site of the second task by using an operating system in the thread, where the running site of the second task includes the register information, the fourth user state command position, and the lock interruption information of the second task;
电子设备可以通过操作系统中的任务调度程序获取第二任务的运行现场。The electronic device can acquire the running site of the second task through the task scheduler in the operating system.
1103C,电子设备通过线程中的操作系统根据第二任务的运行现场恢复第二任务并处理。1103C: The electronic device restores the second task and processes according to the operating site of the second task by using an operating system in the thread.
电子设备可以通过操作系统中的任务调度程序根据运行现场中的寄存器信息和第四用户态指令位置恢复第二任务。The electronic device can restore the second task according to the register information in the running field and the fourth user state command position by the task scheduler in the operating system.
在第二任务被恢复时,电子设备通过任务调度程序根据第二任务的锁中断信息切换解锁中断状态,然后处理该第二任务。When the second task is resumed, the electronic device switches the unlocking interrupt state according to the lock interrupt information of the second task by the task scheduler, and then processes the second task.
第二种,以在一次中断处理后,电子设备调度至需要优先调度的第三任务为例,该第三任务可以是新任务。本步骤包括如下子步骤,如图13所示:Secondly, after an interrupt processing, the electronic device is scheduled to a third task that needs priority scheduling, and the third task may be a new task. This step includes the following sub-steps, as shown in Figure 13:
1103a,在一次中断处理结束时,电子设备通过线程中的操作系统检测是否存在需要优先调度的第三任务;1103a, at the end of an interrupt processing, the electronic device detects, by the operating system in the thread, whether there is a third task that needs to be scheduled preferentially;
电子设备通过操作系统中的任务调度程序检测是否存在需要优先调度的第三任务。The electronic device detects whether there is a third task requiring priority scheduling through a task scheduler in the operating system.
比如,网卡设备接收到1个新的数据包,此时也会产生1个中断请求,该中断请求用于请求对该数据包进行处理,该中断请求被响应后会产生用于处理该数据包的第三任务。For example, if the network card device receives a new data packet, an interrupt request is also generated at this time, and the interrupt request is used to request processing of the data packet, and the interrupt request is generated to be processed for processing the data packet. The third task.
1103b,若存在第三任务,则电子设备通过线程中的操作系统获取第三任务的运行现场,第三任务的运行现场包括寄存器信息、第五用户态指令位置和第三任务的锁中断信息;1103b, if there is a third task, the electronic device acquires a running site of the third task by using an operating system in the thread, where the running site of the third task includes the register information, the fifth user state command location, and the lock interruption information of the third task;
电子设备通过操作系统中的任务调度程序获取第三任务的运行现场。The electronic device acquires the running site of the third task through the task scheduler in the operating system.
1103c,电子设备通过线程中的操作系统根据第三任务的运行现场恢复第三任务并处理。1103c. The electronic device restores the third task and processes according to the operating site of the third task by using an operating system in the thread.
电子设备可以根据根据运行现场中的寄存器信息和第五用户态指令位置恢复第三任务。 The electronic device can resume the third task according to the register information according to the operation site and the fifth user state command position.
在第三任务被恢复时,电子设备通过任务调度程序根据第三任务的锁中断信息将内核层中的锁中断状态切换至解锁中断状态,然后处理该第三任务。When the third task is resumed, the electronic device switches the lock interruption state in the kernel layer to the unlock interruption state according to the lock interruption information of the third task by the task scheduler, and then processes the third task.
综上所述,本实施例提供的任务处理方法,通过在线程中运行操作系统,通过线程中的操作系统进行任务调度;解决了任务调度过程需要多次切换至Linux内核层实现,导致单次任务调度过程的延时较大,影响了任务处理过程的实时性的问题;达到了在用户层中直接完成任务调度,不需要多次切换至内核层,减少任务调度的耗时,提高了任务处理时的实时性的效果。In summary, the task processing method provided in this embodiment performs task scheduling by running an operating system in a thread through an operating system in a thread; and the task scheduling process needs to be switched to the Linux kernel layer multiple times, resulting in a single operation. The delay of the task scheduling process is large, which affects the real-time problem of the task processing process. It achieves the task scheduling directly in the user layer, does not need to switch to the kernel layer multiple times, reduces the time-consuming task scheduling, and improves the task. The effect of real-time processing.
同时,由于背景技术中的任务调度是由内核层来进行,所以内核层的负载较高,本实施例提供的任务处理方法还可以达到降低内核层的负载的效果。At the same time, since the task scheduling in the background technology is performed by the kernel layer, the load of the kernel layer is high, and the task processing method provided in this embodiment can also achieve the effect of reducing the load of the kernel layer.
可以理解,图2-图4任一实施例提供的任务处理装置或图5A或图5B实施例提供的电子设备可以执行图7-图13任一实施例提供的任务处理方法,为描述之简洁,装置实施例各单元或模块的具体功能及工作流程可以参照方法实施例部分的相关,不做过多赘述,同时,本发明提供的各个实施例的内容描述也可以相互参照。It can be understood that the task processing apparatus provided in any of the embodiments of FIG. 2 or FIG. 4 or the electronic apparatus provided in the embodiment of FIG. 5A or FIG. 5B can perform the task processing method provided in any of the embodiments of FIG. 7 to FIG. The specific functions and working procedures of the various units or modules of the device embodiments may be referred to the related parts of the method embodiments, and the descriptions of the various embodiments provided by the present invention may also be referred to each other.
本领域普通技术人员可以理解实现上述实施例的全部或部分步骤可以通过硬件来完成,也可以通过程序来指令相关的硬件完成,所述的程序可以存储于一种计算机可读存储介质中,上述提到的存储介质可以是只读存储器,磁盘或光盘等。A person skilled in the art may understand that all or part of the steps of implementing the above embodiments may be completed by hardware, or may be instructed by a program to execute related hardware, and the program may be stored in a computer readable storage medium. The storage medium mentioned may be a read only memory, a magnetic disk or an optical disk or the like.
以上所述仅为本发明的较佳实施例,并不用以限制本发明,凡在本发明的精神和原则之内,所作的任何修改、等同替换、改进等,均应包含在本发明的保护范围之内。 The above are only the preferred embodiments of the present invention, and are not intended to limit the present invention. Any modifications, equivalents, improvements, etc., which are within the spirit and scope of the present invention, should be included in the protection of the present invention. Within the scope.

Claims (21)

  1. 一种任务处理装置,其特征在于,所述装置包括:A task processing device, characterized in that the device comprises:
    第一运行模块,用于在用户层运行至少一个线程;a first running module, configured to run at least one thread at a user layer;
    第二运行模块,用于在所述线程中运行操作系统,所述操作系统用于处理任务;a second running module, configured to run an operating system in the thread, where the operating system is used to process a task;
    任务处理模块,用于在处理所述任务的过程中,通过所述线程中的所述操作系统进行中断响应和/或任务调度。a task processing module, configured to perform an interrupt response and/or task scheduling by the operating system in the thread during processing of the task.
  2. 根据权利要求1所述的装置,其特征在于,所述任务处理模块,包括:The device according to claim 1, wherein the task processing module comprises:
    请求接收单元,用于通过内核层接收中断源的中断请求;a request receiving unit, configured to receive an interrupt request of an interrupt source through a kernel layer;
    请求传输单元,用于通过所述内核层将所述中断请求传输给所述用户层中对应的线程的操作系统;a requesting transmission unit, configured to transmit, by the kernel layer, the interrupt request to an operating system of a corresponding thread in the user layer;
    请求响应单元,用于通过所述用户层中对应的线程的操作系统的中断处理程序对所述中断请求进行中断响应。And a request response unit, configured to perform an interrupt response to the interrupt request by an interrupt processing program of an operating system of a corresponding thread in the user layer.
  3. 根据权利要求2所述的装置,其特征在于,所述请求传输单元,包括:The device according to claim 2, wherein the request transmission unit comprises:
    第一保存子单元,用于在所述内核层的核心栈中保存被中断的线程的运行现场,所述运行现场包括第一用户态指令位置;a first saving subunit, configured to save an operating site of the interrupted thread in a core stack of the kernel layer, where the running site includes a first user state instruction location;
    转移子单元,用于将所述第一用户态指令位置从所述核心栈中的第一存储位置转移到共享存储区中的第二存储位置进行存储,并将所述中断请求存储到所述共享存储区中的第三存储位置,所述共享存储区为所述内核层和所述用户层均能访问的存储区;a transfer subunit, configured to transfer the first user state instruction location from a first storage location in the core stack to a second storage location in a shared storage area, and store the interrupt request to the a third storage location in the shared storage area, where the shared storage area is a storage area accessible by both the kernel layer and the user layer;
    中断存储子单元,用于在所述核心栈中的第一存储位置中存储所述被中断的线程的所述操作系统中的中断处理程序的起始指令位置;An interrupt storage subunit, configured to store, in a first storage location in the core stack, a start instruction location of an interrupt handler in the operating system of the interrupted thread;
    退出子单元,用于退出所述内核层对所述中断请求的响应。The subunit is exited for exiting the kernel layer response to the interrupt request.
  4. 根据权利要求3所述的装置,其特征在于,所述请求响应单元,包括:The device according to claim 3, wherein the request response unit comprises:
    第一恢复子单元,用于在恢复所述被中断的线程时,从所述核心栈的第一存储位置读取所述操作系统的中断处理程序的起始指令位置;a first recovery subunit, configured to: when recovering the interrupted thread, read a start instruction position of an interrupt handler of the operating system from a first storage location of the core stack;
    第二保存子单元,用于在所述线程的用户栈保存被中断的任务的运行现场, 所述运行现场包括第二用户态指令位置;a second saving subunit, configured to save a running site of the interrupted task in a user stack of the thread, The operation site includes a second user state instruction location;
    栈切换子单元,用于从所述用户栈切换为中断栈;a stack switching subunit, configured to switch from the user stack to an interrupt stack;
    中断响应子单元,用于从所述共享存储区中读取所述中断请求,并基于所述中断栈进行中断响应;An interrupt response subunit, configured to read the interrupt request from the shared memory area, and perform an interrupt response based on the interrupt stack;
    第二恢复子单元,用于在所述中断响应结束后,恢复所述被中断的任务或另一个需要优先调度的任务。And a second recovery subunit, configured to resume the interrupted task or another task that needs to be scheduled after the end of the interrupt response.
  5. 根据权利要求4所述的装置,其特征在于,所述请求响应单元,还包括:The device according to claim 4, wherein the request response unit further comprises:
    替换子单元,用于将所述用户栈中保存的所述第二用户态指令位置,替换为所述共享存储区的第二存储位置中保存的所述第一用户态指令位置;a replacement subunit, configured to replace the second user state instruction location saved in the user stack with the first user state instruction location saved in a second storage location of the shared storage area;
    所述第二恢复子单元,用于通过所述用户栈中保存的所述运行现场,恢复所述被中断的任务。The second recovery subunit is configured to recover the interrupted task by using the running site saved in the user stack.
  6. 根据权利要求1至5任一所述的装置,其特征在于,所述任务处理模块,包括:The device according to any one of claims 1 to 5, wherein the task processing module comprises:
    任务切换单元,用于当从第一任务切换至第二任务时,通过所述操作系统保存被中断的所述第一任务的运行现场,所述第一任务的运行现场包括寄存器信息、第三用户态指令位置和所述第一任务的锁中断信息;a task switching unit, configured to save, by the operating system, an operation site of the interrupted first task when switching from the first task to the second task, where the operation site of the first task includes register information, and a third a user state instruction location and a lock interruption information of the first task;
    第一获取单元,用于通过所述操作系统获取所述第二任务的运行现场,所述第二任务的运行现场包括寄存器信息、第四用户态指令位置和所述第二任务的锁中断信息;a first acquiring unit, configured to acquire, by using the operating system, an operating site of the second task, where the operating site of the second task includes register information, a fourth user state command location, and a lock interruption information of the second task ;
    第一恢复单元,通过所述操作系统根据所述第二任务的运行现场恢复所述第二任务并处理。The first recovery unit recovers the second task and processes according to the operating site of the second task by the operating system.
  7. 根据权利要求1至5任一所述的装置,其特征在于,所述任务处理模块,包括:The device according to any one of claims 1 to 5, wherein the task processing module comprises:
    任务检测单元,用于在一次中断响应结束时,通过所述操作系统检测是否存在需要优先调度的第三任务;a task detecting unit, configured to detect, by the operating system, whether there is a third task that needs to be preferentially scheduled when an interrupt response ends;
    第二获取单元,用于当存在所述第三任务时,通过所述操作系统获取所述第三任务的运行现场,所述第三任务的运行现场包括寄存器信息、第五用户态指令位置和所述第三任务的锁中断信息; a second obtaining unit, configured to acquire, by the operating system, an operation site of the third task when the third task exists, where the running site of the third task includes a register information, a fifth user state instruction location, and The lock interruption information of the third task;
    第二恢复单元,用于通过所述操作系统根据所述第三任务的运行现场恢复所述第三任务并处理。And a second recovery unit, configured to recover the third task and process according to the operating site of the third task by using the operating system.
  8. 一种电子设备,其特征在于,所述电子设备包括:处理器和存储器;An electronic device, comprising: a processor and a memory;
    所述存储器用于存储一个或者一个以上的指令,所述指令用于实现一种任务处理方法;The memory is configured to store one or more instructions for implementing a task processing method;
    所述方法包括:The method includes:
    在用户层运行至少一个线程;Running at least one thread at the user level;
    在所述线程中运行操作系统,所述操作系统用于处理任务;Running an operating system in the thread, the operating system for processing a task;
    在处理所述任务的过程中,通过所述线程中的所述操作系统进行中断响应和/或任务调度;Interrupting response and/or task scheduling by the operating system in the thread during processing of the task;
    所述处理器用于执行所述指令。The processor is operative to execute the instructions.
  9. 根据权利要求8所述的电子设备,其特征在于,所述存储器还存储有用于执行以下操作的指令:The electronic device of claim 8, wherein the memory further stores instructions for performing the following operations:
    通过内核层接收中断源的中断请求;Receiving an interrupt request of an interrupt source through a kernel layer;
    通过所述内核层将所述中断请求传输给所述用户层中对应的线程的操作系统;Transmitting the interrupt request to an operating system of a corresponding thread in the user layer by the kernel layer;
    通过所述用户层中对应的线程的操作系统的中断处理程序对所述中断请求进行中断响应;Interrupting the interrupt request by an interrupt processing program of an operating system of a corresponding thread in the user layer;
    所述处理器还用于执行所述指令。The processor is also operative to execute the instructions.
  10. 根据权利要求9所述的电子设备,其特征在于,所述存储器还存储有用于执行以下操作的指令:The electronic device of claim 9, wherein the memory further stores instructions for performing the following operations:
    在所述内核层的核心栈中保存被中断的线程的运行现场,所述运行现场包括第一用户态指令位置;Saving an operation site of the interrupted thread in a core stack of the kernel layer, the operation site including a first user state instruction location;
    将所述第一用户态指令位置从所述核心栈中的第一存储位置转移到共享存储区中的第二存储位置进行存储,并将所述中断请求存储到所述共享存储区中的第三存储位置;Transferring the first user state instruction location from a first storage location in the core stack to a second storage location in a shared storage area for storage, and storing the interrupt request in the shared storage area Three storage locations;
    在所述核心栈中的第一存储位置中存储所述被中断的线程的所述操作系统中的中断处理程序的起始指令位置; Storing a start instruction location of an interrupt handler in the operating system of the interrupted thread in a first storage location in the core stack;
    退出所述内核层对所述中断请求的响应;Exiting the kernel layer's response to the interrupt request;
    所述处理器还用于执行所述指令。The processor is also operative to execute the instructions.
  11. 根据权利要求10所述的电子设备,其特征在于,所述存储器还存储有用于执行以下操作的指令:The electronic device of claim 10, wherein the memory further stores instructions for performing the following operations:
    在恢复所述被中断的线程时,从所述核心栈的第一存储位置读取所述操作系统的中断处理程序的起始指令位置;Reading the initial instruction location of the interrupt handler of the operating system from the first storage location of the core stack when the interrupted thread is restored;
    在所述线程的用户栈保存被中断的任务的运行现场,所述运行现场包括第二用户态指令位置;A user site of the thread saves an operation site of the interrupted task, the operation site including a second user state instruction location;
    从所述用户栈切换为中断栈;Switching from the user stack to an interrupt stack;
    从所述共享存储区中读取所述中断请求,并基于所述中断栈进行中断响应;Reading the interrupt request from the shared storage area, and performing an interrupt response based on the interrupt stack;
    在所述中断响应结束后,恢复所述被中断的任务或另一个需要优先调度的任务;After the interrupt response ends, recovering the interrupted task or another task requiring priority scheduling;
    所述处理器还用于执行所述指令。The processor is also operative to execute the instructions.
  12. 根据权利要求11所述的电子设备,其特征在于,还存储有用于执行以下操作的指令:The electronic device according to claim 11, characterized by further storing instructions for performing the following operations:
    将所述用户栈中保存的所述第二用户态指令位置,替换为所述共享存储区的第二存储位置中保存的所述第一用户态指令位置;Replacing the second user state instruction location saved in the user stack with the first user state instruction location saved in the second storage location of the shared storage area;
    通过所述用户栈中保存的所述运行现场,恢复所述被中断的任务;Recovering the interrupted task by the running site saved in the user stack;
    所述处理器还用于执行所述指令。The processor is also operative to execute the instructions.
  13. 根据权利要求8至12任一所述的电子设备,其特征在于,还存储有用于执行以下操作的指令:The electronic device according to any one of claims 8 to 12, characterized by further storing instructions for performing the following operations:
    当从第一任务切换至第二任务时,通过所述操作系统保存被中断的所述第一任务的运行现场,所述第一任务的运行现场包括寄存器信息、第三用户态指令位置和所述第一任务的锁中断信息;When the first task is switched to the second task, the operating site of the interrupted first task is saved by the operating system, and the running site of the first task includes register information, a third user state command location, and a location The lock interrupt information of the first task;
    通过所述操作系统获取所述第二任务的运行现场,所述第二任务的运行现场包括寄存器信息、第四用户态指令位置和所述第二任务的锁中断信息;Obtaining, by the operating system, an operation site of the second task, where the operation site of the second task includes register information, a fourth user state instruction location, and lock interruption information of the second task;
    通过所述操作系统根据所述第二任务的运行现场恢复所述第二任务并处理; Recovering and processing the second task according to the operating site of the second task by the operating system;
    所述处理器还用于执行所述指令。The processor is also operative to execute the instructions.
  14. 根据权利要求8至12任一所述的电子设备,其特征在于,还存储有用于执行以下操作的指令:The electronic device according to any one of claims 8 to 12, characterized by further storing instructions for performing the following operations:
    在一次中断响应结束时,通过所述操作系统检测是否存在需要优先调度的第三任务;At the end of an interrupt response, the operating system detects whether there is a third task requiring priority scheduling;
    当存在所述第三任务时,通过所述操作系统获取所述第三任务的运行现场,所述第三任务的运行现场包括寄存器信息、第五用户态指令位置和所述第三任务的锁中断信息;When the third task exists, the operating site of the third task is acquired by the operating system, and the running site of the third task includes register information, a fifth user state command location, and a lock of the third task. Interrupt information;
    通过所述操作系统根据所述第三任务的运行现场恢复所述第三任务并处理;Recovering and processing the third task according to the operating site of the third task by the operating system;
    所述处理器还用于执行所述指令。The processor is also operative to execute the instructions.
  15. 一种任务处理方法,其特征在于,所述方法包括:A task processing method, characterized in that the method comprises:
    在用户层运行至少一个线程;Running at least one thread at the user level;
    在所述线程中运行操作系统,所述操作系统用于处理任务;Running an operating system in the thread, the operating system for processing a task;
    在处理所述任务的过程中,通过所述线程中的所述操作系统进行中断响应和/或任务调度。In the process of processing the task, an interrupt response and/or task scheduling is performed by the operating system in the thread.
  16. 根据权利要求15所述的方法,其特征在于,所述在处理所述任务的过程中,通过所述线程中的所述操作系统进行中断响应,包括:The method according to claim 15, wherein in the process of processing the task, the interrupt response is performed by the operating system in the thread, including:
    通过内核层接收中断源的中断请求;Receiving an interrupt request of an interrupt source through a kernel layer;
    通过所述内核层将所述中断请求传输给所述用户层中对应的线程的操作系统;Transmitting the interrupt request to an operating system of a corresponding thread in the user layer by the kernel layer;
    通过所述用户层中对应的线程的操作系统的中断处理程序对所述中断请求进行中断响应。The interrupt request is interrupted by an interrupt handler of an operating system of a corresponding thread in the user layer.
  17. 根据权利要求16所述的方法,其特征在于,所述通过所述内核层将所述中断请求传输给所述用户层中对应的所述线程的所述操作系统,包括:The method according to claim 16, wherein the transmitting, by the kernel layer, the interrupt request to the operating system of the corresponding one of the user layers comprises:
    在所述内核层的核心栈中保存被中断的线程的运行现场,所述运行现场包括第一用户态指令位置; Saving an operation site of the interrupted thread in a core stack of the kernel layer, the operation site including a first user state instruction location;
    将所述第一用户态指令位置从所述核心栈中的第一存储位置转移到共享存储区中的第二存储位置进行存储,并将所述中断请求存储到所述共享存储区中的第三存储位置,所述共享存储区为所述内核层和所述用户层均能访问的存储区;Transferring the first user state instruction location from a first storage location in the core stack to a second storage location in a shared storage area for storage, and storing the interrupt request in the shared storage area a storage location, where the shared storage area is a storage area accessible by both the kernel layer and the user layer;
    在所述核心栈中的第一存储位置中存储所述被中断的线程的所述操作系统中的中断处理程序的起始指令位置;Storing a start instruction location of an interrupt handler in the operating system of the interrupted thread in a first storage location in the core stack;
    退出所述内核层对所述中断请求的响应。Exiting the kernel layer's response to the interrupt request.
  18. 根据权利要求17所述的方法,其特征在于,所述通过所述操作系统中的中断处理程序对所述中断请求进行中断响应,包括:The method of claim 17, wherein the interrupting the interrupt request by the interrupt handler in the operating system comprises:
    在恢复所述被中断的线程时,从所述核心栈的第一存储位置读取所述操作系统的中断处理程序的起始指令位置;Reading the initial instruction location of the interrupt handler of the operating system from the first storage location of the core stack when the interrupted thread is restored;
    在所述线程的用户栈保存被中断的任务的运行现场,所述运行现场包括第二用户态指令位置;A user site of the thread saves an operation site of the interrupted task, the operation site including a second user state instruction location;
    从所述用户栈切换为中断栈;Switching from the user stack to an interrupt stack;
    从所述共享存储区中读取所述中断请求,并基于所述中断栈进行中断响应;Reading the interrupt request from the shared storage area, and performing an interrupt response based on the interrupt stack;
    在所述中断响应结束后,恢复所述被中断的任务或另一个需要优先调度的任务。After the interrupt response ends, the interrupted task or another task requiring prioritization is resumed.
  19. 根据权利要求18所述的方法,其特征在于,所述从所述用户栈切换为中断栈之前,还包括:The method according to claim 18, wherein before the switching from the user stack to the interrupt stack, the method further comprises:
    将所述用户栈中保存的所述第二用户态指令位置,替换为所述共享存储区的第二存储位置中保存的所述第一用户态指令位置;Replacing the second user state instruction location saved in the user stack with the first user state instruction location saved in the second storage location of the shared storage area;
    所述在所述中断响应结束后,恢复所述被中断的任务,包括:Recovering the interrupted task after the interrupt response ends, including:
    通过所述用户栈中保存的所述运行现场,恢复所述被中断的任务。The interrupted task is resumed by the running site saved in the user stack.
  20. 根据权利要求15至19任一所述的方法,其特征在于,所述在执行所述任务的过程中,通过所述线程中的所述操作系统进行任务调度,包括:The method according to any one of claims 15 to 19, wherein in the performing the task, the task scheduling is performed by the operating system in the thread, including:
    当从第一任务切换至第二任务时,通过所述操作系统保存被中断的所述第一任务的运行现场,所述第一任务的运行现场包括寄存器信息、第三用户态指令位置和所述第一任务的锁中断信息; When the first task is switched to the second task, the operating site of the interrupted first task is saved by the operating system, and the running site of the first task includes register information, a third user state command location, and a location The lock interrupt information of the first task;
    通过所述操作系统获取所述第二任务的运行现场,所述第二任务的运行现场包括寄存器信息、第四用户态指令位置和所述第二任务的锁中断信息;Obtaining, by the operating system, an operation site of the second task, where the operation site of the second task includes register information, a fourth user state instruction location, and lock interruption information of the second task;
    通过所述操作系统根据所述第二任务的运行现场恢复所述第二任务并处理。And recovering, by the operating system, the second task according to the running site of the second task and processing.
  21. 根据权利要求15至19任一所述的方法,其特征在于,所述在执行所述任务的过程中,通过所述线程中的所述操作系统进行任务调度,包括:The method according to any one of claims 15 to 19, wherein in the performing the task, the task scheduling is performed by the operating system in the thread, including:
    在一次中断响应结束时,通过所述操作系统检测是否存在需要优先调度的第三任务;At the end of an interrupt response, the operating system detects whether there is a third task requiring priority scheduling;
    当存在所述第三任务时,通过所述操作系统获取所述第三任务的运行现场,所述第三任务的运行现场包括寄存器信息、第五用户态指令位置和所述第三任务的锁中断信息;When the third task exists, the operating site of the third task is acquired by the operating system, and the running site of the third task includes register information, a fifth user state command location, and a lock of the third task. Interrupt information;
    通过所述操作系统根据所述第三任务的运行现场恢复所述第三任务并处理。 And recovering, by the operating system, the third task according to an operation site of the third task and processing.
PCT/CN2014/085834 2014-09-03 2014-09-03 Task handling apparatus and method, and electronic device WO2016033755A1 (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
PCT/CN2014/085834 WO2016033755A1 (en) 2014-09-03 2014-09-03 Task handling apparatus and method, and electronic device
CN201480034730.1A CN105579963B (en) 2014-09-03 2014-09-03 Task Processing Unit, electronic equipment and method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/CN2014/085834 WO2016033755A1 (en) 2014-09-03 2014-09-03 Task handling apparatus and method, and electronic device

Publications (1)

Publication Number Publication Date
WO2016033755A1 true WO2016033755A1 (en) 2016-03-10

Family

ID=55439004

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2014/085834 WO2016033755A1 (en) 2014-09-03 2014-09-03 Task handling apparatus and method, and electronic device

Country Status (2)

Country Link
CN (1) CN105579963B (en)
WO (1) WO2016033755A1 (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113141385A (en) * 2020-01-19 2021-07-20 大唐移动通信设备有限公司 Data receiving and processing method and device, electronic equipment and storage medium
CN113296900A (en) * 2020-02-21 2021-08-24 大唐移动通信设备有限公司 Task switching method and device
CN116521340A (en) * 2023-04-27 2023-08-01 福州慧林网络科技有限公司 Low-delay parallel data processing system and method based on large-bandwidth network

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116737366A (en) * 2023-05-15 2023-09-12 广州汽车集团股份有限公司 Processing method and device of shared stack, electronic equipment and storage medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101267361A (en) * 2008-05-09 2008-09-17 武汉飞思科技有限公司 A high-speed network data packet capturing method based on zero duplication technology
CN102625064A (en) * 2012-03-28 2012-08-01 深圳市茁壮网络股份有限公司 Method and device for receiving and identifying infrared remote control signal
CN103440169A (en) * 2013-08-21 2013-12-11 华为技术有限公司 Process interruption processing method and device
US20140115591A1 (en) * 2012-10-18 2014-04-24 Oracle International Corporation Apparatus, system and method for providing fairness in task servicing

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7870553B2 (en) * 2003-08-28 2011-01-11 Mips Technologies, Inc. Symmetric multiprocessor operating system for execution on non-independent lightweight thread contexts
CN1825286A (en) * 2006-03-31 2006-08-30 浙江大学 Threading realizing and threading state transition method for embedded SRAM operating system
CN103870326B (en) * 2012-12-11 2018-07-13 厦门雅迅网络股份有限公司 A kind of method and application that interrupt handling routine bottom half is moved to application layer

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101267361A (en) * 2008-05-09 2008-09-17 武汉飞思科技有限公司 A high-speed network data packet capturing method based on zero duplication technology
CN102625064A (en) * 2012-03-28 2012-08-01 深圳市茁壮网络股份有限公司 Method and device for receiving and identifying infrared remote control signal
US20140115591A1 (en) * 2012-10-18 2014-04-24 Oracle International Corporation Apparatus, system and method for providing fairness in task servicing
CN103440169A (en) * 2013-08-21 2013-12-11 华为技术有限公司 Process interruption processing method and device

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113141385A (en) * 2020-01-19 2021-07-20 大唐移动通信设备有限公司 Data receiving and processing method and device, electronic equipment and storage medium
CN113141385B (en) * 2020-01-19 2022-11-15 大唐移动通信设备有限公司 Data receiving and processing method and device, electronic equipment and storage medium
CN113296900A (en) * 2020-02-21 2021-08-24 大唐移动通信设备有限公司 Task switching method and device
CN116521340A (en) * 2023-04-27 2023-08-01 福州慧林网络科技有限公司 Low-delay parallel data processing system and method based on large-bandwidth network
CN116521340B (en) * 2023-04-27 2023-10-10 福州慧林网络科技有限公司 Low-delay parallel data processing system and method based on large-bandwidth network

Also Published As

Publication number Publication date
CN105579963A (en) 2016-05-11
CN105579963B (en) 2019-10-01

Similar Documents

Publication Publication Date Title
JP5405320B2 (en) Virtual machine control device, virtual machine control method, and virtual machine control program
US10884786B2 (en) Switch device, switching method, and computer program product
CN108647104B (en) Request processing method, server and computer readable storage medium
CN106844017B (en) Method and device for processing events by website server
US20090271796A1 (en) Information processing system and task execution control method
JP4529767B2 (en) Cluster configuration computer system and system reset method thereof
JP5167844B2 (en) Processor, electronic device, interrupt control method, and interrupt control program
US20110107344A1 (en) Multi-core apparatus and load balancing method thereof
US10459773B2 (en) PLD management method and PLD management system
JP2007219757A (en) Program for making virtual computer system function
US9632842B2 (en) Exclusive access control method prohibiting attempt to access a shared resource based on average number of attempts and predetermined threshold
WO2016033755A1 (en) Task handling apparatus and method, and electronic device
US9389923B2 (en) Information processing device and method for controlling information processing device
US10229077B2 (en) Method for data transfer between real-time tasks using a DMA memory controller
US9652299B2 (en) Controlling the state of a process between a running and a stopped state by comparing identification information sent prior to execution
KR102053849B1 (en) Airplane system and control method thereof
WO2011116672A1 (en) Method and apparatus for patching shared code segment
JP7012915B2 (en) controller
JP2006085428A (en) Parallel processing system, interconnection network, node and network control program
JP2010134698A (en) Information processing system
US20030014558A1 (en) Batch interrupts handling device, virtual shared memory and multiple concurrent processing device
JP4259390B2 (en) Parallel processing unit
JP5783348B2 (en) Control device, control program, and image forming apparatus
WO2012101759A1 (en) Processor processing method, and processor system
US10261817B2 (en) System on a chip and method for a controller supported virtual machine monitor

Legal Events

Date Code Title Description
WWE Wipo information: entry into national phase

Ref document number: 201480034730.1

Country of ref document: CN

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

Ref document number: 14901012

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: 14901012

Country of ref document: EP

Kind code of ref document: A1