CN109933435B - Control method and device and computer equipment - Google Patents

Control method and device and computer equipment Download PDF

Info

Publication number
CN109933435B
CN109933435B CN201910228643.4A CN201910228643A CN109933435B CN 109933435 B CN109933435 B CN 109933435B CN 201910228643 A CN201910228643 A CN 201910228643A CN 109933435 B CN109933435 B CN 109933435B
Authority
CN
China
Prior art keywords
external device
external
application
virtual
equipment
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201910228643.4A
Other languages
Chinese (zh)
Other versions
CN109933435A (en
Inventor
高云伟
杨立中
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Lenovo Beijing Ltd
Original Assignee
Lenovo Beijing Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Lenovo Beijing Ltd filed Critical Lenovo Beijing Ltd
Priority to CN201910228643.4A priority Critical patent/CN109933435B/en
Publication of CN109933435A publication Critical patent/CN109933435A/en
Application granted granted Critical
Publication of CN109933435B publication Critical patent/CN109933435B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Abstract

The application provides a control method, a control device and a computer device, wherein at least one container is deployed on an operating system of the computer device, under the condition that any application in the container is operated, if the application needs to use some external device currently, a device file of the corresponding virtual device is operated, during the period, a device driver can determine the external device mapped by the virtual device, and the device operation context of the external device is switched based on the state saving and restoring logic of the external device, so that the application can access the external device, the use requirement of the current application on the external device is met, and the use of other applications on the external device is not influenced, namely, the sharing of the external device or exclusive use of the external device is realized.

Description

Control method and device and computer equipment
Technical Field
The present application relates to the field of communications technologies, and in particular, to a control method, an apparatus, and a computer device.
Background
In recent years, container technology has become a widely recognized virtualization technology that can be used to implement server resource sharing. Compared with a virtual machine, the container is directly deployed on a host operating system, and when some application in the container runs, the application can share an external device connected with a host with applications in other containers, and can monopolize one or more external devices.
However, in practical applications, some external devices are not shared by applications in multiple containers; although some devices support device virtualization to realize sharing of multiple logical devices, some devices cannot be shared in a containerization scene, and even some devices can also be shared in the containerization scene, only part of device resources can be used, and the exclusive requirement of some applications on all device resources cannot be met. Therefore, how to make the devices efficiently share in the containerization scene becomes a problem which needs to be solved urgently.
Disclosure of Invention
In view of this, the present application provides a control method, an apparatus and a computer device, which implement efficient sharing of external devices in a containerization scenario.
In order to achieve the above object, the present application provides the following technical solutions:
the application provides a control method, which comprises the following steps:
during the running period of the application in the container, acquiring a device file of the virtual device used by the application, and determining the external device mapped by the virtual device;
and switching the device running context of the external device based on the state saving and restoring logic in the external device so that the application can access or release the external device.
Optionally, the implementing, based on the state saving and restoring logic in the external device, the switching of the device operating context of the external device includes:
under the condition that the application needs to use the external equipment, writing the equipment running context of the external equipment into the external equipment, and sending a state recovery command to the external equipment so that the external equipment responds to the equipment running context to realize data interaction with the application;
if the external equipment is not accessed by the application within a preset time period, sending a state saving command to the external equipment so that the external equipment saves the current equipment running context;
synchronizing the current device running context of the external device, releasing the mapping relation between the external device and the virtual device, and adjusting the current state of the external device to be an idle state.
Optionally, the determining the external device mapped by the virtual device includes:
inquiring whether the virtual equipment is mapped with external equipment;
if yes, executing the state saving and restoring logic based on the external equipment to realize the switching of the equipment running context of the external equipment;
if not, acquiring the external equipment in the idle state at present, and establishing a mapping relation between the virtual equipment and the external equipment in the idle state at present.
Optionally, in a case that the container engine creates the container, the method further includes:
configuring a virtual device identifier and creating a device running context for the container;
creating a virtual device corresponding to the virtual device identifier and the device operating context, and a device file of the virtual device;
acquiring attribute information of the equipment file, feeding the attribute information back to the container engine so that the application acquires the attribute information of the equipment file through the container engine, and acquiring the equipment file based on the attribute information of the equipment file;
wherein the attribute information of the device file includes a path and/or a file number of the device file.
Optionally, the method further includes:
receiving a container destruction command for the container sent by the container engine, the container destruction command being generated if each application in the container is cleared;
responding to the container destroying command, and releasing the virtual equipment identifier and the equipment operation context corresponding to the container;
clearing the virtual appliance created for the container.
Optionally, the external device includes: the device comprises an interface register used for receiving a state recovery command and a state saving command, and a device memory used for storing a device running context, wherein the device running context comprises configuration information and state information of the external device.
The present application also provides a control device, the device comprising:
the system comprises an acquisition module, a storage module and a display module, wherein the acquisition module is used for acquiring a device file of a virtual device used by an application during the running of the application in a container and determining an external device mapped by the virtual device;
and the control module is used for realizing switching of the device running context of the external device based on the state saving and restoring logic in the external device so as to enable the application to access or release the external device.
Optionally, the control module includes:
a writing unit, configured to write a device running context of the external device into the external device when the application needs to use the external device;
a state recovery command sending unit, configured to send a state recovery command to the external device, so that the external device responds to the device running context to implement data interaction with the application;
a state saving command sending unit, configured to send a state saving command to the external device when the external device is not accessed by the application within a preset time period, so that the external device saves a current device operating context;
a data synchronization unit for synchronizing a current device operating context of the external device;
and the device releasing unit is used for releasing the mapping relation between the external device and the virtual device and adjusting the current state of the external device to be an idle state.
Optionally, the obtaining module includes:
the query unit is used for querying whether the virtual device is mapped with an external device, and if the query result is yes, triggering the control module to execute the state saving and restoring logic based on the external device so as to realize the switching step of the device running context of the external device;
and the mapping relation establishing unit is used for acquiring the external equipment in the idle state currently and establishing the mapping relation between the virtual equipment and the external equipment in the idle state currently under the condition that the query result of the query unit is negative.
The present application further provides a computer device, comprising:
the communication interface is used for connecting external equipment, and the external equipment is provided with state saving and restoring logic;
a memory for storing a program for implementing the control method as described above;
a processor for loading and executing the memory-stored program, the program for:
during the running period of the application in the container, acquiring a device file of the virtual device used by the application, and determining the external device mapped by the virtual device;
and switching the device running context of the external device based on the state saving and restoring logic in the external device so that the application can access or release the external device.
Therefore, compared with the prior art, the application provides a control method, a control device and a computer device, where at least one container is deployed on an operating system of the computer device, and when any application in the container is run, if the application currently needs to use some external device, a device file corresponding to a virtual device will be operated, and during this period, a device driver may determine the external device mapped by the virtual device, and implement switching of a device running context of the external device based on a state saving and restoring logic of the external device, so that the application can access the external device, and meet a use requirement of the current application on the external device, and will not affect use of the external device by other applications, that is, sharing of the external device or exclusive use of the external device is implemented.
Drawings
In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings needed to be used in the description of the embodiments or the prior art will be briefly introduced below, it is obvious that the drawings in the following description are only embodiments of the present application, and for those skilled in the art, other drawings can be obtained according to the provided drawings without creative efforts.
Fig. 1 shows a schematic flow chart of an embodiment of the control method proposed by the present application;
fig. 2 shows a schematic flow chart of another embodiment of the control method proposed by the present application;
fig. 3 shows a schematic flow chart of a further embodiment of the control method proposed by the present application;
fig. 4 is a signaling flow diagram illustrating an embodiment of a control method proposed in the present application;
fig. 5 shows a signaling flow diagram of another embodiment of the control method proposed by the present application;
fig. 6 shows a schematic structural diagram of an embodiment of the control device proposed by the present application;
fig. 7 shows a schematic structural diagram of another embodiment of the control device proposed by the present application;
fig. 8 shows a schematic structural diagram of another embodiment of the control device proposed by the present application;
fig. 9 shows a schematic structural diagram of a further embodiment of the control device proposed by the present application;
fig. 10 shows a hardware structure diagram of an embodiment of the computer device proposed in the present application.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
At present, in order to realize the sharing of an external device connected to a computer device by multiple applications, a virtualization technology is generally adopted to create multiple virtual devices (i.e., logical devices) of the same external device for use by multiple applications. Specifically, a software virtualization method may be adopted, that is, a plurality of virtual devices of the external device may be constructed in a software model manner, but such virtualization method is high in overhead and strong in coupling with a hypervisor (virtual machine monitor), and cannot be used in a containerization scenario.
A hardware virtualization method is also provided in the prior art, that is, technologies such as SR-IOV are used, so that one external device presents multiple virtual devices to the outside, but such virtual devices can only use partial resources of the external device, such as a GPU (Graphics Processing Unit), which causes some applications that require exclusive use of resources of the external device to be unavailable, and the implementation is very complex, and many external devices are not applicable.
In addition, a hot plug method is also proposed, that is, a device is switched among a plurality of virtual machines in a time-division manner by simulating a device hot plug event, but in the implementation method, all containers in the computer device share one kernel, and the device hot plug cannot be performed on a certain container, so that the method is not applicable in a containerization scene. And the application can sense the joining and leaving of the external device, the application is opaque, and the related operation of ACPI (Advanced Configuration and Power Management Interface) is also involved, which causes large overhead and large delay.
In order to improve several existing technologies listed above, the present application provides a state saving and restoring logic added in an external device, so that a driver of a computer device can be responsible for switching device contexts based on the state saving and restoring logic, maintaining the external device and a virtual device, and dynamically updating a mapping relationship between the external device and the virtual device, so that the device driver can transparently provide services for containerized applications through the virtual device, and ensure that the external device can be efficiently shared by existing applications without changing the existing applications.
In order to make the aforementioned objects, features and advantages of the present application more comprehensible, the present application is described in further detail with reference to the accompanying drawings and the detailed description.
Referring to fig. 1, a flowchart of a control method provided in an embodiment of the present application is illustrated, where the method may be applied to a computer device, and the present application does not limit a product type of the computer device, and as shown in fig. 1, the method may include, but is not limited to, the following steps:
step S11, acquiring a device file of a virtual device used by the application during the running of the application in the container;
in the present application, the content of the device file of the virtual device is not limited, and in actual applications, the virtual device and the device file thereof are usually created during the creation of the corresponding container, and the specific process may refer to the description of the corresponding embodiment below.
In this embodiment, during the running of the application deployed in the container and requiring the use of the external device, the device file is usually operated, and the external device mapped to the external device is used through the virtual device, so that, for any application running process in any container in the computer device, the external device needs to be used, and the device file of the virtual device mapped to the container where the external device is located can be acquired, and a specific acquisition method is not limited.
Step S12, determining an external device to which the virtual device is mapped;
after each virtual device is created, a device file is usually created for the virtual device, and the device driver uses the virtual device through the device file, thereby using the external device mapped by the virtual device. Therefore, during the running of any application deployed in the container, the device driver may determine the device file to be operated by the application, i.e. determine the virtual device to which the device file belongs, and then determine the real external device mapped by the virtual device.
The mapping relationship between the virtual device and the external device may be dynamic, but is not fixed, and the dynamic mapping relationship between the virtual device and the external device may be dynamically adjusted according to an actual situation.
In the present application, the external device may refer to a hardware device other than a host computer, which plays a role in transmitting, transferring and storing data and information, is an important component in a computer system, and may be classified into input devices, display devices, printing devices, external storage devices, network devices, and the like, but is not limited thereto.
Step S13, based on the state saving and restoring logic in the external device, implement switching the device running context of the external device, so that the application can access or release the external device.
In this embodiment, the device running context may include configuration of a corresponding external device, some key state data, and the like, which may indicate a running condition of the external device, and in an actual application, the device context data of the external device is often opaque to the application, so that the application cannot directly implement switching control of the device running context, that is, cannot directly send a state save/restore command to the external device, and cannot implement flexible use of the external device, and flexible selection is to monopolize resources of the external device, or share resources of the external device with other applications, and further reduce the working performance of the computer device to a certain extent.
In order to improve the above problem, the present application proposes to add logic for saving and restoring the state of the external device, such as an interface register for configuring a state saving/restoring command and a device memory for storing device running context data, to the external device directly, so that the device driver can directly control the external device and realize interaction between the external device and the application.
Therefore, the device driver in the computer device can save the recovery logic based on the state of the external device, and implement switching of the device running context of the external device, so that the application can access the external device according to the usage requirement of the current running phase on the external device resource, such as exclusive use of the external device resource or sharing of the external device resource with other applications, or release the external device, so that other applications can exclusive use of the external device resource, that is, sharing of the same external device by multiple applications in a containerization scenario, or exclusive use of the external device by one application in a specific running phase is implemented
In conjunction with the above description of step S11, the following describes the creation of contents such as virtual devices and device operating contexts, which are generally implemented in the container creation phase in this application, and specifically, refer to a flow diagram of another control method shown in fig. 2, where the method mainly describes the creation process of contents such as virtual devices and device operating contexts in the container creation phase, and for the use of the method, refer to the description of the above embodiments, as shown in fig. 2, and the method may include, but is not limited to, the following steps:
step S21, in the case that the container engine creates a container, configuring a virtual device identifier for the container, and creating a device running context;
in practical applications, the container creation may be implemented by using a container engine docker or a container composer, so the container engine of step S21 may refer to the container engine docker or the container composer, and this embodiment does not describe the container creation process in detail.
In addition, in this embodiment, a group of containers may be referred to as a pod, and an operating system of the computer device in this embodiment often deploys a plurality of containers, so that the control method proposed in this embodiment is executed when a container is created by a container engine, or may be considered to be executed when a pod is created.
In this embodiment, when creating the container/pod, the container engine may notify the device driver to create the corresponding virtual device, specifically, the device driver may assign a globally unique virtual device identifier to the container, and may also create a device running context, and at this time, the created device running context may be used as device default data for an external device mapped by the virtual device.
Step S22, creating a virtual device corresponding to the virtual device identifier and the device operation context, and a device file of the virtual device;
wherein the created virtual device has a unique virtual device identifier for any container in the computer device to distinguish virtual devices created for other containers in the computer device. After the virtual device is created, a device file is created for the virtual device, so that the virtual device can be used by operating the device file.
Step S23, obtaining the attribute information of the device file, and feeding the attribute information back to the container engine, so that the application obtains the attribute information of the device file through the container engine, and obtains the device file based on the attribute information of the device file.
In this embodiment, the attribute information is mainly used to indicate how the application accurately acquires the required device file, that is, the attribute information may direct the application to accurately acquire the required device file from a plurality of device files created by the device driver.
In the practical application of this embodiment, after the device driver completes creation of the virtual device and the device file thereof for any container, the device file path and/or the file number may be fed back to each application in the container through the container engine, so that, when the application in the container needs to use the virtual device, that is, the device file of the virtual device needs to be operated, the device file may be read through the recorded attribute information such as the file path and/or the file number of the device file, and then the virtual device to which the device file belongs may be used by operating the device file.
Based on the above description of the core concept of the control method of the present application, in combination with the above description of the creation process of the virtual device and the device file thereof, the present application proposes a refinement of the control method, and with reference to a flow diagram of another control method shown in fig. 3, the method may include, but is not limited to, the following steps:
step S31, acquiring a device file of a virtual device used by the application during the running of the application in the container;
step S32, inquiring whether the virtual device is mapped with an external device, if not, entering step S33; if yes, go to step S35;
in this embodiment, an application running on a virtual device can access an external device mapped by the virtual device, and in an actual application, the virtual device is created for a certain container, but a plurality of containers can share the same external device, so the virtual device usually corresponds to a unique container, but can be mapped to a plurality of external devices, so that the application running on the virtual device can use the plurality of external devices.
In order to improve the reliability of the application using the external device, when the application deployed in a certain container needs to use the external device, for example, a device driver obtains a device access request of the application, it may first check whether a virtual device corresponding to the container is currently mapped with a real external device.
Step S33, acquiring the external equipment in idle state;
in the case that the virtual device in which the application runs is not currently mapped with an external device (i.e., an external device that the application needs to use), the state of each external device in the computer system may be detected, and the external device that is the same as the external device that the application needs to use and is currently in an idle state may be determined.
In this case, the external device in the idle state may not establish a mapping relationship with any virtual device, or even if there is a virtual device that establishes a mapping relationship with the external device, the application running in the virtual device does not currently use the resource of the external device.
Of course, the idle state of the external device may also mean that the external device is used by at least one application, but its resources still have margins, i.e. access requests of new applications may also be accepted. In this case, the external device is usually mapped with virtual devices, but the applications currently running in the mapped virtual devices do not occupy all resources of the external device, and the remaining resources can also support other applications to run.
Therefore, the present application can determine whether the external device is in the idle state by detecting the mapping relationship of the external device and/or the resource occupation condition of the external device, but is not limited to the detection method described in this embodiment.
Step S34, establishing the mapping relationship between the virtual device and the external device in idle state;
the method for constructing the mapping relationship between the virtual device and the external device is not limited in the present application, and in a general case, after the mapping relationship between the virtual device and the external device is determined, the mapping relationship may be stored in the corresponding virtual device and the external device, so that the application in the virtual device can perform data interaction with the external device, but the present application is not limited thereto.
Step S35, writing the device running context into the external device currently mapped by the virtual device;
in combination with the above description, the external device configures a device memory for storing a device running context, and when the external device is used for the first time, the device running context created by the device driver may be written into the device memory of the external device, so as to complete the initial configuration of the external device, and further enable the external device to operate normally.
Step S36, sending a state recovery command to the external device, so that the external device responds to the device running context to implement data interaction with the application.
In this embodiment, the external device configures the interface register for receiving the state restoring command and the state saving command, so that the state saving restoring command interface is transparent to the outside, and therefore, the device driver of the computer device may call the state saving restoring command interface to send the state restoring command to the interface register, so that the external device reads the device running context in the device memory, and responds to the device running context to complete the initial configuration, and further enable the application to normally operate the external device, thereby meeting the application requirements, for example, the external device may receive and respond to the operation instruction sent by the application, and feed back operation data to the application, that is, implementing data interaction between the external device and the application.
The data interaction process between the application and the external device is not described in detail in the present application, and may be specifically determined according to factors such as the type of the application and the requirements of the current operation stage of the application, so that for different types of applications, the data interaction process with the external device may be different in different operation stages, and the detailed description is not given in the present application.
Optionally, in an actual application, after data interaction between an application and some external device is implemented in the manner described in the above embodiment, the application may not need to use the external device for a while, so as to avoid waste of resources of the external device, the external device may be released, and thus other applications can use the external device. The specific release process may refer to a signaling flow chart of another embodiment of the control method shown in fig. 4, which mainly describes a control flow in a case where a certain external device is accessed by an application for a long time, as shown in fig. 4, the method may include, but is not limited to, the following steps:
step S41, the device driver determines that the external device is not accessed by the application within the preset time period, and sends a state saving command to the external device;
the preset time period may be a longer continuous time period, and the specific numerical value is not limited in the present application.
In practical applications, there are many situations where an external device is not used for a long time, for example, the external device is not mapped to any virtual device, and no application can use the external device; or, the external device is mapped with a virtual device, but an application running on the virtual device does not need to use the external device, and uses another external device mapped by the virtual device, so that the external device is not used for a long time.
In order to avoid waste of external device resources, in the case that a certain external device is determined to be unused for a long time, the external device may be released, and before that, the driving device needs to record the current device running context of the external device, so that when the external device is used next time, the external device can be controlled to be directly restored to the current state.
Based on this, the present embodiment may send the state saving command to the interface register of the external device by calling the state saving interface of the external device, but the sending method of the state saving command is not limited to this implementation.
Step S42, the external device responds to the state saving command and saves the current device running context;
step S43, the external device feeds back the state saving prompt information to the device driver;
after the external device receives a command of a device driver requesting to store the state, the configuration of the current device and some internal key state data, namely the current device operation context of the external device, can be synchronized to the device memory of the external device for storage.
In practical applications, after determining that the current device operating context is written in the device memory, the external device may notify the device driver, for example, the device driver is fed back with the state saving prompt information to notify the device driver that the external device has backed up and stored the current device operating context. The content of the state saving prompt information and the output form thereof are not limited in the present application.
Step S44, the device driver synchronously stores the current device running context saved by the external device;
after learning that the external device writes the current device operating context into the device memory, the device driver can directly read the current operating context of the device from the device memory and synchronize to the driver, so that when the device driver determines that the external device is used again, the current device operating context stored at this time can be written into the external device, and the external device can be directly restored to the state when the external device is used last time.
In step S45, the device driver releases the mapping relationship between the external device and the virtual device, and adjusts the current state of the external device to an idle state.
After the above analysis, the device driver determines that the external device is not used for a long time, and may consider that each application does not need to use the external device in the current stage, may directly release the mapping relationship between the external device and the virtual device, and adjust the current state of the external device to an idle state, that is, may mark the external device that is not used for a long time as an idle device.
In this way, during the running of the application in the future, the external device needs to be used, and the running virtual device does not map the external devices of the same type, according to the manner described in the above embodiment, the virtual device and the idle device can be directly mapped, and then the idle device can be used by using the application, and the specific operation process may refer to the description of the corresponding part in the above embodiment.
Optionally, in the case that it is determined that the external device is not used for a long time, the device driver may also directly adjust the current state of the external device to be the idle state without releasing the mapping relationship between the external device and the virtual device, so that the subsequent application can use the idle device, for example, monopolize the resource of the external device in the idle state, or share the resource of the external device in the idle state with other applications, and the like. The present application does not limit the release method of the external device that is not used for a long time.
In summary, the external device of the present application provides an externally transparent state saving and restoring command interface, so that the device driver can directly send a state saving command or a state restoring command to the external device according to the current requirement, and control the external device to save or restore the state, thereby avoiding waste caused by long-time occupation of external device resources, or meeting the data interaction requirement with the application.
And the external device also provides an external transparent device running context stored in the device memory, so that the device driver can directly perform read-write operation on the device running context according to the actual requirement of running application, namely the device driver can select the opportunity to cooperate with the hardware device to perform context switching, and the device running context during switching is stored.
The mapping relation between the virtual equipment and the external equipment is dynamic, the external equipment can be released in time when the external equipment is not needed, waste of external equipment resources is reduced, and the external equipment can be efficiently shared by a plurality of applications without changing the applications.
As another alternative embodiment of the present application, referring to fig. 5, a signaling flow diagram of another embodiment of the control method provided by the present application is shown, where the method may include, but is not limited to, the following steps:
step S51, the container engine determines that each application in the first container is cleared, and generates a container destruction command for the first container;
in practical applications of this embodiment, an operating system of a computer device may deploy at least one container, and each container may deploy at least one application. In this way, in the event that it is determined that all applications in any container are purged, in order to save space, it may be considered to destroy the container, so a container destruction command for the container may be generated at this time.
The first container in step S51 may be any container deployed in an operating system of the computer device, and the method for detecting whether each application in the first container is cleared is not limited in this application, for example, whether each application process is ended is detected.
Step S52, the container engine sends the container destroying command to the device driver;
step S53, the device driver responds to the container destroy command to release the virtual device identifier and the device operation context corresponding to the first container;
in step S54, the device driver clears the virtual device created for the first container.
In this embodiment, after determining that a certain container can be destroyed, the container engine may send a container destruction command for the container to the device driver, and the device driver responds to the container destruction command, specifically, before destroying the container, the virtual device identifier and the device operating context corresponding to the container may be released first, and then the virtual device created for the container is removed, where a specific removal method is not limited in this embodiment.
Therefore, in the case that each application in the container is no longer used, the present embodiment may destroy the container, avoid the occupation of the computer device resource by the container, and make room for other applications or device work.
Referring to fig. 6, a schematic structural diagram of an embodiment of a control apparatus provided in the present application, where the apparatus may be applied to a computer device, specifically, the apparatus may include:
an obtaining module 11, configured to obtain, during running of an application in a container, a device file of a virtual device used by the application, and determine an external device mapped by the virtual device;
wherein, the external device may include: the device may further include an interface register for receiving a state restore command and a state save command, and a device memory for storing a device run context, and the device run context may include configuration information and state information of the external device.
The control module 12 is configured to implement switching of a device running context of the external device based on state saving and restoring logic in the external device, so that the application can access or release the external device.
Alternatively, as shown in fig. 7, the control module 12 may include:
a writing unit 121, configured to write a device running context of the external device into the external device if the application needs to use the external device;
a state recovery command sending unit 122, configured to send a state recovery command to the external device, so that the external device responds to the device running context to implement data interaction with the application;
a state saving command sending unit 123, configured to send a state saving command to the external device when the external device is not accessed by the application within a preset time period, so that the external device saves a current device operating context;
a data synchronization unit 124 for synchronizing a current device operating context of the external device;
a device releasing unit 125, configured to release the mapping relationship between the external device and the virtual device, and adjust the current state of the external device to an idle state.
As another alternative embodiment of the present application, as shown in fig. 7, the obtaining module 11 may include:
the query unit 111 is configured to query whether the virtual device is mapped with an external device, and if the query result is yes, trigger the control module 12 to execute the state saving and restoring logic based on the external device, so as to implement a step of switching an operating context of the external device;
a mapping relationship establishing unit 112, configured to, if the query result of the querying unit is negative, obtain the external device currently in the idle state, and establish a mapping relationship between the virtual device and the external device currently in the idle state.
Optionally, referring to fig. 8, in the case that the container engine creates the container, the apparatus may further include:
a first creating module 13, configured to configure a virtual device identifier and create a device running context for the container;
a second creating module 14, configured to create a virtual device corresponding to the virtual device identifier and the device operating context, and a device file of the virtual device;
the information acquisition module 15 is configured to acquire attribute information of the device file, and feed back the attribute information to the container engine, so that the application acquires the attribute information of the device file through the container engine, and acquires the device file based on the attribute information of the device file;
wherein the attribute information of the device file includes a path and/or a file number of the device file.
As another embodiment of the present application, as shown in fig. 9, the apparatus may further include:
a command receiving module 16, configured to receive a container destruction command for the container sent by the container engine, where the container destruction command is generated when each application in the container is cleared;
a releasing module 17, configured to respond to the container destruction command and release the virtual device identifier and the device operation context corresponding to the container;
a clearing module 18 configured to clear the virtual appliance created for the container.
It should be noted that the modules and units may be program modules for implementing corresponding functions, and specific implementation processes for implementing corresponding functions by each program module may refer to descriptions of corresponding parts in the foregoing method embodiments, which are not described in detail in this embodiment.
Referring to fig. 10, a hardware structure diagram of a computer device provided in this embodiment of the present application, where the computer device may be a terminal or a server, and the present application does not limit a product type thereof, and in this embodiment, the computer device may include: a communication interface 21, an external device 22, a memory 23, and a processor 24, wherein:
the communication interface 21 may include an interface of a wireless communication module and/or a wired communication module, such as an interface of a communication module, such as a WIFI module, a GPRS module, a GSM module, etc., and may also be an interface that implements data interaction inside the computer device, such as a USB interface, a parallel/serial port, etc.
The external device 22 may be a hardware device in the computer device except for the host, and the number and types of the external devices are not limited in the present application, and may be determined based on factors such as the product type and functions of the computer device, such as an accelerator, a GPU, and the like.
The memory 23 is used for storing a program for implementing the control method;
in the present application, the memory 23 may also be used to store device files, various data generated during the running of applications, and the like.
Optionally, the memory may store program codes for implementing the functional modules included in the virtual device, and may specifically be a high-speed RAM memory, or a non-volatile memory (non-volatile memory), such as at least one disk memory.
The processor 24 may be a central processing unit CPU, or an application Specific Integrated circuit asic (application Specific Integrated circuit), or one or more Integrated circuits configured to implement the embodiments of the present application, and the present application does not limit the composition of the processor 44.
In the embodiment of the present application, the processor 24 is configured to load and execute a program stored in a memory to implement the steps of the control method, which is not described herein again.
It should be noted that the structural components of the computer device proposed in the present application are not limited to the above-listed components, and may be determined according to the product type of the computer device, and the present application is not described in detail.
Finally, it should be noted that, in the embodiments, relational terms such as first, second and the like may be used solely to distinguish one operation, unit or module from another operation, unit or module without necessarily requiring or implying any actual such relationship or order between such units, operations or modules. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, or system that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, or system. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method or system that comprises the element.
The embodiments in the present description are described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same and similar parts among the embodiments are referred to each other. The device and the computer equipment disclosed by the embodiment correspond to the method disclosed by the embodiment, so that the description is relatively simple, and the relevant points can be referred to the method part for description.
The previous description of the disclosed embodiments is provided to enable any person skilled in the art to make or use the present application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the application. Thus, the present application is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims (9)

1. A method of controlling, the method comprising:
during the running period of the application in the container, acquiring a device file of the virtual device used by the application, and determining the external device mapped by the virtual device;
based on state saving and restoring logic in the external device, switching a device running context of the external device is realized, so that the application can access or release the external device according to the use requirement of the current running stage on external device resources, and interaction between the external device and the application is realized, wherein the device running context comprises configuration of the external device and preset key state data;
wherein the external device includes: the device comprises an interface register used for receiving a state recovery command and a state saving command, and a device memory used for storing a device running context, wherein the device running context comprises configuration information and state information of the external device.
2. The method of claim 1, wherein the enabling the switching of the device operating context of the external device based on state save recovery logic in the external device comprises:
under the condition that the application needs to use the external equipment, writing the equipment running context of the external equipment into the external equipment, and sending a state recovery command to the external equipment so that the external equipment responds to the equipment running context to realize data interaction with the application;
if the external equipment is not accessed by the application within a preset time period, sending a state saving command to the external equipment so that the external equipment saves the current equipment running context;
synchronizing the current device running context of the external device, releasing the mapping relation between the external device and the virtual device, and adjusting the current state of the external device to be an idle state.
3. The method of claim 2, the determining the external device to which the virtual device is mapped, comprising:
inquiring whether the virtual equipment is mapped with external equipment;
if yes, executing the state saving and restoring logic based on the external equipment to realize the switching of the equipment running context of the external equipment;
if not, acquiring the external equipment in the idle state at present, and establishing a mapping relation between the virtual equipment and the external equipment in the idle state at present.
4. A method according to any of claims 1 to 3, in the case of a container engine creating the container, the method further comprising:
configuring a virtual device identifier and creating a device running context for the container;
creating a virtual device corresponding to the virtual device identifier and the device operating context, and a device file of the virtual device;
acquiring attribute information of the equipment file, feeding the attribute information back to the container engine so that the application acquires the attribute information of the equipment file through the container engine, and acquiring the equipment file based on the attribute information of the equipment file;
wherein the attribute information of the device file includes a path and/or a file number of the device file.
5. The method of claim 4, further comprising:
receiving a container destruction command for the container sent by the container engine, the container destruction command being generated if each application in the container is cleared;
responding to the container destroying command, and releasing the virtual equipment identifier and the equipment operation context corresponding to the container;
clearing the virtual appliance created for the container.
6. A control device, the device comprising:
an obtaining module, configured to obtain, during running of an application in a container, a device file of a virtual device used by the application, and determine an external device mapped by the virtual device, where the external device includes: the device comprises an interface register used for receiving a state recovery command and a state saving command, and a device memory used for storing a device running context, wherein the device running context comprises configuration information and state information of the external device;
the control module is configured to implement switching of a device running context of the external device based on the state saving and restoring logic in the external device, so that the application can access or release the external device according to a use requirement of a current running stage on an external device resource to implement interaction between the external device and the application, where the device running context includes configuration of the external device and preset critical state data.
7. The apparatus of claim 6, the control module comprising:
a writing unit, configured to write a device running context of the external device into the external device when the application needs to use the external device;
a state recovery command sending unit, configured to send a state recovery command to the external device, so that the external device responds to the device running context to implement data interaction with the application;
a state saving command sending unit, configured to send a state saving command to the external device when the external device is not accessed by the application within a preset time period, so that the external device saves a current device operating context;
a data synchronization unit for synchronizing a current device operating context of the external device;
and the device releasing unit is used for releasing the mapping relation between the external device and the virtual device and adjusting the current state of the external device to be an idle state.
8. The apparatus of claim 7, the obtaining module comprising:
the query unit is used for querying whether the virtual device is mapped with an external device, and if the query result is yes, triggering the control module to execute the state saving and restoring logic based on the external device so as to realize the switching step of the device running context of the external device;
and the mapping relation establishing unit is used for acquiring the external equipment in the idle state currently and establishing the mapping relation between the virtual equipment and the external equipment in the idle state currently under the condition that the query result of the query unit is negative.
9. A computer device, the computer device comprising:
the communication interface is used for connecting external equipment, and the external equipment is provided with state saving and restoring logic;
a memory for storing a program for implementing the control method according to any one of claims 1 to 5;
a processor for loading and executing the memory-stored program, the program for:
during the running of an application in a container, acquiring a device file of a virtual device used by the application, and determining an external device mapped by the virtual device, wherein the external device comprises: the device comprises an interface register used for receiving a state recovery command and a state saving command, and a device memory used for storing a device running context, wherein the device running context comprises configuration information and state information of the external device;
based on state saving and restoring logic in the external device, switching a device running context of the external device is realized, so that the application can access or release the external device according to the use requirement of the current running stage on external device resources, and interaction between the external device and the application is realized, wherein the device running context comprises configuration of the external device and preset key state data;
wherein the application accesses the external device such that the application monopolizes the external device resource or the application shares the external device resource with other applications; and the application releases the external equipment so that other applications can monopolize the external equipment resources.
CN201910228643.4A 2019-03-25 2019-03-25 Control method and device and computer equipment Active CN109933435B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910228643.4A CN109933435B (en) 2019-03-25 2019-03-25 Control method and device and computer equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910228643.4A CN109933435B (en) 2019-03-25 2019-03-25 Control method and device and computer equipment

Publications (2)

Publication Number Publication Date
CN109933435A CN109933435A (en) 2019-06-25
CN109933435B true CN109933435B (en) 2022-03-25

Family

ID=66988103

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910228643.4A Active CN109933435B (en) 2019-03-25 2019-03-25 Control method and device and computer equipment

Country Status (1)

Country Link
CN (1) CN109933435B (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110955510B (en) * 2019-12-11 2021-03-02 腾讯科技(上海)有限公司 Isolation processing method and related device
CN113296872B (en) * 2020-04-13 2022-05-06 阿里巴巴集团控股有限公司 Container state query method, device, equipment, storage medium and system

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1936845A (en) * 2005-09-19 2007-03-28 联想(北京)有限公司 Method and apparatus for dynamic distribution of virtual machine system input-output apparatus
US7454756B2 (en) * 2004-03-05 2008-11-18 Intel Corporation Method, apparatus and system for seamlessly sharing devices amongst virtual machines
CN105354090A (en) * 2015-10-16 2016-02-24 安一恒通(北京)科技有限公司 Management method and device of virtual equipment
CN107179955A (en) * 2017-05-08 2017-09-19 北京海杭通讯科技有限公司 Equipment blocking method and its terminal based on Android containers

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2010097933A1 (en) * 2009-02-27 2010-09-02 富士通株式会社 Information processing device, information processing method, and computer program
US8438349B2 (en) * 2009-08-21 2013-05-07 Symantec Corporation Proxy backup of virtual disk image files on NAS devices
US20150106805A1 (en) * 2013-10-15 2015-04-16 Cisco Technology, Inc. Accelerated instantiation of cloud resource
US10091070B2 (en) * 2016-06-01 2018-10-02 Cisco Technology, Inc. System and method of using a machine learning algorithm to meet SLA requirements

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7454756B2 (en) * 2004-03-05 2008-11-18 Intel Corporation Method, apparatus and system for seamlessly sharing devices amongst virtual machines
CN1936845A (en) * 2005-09-19 2007-03-28 联想(北京)有限公司 Method and apparatus for dynamic distribution of virtual machine system input-output apparatus
CN105354090A (en) * 2015-10-16 2016-02-24 安一恒通(北京)科技有限公司 Management method and device of virtual equipment
CN107179955A (en) * 2017-05-08 2017-09-19 北京海杭通讯科技有限公司 Equipment blocking method and its terminal based on Android containers

Also Published As

Publication number Publication date
CN109933435A (en) 2019-06-25

Similar Documents

Publication Publication Date Title
US10990540B2 (en) Memory management method and apparatus
US9558016B2 (en) Platform system, method for changing support hardware configuration of universal extensible firmware interface basic input output system and computer program product
US8719639B2 (en) Virtual machine control program, virtual machine control system, and dump capturing method
US7996648B2 (en) Coupled symbiotic operating systems
CN105874428B (en) Technology for the operating system transformation in multiple operating system environments
CN113939805A (en) Method and system for interprocess communication
CN109033328B (en) Access request processing method, device, equipment and readable storage medium
CN109933435B (en) Control method and device and computer equipment
CN110704161B (en) Virtual machine creation method and device and computer equipment
JP2021524104A (en) Master / Standby Container System Switching
CN111090521A (en) Memory allocation method and device, storage medium and electronic equipment
CN103324582A (en) Memory migration method, memory migration device and equipment
US20190227918A1 (en) Method for allocating memory resources, chip and non-transitory readable medium
CN1979428A (en) System for automatically releasing applied programe module leaked memory in inlaid system
CN111444117A (en) Method and device for realizing fragmentation of storage space, storage medium and electronic equipment
CN113704177B (en) Storage method, system and related components of server firmware upgrade file
CN111628895B (en) Configuration data synchronization method, device, equipment and readable storage medium
CN116028455A (en) Data processing method and device, storage medium and electronic equipment
CN114489826A (en) Chip operation method and device, storage medium and electronic equipment
WO2014087654A1 (en) Data transmission device, data transmission method, and storage medium
CN117692322B (en) Network card configuration method and device, electronic equipment and storage medium
CN117369891B (en) Method and device for starting and running server, server and storage medium
CN113918353B (en) Workload capacity expansion method and system
CN117687703B (en) Method, device and system for starting server, storage medium and electronic equipment
CN113485789B (en) Resource allocation method and device and computer architecture

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant