[go: up one dir, main page]

CN100383739C - Startup Optimization Method for Embedded Operating System Image Startup - Google Patents

Startup Optimization Method for Embedded Operating System Image Startup Download PDF

Info

Publication number
CN100383739C
CN100383739C CNB2006100498559A CN200610049855A CN100383739C CN 100383739 C CN100383739 C CN 100383739C CN B2006100498559 A CNB2006100498559 A CN B2006100498559A CN 200610049855 A CN200610049855 A CN 200610049855A CN 100383739 C CN100383739 C CN 100383739C
Authority
CN
China
Prior art keywords
operating system
image
kernel
startup
memory
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Expired - Fee Related
Application number
CNB2006100498559A
Other languages
Chinese (zh)
Other versions
CN1818869A (en
Inventor
陈天洲
黄江伟
梁晓
钱杰
吴心亮
郑臻伟
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Zhejiang University ZJU
Original Assignee
Zhejiang University ZJU
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Zhejiang University ZJU filed Critical Zhejiang University ZJU
Priority to CNB2006100498559A priority Critical patent/CN100383739C/en
Publication of CN1818869A publication Critical patent/CN1818869A/en
Application granted granted Critical
Publication of CN100383739C publication Critical patent/CN100383739C/en
Expired - Fee Related legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Stored Programmes (AREA)

Abstract

本发明公开了一种嵌入式操作系统镜像启动的启动优化方法。本发明采用的方法是在操作系统启动时,引导程序直接从存储器上将原先保存的系统最小任务镜像读入内存,并根据系统读入的信息设置各种结构的属性和系统寄存器内存的信息,将系统迅速恢复到工作状态,达到快速启动的方法。本发明提出了一种操作系统镜像启动的启动优化方法,对原来操作系统启动过程进行了改进,使得系统在启动过程中更加快捷,能够非常快的达到系统的工作状态。

Figure 200610049855

The invention discloses a startup optimization method for mirror startup of an embedded operating system. The method that the present invention adopts is that when the operating system is started, the boot program directly reads the original saved system minimum task image into the memory from the memory, and sets the attributes of various structures and the information of the system register memory according to the information read in by the system. Quickly restore the system to the working state to achieve a quick start method. The invention proposes a start-up optimization method for operating system image start-up, which improves the original start-up process of the operating system, making the system start-up faster and reaching the working state of the system very quickly.

Figure 200610049855

Description

嵌入式操作系统镜像启动的启动优化方法 Startup Optimization Method for Embedded Operating System Image Startup

技术领域 technical field

本发明涉及基于嵌入式操作系统启动领域,特别是涉及一种嵌入式操作系统镜像启动的启动优化方法。The invention relates to the field of startup based on an embedded operating system, in particular to a startup optimization method for mirror startup of an embedded operating system.

背景技术 Background technique

手机等嵌入式系统由于考虑到人的忍耐度,所以在启动的时候不能花较长的时间。为了使用上的方便,要尽量缩短手机操作系统的引导和启动时间,虽然内核经过很大程度的裁减,并且各种功能模块都尽量做了优化,但是由于硬件条件的限制,如果不对引导和启动作特殊的设计,还是会造成启动时间过长。Embedded systems such as mobile phones cannot take a long time to start because of human tolerance. For the convenience of use, the boot and startup time of the mobile phone operating system should be shortened as much as possible. Although the kernel has been greatly reduced and various functional modules have been optimized as much as possible, due to hardware constraints, if the boot and startup For special design, it will still cause the startup time to be too long.

现在主要采用两种技术来缩短这个时间。一,固化各种不可扩展硬件的设置,尽量标准化可扩展设备的接口,节约设备检测时间。二,延时装载技术,既LazyLoading,这种技术不加载当前非必需的模块,这些模块可以在启动后待机时间内加载,或者在具体用到之后再加载,把启动时间打散,从而缩短对用户来说至关重要的反应时间。Now mainly adopt two kinds of techniques to shorten this time. First, solidify the settings of various non-extensible hardware, try to standardize the interface of extensible equipment, and save equipment detection time. 2. Delayed loading technology, LazyLoading, this technology does not load modules that are not currently required. These modules can be loaded during the standby time after startup, or after they are specifically used, to break up the startup time, thereby shortening the time spent on the module. Reaction time is critical for users.

对第一种技术来说,目前以及在将来较短一段时间内最主要的还是固化不可扩展硬件的设置,因为首先现在手机的可扩展设备还很少,其次硬件条件限制较多,所以把一些固定的设置固化在操作系统内部应该是比较理想的措施。而考虑到将来的发展趋势,手机将可以连接越来越多的外设,而且这些外设都必须是即插即用的,所以不可能固化它们的设置。但是如果给所有的手机外设制定一套标准接口,则启动时最多只需加载一个标准的公用接口模块即可,大大节省了启动时间,并节约了存储空间。For the first technology, at present and in a short period of time in the future, the most important thing is to solidify the settings of non-extensible hardware, because first of all, there are few scalable devices for mobile phones, and secondly, there are many hardware conditions, so some It should be an ideal measure to fix the fixed settings inside the operating system. And considering the future development trend, the mobile phone will be able to connect more and more peripherals, and these peripherals must be plug and play, so it is impossible to fix their settings. However, if a set of standard interfaces is established for all mobile phone peripherals, at most one standard public interface module only needs to be loaded during startup, which greatly saves startup time and storage space.

对于第二种技术来说,由于操作系统将在很多地方采用“组件化”的技术,故而非常方便Lazy Loading。并且为了进一步缩短反应时间,将“动态设置”必需模块,根据对用户的使用习惯等条件的统计,把一些用户在开机后不会立即使用的模块设置为非必须模块,而把用户经常在开机后就使用的功能设置为必须模块,这样对用户来说反应时间就得到了很大的改善。For the second technology, since the operating system will adopt "componentized" technology in many places, it is very convenient for Lazy Loading. And in order to further shorten the response time, "dynamically set" the necessary modules, according to the statistics of users' usage habits and other conditions, set some modules that users will not use immediately after starting up as non-essential modules, and set users who often The functions that will be used later are set as mandatory modules, so that the reaction time for the user is greatly improved.

发明内容 Contents of the invention

本发明的目的在于提供一种嵌入式操作系统镜像启动的启动优化方法。The purpose of the present invention is to provide a startup optimization method for embedded operating system image startup.

本发明解决其技术问题采用的技术方案如下:The technical scheme that the present invention solves its technical problem adopts is as follows:

1)操作系统镜像准备:1) Operating system image preparation:

操作系统的引导程序在启动的过程中,首先将自己从外存上拷贝到内存空间,然后到指定的外存位置查找操作系统内核镜像,如果操作系统内核镜像存在,那么将操作系统内核镜像从指定的外存位置载入内核,并进行解压缩,在启动过程中,操作系统要判断是否存在快速启动的操作系统镜像,如果不存在则正常启动,如果存在则快速启动,引导程序如果发现只存在原始的操作系统镜像,操作系统将按正常程序启动;During the startup process, the boot program of the operating system first copies itself from the external storage to the memory space, and then searches for the operating system kernel image at the specified external storage location. If the operating system kernel image exists, then copy the operating system kernel image from the The specified external memory location is loaded into the kernel and decompressed. During the startup process, the operating system needs to judge whether there is a fast-boot operating system image. If it does not exist, it will start normally. If it exists, it will start quickly. There is an original operating system image, and the operating system will start according to the normal procedure;

当操作系统启动到最简洁的基本工作状态后,操作系统将启动操作系统休眠进程,这个进程的主要工作是为保存操作系统镜像做各种准备工作;When the operating system starts to the simplest basic working state, the operating system will start the operating system hibernation process. The main job of this process is to make various preparations for saving the operating system image;

2)保存操作系统镜像:2) Save the operating system image:

这部分主要完成操作系统现场的保存工作,首先将建立一个虚拟终端,用来模拟内核与用户态进程的通讯,然后开始结束除内核态进程,僵死进程,当前进程之外所有的进程,此后调用函数来释放尽可能多的内存空间,以减少操作系统镜像的大小,然后对一些驱动进行处理,对在电源管理系统中注册的所有外设,发送挂起命令,然后插入内存屏障,开始保存处理器上下文,最后将操作系统镜像到外部指定的设备上,最后将操作系统休眠;This part mainly completes the on-site preservation of the operating system. First, a virtual terminal will be established to simulate the communication between the kernel and the user mode process, and then start to end all processes except the kernel mode process, the dead process, and the current process, and then call Function to release as much memory space as possible to reduce the size of the operating system image, then process some drivers, send a suspend command to all peripherals registered in the power management system, then insert a memory barrier, and start saving processing server context, and finally mirror the operating system to an external specified device, and finally sleep the operating system;

3)操作系统镜像的装载:3) Loading of operating system image:

操作系统的引导程序在启动的过程中,首先将自己从外存上拷贝到内存空间,然后到指定的外存位置查找操作系统内核镜像,如果操作系统内核镜像存在,那么将操作系统内核镜像从指定的外存位置载入内核,并进行解压缩,在启动过程中,引导程序如果发现存在快速启动的操作系统镜像,操作系统将这个镜像载入内存,并进行解压缩;During the startup process, the boot program of the operating system first copies itself from the external storage to the memory space, and then searches for the operating system kernel image at the specified external storage location. If the operating system kernel image exists, then copy the operating system kernel image from the The specified external storage location is loaded into the kernel and decompressed. During the startup process, if the boot program finds that there is a fast-boot operating system image, the operating system loads the image into the memory and decompresses it;

操作系统先创立一个虚拟终端,用来显示装载镜像过程中的系统信息,首先检查操作系统镜像的正确性,如果正确,则将操作系统镜像载入,循环获取所有保存的页面,并恢复内存内容,通过插入的内存屏障恢复处理器寄存器的值,最后释放恢复过程中申请的内存空间,并通过向电源管理模块中注册的设备发送系统恢复通知,完成整个操作系统镜像的装载。The operating system first creates a virtual terminal to display system information during the process of loading the image, first checks the correctness of the operating system image, and if it is correct, loads the operating system image, loops to obtain all saved pages, and restores the memory content , restore the value of the processor register through the inserted memory barrier, and finally release the memory space requested during the restoration process, and complete the loading of the entire operating system image by sending a system restoration notification to the device registered in the power management module.

本发明与背景技术相比,具有的有益的效果是:Compared with the background technology, the present invention has the beneficial effects that:

1、无延时:上面这种方法,只能为用户造成一种假相,系统看上去可以用,已经起来,实际上在用的时候还得加载必须得模块。而嵌入式操作系统镜像启动的启动优化方法,是真实的为应用提供了一个完整的系统,直接通过设置系统的应用环境,不需要延时加载,以及在用的时候在加载必要的模块,节约了时间和能量;1. No delay: The above method can only create a false appearance for the user. The system seems to be usable and has already started up. In fact, the necessary modules must be loaded when it is used. The startup optimization method of embedded operating system image startup is to provide a complete system for the application, directly by setting the application environment of the system, without delay loading, and loading the necessary modules when in use, saving time and energy;

2、快捷性:嵌入式操作系统镜像启动的启动优化方法采用的是直接设置系统环境的启动方法,这个方法更加快捷;2. Quickness: The startup optimization method of embedded operating system image startup adopts the startup method of directly setting the system environment, which is faster;

3、通用性:可以自动设置启动镜像,不需要针对不同的应用平台进行不同的设置,更换平台不需要更换镜像,只要重新启动系统,然后让系统自动根据系统情况设置一个镜像,就可以。3. Versatility: The startup image can be set automatically, and there is no need to make different settings for different application platforms. It is not necessary to change the image when changing the platform, just restart the system, and then let the system automatically set an image according to the system situation.

附图说明 Description of drawings

附图为整个系统的流程图。Accompanying drawing is the flowchart of whole system.

具体实施方式 Detailed ways

在实施基于嵌入式操作系统启动优化方法时,镜像启动技术被广泛利用。When implementing boot optimization methods based on embedded operating systems, mirror boot technology is widely used.

嵌入式操作系统镜像启动的启动优化方法具体实现流程如下。The specific implementation process of the startup optimization method for mirror startup of the embedded operating system is as follows.

一、系统镜像准备1. System image preparation

系统镜像准备过程主要分为以下几部分:The system image preparation process is mainly divided into the following parts:

1、操作系统引导1. Operating system boot

操作系统的引导程序在启动的过程中,首先将自己从外存上拷贝到内存空间,然后到指定的外存位置查找系统镜像,如果系统镜像存在,那么将操作系统内核镜像从系统的外存上载入内核,由于系统内核镜像比较大,一般情况下都是被压缩后保存到外存的,所以要进行解压缩;During the boot process of the operating system, the boot program first copies itself from the external storage to the internal memory space, and then searches for the system image at the specified external storage location. If the system image exists, the operating system kernel image is copied from the external storage of the system. Upload and load the kernel. Since the system kernel image is relatively large, it is usually compressed and saved to the external memory, so it needs to be decompressed;

以Sistang嵌入式实验平台上的ARM-Linux操作系统为例,他的操作系统引导过程可见下面。Taking the ARM-Linux operating system on the Sistang embedded experimental platform as an example, its operating system boot process can be seen below.

在内核运行之前需要系统引导程序完成加载内核和一些辅助性的工作,然后跳转到内核代码的起始地址并执行。Before the kernel runs, the system bootloader needs to complete the loading of the kernel and some auxiliary work, and then jump to the starting address of the kernel code and execute it.

首先,启动后Sitsang板子将地址0x0c00 0000映射到0(可通过跳线设置),实际上从0x0c00 0000启动,进入的bootloader,但由于flash速度慢,所以bootloader前面有一小段程序把bootloader拷贝到SDRAM中的0x0AFE0100,再从0x 0800 0000运行bootloader,叫这段小程序为flashloader,flashloader必须要首先初始化SDRAM。flashloader把bootloader load到0x0AFE0100,然回跳了过去,其实0x0AFE0100就是烧在flash 0x0C000100中的真正的bootloader。First of all, after booting, the Sitsang board maps the address 0x0c00 0000 to 0 (can be set by jumpers), actually boots from 0x0c00 0000, and enters the bootloader, but because the flash speed is slow, there is a small program in front of the bootloader to copy the bootloader to SDRAM 0x0AFE0100, and then run the bootloader from 0x 0800 0000, call this small program flashloader, flashloader must first initialize SDRAM. The flashloader loads the bootloader to 0x0AFE0100, and then jumps back. In fact, 0x0AFE0100 is the real bootloader burned in the flash 0x0C000100.

BootLoader将操作系统代码调入内存,然后将控制权交给arch/arm/boot中的Setup.S这段程序。Setup.S这段程序在实模式下对系统进行基本的检测和设置后转入保护模式把控制权交给head_armv.S。一个步骤是系统内核的解压过程,这部分代码在地址0x1000(文件/Boot/head.S),该段程序初始化寄存器,然后执行decompress_kernel(),这个函数源于zBoot/inflate.c、zBoot/unzip.c和zBoot/misc.c三个文件。解压后数据放在地址0x100000。Head.S建立内存管理和中断管理的框架。BootLoader transfers the operating system code into the memory, and then hands over control to the Setup.S program in arch/arm/boot. This program of Setup.S performs basic detection and settings on the system in real mode, then transfers to protection mode and hands over the control right to head_armv.S. One step is the decompression process of the system kernel. This part of the code is at address 0x1000 (file/Boot/head.S). This program initializes the registers and then executes decompress_kernel(). This function originates from zBoot/inflate.c, zBoot/unzip .c and zBoot/misc.c three files. After decompression, the data is placed at address 0x100000. Head.S establishes the framework of memory management and interrupt management.

2、操作系统启动2. Start the operating system

1)、判断是否存在快速启动镜像1), determine whether there is a quick boot image

在内核镜像解压缩后,系统要判断是否存在快速启动镜像,如过不存在则正常启动,如果存在则快速启动。After the kernel image is decompressed, the system needs to judge whether there is a fast boot image, if it does not exist, it will start normally, if it exists, it will start quickly.

2)、正常启动2), normal startup

在启动过程中,引导程序如果发现只存在原始的操作系统镜像,系统将按正常程序启动,首先系统将按顺序初始化各种部件,首先初始化体系结构,然后初始化中断向量表、调度器、内存等等,最后启动系统的各种服务。During the boot process, if the boot program finds that there is only the original operating system image, the system will start according to the normal program. First, the system will initialize various components in order, first initialize the architecture, and then initialize the interrupt vector table, scheduler, memory, etc. Wait, and finally start various services of the system.

以ARM-Linux为例,这个启动过程主要从Start_kernel开始直到创建init进程。Init进程调用lock_kernel之后,在调用prepare_namespace加载rootfs之前,调用do_basic_setup函数,进行一些基础的设置,如pci,sbus,ecard等,do_basic_setup然后调用start_context_thread()和do_initcalls(),加载一些设备的驱动程序,之后,进入software_resume()这个新添加的函数,准备检查交换分区,进行系统的恢复。Taking ARM-Linux as an example, the startup process mainly starts from Start_kernel until the init process is created. After the Init process calls lock_kernel, before calling prepare_namespace to load rootfs, call the do_basic_setup function to perform some basic settings, such as pci, sbus, ecard, etc., do_basic_setup then calls start_context_thread() and do_initcalls() to load some device drivers, and then , enter the newly added function software_resume(), and prepare to check the swap partition and restore the system.

software_resume函数进行一些必要的条件检测之后,调用read_suspend_image函数,来读取之前保存的镜像,如果镜像不存在读取失败,software_resume函数会调用kernel_thread(swsusp_mainloop,NULL,CLONE_FS|CLONE_FILES|CLONE_SIGHAND|SIGCHLD)来创建一个内核态的进程,swsusp_mainloop()函数调用daemonize()来释放对用户空间的引用使自己成为一个后台的守护进程,并重命名自己为kswsuspd,之后便陷入了无限的循环,并且每隔一秒检测一下swsusp_state[0]的值是否出现变化(若此值从0变成1,则会跳出循环,调用休眠的函数)。至此,software_resume函数返回,继续do_basic_setup以及init(),直至系统正常启动。After the software_resume function checks some necessary conditions, it calls the read_suspend_image function to read the previously saved image. If the image does not exist and fails to read, the software_resume function calls kernel_thread(swsusp_mainloop, NULL, CLONE_FS|CLONE_FILES|CLONE_SIGHAND|SIGCHLD) to create A kernel mode process, the swsusp_mainloop() function calls daemonize() to release the reference to the user space to make itself a background daemon process, and rename itself to kswsuspd, and then falls into an infinite loop, and detects every second Check whether the value of swsusp_state[0] changes (if the value changes from 0 to 1, it will jump out of the loop and call the sleep function). At this point, the software_resume function returns, continue do_basic_setup and init(), until the system starts normally.

3)、镜像启动3), mirror start

如果引导程序发现存在操作系统的镜像,引导程序将这个镜像载入内存,并进行解压缩;系统先创立一个虚拟终端,用来显示装载镜像过程中的系统信息,首先检查镜像的正确性,然后按照顺序将镜像中的内存页面恢复到内存,最后将处理器的上下文恢复。这部分工作的具体举例说明将放到后面。If the boot program finds that there is an image of the operating system, the boot program loads the image into memory and decompresses it; the system first creates a virtual terminal to display system information during the process of loading the image, first checks the correctness of the image, and then The memory pages in the image are restored to the memory in order, and finally the context of the processor is restored. The specific examples of this part of the work will be put later.

3、镜像工作环境的建立3. Establishment of a mirror working environment

当系统启动到最简洁的基本工作状态后,操作系统将启动系统休眠过进程,这个进程的主要工作是为保存系统镜像做各种准备工作;When the system starts to the simplest basic working state, the operating system will start the system hibernation process. The main job of this process is to make various preparations for saving the system image;

以Linux操作系统能够的镜像启动为例,这部分工作主要包括:Taking the image startup of the Linux operating system as an example, this part of the work mainly includes:

1)向内核的数据段里面添加一段:_nosave,以便于把一些变量放到其中。这样一来,在使用这些变量的时候,就不会涉及到堆栈。1) Add a section to the data segment of the kernel: _nosave, so as to put some variables in it. In this way, when using these variables, the stack will not be involved.

2)定义保存/恢复镜像的设备static char resume_file[256]=″/dev/modify″,此设备的主设备号是241,次设备号是2,同时需要在init/do_mounts.c中的root_dev_names[]中添加一项:{″modify″,0xf102},此后通过name_to_kdev_t函数,指定参数”/dev/modify”就可以获得该设备的设备号0xf102,再通过宏MAJOR()和MINOR()就可分别获得该设备的主设备号241和从设备号2。2) Define the device static char resume_file[256]="/dev/modify" for saving/restoring the mirror image, the major device number of this device is 241, the minor device number is 2, and root_dev_names[ in init/do_mounts.c is required at the same time ], add an item: {"modify", 0xf102}, after that, through the name_to_kdev_t function, specify the parameter "/dev/modify" to get the device number 0xf102 of the device, and then use the macro MAJOR() and MINOR() to respectively Get the device's major device number 241 and slave device number 2.

3)定义状态量:int swsusp_state[3]用来管理进行休眠和镜像过程中的一些参数信息。3) Define the state quantity: int swsusp_state[3] is used to manage some parameter information in the process of dormancy and mirroring.

二、保存系统镜像2. Save the system image

这部分主要完成系统现场的保存工作,首先将将建立一个虚拟终端,用来模拟通讯;然后开始结束除内核态进程,僵死进程,当前进程之外所有的进程,此后调用函数来释放尽可能多的内存空间,以减少内存镜像的大小,然后对一些驱动进行处理,对在电源管理系统中注册的所有外设,发送挂起命令,然后插入系统屏障,阻断系统执行,开始保存处理器上下文,最后将内存镜像到外部制定的设备上,最后将操作系统休眠。This part mainly completes the preservation work of the system site. First, a virtual terminal will be established to simulate communication; memory space to reduce the size of the memory image, and then process some drivers, send a suspend command to all peripherals registered in the power management system, and then insert a system barrier, block system execution, and start saving the processor context , and finally mirror the memory to an externally specified device, and finally sleep the operating system.

以ARM-Linux为例,整个过程如下所示:Taking ARM-Linux as an example, the whole process is as follows:

1)、系统要建立镜像将必须调用一个叫做software_suspend函数。software_suspend()调用了do_software_suspend函数,真正开始了系统的休眠和镜像的建立。1), the system must call a function called software_suspend to create a mirror image. software_suspend() calls the do_software_suspend function, which really starts the system's hibernation and image creation.

2)、software_suspend()调用了do_software_suspend函数,首先建立一个虚拟的终端,然后开始调用freeze_processes函数来结束除内核态进程,僵死进程,当前进程之外所有的进程,此后调用free_some_memory函数来释放尽可能多的内存空间,以减少内存镜像的大小。然后对一些驱动进行处理,调用了pm_send_all(PM_SUSPEND,(void*)3)向在电源管理PM模块中注册了的设备发送系统挂起suspend的通知。2), software_suspend() calls the do_software_suspend function, first creates a virtual terminal, and then starts calling the freeze_processes function to end all processes except the kernel mode process, the zombie process, and the current process, and then calls the free_some_memory function to release as much as possible memory space to reduce the size of the memory image. Then, some drivers are processed, and pm_send_all(PM_SUSPEND, (void*)3) is called to send a system suspend notification to the device registered in the power management PM module.

3)、最后do_software_suspend函数调用do_suspend_lowlevel函数。do_suspend_lowlevel依次调用do_magic_suspend_1(),save_processor_context()和do_magic_suspend_2()三个函数do_magic_suspend_1()调用mb()和barrier()来为接下来的save_processor_context函数做准备。Void Barrier(void)通知编译器插入一个内存屏障,但对硬件无效,编译后的代码会把当前CPU寄存器中的所有修改过的数值存入内存,需要这些数据的时候再重新从内存中读出。3). Finally, the do_software_suspend function calls the do_suspend_lowlevel function. do_suspend_lowlevel calls do_magic_suspend_1(), save_processor_context() and do_magic_suspend_2() three functions in turn. do_magic_suspend_1() calls mb() and barrier() to prepare for the next save_processor_context function. Void Barrier (void) informs the compiler to insert a memory barrier, but it is invalid for the hardware. The compiled code will store all the modified values in the current CPU registers into the memory, and then read them out from the memory again when the data is needed. .

4)、save_processor_context函数保存当前状态下的CPU的运行上下文。用来保存这些值的一个struct具有_attribute_((packed))的属性,可将其成员变量紧凑排列。4). The save_processor_context function saves the running context of the CPU in the current state. A struct used to hold these values has the attribute _attribute_((packed)), which can compactly arrange its member variables.

5)、之后进入do_magic_suspend_2函数。此函数负责把内存页面保存到swap分区中。此函数首先调用read_swapfiles从可能的32个交换设备(包括文件和分区)中找到在前文中指定的分区:/dev/modify。然后调用save_suspend_image来完成全部的复制操作之后,调用suspend_power_down,关闭或者重新启动计算机。5), then enter the do_magic_suspend_2 function. This function is responsible for saving the memory page to the swap partition. This function first calls read_swapfiles to find the partition specified in the previous article from the possible 32 swap devices (including files and partitions): /dev/modify. Then call save_suspend_image to complete all copy operations, call suspend_power_down, shut down or restart the computer.

三、操作系统镜像的装载Third, the loading of the operating system image

操作系统的引导程序在启动的过程中,将操作系统内核镜像从系统的外存上载入内核,并进行解压缩,在启动过程中,引导程序如果发现存在操作系统启动优化镜像,系统将这个镜像载入内存,并进行解压缩;During the startup process, the boot program of the operating system loads the kernel image of the operating system from the external memory of the system into the kernel and decompresses it. The image is loaded into memory and decompressed;

系统先创立一个虚拟终端,用来显示装载镜像过程中的系统信息,首先检查镜像的正确性,然后按照顺序将镜像中的内存页面恢复到内存,最后将处理器的上下文恢复;The system first creates a virtual terminal to display system information during the process of loading the image, first checks the correctness of the image, then restores the memory pages in the image to the memory in order, and finally restores the context of the processor;

以ARM-Linux为例,整个过程如下所示:Taking ARM-Linux as an example, the whole process is as follows:

1)、开机后,BootLoader装载linux kernel并解压缩,然后start_kernel直到创建init进程。Init进程调用lock_kernel之后,在调用prepare_namespace加载rootfs之前,调用do_basic_setup函数,进行一些基础的设置,如pci,sbus,ecard等,do_basic_setup然后调用start_context_thread()和do_initcalls(),加载一些设备的驱动程序,之后,进入自己的software_resume()函数,准备检查交换分区,进行系统的恢复。1) After booting, BootLoader loads the linux kernel and decompresses it, then start_kernel until the init process is created. After the Init process calls lock_kernel, before calling prepare_namespace to load rootfs, call the do_basic_setup function to perform some basic settings, such as pci, sbus, ecard, etc., do_basic_setup then calls start_context_thread() and do_initcalls() to load some device drivers, and then , enter your own software_resume() function, ready to check the swap partition and restore the system.

2)、software_resume函数进行一些必要的条件检测之后,调用read_suspend_image函数,来读取之前保存的镜像,read_suspend_image调用更底层的_read_suspend_image来完成主动的镜像读取工作。2) After the software_resume function checks some necessary conditions, it calls the read_suspend_image function to read the previously saved image, and read_suspend_image calls the lower-level _read_suspend_image to complete the active image reading work.

3)、_read_suspend_image调用prepare_suspend_console来创建一个虚拟的控制台,用来显示恢复中的一些相关信息。之后调用bdev_read_page来从/dev/modify设备里面获取一页,得到镜像的头部信息,并调用sanity_check函数来检测镜像的头部信息是否正确,以确定现在的系统是否是休眠前的系统,如果不是则按照正常系统启动。3), _read_suspend_image calls prepare_suspend_console to create a virtual console to display some relevant information during recovery. Then call bdev_read_page to get a page from the /dev/modify device, get the header information of the image, and call the sanity_check function to check whether the header information of the image is correct, to determine whether the current system is the system before hibernation, if not Then start according to the normal system.

4)、接下来通过循环调用bdev_read_page来获得pagedir和所有的保存的内存的页面(读取内存页面的顺序与保存内存页面时的顺序正好相反)。并回复内存内容,然后read_suspend_image函数返回。接下来调用do_suspend_lowlevel来进一步地恢复系统。4) Next, pagedir and all saved memory pages are obtained by calling bdev_read_page cyclically (the order of reading memory pages is just opposite to the order of saving memory pages). And restore the memory content, and then the read_suspend_image function returns. Next call do_suspend_lowlevel to further restore the system.

5)、do_suspend_lowlevel通过对CPU寄存器Cr3的设置,把swapper_pg_dir的物理地址做为更改为页目录的物理地址。并且通过对ecx的设置,创建了新的堆栈指针。CR3用于保存页目录表的起始物理地址。由于目录是页对齐的,所以仅高20位有效,低12位保留未用。向CR3中装入一个新值时,低12位必须为0;但从CR3中取值时,低12位被忽略。每当用MOV指令重置CR3的值时,会导致分页机制高速缓冲区的内容无效,用此方法,可以在启用分页机制之前,即把PG位置1之前,预先刷新分页机制的高速缓存。CR3寄存器即使在CR0寄存器的PG位或PE位为0时也可装入,如在实模式下也可设置CR3,以便进行分页机制的初始化。在任务切换时,CR3要被改变,但是如果新任务中CR3的值与原任务中CR3的值相同,那么处理器不刷新分页高速缓存,以便当任务共享也表时有较快的执行速度。5), do_suspend_lowlevel changes the physical address of swapper_pg_dir to the physical address of the page directory by setting the CPU register Cr3. And by setting ecx, a new stack pointer is created. CR3 is used to save the starting physical address of the page directory table. Since the directory is page-aligned, only the upper 20 bits are valid, and the lower 12 bits are reserved for unused. When loading a new value into CR3, the lower 12 bits must be 0; but when fetching a value from CR3, the lower 12 bits are ignored. Whenever the value of CR3 is reset with the MOV instruction, the content of the paging mechanism high-speed buffer will be invalid. In this way, the high-speed cache of the paging mechanism can be pre-refreshed before the paging mechanism is enabled, that is, before the PG bit is set to 1. The CR3 register can be loaded even when the PG bit or the PE bit of the CR0 register is 0. For example, CR3 can also be set in the real mode to initialize the paging mechanism. When the task is switched, CR3 will be changed, but if the value of CR3 in the new task is the same as the value of CR3 in the original task, then the processor will not refresh the paging cache, so as to have a faster execution speed when the task shares the same table.

6)、do_suspend_lowlevel接下来依次调用do_magic_resume_1()restore_processor_context和do_magic_resume_2()来完成所有的恢复工作。6), do_suspend_lowlevel then calls do_magic_resume_1() restore_processor_context and do_magic_resume_2() in turn to complete all recovery work.

7)、do_magic_resume_1()调用了mb();barrier();来为接下来的restore_processor_context函数做准备。Void Barrier(void)通知编译器插入一个内存屏障,但对硬件无效,编译后的代码会把当前CPU寄存器中的所有修改过的数值存入内存,需要这些数据的时候再重新从内存中读出。此后,do_suspend_lowlevel开始以sizeof(char)为单位进行内存页面的复制。之所以这里不能使用copy_page这样的函数,是因为在内存页面复制的时候,会破坏堆栈(stack),在完全恢复CPU寄存器的值之前,不能再使用堆栈以及局部变量,但是可以使用位于内核代码段的_nosave区的变量。之后,restore_processor_context()函数开始恢复CPU寄存器的值。最后进入do_magic_resume_2()。7), do_magic_resume_1() calls mb(); barrier(); to prepare for the next restore_processor_context function. Void Barrier (void) informs the compiler to insert a memory barrier, but it is invalid for the hardware. The compiled code will store all the modified values in the current CPU registers into the memory, and then read them out from the memory again when the data is needed. . After that, do_suspend_lowlevel starts copying memory pages in units of sizeof(char). The reason why functions such as copy_page cannot be used here is that when the memory page is copied, the stack (stack) will be destroyed. Before the value of the CPU register is completely restored, the stack and local variables can no longer be used, but it can be used in the kernel code segment Variables in the _nosave area. After that, the restore_processor_context() function starts to restore the values of the CPU registers. Finally enter do_magic_resume_2().

8)、do_magic_resume_2()主要处理一些清扫现场的工作。它释放掉在休眠时分配的pagedir,以保证内存完全恢复到休眠前的状态然后通过调用pm_send_all(PM_RESUME,(void*)0)向在电源管理PM模块中注册了的设备发送系统恢复resume的通知。至此,所有的工作都完成了。系统已经恢复到休眠之前的状态。8), do_magic_resume_2 () mainly deals with some work of cleaning the scene. It releases the pagedir allocated during hibernation to ensure that the memory is completely restored to the state before hibernation, and then sends a system resume notification to the device registered in the power management PM module by calling pm_send_all(PM_RESUME, (void*)0) . At this point, all the work is done. The system has returned to the state it was in before hibernation.

整个系统的流程图如附图所示。The flowchart of the whole system is shown in the accompanying drawing.

Claims (1)

1.一种嵌入式操作系统镜像启动的启动优化方法,其特征在于:1. a startup optimization method for embedded operating system image startup, characterized in that: 1)操作系统镜像准备:1) Operating system image preparation: 操作系统的引导程序在启动的过程中,首先将自己从外存上拷贝到内存空间,然后到指定的外存位置查找操作系统内核镜像,如果操作系统内核镜像存在,那么将操作系统内核镜像从指定的外存位置载入内核,并进行解压缩,在启动过程中,操作系统要判断是否存在快速启动的操作系统镜像,如果不存在则正常启动,如果存在则快速启动,引导程序如果发现只存在原始的操作系统镜像,操作系统将按正常程序启动;During the startup process, the boot program of the operating system first copies itself from the external storage to the memory space, and then searches for the operating system kernel image at the specified external storage location. If the operating system kernel image exists, then copy the operating system kernel image from the The specified external memory location is loaded into the kernel and decompressed. During the startup process, the operating system needs to judge whether there is a fast-boot operating system image. If it does not exist, it will start normally. If it exists, it will start quickly. There is an original operating system image, and the operating system will start according to the normal procedure; 当操作系统启动到最简洁的基本工作状态后,操作系统将启动操作系统休眠进程,这个进程的主要工作是为保存操作系统镜像做各种准备工作;When the operating system starts to the simplest basic working state, the operating system will start the operating system hibernation process. The main job of this process is to make various preparations for saving the operating system image; 2)保存操作系统镜像:2) Save the operating system image: 这部分主要完成操作系统现场的保存工作,首先将建立一个虚拟终端,用来模拟内核与用户态进程的通讯,然后开始结束除内核态进程,僵死进程,当前进程之外所有的进程,此后调用函数来释放尽可能多的内存空间,以减少操作系统镜像的大小,然后对一些驱动进行处理,对在电源管理系统中注册的所有外设,发送挂起命令,然后插入内存屏障,开始保存处理器上下文,最后将操作系统镜像到外部指定的设备上,最后将操作系统休眠;This part mainly completes the on-site preservation of the operating system. First, a virtual terminal will be established to simulate the communication between the kernel and the user mode process, and then start to end all processes except the kernel mode process, the dead process, and the current process, and then call Function to release as much memory space as possible to reduce the size of the operating system image, then process some drivers, send a suspend command to all peripherals registered in the power management system, then insert a memory barrier, and start saving processing server context, and finally mirror the operating system to an external specified device, and finally sleep the operating system; 3)操作系统镜像的装载:3) Loading of operating system image: 操作系统的引导程序在启动的过程中,首先将自己从外存上拷贝到内存空间,然后到指定的外存位置查找操作系统内核镜像,如果操作系统内核镜像存在,那么将操作系统内核镜像从指定的外存位置载入内核,并进行解压缩,在启动过程中,引导程序如果发现存在快速启动的操作系统镜像,操作系统将这个镜像载入内存,并进行解压缩;During the startup process, the boot program of the operating system first copies itself from the external storage to the memory space, and then searches for the operating system kernel image at the specified external storage location. If the operating system kernel image exists, then copy the operating system kernel image from the The specified external storage location is loaded into the kernel and decompressed. During the startup process, if the boot program finds that there is a fast-boot operating system image, the operating system loads the image into the memory and decompresses it; 操作系统先创立一个虚拟终端,用来显示装载镜像过程中的系统信息,首先检查操作系统镜像的正确性,如果正确,则将操作系统镜像载入,循环获取所有保存的页面,并恢复内存内容,通过插入的内存屏障恢复处理器寄存器的值,最后释放恢复过程中申请的内存空间,并通过向电源管理模块中注册的设备发送系统恢复通知,完成整个操作系统镜像的装载。The operating system first creates a virtual terminal to display system information during the process of loading the image, first checks the correctness of the operating system image, and if it is correct, loads the operating system image, loops to obtain all saved pages, and restores the memory content , restore the value of the processor register through the inserted memory barrier, and finally release the memory space requested during the restoration process, and complete the loading of the entire operating system image by sending a system restoration notification to the device registered in the power management module.
CNB2006100498559A 2006-03-15 2006-03-15 Startup Optimization Method for Embedded Operating System Image Startup Expired - Fee Related CN100383739C (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CNB2006100498559A CN100383739C (en) 2006-03-15 2006-03-15 Startup Optimization Method for Embedded Operating System Image Startup

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CNB2006100498559A CN100383739C (en) 2006-03-15 2006-03-15 Startup Optimization Method for Embedded Operating System Image Startup

Publications (2)

Publication Number Publication Date
CN1818869A CN1818869A (en) 2006-08-16
CN100383739C true CN100383739C (en) 2008-04-23

Family

ID=36918897

Family Applications (1)

Application Number Title Priority Date Filing Date
CNB2006100498559A Expired - Fee Related CN100383739C (en) 2006-03-15 2006-03-15 Startup Optimization Method for Embedded Operating System Image Startup

Country Status (1)

Country Link
CN (1) CN100383739C (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101373437B (en) * 2007-04-10 2012-09-05 标准微系统公司 Accessing safety memory by embedded controller to increase system safety

Families Citing this family (21)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8001336B2 (en) * 2007-03-02 2011-08-16 International Business Machines Corporation Deterministic memory management in a computing environment
CN101216772B (en) * 2008-01-15 2011-05-11 中兴通讯股份有限公司 Embedded equipment startup method and software upgrading method
CN101515194B (en) 2008-02-21 2011-11-09 鸿富锦精密工业(深圳)有限公司 Computer operating state converting method
CN101576829B (en) * 2009-06-12 2011-08-24 宋志飞 Method and system for hosting application process in embedded Linux system
CN101593122B (en) * 2009-06-24 2012-09-05 中兴通讯股份有限公司 Method and device for starting embedded system
CN102012823A (en) * 2009-09-04 2011-04-13 中兴通讯股份有限公司 Method and device for quickly restarting computer
CN103995711B (en) * 2010-03-30 2018-02-02 鸿富锦精密工业(深圳)有限公司 Electronic calculator device and its method for restarting
WO2012048459A1 (en) * 2010-10-12 2012-04-19 北京中科院软件中心有限公司 Method and systeme for loading running environments of remote terminal
CN102455917B (en) * 2010-10-22 2016-06-29 康佳集团股份有限公司 The startup control method of a kind of Web TV and device
KR101813641B1 (en) * 2011-11-15 2018-01-02 에스프린팅솔루션 주식회사 Image forming apparatus and method for booting the same having hibernation function
CN103514065B (en) * 2012-06-29 2016-08-10 国基电子(上海)有限公司 Electronic device and method with automatic detection and recovery functions
US9600369B2 (en) 2013-12-10 2017-03-21 Huawei Technologies Co., Ltd. Operating system recovery method and apparatus, and terminal device
CN103729211B (en) * 2013-12-10 2017-08-04 华为技术有限公司 Method, device and terminal equipment for recovering operating system
CN105786547A (en) * 2014-12-26 2016-07-20 中兴通讯股份有限公司 Operation system restarting method and apparatus
CN104950703B (en) * 2015-03-31 2017-10-17 南通艾利特自动化有限公司 Industrial robot controller quick start method based on embedded system
CN107977233B (en) * 2016-10-19 2021-06-01 华为技术有限公司 Kernel image file fast loading method and device
CN110716758A (en) * 2018-06-26 2020-01-21 阿里巴巴集团控股有限公司 Program running method, device, equipment and storage medium
CN112214247B (en) 2019-07-12 2022-05-17 华为技术有限公司 System starting method and related equipment
CN110647428B (en) * 2019-09-29 2023-08-04 海信视像科技股份有限公司 Mirror image file manufacturing and recovering method, processor and embedded system
CN113485764B (en) * 2021-07-05 2024-07-02 珠海格力电器股份有限公司 Embedded system, control method and device thereof and storage medium
CN113392038B (en) * 2021-08-17 2021-11-09 北京鲸鲮信息系统技术有限公司 Linux kernel-based system sleep memory management method and device

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1334510A (en) * 2001-09-07 2002-02-06 清华大学 Remoteboot method of computer in network environment
US20020078338A1 (en) * 2000-12-15 2002-06-20 Ibm Corporation Method and apparatus for fast computer initialization
DE202004009434U1 (en) * 2004-06-15 2004-08-12 Eltec Elektronik Ag Computer system for cloning a process operating system including all applications programs and applications data has a working memory, a non-volatile memory and other hardware as required
WO2005029325A1 (en) * 2003-08-21 2005-03-31 Ti Technologies Limited (A New Zealand Company) Method and apparatus for booting a computer system

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20020078338A1 (en) * 2000-12-15 2002-06-20 Ibm Corporation Method and apparatus for fast computer initialization
CN1334510A (en) * 2001-09-07 2002-02-06 清华大学 Remoteboot method of computer in network environment
WO2005029325A1 (en) * 2003-08-21 2005-03-31 Ti Technologies Limited (A New Zealand Company) Method and apparatus for booting a computer system
DE202004009434U1 (en) * 2004-06-15 2004-08-12 Eltec Elektronik Ag Computer system for cloning a process operating system including all applications programs and applications data has a working memory, a non-volatile memory and other hardware as required

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101373437B (en) * 2007-04-10 2012-09-05 标准微系统公司 Accessing safety memory by embedded controller to increase system safety

Also Published As

Publication number Publication date
CN1818869A (en) 2006-08-16

Similar Documents

Publication Publication Date Title
CN100383739C (en) Startup Optimization Method for Embedded Operating System Image Startup
EP2329365B1 (en) Turbo boot systems and methods
EP3491519B1 (en) Optimized uefi reboot process
CN102369510B (en) Load the operating system using memory segmentation and ACPI-based context switching
JP5368947B2 (en) Method and system for enabling fast platform restart
TW445416B (en) Upgrade card for a computer system and method of operating the same
JPH04362717A (en) System restarting device
WO2006066473A1 (en) A computer multiple operation system switching method
JP2023020861A (en) Firmware updating
CN100377085C (en) Implementation Method of Embedded Operating System Hardware Image Boot Optimization
WO2006075048A1 (en) Method and system for preserving crash dump in a diskless system
WO2012163275A1 (en) Control method, control device and computer system
CN116795437A (en) Computing system, computer-implemented method, and computer program product
Kaminaga Improving linux startup time using software resume (and other techniques)
WO2022135429A1 (en) Rapid start-up method
CN116339925A (en) Method, device, electronic device and storage medium for managing and controlling running state of cloud desktop
JPH07287682A (en) Computer system
US9910677B2 (en) Operating environment switching between a primary and a secondary operating system
CN102169446B (en) A BIOS system and method based on an open source system basic input and output system
CN101615129A (en) Upgrade method and version management client applied in distributed system
Baik et al. Boosting up Embedded Linux device: experience on Linux-based Smartphone
CN102495670A (en) Systematic one-key reset device applicable to embedded Linux operating system
US7484083B1 (en) Method, apparatus, and computer-readable medium for utilizing BIOS boot specification compliant devices within an extensible firmware interface environment
CN102789397B (en) Multi-operating system switching method in computer system
CN111694787A (en) Chip starting method, network equipment and machine readable storage medium

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C14 Grant of patent or utility model
GR01 Patent grant
C17 Cessation of patent right
CF01 Termination of patent right due to non-payment of annual fee

Granted publication date: 20080423

Termination date: 20120315