Method, device and system for switching client operating system
By setting multiple memory spaces, configuration registers and stack registers in the chip, and using the virtual machine monitor to automatically complete the Guest OS switching process, the problem of long Guest OS switching time caused by the AUTOSARCP domain chip does not support MMU, achieving the effect of significantly reducing the switching time.
Patent Information
- Application Number
- CN202411971395.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-30
- Publication Date
- 2025-04-04
AI Technical Summary
When many chips in the AUTOSARCP domain do not support MMU, the switching time of Guest OS is long, mainly because the switching work is completed by the software, which consumes a lot of time.
By setting multiple memory spaces, configuration registers and stack registers corresponding to the number of guest operating systems in the chip, each guest operating system is configured with one configuration register and two stack registers. When switching between Guest OS using the virtual machine monitor, the target memory space pointed to by the stack register is determined, and the target register is determined based on the bit identification in the configuration register, and the storage location of the target register is updated based on the target memory space.
By dividing separate memory space for each Guest OS, adding stack registers and configuration registers, most of the switching process is automatically completed by digital logic, significantly reducing switching time.
Smart Images

Figure CN119759503A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of chip technology, for example, to a switching method, device and system for a client operating system. Background Art
[0002] With the development of electronic technology, the number of electronic control units (Memory Management Unit ECU) in automobiles has continued to increase, forcing automobile OEMs (Original Equipment Manufacturers) to integrate multiple units into a single high-computing platform, which has gradually led to the application of virtualization technology in the field of automotive electronics. Tasks in a virtualized environment may involve multiple Guest OSs. By switching Guest OSs, the virtualization platform can flexibly manage these tasks to ensure that they are executed smoothly in different operating system environments. If the chip supports MMU (Memory Management Unit), the conversion of address space can be efficiently completed at the hardware level through hardware MMU technology, thereby reducing switching time.
[0003] In the process of implementing the embodiments of the present disclosure, it was found that there are at least the following problems in the related technology: many chips in the current AUTOSARCP (Automotive Open System Architecture Classic Platform) domain do not support MMU, which requires that during the Guest OS switching process, most of the switching work be completed by software, which is time-consuming.
[0004] It should be noted that the information disclosed in the above background technology section is only used to enhance the understanding of the background of the present application, and therefore may include information that does not constitute the prior art known to ordinary technicians in the field. Summary of the invention
[0005] In order to provide a basic understanding of some aspects of the disclosed embodiments, a brief summary is given below. The summary is not an extensive review, nor is it intended to identify key / critical components or delineate the scope of protection of these embodiments, but rather serves as a prelude to the detailed description that follows.
[0006] The embodiments of the present disclosure provide a method, device and system for switching a guest operating system, so as to reduce the switching time of the Guest OS when the chip does not support MMU.
[0007] In some embodiments, the chip's memory is configured with multiple memory spaces corresponding to the number of client operating systems, the chip is configured with configuration registers and stack registers that match the number of memory spaces, and each client operating system is configured with one configuration register and two stack registers; the switching method for client operating systems includes: when the virtual machine monitor performs a switching operation between client operating systems, determining the target memory space pointed to by the stack register; determining the target register based on the bit identifier in the configuration register; and updating the storage location of the target switching data corresponding to the target register based on the target memory space.
[0008] In some embodiments, a switching device for a client operating system includes: a system configuration module, configured to set a plurality of memory spaces corresponding to the number of client operating systems, and to set configuration registers and stack registers matching the number of memory spaces, each client operating system being configured with one configuration register and two stack registers; a client operating system switching module, configured to determine a target memory space pointed to by a stack register when a virtual machine monitor performs a switching operation between client operating systems; determine a target register according to a bit identifier in the configuration register; and update a storage location of target switching data corresponding to the target register based on the target memory space.
[0009] In some embodiments, the switching method for the client operating system includes a processor and a memory storing program instructions, and the processor is configured to perform the aforementioned switching method for the client operating system when executing the program instructions.
[0010] In some embodiments, a switching system for client operating systems includes: multiple client operating systems; memory spaces, the number of which corresponds to the number of client operating systems; configuration registers, the number of which is consistent with the number of memory spaces; stack registers, the number of which is twice the number of memory spaces; and the aforementioned switching device for client operating systems.
[0011] The method, device and system for switching a client operating system provided by the embodiments of the present disclosure can achieve the following technical effects:
[0012] In the technical solution disclosed in the present invention, the memory of the chip is set to have multiple memory spaces corresponding to the number of client operating systems, and the chip is set to have configuration registers and stack registers that match the number of memory spaces, and each client operating system is configured with one configuration register and two stack registers. When the virtual machine monitor performs a switching operation between client operating systems, the target memory space pointed to by the stack register is determined, and then the target register is determined based on the bit identifier in the configuration register, and then the storage location of the target switching data corresponding to the target register is updated based on the target memory space to complete the switching process. In this way, by dividing a separate memory space for each Guest OS, adding stack registers and configuration registers, most of the switching process is automatically completed by digital logic, thereby reducing the switching time. By sacrificing additional memory space and adding registers, the time consumed by the Guest OS switching is reduced.
[0013] The above general description and the following description are exemplary and explanatory only and are not intended to limit the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0014] One or more embodiments are exemplarily described by corresponding drawings, which do not limit the embodiments. Elements with the same reference numerals in the drawings are shown as similar elements, and the drawings do not constitute a scale limitation, and wherein:
[0015] Figure 1 is a structural schematic diagram of a switching system for a client operating system provided by an embodiment of the present disclosure;
[0016] Figure 2 is a structural schematic diagram of another switching system for a client operating system provided by an embodiment of the present disclosure;
[0017] Figure 3 is a flow chart of a method for switching a client operating system provided by an embodiment of the present disclosure;
[0018] Figure 4 is a flowchart of another method for switching a client operating system provided by an embodiment of the present disclosure;
[0019] Figure 5 is a flowchart of another method for switching a client operating system provided by an embodiment of the present disclosure;
[0020] Figure 6 is a flowchart of another method for switching a client operating system provided by an embodiment of the present disclosure;
[0021] Figure 7 is a flowchart of another method for switching a client operating system provided by an embodiment of the present disclosure;
[0022] Figure 8 is a structural schematic diagram of a switching device for a client operating system provided by an embodiment of the present disclosure;
[0023] Fig. 9 It is a structural schematic diagram of another switching device for a client operating system provided by an embodiment of the present disclosure. DETAILED DESCRIPTION
[0024] In order to be able to understand the features and technical contents of the embodiments of the present disclosure in more detail, the implementation of the embodiments of the present disclosure is described in detail below in conjunction with the accompanying drawings. The attached drawings are for reference only and are not used to limit the embodiments of the present disclosure. In the following technical description, for the convenience of explanation, a full understanding of the disclosed embodiments is provided through multiple details. However, one or more embodiments can still be implemented without these details. In other cases, to simplify the drawings, well-known structures and devices can be simplified for display.
[0025] The terms "first", "second", etc. in the specification and claims of the embodiments of the present disclosure and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the terms used in this way can be interchanged where appropriate, so that the embodiments of the embodiments of the present disclosure described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions.
[0026] Unless otherwise specified, the term "plurality" means two or more than two. In the disclosed embodiment, the character " / " indicates that the objects before and after are in an "or" relationship. For example, A / B means: A or B. The term "and / or" is a description of the association relationship between objects, indicating that three relationships may exist. For example, A and / or B means: A or B, or, the three relationships of A and B. The term "corresponding" may refer to an association relationship or a binding relationship, and the correspondence between A and B means that there is an association relationship or a binding relationship between A and B.
[0027] Combination Figure 1 As shown, in the technical solution of the present application, the switching system for the guest operating system includes: multiple guest operating systems Guest OS; memory spaces, the number of which corresponds to the number of guest operating systems; configuration registers, the number of which is consistent with the number of memory spaces; stack registers, the number of which is twice the number of memory spaces; and the aforementioned switching device for the guest operating system. The guest operating system communicates with the hardware through a virtual machine monitor (Hypervisor).
[0028] The chip memory is configured with multiple memory spaces corresponding to the number of client operating systems, and the chip is configured with configuration registers and stack registers matching the number of memory spaces. Each client operating system is configured with one configuration register and two stack registers. The two stack registers respectively store the current stack pointer and the stack bottom pointer corresponding to the client operating system. The current stack pointer points to the target memory space. The initial current stack pointer and the stack bottom pointer are both set to the starting address of the memory space.
[0029] The relationship between Hypervisor, Guest OS, memory space, configuration registers and stack registers is as follows Figure 1 As shown in the figure: The Guest OS is located above the Hypervisor, and the Hypervisor is responsible for the switching operation between Guest OSes. Memory space, configuration registers, and stack registers are added to the Guest OS. The memory space is used to store important data and register contents, the configuration registers are used to identify which registers need to be saved, and the stack registers are used to point to the location in the stack space.
[0030] The following is a further explanation of some technical terms in this application:
[0031] A guest operating system (Guest OS) refers to an operating system installed and running on a virtual machine (VM) in a virtualized environment. The guest operating system provides an operating environment and resources for applications. In a virtualized environment, the guest operating system enables multiple applications to run independently on the same physical computer without interfering with each other. In addition, the guest operating system can also provide functions such as security isolation, resource management and optimization to meet the needs of different applications. In the technical solution disclosed in the present invention, the number of Guest OS is N, each Guest OS corresponds to a memory space, and N separate memory spaces are divided in the chip memory.
[0032] A configuration register is a hardware register used to store configuration information about memory space or other system resources. By reading the configuration register, you can understand the properties of each memory space, such as whether it is valid, whether it is readable / writable, whether it is executable, etc. In the technical solution disclosed in the present invention, configuration registers matching the number of memory spaces are set, that is, N configuration registers are added to the chip. Each bit in the configuration register corresponds to a register, for example, bit 0 identifies a virtual timer register, bit 1 identifies a virtual interrupt register, bit 2 identifies a system control register, etc. Combined with Figure 2 As shown, the corresponding bit in the configuration register is set to 1, indicating that the corresponding register will be saved to the stack during the switching process; it is set to 0, indicating that the corresponding register does not need to be saved to the stack during the switching process.
[0033] The stack register is a hardware register used to point to the current position of the top of the stack. In computer architecture, a stack is a last-in-first-out (LIFO) data structure used to store temporary data, function call parameters, local variables, etc. The stack register is used to track the position of the top of the stack so that data can be popped from the stack or pushed into the stack when needed. In the technical solution disclosed in the present invention, a stack register that matches the amount of memory space is set, that is, 2N stack registers are added to the chip. The two stack registers store the bottom stack pointer and the current stack pointer of the Guest OS respectively. The bottom stack pointer points to the bottom address of the memory space, and the current stack pointer points to the address currently used to store data. When the Hypervisor is initialized, both stack registers are set to the bottom address of the Guest OS allocated space, and the value of the configuration register identifies the important registers that need to be saved and restored during the switching process.
[0034] In some embodiments, the size of the memory space satisfies the following relationship: N≥N1+N2, where N is the size of the memory space, N1 is the size of the key data, and N2 is the size of the target switching data.
[0035] Among them, key data refers to data that is critical, urgent and important during the operation and switching of the client operating system. In some practical applications, key data includes system core data (such as key data structures of the operating system kernel, process control blocks, etc.), real-time task data (need to be quickly accessed and processed), key business data (such as transaction records, etc.) and security-related data (such as security keys, authentication information, etc.).
[0036] In this way, by storing key data separately from target switching data and ensuring that the memory space is large enough to accommodate both (N≥N1+N2), and ensuring that the space of each Guest OS does not overlap, the risk of data loss or damage can be reduced during system switching, thereby improving data security. At the same time, during the system switching process, key data is properly protected and processed. Even if some unexpected system events (such as power failure, hardware failure, etc.) occur, the system can recover to a stable state more quickly, reducing the risk of system crash or downtime.
[0037] The present disclosure provides a method for switching a client operating system. Figure 3 As shown, the following steps are included:
[0038] S301, when a virtual machine monitor performs a switching operation between guest operating systems, determining a target memory space pointed to by a stack register.
[0039] When the client operating system needs to perform a switch operation, the system will first check the stack register. By reading the current stack pointer in the stack register, the system can determine the location of the stack frame (i.e., memory space) currently in use, and the system will use this stack frame as the target memory space to prepare for subsequent switch data update operations.
[0040] S302: Determine a target register according to a bit identifier in the configuration register.
[0041] The system determines the target register to be updated based on the value of the bit mark in the configuration register. These bit marks are usually represented by a specific encoding method, and the system can parse these encodings and find the corresponding target register.
[0042] S303: Based on the target memory space, update the storage location of the target switching data corresponding to the target register.
[0043] After determining the target memory space and target register, the system will update the storage location of the target switching data corresponding to the target register according to the information in the target memory space. This process usually involves copying the target switching data from the current location to the new location. In this way, after the operating system switch is completed, the new operating system can correctly access and use these switching data.
[0044] In the disclosed embodiment, the chip's memory is configured with a plurality of memory spaces corresponding to the number of client operating systems, the chip is configured with configuration registers and stack registers that match the number of memory spaces, and each client operating system is configured with one configuration register and two stack registers. When the virtual machine monitor performs a switching operation between client operating systems, the target memory space pointed to by the stack register is determined, and then the target register is determined based on the bit identifier in the configuration register, and then the storage location of the target switching data corresponding to the target register is updated based on the target memory space to complete the switching process. By dividing a separate memory space for each Guest OS, adding stack registers and configuration registers, most of the switching process is automatically completed by digital logic, and since each Guest OS has its own independent memory space, and only the values of a few key registers need to be updated during switching, the time for context saving and recovery can be significantly reduced, thereby reducing the switching time.
[0045] In some embodiments, based on the target memory space, the storage location of the target switching data corresponding to the target register is updated, including: when the switching operation is swapping out, the target switching data corresponding to the target register is copied to the target memory space pointed to by the current stack pointer, and the position of the current stack pointer is updated; and / or, when the switching operation is swapping in, the target switching data in the target memory space pointed to by the current stack pointer is copied to the target register, and the position of the current stack pointer is updated.
[0046] When the Guest OS is swapped out, the system will back up the target switching data in the target register to the previously determined target memory space (i.e., part of the current stack frame or a memory area reserved specifically for this purpose). After the backup is completed, the system will update the current stack pointer in the stack register to reflect the new stack top position. Generally speaking, the current stack pointer will move downward (when the stack grows downward) to make room for the next switch operation or other stack operations.
[0047] When the Guest OS is swapped in, the system reads the previously backed-up target switching data from the target memory space and restores it to the target registers, including restoring the state of the CPU registers, the program counter, and the stack pointer. After the restoration is complete, the system updates the current stack pointer in the stack register again to reflect the restored stack top position. This usually means that the stack pointer moves upward (if the stack reduction direction is upward) to reflect the restored stack frame.
[0048] Combination Figure 4 As shown, a method for switching a client operating system is provided, comprising the following steps:
[0049] S401, when a virtual machine monitor performs a switching operation between guest operating systems, determining a target memory space pointed to by a stack register.
[0050] S402, determining a target register according to a bit identifier in the configuration register.
[0051] In practical applications, each bit identifier in the configuration register corresponds to a register, and the target register is determined according to the bit identifier.
[0052] In some possible implementations, the target register is determined based on the bit identifier in the configuration register, including: when the switching operation is swapping out, determining whether the saved data of the register is saved to the target memory space during the switching operation based on the bit identifier; and using the register whose data needs to be saved to the target memory space during the switching operation as the target register.
[0053] According to the bit identifier, determine whether the saved data of the register is saved to the target memory space during the switching operation, including: determining that the saved data of the register corresponding to the bit identifier with a value of 1 is saved to the target memory space during the switching operation; determining that the saved data of the register corresponding to the bit identifier with a value of 0 is not saved to the target memory space during the switching operation.
[0054] In some possible implementations, the target register is determined based on the bit identifier in the configuration register, including: when the switching operation is a swap-in, determining the register to which the saved data of the target memory space needs to be saved during the switching operation based on the bit identifier; and using the register to which the saved data of the target memory space needs to be saved during the switching operation as the target register.
[0055] According to the bit identifier, determine the register to which the saved data of the target memory space needs to be saved during the switching operation, including: determining that the register corresponding to the bit identifier with a value of 1 is the register to which the saved data of the target memory space needs to be saved during the switching operation; determining that the register corresponding to the bit identifier with a value of 0 is not the register to which the saved data of the target memory space needs to be saved during the switching operation.
[0056] A configuration register is a collection of one or more binary bits, each of which can be independently set to 0 or 1 to represent different configuration options or status information. A bit flag is used to indicate a specific register in a configuration register. A bit flag set to 1 indicates the target register that needs to be updated or operated.
[0057] The target register is dynamically determined by the bit identifier in the configuration register, so that the system can flexibly adapt to different configuration requirements. When the register that needs to be updated or operated changes, only the value of the configuration register needs to be modified without modifying the core code or data structure of the system. This technical solution can quickly determine the target register and update or operate it, reducing the delay and overhead of the system when processing switching requests, allowing the system to respond and complete tasks faster.
[0058] S403, when the switching operation is swapping out, copy the target switching data corresponding to the target register to the target memory space pointed to by the current stack pointer, and update the position of the current stack pointer.
[0059] S404, when the switching operation is a swap-in, copy the target switching data in the target memory space pointed to by the current stack pointer to the target register, and update the position of the current stack pointer.
[0060] In the disclosed embodiment, by backing up the target switching data to the memory space when the client operating system is swapped out, and restoring it from the memory space when it is swapped in, the integrity and consistency of the data are ensured, which helps to prevent the loss or damage of data during the client operating system switching process. Moreover, by directly backing up and restoring the register data instead of the entire operating system state, the efficiency of operating system switching can be significantly improved, the delay and overhead in the switching process can be reduced, and the system can respond to the switching request more quickly.
[0061] In some embodiments, based on the target memory space, the storage location of the target switching data corresponding to the target register is updated, including: when the switching operation is swapping out, the key data of the current client operating system is copied to the target memory space pointed to by the current stack pointer, and the position of the current stack pointer is updated; after updating the position of the current stack pointer, the target switching data corresponding to the target register is copied to the target memory space pointed to by the current stack pointer, and the position of the current stack pointer is updated.
[0062] Among them, the critical data can be stored in a specific register indicated by an additional field in the configuration register, or in a separate priority register. In the case where the switching operation is swapping out, the system will first check the position of the current stack pointer in the stack register, and determine a free or pre-allocated memory area as the target memory space based on the position of the current stack pointer. The size of this space should be large enough to accommodate all critical data that need to be backed up. The system reads the critical data and backs it up to the target memory space. After backing up the critical data, the system will update the current stack pointer and continue to execute the next step of the switching operation, that is, update the storage location of the target switching data corresponding to the target register.
[0063] In some embodiments, based on the target memory space, the storage location of the target switching data corresponding to the target register is updated, including: when the switching operation is a swap-in, the target switching data in the target memory space pointed to by the current stack pointer is copied to the target register, and the position of the current stack pointer is updated; after updating the position of the current stack pointer, the key data of the current client operating system pointed to by the current stack pointer is copied to the specified position of the current memory space, and the current stack pointer is updated until the current stack pointer and the stack bottom pointer are equal, and the switch is completed.
[0064] In the case where the switching operation is a swap-in, the system will first update the storage location of the target switching data corresponding to the target register according to the previously saved task context information. After updating the data of the target register, the system will check the position of the current stack pointer in the stack register to determine the target memory space used when backing up the key data before, read the key data from the target memory space, and restore it to the specified location of the current memory space or the corresponding register. After restoring the key data, the system will update the current stack pointer to point to the correct task context.
[0065] In some embodiments, in combination Figure 5 As shown, the switching method for the client operating system includes the following steps:
[0066] S501, when the virtual machine monitor performs a switching operation between guest operating systems, determining a target register according to a bit identifier in a configuration register.
[0067] S502: When the switching operation is swapping out, determine the target memory space corresponding to the current stack pointer in the stack register.
[0068] S503, copy the key data of the current client operating system to the target memory space pointed to by the current stack pointer, and update the position of the current stack pointer.
[0069] S504, after the position of the current stack pointer is updated, the target switching data corresponding to the target register is copied to the target memory space pointed to by the current stack pointer, and the position of the current stack pointer is updated.
[0070] S505: When the switching operation is a swap-in, determine the target memory space corresponding to the current stack pointer in the stack register.
[0071] S506, copy the target switching data in the target memory space pointed to by the current stack pointer to the target register, and update the position of the current stack pointer.
[0072] S507, after updating the position of the current stack pointer, copy the key data of the current client operating system pointed to by the current stack pointer to the specified position of the current memory space, and update the current stack pointer until the current stack pointer is equal to the stack bottom pointer, and the switching is completed.
[0073] Optionally, copying the critical data of the current client operating system pointed to by the current stack pointer to a specified location in the current memory space includes: continuously restoring the critical data from the target memory space to the specified location in the current memory space until the current stack pointer is equal to the stack bottom pointer.
[0074] In the disclosed embodiment, by backing up key data before the switching operation, the system can ensure that even if an accident occurs during the switching process (such as power failure, hardware failure, etc.), these key data will not be lost, which helps to protect the stability and reliability of the system and prevent system crashes or task failures caused by data loss. By restoring key data to the corresponding registers after the swap-in operation, it can be ensured that the task can be correctly continued from the previous execution point, preventing task failures or system crashes caused by data loss or damage.
[0075] In some embodiments, when there are multiple target registers, the storage location of the target switching data corresponding to the target register is updated based on the target memory space, including: based on the target memory space, according to the position order of the target bit identifier, the storage location of the multiple target switching data corresponding to the target register is updated; wherein the target bit identifier is a bit identifier with a value of 1 in the configuration register; or, based on the target memory space, according to the priority of the target register, the storage location of the multiple target switching data corresponding to the target register is updated; or, based on the target memory space, the storage location of the multiple target switching data corresponding to the target register is updated in parallel.
[0076] The above implementations provide multiple options, allowing the system to flexibly select the most appropriate update strategy based on specific needs and environments. Whether based on location order, priority or parallel update, these implementations can effectively improve the efficiency of storage location updates and reduce delays and resource consumption during switching.
[0077] In some possible implementations, combined with Figure 6 As shown, the switching method for the client operating system includes the following steps:
[0078] S601, when the virtual machine monitor performs a switching operation between guest operating systems, determining a target memory space indicated by a current stack pointer in a stack register.
[0079] S602: Determine a target register according to a bit identifier in the configuration register.
[0080] S603, when there are multiple target registers, based on the target memory space, the storage locations of multiple target switching data corresponding to the target registers are updated according to the position order of the target bit identifiers.
[0081] Here, the target bit identifier is a bit identifier whose value is 1 in the configuration register.
[0082] In actual applications, the system processes each target register in turn according to the position order of the target bit identifier in the configuration register (from left to right or from right to left, depending on the specific implementation). For each target register, the system reads its corresponding switching data (such as register value) from the target memory space and updates these switching data to the target memory space for use in the execution context after switching. After each target register is processed, the current stack pointer is updated.
[0083] Based on the target memory space, the storage location of multiple target switching data corresponding to the target register is updated according to the position order of the target bit identifier. By accurately updating the target switching data, the execution context after switching is ensured to be consistent with that before switching, avoiding data loss or inconsistency.
[0084] In some possible implementations, combined with Figure 7 As shown, the switching method for the client operating system includes the following steps:
[0085] S701, when a virtual machine monitor performs a switching operation between guest operating systems, determining a target memory space indicated by a current stack pointer in a stack register.
[0086] S702, determine the target register according to the bit identifier in the configuration register.
[0087] S703: When there are multiple target registers, based on the target memory space, update the storage locations of multiple target switching data corresponding to the target registers in parallel.
[0088] Optionally, based on the target memory space, the storage locations of multiple target switching data corresponding to the target register are updated in parallel, including: after acquiring the mutex lock of the current target register, determining the preset storage data size corresponding to the current target register; based on the target memory space, according to the preset storage data size, the storage locations of multiple target switching data corresponding to the target register are updated in parallel; after updating the storage locations of the target switching data corresponding to all target registers, updating the current stack pointer.
[0089] In some practical applications, when the switching operation is swapping out, based on the target memory space, according to the preset storage data size, the target switching data of each target register is backed up to the target memory space in parallel, and after the target switching data of all target registers are backed up to the target memory space, the current stack pointer is updated.
[0090] In some practical applications, when the switching operation is swap-in, based on the target memory space, according to the preset storage data size, the target switching data is restored from the target memory space to the target register in parallel, and after all the target switching data are restored from the target memory space to the target register, the current stack pointer is updated.
[0091] To ensure data consistency and integrity, the system first acquires a mutex lock for each target register that needs to be updated to prevent data contention or data corruption during the update process. After completing the storage location update of the target switching data, the system releases the previously acquired mutex lock so that other units can access or modify the data of the target register.
[0092] Each target register has a specific data size, which is determined when the system is designed. The system will allocate the corresponding area in the target memory space according to this preset size. For example, assuming that the size of the target memory space is 256 bytes, there are 3 target registers: R1 (integer register): 32 bits (4 bytes); R2 (floating point register): 64 bits (8 bytes); R3 (address register): 64 bits (8 bytes). Then, R1 is a 32-bit integer register, 4 bytes of memory space are allocated to it, assuming that the starting address of the target memory space is 0x1000, the value of R1 will be saved between addresses 0x1000 and 0x1003; R2 is a 64-bit floating-point register, 8 bytes of memory space are allocated to it, immediately after the memory space of R1, the value of R2 will be saved between addresses 0x1004 and 0x100B; R3 is a 64-bit address register, requiring 8 bytes of memory space, immediately after the memory space of R2, the value of R3 will be saved between addresses 0x100C and 0x1013.
[0093] In the disclosed embodiment, by updating the data of multiple target registers in parallel, the system can significantly reduce the time required for task switching. At the same time, using a mutex to ensure the atomicity of data update can prevent data competition or data corruption during task switching, thereby enhancing data consistency and integrity.
[0094] In some embodiments, the switching device 800 for a guest operating system includes:
[0095] The system configuration module 801 is configured to set a plurality of memory spaces corresponding to the number of client operating systems, and to set configuration registers and stack registers matching the number of memory spaces, wherein each client operating system is configured with one configuration register and two stack registers;
[0096] The client operating system switching module 802 is configured to determine the target memory space pointed to by the stack register when the virtual machine monitor performs a switching operation between client operating systems; determine the target register according to the bit identifier in the configuration register; and update the storage location of the target switching data corresponding to the target register based on the target memory space.
[0097] In some practical applications, the guest operating system switching module 802 includes a guest operating system swap-out module 8021 and a guest operating system swap-in module 8022, wherein:
[0098] The client operating system swap module 8021 is configured as follows: first, obtain the current stack pointer of the current client operating system from the current stack register, copy the key data of the current client operating system to the specified position of the current memory space pointed to by the current stack pointer, and update the position of the current stack pointer; then, according to the current configuration register content, copy the register content corresponding to each bit to the specified position of the current memory space pointed to by the current stack pointer, and update the position of the current stack pointer.
[0099] The client operating system swap module 8022 is configured as follows: first, obtain the current stack pointer of the current client operating system from the current stack register; find the register corresponding to each bit of the current configuration register, copy the content pointed to by the current stack pointer to the register corresponding to each bit, and update the position of the current stack pointer; then, copy the key data of the current client operating system pointed to by the current stack pointer to the specified location of the current memory space, and update the current stack pointer until it is equal to the current stack bottom pointer, and the switch is completed.
[0100] Combination Fig. 9 As shown, the embodiment of the present disclosure provides a switching device (e.g., computer, controller, etc.) 900 for a client operating system, including a processor 90 and a memory 91, and may also include a communication interface 92 and a bus 93. The processor 90, the communication interface 92, and the memory 91 may communicate with each other through the bus 93. The communication interface 92 may be used for information transmission. The processor 90 may call the logic instructions in the memory 91 to execute the switching method for the client operating system of the above embodiment.
[0101] In addition, the logic instructions in the above-mentioned memory 91 can be implemented in the form of software functional units and can be stored in a computer-readable storage medium when sold or used as an independent product.
[0102] The memory 91 is a computer-readable storage medium that can be used to store software programs and computer executable programs, such as program instructions / modules corresponding to the method in the embodiment of the present disclosure. The processor 90 executes the functional application and data processing by running the program instructions / modules stored in the memory 91, that is, the switching method for the client operating system in the above method embodiment is implemented.
[0103] The memory 91 may include a program storage area and a data storage area, wherein the program storage area may store an operating system and an application required for at least one function; the data storage area may store data created according to the use of the terminal device, etc. In addition, the memory 91 may include a high-speed random access memory and may also include a non-volatile memory.
[0104] Using the switching device for client operating systems provided by the embodiment of the present disclosure, the memory of the chip is set to multiple memory spaces corresponding to the number of client operating systems, the chip is set to configure registers and stack registers that match the number of memory spaces, and each client operating system is configured with one configuration register and two stack registers. When the virtual machine monitor performs a switching operation between client operating systems, the target memory space pointed to by the stack register is determined, and then the target register is determined based on the bit identifier in the configuration register, and then the storage location of the target switching data corresponding to the target register is updated based on the target memory space to complete the switching process. By dividing a separate memory space for each Guest OS, adding stack registers and configuration registers, most of the switching process is automatically completed by digital logic, and because each Guest OS has its own independent memory space, and only the values of a few key registers need to be updated during switching, the time for context saving and recovery can be significantly reduced, thereby reducing the switching time.
[0105] An embodiment of the present disclosure provides a computer-readable storage medium storing computer-executable instructions, wherein the computer-executable instructions are configured to execute the above-mentioned switching method for a client operating system.
[0106] An embodiment of the present disclosure provides a computer program product, which includes a computer program stored on a computer-readable storage medium, and the computer program includes program instructions. When the program instructions are executed by a computer, the computer executes the above-mentioned switching method for a client operating system.
[0107] The computer-readable storage medium mentioned above may be a transient computer-readable storage medium or a non-transitory computer-readable storage medium.
[0108] The technical solution of the embodiment of the present disclosure can be embodied in the form of a software product, which is stored in a storage medium and includes one or more instructions for enabling a computer device (which may be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in the embodiment of the present disclosure. The aforementioned storage medium may be a non-transient storage medium, including: a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and other media that can store program codes, or a transient storage medium.
[0109] The above description and the accompanying drawings fully illustrate the embodiments of the present disclosure so that those skilled in the art can practice them. Other embodiments may include structural, logical, electrical, process and other changes. The embodiments represent only possible changes. Unless explicitly required, individual components and functions are optional, and the order of operation may vary. The parts and features of some embodiments may be included in or replace the parts and features of other embodiments. The scope of the embodiments of the present disclosure includes the entire scope of the claims, and all available equivalents of the claims. When used in this application, although the terms "first", "second", etc. may be used in this application to describe each element, these elements should not be limited by these terms. These terms are only used to distinguish one element from another element. For example, without changing the meaning of the description, the first element can be called the second element, and similarly, the second element can be called the first element, as long as all occurrences of the "first element" are renamed consistently and all occurrences of the "second element" are renamed consistently. The first element and the second element are both elements, but may not be the same element. Moreover, the words used in this application are only used to describe the embodiments and are not used to limit the claims. As used in the description of the embodiments and claims, unless the context clearly indicates, the singular forms "a", "an" and "the" are intended to include the plural forms as well. Similarly, the term "and / or" as used in this application refers to any and all possible combinations of one or more associated listings. In addition, when used in this application, the term "comprise" and its variants "comprises" and / or comprising refer to the presence of stated features, wholes, steps, operations, elements, and / or components, but do not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or groups of these. In the absence of further restrictions, the elements defined by the sentence "including one..." do not exclude the presence of other identical elements in the process, method or device including the elements. In this article, each embodiment may focus on the differences from other embodiments, and the same and similar parts between the embodiments may refer to each other. For the methods, products, etc. disclosed in the embodiments, if they correspond to the method part disclosed in the embodiments, then the relevant parts can refer to the description of the method part.
[0110] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software may depend on the specific application and design constraints of the technical solution. The technicians may use different methods for each specific application to implement the described functions, but such implementations should not be considered to exceed the scope of the embodiments of the present disclosure. The technicians may clearly understand that, for the convenience and simplicity of description, the specific working processes of the systems, devices and units described above may refer to the corresponding processes in the aforementioned method embodiments, and will not be repeated here.
[0111] In the embodiments disclosed herein, the disclosed methods and products (including but not limited to devices, equipment, etc.) can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units can be only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between each other shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms. The units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the units may be selected according to actual needs to implement this embodiment. In addition, each functional unit in the embodiment of the present disclosure may be integrated in a processing unit, or each unit may exist physically alone, or two or more units may be integrated in one unit.
[0112] The flowchart and block diagram in the accompanying drawings show the possible architecture, function and operation of the system, method and computer program product according to the embodiment of the present disclosure. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of the code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. In some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, which can depend on the functions involved. In the description corresponding to the flowchart and the block diagram in the accompanying drawings, the operations or steps corresponding to different boxes can also occur in a different order from the order disclosed in the description, and sometimes there is no specific order between different operations or steps. For example, two consecutive operations or steps can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, which can depend on the functions involved. Each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, may be implemented by a dedicated hardware-based system that performs the specified functions or actions, or may be implemented by a combination of dedicated hardware and computer instructions.
Claims
1. A method for switching a client operating system, characterized in that: The memory of the chip is configured with a plurality of memory spaces corresponding to the number of client operating systems, the chip is configured with configuration registers and stack registers matching the number of memory spaces, and each client operating system is configured with one configuration register and two stack registers; the switching method includes: In the case where the virtual machine monitor performs a switching operation between guest operating systems, determining a target memory space pointed to by a stack register; Determine the target register according to the bit identifier in the configuration register; Based on the target memory space, the storage location of the target switching data corresponding to the target register is updated.
2. The switching method according to claim 1, characterized in that: The two stack registers store the current stack pointer and the stack bottom pointer corresponding to the client operating system respectively. The current stack pointer points to the target memory space. The initial current stack pointer and the stack bottom pointer are both set to the starting address of the memory space.
3. The switching method according to claim 1, characterized in that: Each bit identifier in the configuration register corresponds to a register, and the target register is determined according to the bit identifier.
4. The switching method according to claim 1, characterized in that: Determine the target register based on the bit identifier in the configuration register, including: In the case where the switching operation is a swap-out, determining whether the saved data of the register is saved to the target memory space during the switching operation according to the bit flag; The register that needs to be saved to the target memory space during the switch operation is used as the target register.
5. The switching method according to claim 4, characterized in that: According to the bit flag, determine whether the saved data of the register is saved to the target memory space during the switching operation, including: Determine that the saved data of the register corresponding to the bit mark with a value of 1 is saved to the target memory space during the switching operation; It is determined that the saved data of the register corresponding to the bit mark with a value of 0 is not saved to the target memory space during the switching operation.
6. The switching method according to any one of claims 1 to 5, characterized in that: Based on the target memory space, the storage location of the target switching data corresponding to the target register is updated, including: When the switching operation is swapping out, the target switching data corresponding to the target register is copied to the target memory space pointed to by the current stack pointer, and the position of the current stack pointer is updated; or, When the switching operation is swapping out, the key data of the current client operating system is copied to the target memory space pointed to by the current stack pointer, and the position of the current stack pointer is updated; After the current stack pointer position is updated, the target switching data corresponding to the target register is copied to the target memory space pointed to by the current stack pointer, and the current stack pointer position is updated.
7. The switching method according to any one of claims 1 to 5, characterized in that: Based on the target memory space, the storage location of the target switching data corresponding to the target register is updated, including: When the switch operation is a swap-in, the target switch data in the target memory space pointed to by the current stack pointer is copied to the target register, and the position of the current stack pointer is updated; or, When the switch operation is a swap-in, the target switch data in the target memory space pointed to by the current stack pointer is copied to the target register, and the position of the current stack pointer is updated; After the position of the current stack pointer is updated, the key data of the current client operating system pointed to by the current stack pointer is copied to the specified position of the current memory space, and the current stack pointer is updated until the current stack pointer and the stack bottom pointer are equal, completing the switching.
8. A switching device for a client operating system, comprising: A system configuration module is configured to set a plurality of memory spaces corresponding to the number of client operating systems, and to set configuration registers and stack registers matching the number of memory spaces, wherein each client operating system is configured with one configuration register and two stack registers; a guest operating system switching module configured to determine a target memory space pointed to by a stack register when the virtual machine monitor performs a switching operation between guest operating systems; Determine the target register according to the bit identifier in the configuration register; Based on the target memory space, the storage location of the target switching data corresponding to the target register is updated.
9. A switching device for a client operating system, comprising a processor and a memory storing program instructions, characterized in that: The processor is configured to execute the switching method for a guest operating system according to any one of claims 1 to 7 when executing the program instructions.
10. A switching system for a client operating system, characterized in that: include: Multiple guest operating systems; Memory space, the amount corresponds to the number of client operating systems; Configuration registers, the number is consistent with the number of memory spaces; Stack registers, the number of which is twice the number of memory spaces; A switching device for a client operating system as claimed in claim 8 or 9.