Disclosure of Invention
One object of the present disclosure is to propose a program running scheme capable of increasing the program start-up speed.
According to a first aspect of the present disclosure, there is provided a program execution method including: in the process of starting the program, saving the running time of the process by using the time after at least one part of the resource file required by the process loading program so as to obtain a mirror process of the process; and responding to the next starting of the program, and recovering the mirror process to obtain a process entity which is consistent with the running state of the process corresponding to the moment.
Optionally, the program execution method further includes: responding to the next starting of the program, and judging whether an available mirror image process exists or not; and executing a step of recovering the mirror process in the case where it is determined that there is an available mirror process.
Optionally, the step of saving the runtime of the process includes: acquiring the current running state of a process; based on the runtime state, collecting thread context in the process; and writing each thread and semaphore in the process into a file one by one according to the thread context and storing to obtain the mirror image process.
Optionally, the step of collecting thread context in the process includes: transmitting the runtime state formation parameter list to the kernel; calling a process entity in the kernel according to the parameter list; and collecting the thread context in the process entity called currently by the kernel as the thread context in the process.
Optionally, the step of recovering the mirroring process includes: analyzing the mirror image process to obtain a runtime structure; creating a process structure according to the runtime structure; and generating a process entity according to the created process structure.
Optionally, the runtime includes an element corresponding to the current running state of the process.
Optionally, the elements include: stacking; a register; memory layout; and a semaphore.
Optionally, the program execution method further includes: and registering a callback and error processing mechanism in the application layer, wherein the callback and error processing mechanism is used for carrying out callback and error processing under the condition that an error occurs during the process of saving the process.
According to a second aspect of the present disclosure, there is also provided a program execution method including: responding to the starting of the program, and judging whether a mirror process corresponding to the program exists or not; under the condition that the mirror image process corresponding to the program exists, constructing a process entity based on the mirror image process; and/or under the condition that the mirror process corresponding to the program does not exist, using the resource file required by the process loading program, and saving the running time of the process at the time after at least one part of the resource file required by the process loading program so as to obtain the mirror process of the process.
According to a third aspect of the present disclosure, there is also provided a program execution device including: the system comprises a mirror image process generation module, a process loading module and a processing module, wherein the mirror image process generation module is used for saving the running time of a process at the moment after at least one part of a resource file required by the process loading program in the process of starting the program so as to obtain a mirror image process of the process; and the mirror image process recovery module is used for responding to the next starting of the program and recovering the mirror image process so as to obtain a process entity with the running state consistent with that of the process corresponding to the moment.
Optionally, the program execution device further includes: and the judging module is used for responding to the next starting of the program, judging whether an available mirror process exists or not, and under the condition that the available mirror process exists, the mirror process recovering module recovers the mirror process.
Optionally, the mirror process generating module includes: the runtime acquisition module is used for acquiring the current runtime state of the process; a thread context collection module for collecting thread contexts in the process based on the runtime state; and the file saving module is used for writing each thread and semaphore in the process into a file one by one according to the thread context and saving the thread and the semaphore to obtain the mirror image process.
Optionally, the thread context collecting module includes: the list generation module is used for forming a parameter list from the runtime state and transmitting the parameter list to a kernel; the process creating module is used for creating and calling a process entity according to the parameter list; and the collection module is used for collecting the thread context in the currently called process entity as the thread context in the process.
Optionally, the mirror process restoring module includes: the runtime structure analysis module is used for analyzing the mirror image process to obtain a runtime structure; the process structure creating module is used for creating a process structure according to the runtime structure; and the process entity generating module is used for generating the process entity according to the created process structure.
Optionally, the runtime includes an element corresponding to the current running state of the process.
Optionally, the elements include: stacking; a register; memory layout; and a semaphore.
Optionally, the program execution device further includes: and the registration module is used for registering a callback and error processing mechanism in an application layer and carrying out callback and error processing under the condition of saving errors in the process running.
According to a fourth aspect of the present disclosure, there is also provided a program execution device including: the judging module is used for responding to the starting of a program and judging whether a mirror process corresponding to the program exists or not; the construction module is used for constructing a process entity based on the mirror image process under the condition that the mirror image process corresponding to the program is judged to exist; and/or a mirror process generation module, configured to, when it is determined that there is no mirror process corresponding to the program, load a resource file required by the program using a process, and save the runtime of the process at a time after the process loads at least a part of the resource file required by the program, to obtain the mirror process of the process.
According to a fifth aspect of the present disclosure, there is also provided a computing device comprising: a processor; and a memory having executable code stored thereon, which when executed by the processor, causes the processor to perform a method as set forth in the first or second aspect of the disclosure.
According to a sixth aspect of the present disclosure, there is also provided a non-transitory machine-readable storage medium having stored thereon executable code, which when executed by a processor of an electronic device, causes the processor to perform a method as set forth in the first or second aspect of the present disclosure.
The method and the device have the advantages that the process for preloading the program is snapshot, so that the mirror image process stored on the disk can be directly started when the program is started next time, the initialization part of the resource can be reduced or even skipped, the memory distribution of the process does not need to be reconstructed, and the time for processing the program is reduced when the snapshot process is used during running, so that the aim of quick starting is fulfilled.
Detailed Description
Preferred embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. While the preferred embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be embodied in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the disclosure to those skilled in the art.
[ term interpretation ]
Preloading: and in the program starting process, loading the resources required by the program by using another process.
Resource files: the resources to be loaded in the program starting process may be resources such as a shared library, a data space, a code space, an opened file, and the like used in the program running.
And (3) running: the corresponding elements of the process in the running process can be a general name of private elements such as stacks, registers, memory layout, semaphores and the like. Through these elements, a complete process can be described.
Snapshot: and carrying out one-time run-time saving process on the running process. The runtime is stored on disk in a special format.
And (3) mirroring process: a snapshot of a process saved on disk is referred to as a mirrored process of the process. The mirror process has all the runtimes of the process at a certain time point, and the runtimes can be independently started.
Thread context: there may be multiple threads in a process that are automatically scheduled by the kernel and each thread has its own thread context, including semaphores such as thread ID, stack pointer, program counter, general purpose registers, and condition codes.
[ scheme overview ]
Fig. 2 is a schematic flow chart diagram illustrating a program execution method according to an embodiment of the present disclosure.
Referring to fig. 2, in step S210, during program startup, the runtime of the process is saved at a time after using at least a portion of the resource file required by the process loader to obtain a mirrored process of the process.
The process mentioned here refers to a process for performing a preload operation during program start-up. When the process is saved, the starting speed of the program can be increased by selecting a proper time point. In practical application, an optimal time point can be determined through continuous debugging. Generally, the time after the resource file loading is completed may be selected as the time when the save process is running. That is, the runtime of the process may be saved, preferably at a time after all of the resource files needed by the process loader are used.
The saved runtime includes all elements corresponding to the current running state of the process, for example, elements such as a stack, a register, a memory layout, and a semaphore may be included.
As an example, the runtime of a process may be saved to obtain a mirrored process for the process as follows. Specifically, at a time after using at least a portion of the resource file required by the process loader, the current runtime state of the process may be obtained, and a thread context (thread context) in the process may be collected based on the runtime state. According to the collected thread context, each thread in the process and the semaphore can be written into a file one by one and stored to obtain the mirror process. Wherein the operation of collecting thread context in a process may be performed by the kernel. For example, the runtime state forming parameter list may be passed to the kernel, and the kernel may create and invoke a process entity according to the parameter list, and then collect, by the kernel, a thread context in the currently invoked process entity as a thread context in the process that needs to be collected.
In step S220, in response to the next startup of the program, the mirroring process is restored to obtain a process entity that is consistent with the running state of the process corresponding to the time at the time of saving.
In response to the next startup of the program, it may be determined whether there is an available mirror process, and in the case where it is determined that there is an available mirror process, the mirror process may be restored. In the case that it is determined that there is no available mirror process, the process creation process may be started according to an existing program, and the resource file required by the created process is loaded to implement initialization of the resource. In addition, in the process running process, step S210 may be executed to obtain the mirror process of the process, so that the mirror process may be directly used when the program is started next time, so as to reduce or even avoid the resource initialization operation, thereby increasing the program starting speed.
After all resource files required by the process loading program are used, under the condition of saving the running time of the process, when the program is started next time, the mirror image process saved on the disk is directly started, the initialization part of the resource is skipped, the memory distribution of the process does not need to be reconstructed, and the running time of the snapshot process is used, so that the time for processing the program is reduced, and the purpose of quick starting is achieved.
Therefore, when the program is started next time, the program can be operated by using the previously saved mirror image process, so that the resource initialization operation can be reduced or even avoided, and the starting time of the program is reduced. This overhead reduction is more significant, particularly when the resources are large and the categories are numerous.
So far, the implementation principle of the program operation scheme of the present disclosure is briefly explained. As can be seen from the above description, the program execution scheme of the present disclosure mainly includes a mirror process generation step and a mirror process recovery step. These two steps are further described below.
[ Generation of mirror image Process ]
FIG. 3 shows a schematic flow diagram of a mirror process generation process in accordance with an embodiment of the present disclosure.
Referring to fig. 3, in response to the start of the program, step S310 may be performed first to load a resource file.
In step S320, resources are initialized. The resource initialization mentioned herein mainly refers to the initialization of the resource file loaded in step S310.
The process of loading the resource file (step S310) and initializing the resource (step S320) belongs to the existing program starting process, and is not described herein again.
In step S330, the snapshot library is initialized.
It is mainly to detect whether the current platform supports the solution of the present disclosure. And under the condition of supporting the scheme of the present disclosure, the snapshot library initialization operation is carried out, so as to facilitate the subsequent processing. The snapshot library is similar to the existing initialization process, and is not described here again.
At step S340, a snapshot callback is registered.
A callback and error handling mechanism may be registered in the application layer for performing callback and error handling in case of an error in the runtime of the save process (i.e., step S395). For example, when an error occurs in the process runtime saving, the process runtime is re-acquired by returning to step S350.
In step S350, the process runtime is acquired.
The method mainly comprises the step of obtaining the runtime state of the current process. As shown in FIG. 4, the retrieved runtime may include a process stack structure, process registers, data space mappings, open file structures, process attributed signals, and resource files, among others.
Step S350 may be executed during the process of loading the resource file by the process, or step S350 may be executed after the process finishes loading the resource file. Preferably, step S350 may be executed after the process finishes loading the resource file.
At step S360, runtime parameters are constructed.
Here, the parameter list is mainly constructed according to the runtime acquired in step S350. The constructed parameter list may be saved as a snapshot.
In step S370, the kernel is notified of the processing runtime parameters.
The constructed parameter list may be passed to the kernel. The kernel can restore the obtained parameter list (i.e. snapshot) according to the obtained parameter list to create a corresponding process entity, and can call the created process entity.
In step S380, the kernel builds a thread data linked list.
Here, mainly the kernel collects the thread context in the current process (i.e. the created process entity), and the collected thread context can be regarded as the thread context in the process runtime acquired when step S350 is executed.
In step S390, the kernel is notified to start recording the snapshot.
The kernel can write the threads and semaphores into the file one by one according to the collected thread context to obtain the recorded snapshot file.
In step S395, the run is saved, and the run program is continued.
The recorded snapshot file may be saved on disk to obtain the mirroring process. Wherein if the saving is successful, the program can continue to run. If the save fails, subsequent processing may be performed based on the previously registered callback and error handling mechanisms. For example, the process runtime may be re-acquired by returning to step S350, or the runtime parameters may be reconstructed by returning to step S360.
[ mirror Process recovery ]
FIG. 5 shows an illustrative flow diagram of a mirrored process recovery process in accordance with an embodiment of the disclosure.
Referring to fig. 5, in step S510, in response to the start of the program (which can be regarded as the next start as compared to fig. 3), the mirroring process is opened. Here, a previously saved mirror process consistent with the program started this time may be designated and opened.
In step S520, the kernel is notified to resolve the process runtime in the mirror process.
The runtime structure can be parsed out according to the format of the saved mirror process.
In step S530, the kernel resumes process runtime.
From the parsed runtime structure, a process structure can be created.
In step S540, the kernel notifies the parent process fork to come out of the new process.
A process entity (i.e., a new process) may be fork based on the newly created process structure (i.e., parent process) described above.
In step S550, the new process notifies the kernel to run the resumed runtime.
The new process out of fork is consistent with the running state of the process corresponding to the previously saved mirror process, so that the recovery of the previously saved running (namely, the mirror process) can be realized based on the new process.
In summary, the recovery of the mirror process involves reading data at runtime and recreating a process structure, the whole process needs to ensure the spatial integrity of the newly created process, and the process cannot be started normally in a place with errors. In principle, is the reverse of the mirror process generation process described above. After the mirror image process is recovered, the mirror image process is directly executed from the last snapshot point, so that the initialization stage of resources can be reduced or even skipped, some unnecessary analysis steps are saved, and the starting time is saved. The advantages of the disclosed solution are even more apparent if a program has a large number of resource loading operations.
[ application example ]
Fig. 6 is a schematic flow chart diagram illustrating a program execution method according to an embodiment of the present disclosure.
Referring to fig. 6, in step S610, in response to the start of the program, it may be first determined whether a corresponding mirroring process exists. I.e. to determine whether a mirrored process consistent with the currently started program has been saved before.
If it is determined that there is no mirroring process, step S650 and step S660 may be executed, according to a conventional program starting procedure, loading a resource file that needs to be used in the program starting process, and performing an initialization operation on the resource file. For example, a separate process may be created, and the steps S650 and S660 may be executed by the process to perform the preloading operation during the program start-up.
In step S670, a mirror process of the process may be generated at a time after at least a portion (preferably all) of the resource files required by the process to load the program. The generation process of the mirror process may refer to the above description, and is not described herein again. Then, the program can be normally run.
In the case that it is determined that the mirror process exists, when the loader starts the required resource file in step S620, the resource initialization step may be skipped, and the mirror process may be loaded (step S630) and restored to restore the runtime corresponding to the mirror process (i.e., step S640). Then, the program can be normally run. The step S630 and the step S640 may refer to the recovery process of the mirror process, which is not described herein again.
Therefore, when the program is started, the mirror image process is used, so that the initialization operation of the resource can be reduced or even skipped, and the starting time of the program is reduced. Therefore, the essence of the program running scheme disclosed by the invention is that in the process of starting the program, the mirror image process stored on the disk is directly started, the initialization part of the resource can be reduced or even skipped, the memory distribution of the process does not need to be reconstructed, and the running of the snapshot process is used, so that the time for processing the program is reduced, and the purpose of quick starting is achieved.
Furthermore, the method and the device have the advantages that the single program process snapshot is realized, the overhead is low, and the use is flexible. And a large amount of hardware drive callbacks similar to hibernate do not exist, and special drive support is not needed.
Through actual project tests, when a container is operated by using a mirror process, the starting time is averaged to be 7s, while the average time is 12s under the conventional starting condition, which is improved by about 40%. The main reason is that about 100 pieces of picture information need to be loaded during startup of the container, and decoding needs to be performed on these picture resources, which takes about 45% of the whole startup time. After the scheme is adopted, the content which is decoded is used, and the efficiency can be obviously improved.
In addition, the program can be started quickly by using the scheme, and the program can be started as required, so that the aim of saving the memory is fulfilled. For example, after the program is snapshot, the original program can be directly exited without running, and when the program is needed next time, the mirror process is directly started, and the starting speed is faster than the restarting speed after the simple process kill.
[ PROGRAM OPERATING DEVICE ]
Fig. 7 is a schematic block diagram showing the configuration of a program execution device according to an embodiment of the present invention. Wherein the functional blocks of the program execution device may be implemented by hardware, software, or a combination of hardware and software that implement the principles of the present invention. It will be appreciated by those skilled in the art that the functional blocks described in fig. 7 may be combined or divided into sub-blocks to implement the principles of the invention described above. Thus, the description herein may support any possible combination, or division, or further definition of the functional modules described herein.
In the following, functional modules that the program execution device can have and operations that each functional module can perform are briefly described, and for the details related thereto, reference may be made to the description above in conjunction with fig. 2 to 5, which is not described again here.
Referring to fig. 7, the program execution device 700 may include a mirror process generating module 710 and a mirror process restoring module 720.
The mirror process generating module 710 is configured to save the runtime of the process at a time after at least a portion of the resource file required by the process loader is used in the process of starting the program, so as to obtain a mirror process of the process. The runtime includes elements corresponding to the current running state of the process, and may include, for example, elements such as stacks, registers, memory layout, and semaphores.
By way of example, the mirror process generation module 710 may include a runtime acquisition module 711, a thread context collection module 713, and a file save module 715.
The runtime acquisition module 711 is used to acquire the current runtime state of the process. The thread context collection module 713 is configured to collect thread contexts in a process based on the runtime state. The file saving module 715 is configured to write and save each thread and semaphore in the process into a file one by one according to the thread context, so as to obtain the mirror process.
Optionally, thread context collection module 713 may include a list generation module 7131, a process creation module 7133, and a collection module 7135.
The list generation module 7131 is used to form and pass the runtime state into a parameter list to the kernel. The process creation module 7133 is used to create and invoke process entities from the parameter list. The collection module 7135 is used to collect thread contexts in currently called process entities as thread contexts in the process to be collected.
The mirror process recovery module 720 is configured to recover the mirror process in response to the next startup of the program, so as to obtain a process entity whose running state is consistent with the process corresponding to the time.
By way of example, the mirrored process recovery module 720 can include a runtime fabric parsing module 721, a process fabric creation module 723, and a process entity generation module 725.
The runtime structure parsing module 721 is configured to parse the mirror process to obtain a runtime structure. The process structure creation module 723 is configured to create a process structure based on the runtime structure. The process entity generation module 725 is used to generate process entities from the created process structure.
As shown in fig. 7, the program execution device 700 may optionally include a determination module 730. The determining module 730 is configured to determine whether an available mirror process exists in response to a next startup of the program. In the event that the decision block 730 determines that there is an available mirror process, the mirror process recovery block 720 recovers the mirror process.
As shown in fig. 7, the program execution device 700 may optionally include a registration module 740. The registration module 740 is configured to register a callback and error handling mechanism in the application layer, and is configured to perform callback and error handling when an error occurs during the process saving operation.
Fig. 8 is a schematic block diagram showing the configuration of a program execution device according to an embodiment of the present invention. Wherein the functional blocks of the program execution device may be implemented by hardware, software, or a combination of hardware and software that implement the principles of the present invention. It will be appreciated by those skilled in the art that the functional blocks described in fig. 8 may be combined or divided into sub-blocks to implement the principles of the invention described above. Thus, the description herein may support any possible combination, or division, or further definition of the functional modules described herein.
In the following, functional modules that the program execution device can have and operations that each functional module can perform are briefly described, and for the details related thereto, reference may be made to the description above in conjunction with fig. 6, which is not described herein again.
Referring to fig. 8, the program execution device 800 may include a determination module 810, a construction module 820, and a mirror process generation module 830.
The determining module 810 is configured to determine whether a mirror process corresponding to the program exists in response to the starting of the program.
The building module 820 is configured to build a process entity based on the mirror process in a case where the determining module 810 determines that the mirror process corresponding to the program exists.
And a mirror process generation module, configured to use the resource file required by the process loader when the determination module 810 determines that the mirror process corresponding to the program does not exist, and save the running time of the process at a time after at least a part of the resource file required by the process loader, so as to obtain the mirror process of the process.
[ calculating device ]
Fig. 9 is a schematic structural diagram of a data processing computing device that can be used to implement the program execution method according to an embodiment of the present invention.
Referring to fig. 9, computing device 900 includes memory 910 and processor 920.
The processor 920 may be a multi-core processor or may include multiple processors. In some embodiments, processor 920 may include a general-purpose main processor and one or more special purpose coprocessors such as a Graphics Processor (GPU), Digital Signal Processor (DSP), or the like. In some embodiments, processor 920 may be implemented using custom circuits, such as Application Specific Integrated Circuits (ASICs) or Field Programmable Gate Arrays (FPGAs).
The memory 910 may include various types of storage units, such as system memory, Read Only Memory (ROM), and permanent storage. Wherein the ROM may store static data or instructions for the processor 920 or other modules of the computer. The persistent storage device may be a read-write storage device. The persistent storage may be a non-volatile storage device that does not lose stored instructions and data even after the computer is powered off. In some embodiments, the persistent storage device employs a mass storage device (e.g., magnetic or optical disk, flash memory) as the persistent storage device. In other embodiments, the permanent storage may be a removable storage device (e.g., floppy disk, optical drive). The system memory may be a read-write memory device or a volatile read-write memory device, such as a dynamic random access memory. The system memory may store instructions and data that some or all of the processors require at runtime. In addition, the memory 910 may include any combination of computer-readable storage media, including various types of semiconductor memory chips (DRAM, SRAM, SDRAM, flash memory, programmable read-only memory), magnetic and/or optical disks, may also be employed. In some embodiments, memory 910 may include a removable storage device that is readable and/or writable, such as a Compact Disc (CD), a digital versatile disc read only (e.g., DVD-ROM, dual layer DVD-ROM), a Blu-ray disc read only, an ultra-dense disc, a flash memory card (e.g., SD card, min SD card, Micro-SD card, etc.), a magnetic floppy disk, or the like. Computer-readable storage media do not contain carrier waves or transitory electronic signals transmitted by wireless or wired means.
The memory 910 stores processable code, which, when processed by the processor 920, causes the processor 920 to perform the above-described program execution methods.
The program execution method, apparatus, and computing device according to the present invention have been described in detail above with reference to the accompanying drawings.
Furthermore, the method according to the invention may also be implemented as a computer program or computer program product comprising computer program code instructions for carrying out the above-mentioned steps defined in the above-mentioned method of the invention.
Alternatively, the invention may also be embodied as a non-transitory machine-readable storage medium (or computer-readable storage medium, or machine-readable storage medium) having stored thereon executable code (or a computer program, or computer instruction code) which, when executed by a processor of an electronic device (or computing device, server, etc.), causes the processor to perform the steps of the above-described method according to the invention.
Those of skill would further appreciate that the various illustrative logical blocks, modules, circuits, and algorithm steps described in connection with the disclosure herein may be implemented as electronic hardware, computer software, or combinations of both.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems and methods according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
Having described embodiments of the present invention, the foregoing description is intended to be exemplary, not exhaustive, and not limited to the embodiments disclosed. Many modifications and variations will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The terminology used herein is chosen in order to best explain the principles of the embodiments, the practical application, or improvements made to the technology in the marketplace, or to enable others of ordinary skill in the art to understand the embodiments disclosed herein.