Virtual machine monitor, serial port sharing method and device of virtual machine and storage medium

By building a serial port sharing mechanism between the virtual machine monitor and the virtual machine, the problem of limited serial port resources in the embedded virtualization system is solved, and the tuning of the virtual machine monitor and the virtual machine on the same physical serial port is realized, which improves the Convenience and efficiency of adjustment.

CN119105842APending Publication Date: 2024-12-10CHINA AUTOMOTIVE INNOVATION CORP
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411250575.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-06
Publication Date
2024-12-10

AI Technical Summary

Technical Problem

In embedded virtualization systems, hypervisor and multiple virtual machines require serial port resources, resulting in limited debugging resources and difficult to use effectively.

Method used

By creating a preset serial port structure when the virtual machine monitor is started, and creating owner objects for the virtual machine monitor and virtual machine respectively, building an owner linked list to realize serial port sharing between the virtual machine monitor and virtual machine, allowing virtual machines to The machine monitor and the virtual machine use the same serial port for debugging.

Benefits of technology

It saves debugging resources, improves the convenience of debugging, enables the virtual machine monitor and virtual machine to perform debugging on the same physical serial port, and improves the efficiency and convenience of debugging.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119105842A_ABST
    Figure CN119105842A_ABST
Patent Text Reader

Abstract

The invention discloses a virtual machine monitor, a serial port sharing method and device of a virtual machine and a storage medium, the method is applied to the virtual machine monitor, and the method comprises the steps that when the virtual machine monitor is started, a preset serial port structure is created, and a first owner object corresponding to the virtual machine monitor is created; constructing an initial owner linked list according to the first owner object, storing the initial owner linked list into a preset serial port structure, and setting a current owner object of the preset serial port structure as the first owner object; creating second owner objects corresponding to the plurality of virtual machines based on the object creation request; storing the plurality of second owner objects in the initial owner linked list to obtain a target owner linked list; and switching the current owner object of the preset serial port structure to the second target owner object according to the target owner linked list. According to the invention, the virtual machine monitor and the virtual machine can use the same serial port for debugging and testing, and debugging and testing resources are saved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a method, device and storage medium for serial port sharing between a virtual machine monitor and a virtual machine. Background Art

[0002] Embedded virtualization technology can run a virtual machine monitor (hypervisor) on a single SOC. Multiple virtual machines can be virtualized on the hypervisor. The resources and time and space isolation between the virtual machines are achieved, and each virtual machine can run an operating system independently.

[0003] In embedded systems, serial port resources are limited, and debugging usually only allocates one serial port. However, in embedded virtualization systems, both the hypervisor and each virtual machine require a serial port, which brings inconvenience to debugging. Summary of the invention

[0004] The present application provides a method, device and storage medium for sharing serial ports of a virtual machine monitor and a virtual machine, which can enable the virtual machine monitor and the virtual machine to use the same serial port for debugging, save debugging resources and improve the convenience of debugging.

[0005] In one aspect, the present application provides a method for serial port sharing between a virtual machine monitor and a virtual machine, the method being applied to the virtual machine monitor, the method comprising:

[0006] When the virtual machine monitor is started, a preset serial port structure is created, and a first owner object corresponding to the virtual machine monitor is created;

[0007] Constructing an initial owner linked list according to the first owner object, storing the initial owner linked list in the preset serial port structure, and setting the current owner object of the preset serial port structure to the first owner object;

[0008] Based on an object creation request, creating a second owner object corresponding to each of the plurality of virtual machines; the object creation request is sent by the plurality of virtual machines to the virtual machine monitor when the plurality of virtual machines are started; the object creation request carries identification information of each of the virtual machines;

[0009] storing a plurality of the second owner objects into the initial owner linked list, obtaining a target owner linked list, and storing the target owner linked list in the preset serial port structure; each of the virtual machines corresponds to one second owner object;

[0010] When an owner object switching instruction is received, the current owner object of the preset serial port structure is switched to a second target owner object according to the target owner linked list.

[0011] In an exemplary embodiment, the method further comprises:

[0012] Constructing an operation strategy for the virtual machine monitor to operate the preset serial port structure and an operation strategy for each of the virtual machines to operate the preset serial port structure;

[0013] storing the identification information of the virtual machine monitor and the operation policy of the virtual machine monitor operating the preset serial port structure in the first owner object;

[0014] The identification information of each of the virtual machines and the operation strategy of each of the virtual machines for operating the preset serial port structure are stored in the second owner object.

[0015] In an exemplary embodiment, switching the current owner object of the preset serial port structure to the second target owner object according to the target owner linked list includes:

[0016] When receiving the owner object switching instruction, searching the target owner linked list to obtain the second target owner object;

[0017] determining a target operation policy corresponding to the second target owner object;

[0018] The current owner object of the preset serial port structure is switched to the second target owner object, so that the second target owner object operates the preset serial port structure according to the target operation policy corresponding to the second target owner object.

[0019] In an exemplary embodiment, the owner object switching instruction includes a switching string, and searching the target owner linked list to obtain the second target owner object includes:

[0020] When receiving the owner object switching instruction, obtaining the registration information of the switching string;

[0021] When the registration information indicates that the switching string is a registered switching string, the target owner linked list is searched, and any owner object in the target owner linked list is used as the second target owner object.

[0022] In an exemplary embodiment, the method further comprises:

[0023] When receiving the owner object secondary switching instruction, searching the target owner linked list, and taking the owner objects in the target owner linked list except the second target owner object and the first owner object as the current owner object linked list;

[0024] Taking any owner object in the current owner object linked list as the target owner object;

[0025] Determining a target operation policy corresponding to the target owner object;

[0026] The current owner object of the preset serial port structure is switched to the target owner object, so that the target owner object operates the preset serial port structure according to the target operation policy corresponding to the target owner object.

[0027] In an exemplary embodiment, before creating the second owner objects corresponding to the plurality of virtual machines respectively based on the object creation request, the method includes:

[0028] receiving a device search request and searching for virtual devices corresponding to the plurality of virtual machines; the device search request is sent by the virtual machine to the virtual machine monitor when each of the virtual machines responds to a start instruction;

[0029] The virtual device is initialized and initialization status information of the virtual device is obtained, so that when the initialization status information indicates that the virtual machine is performing a virtual serial port initialization operation, the virtual machine sends the object creation request to the virtual machine monitor.

[0030] In an exemplary embodiment, after the current owner object of the preset serial port structure is switched to the second target owner object according to the target owner linked list, the method includes:

[0031] Receiving prompt information sent by the virtual machine, the prompt information including an updated available descriptor table; the updated available descriptor table is generated by the virtual machine according to the debugging instruction when the debugging instruction is received; the virtual machine stores the debugging information in a virtualization queue, obtains an updated descriptor, and updates the available descriptor table according to the updated descriptor;

[0032] Based on the updated available descriptor table, the debugging information is obtained from the virtualization queue.

[0033] On the other hand, a serial port sharing device for a virtual machine monitor and a virtual machine is provided, which is applied to the virtual machine monitor, and the device includes:

[0034] A first owner object creation module, used to create a preset serial port structure and a first owner object corresponding to the virtual machine monitor when the virtual machine monitor is started;

[0035] A first owner object setting module, used for constructing an initial owner linked list according to the first owner object, storing the initial owner linked list in the preset serial port structure, and setting the current owner object of the preset serial port structure to the first owner object;

[0036] A second owner object creation module is used to create second owner objects corresponding to each of the multiple virtual machines based on an object creation request; the object creation request is sent by the multiple virtual machines to the virtual machine monitor when the multiple virtual machines are started; the object creation request carries identification information of each virtual machine;

[0037] a target owner linked list acquisition module, used to store a plurality of the second owner objects into the initial owner linked list, obtain a target owner linked list, and store the target owner linked list in the preset serial port structure; each of the virtual machines corresponds to one second owner object;

[0038] The current owner object switching module is used to switch the current owner object of the preset serial port structure to a second target owner object according to the target owner linked list when receiving an owner object switching instruction.

[0039] On the other hand, an electronic device is provided, comprising a processor and a memory, wherein the processor is used to store the memory for storing instructions executable by the processor; wherein the processor is configured to execute the instructions to implement the serial port sharing method of the virtual machine monitor and the virtual machine as described above.

[0040] On the other hand, a computer-readable storage medium is provided, characterized in that the computer-readable storage medium contains at least one instruction or at least one program, and the at least one instruction or at least one program is loaded and executed by a processor to implement the serial port sharing method of a virtual machine monitor and a virtual machine as described above.

[0041] On the other hand, a computer program product or a computer program is provided, the computer program product or the computer program includes computer instructions, the computer instructions are stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes to implement the serial port sharing method of a virtual machine monitor and a virtual machine as described above.

[0042] The serial port sharing method, device and storage medium of the virtual machine monitor and virtual machine provided in the present application have the following technical effects:

[0043] When the virtual machine monitor is started, the present application creates a preset serial port structure and creates a first owner object corresponding to the virtual machine monitor; constructs an initial owner linked list based on the first owner object, stores the initial owner linked list in the preset serial port structure, and sets the current owner object of the preset serial port structure to the first owner object; creates second owner objects corresponding to multiple virtual machines based on an object creation request; the object creation request is sent by multiple virtual machines to the virtual machine monitor when multiple virtual machines are started; the object creation request carries the identification information of each virtual machine; stores multiple second owner objects in the initial owner linked list, obtains the target owner linked list, and stores the target owner linked list in the preset serial port structure; each virtual machine corresponds to a second owner object; when an owner object switching instruction is received, the current owner object of the preset serial port structure is switched to the second target owner object according to the target owner linked list. The present application enables the virtual machine monitor and multiple virtual machines to use the same serial port for debugging, saving debugging resources and improving the convenience of debugging. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0045] Figure 1 It is a flowchart of a method for sharing serial ports between a virtual machine monitor and a virtual machine provided in an embodiment of this specification;

[0046] Figure 2 It is a schematic diagram of a serial port sharing method of a virtual machine monitor and a virtual machine provided in an embodiment of this specification;

[0047] Figure 3 It is a flowchart before creating a second owner object corresponding to each of the plurality of virtual machines provided in an embodiment of this specification;

[0048] Figure 4 It is a flowchart of a preset serial port structure storing each owner object provided by an embodiment of this specification;

[0049] Figure 5 It is a flowchart of switching the current owner object of a preset serial port structure to a second target owner object provided by an embodiment of this specification;

[0050] Figure 6 This is a schematic diagram of a flow chart of determining registration information of a switching string provided by an embodiment of this specification;

[0051] Figure 7 It is a flowchart of switching the current owner object of a preset serial port structure to a target owner object provided by an embodiment of this specification;

[0052] Figure 8 It is a schematic diagram of a virtualized queue transmitting data provided by an embodiment of this specification;

[0053] Fig. 9 It is a structural diagram of a server provided in an embodiment of this specification. DETAILED DESCRIPTION

[0054] The following will be combined with the drawings in the embodiments of this specification to clearly and completely describe the technical solutions in the embodiments of this specification. Obviously, the described embodiments are only part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0055] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application 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 data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or server that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0056] The following describes a method for sharing serial ports between a virtual machine monitor and a virtual machine of the present application. Figure 1 is a flow chart of a method for sharing serial ports between a virtual machine monitor and a virtual machine provided in an embodiment of the present application, Figure 2 It is a schematic diagram of a serial port sharing method for a virtual machine monitor and a virtual machine provided in an embodiment of the present application. This specification provides method operation steps as described in the embodiment or flowchart, but may include more or fewer operation steps based on conventional or non-creative labor. The order of steps listed in the embodiment is only one way of executing the steps among many orders, and does not represent the only order of execution. When the actual system or the fourth server product is executed, it can be executed in sequence or in parallel according to the method shown in the embodiment or the accompanying drawings (for example, in a parallel processor or multi-threaded processing environment). Specifically, Figure 1As shown, the method is applied to the virtual machine monitor, and the method may include:

[0057] S1: When the virtual machine monitor is started, a preset serial port structure is created, and a first owner object corresponding to the virtual machine monitor is created.

[0058] In an embodiment of the present application, a virtual machine monitor (hypervisor) manages all hardware resources. When the virtual machine monitor is started, a shell thread is created, and then a global HV-UART structure corresponding to the debugging serial port hardware device is created, that is, the above-mentioned preset serial port structure. A linked list of owners is stored in this structure. In addition, an owner object corresponding to the virtual machine monitor is created, that is, the above-mentioned first owner object.

[0059] S2: constructing an initial owner linked list according to the first owner object, storing the initial owner linked list in the preset serial port structure, and setting the current owner object of the preset serial port structure to the first owner object.

[0060] In the embodiment of the present application, the first owner object corresponding to the created virtual machine monitor is attached to the owner list in HV-UART, and the current owner object of the preset serial port structure is set to the virtual machine monitor. In addition, the switching string needs to be registered, and the specific switching string can be set according to actual needs.

[0061] S3: Based on an object creation request, create a second owner object corresponding to each of the multiple virtual machines; the object creation request is sent by the multiple virtual machines to the virtual machine monitor when the multiple virtual machines are started; the object creation request carries identification information of each virtual machine.

[0062] In an exemplary embodiment, if Figure 3 As shown, before creating the second owner objects corresponding to the plurality of virtual machines respectively based on the object creation request, the method includes:

[0063] S301: receiving a device search request, and searching for virtual devices corresponding to the plurality of virtual machines; the device search request is sent by the virtual machine to the virtual machine monitor when each of the virtual machines responds to a start instruction;

[0064] S302: Initialize the virtual device and obtain initialization status information of the virtual device; so that when the initialization status information indicates that the virtual machine is performing a virtual serial port initialization operation, the virtual machine sends the object creation request to the virtual machine monitor.

[0065] In an embodiment of the present application, when the virtual machine monitor starts each virtual machine, it will search for the virtual devices in each virtual machine and initialize the virtual device backend. When the virtual serial port is initialized, that is, the virtual serial port backend is initialized, the virtual machine monitor creates an owner object corresponding to the virtual machine, that is, the above-mentioned second owner object, wherein each virtual machine corresponds to a second owner object.

[0066] In the embodiment of the present application, when the virtual machine monitor initializes the virtual serial port backend of the virtual machine, an owner object corresponding to the virtual machine is created, thereby constructing a target owner linked list in the preset serial port structure to achieve switching of the target owner object of the preset serial port structure.

[0067] In an exemplary embodiment, if Figure 4 As shown, the method may also include:

[0068] S311: constructing an operation strategy for the virtual machine monitor to operate the preset serial port structure and an operation strategy for each of the virtual machines to operate the preset serial port structure;

[0069] S312: storing the identification information of the virtual machine monitor and the operation policy of the virtual machine monitor operating the preset serial port structure in the first owner object;

[0070] S313: Store the identification information of each of the virtual machines and the operation strategy of each of the virtual machines for operating the preset serial port structure in the second owner object.

[0071] In an embodiment of the present application, an operation strategy for the virtual machine monitor to operate the preset serial port structure and an operation strategy for each of the virtual machines to operate the preset serial port structure are constructed, and an operation method and structure for the virtual machine monitor to operate the preset serial port structure are stored in a first owner object, and an operation method and structure for each virtual machine to operate the preset serial port structure are stored in a second owner object, wherein the structure in the operation method and structure refers to a description of each relevant data.

[0072] In the embodiment of the present application, the operation strategy of the virtual machine monitor operating the preset serial port structure and the operation strategy of each virtual machine operating the preset serial port structure are respectively stored in the first owner object and the second owner object, thereby constructing a target owner linked list, so that the virtual machine monitor and each virtual machine can use the same physical serial port, and can perform a series of operations on the serial port according to their corresponding operation strategies to achieve the purpose of debugging.

[0073] S4: storing a plurality of the second owner objects into the initial owner linked list to obtain a target owner linked list, and storing the target owner linked list in the preset serial port structure; each of the virtual machines corresponds to one second owner object.

[0074] In an embodiment of the present application, the second owner object is also attached to the owner list in HV-UART to obtain the final target owner list, so that the target owner list stores the operation strategy of the virtual machine monitor and each virtual machine operation preset serial port structure.

[0075] In the embodiment of the present application, by storing multiple second owner objects corresponding to each virtual machine in the owner linked list in HV-UART, the final target owner linked list can be obtained, and the first owner object and each second owner object are respectively stored in the target owner linked list, so that when a switching instruction is received, the first owner object and each second owner object can be switched according to the target owner linked list, thereby realizing a series of debugging of the virtual machine monitor and each virtual machine on the same physical serial port.

[0076] S5: When an owner object switching instruction is received, the current owner object of the preset serial port structure is switched to a second target owner object according to the target owner linked list.

[0077] In an exemplary embodiment, if Figure 5 As shown, switching the current owner object of the preset serial port structure to the second target owner object according to the target owner linked list includes:

[0078] S51: when receiving an owner object switching instruction, searching the target owner linked list to obtain a second target owner object;

[0079] S52: Determine a target operation policy corresponding to the second target owner object;

[0080] S53: Switch the current owner object of the preset serial port structure to the second target owner object, so that the second target owner object operates the preset serial port structure according to the target operation policy corresponding to the second target owner object.

[0081] In an embodiment of the present application, when an owner object switching instruction is received in the shell thread, the target owner linked list in the HV-UART is searched, and one of the second owner objects in the target owner linked list can be used as the second target owner object, and the operation strategy for operating the preset serial port structure corresponding to the second target owner object is determined, and the current owner object of the preset serial port structure is switched to the second target owner object. After the switching, the second target owner object can debug the preset serial port structure or perform other related operations according to the target operation strategy corresponding to the second target owner object.

[0082] When receiving an owner object switching instruction, the embodiment of the present application can effectively switch the current owner object of the preset serial port structure from the virtual machine monitor to a certain virtual machine by searching each second owner object in the target owner linked list to determine the second target owner object and its corresponding target operation policy, thereby improving the efficiency of searching and switching, allowing the virtual machine monitor and each virtual machine to use the same physical serial port, and effectively saving device resources.

[0083] In an exemplary embodiment, if Figure 6 As shown, the owner object switching instruction includes a switching string, and searching the target owner linked list to obtain a second target owner object includes:

[0084] S501: when receiving the owner object switching instruction, obtaining the registration information of the switching string;

[0085] S502: When the registration information indicates that the switching string is a registered switching string, searching the target owner linked list, and taking any owner object in the target owner linked list as a second target owner object.

[0086] In an embodiment of the present application, when the owner object switching instruction is received, the registration status of the switching string needs to be checked. Only when the switching string is a previously registered switching string, the target owner linked list will be searched to determine the target owner object and perform subsequent switching.

[0087] The embodiment of the present application can effectively improve the switching efficiency of the owner object by using a simple switching string as a switching instruction. In addition, the switching operation is only for the registered switching string, which can avoid the intrusion of illegal information and ensure the security of the switching process.

[0088] In an exemplary embodiment, if Figure 7 As shown, the method also includes:

[0089] S531: when receiving the owner object secondary switching instruction, searching the target owner linked list, taking the owner objects in the target owner linked list except the second target owner object and the first owner object as the current owner object linked list;

[0090] S532: taking any owner object in the current owner object linked list as the target owner object;

[0091] S533: Determine a target operation policy corresponding to the target owner object;

[0092] S534: Switch the current owner object of the preset serial port structure to the target owner object, so that the target owner object operates the preset serial port structure according to the target operation policy corresponding to the target owner object.

[0093] In an embodiment of the present application, when a switching instruction is received again, the previously selected second target owner object and the first owner object can be excluded, and one of the other owner objects is selected as the target owner object and the corresponding target operation strategy is determined, and then the current owner object of the preset serial port structure is switched, thereby achieving the re-switching of the current owner object of the preset serial port structure.

[0094] In an embodiment of the present application, for the switching of owner objects, it is possible to switch from a virtual machine monitor to a virtual machine, from a virtual machine to a virtual machine, or from a virtual machine to a virtual machine monitor. Each time a registered switching string is received in the shell thread, a search is performed on the target owner list, and a switch is performed on the current owner object of the preset serial port structure. The switched owner object takes over the input and output of the serial port. After multiple switches, all owner objects in the target owner object can be traversed, and after traversing all owner objects, the original target owner list can continue to be searched, so that the same shell can be used to log in to all virtual machines and virtual monitor terminals, and the same physical serial port can be used to achieve the purpose of debugging.

[0095] The embodiment of the present application searches the target owner list through the owner object switching instruction, can quickly switch the owner object of the preset serial port structure, improve the switching efficiency of the owner object of the preset serial port structure, can effectively realize the sharing of the debugging serial port between the virtual machine monitor and each virtual machine, can adjust the debugging object in real time according to the debugging requirements, and effectively save the debugging resources.

[0096] In an exemplary embodiment, after switching the current owner object of the preset serial port structure to the second target owner object according to the target owner linked list, the method includes:

[0097] Receiving prompt information sent by the virtual machine, the prompt information including an updated available descriptor table; the updated available descriptor table is generated by the virtual machine according to the debugging instruction when the debugging instruction is received; the virtual machine stores the debugging information in a virtualization queue, obtains an updated descriptor, and updates the available descriptor table according to the updated descriptor;

[0098] Based on the updated available descriptor table, the debugging information is obtained from the virtualization queue.

[0099] In an exemplary embodiment, the method may further include:

[0100] The virtual machine obtains descriptor information of each of the plurality of memory areas; each of the memory areas corresponds to one descriptor;

[0101] The virtual machine constructs a descriptor table according to the multiple descriptors corresponding to the multiple memory areas;

[0102] The virtual machine obtains usage status information of each of the descriptors;

[0103] The virtual machine constructs an available descriptor table by taking the usage status information of each descriptor as the current available status of each descriptor;

[0104] The virtual machine constructs, according to the usage status information of each descriptor, each descriptor characterized by the usage status information as being in a used state into a used descriptor table;

[0105] The virtual machine constructs a virtualization queue according to the descriptor table, the available descriptor table and the used descriptor table.

[0106] In an exemplary embodiment, in a virtualization solution, a commonly used technology for device sharing is virtio (paravirtualization). Virtio is a widely used I / O (input / output) virtualization standard, and its design goal is to provide I / O functions and performance similar to physical devices in a virtualized environment, and avoid installing additional drivers in a virtual machine. The virtio framework mainly includes the following three parts: front-end driver, back-end device, and virtualization queue (Virtqueue). The data interaction between the front-end driver and the back-end device is implemented through Virtqueue. According to the virtio specification, a Virtqueue contains 3 parts: descriptor table, available ring table, and used ring table. Vring is the main data structure of virtqueue. This data structure mainly includes three parts. Descriptor array (desc), available ring, and used ring. desc is used to store some associated descriptors, each of which records a description of a buffer. Availablering is used by the guest (front-end component) to indicate which descriptors are currently available, while used ring indicates which descriptors have been used by the host (back-end component). Virtqueue is mainly used as follows: Figure 8 The two ring buffers shown are used to complete the forwarding of data flow.

[0107] In an embodiment of the present application, if the current owner object of the preset serial port structure is a virtual machine, the subsequent operation process is as follows: in the output direction: the front-end driver fills the output request into the virtualization queue (virtqueue), and then notifies the back-end. The back-end driver obtains the request from the virtqueue, first takes out the characters to be output, and then sends them to the output processing task of the back-end through the sending pipe. The back-end output processing task obtains the output characters from the pipe, and then calls the driver of the physical device to send the characters out; in the input direction: the characters input from the serial port terminal are recognized by the serial port physical driver and sent to the shell thread. The shell thread queries and sends the input characters to the receiving pipe. The back-end receiving processing task of the current owner obtains the input data from the pipe, and then obtains the buffer from the virtqueue and fills it, and then notifies the front end. The front end processes the buffer after receiving the notification.

[0108] In an embodiment of the present application, if the current owner object of the preset serial port structure is a virtual machine monitor, the subsequent operation process is as follows: in the output direction: the shell thread receives the characters to be sent and directly calls the physical device driver for output; in the input direction: the characters input from the serial port terminal are sent to the shell thread after being recognized by the physical device, and the shell thread echoes the input characters on the shell.

[0109] The embodiment of the present application realizes data transmission through a virtualization queue, so that the debugging information of the virtual machine is displayed on the shell thread, and the debugging of the virtual machine is realized, which makes it easy to find problems that occur during the debugging process according to relevant debugging information and ensure the stable operation of the virtual machine.

[0110] The embodiment of the present application switches the owner object of the preset serial port structure through a switching instruction, and can switch the current owner object of the preset serial port structure to a virtual machine monitor or any virtual machine that needs to be debugged, and then operate the serial port according to the corresponding operation method in the target owner linked list, thereby realizing the debugging of the virtual machine monitor or the virtual machine on the same physical serial port, effectively saving debugging resources and improving the convenience of debugging.

[0111] In the embodiment of the present application, when the virtual machine monitor is started, a shell thread is created, a global HV-UART structure corresponding to the debugging serial port hardware device is created, and an owner linked list is saved in the serial port structure, and owner objects corresponding to the virtual machine monitor and each virtual machine are created respectively. These owner objects each store a method for the virtual machine monitor and each virtual machine to operate the serial port. The owner objects corresponding to the virtual machine monitor and each virtual machine are stored in the owner linked list in the serial port structure to obtain the target owner linked list. When the shell thread receives a registered owner object switching instruction, the target owner linked list is searched and the target Any owner object in the target owner list is used as the target owner object, and the current owner object of the serial port is switched to the target owner object, so that the target owner object takes over the serial port, and operates the serial port according to the method of operating the serial port corresponding to the target owner object; each time an owner object switching instruction is received, the target owner list is searched once, and the current owner object of the serial port is switched once, so that each virtual machine and virtual machine monitor terminal can be logged in in the same shell, and each virtual machine and virtual machine monitor can be debugged through the same serial port, which effectively saves debugging resources and improves the convenience of debugging.

[0112] The embodiment of the present application further provides a serial port sharing device for a virtual machine monitor and a virtual machine, which is applied to the virtual machine monitor, and the device may include:

[0113] A first owner object creation module, used to create a preset serial port structure and a first owner object corresponding to the virtual machine monitor when the virtual machine monitor is started;

[0114] A first owner object setting module, used for constructing an initial owner linked list according to the first owner object, storing the initial owner linked list in the preset serial port structure, and setting the current owner object of the preset serial port structure to the first owner object;

[0115] A second owner object creation module is used to create second owner objects corresponding to each of the multiple virtual machines based on an object creation request; the object creation request is sent by the multiple virtual machines to the virtual machine monitor when the multiple virtual machines are started; the object creation request carries identification information of each virtual machine;

[0116] a target owner linked list acquisition module, used to store a plurality of the second owner objects into the initial owner linked list, obtain a target owner linked list, and store the target owner linked list in the preset serial port structure; each of the virtual machines corresponds to one second owner object;

[0117] The current owner object switching module is used to switch the current owner object of the preset serial port structure to a second target owner object according to the target owner linked list when receiving an owner object switching instruction.

[0118] In an exemplary embodiment, the apparatus may further include:

[0119] An operation strategy building module, used to build an operation strategy for the virtual machine monitor to operate the preset serial port structure and an operation strategy for each of the virtual machines to operate the preset serial port structure;

[0120] A first storage module, configured to store the identification information of the virtual machine monitor and the operation strategy of the virtual machine monitor operating the preset serial port structure in the first owner object;

[0121] The second storage module is used to store the identification information of each virtual machine and the operation strategy of each virtual machine operating the preset serial port structure in the second owner object.

[0122] In an exemplary embodiment, the current owner object switching module may include:

[0123] A second target owner object acquisition unit, configured to search the target owner linked list to obtain a second target owner object when receiving an owner object switching instruction;

[0124] an operation policy determining unit, configured to determine a target operation policy corresponding to the second target owner object;

[0125] The switching unit is used to switch the current owner object of the preset serial port structure to the second target owner object, so that the second target owner object operates the preset serial port structure according to the target operation policy corresponding to the second target owner object.

[0126] In an exemplary embodiment, the owner object switching instruction includes a switching string, and the second target owner object acquiring unit may include:

[0127] A registration information acquisition subunit, configured to acquire the registration information of the switching string when receiving the owner object switching instruction;

[0128] The second target owner object determining subunit is used to search the target owner linked list and use any owner object in the target owner linked list as the second target owner object when the registration information indicates that the switching string is a registered switching string.

[0129] In an exemplary embodiment, the current owner object switching module may further include:

[0130] a current owner object linked list determining unit, configured to search the target owner linked list when receiving the owner object secondary switching instruction, and use the owner objects in the target owner linked list except the second target owner object and the first owner object as the current owner object linked list;

[0131] a target owner object determining unit, configured to take any owner object in the current owner object linked list as a target owner object;

[0132] A target operation policy determining unit, configured to determine a target operation policy corresponding to the target owner object;

[0133] The current owner object switching unit is used to switch the current owner object of the preset serial port structure to the target owner object, so that the target owner object operates the preset serial port structure according to the target operation policy corresponding to the target owner object.

[0134] In an exemplary embodiment, the apparatus may further include:

[0135] A search request receiving module, used for receiving a device search request and searching for virtual devices corresponding to the plurality of virtual machines; the device search request is sent by the virtual machine to the virtual machine monitor when each of the virtual machines responds to a start instruction;

[0136] A startup module, used for starting the multiple virtual machines and searching for virtual devices corresponding to the multiple virtual machines;

[0137] The initialization module is used to initialize the virtual device and obtain the initialization status information of the virtual device; when the initialization status information indicates that the virtual machine is performing a virtual serial port initialization operation, the virtual machine sends the object creation request to the virtual machine monitor.

[0138] In an exemplary embodiment, the apparatus may further include:

[0139] A prompt information receiving module, used to receive prompt information sent by the virtual machine, the prompt information including an updated available descriptor table; the updated available descriptor table is generated by the virtual machine according to the debugging instruction when receiving the debugging instruction; the virtual machine stores the debugging information in the virtualization queue, obtains an updated descriptor, and updates the available descriptor table according to the updated descriptor;

[0140] The debugging information acquisition module is used to acquire the debugging information from the virtualization queue based on the updated available descriptor table.

[0141] The device and method embodiments in the device embodiments described in this specification are based on the same inventive concept.

[0142] An embodiment of the present application also provides an electronic device, which includes a processor and a memory, wherein the memory stores at least one instruction or at least one program, and the at least one instruction or at least one program is loaded and executed by the processor to implement the serial port sharing method of a virtual machine monitor and a virtual machine provided in the above method embodiment.

[0143] An embodiment of the present application also provides a computer-readable storage medium, which can be set in a terminal to store at least one instruction or at least one program related to the serial port sharing method between a virtual machine monitor and a virtual machine in an embodiment of the method. The at least one instruction or at least one program is loaded and executed by the processor to implement the serial port sharing method between a virtual machine monitor and a virtual machine provided in the above-mentioned embodiment of the method.

[0144] The embodiment of the present application also provides a computer program product or a computer program, which includes a computer instruction, and the computer instruction is stored in a computer-readable storage medium. The processor of the computer device reads the computer instruction from the computer-readable storage medium, and the processor executes the computer instruction, so that the computer device executes to implement the serial port sharing method of the virtual machine monitor and the virtual machine provided in the above method embodiment.

[0145] Optionally, in the embodiments of this specification, the storage medium may be located in at least one of the multiple network servers of the computer network. Optionally, in this embodiment, the storage medium may include, but is not limited to: a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, and other media that can store program codes.

[0146] The memory described in the embodiments of this specification can be used to store software programs and modules, and the processor executes various functional applications and data processing by running the software programs and modules stored in the memory. The memory may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, application programs required for functions, etc.; the data storage area may store data created according to the use of the device, etc. In addition, the memory may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage device. Accordingly, the memory may also include a memory controller to provide the processor with access to the memory.

[0147] The serial port sharing method embodiment of the virtual machine monitor and virtual machine provided in the embodiments of this specification can be executed in a mobile terminal, a computer terminal, a server or a similar computing device. Taking running on a server as an example, Fig. 9 1 is a hardware structure diagram of a method for sharing serial ports of a virtual machine monitor and a virtual machine provided in an embodiment of this specification. Fig. 9As shown, the server 900 may have relatively large differences due to different configurations or performances, and may include one or more central processing units (CPU) 910 (the central processing unit 910 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA), a memory 930 for storing data, and one or more storage media 920 (such as one or more mass storage devices) for storing application programs 923 or data 922. Among them, the memory 930 and the storage medium 920 can be short-term storage or permanent storage. The program stored in the storage medium 920 may include one or more modules, each of which may include a series of instruction operations on the server. Furthermore, the central processing unit 910 can be configured to communicate with the storage medium 920 and execute a series of instruction operations in the storage medium 920 on the server 900. The server 900 may also include one or more power supplies 960, one or more wired or wireless network interfaces 950, one or more input and output interfaces 940, and / or one or more operating systems 921, such as Windows ServerTM, Mac OS XTM, UnixTM, LinuxTM, FreeBSDTM, etc.

[0148] The input / output interface 940 may be used to receive or send data via a network. The specific example of the network may include a wireless network provided by a communication provider of the server 900. In one example, the input / output interface 940 includes a network adapter (Network Interface Controller, NIC), which may be connected to other network devices via a base station so as to communicate with the Internet. In one example, the input / output interface 940 may be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.

[0149] It can be understood by those skilled in the art that Fig. 9 The structure shown is only for illustration and does not limit the structure of the above electronic device. Fig. 9 More or fewer components as shown, or with Fig. 9 Different configurations shown.

[0150] It can be seen from the embodiments of the serial port sharing method, device and storage medium of the virtual machine monitor and virtual machine provided by the above-mentioned application that when the virtual machine monitor is started, the application creates a preset serial port structure and creates a first owner object corresponding to the virtual machine monitor; constructs an initial owner linked list according to the first owner object, stores the initial owner linked list in the preset serial port structure, and sets the current owner object of the preset serial port structure to the first owner object; creates second owner objects corresponding to multiple virtual machines based on an object creation request; the object creation request is sent by multiple virtual machines to the virtual machine monitor when multiple virtual machines are started; the object creation request carries the identification information of each virtual machine; stores multiple second owner objects in the initial owner linked list, obtains the target owner linked list, and stores the target owner linked list in the preset serial port structure; each virtual machine corresponds to a second owner object; when an owner object switching instruction is received, the current owner object of the preset serial port structure is switched to the second target owner object according to the target owner linked list. The application can realize the debugging of the virtual machine monitor and multiple virtual machines using the same physical serial port in the same shell interface, saving debugging resources and improving the convenience of debugging.

[0151] It should be noted that the above sequence of the embodiments of this specification is for description only and does not represent the advantages and disadvantages of the embodiments. The above describes specific embodiments of this specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0152] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device, equipment, and storage medium embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

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

[0154] The above description is only a preferred embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application should be included in the protection scope of the present application.

Claims

1. A method for sharing serial ports between a virtual machine monitor and a virtual machine, the method being applied to the virtual machine monitor, the method comprising: When the virtual machine monitor is started, a preset serial port structure is created, and a first owner object corresponding to the virtual machine monitor is created; Constructing an initial owner linked list according to the first owner object, storing the initial owner linked list in the preset serial port structure, and setting the current owner object of the preset serial port structure to the first owner object; Based on an object creation request, creating a second owner object corresponding to each of the plurality of virtual machines; the object creation request is sent by the plurality of virtual machines to the virtual machine monitor when the plurality of virtual machines are started; the object creation request carries identification information of each of the virtual machines; storing a plurality of the second owner objects into the initial owner linked list, obtaining a target owner linked list, and storing the target owner linked list in the preset serial port structure; each of the virtual machines corresponds to one second owner object; When an owner object switching instruction is received, the current owner object of the preset serial port structure is switched to a second target owner object according to the target owner linked list.

2. The method according to claim 1, characterized in that The method further comprises: Constructing an operation strategy for the virtual machine monitor to operate the preset serial port structure and an operation strategy for each of the virtual machines to operate the preset serial port structure; storing the identification information of the virtual machine monitor and the operation policy of the virtual machine monitor operating the preset serial port structure in the first owner object; The identification information of each of the virtual machines and the operation strategy of each of the virtual machines for operating the preset serial port structure are stored in the second owner object.

3. The method according to claim 2, characterized in that The step of switching the current owner object of the preset serial port structure to the second target owner object according to the target owner linked list includes: When receiving the owner object switching instruction, searching the target owner linked list to obtain the second target owner object; determining a target operation policy corresponding to the second target owner object; The current owner object of the preset serial port structure is switched to the second target owner object, so that the second target owner object operates the preset serial port structure according to the target operation policy corresponding to the second target owner object.

4. The method according to claim 3, characterized in that The owner object switching instruction includes a switching string, and searching the target owner linked list to obtain a second target owner object includes: When receiving the owner object switching instruction, obtaining the registration information of the switching string; When the registration information indicates that the switching string is a registered switching string, the target owner linked list is searched, and any owner object in the target owner linked list is used as the second target owner object.

5. The method according to claim 3, characterized in that: The method further comprises: When receiving the owner object secondary switching instruction, searching the target owner linked list, and taking the owner objects in the target owner linked list except the second target owner object and the first owner object as the current owner object linked list; Taking any owner object in the current owner object linked list as the target owner object; Determining a target operation policy corresponding to the target owner object; The current owner object of the preset serial port structure is switched to the target owner object, so that the target owner object operates the preset serial port structure according to the target operation policy corresponding to the target owner object.

6. The method according to claim 1, characterized in that Before creating the second owner objects corresponding to the plurality of virtual machines respectively based on the object creation request, the method includes: receiving a device search request and searching for virtual devices corresponding to the plurality of virtual machines; the device search request is sent by the virtual machine to the virtual machine monitor when each of the virtual machines responds to a start instruction; The virtual device is initialized and initialization status information of the virtual device is obtained, so that when the initialization status information indicates that the virtual machine is performing a virtual serial port initialization operation, the virtual machine sends the object creation request to the virtual machine monitor.

7. The method according to claim 1, characterized in that After the current owner object of the preset serial port structure is switched to the second target owner object according to the target owner linked list, the method includes: Receiving prompt information sent by the virtual machine, the prompt information including an updated available descriptor table; the updated available descriptor table is generated by the virtual machine according to the debugging instruction when the debugging instruction is received; the virtual machine stores the debugging information in a virtualization queue, obtains an updated descriptor, and updates the available descriptor table according to the updated descriptor; Based on the updated available descriptor table, the debugging information is obtained from the virtualization queue.

8. A serial port sharing device for a virtual machine monitor and a virtual machine, applied to the virtual machine monitor, the device comprising: A first owner object creation module, used to create a preset serial port structure and a first owner object corresponding to the virtual machine monitor when the virtual machine monitor is started; A first owner object setting module, used for constructing an initial owner linked list according to the first owner object, storing the initial owner linked list in the preset serial port structure, and setting the current owner object of the preset serial port structure to the first owner object; A second owner object creation module is used to create second owner objects corresponding to each of the multiple virtual machines based on an object creation request; the object creation request is sent by the multiple virtual machines to the virtual machine monitor when the multiple virtual machines are started; the object creation request carries identification information of each virtual machine; a target owner linked list acquisition module, used for storing a plurality of the second owner objects into the initial owner linked list, obtaining a target owner linked list, and storing the target owner linked list in the preset serial port structure; each of the virtual machines corresponds to one second owner object; The current owner object switching module is used to switch the current owner object of the preset serial port structure to a second target owner object according to the target owner linked list when receiving an owner object switching instruction.

9. An electronic device comprising a processor and a memory, wherein the processor is used to store the memory for storing instructions executable by the processor; wherein: The processor is configured to execute the instructions to implement the serial port sharing method of a virtual machine monitor and a virtual machine according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores at least one instruction or at least one program, and the at least one instruction or at least one program is loaded and executed by a processor to implement the serial port sharing method of a virtual machine monitor and a virtual machine as described in any one of claims 1-7.