Detailed Description
Reference will now be made in detail to embodiments of the present invention, examples of which are illustrated in the accompanying drawings, wherein like or similar reference numerals refer to the same or similar elements or elements having the same or similar function throughout. The embodiments described below with reference to the drawings are illustrative only and should not be construed as limiting the invention.
As used herein, the singular forms "a", "an", "the" and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. It will be further understood that the terms "comprises" and/or "comprising," when used in this specification, specify the presence of stated features, integers, steps, operations, elements, and/or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and/or groups thereof. It will be understood that when an element is referred to as being "connected" or "coupled" to another element, it can be directly connected or coupled to the other element or intervening elements may also be present. Further, "connected" or "coupled" as used herein may include wirelessly connected or wirelessly coupled. As used herein, the term "and/or" includes all or any element and all combinations of one or more of the associated listed items.
It will be understood by those skilled in the art that, unless otherwise defined, all terms (including technical and scientific terms) used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention belongs. It will be further understood that terms, such as those defined in commonly used dictionaries, should be interpreted as having a meaning that is consistent with their meaning in the context of the prior art and will not be interpreted in an idealized or overly formal sense unless expressly so defined herein.
As will be appreciated by those skilled in the art, a "terminal" as used herein includes both devices having a wireless signal receiver, which are devices having only a wireless signal receiver without transmit capability, and devices having receive and transmit hardware, which have devices having receive and transmit hardware capable of two-way communication over a two-way communication link. Such a device may include: a cellular or other communication device having a single line display or a multi-line display or a cellular or other communication device without a multi-line display; PCS (Personal Communications Service), which may combine voice, data processing, facsimile and/or data communication capabilities; a PDA (Personal Digital Assistant), which may include a radio frequency receiver, a pager, internet/intranet access, a web browser, a notepad, a calendar and/or a GPS (Global Positioning System) receiver; a conventional laptop and/or palmtop computer or other device having and/or including a radio frequency receiver. As used herein, a "terminal" or "terminal device" may be portable, transportable, installed in a vehicle (aeronautical, maritime, and/or land-based), or situated and/or configured to operate locally and/or in a distributed fashion at any other location(s) on earth and/or in space. As used herein, a "terminal Device" may also be a communication terminal, a web terminal, a music/video playing terminal, such as a PDA, an MID (Mobile Internet Device) and/or a Mobile phone with music/video playing function, or a smart tv, a set-top box, etc.
In the embodiment of the invention, the terminal equipment is provided with the main control system and at least two container systems, and a resource allocation strategy is preset. When the master control system is started, according to the respective resource proportion upper limits of the master control system, the foreground container system and the background container system specified in the preset resource allocation strategy, creating a resource allocation directory comprising respective resource allocation subdirectories of the master control system, the first container system in the foreground and at least one other container system in the background; the main control system starts the first container system and at least one other container system; and the first container system and each other container system after starting acquire resources according to the respective resource allocation subdirectory. It can be seen that, in the embodiment of the present invention, according to the resource allocation policy, the main control system, the container system in the foreground, and the at least one other container system in the background all have respective resource occupation upper limits, and each system can obtain and use software and hardware resources of the terminal device within the respective resource occupation upper limits, so that each system can be ensured to be in a runnable state, and a certain system can be prevented from occupying resource shares of other systems, for example, other container systems in the background can be prevented from occupying resource shares of the container system in the foreground; therefore, the system can not delay each system to process each task, and can also ensure that the container system at the foreground can obtain enough resources to ensure that the interaction with the user is not influenced, thereby bringing convenience to the user and improving the experience of the user.
The technical solution of the embodiments of the present invention is specifically described below with reference to the accompanying drawings.
A frame schematic diagram of an internal structure of a terminal device according to an embodiment of the present invention is shown in fig. 1, and includes: a master control system and more than two container systems.
Wherein the two or more container systems comprise a first container system, a second container system, … …, and an Nth container system. N is a positive integer of 2 or more.
The container system in the embodiment of the present invention is an operating system provided in a container created by the Linux container virtualization technology. The operating system may be a Linux operating system or a Unix operating system in the conventional sense, an Android system or an Ubuntu system derived from the Linux operating system, or a Windows system based on a Windows platform. In fact, the container system of the present invention is not limited to the aforementioned exemplary operating systems, and may cover all operating systems capable of operating in a container. For convenience of description, the technical solution of the present invention is described below by taking an Android system as a container system as an example.
The master control system may be the above-mentioned conventional operating system, or may be an operating system obtained by modifying the conventional operating system. The kernel is a kernel, or an enhanced kernel obtained after a functional module is added on the basis of the kernel. Preferably, the master control system may include a kernel; the container system calls or accesses the kernel through the master control system to realize various functions. Or the container system and the master control system share the kernel; the container system and the master control system comprise parts except the kernel in the existing operating system, such as parts of a framework layer and an application layer; both the container system and the master control system can independently call or access the kernel to realize various functions.
The main control system is mainly used for performing foreground and background management on a plurality of container systems, interacting with each container system and the like.
Preferably, the master control system may communicate with the container system through a container channel. Further, the container channel may be a socket channel.
The method for establishing the container channel between the main control system and the container system is described below.
The container system sends a container channel creating request to the master control system, wherein the container channel creating request comprises file descriptors corresponding to the container channel, file permissions, system identifiers of more than two operating systems allowing access to the container channel, the maximum allowed access number, identifiers of descriptors of files to be generated and the like. The two or more operating systems include a container system (that sends a container channel creation request) and an operating system that the container system expects to interact with.
After receiving a container channel creation request of the container system, the master control system creates a pair of socket file descriptors (socket pair) and a container channel connecting the pair of file descriptors, and names the pair of file descriptors. And recording the file authority, the system identification allowed to be accessed, the maximum access number allowed and the identification of the descriptor of the file to be generated in the container channel creating request into the created container channel.
The master control system registers the container channel and its identifier and a pair of file descriptors, and a system identifier allowing access to the container channel in an NSS (domain Space Server) virtual device of the kernel. The master control system and the kernel correspondingly record the registered container channel, the identification and file descriptor pair thereof and the system identification allowing the container channel to be accessed.
The NSS of the kernel returns the identification of the container channel to the container system, along with the system identifications that allow access to the container channel. And respectively returning the identifier of the container channel and each system identifier allowing to access the container channel to the operating system corresponding to each system identifier.
The container system acquires one file descriptor in the file descriptor pair of the container channel from the NSS according to the acquired identifier of the container channel.
After receiving the request of the main control system for acquiring the container channel, the main control system finds out the identifier of the registered container channel and returns the identifier to the main control system.
After acquiring the identifier of the container channel, the master control system sends a file descriptor acquisition request carrying the identifier of the container channel to the NSS virtual device in the kernel.
And the NSS virtual equipment in the kernel searches out the other file descriptor in the file descriptor pair of the container channel from the registered container channel, the identifier of the container channel and the file descriptor pair according to the identifier of the container channel in the received file descriptor acquisition request, and returns the other file descriptor. Preferably, the NSS checks whether the security information such as the system identifier, the access number, and the like of the container system that sends the file descriptor acquisition request matches with the corresponding information recorded in the container channel; if the verification result is consistent, the identifier of the container channel in the request is obtained according to the received file descriptor, and the other file descriptor in the file descriptor pair of the container channel is found out from the registered container channel, the identifier of the container channel and the file descriptor pair, and is returned to the master control system.
Equivalently, one file descriptor in a pair of file descriptors connecting two ends of the container channel is returned to the container system, and the other file descriptor is returned to the process of the master control system.
And after the master control system acquires the other file descriptor returned by the kernel, the establishment of the container channel between the master control system and the container system is finished. The master control system may communicate with the container system that owns a file descriptor of the container channel to which the another file descriptor belongs, through the another file descriptor.
Preferably, for a pair of file descriptors, the master control system obtains the structure of the socket description file from the kernel according to one file descriptor returned to one container system, associates the structure with the one file descriptor, and records the structure in the container channel. The container channel is then registered into the NSS virtual device of the kernel.
After receiving a file descriptor acquisition request of a process of a main control system, NSS virtual equipment in a kernel queries an unused file descriptor in the process of the main control system, associates the unused file descriptor with a file structure of a socket description file stored in a container channel, and returns the associated file descriptor to the process of the main control system. At this time, the associated file descriptor is equivalent to another file descriptor in the file descriptors of the same container channel.
The terminal equipment in the embodiment of the invention is preset with a resource scheduling strategy. The resource scheduling policy defines respective resource occupation upper limits of the main control system, the foreground container system and the background container system. The resource in the embodiment of the present invention may include at least one of the following: processor resources, memory resources, non-volatile memory resources, data transfer bus bandwidth resources, and the like.
Preferably, in the embodiment of the present invention, a main control system, a container system in the foreground, and at least one other container system in the background may be configured in the terminal device.
For example, when there is one other container system in the background, the resource occupancy upper limits of the master system, the container system in the foreground, and the other container system in the background specified in the resource scheduling policy are 30%, 50%, and 20%, respectively.
When the number of the other container systems in the background is more than two, the resource scheduling policy specifies the resource occupation upper limit of each other container system in the background.
Preferably, the resource scheduling policy may first specify the resource occupancy upper limit of the master control system and the container system in the foreground from the total resources of the terminal device, and then determine the remaining resources outside the resource occupancy upper limit of the master control system and the container system in the foreground, and specify the resource occupancy upper limit of each of the other container systems in the background within the range of the remaining resources. And the resource proportion upper limit of each other container system in the background is not less than the minimum resource required by the other container systems to maintain running.
Further, the average resource required by the continuous operation of each other container system in the background is determined, and the resource proportion upper limit and the like of each other container system in the background are specified by taking the average resource as a unit from the residual resources. For example, when there are two other container systems in the background, the resource ratio upper limits of the master control system, the container system in the foreground, the container system a in the background, and the container system B in the background specified in the resource scheduling policy are 30%, 50%, 10%, and 10%, respectively.
Therefore, the resource scheduling strategy and the subsequent resource scheduling method of the multi-system based on the resource scheduling strategy in the embodiment of the invention are suitable for application scenes of a plurality of other container systems in the background.
For convenience of understanding, a method for scheduling resources of multiple systems according to an embodiment of the present invention is described below by taking a main control system, a first container system in a foreground, and a second container system in a background (i.e., one other container system in the background) as an example, where a flowchart of the method is shown in fig. 2a, and includes the following steps:
s201: when the master control system is started, according to the resource proportion upper limit of each of the master control system, the foreground container system and the background container system specified in the preset resource allocation strategy, a resource allocation directory including resource allocation subdirectories of the master control system, the first container system in the foreground and the second container system in the background is created.
And when the master control system is started, mounting the resource subsystem. For example, when the master control system starts up and needs to allocate processor resources of the master control system, the first container system and the second container system, the processor resource subsystem in the Cgroup of the kernel is acquired and mounted.
The main control system creates a resource allocation directory comprising resource allocation subdirectories of the main control system, a first container system in the foreground and a second container system in the background through the resource subsystem according to respective resource proportion upper limits of the main control system, the foreground container system and the background container system specified in a preset resource allocation strategy.
Preferably, the master control system creates a multi-system resource allocation directory through the resource subsystem.
The master control system creates a resource allocation subdirectory of the master control system under the name of the resource allocation directory through the resource subsystem; in the specified file of the resource allocation subdirectory of the main control system, the resource occupation ratio upper limit of the main control system and/or the numerical value related to the resource occupation ratio upper limit specified by the resource allocation strategy are set.
The main control system creates a resource allocation subdirectory of a first container system in the foreground through a resource subsystem; in a designated file of the resource allocation subdirectory of the first container system, a resource occupation upper limit of the foreground container system and/or a numerical value related to the resource occupation upper limit specified by the resource allocation policy are set.
The master control system creates a resource allocation subdirectory of a second container system in the background through the resource subsystem; and setting a resource proportion upper limit of the background container system and/or a numerical value related to the resource proportion upper limit specified by the resource allocation strategy in a specified file of the resource allocation subdirectory of the second container system.
For example, when the resource is specifically a processor resource, in a specified file cpu.shares in a processor resource allocation subdirectory of the master control system, a numerical value associated with a resource occupation ratio upper limit of the master control system specified by the resource allocation policy is set to be 614; in a designated file cpu.shares in a processor resource allocation subdirectory of a first container system, setting a value associated with a resource occupation ratio upper limit of a main control system specified by a resource allocation strategy as 1024; shares in a designated file cpu in a processor resource allocation subdirectory of the second container system, a numerical value associated with a resource occupation ratio upper limit of the main control system specified by the resource allocation policy is set as 410. The numerical value of the total processor resource of the terminal equipment of the embodiment of the invention is represented as the sum 2048 of 614, 1024 and 410; the processor resource allocation upper limits of the master control system, the first container system in the foreground, and the second container system in the background are about 614/2048-30%, 1024/2048-50%, and 410/2048-20%, respectively.
Preferably, the master control system stores the created resource allocation directory including the resource allocation subdirectories of the respective systems in the master control system or the kernel for the respective container systems to acquire.
Preferably, the master control system creates the front and background resource subdirectories of the master control system under the names of the resource allocation subdirectories thereof according to the respective resource occupation upper limits of the front and background processes of the master control system specified in the resource allocation strategy within the range of the resource occupation upper limit in the resource allocation subdirectories thereof.
The main control system distributes resources for the front and the back stage processes according to the front and the back stage resource subdirectories respectively.
Specifically, the master control system creates a foreground resource subdirectory of the master control system under the name of a resource allocation subdirectory of the master control system through a resource subsystem; in the range of the resource occupation upper limit in the resource allocation subdirectory, the resource occupation upper limit of the foreground process of the main control system specified in the resource allocation strategy and/or the numerical value related to the resource occupation upper limit are set in the specified file of the foreground resource subdirectory of the main control system.
The master control system creates a background resource subdirectory of the master control system under the name of the resource allocation subdirectory through the resource subsystem; in the range of the resource ratio upper limit in the resource allocation subdirectory, the resource ratio upper limit of the background process of the main control system and/or the numerical value related to the resource ratio upper limit specified in the resource allocation strategy are set in the specified file of the background resource subdirectory of the main control system.
The main control system distributes resources for the foreground process and the background process of the main control system according to the resource occupation upper limit in the foreground resource subdirectory and the background resource subdirectory and/or the numerical value associated with the resource occupation upper limit.
For example, the resource is specifically a processor resource, the upper limit of the processor resource occupation ratio of the front and the background processes of the main control system specified in the resource allocation policy is 60% and 40%, respectively, and the upper limit of the resource occupation ratio in the processor resource allocation subdirectory of the main control system is 30%; the upper limit of the processor resource ratio is set to 30% × 60% >, 18%, and 30% × 40% >, 12% respectively in the designated files of the front and back resource subdirectories of the main control system. The main control system distributes processor resources for a foreground process and a background process of the main control system according to the upper limit of the processor resource occupation ratio of 18 percent and 12 percent respectively.
S202: the master control system starts the first and second container systems.
Preferably, after the master control system starts the first container system, the resource occupation upper limits of the front and background processes of the background container system specified in the resource allocation policy are sent to the first container system through the container channel.
And after the master control system starts the second container system, sending the resource ratio upper limits of the front and background processes of the background container system specified in the resource allocation strategy to the second container system through the container channel.
S203: and the first container system and the second container system after starting acquire resources according to respective resource allocation subdirectories.
And when the first container system and the second container system are started, respectively acquiring the resource subsystems from the kernel, and mounting the acquired resource subsystems.
The first and second container systems obtain respective resource allocation subdirectories through the resource subsystem.
The first and second container systems respectively obtain resources according to their respective resource allocation subdirectories.
Preferably, the first and second container systems may use a variety of methods to allocate resources for their foreground and background processes.
A method for a container system to allocate resources for a front and a back stage process thereof comprises the following steps: after the first container system receives the resource occupation upper limits of the front and the background processes of the background container system specified in the resource allocation strategy sent by the master control system through the container channel, in the range of the resource occupation upper limits in the resource allocation subdirectory of the first container system, the front and the background resource subdirectories of the first container system are respectively created under the names of the resource allocation subdirectories according to the received resource occupation upper limits of the front and the background processes of the background container system.
And the first container system allocates resources for the front and the background processes according to the front and the background resource subdirectories.
Specifically, the first container system creates a foreground resource subdirectory of the first container system under the name of a resource allocation subdirectory of the first container system through a resource subsystem; in the range of the resource occupation upper limit in the resource allocation subdirectory, the resource occupation upper limit of the foreground process of the foreground container system specified in the resource allocation strategy and/or the numerical value related to the resource occupation upper limit are set in the specified file of the foreground resource subdirectory of the first container system.
The first container system creates a background resource subdirectory of the first container system under the name of a resource allocation subdirectory of the first container system through a resource subsystem; in the range of the resource occupation upper limit in the resource allocation subdirectory, the resource occupation upper limit of the background process of the foreground container system specified in the resource allocation strategy and/or the numerical value related to the resource occupation upper limit are set in the specified file of the background resource subdirectory of the first container system.
The first container system distributes resources for the foreground process and the background process of the first container system according to the resource occupation upper limit in the foreground resource subdirectory and the background resource subdirectory and/or the numerical value associated with the resource occupation upper limit.
For example, the resource is specifically a processor resource, the respective processor resource occupation upper limits of the front and back processes of the front container system specified in the resource allocation policy are 70% and 30%, respectively, and the resource occupation upper limit in the processor resource allocation subdirectory of the front container system is 50%; then, in the designated files of the front and back-end resource subdirectories of the first container system, the upper limit of the processor resource ratio is set to 50% × 70% >, 35%, 50% × 30% >, 15%, respectively. The first container system allocates processor resources for the foreground process and the background process of the first container system according to the processor resource occupation upper limits of 35% and 15% respectively.
Similarly, the second container system may allocate resources for the foreground and background processes of the second container system according to the method.
For example, the resource is specifically a processor resource, the respective upper limits of the processor resource occupation ratios of the front and the background processes of the background container system specified in the resource allocation policy are respectively 80% and 20%, and the upper limit of the resource occupation ratio in the processor resource allocation subdirectory of the background container system is 20%; then, in the designated files of the front and back-end resource subdirectories of the second container system, the upper limit of the processor resource ratio is set to 20% × 80% >, 16%, 20% × 20% >, 4%, respectively. And the second container system allocates processor resources for the foreground process and the background process of the second container system according to the 16 percent and 4 percent of processor resource occupation ratio upper limit respectively.
In addition, it should be noted that, in this step, the resource occupation rate upper limits of the foreground process and the background process of the first container system in the foreground are higher than the resource occupation rate upper limits of the foreground process and the background process of the second container system in the background. However, this is not essential. Those skilled in the art can reasonably determine the resource ratio upper limit of each system and its foreground and background processes according to historical data, empirical data, experimental data, and/or actual conditions, etc., so as to meet various needs of users.
Another method for allocating resources to the front and the back processes by the container system comprises the following steps: the first container system respectively creates front and background resource subdirectories of the first container system under the name of a resource allocation subdirectory thereof according to respective resource proportion upper limits of the front and background processes preset therein; the first container system allocates resources for the front and background processes according to the front and background resource subdirectories respectively.
Specifically, the first container system creates a foreground resource subdirectory of the first container system under the name of a resource allocation subdirectory of the first container system through a resource subsystem; in the range of the resource occupation upper limit in the resource allocation subdirectory, the resource occupation upper limit of the foreground process preset in the first container system and/or the numerical value associated with the resource occupation upper limit are set in the specified file of the foreground resource subdirectory of the first container system.
The first container system creates a background resource subdirectory of the first container system under the name of a resource allocation subdirectory of the first container system through a resource subsystem; in the range of the resource ratio upper limit in the resource allocation subdirectory, the resource ratio upper limit of the background process preset in the first container system and/or the numerical value associated with the resource ratio upper limit are set in the designated file of the background resource subdirectory of the first container system.
The first container system distributes resources for the foreground process and the background process of the first container system according to the resource occupation upper limit in the foreground resource subdirectory and the background resource subdirectory and/or the numerical value associated with the resource occupation upper limit.
Similarly, the second container system respectively creates front and background resource subdirectories of the second container system under the names of the resource allocation subdirectories according to the respective resource proportion upper limits of the front and background processes preset in the second container system; and the second container system distributes resources for the front and the background processes according to the front and the background resource subdirectories respectively.
It is easy to understand that the method for allocating resources to the foreground and background processes by the container system is more suitable for application scenarios in which the container system does not have (preset) the resource occupation upper limit of the foreground and background processes, or has higher security requirements although the container system has the resource occupation upper limit of the foreground and background processes; for example, the resource occupation upper limit of the foreground and background processes of the container system may be tampered with by a malicious program, and a file where the resource occupation upper limit of the foreground and background processes of the container system is attached by the malicious program.
In practical operation, for the above steps S201 and S202, step S201 may be executed first and then step S202 may be executed, step S202 may be executed first and then step S201 may be executed, or step S201 and step S202 may be executed simultaneously.
In fact, through the flow of the above steps S201 to S203, a schematic diagram of an example of the resource allocation directory of multiple systems in the terminal device in the embodiment of the present invention is shown in fig. 3, and the resource allocation directory is in a tree structure, and is located at a root node, and has resource allocation subdirectories of the master control system, the first container system in the foreground, and the second container system in the background; a foreground resource subdirectory and a background resource subdirectory of the master control system are arranged under the resource allocation subdirectory name of the master control system; a foreground resource subdirectory and a background resource subdirectory of the first system are arranged under the name of the resource allocation subdirectory of the first system; the resource allocation subdirectory of the second system is provided with a foreground resource subdirectory and a background resource subdirectory of the second system.
The other method for distributing resources for the foreground and background processes by the container system is more suitable for application scenarios in which the container system has the resource occupation upper limit of the foreground and background processes and has lower security requirements.
In fact, an embodiment of the present invention further provides a method for scheduling resources of multiple systems suitable for foreground and background switching of a container system, where a flowchart of the method is shown in fig. 2b, and on the basis of the above steps S201 to S203, the following steps are added:
s204: and the master control system updates the resource allocation subdirectories of the first container system and the second container system which are respectively switched to the background and the foreground according to the resource allocation strategy.
And after the main control system detects that the first container system and the second container system are switched between the front stage and the back stage, updating the resource occupation upper limits in the resource allocation subdirectories of the first container system and the second container system respectively switched to the back stage and the front stage according to the respective resource occupation upper limits of the back stage container system and the front stage container system specified in the resource allocation strategy.
Specifically, after detecting that the first container system is switched to the background and the second container system is switched to the foreground, the main control system updates the resource proportion upper limit and/or the numerical value associated with the resource proportion upper limit in the specified file of the resource allocation subdirectory of the first container system to the resource proportion upper limit and/or the numerical value associated with the resource proportion upper limit of the background container system specified in the resource allocation strategy; and updating the resource occupation upper limit and/or the numerical value associated with the resource occupation upper limit in the specified file of the resource allocation subdirectory of the second container system into the resource occupation upper limit and/or the numerical value associated with the resource occupation upper limit of the foreground container system specified in the resource allocation strategy.
S205: and respectively switching to the first container system and the second container system of the background and the foreground, and respectively acquiring resources according to the updated resource allocation subdirectories.
And respectively switching to the first container system and the second container system of the background and the foreground, respectively acquiring the resource subsystems from the kernel, and mounting the acquired resource subsystems.
And respectively switching to the first container system and the second container system of the background and the foreground to obtain the updated resource allocation subdirectories through the resource subsystems.
And respectively switching to the first container system and the second container system of the background and the foreground to acquire resources according to the updated resource allocation subdirectories.
Preferably, the main control system updates the resource proportion upper limit and/or the numerical value associated with the resource proportion upper limit in the specified file of the resource allocation subdirectory of the first container system switched to the background to the resource proportion upper limit and/or the numerical value associated with the resource proportion upper limit of the background container system specified by the resource allocation policy through the resource subsystem.
And the main control system updates the resource occupation upper limit and/or the numerical value associated with the resource occupation upper limit in the specified file of the resource allocation subdirectory of the second container system switched to the foreground into the resource occupation upper limit and/or the numerical value associated with the resource occupation upper limit of the foreground container system specified by the resource allocation strategy through the resource subsystem.
Preferably, the first container system is switched to the background, and the foreground resource subdirectory and the background resource subdirectory of the first container system under the name of the resource allocation subdirectory of the first container system are updated according to the respective resource occupation upper limits of the front and background processes of the background container system or the respective resource occupation upper limits of the front and background processes preset in the first container system, which are specified in the resource allocation strategy, in the range of the resource occupation upper limit in the updated resource allocation subdirectory of the first container system.
And the first container system switched to the background allocates resources for the front and background processes according to the updated front and background resource subdirectories.
Further, the first container system switched to the background updates the resource occupation upper limit of the foreground process in the specified file of the foreground resource subdirectory of the first container system and/or the numerical value associated with the resource occupation upper limit to the resource occupation upper limit of the foreground process of the background container system and/or the numerical value associated with the resource occupation upper limit specified in the resource allocation strategy in the range of the resource occupation upper limit in the resource allocation subdirectory updated by the resource subsystem.
And the first container system switched to the background updates the resource occupation upper limit of the background process in the specified file of the background resource subdirectory of the first container system and/or the numerical value associated with the resource occupation upper limit into the resource occupation upper limit of the background process of the background container system and/or the numerical value associated with the resource occupation upper limit specified in the resource allocation strategy in the range of the resource occupation upper limit in the resource allocation subdirectory updated by the first container system through the resource subsystem.
And the first container system switched to the background allocates resources for the foreground process and the background process of the first container system switched to the background according to the updated resource occupation upper limit in the foreground resource subdirectory and the background resource subdirectory and/or the value associated with the resource occupation upper limit.
For example, the resource is specifically a processor resource, the respective upper limits of the processor resource occupation ratios of the front and the background processes of the background container system specified in the resource allocation policy are respectively 80% and 20%, and the upper limit of the resource occupation ratio in the processor resource allocation subdirectory of the background container system is 20%; the processor resource in the designated file of the updated front and background resource subdirectories of the first container system switched to the background is updated to 20% × 80% ═ 16%, and 20% × 20% ═ 4%, respectively. And the first container system switched to the background allocates processor resources for the foreground process and the background process of the first container system switched to the background according to the processor resource occupation upper limits of 16% and 4% respectively.
Similarly, the resource allocation subdirectory, the foreground resource subdirectory, and the resource proportion upper limit and/or the resource proportion upper limit associated numerical value in the background resource subdirectory of the second container system switched to the foreground can be updated.
In real time, the resource proportion upper limit of the first container system and the foreground and background processes switched to the background is consistent with the resource proportion upper limit of the second container system and the foreground and background processes when the second container system and the foreground and background processes are in the background; the resource ratio upper limit of the second container system and the foreground and background processes switched to the foreground is consistent with the resource ratio upper limit of the first container system and the foreground and background processes when the first container system and the foreground and background processes are in the foreground.
The embodiment of the present invention further provides another resource scheduling method for multiple systems suitable for switching between a front and a back of a container system, and a flowchart of the method is shown in fig. 2c, where on the basis of the above steps S201 to S203, the following steps are added:
s211: and the main control system determines the resource ratio upper limits of the first container system and the second container system which are respectively switched to the background and the background according to the resource allocation strategy, and respectively sends the resource ratio upper limits to the first container system and the second container system.
Specifically, after detecting that the first container system is switched to the background and the second container system is switched to the foreground, the main control system determines values associated with the resource ratio upper limit and/or the resource ratio upper limit of the first container system switched to the background and the resource ratio upper limit and/or the resource ratio upper limit of the second container system switched to the foreground according to the resource ratio upper limits of the background container system and the foreground container system specified in the resource allocation policy.
And the main control system sends the determined resource occupation ratio upper limit and/or the numerical value related to the resource occupation ratio upper limit of the first container system switched to the background to the first container system through a container channel between the main control system and the first container system.
Preferably, the main control system sends the determined foreground process of the first container system switched to the background, and the resource occupation ratio upper limit of the background process and/or the numerical value associated with the resource occupation ratio upper limit to the first container system through a container channel between the main control system and the first container system.
And the main control system sends the determined resource occupation ratio upper limit and/or the numerical value related to the resource occupation ratio upper limit of the second container system switched to the foreground to the second container system through a container channel between the main control system and the second container system.
Preferably, the main control system sends the determined foreground process of the second container system switched to the foreground and the resource occupation ratio upper limit and/or the value associated with the resource occupation ratio upper limit of the background process to the second container system through a container channel between the main control system and the second container system.
S212: and respectively switching to the first container system and the second container system of the background and the background to update the respective resource allocation subdirectories according to the respective received resource ratio upper limit.
And after the first container system switched to the background receives the resource proportion upper limit and/or the numerical value associated with the resource proportion upper limit of the first container system sent by the main control system through the container channel, updating the resource proportion upper limit and/or the numerical value associated with the resource proportion upper limit in the specified file of the resource allocation catalog of the first container system according to the received resource proportion upper limit and/or the numerical value associated with the resource proportion upper limit.
Preferably, after the first container system switched to the background receives the values associated with the resource occupation upper limit and/or the resource occupation upper limit of the foreground process and the resource occupation upper limit of the background process sent by the main control system through the container channel, the values associated with the resource occupation upper limit and/or the resource occupation upper limit in the specified file of the foreground resource subdirectory and the background resource subdirectory of the first container system are updated.
And after the second container system switched to the foreground receives the resource ratio upper limit and/or the numerical value associated with the resource ratio upper limit of the second container system sent by the main control system through the container channel, updating the resource ratio upper limit and/or the numerical value associated with the resource ratio upper limit in the specified file of the resource allocation catalog of the second container system according to the received resource ratio upper limit and/or the numerical value associated with the resource ratio upper limit.
Preferably, after the second container system switched to the foreground receives the values, which are sent by the master control system, of the foreground process of the second container system and associated with the resource occupation upper limit and/or the resource occupation upper limit of the foreground process through the container channel, the values associated with the resource occupation upper limit and/or the resource occupation upper limit in the foreground resource subdirectory and the specified file of the foreground resource subdirectory of the second container system are updated.
S213: and respectively switching to the first container system and the second container system of the background and the foreground, and respectively acquiring resources according to the updated resource allocation subdirectories.
The method in this step is consistent with the specific method in step S205, and is not described herein again.
Based on the foregoing method for scheduling resources for multiple systems, an embodiment of the present invention further provides a device for scheduling resources for multiple systems, where the device is disposed in a terminal device in the embodiment of the present invention, and a schematic frame diagram of an internal structure of the device is shown in fig. 4, where the method includes: a master control system, a first container system, and at least one other container system.
Wherein, master control system includes: a resource allocation directory processing module 401 and a container system startup module 402.
The resource allocation directory processing module 401 is configured to, when the master control system is started, create a resource allocation directory that includes resource allocation subdirectories of the master control system, the first container system in the foreground, and the at least one other container system in the background, according to resource occupation upper limits of the master control system, the foreground container system, and the background container system, which are specified in a preset resource allocation policy.
The container system activation module 402 is used to activate a first container system and at least one other container system.
The first container system includes:
the first resource obtaining and allocating module 411 is configured to obtain resources according to the resource allocation subdirectory of the first container system.
Each of the other container systems includes:
the other resource acquiring and allocating module 421 is configured to acquire resources according to the resource allocation subdirectory of the other container system to which the other resource acquiring and allocating module 421 belongs.
Preferably, the resource allocation directory processing module 401 is specifically configured to mount the resource subsystem when the master control system is started; and creating a resource allocation directory comprising respective resource allocation subdirectories of the main control system, the first container system in the foreground and each other container system in the background through the resource subsystem according to respective resource proportion upper limits of the main control system, the foreground container system and the background container system specified in a preset resource allocation strategy.
Preferably, the resource allocation directory processing module 401 is specifically configured to create resource allocation subdirectories of the master control system, the first container system, and other container systems, and set resource occupation upper limits of the master control system, the foreground container system, and the background container system, which are specified by the resource allocation policy, in an assigned file of each resource allocation subdirectory.
Preferably, as shown in fig. 4, the master control system in the embodiment of the present invention further includes:
the main control resource allocation module 403 is configured to create front and background resource subdirectories of the main control system under the resource allocation subdirectory name of the main control system according to respective resource occupation upper limits of front and background processes of the main control system specified in the resource allocation policy in the range of the resource occupation upper limit in the resource allocation subdirectory of the main control system; and distributing resources for the front and the back stage processes of the main control system according to the front and the back stage resource subdirectories of the main control system.
Preferably, the first resource obtaining and allocating module 411 is specifically configured to mount the resource subsystem when the first container system is started; acquiring a resource allocation subdirectory of the first container system through a resource subsystem; the resources are acquired according to the resource allocation subdirectory of the first container system.
The other resource obtaining and allocating module 421 is specifically configured to mount the resource subsystem when the other container system to which the other resource obtaining and allocating module belongs is started; acquiring resource allocation subdirectories of other container systems to which the resource subsystems belong through the resource subsystems; and acquiring the resources according to the resource allocation subdirectory of the other container system to which the system belongs.
Preferably, the container system starting module 402 is further configured to send the resource occupation ratio upper limit transmission notification after the first container system is started.
The resource allocation catalog processing module 401 is further configured to send, after receiving the resource allocation upper limit transmission notification, the resource allocation catalog upper limit of each of the foreground and background processes of the foreground container system specified in the resource allocation policy to the first container system through the container channel.
The first resource obtaining and allocating module 411 is further configured to, within the range of the resource proportion upper limit in the resource allocation subdirectory of the first container system, respectively create front and background resource subdirectories of the first container system under the allocation subdirectory name of the first container system according to the received resource proportion upper limit of the front and background processes of the front and background container systems; and allocating resources for the front and background processes of the first container system according to the front and background resource subdirectories of the first container system.
Further, the resource allocation catalog processing module 401 is further configured to send, after receiving the resource allocation upper limit transmission notification, the resource allocation catalog upper limit of each of the foreground and background processes of the corresponding background container system specified in the resource allocation policy to each of the other container systems through the container channel.
The second resource obtaining and allocating module 421 is further configured to, within the range of the resource proportion upper limit in the resource allocation subdirectory of the other container system to which the second resource obtaining and allocating module belongs, respectively create the front and background resource subdirectories of the other container system under the allocation subdirectory names of the other container system to which the second resource obtaining and allocating module belongs according to the received respective resource proportion upper limits of the front and background processes of the corresponding background container system; and allocating resources for the front and background processes of the other container systems according to the front and background resource subdirectories of the other container systems.
Preferably, the first resource obtaining and allocating module 411 is specifically configured to respectively create front and background resource subdirectories of the first container system under the resource allocation subdirectory names of the first container system according to respective resource proportion upper limits of front and background processes preset in the first container system; and allocating resources for the front and background processes of the first container system according to the front and background resource subdirectories of the first container system.
Preferably, the second resource obtaining and allocating module 421 is specifically configured to respectively create front and background resource subdirectories of other container systems under the resource allocation subdirectory names of the other container systems to which the second resource obtaining and allocating module belongs, according to respective resource occupation upper limits of front and background processes preset in the other container systems to which the second resource obtaining and allocating module belongs; and allocating resources for the front and background processes of the other container systems according to the front and background resource subdirectories of the other container systems.
Preferably, the resource allocation directory processing module 401 is further configured to, after detecting that the first container system is switched between the background and the other container systems, update the resource occupation upper limits in the resource allocation subdirectories of the first container system and the other container system respectively switched to the background and the foreground according to the resource occupation upper limits of the background container system and the foreground container system specified in the resource allocation policy.
Preferably, the resource allocation catalog processing module 401 is further configured to determine, according to respective resource occupation upper limits of the background container system and the foreground container system specified in the resource allocation policy, resource occupation upper limits of the first container system and the one other container system respectively switched to the background and the foreground, after detecting that the first container system is switched to the other container system in the foreground and the background, and send the determined resource occupation upper limits to the first container system and the one other container system through the container channel.
And the first resource obtaining and allocating module 411 is further configured to update the resource proportion upper limit in the resource allocation subdirectory of the first container system according to the received resource proportion upper limit of the first container system switched to the background.
The second resource obtaining and allocating module 421 is further configured to update the resource occupation upper limit in the resource allocation subdirectory of the other container system to which the foreground belongs according to the received resource occupation upper limit of the other container system to which the foreground belongs.
For the above-mentioned method for implementing the functions of the resource allocation directory processing module 401, the container system starting module 402, and the main control resource allocation module 403 in the main control system, the first resource obtaining and allocating module 411 in the first container system, and the other resource obtaining and allocating modules 421 in the other container systems, reference may be made to the above-mentioned specific contents of the flow steps shown in fig. 2a, 2b, and 2c, and details thereof are not repeated here.
In the embodiment of the invention, according to the resource allocation strategy, the main control system, the container system in the foreground and at least one container system in the background all have respective resource proportion upper limits, and each system can acquire and use software and hardware resources of the terminal equipment in the range of the respective resource proportion upper limits, so that each system can be ensured to be in a running state, and a certain system can be prevented from occupying the resource share of other systems, for example, the container system in the background can be prevented from occupying the resource share of the container system in the foreground; therefore, the system can not delay each system to process each task, and can also ensure that the container system at the foreground can obtain enough resources to ensure that the interaction with the user is not influenced, thereby bringing convenience to the user and improving the experience of the user.
In addition, in the embodiment of the invention, the resources in the resource occupation upper limit range of the resource allocation subdirectory of the main control system are equivalent to the resources allocated to the main control system; the main control system can independently distribute resources to the foreground process and the background process of the main control system within the resource range allocated to the main control system according to the resource occupation ratio upper limit of the front process and the background process of the main control system specified by the resource distribution strategy. The resource occupation upper limits of the front and the background processes of the main control system in the resource allocation strategy are reasonably set, so that the processes in the main control system can be prevented from occupying the resources of the processes allocated to the container system in an crowded manner under the condition of ensuring the normal operation of the front and the background processes in the main control system; the method not only fully utilizes the resource of the upper limit range of the resource occupation of the main control system, but also enhances the safety and reliability of the process utilizing the resource of the main control system.
Furthermore, in the embodiment of the present invention, the resources in the resource occupation ratio upper limit ranges of the resource allocation subdirectories of the first container system and the at least one other container system respectively located in the foreground and the background are equivalent to the resources allocated to the first container system and each other container system located in the foreground and the background respectively; the first container system and each other container system respectively in the foreground and the background can respectively and independently perform resource allocation on the respective foreground process and the respective background process in the resource allocation range according to the resource occupation upper limit of the respective foreground process and the respective background process specified by the resource allocation strategy. The resource occupation upper limits of the respective front and background processes of the foreground container system and the background container system in the resource allocation strategy are reasonably set, so that the process in one container system can be prevented from occupying the resources of the processes allocated to the main control system and the other container system in an crowded manner under the condition that the front and background processes in the first container system in the foreground and the background and the front and background processes in the other container systems are ensured to run normally; the method not only fully utilizes the resource of the resource proportion upper limit range of each container system, but also enhances the safety and reliability of the process utilizing the resource of the container system to which the process belongs.
In addition, in the embodiment of the present invention, after detecting that the foreground and background states of the first container system are switched to the other container system, the resource proportion upper limit in the resource allocation subdirectory of the first container system and the other container system respectively switched to the background and the foreground may be updated, which is equivalent to updating the resource range allocated to the first container system and the other container system switched to the background and the foreground. Moreover, the resource occupation upper limits in the foreground resource subdirectory and the background resource subdirectory of the first container system and the other container system respectively switched to the background and the foreground can be updated, which is equivalent to updating the resource ranges allocated to the foreground process and the background process of the first container system and the other container system respectively switched to the background and the foreground. By utilizing the embodiment of the invention, the allocated (acquirable) resource range of each container system for switching the foreground and background states and the allocated resource range of the foreground and background processes in the container system can be automatically adjusted under the condition that the container system is switched between the foreground and background states; the method and the system ensure that the resources of the terminal equipment are fully utilized on the whole, prevent the process of each container system switching the foreground and background states from occupying the resources in the resource range of other systems, and ensure the safety and reliability of the process of each container system in resource utilization.
Those skilled in the art will appreciate that the present invention includes apparatus directed to performing one or more of the operations described in the present application. These devices may be specially designed and manufactured for the required purposes, or they may comprise known devices in general-purpose computers. These devices have stored therein computer programs that are selectively activated or reconfigured. Such a computer program may be stored in a device (e.g., computer) readable medium, including, but not limited to, any type of disk including floppy disks, hard disks, optical disks, CD-ROMs, and magnetic-optical disks, ROMs (Read-Only memories), RAMs (Random Access memories), EPROMs (Erasable Programmable Read-Only memories), EEPROMs (Electrically Erasable Programmable Read-Only memories), flash memories, magnetic cards, or optical cards, or any type of media suitable for storing electronic instructions, and each coupled to a bus. That is, a readable medium includes any medium that stores or transmits information in a form readable by a device (e.g., a computer).
It will be understood by those within the art that each block of the block diagrams and/or flowchart illustrations, and combinations of blocks in the block diagrams and/or flowchart illustrations, can be implemented by computer program instructions. Those skilled in the art will appreciate that the computer program instructions may be implemented by a processor of a general purpose computer, special purpose computer, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, implement the features specified in the block or blocks of the block diagrams and/or flowchart illustrations of the present disclosure.
Those of skill in the art will appreciate that various operations, methods, steps in the processes, acts, or solutions discussed in the present application may be alternated, modified, combined, or deleted. Further, various operations, methods, steps in the flows, which have been discussed in the present application, may be interchanged, modified, rearranged, decomposed, combined, or eliminated. Further, steps, measures, schemes in the various operations, methods, procedures disclosed in the prior art and the present invention can also be alternated, changed, rearranged, decomposed, combined, or deleted.
The foregoing is only a partial embodiment of the present invention, and it should be noted that, for those skilled in the art, various modifications and decorations can be made without departing from the principle of the present invention, and these modifications and decorations should also be regarded as the protection scope of the present invention.