Gatekeeper detection method and electronic device
By introducing a second watchdog to detect the first watchdog and starting it after the system service process is started, the problem of the software watchdog being unable to reset the business process due to interference from uncontrollable factors is solved, and stable hierarchical recovery of the equipment is achieved.
Patent Information
- Application Number
- CN202210017955.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-07
- Publication Date
- 2025-10-17
- Estimated Expiration
- 2042-01-07
AI Technical Summary
The software watchdog may fail to successfully reset the service process due to interference from uncontrollable factors, affecting the normal use of the device or even causing it to fail.
A second watchdog is introduced to detect the first watchdog and is started after the system service process is started to avoid accidental restart of the kernel system; the second watchdog restarts the kernel system when the first watchdog is abnormal to ensure hierarchical recovery.
This effectively avoids the phenomenon in which the software watchdog mistakenly believes that the first watchdog is abnormal and restarts the kernel system before the system service process is started, ensuring the stable recovery of the device.
Smart Images

Figure CN116450387B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of intelligent terminals, and in particular to a watchdog detection method and an electronic device. BACKGROUND
[0002] A watchdog, also known as a watchdog timer, is essentially a timer. The watchdog can be divided into a software watchdog and a hardware watchdog. The watchdog generally has one input and one output, wherein the input is called kicking the dog or service the dog, and the output is generally used to reset the corresponding service process or hardware when an abnormality occurs in the service process or hardware detected by the watchdog, so as to restore the service process or hardware to normal.
[0003] Although the software watchdog can restore the service process detected thereby, in actual application, due to uncontrollable interference factors, the software watchdog can fail to successfully reset the service process detected thereby, or even fail, thereby affecting normal use of the device. SUMMARY
[0004] To solve the above technical problem, the present application provides a watchdog detection method and an electronic device. In the method, the second watchdog is used not only to detect the kernel system, but also to detect the first watchdog. The first watchdog is used to detect a system service process located in an application program framework layer of the electronic device, and restart the system service process when the system service process is abnormal. Since the detection function of the second watchdog on the first watchdog is started after the system service process is started, the problem that the second watchdog detects the first watchdog before the system service process is started can be avoided, and thus the phenomenon that the second watchdog restarts the kernel system by mistake when the first watchdog is abnormal before the system service process is started is avoided.
[0005] In a first aspect, the present application provides a watchdog detection method. The method comprises: starting a first watchdog in a process of initializing a system service process; wherein the first watchdog is used to detect the system service process, and restart the system service process when the system service process is abnormal; the system service process is located in an application program framework layer of an electronic device; starting a detection function of a second watchdog on the first watchdog; wherein the second watchdog is located in a kernel layer of the electronic device, and the second watchdog is also used to detect a kernel system; and restarting the kernel system by the second watchdog when the first watchdog is abnormal. Thus, since the detection function of the second watchdog on the first watchdog is started after the system service process is started, the problem that the second watchdog detects the first watchdog before the system service process is started can be avoided, and thus the phenomenon that the second watchdog restarts the kernel system by mistake when the first watchdog is abnormal before the system service process is started is avoided.
[0006] For example, the first watchdog is the System Server WatchDog mentioned below, and the second watchdog is the Hungdetect watchdog mentioned below.
[0007] According to the first aspect, before the system service process is initialized, the method further comprises: starting the second watchdog in the process of initializing the kernel system; and restarting the kernel system when the second watchdog detects an exception of the kernel system. In this way, when the kernel system is started, the detection function of the second watchdog on the kernel system is started, and effective detection on the running state of the kernel system can be achieved.
[0008] According to the first aspect, or any one of the implementations of the first aspect, the second watchdog starts the detection function on the first watchdog, comprising: if the second watchdog receives indication information, the second watchdog starts the detection function on the first watchdog; and wherein the indication information is used to indicate that the system service process performs an initialization operation.
[0009] According to the first aspect, or any one of the implementations of the first aspect, the second watchdog restarts the kernel system when the first watchdog is abnormal, comprising: the second watchdog restarts the kernel system when the first watchdog is invalid or the first watchdog fails to successfully restart the system service process. In this way, whether the first watchdog is invalid or the first watchdog fails to successfully restart the system service process when the system service process is abnormal, the second watchdog can restart the kernel system to restore the system service process in the application framework layer.
[0010] According to the first aspect, or any one of the implementations of the first aspect, the method further comprises: the first watchdog performs a feeding operation on the second watchdog at a regular time when the system service process is normal; the first watchdog stops the feeding operation on the second watchdog when the system service process is abnormal; and if the second watchdog does not receive the feeding operation of the first watchdog within one or more continuous detection periods, it is determined that the first watchdog is abnormal.
[0011] According to the first aspect, or any one of the implementations of the first aspect, the method further comprises: the system service process detects whether a target service runs normally at a regular time; wherein the target service runs in the system service process; if the target service runs normally, the system service process performs a feeding operation on the first watchdog; if the target service runs abnormally, the system service process stops the feeding operation on the first watchdog; and if the first watchdog does not receive the feeding operation of the system service process within one or more continuous detection periods, it is determined that the system service process is abnormal.
[0012] According to a first aspect, or any possible implementation mode of the first aspect, the target service comprises at least a window management service, a running management service, and a package management service.
[0013] According to the first aspect, or any possible implementation mode of the first aspect, the second detection period is an integer multiple of the first detection period; the first detection period is a detection period of the first watchdog on the system service process, and the second detection period is a detection period of the second watchdog on the first watchdog. In this way, since the second detection period is longer than the first detection period, the first watchdog is used to recover the application framework layer first, and the second watchdog is used to recover the kernel system when the first watchdog fails to successfully recover the application framework layer, so as to ensure the effect of hierarchical recovery of the electronic device.
[0014] In a second aspect, the present application provides an electronic device. The electronic device comprises one or more processors, one or more memories, and the one or more memories store one or more programs, which, when executed by the one or more processors, cause the electronic device to perform the watchdog detection method of the first aspect and any one of the implementation modes of the first aspect.
[0015] The second aspect and any one of the implementation modes of the second aspect correspond to the first aspect and any one of the implementation modes of the first aspect respectively. The technical effects corresponding to the second aspect and any one of the implementation modes of the second aspect can be referred to the technical effects corresponding to the first aspect and any one of the implementation modes of the first aspect, which will not be described here.
[0016] In a third aspect, the present application provides a computer readable medium, which comprises a computer program, and when the computer program is executed on an electronic device, the electronic device performs the watchdog detection method of the first aspect and any one of the implementation modes of the first aspect.
[0017] The third aspect and any one of the implementation modes of the third aspect correspond to the first aspect and any one of the implementation modes of the first aspect respectively. The technical effects corresponding to the third aspect and any one of the implementation modes of the third aspect can be referred to the technical effects corresponding to the first aspect and any one of the implementation modes of the first aspect, which will not be described here. BRIEF DESCRIPTION OF DRAWINGS
[0018] Figure 1 The hardware structure schematic diagram of the electronic device is exemplarily shown;
[0019] Figure 2 The software structure schematic diagram of the electronic device is exemplarily shown;
[0020] Figure 3The system architecture diagram corresponding to the watchdog detection method provided by the embodiment of the present application is shown in the figure;
[0021] Figure 4 The flowchart of the watchdog detection method provided by the embodiment of the present application is shown in the figure;
[0022] Figure 5 The application scenario to which the watchdog detection method shown in Figure 4 The application scenario to which the watchdog detection method shown in
[0023] Figure 6 The flowchart of the watchdog detection method provided by the embodiment of the present application is shown in the figure;
[0024] Figure 7 The flowchart of the watchdog detection method provided by the embodiment of the present application is shown in the figure;
[0025] Figure 8 The application scenario to which the watchdog detection method shown in Figure 7 The application scenario to which the watchdog detection method shown in
[0026] Figure 9 The flowchart of the watchdog detection method provided by the embodiment of the present application is shown in the figure;
[0027] Figure 10 The application scenario to which the watchdog detection method shown in Figure 9 The application scenario to which the watchdog detection method shown in
[0028] Figure 11 Another application scenario to which the watchdog detection method shown in the figure is applicable;
[0029] Figure 12 Another application scenario to which the watchdog detection method shown in the figure is applicable;
[0030] Figure 13 The CPU core state detection diagram is shown in the figure;
[0031] Figure 14 The CPU core state detection diagram is shown in the figure;
[0032] Figure 15 Another application scenario to which the watchdog detection method shown in the figure is applicable. DETAILED DESCRIPTION
[0033] With reference to the drawings, the technical solutions in the embodiments of the present application will be clearly and completely described below. Obviously, the described embodiments are only some of the embodiments of the present application, but not all of them. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts are within the scope of the present application.
[0034] The term "and / or" used in the present application is only used to describe an association relationship of associated objects, and indicates that there can be three relationships, for example, A and / or B can represent three cases of A existing alone, A and B existing simultaneously, and B existing alone.
[0035] The terms "first" and "second" and the like in the description and claims of the embodiments of the present application are used to distinguish different objects, and are not used to describe a specific order of the objects. For example, the first target object and the second target object are used to distinguish different target objects, and are not used to describe a specific order of the target objects.
[0036] In the embodiments of the present application, the words "exemplary" or "for example" are used to mean serving as an example, instance, or illustration. Any embodiment or design presented as "exemplary" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or advantageous than other embodiments or design solutions. Rather, the use of "exemplary" or "for example" is intended to present concepts in a concrete manner.
[0037] In the description of the embodiments of the present application, unless otherwise specified, the meaning of "a plurality of" is two or more. For example, a plurality of processing units means two or more processing units; a plurality of systems means two or more systems.
[0038] Figure 1 A structural schematic diagram of an electronic device 100 is shown. Optionally, the electronic device 100 can be a terminal, which can also be referred to as a terminal device. The terminal can be a cellular phone or a pad, etc., which is not limited in the present application. It should be understood that, Figure 1 The electronic device 100 shown is only an example of an electronic device, and the electronic device 100 can have more or fewer components than those shown in the figure, can combine two or more components, or can have a different component configuration. Figure 1 The various components shown in the figure can be implemented in hardware, software, or a combination of hardware and software, including one or more signal processing and / or application specific integrated circuits.
[0039] The electronic device 100 can include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, a headset interface 170D, a sensor module 180, a key 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc. The sensor module 180 can include a pressure sensor, a gyroscope sensor, a barometric pressure sensor, a magnetic sensor, an acceleration sensor, a distance sensor, a proximity light sensor, a fingerprint sensor, a temperature sensor, a touch sensor, an ambient light sensor, a bone conduction sensor, etc.
[0040] The processor 110 can include one or more processing units, for example: the processor 110 can include an application processor (AP), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, a memory, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc. Different processing units can be independent devices, or can be integrated in one or more processors.
[0041] The controller can be the nerve center and command center of the electronic device 100. The controller can generate operation control signals according to instruction operation codes and timing signals, and complete the control of fetching and executing instructions.
[0042] The processor 110 can also be provided with a memory for storing instructions and data. In some embodiments, the processor 110 can include one or more interfaces, such as a PCM interface, a universal serial bus (USB) interface, and the like. The PCM interface can also be used for audio communication, sampling, quantizing, and encoding analog signals. In some embodiments, the audio module 170 and the wireless communication module 160 can be coupled through a PCM bus interface. In some embodiments, the audio module 170 can also transmit audio signals to the wireless communication module 160 through the PCM interface to implement the function of answering a phone call through a Bluetooth headset. Both the I2S interface and the PCM interface can be used for audio communication. The USB interface 130 is an interface that complies with the USB standard specification, and can be a Mini USB interface, a Micro USB interface, a USB Type C interface, or the like. The USB interface 130 can be used to connect a charger to charge the electronic device 100, and can also be used to transmit data between the electronic device 100 and a peripheral device. The interface can also be used to connect a headset to play audio through the headset. The interface can also be used to connect other electronic devices, such as an AR device, and the like.
[0043] In addition, it should be noted that in some embodiments, the processor 110 can be built-in with a hardware watchdog, for example, a timer in the processor 110 is used as a hardware watchdog. The processor 110 initializes the timer through a program, writes an initial value, and starts the timer to detect the processor 110. Once the processor 110 has an error, the timer sends a restart signal to the processor 110.
[0044] In some other embodiments, a separate watchdog chip can be provided in the electronic device 100 as a hardware watchdog to detect the processor 110. The watchdog chip mainly includes a pin for feeding the watchdog (generally connected to a GPIO (General Purpose Input Output) pin of the processor 110) and a reset pin (connected to a RESET pin of the processor 110). If the processor 110 does not change the level of the watchdog feeding pin within a certain time, the reset pin will change state to reset the processor 110.
[0045] The charging management module 140 is configured to receive charging input from a charger. The charging management module 140 can also supply power to the electronic device through the power management module 141 while charging the battery 142. The power management module 141 is configured to connect the battery 142, the charging management module 140, and the processor 110. The power management module 141 receives input from the battery 142 and / or the charging management module 140 to supply power to the processor 110, the internal memory 121, the external memory, the display 194, the camera 193, and the wireless communication module 160.
[0046] The wireless communication function of the electronic device 100 can be implemented through the antenna 1, the antenna 2, the mobile communication module 150, the wireless communication module 160, the modem processor, and the baseband processor. The antenna 1 and the antenna 2 are configured to transmit and receive electromagnetic wave signals. The mobile communication module 150 can provide a solution for wireless communication including 2G / 3G / 4G / 5G, etc. applied to the electronic device 100. The wireless communication module 160 can provide a solution for wireless communication including wireless local area networks (WLAN) (e.g., wireless fidelity (Wi-Fi) network), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), infrared (IR) technology, etc. applied to the electronic device 100. In some embodiments, the antenna 1 of the electronic device 100 is coupled to the mobile communication module 150, and the antenna 2 is coupled to the wireless communication module 160, so that the electronic device 100 can communicate with a network and other devices through wireless communication technology.
[0047] The electronic device 100 can implement a display function through the GPU, the display 194, and the application processor. The display 194 is configured to display images, videos, etc. In some embodiments, the electronic device 100 can include one or N displays 194, where N is a positive integer greater than 1.
[0048] The electronic device 100 can implement a photographing function through the ISP, the camera 193, the video codec, the GPU, the display 194, and the application processor. The camera 193 is configured to capture still images or videos. In some embodiments, the electronic device 100 can include one or N cameras 193, where N is a positive integer greater than 1.
[0049] A video codec is used to compress or decompress digital video. The electronic device 100 can support one or more video codecs. In this way, the electronic device 100 can play or record videos in multiple encoding formats, such as moving picture experts group (MPEG) 1, MPEG 2, MPEG 3, MPEG 4, and so on.
[0050] The external memory interface 120 can be used to connect an external memory card, such as a Micro SD card, to extend the storage capacity of the electronic device 100. The external memory card communicates with the processor 110 through the external memory interface 120 to implement a data storage function. For example, files such as music and videos are stored in the external memory card.
[0051] The internal memory 121 can be used to store computer executable program codes, which include instructions. The processor 110 executes various function applications and data processing of the electronic device 100 by running the instructions stored in the internal memory 121, so that the electronic device 100 implements the watchdog detection method in the embodiments of the present application. The internal memory 121 can include a program storage area and a data storage area. The program storage area can store an operating system, at least one application program required by a function (such as a sound playing function, an image playing function, and so on), and the like. The data storage area can store data created during use of the electronic device 100 (such as audio data, a phonebook, and so on), and the like.
[0052] The electronic device 100 can implement audio functions through the audio module 170, the speaker 170A, the receiver 170B, the microphone 170C, the earphone interface 170D, the application processor, and the like. For example, music playing, recording, and the like.
[0053] The audio module 170 is used to convert digital audio information into an analog audio signal output, and is also used to convert an analog audio input into a digital audio signal. The audio module 170 can also be used to encode and decode audio signals. In some embodiments, the audio module 170 can be disposed in the processor 110, or part of the functions of the audio module 170 can be disposed in the processor 110.
[0054] The speaker 170A, also called a "loudspeaker", is used to convert an audio electrical signal into a sound signal. The electronic device 100 can listen to music or listen to a hands-free call through the speaker 170A.
[0055] The receiver 170B, also called an "earpiece", is used to convert an audio electrical signal into a sound signal. When the electronic device 100 answers a call or a voice message, the receiver 170B can be held close to the ear to listen to the voice.
[0056] Microphone 170C, also called "microphone", "microphone", is used to convert sound signals into electrical signals.
[0057] Earphone interface 170D is used to connect wired earphones. Earphone interface 170D can be USB interface 130, or 3.5mm open mobile terminal platform (OMTP) standard interface, cellular telecommunications industry association of the USA (CTIA) standard interface.
[0058] Pressure sensor is used to sense pressure signals, and can convert pressure signals into electrical signals. In some embodiments, pressure sensor can be disposed on display screen 194. In some embodiments, touch operations acting on the same touch position but with different touch operation intensities can correspond to different operation instructions.
[0059] Touch sensor, also called "touch panel". Touch sensor can be disposed on display screen 194, and touch screen, also called "touch screen", is composed of touch sensor and display screen 194. Touch sensor is used to detect touch operations acting on or near it. Touch sensor can pass the detected touch operation to application processor to determine the touch event type. Visual output related to touch operation can be provided through display screen 194.
[0060] Keys 190 include power-on key, volume key, etc. Electronic device 100 can receive key input and generate key signal input related to user settings and function control of electronic device 100.
[0061] The software system of electronic device 100 can adopt layered architecture, event-driven architecture, microkernel architecture, microservice architecture, or cloud architecture. The software structure of electronic device 100 is exemplarily illustrated by taking the layered architecture of Android system as an example.
[0062] Figure 2 is the software structure block diagram of electronic device 100 of the embodiment of the present application.
[0063] The layered architecture of electronic device 100 divides software into several layers, each layer has clear role and division of labor. Layers communicate with each other through software interface. In some embodiments, Android system is divided into three layers, from top to bottom, application layer, application framework layer, and kernel layer.
[0064] Application layer can include a series of application packages.
[0065] AsFigure 2 As shown, the application package can include camera, gallery, calendar, call, map, navigation, music, video, short message, etc. applications.
[0066] The application framework layer provides application programming interface (API) and programming framework for the applications of the application layer. The application framework layer includes some pre-defined functions.
[0067] As shown, the application framework layer can include System Server, System Server WatchDog, SurfaceFlinger, Xcollie, Init, Init WatchDog, etc. Figure 2
[0068] System Server is the provider of Android basic services, and is the most basic requirement for the running of Android system. Some services in the system reside in System Server, such as WMS (Window Manager Server), AMS (Activity Manager System Service), PMS (PackageManager Server), etc. These services exist in the System Server process in the form of a thread.
[0069] System Server WatchDog is used to detect whether System Server has problems such as deadlock, no response, etc. When System Server fails, System Server WatchDog kills the System Server process to achieve soft restart and self-recovery of System Server. The objects detected by System Server WatchDog mainly include two categories, one is object lock, and the other is thread Handler.
[0070] System Server WatchDog is initialized and started in the System Server process. When System Server is started, various Android services are registered and started, including the initialization and start of System Server WatchDog.
[0071] System Server periodically detects whether key services such as AMS, WMS, etc. are running normally. If System Server detects that all key services such as AMS, WMS, etc. are running normally, the System Server WatchDog is fed. If System Server detects that any key service such as AMS, WMS, etc. is not running normally, the System Server WatchDog is not fed. When System Server does not feed the System Server WatchDog for a plurality of (e.g., three) periods, the System Server WatchDog resets the System Server process.
[0072] SurfaceFlinger is started in the System Server process and is responsible for managing the frame buffer of the device uniformly. SurfaceFlinger creates two threads in the process of starting, one of which is used to detect console events, and the other is used to render the UI of the system. Specifically, SurfaceFlinger can be used to manage the display subsystem and provide fusion of 2D and 3D layers for multiple applications.
[0073] In some implementations, SurfaceFlinger can also be set in the system library of the Android system, which is not limited in the present application.
[0074] The system key task timeout detection watchdog (Xcollie) is used to detect whether the action performed in the key process is completed. Xcollie can set two threads, one of which is used to set the state flag of the key process to normal when the key thread starts to perform the action, and to determine whether to set the state flag of the key process to abnormal according to whether the action performed by the key process is timed out, and the other is used to poll the state of each key process and reset the key process when the state flag of the key process is abnormal.
[0075] For example, the key process can be SurfaceFlinger, Vold (volume daemon), AudioFlinger, Face Regconize (face recognition), etc.
[0076] Vold, i.e. Volume daemon, is used to manage the hot plug event of the storage class in Android. AudioFlinger is the executor of the audio system policy, responsible for the management of the audio stream device and the processing and transmission of audio stream data. Face Regconize is used to implement face recognition and face verification, etc.
[0077] Init is the first process in the Linux user space, and therefore the first process in the Linux kernel-based Android user space. The Init process is primarily responsible for parsing property files and initializing properties, parsing the init.rc script, triggering actions and starting services, providing system property service management and completing corresponding triggering events, and maintaining system-level services.
[0078] The Init watchdog is used to detect the Init process and reset the Init process if it is abnormal.
[0079] The kernel layer is the layer between hardware and software.
[0080] like Figure 2 As shown, the kernel layer at least includes a hung detect watchdog and a CPU core status watchdog.
[0081] Among them, the Hungdetect watchdog is used to detect the kernel system and control the kernel restart when a kernel error (Kernel Panic) occurs.
[0082] In this embodiment, the Hungdetect watchdog is also used to detect the System Server WatchDog, Xcollie and Init watchdogs, and control the kernel to restart when any of the System Server WatchDog, Xcollie and Init watchdogs fails, or the services detected by any of the System Server WatchDog, Xcollie and Init watchdogs cannot be restored.
[0083] The CPU core status watchdog is used to detect the operating status of each CPU core and control the core restart when the CPU core status meets the preset core restart conditions.
[0084] In this embodiment, the hardware watchdog can also detect the Hungdetect watchdog and the CPU core status watchdog, for example, detecting the reset action of the Hungdetect watchdog and the CPU core status watchdog. Among them, if either the Hungdetect watchdog or the CPU core status watchdog fails, or the Hungdetect watchdog and the CPU core status watchdog cannot successfully restart the kernel, the hardware watchdog can control the entire machine to restart.
[0085] For example, the kernel layer can further include a software watchdog (referred to as a hungtast watchdog herein) for detecting whether a process is in a D (uninterruptible sleep) state.
[0086] Correspondingly, in actual applications, the hardware watchdog can also detect the hungtast watchdog. It can be understood that the detection of the hungtast watchdog by the hardware watchdog can refer to the detection of the hungdetect watchdog by the hardware watchdog described above, which will not be repeated here.
[0087] It can be understood that, Figure 2 The layers shown in the software structure and the components included in each layer do not constitute a specific limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 can include more or fewer layers than shown, and each layer can include more or fewer components, which are not limited in the present application.
[0088] It can be understood that, in order to implement the watchdog detection method in the present application, the electronic device includes corresponding hardware and / or software modules for performing each function. The algorithm steps of each example described in combination with the embodiments disclosed herein can be implemented in hardware or a combination of hardware and computer software. Whether a certain function is implemented in hardware or computer software driven hardware depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application in combination with the embodiments, but such implementation should not be considered beyond the scope of the present application.
[0089] The present application provides a watchdog detection method. In the present embodiment, the lower layer watchdog of the electronic device can not only detect whether the service of the present layer is abnormal, but also reset the service of the present layer when the service of the present layer is abnormal. The lower layer watchdog of the electronic device can also detect the upper layer watchdog, and reset the service of the present layer when the upper layer watchdog is invalid or the upper layer watchdog cannot recover the service of the upper layer, so as to recover the service of the upper layer, that is, to implement the layered and hierarchical recovery watchdog detection method.
[0090] It should be noted that the "layer" referred to in the present embodiment can be divided according to the software and hardware of the electronic device, or can be divided according to the system architecture of the electronic device, which is not limited in the present application.
[0091] Figure 3 The system architecture provided in the present embodiment is provided. The watchdog detection method provided in the present embodiment is explained and described below by taking the first layer and the second layer of the electronic device as examples. The first layer is the upper layer of the second layer.
[0092] As shown in Figure 3 , a first watchdog is included in the first layer of the electronic device, for detecting a first service in the first layer, and performing a reset or restart operation on the first service when the first service is abnormal.
[0093] For example, when the first service is running normally, the first service performs a first feeding operation on the first watchdog at a regular time. When the first service is unable to run normally, the first service stops the first feeding operation on the first watchdog. If the first watchdog does not receive the first feeding operation from the first service within one detection period or within a plurality of (e.g., 3) consecutive detection periods, the first watchdog performs a reset or restart operation on the first service.
[0094] For another example, the first watchdog regularly acquires a first status mark of the first service. When the first service is running normally, the first status mark of the first service indicates that the service is normal; when the first service is unable to run normally, the first status mark of the first service indicates that the service is abnormal. For example, when the status mark is “ERROR”, it indicates that the service is abnormal; when the status mark is “OK”, it indicates that the service is normal. If the first status mark of the first service acquired by the first watchdog indicates that the first service is abnormal, or if the first status mark of the first service acquired by the first watchdog within a plurality of (e.g., 3) consecutive detection periods all indicates that the first service is abnormal, the first watchdog performs a reset or restart operation on the first service.
[0095] As shown in Figure 3 , a second watchdog is included in the second layer of the electronic device, for detecting a second service in the second layer, and performing a reset or restart operation on the second service when the second service is abnormal.
[0096] For example, when the second service is running normally, the second service performs a second feeding operation on the second watchdog at a regular time. When the second service is unable to run normally, the second service stops the second feeding operation on the second watchdog. If the second watchdog does not receive the second feeding operation from the second service within one detection period or within a plurality of (e.g., 3) consecutive detection periods, the second watchdog performs a reset or restart operation on the second service.
[0097] For another example, the second watchdog regularly acquires a second status mark of the second service. When the second service is running normally, the second status mark of the second service indicates that the service is normal; when the second service is unable to run normally, the second status mark of the second service indicates that the service is abnormal. If the second status mark of the second service acquired by the second watchdog indicates that the second service is abnormal, or if the second status mark of the second service acquired by the second watchdog within a plurality of (e.g., 3) consecutive detection periods all indicates that the second service is abnormal, the second watchdog performs a reset or restart operation on the second service.
[0098] Continuing to refer to Figure 3, the second watchdog, in addition to detecting the second service in the second layer, is also used for detecting the first watchdog and performing a reset or restart operation on the second service when the first watchdog is abnormal, so as to reload the first service in the first layer to run after the second service is reset or restarted successfully, so that the first service returns to normal. Wherein, the first watchdog abnormality can mean that the first watchdog fails, or the first watchdog cannot successfully recover or restart the first service.
[0099] For example, when the first watchdog is normally running and the first service detected by it is normally running, the first watchdog performs a third feeding operation on the second watchdog. When the first watchdog cannot normally run, or cannot successfully recover or restart the first service, the first watchdog stops the third feeding operation on the second watchdog. If the second watchdog does not receive the third feeding operation of the first watchdog within a detection period or a plurality of (such as 3) consecutive detection periods, it performs a reset or restart operation on the second service.
[0100] For another example, the second watchdog acquires a third status mark of the first watchdog. When the first watchdog is normally running and the first service detected by it is normally running, the third status mark of the first watchdog indicates that the service is normal; when the first watchdog cannot normally run, or cannot successfully recover or restart the first service, the third status mark of the first watchdog indicates that the service is abnormal. If the third status mark of the first watchdog acquired by the second watchdog indicates that the service is abnormal, or the third status mark of the first watchdog acquired by the second watchdog within a plurality of (such as 3) consecutive detection periods all indicates that the service is abnormal, the second watchdog performs a reset or restart operation on the second service.
[0101] Wherein, when the first watchdog and the second watchdog are both software watchdogs, the detection period of the second watchdog for the first watchdog is longer than the detection period of the first watchdog for the first service. Optionally, the detection period of the second watchdog for the first watchdog is an integer multiple (such as 2 times) of the detection period of the first watchdog for the first service.
[0102] As an optional implementation, the first layer is an application program layer of the electronic device, and the second layer is an application program framework layer of the electronic device. Wherein, the first service is an application program, and the second service is a system service.
[0103] As another optional implementation, the first layer is an application program framework layer of the electronic device, and the second layer is a kernel layer of the electronic device. Wherein, the first service is a system service, and the second service is a kernel system.
[0104] As yet another optional implementation, the first layer is an application program kernel layer of the electronic device, and the second layer is a hardware layer of the electronic device. Wherein, the first service is a kernel system, and the second service is a processing chip.
[0105] It should be noted that the second watchdog triggers the reset or restart operation of the second service, which can be triggered by the first watchdog stopping the second feeding operation or the state flag of the first watchdog indicating service exception, or by the second service stopping the first feeding operation or the state flag of the second service indicating service exception.
[0106] In this way, by setting the detection mechanism between the layers, the layered and hierarchical recovery of the electronic device is realized. Since the second layer is the lower layer of the first layer, the granularity of the service recovery or restart of the second layer is greater than that of the first layer, so that the success rate of the first layer service recovery is higher. When the first watchdog in the first layer of the electronic device fails to successfully recover the first service it detects, the first service in the first layer can be recovered through the second layer (i.e. the next layer), that is, the first service is reloaded and run after the second service is reset or restarted, so that the first service in the first layer is recovered to normal. If the second service in the second layer also fails to successfully recover, it can continue to be recovered through the next layer (i.e. the third layer), thereby avoiding the problem that the reset or restart operation is repeatedly performed in a layer of the electronic device but fails to be successful.
[0107] Based on the above-described layered and hierarchical recovery scheme of the electronic device, the technical scheme of the present application is described in detail through several specific scenarios applicable thereto.
[0108] Scenario one
[0109] In this scenario, a detection mechanism is set between the application framework layer and the kernel layer of the electronic device, and a Hungdetect watchdog (stuck detection watchdog) in the kernel layer detects a System Server WatchDog (system service watchdog) in the application framework layer. The watchdog detection method provided by the present application is explained and described.
[0110] Figure 4 A flowchart of the System Server WatchDog executing the watchdog detection method is shown for illustrative purposes.
[0111] As shown in Figure 4 The flow of the System Server WatchDog executing the watchdog detection method includes the following steps:
[0112] Step 101, initializing the system service watchdog during the startup of the system service process.
[0113] As can be seen from the foregoing description, the system service watchdog, i.e. the System Server WatchDog, is used to detect the system service process, i.e. the System Server process, in the application framework layer, for example, to detect whether the System Server process has a deadlock, no response, or other problems.
[0114] In step 102, the system service process detects whether it is running normally according to a preset period.
[0115] It should be noted that when the System Server process is started, various Android services, such as AMS, WMS, etc., are registered and started. Therefore, the operation in step 102 is, for example, that the system service process periodically detects whether the above-mentioned registered and started key services running therein are running normally.
[0116] Correspondingly, when these key services are running normally, it is determined that the system service process is currently running normally, and step 103 is performed; otherwise, it is determined that the system service process cannot run normally, and step 105 is performed.
[0117] In step 103, the system service process sends first feeding information to the system service watchdog.
[0118] For example, in some implementations, the first feeding information sent by the system service process to the system service watchdog can be, for example, "kick" marked information, or other agreed information.
[0119] Based on the working principle of the watchdog, when the system service watchdog receives the first feeding information sent by the system service process within the feeding period, it is considered that the system service process is currently running normally, and no reset operation is required, i.e. after receiving the first feeding information, the system service watchdog does not process the system service process.
[0120] In step 104, the system service watchdog sends second feeding information to the deadlock detection watchdog located in the kernel layer.
[0121] For example, in some implementations, the second feeding information sent by the system service watchdog to the deadlock detection watchdog can be, for example, "kick" marked information, or other agreed information.
[0122] Based on the working principle of the watchdog, when the deadlock detection watchdog receives the second feeding information sent by the system service watchdog within the feeding period, it is considered that the system service process is currently running normally, and no reset operation is required, i.e. after receiving the second feeding information, the deadlock detection watchdog does not restart the kernel system.
[0123] The embodiment does not limit the timing of steps 103 and 104.
[0124] At step 105, during the feeding dog period, the system service watchdog stops sending the second feeding dog information to the dead lock detection watchdog, and performs a reset operation on the system service process, if the system service watchdog does not receive the first feeding dog information sent by the system service process.
[0125] Specifically, in some implementations, in order to avoid frequent reset operations on the system service process, i.e., restart, and reduce the impact on the user using the electronic device, the system service watchdog can be set to perform a reset operation on the system service process if the system service watchdog does not receive the first feeding dog information sent by the system service process in a plurality of (e.g., 3) feeding dog periods, or detection periods.
[0126] Further, in some implementations, in order to avoid the system service process sending the first feeding dog information, but because of some reasons, such as external interference, the first feeding dog information does not arrive at the system service watchdog in time, and thus the system service watchdog mistakenly thinks that the system service process is abnormal, and performs a reset operation on the system service process. The system service watchdog can be set to trigger a dog bark if the system service watchdog does not receive the first feeding dog information sent by the system service process in n feeding dog periods, and perform a dog bite if the system service watchdog does not receive the first feeding dog information sent by the system service process in (n+m) feeding dog periods.
[0127] For example, n is an integer greater than 0, and m is an integer greater than 0.
[0128] In addition, regarding the dog bite mentioned above, i.e., triggering the system service watchdog to perform a reset operation on the system service process, the dog bark is to remind the operation and maintenance personnel to maintain and test the system.
[0129] Correspondingly, in order to facilitate the operation and maintenance personnel to maintain and test the system, and accurately locate the abnormal problem, when the dog bark is triggered, the system service watchdog can capture the abnormal log through the pre-compiled dump logic.
[0130] In addition, it should be noted that when the system service watchdog stops sending the second feeding dog information to the dead lock detection watchdog, if the system service watchdog does not receive the second feeding dog information sent by the system service watchdog within a preset period, it will be considered that the system service watchdog has not successfully reset the system service process, or the system service watchdog is invalid, i.e., cannot reset the system service process. In this case, the dead lock detection watchdog will perform a reset operation, i.e., restart the kernel system. In this way, after the kernel is successfully restarted, the System Server process will be reloaded and started, thereby recovering to normal.
[0131] In addition, for the deadlock detection watchdog, in addition to receiving the first feeding information provided by the system service watchdog from the upper layer, the third feeding information provided by the kernel system is also received. Therefore, in actual application, the condition for triggering the deadlock detection watchdog to perform the reset operation can be that the second feeding information is not received within the preset period, or the third feeding information is not received within the preset period.
[0132] In addition, since the second feeding information and the third feeding information are from different objects, the corresponding preset periods can be different, and the specific setting mode can be set according to actual business requirements, which is not limited in the present application.
[0133] In addition, it should be noted that in actual application, the first feeding information can be actively sent by the system service process to the system service watchdog, or can be actively acquired by the system service watchdog from the system service process, which is not limited in the present embodiment.
[0134] Correspondingly, the second feeding information can be actively sent by the system service watchdog to the deadlock detection watchdog, or can be actively acquired by the deadlock detection watchdog from the system service watchdog, which is not limited in the present embodiment.
[0135] Correspondingly, the third feeding information can be actively sent by the kernel system to the deadlock detection watchdog, or can be actively acquired by the deadlock detection watchdog from the kernel system, which is not limited in the present embodiment.
[0136] Therefore, the watchdog detection method provided in the present embodiment can connect the Hungdetect watchdog in the kernel layer to the System Server WatchDog for detecting the System Server, when the System Server WatchDog is abnormal and cannot be restored to normal through the reset of the detected business process, the Hungdetect watchdog in the kernel layer performs the reset operation, so that based on the above hierarchical and graded recovery principle, the abnormal business process can be restored to normal, thereby ensuring the normal use of the electronic device.
[0137] In order to better understand the implementation scheme of the Hungdetect watchdog for detecting the System Server WatchDog, the following will be specifically described in combination with Figure 5 .
[0138] Figure 5 An application scenario is shown for example. As shown in Figure 5As shown, the application framework layer of the electronic device includes System Server WatchDog, which is used to detect the System Server process in the application framework layer, for example, to detect whether the System Server process has deadlocked, is unresponsive, or other problems.
[0139] The System Server process periodically checks whether key services running in its process are operating normally. Key services may be, for example, AMS and WMS. When all key services running in the System Server process are operating normally, the System Server process periodically performs the first dog-feeding operation on the System Server WatchDog. That is, the System Server process periodically sends the aforementioned first dog-feeding information to the System Server WatchDog, or the System Server WatchDog periodically obtains the first dog-feeding information from the System Server process. When any key service running in the System Server process fails to operate normally, the System Server process stops the first dog-feeding operation on the System ServerWatchDog.
[0140] If the System Server WatchDog does not receive the first dog feeding operation of the System Server process within one detection cycle or multiple (such as three) consecutive detection cycles, the System Server WatchDog restarts the System Server process.
[0141] like Figure 5 As shown, the kernel layer of the electronic device includes a Hungdetect watchdog for detecting whether the kernel system is operating normally.
[0142] Among them, when the kernel system operates normally, the kernel system regularly performs the second dog feeding operation on the Hungdetect watchdog, that is, the kernel system regularly sends the third dog feeding information mentioned above to the Hungdetect watchdog, or the Hungdetect watchdog regularly obtains the third dog feeding information from the kernel system. When the kernel system fails to operate normally, the kernel system stops the second dog feeding operation on the Hungdetect watchdog.
[0143] If the Hungdetect watchdog does not receive the second feeding operation of the kernel system within one detection cycle or multiple (such as 3) consecutive detection cycles, the kernel system will be restarted.
[0144] Continue to refer to Figure 5, Hungdetect watchdog can detect not only the kernel system, but also the System Server WatchDog, and restart the kernel system when the System Server WatchDog is abnormal, so as to reload the System Server process after the kernel restarts successfully, and make the System Server process normal. The abnormality of the System Server WatchDog can refer to the failure of the System Server WatchDog, or the failure of the System Server WatchDog to successfully restart the System Server process.
[0145] When the System Server WatchDog is running normally and the System Server process detected by the System Server WatchDog is running normally, the System Server WatchDog periodically performs a third feeding operation on the Hungdetect watchdog, that is, the System Server WatchDog periodically sends the second feeding information to the Hungdetect watchdog, or the Hungdetect watchdog periodically acquires the second feeding information from the System Server WatchDog. When the System Server WatchDog cannot run normally, or cannot successfully restart the System Server process, the System Server WatchDog stops the third feeding operation on the Hungdetect watchdog.
[0146] If the Hungdetect watchdog does not receive the third feeding operation of the System Server WatchDog within one detection period or a plurality of (such as 3) continuous detection periods, the Hungdetect watchdog restarts the kernel system. Further, after the kernel restarts successfully, the System Server process is reloaded and started to recover to normal.
[0147] The detection period of the Hungdetect watchdog on the System Server WatchDog is longer than the detection period of the System Server WatchDog on the System Server process. Optionally, the detection period of the Hungdetect watchdog on the System Server WatchDog is an integer multiple of the detection period of the System Server WatchDog on the System Server process. For example, the detection period of the System Server WatchDog on the System Server process is 30 seconds, and the detection period of the Hungdetect watchdog on the System Server WatchDog is 60 seconds.
[0148] In this way, by setting the detection mechanism between the kernel layer and the application framework layer, the layered and hierarchical recovery of the electronic device is realized. Since the granularity of the kernel restart is greater than the granularity of the System Server process restart, when the System Server process cannot be restarted successfully, the success rate of recovering the System Server process can be greatly improved by kernel restart, and the problem that the electronic device repeatedly restarts the System Server process but cannot be successful can also be avoided.
[0149] In an application scenario of electronic device restart, the kernel system may start successfully, but the System Server process may not start successfully. At this time, the Hungdetect watchdog in the kernel layer will still detect the System Server WatchDog. Since the System Server process does not start successfully, the System Server WatchDog cannot perform the Hungdetect watchdog feeding operation, and the Hungdetect watchdog will consider that the System Server WatchDog is abnormal, and restart the kernel system again, which may cause the problem of multiple kernel system restarts.
[0150] To solve this problem, the starting time of the Hungdetect watchdog in the kernel layer is adjusted. After the System Server starts successfully, the Hungdetect watchdog will start the detection function on the System Server WatchDog, rather than starting after the kernel system starts.
[0151] Figure 6 A flowchart of a watchdog detection method is shown for illustration. As shown in FIG. 1, the Hungdetect watchdog in the kernel layer detects the System Server WatchDog in the application framework layer. Figure 6As shown, the flow of the watchdog detection method specifically includes:
[0152] Step 11, in the process of initializing the system service process, the System Server WatchDog starts.
[0153] Step 12, the Hungdetect watchdog starts the detection function on the System Server WatchDog.
[0154] Step 13, the Hungdetect watchdog restarts the kernel system when the System Server WatchDog is abnormal.
[0155] When the electronic device is initialized and restarted, the System Server will be killed, and the System Server WatchDog will also be closed. At this time, the System Server WatchDog will not feed the Hungdetect watchdog in the kernel layer. Until the System Server is successfully restarted, the System Server WatchDog will continue to feed the Hungdetect watchdog.
[0156] In the process of initializing the electronic device, the kernel system starts first, and then the processes in the application framework layer start. When the kernel system is initialized, the Hungdetect watchdog in the kernel layer starts, but its detection function on the System Server WatchDog does not start. When the System Server in the application framework layer is initialized, the Hungdetect watchdog in the kernel layer is instructed to start its detection function on the System Server WatchDog.
[0157] For example, when the System Server performs an initialization operation, an instruction information is sent to the Hungdetect watchdog in the kernel layer, wherein the instruction information is used to indicate that the System Server has been initialized, or to indicate that the Hungdetect watchdog starts the detection function on the System Server WatchDog. Further, the kernel system starts its detection function on the System Server WatchDog based on the instruction information, so as to realize the detection on the System Server WatchDog.
[0158] Thus, since the detection function of the Hungdetect watchdog on the System Server WatchDog is started after the System Server is started, at least after the System Server is successfully started once, the problem that the Hungdetect watchdog detects the System Server WatchDog before the System Server is started can be avoided, and thus the phenomenon that the Hungdetect watchdog mistakenly considers that the System Server WatchDog is abnormal and restarts the kernel system before the System Server is started can be avoided.
[0159] Scenario two
[0160] In this scenario, a detection mechanism is arranged between the application framework layer and the kernel layer of the electronic device, and the Hungdetect watchdog in the kernel layer detects the Xcollie (system key task timeout detection watchdog) in the application framework layer as an example to explain the watchdog detection method provided in the present application.
[0161] Figure 7 A flowchart of the Xcollie executing the watchdog detection method is shown for illustration. As shown in Figure 7 The Xcollie executing the watchdog detection method includes the following steps:
[0162] Step 201, initializing the system key task timeout detection watchdog, and setting the state information identifying the key process as a normal mark.
[0163] Specifically, the key process in the present embodiment can be, for example, the Vold, SurfaceFlinger, AudioFlinger, Face Regconize and the like mentioned above, which will not be listed one by one, and the present application does not limit this.
[0164] In addition, it should be noted that the timing of initializing the system key task timeout detection watchdog can be, in some implementations, during the process of starting the key process, so that the key detection watchdog can start detecting in time when the function corresponding to the action of the key process is called.
[0165] In addition, as known from the above description, the system critical task timeout detection watchdog is a resident thread in the key process, which is used to detect whether the action performed by the key process is completed. For example, the system critical task timeout detection watchdog detects whether the action of rendering the system UI is completed. Therefore, in some other implementations, the system critical task timeout detection watchdog can also be initialized when the key process is started and a function corresponding to the action performed by the key process is called, so that it can be determined according to the business requirement which actions need to be detected by the system critical task timeout detection watchdog, and better adapt to various application scenarios.
[0166] That is, whether to initialize the system critical task timeout detection watchdog and whether the system critical task timeout detection watchdog detects whether the action is completed can be determined according to the actual business requirement.
[0167] In addition, as mentioned above, after the system critical task timeout detection watchdog is successfully initialized, the state information identifying the key process is set to a normal mark, for example, set to "OK". Correspondingly, the abnormal mark mentioned below can be represented by "ERROR".
[0168] In addition, in some implementations, "1" can be agreed as the normal mark and "0" can be agreed as the abnormal mark as needed.
[0169] It should be understood that the above description is only an example for better understanding the technical solution of the embodiment and is not the only limitation of the embodiment. In actual application, the normal mark and the abnormal mark can be agreed as needed, and the present application does not limit this.
[0170] In step 202, the system critical task timeout detection watchdog records the execution duration of the action performed by the key process after detecting the start node of the action performed by the key process.
[0171] It can be understood that in actual application, the action performed by the key process is implemented by a function (or program code, hereinafter referred to as function) implementing the action, and the start node (begin identification bit) identifying the start of the action and the end node (end identification bit) identifying the end of the action are in the function.
[0172] For example, the system critical task timeout detection watchdog can obtain the start time of the action according to the call of the begin identification bit and obtain the end time of the action according to the call of the end identification bit.
[0173] In addition, the timeout period for each action can be reasonably set based on the business characteristics and the time required for the action to be executed normally.
[0174] For example, for an action with a completion time of 5ms (the time from the call start node to the call end node), the timeout period can be 5ms, or 8ms, or n*5ms. Exemplarily, n is an integer greater than 0.
[0175] It should be understood that the above description is merely an example listed for a better understanding of the technical solution of this embodiment, and is not intended to be the sole limitation on this embodiment.
[0176] Step 203: When the execution time reaches the timeout time corresponding to the action, the system key task timeout detection watchdog query action end node is called.
[0177] Specifically, if the execution time reaches the timeout period corresponding to the action but the end node is not called, that is, a timeout occurs, step 204 is executed; otherwise, step 206 is executed.
[0178] In step 204 , the system critical task timeout detection watchdog modifies the status information identifying the critical process from a normal mark to an abnormal mark.
[0179] Specifically, when a timeout occurs, it indicates that the action executed by the critical process was not completed. This may be due to an exception in the critical process. Therefore, in order to reset the system's critical task timeout detection watchdog or the critical process deadlock detection watchdog to restore the critical process to normal operation, it is necessary to modify the status information identifying the critical process from a normal mark to an abnormal mark, such as changing "OK" to "ERROR". In this way, after the critical process performs the reset operation and the next initialization is successful, "ERROR" can be changed back to "OK", and the system's critical task timeout detection watchdog can resume detecting the required action.
[0180] In step 205 , the system critical task timeout detection watchdog sends an abnormality flag to the stuck detection watchdog in the kernel layer, and the stuck detection watchdog performs a reset operation.
[0181] It is understandable that, because the application framework layer is located above the kernel layer, the system-critical task timeout detection watchdog located in the application framework has less impact on the electronic device when performing a reset operation than the freeze detection watchdog located in the kernel layer when performing a reset operation. Therefore, in some implementations, the system-critical task timeout detection watchdog may first perform a reset operation before executing step 205.
[0182] For example, if the key detection watchdog resets successfully, i.e. the key process is resumed to normal, the state information of the key process is modified from the abnormal mark to the normal mark, and the normal mark is sent to the deadlock detection watchdog in the kernel layer, so that the deadlock detection watchdog does not bark or even bite (i.e. performs a reset operation on the kernel system) when the preset period (feed dog period) arrives.
[0183] For example, if the key detection watchdog does not reset successfully, e.g. the key process is not resumed to normal, or the system key task timeout detection watchdog fails to reset the key process, step 205 is performed, i.e. the reset is performed by means of the lower-layer deadlock detection watchdog.
[0184] In addition, it should be understood that, in actual applications, the granularity of the business recovery or restart performed by the lower-layer deadlock detection watchdog is greater than the granularity of the business recovery or restart performed by the upper-layer system key task timeout detection watchdog, and the impact of the reset operation performed by the deadlock detection watchdog on the electronic device is greater than the impact of the reset operation performed by the system key task timeout detection watchdog on the electronic device, so the period for triggering the reset operation of the deadlock detection watchdog is usually greater than the period for triggering the reset operation of the system key task timeout detection watchdog.
[0185] Based on this, in order to better understand when the reset operation is performed by the system key task timeout detection watchdog and when the reset operation is performed by the deadlock detection watchdog in the watchdog detection scheme in the embodiment, two specific implementation manners are given below.
[0186] Manner 1:
[0187] For example, the system key task timeout detection watchdog detects the abnormal duration of the state information of the key process in the abnormal mark.
[0188] Correspondingly, when the abnormal duration is less than the duration threshold, the system key task timeout detection watchdog re-executes the reset operation; and when the abnormal duration is not less than the duration threshold, step 205 is performed.
[0189] It can be understood that, regarding the duration threshold mentioned above, in some implementation manners, the duration threshold can be determined according to the timeout duration of the action of appearing timeout, the detection period (which can also be understood as the feed dog period) of the deadlock detection watchdog, and the time delay between the application program framework layer and the kernel layer.
[0190] Manner 2:
[0191] Exemplarily, similar to the manner 1, the system key task timeout detection watchdog can still detect that the state information of the key process is in the abnormal time length of the abnormal mark. The difference is that, in this manner, whether the reset operation is continued to be executed by the system key task timeout detection watchdog or the reset operation is executed by the dead lock detection watchdog is determined by judging the timeout times. Therefore, after obtaining the abnormal time length, the system key task timeout detection watchdog can determine the timeout times according to the abnormal time length and the timeout time length.
[0192] Correspondingly, when the timeout times are less than the times threshold, the system key task timeout detection watchdog re-executes the reset operation; and when the abnormal time length is not less than the times threshold, the step 205 is executed.
[0193] Regarding the setting of the timeout times, similar to the setting of the time length threshold, the setting can be made according to the business requirement and the actual situation, and the present application does not limit this.
[0194] It should be understood that the above description is only an example for better understanding the technical solution of the present embodiment, and is not the only limitation of the present embodiment.
[0195] In addition, it should be noted that, in actual application, in addition to the system key task timeout detection watchdog, there will also be a system service watchdog, an initialization watchdog and other watchdogs for detecting different business processes in the application program framework layer. Therefore, in order to enable the dead lock detection watchdog located in the lower layer to detect different watchdogs in the upper layer, a pre-packaged common node for deciding whether the reset operation is executed by the dead lock detection watchdog can be set in the kernel layer.
[0196] Correspondingly, the abnormal mark sent by the system key task timeout detection watchdog to the dead lock detection watchdog is specifically sent to the common node in the kernel layer in this implementation scheme in which the common node is set.
[0197] Exemplarily, the preset strategy, that is, the strategy for deciding whether the reset operation is executed by the dead lock detection watchdog, is pre-set in the common node. Therefore, after receiving the abnormal mark sent by the watchdog in the upper layer, for example, the system key task timeout detection watchdog in the present embodiment, the common node will determine whether the reset operation needs to be executed by the dead lock detection watchdog according to the abnormal mark and the preset strategy.
[0198] Correspondingly, the common node notifies the dead lock detection watchdog to execute the reset operation by processing when it is determined that the reset operation needs to be executed by the dead lock detection watchdog.
[0199] Exemplarily, in some implementations, the common node can actively send a reset instruction to the dead lock detection watchdog when it is determined that the reset operation needs to be performed by the dead lock detection watchdog, or the dead lock detection watchdog can periodically obtain the instruction information decided by the common node from the common node, and then perform the reset operation when the reset instruction is obtained.
[0200] In addition, it should be noted that, in order to make the technical solutions provided by the present embodiment applicable to more application scenarios and meet different business needs, in actual application, when it is identified that the execution process of some actions is abnormal, the reset can be performed with the help of the lower-layer dead lock detection watchdog according to the business needs.
[0201] Exemplarily, the above operation can be, for example, when starting a key process, calling a function corresponding to an action executed by the key process, initializing the system key task timeout detection watchdog, and setting a hierarchical recovery mark for the function corresponding to the action executed by the key process. In this way, when the state information of the key process is in an abnormal state and the action executed by the key process is set by the hierarchical recovery mark, the system key task timeout detection watchdog will notify the dead lock detection watchdog to perform the reset operation.
[0202] It should be noted that the hierarchical recovery mark described above can be set as needed in actual application, which is not limited herein.
[0203] Exemplarily, in some implementations, the system key task timeout detection watchdog can only send the abnormal mark of the key process corresponding to the action set with the hierarchical recovery mark to the dead lock detection watchdog. In this way, after receiving the abnormal mark, the dead lock detection watchdog, or the common node, does not need to consider whether the key process corresponding to the abnormal mark is set with the hierarchical recovery mark, and by default, all received abnormal marks are set with the hierarchical recovery mark, that is, the dead lock detection watchdog intervenes.
[0204] Exemplarily, in some other implementations, the system key task timeout detection watchdog can not distinguish whether the key process is set with the hierarchical recovery mark, and directly send the state information of the key process and other mark information set for the key process, such as the hierarchical recovery mark, to the lower-layer common node or dead lock detection watchdog when detecting that the state information of the key process changes, so as to identify whether the intervention is needed by the lower-layer common node or dead lock detection watchdog.
[0205] It should be understood that the above description is only an example for better understanding the technical solutions of the present embodiment, and is not the only limitation of the present embodiment.
[0206] Step 206, stopping detecting the action executed by the key process.
[0207] It can be understood that in actual application, the change of the key process state is shown in Table 1.
[0208] Table 1: Change table of key process state
[0209] Scenario State Initialization (init) Normal End of execution (end) Normal Execution timeout (Timeout) Abnormal
[0210] That is, if the end node is called within the timeout duration, it indicates that the current execution of the action ends normally, in which case the system key task timeout detection watchdog does not need to be processed, that is, it does not need to be reset, and therefore after the current execution of the action ends normally, the system key task timeout detection watchdog can stop detecting the action performed by the key process, thereby saving the occupation of the electronic device system resource.
[0211] In addition, it should be noted that when the end node is called in the implementation of the watchdog detection method provided in the embodiment based on the system architecture applicable to the above-mentioned hierarchical recovery scheme, the state information identifying the key process can also be sent to the Hungdetect watchdog of the lower layer, that is, the kernel layer. For this case, the state information sent by the system key task timeout detection watchdog to the Hungdetect watchdog is a normal mark identifying that the key process is in a normal state, for example, "OK".
[0212] In addition, in some implementations, when the detection of the action ends, the information sent by the system key task timeout detection watchdog to the Hungdetect watchdog can also be state information identifying that the action ends normally, so that the Hungdetect watchdog does not consider that the key process is abnormal or that the system key task timeout detection watchdog is invalid when it does not receive state information about the execution of the action by the key process within a preset period (dog feeding period), and therefore does not perform a reset operation.
[0213] Therefore, the watchdog detection method provided in the embodiment can connect the Xcollie detecting the key process to the Hungdetect watchdog of the kernel layer, so that when the Xcollie is abnormal and cannot be restored to normal by resetting the detected business process, the Hungdetect watchdog of the kernel layer performs a reset operation, thereby enabling the abnormal business process to be restored to normal based on the principle of the above-mentioned hierarchical recovery, and thereby ensuring the normal use of the electronic device.
[0214] In order to better understand the implementation scheme of the Hungdetect watchdog detecting the Xcollie, the following will be specifically described in combination with Figure 8 .
[0215] Figure 8An application scenario is shown in the following figure. As shown in the figure, the electronic device includes an application framework layer, which includes Xcollie for detecting whether an action performed by a key process SurfaceFlinger is completed, for example, detecting whether a UI operation of a rendering system is completed. Figure 8
[0216] It can be understood that SurfaceFlinger is started in a System Server process and is responsible for unified management of frame buffers of the device. SurfaceFlinger creates two threads in the process of starting, one of which is used to detect console events (hereinafter referred to as thread A), and the other thread (hereinafter referred to as thread B) is used to render the UI of the system. Specifically, SurfaceFlinger can be used to manage the display subsystem and provide fusion of 2D and 3D layers for multiple applications.
[0217] Xcollie is used to detect whether an action performed in a key process is completed. Xcollie can set two threads, one thread (hereinafter referred to as thread C) is used to set a state flag of the key process to normal when the key thread starts to perform the action, and determine whether to set the state flag of the key process to abnormal according to whether the key process performs the action in time, and one thread (hereinafter referred to as thread D) is used to poll the state of each key process and reset the key process when the state flag of the key process is abnormal.
[0218] Based on the characteristics of Xcollie and SurfaceFlinger, continue to refer to Figure 8 , the first state flag obtained by Xcollie from SurfaceFlinger is specifically obtained by thread D in Xcollie.
[0219] For example, in some implementations, the first state flag can be determined by thread D in Xcollie according to the console events detected by thread A and / or the progress information of the rendering of thread B in SurfaceFlinger.
[0220] For example, in some implementations, the first state flag can be determined by thread D in Xcollie according to the console events detected by thread A and / or the progress information of the rendering of thread B in SurfaceFlinger.
[0221] Continue to refer to Figure 8 When the action performed by the SurfaceFlinger is normally executed, the first status mark obtained by the Xcollie is a normal mark, such as "OK"; when the action performed by the SurfaceFlinger is timed out, the first status mark obtained by the Xcollie is an abnormal mark, such as "ERROR".
[0222] That is, the information provided by the SurfaceFlinger to the Xcollie is actually a mark identifying the status of the SurfaceFlinger. Whether the Xcollie performs a reset operation or whether the Xcollie notifies the Hungdetect watchdog in the kernel layer to perform a reset operation is determined according to the first status mark identifying the status of the SurfaceFlinger.
[0223] For example, in some implementations, if the Xcollie obtains the abnormal mark in one detection period or in a plurality of (for example, 3) continuous detection periods, the Xcollie performs a restart operation on the SurfaceFlinger process, that is, the Xcollie performs a reset operation.
[0224] Continuing to refer to Figure 8 The Hungdetect watchdog is included in the kernel layer of the electronic device and is used to detect whether the kernel system is normally running.
[0225] When the kernel system is normally running, the kernel system periodically feeds the Hungdetect watchdog. When the kernel system cannot normally run, the kernel system stops feeding the Hungdetect watchdog.
[0226] For example, if the Hungdetect watchdog does not receive the feeding operation of the kernel system in one detection period or in a plurality of (for example, 3) continuous detection periods, the Hungdetect watchdog restarts the kernel system, that is, performs a reset operation.
[0227] Continuing to refer to Figure 8 In addition to detecting the kernel system, the Hungdetect watchdog can also detect the Xcollie and restart the kernel system when the Xcollie is abnormal, so as to reload the SurfaceFlinger process after the kernel is restarted successfully, so that the SurfaceFlinger process returns to normal. The abnormality of the Xcollie can refer to the failure of the Xcollie or the failure of the Xcollie to successfully restart the SurfaceFlinger process.
[0228] When Xcollie is normal and the SurfaceFlinger process detected by Xcollie is normal, Xcollie can actively send the second status mark to the Hungdetect watchdog, or the Hungdetect watchdog can actively acquire the second status mark from Xcollie.
[0229] It can be understood that, in some implementations, whether Xcollie actively sends the second status mark to the Hungdetect watchdog or the Hungdetect watchdog actively acquires the second status mark from Xcollie, the sending or acquisition can be performed according to a preset period, that is, the sending or acquisition is performed at a timing.
[0230] It should be noted that, in actual applications, the second status mark can be the same as or different from the first status mark.
[0231] For example, when the first status mark is a normal mark, if Xcollie is normal (valid), the second status mark is the same as the first status mark, and is also a normal mark.
[0232] For example, when the first status mark is a normal mark, if Xcollie is abnormal (invalid), the second status mark is different from the first status mark, and is specifically an abnormal mark.
[0233] For example, when the first status mark is an abnormal mark, whether Xcollie is normal or not, the second status mark is the same as the first status mark, and is an abnormal mark.
[0234] That is, for the scenario in which Xcollie accesses the Hungdetect, the Hungdetect watchdog can acquire the second status mark regardless of whether Xcollie is normal or whether the SurfaceFlinger process can be restarted.
[0235] In addition, it should be noted that, in other implementations, the second status mark can be detection of a communication channel between the Hungdetect watchdog and Xcollie, or detection of information sent by Xcollie.
[0236] Specifically, if the Hungdetect watchdog does not query any information provided by Xcollie, and cannot detect the current state of Xcollie, an abnormal second status mark can be generated.
[0237] For example, if the Hungdetect watchdog does not obtain the second state mark indicating that the SurfaceFlinger process is normal or the information indicating that the Xcollie stops the action of detecting the SurfaceFlinger execution within one detection period or within multiple (for example, 3) continuous detection periods, the kernel system is restarted. Then, after the kernel is restarted successfully, the SurfaceFlinger process is reloaded and started to recover to normal.
[0238] In addition, it can be understood that, in order to ensure the implementation of the scheme, the detection period of the Hungdetect watchdog on the Xcollie is longer than the detection period of the Xcollie on the SurfaceFlinger process.
[0239] Optionally, the detection period of the Hungdetect watchdog on the Xcollie is an integer multiple of the detection period of the Xcollie on the SurfaceFlinger process. For example, the detection period of the Xcollie on the SurfaceFlinger process is 30 seconds, and the detection period of the Hungdetect watchdog on the Xcollie is 60 seconds.
[0240] In this way, by setting the detection mechanism between the kernel layer and the application framework layer, the layered and hierarchical recovery of the electronic device is realized. Since the granularity of the kernel restart is greater than the granularity of the SurfaceFlinger process restart, when the SurfaceFlinger process cannot be restarted successfully, the kernel restart can greatly improve the success rate of recovering the SurfaceFlinger process, and the problem that the electronic device repeatedly restarts the SurfaceFlinger process in the application framework layer but cannot be successfully recovered can be avoided.
[0241] Scenario Three
[0242] In this scenario, a detection mechanism is set between the application framework layer and the kernel layer of the electronic device, and the Hungdetect watchdog in the kernel layer can simultaneously detect multiple software watchdogs in the application framework layer.
[0243] Referring to Figure 9 , Figure 9 For example, by means of the pre-encapsulated common node in the kernel layer, the multiple software watchdogs in the application framework layer are connected to the Hungdetect watchdog, and a flowchart for realizing that the Hungdetect watchdog can simultaneously detect multiple software watchdogs in the application framework layer is shown.
[0244] For example, by means of the pre-encapsulated common node in the kernel layer, the multiple software watchdogs in the application framework layer are connected to the Hungdetect watchdog, and a flowchart for realizing that the Hungdetect watchdog can simultaneously detect multiple software watchdogs in the application framework layer is shown. Figure 9As shown, the watchdog detection method provided by the embodiment applies the public node pre-packaged in the kernel layer, and specifically includes:
[0245] In step 301, the public node receives information provided by each software watchdog in the application framework layer.
[0246] For example, the software watchdogs mentioned above can be System Server WatchDog, Xcollie, Init watchdog, etc., which will not be listed one by one this time, and the present application does not limit this.
[0247] Correspondingly, the information provided by the software watchdogs mentioned above is related to the characteristics of the software watchdogs in actual application.
[0248] For example, for System Server WatchDog, the provided information can be the second feeding information mentioned in scenario one.
[0249] As can be understood, when the information provided by System Server WatchDog is the second feeding information, it indicates that System Server WatchDog is effective, and the System Server process detected by System Server WatchDog is also normal.
[0250] Correspondingly, in some implementation scenarios, the information provided by System Server WatchDog can not be the second feeding information, for example, when System Server WatchDog is invalid or the System Server process detected by System Server WatchDog is abnormal, System Server WatchDog will stop providing the second feeding information. In this case, System Server WatchDog can no longer provide information, or set the provided information to "null", or in order to facilitate informing the lower layer public node that it has currently entered an exception, a conventional exception information can be provided.
[0251] The information provided by Xcollie can be the second state flag mentioned in scenario two. According to the description of scenario two, when the reset operation needs to be performed by means of the hung detection watchdog (Hungdetect watchdog), the second state flag is an abnormal flag, and when Xcollie and the corresponding key process state are normal, the second state flag provided is a normal flag.
[0252] It should be understood that the above description is only an example for better understanding the technical solution of the embodiment, and is not the only limitation of the embodiment.
[0253] At step 302, the common node determines the priority of the information provided by each software watchdog according to the service process corresponding to each software watchdog.
[0254] For example, in the Android system, most of the key processes are registered and started in the System Server process, so the System Server process is normally the prerequisite for ensuring the normality of other key processes. Therefore, in some implementations, the information related to the System Server process can be determined as the first priority, and the information provided by other key processes running in the System Server process can be determined as the second priority, i.e., the first priority is higher than the second priority.
[0255] Based on this, if the information is provided by the System Server WatchDog, the priority is determined as the first priority, and if the information is provided by Xcollie, the priority is determined as the second priority.
[0256] It should be understood that the above description is only an example for better understanding the technical solution of the embodiment and is not the only limitation of the embodiment. In actual application, the priority of different service processes can be reasonably set according to other service requirements to better adapt to various application scenarios.
[0257] At step 303, the common node determines whether to perform the reset operation according to the preset decision and the priority of the information provided by each software watchdog.
[0258] For example, in some implementations, the preset decision can stipulate that when the information of the first priority is the second watchdog feeding information mentioned above, i.e., the System Server process is normal, regardless of the content of the information provided by other software watchdogs, the current does not need to be intervened by the watchdog for reset operation.
[0259] For example, in some other implementations, the preset decision can stipulate that when the information of the first priority is the second watchdog feeding information mentioned above, and the information provided by other software watchdogs (such as N) has n abnormal information, it is determined that the current needs to be intervened by the watchdog for reset operation.
[0260] For example, n is an integer greater than 1, and N is an integer greater than n.
[0261] For example, the common node receives 5 pieces of information of software watchdogs in one detection period, one of which is provided by the System Server WatchDog, and 4 (i.e. N mentioned above) are provided by other software watchdogs (2 pieces of information are normal information, and 2 pieces of information are abnormal information). If it is specified that n≥2, the reset detection watchdog intervention is executed, in this case, the decision information made by the common node is the reset instruction.
[0262] For example, in another implementation, the preset decision can specify that the first priority information is the second feeding dog information mentioned above, and the software watchdog providing the second priority information is a designated software watchdog, for example, a reset flag is set, and it is determined that the reset operation of the reset detection watchdog intervention is currently required.
[0263] Further, on the basis of the above, it can also be considered that each software watchdog of the upper layer fails or the detected business process is abnormal. If it is not recovered for a plurality of periods (for example, 3 periods), the common node determines that the reset operation of the reset detection watchdog intervention is currently required.
[0264] It should be understood that the above description is only an example for better understanding the technical scheme of the embodiment and is not the only limitation of the embodiment. In actual application, different preset strategies can be reasonably set according to other business requirements to better adapt to various application scenarios.
[0265] Correspondingly, based on the preset strategy and the priority of the information provided by each software watchdog determined, if it is determined that the reset operation is required, step 304 is executed; otherwise, step 305 is executed.
[0266] In step 304, the common node provides a reset instruction to trigger the reset operation of the reset detection watchdog.
[0267] For the description of the reset operation of the reset detection watchdog, please refer to the part of scenario one and scenario two described above, which will not be repeated here.
[0268] In step 305, the common node provides the agreed feeding dog information to the reset detection watchdog.
[0269] It can be understood that the common node provides the agreed feeding dog information, for example, a "kick" flag or an "OK" flag, so that the reset detection watchdog knows that the software watchdog of the upper layer and the detected business process are normal, and the current does not require intervention to restart the kernel system.
[0270] Therefore, the watchdog detection method provided in this embodiment pre-encapsulates a common node that can decide whether the lower-layer software watchdog should perform the reset when the upper-layer software watchdog fails to successfully reset the abnormal business process. The common node uniformly receives status marks sent by different upper-layer software watchdogs to identify the business process / actions performed by the upper-layer software watchdog detection. By analyzing and deciding the status marks according to preset strategies, the deadlock detection watchdog is notified to perform the reset only when it is determined that the deadlock detection watchdog needs to perform the reset, making the hierarchical recovery scheme in this application more reasonable.
[0271] In addition, according to business needs, public nodes can decide a processing result based on the dog feeding information and status marks from different upper-level software watchdogs, thereby minimizing the restart operation of the kernel system by the deadlock detection watchdog without affecting the user's use of electronic devices, thereby reducing resource overhead.
[0272] In order to better understand the implementation scheme of connecting multiple software watchdogs in the application framework layer to the Hungdetect watchdog, the following takes the Hungdetect watchdog in the kernel layer to simultaneously detect the System ServerWatchDog and Xcollie in the application framework layer as an example to explain the watchdog detection method provided by this application.
[0273] See also Figure 10 , Figure 10 The figure is a schematic diagram showing an exemplary application scenario.
[0274] like Figure 10 As shown, the application framework layer of the electronic device includes System Server WatchDog, the System Server process detected by System Server WatchDog, Xcollie, and key processes corresponding to Xcollie, such as SurfaceFlinger; the kernel layer of the electronic device includes the Hungdetect watchdog, which is used to detect whether the kernel system is running normally, and a public node that communicates with the System Server WatchDog and Xcollie of the application framework layer and the Hungdetect watchdog of the kernel layer respectively.
[0275] Regarding System Server WatchDog detecting the System Server process, the System Server process performing the first watchdog feeding operation on System Server WatchDog, when to restart the System Server process, and when System Server WatchDog performs the second watchdog feeding operation (the second watchdog feeding information in Scenario 1), please refer to the description in Scenario 1 and will not be repeated here.
[0276] Regarding how Xcollie detects the action in SurfaceFlinger, how Xcollie obtains the first status mark of SurfaceFlinger, when to restart SurfaceFlinger, and when Xcollie provides the second status mark, please refer to the description in Scenario 2 for details, which will not be repeated here.
[0277] For details about how the Hungdetect watchdog detects the kernel system, the kernel system performs the third feeding operation on the Hungdetect watchdog, and when to restart the kernel system, please refer to the description of the Hungdetect watchdog detecting the kernel system of this layer in Scenario 1 or Scenario 2. We will not repeat them here.
[0278] The following combination Figure 10 The focus is on writing the second feeding operation and the second status flag into the public node of the kernel layer, and the public node decides whether the dead detection watchdog performs the reset operation instead of directly giving it to the hungdetect watchdog.
[0279] For example, in a specific implementation, a preset policy may be pre-installed in the public node according to business requirements, that is, a policy for deciding whether the stuck detection watchdog performs a reset operation.
[0280] Therefore, the public node will decide whether the Hungdetect watchdog needs to perform a reset operation based on the preset strategy, the obtained dog feeding information and the status mark.
[0281] Regarding the watchdog feeding information obtained above, in some implementation scenarios, the information obtained may be that the SystemServer WatchDog is normal. In this case, it indicates that the System Server process it detects is also normal, and the System Server WatchDog is feeding the Hungdetect watchdog normally.
[0282] Correspondingly, in other implementation scenarios, the information that the System Server WatchDog is invalid, or the System Server WatchDog is normal but the System Server process detected by the System Server WatchDog is abnormal, the System Server WatchDog stops providing the Hungdetect watchdog with the feeding information, i.e., the second feeding operation cannot be performed, or the feeding of the Hungdetect watchdog by the System Server WatchDog is abnormal, can also be obtained.
[0283] Regarding the state flag mentioned above, in some implementation scenarios, the flag can be a normal flag, i.e., both the Xcollie and the SurfaceFlinger are normal. In other implementation scenarios, the flag can be an abnormal flag, i.e., at least one of the Xcollie and the SurfaceFlinger is abnormal.
[0284] Correspondingly, the common node can obtain the decision information through processing.
[0285] For example, in some implementation manners, the decision information obtained by the common node can be actively pushed to the Hungdetect watchdog, or can be actively acquired by the Hungdetect watchdog from the common node.
[0286] Taking the decision information that the Hungdetect watchdog needs to perform the reset operation as an example, in one scenario, when the common node determines that the Hungdetect watchdog needs to perform the reset operation, the common node actively notifies the Hungdetect watchdog to perform the reset operation. In another scenario, when the common node determines that the Hungdetect watchdog needs to perform the reset operation, the common node can first save the decision information, wait for the Hungdetect watchdog to periodically acquire the decision information decided by the common node from the common node, and then perform the reset operation when the reset instruction is acquired.
[0287] Correspondingly, when the decision information that the Hungdetect watchdog does not need to perform the reset operation is obtained, the Hungdetect watchdog can be uniformly sent with the agreed feeding information to implement the feeding, so as to avoid the Hungdetect watchdog from triggering the dog bark or even the dog bite.
[0288] Further, in some implementations, a common node in the kernel layer is configured to store the kick information of the software watchdog and the sent process state information of the Hungdetect watchdog. The kick information can include the name of the software watchdog and the kick action, and the process state information can include the name of the software watchdog and the process state (OK or ERROR). The Hungdetect watchdog, as a consumer of the common node, can periodically check the kick information and the sent process state information (e.g., OK or ERROR) stored in the common node.
[0289] The Hungdetect watchdog determines whether to perform the operation of resetting the kernel system based on the kick information and / or the process state information obtained from the common node periodically and a preset policy. The preset policy can be the aforementioned preset decision and the priority of the information provided by each software watchdog, which will not be repeated here.
[0290] It should be understood that the above description is only an example for better understanding the technical solutions of the embodiments and is not the only limitation of the embodiments.
[0291] Scenario Four
[0292] In this scenario, a detection mechanism is arranged between the kernel layer and the hardware layer of the electronic device. For example, the Hungdetect watchdog in the kernel layer is detected by the hardware watchdog in the hardware layer.
[0293] Figure 11 An application scenario is shown by way of example.
[0294] As shown in Figure 11 , the Hungdetect watchdog is included in the kernel layer of the electronic device and is configured to detect whether the kernel system is running normally.
[0295] When the kernel system is running normally, the kernel system performs a first feeding operation on the Hungdetect watchdog periodically. When the kernel system cannot run normally, the kernel system stops the first feeding operation on the Hungdetect watchdog. If the Hungdetect watchdog does not receive the first feeding operation from the kernel system within one detection period or a plurality of (e.g., 3) consecutive detection periods, the Hungdetect watchdog restarts the kernel system.
[0296] As shown in Figure 11 , the hardware watchdog (Hardware WatchDog) is included in the hardware layer of the electronic device and is configured to detect the hardware chip.
[0297] When the program in the hardware chip runs normally, the hardware chip performs the second feeding operation on the hardware watchdog at regular intervals, such as setting the first time of the hardware watchdog to zero to make it start timing again. When the program in the hardware chip runs abnormally, the second feeding operation on the hardware watchdog is stopped.
[0298] When the hardware watchdog does not receive the second feeding operation from the hardware chip, if the first time increases to the first set value, the hardware chip is reset to restart the whole electronic device. Here, the detection period corresponding to the first time is the detection period of the hardware watchdog for detecting the hardware chip. The first timer in the hardware watchdog is used to implement the operation of the first time.
[0299] Continuing to refer to Figure 11 In addition to detecting the hardware chip, the hardware watchdog can also detect the Hungdetect watchdog, and reset the hardware chip when the Hungdetect watchdog is abnormal to restart the whole electronic device and restore the kernel system. The Hungdetect watchdog abnormality can refer to the Hungdetect watchdog failure, or the Hungdetect watchdog failing to successfully restart the kernel system.
[0300] When the Hungdetect watchdog runs normally and the kernel system it detects runs normally, the Hungdetect watchdog performs the third feeding operation on the Hungdetect watchdog at regular intervals, such as setting the second time of the hardware watchdog to zero to make it start timing again. When the Hungdetect watchdog cannot run normally or cannot successfully restart the kernel system, the Hungdetect watchdog stops the third feeding operation on the hardware watchdog.
[0301] As an optional implementation, the Hungdetect watchdog stops the third feeding operation on the hardware watchdog before triggering the kernel system reset (or restart).
[0302] When the hardware watchdog does not receive the third feeding operation from the Hungdetect watchdog, if the second time increases to the second set value, the hardware chip is reset to restart the whole electronic device. Here, the detection period corresponding to the second time is the detection period of the hardware watchdog for detecting the Hungdetect watchdog. The second timer in the hardware watchdog is used to implement the operation of the second time.
[0303] In this way, by setting the detection mechanism between the hardware layer and the kernel layer, the layered and hierarchical recovery of the electronic device is realized. Since the granularity of hardware restart is greater than that of kernel restart, when the kernel cannot be successfully restarted, hardware restart can greatly improve the success rate of recovering the kernel system, thereby avoiding the problem that the kernel layer of the electronic device repeatedly restarts the kernel system but fails to do so.
[0304] Scenario five
[0305] In this scenario, a detection mechanism is set between the kernel layer and the hardware layer of the electronic device. Taking the detection of the CPU core state watchdog in the kernel layer by the hardware watchdog in the hardware layer as an example, the watchdog detection method provided by the present application is explained and described.
[0306] Figure 12 An application scenario diagram is shown for illustration.
[0307] As Figure 12 shown, the CPU core state watchdog is included in the kernel layer of the electronic device, which is used to check the running state of the CPU and control the kernel to restart when the running state of the CPU meets the preset kernel restart condition.
[0308] Specifically, the CPU core state watchdog can be used to detect the running state of each CPU core and control the kernel to restart when the running state of each CPU core meets the preset kernel restart condition.
[0309] The CPU core state watchdog periodically acquires the running state of each CPU core and controls the kernel to restart when the running state of the CPU meets the preset kernel restart condition. For example, the CPU core state watchdog acquires the running state of each CPU core every 30 seconds and controls the kernel to restart when the running state of the CPU meets the preset kernel restart condition.
[0310] As an optional implementation, the CPU core state watchdog can determine the running state of the CPU core based on whether the task on the CPU core can be scheduled, thereby realizing the detection of the CPU scheduling problem.
[0311] Among them, a target task is bound to each core of the CPU, and the target task runs regularly on the bound CPU core. For example, the target task runs on the CPU core to which it is bound once every 30 seconds. The CPU core status watchdog regularly detects whether the target tasks bound to each CPU core can be scheduled through the first detection task, thereby determining the running status of each CPU core. For example, the first detection task checks once every 30 seconds whether the target tasks bound to each CPU core can be scheduled. If the target task on a certain CPU core cannot be scheduled, the CPU core status watchdog can determine that the running status of the CPU core is abnormal; if the target task on a certain CPU core can be scheduled, the CPU core status watchdog can determine that the running status of the CPU core is normal.
[0312] like Figure 13 As shown, the CPU of the electronic device includes eight cores, namely CPU0, CPU1, CPU2, ..., CPU7. Each CPU core is bound to a target task, for example, CPU0 is bound to target task Tast 0, CPU1 is bound to target task Tast 1, CPU2 is bound to target task Tast 2, ..., and CPU7 is bound to target task Tast 7. Each target task is scheduled to run on the CPU core to which it is bound, for example, target task Tast 0 is scheduled to run on CPU0, target task Tast 1 is scheduled to run on CPU1, target task Tast 2 is scheduled to run on CPU2, ..., and target task Tast 7 is scheduled to run on CPU7.
[0313] The CPU core status watchdog periodically detects whether each target task (Tast 0-Tast 7) can be scheduled on the CPU core to which it is bound through the first detection task, thereby determining the operating status of each CPU core. Among them, the first detection task can run on any CPU core. For example, if Tast 0 cannot be scheduled on the CPU0 core to which it is bound, the CPU core status watchdog can determine that the operating status of the CPU0 core is abnormal. For example, if Tast 7 can be scheduled on the CPU0 core to which it is bound, the CPU core status watchdog can determine that the operating status of the CPU7 core is normal. In this way, the CPU core status watchdog can determine the operating status of each CPU core.
[0314] For example, when the running state of the CPU core is "1", the CPU core runs normally; when the running state of the CPU core is "0", the CPU core runs abnormally. Further, the first detection task detects whether each target task can be scheduled on the CPU core bound to the target task at a time, and generates a running state identifier corresponding to each CPU core according to a detection result, and then the CPU core state watchdog determines whether the running state of each CPU core is abnormal according to the running state identifier generated by the first detection task. The number of bits in the running state identifier is the same as the number of CPU cores. For example, the CPU includes 8 cores, CPU0 core, CPU1 core, CPU2 core,..., CPU7 core, and the running state identifier includes 8 bits, and the values of the 8 bits identify the running state of each CPU core in turn. Assuming that the running state identifier generated by the first detection task is "111111101", the CPU core state watchdog can determine that the running state of the CPU6 core is abnormal, and the running state of the remaining CPU cores is normal.
[0315] As another optional implementation, the CPU core state watchdog can determine the running state of the CPU core based on the probe message.
[0316] The CPU core state watchdog can determine the running state of the CPU core based on the probe message through the second detection task. For example, the CPU core state watchdog can determine the running state of the CPU core based on the probe message through the second detection task every 30 seconds.
[0317] For example, the CPU core state watchdog can determine that the running state of the CPU core is normal if the CPU core state watchdog sends a probe message to the CPU core in the online state through the second detection task and receives the probe feedback message sent by the CPU core in response to the probe message, otherwise, the CPU core state watchdog determines that the running state of the CPU core is abnormal. It should be noted that the CPU core state watchdog can not probe the running state of the CPU core in the offline state.
[0318] Optionally, the probe message can be a ping message. The CPU core state watchdog can send the ping message to the CPU core in the form of an interrupt through the second detection task, and the CPU core sends the feedback message in the form of an interrupt in response to the ping message, so as to realize the detection of the CPU interrupt storm by the CPU core state watchdog.
[0319] As Figure 14As shown, the CPU of the electronic device includes 8 cores, namely, a CPU0 core, a CPU1 core, a CPU2 core, …, and a CPU7 core. The CPU core state watchdog sends a ping message to the CPU core in the online state in turn through the second detection task, and if a feedback message sent by the CPU core in response to the ping message is received, it is determined that the CPU core can respond normally, and the running state of the CPU core is determined to be normal, otherwise, the CPU core cannot respond normally, and the running state of the CPU core is determined to be abnormal. For example, if the CPU core state watchdog can receive the feedback message sent by the CPU0 core in response to the ping message after sending the ping message to the CPU0 core in the online state through the second detection task, it is determined that the running state of the CPU0 core is normal. For another example, if the CPU core state watchdog cannot receive the feedback message sent by the CPU1 core in response to the ping message after sending the ping message to the CPU1 core in the online state through the second detection task, it is determined that the running state of the CPU1 core is abnormal. In this way, the CPU core state watchdog can determine the running state of each CPU core.
[0320] After determining the running state of each core of the CPU, the CPU core state watchdog determines whether the running state of each core of the CPU satisfies a preset core restart condition, and if so, controls to restart the core. The preset core restart condition is not limited in the embodiment.
[0321] For example, if the number of CPU cores with abnormal running states exceeds a preset number threshold, the CPU core state watchdog determines that the running state of each core of the CPU satisfies the preset core restart condition, and controls to restart the core.
[0322] For another example, if the running state of the CPU target core is abnormal, the CPU core state watchdog determines that the running state of each core of the CPU satisfies the preset core restart condition, and controls to restart the core. The CPU target core is a CPU core of a preset type, for example, a CPU large core or a core that is relatively important in the CPU. For example, if the CPU0 core is a CPU large core, when the running state of the CPU0 core is abnormal, the CPU core state watchdog determines that the running state of each core of the CPU satisfies the preset core restart condition, and controls to restart the core.
[0323] As an optional implementation, the CPU core state watchdog can determine the first running state of the CPU core based on whether the task on the CPU core can be scheduled, and the second running state of the CPU core based on the detection message. When the first running state and the second running state of a certain CPU core both indicate abnormality, the CPU core state watchdog determines that the CPU core runs abnormally.
[0324] As another optional implementation, the CPU core state watchdog can determine a first running state of the CPU core based on whether a task on the CPU core can be scheduled, and a second running state of the CPU core based on the probe message. When either the first running state or the second running state of a certain CPU core indicates an exception, the CPU core state watchdog determines that the CPU core is abnormal.
[0325] As shown in FIG. 1, the electronic device includes a hardware watchdog in a hardware layer of the electronic device. Figure 12
[0326] When the program in the hardware chip runs normally, the hardware chip performs a second feeding operation on the hardware watchdog at a regular time, such as setting the first timer of the hardware watchdog to zero to restart the timer. When the program in the hardware chip runs abnormally, the second feeding operation on the hardware watchdog is stopped.
[0327] When the hardware watchdog does not receive the second feeding operation from the hardware chip, if the first timer increases to a first set value, the hardware watchdog resets the hardware chip to restart the entire electronic device. Here, the detection period corresponding to the first timer is the detection period of the hardware watchdog for detecting the hardware chip. The first timer in the hardware watchdog is used to implement the first timer operation.
[0328] Continuing to refer to Figure 12 , the hardware watchdog can detect not only the hardware chip but also the CPU core state watchdog, and reset the hardware chip when the CPU core state watchdog is abnormal to restart the entire electronic device and restore the kernel system. The CPU core state watchdog abnormality can refer to the failure of the CPU core state watchdog or the inability of the CPU core state watchdog to successfully restart the kernel system.
[0329] When the CPU core state watchdog runs normally and the CPU core state detected by the CPU core state watchdog does not meet the preset kernel restart condition, the CPU core state watchdog performs a third feeding operation on the Hungdetect watchdog at a regular time, such as setting the second timer of the hardware watchdog to zero to restart the timer. When the CPU core state watchdog cannot run normally or cannot successfully restart the kernel system, the CPU core state watchdog stops the third feeding operation on the hardware watchdog.
[0330] As an optional implementation, the CPU core state watchdog stops the third feeding operation on the hardware watchdog before triggering the kernel system reset (or restart).
[0331] When the second time count increases to the second set value without receiving the third feeding operation of the CPU core state watchdog, the hardware watchdog resets the hardware chip to restart the electronic device. Here, the detection period corresponding to the second time count is the detection period of the hardware watchdog for detecting the CPU core state watchdog. The second timer in the hardware watchdog is used to implement the second time count.
[0332] In an embodiment, the hardware watchdog can detect not only the hardware chip but also the CPU core state watchdog and the Hungdetect watchdog in the kernel layer. In this case, the hardware watchdog can be provided with a second timer and a third timer for detecting the feeding operation of the CPU core state watchdog and the Hungdetect watchdog to the hardware watchdog, respectively. For example, when the hardware watchdog does not receive the feeding operation of the CPU core state watchdog, if the second time count increases to the second set value, the hardware watchdog resets the hardware chip to restart the electronic device. When the hardware watchdog does not receive the feeding operation of the Hungdetect watchdog, if the third time count increases to the third set value, the hardware watchdog resets the hardware chip to restart the electronic device. Here, the detection period corresponding to the second time count is the detection period of the hardware watchdog for detecting the CPU core state watchdog; and the detection period corresponding to the third time count is the detection period of the hardware watchdog for detecting the Hungdetect watchdog. The embodiment does not limit the size of the first set value, the second set value, and the third set value.
[0333] If the hardware watchdog can also detect other watchdogs in the kernel layer, the processing manner can refer to the detection of the Hungdetect watchdog or the CPU core state watchdog by the hardware watchdog, which will not be described herein.
[0334] In this way, by setting the detection mechanism between the hardware layer and the kernel layer, the layered and hierarchical recovery of the electronic device is achieved. Since the granularity of hardware restart is greater than that of kernel restart, when the kernel cannot be successfully restarted, hardware restart can greatly improve the success rate of recovering the kernel system, thereby avoiding the problem that the kernel system cannot be successfully restarted repeatedly in the kernel layer of the electronic device.
[0335] Scenario six
[0336] In this scenario, the detection mechanism is set between the application framework layer and the kernel layer of the electronic device and between the kernel layer and the hardware layer, and the Hungdetect watchdog in the kernel layer can simultaneously detect multiple software watchdogs in the application framework layer.
[0337] Figure 15 An application scenario shown by way of example is schematically shown in the following figure.
[0338] As shown in Figure 15 System Server WatchDog, Xcollie and Init watchdog are included in the application framework layer of the electronic device. Among them, System Server WatchDog is used to detect the System Server process in the application framework layer, such as detecting whether the System Server process has deadlock, no response and other problems. Xcollie is used to detect whether the action performed by the key process SurfaceFlinger is completed, such as detecting whether the UI operation of the rendering system is completed. Init watchdog is used to detect the Init process, such as detecting whether the electronic device shutdown and startup process is abnormal.
[0339] Hungdetect watchdog and CPU core state watchdog are included in the kernel layer of the electronic device. Among them, Hungdetect watchdog is used to detect the kernel system, such as detecting whether the kernel system is deadlocked. CPU core state watchdog is used to detect the running state of each core of the CPU, such as detecting whether each CPU core is running abnormally.
[0340] Hardware watchdog is included in the hardware layer of the electronic device. Among them, Figure 15 The first hardware watchdog, the second hardware watchdog and the third hardware watchdog shown in Figure 15 The first hardware watchdog, the second hardware watchdog and the third hardware watchdog shown in
[0341] Referring to Figure 15 In this embodiment, the kernel layer Hungdetect watchdog can not only detect the kernel system, but also detect the System Server WatchDog, Xcollie and Init watchdog in the application framework layer.
[0342] In this embodiment, the kernel layer sets a common node for storing the Hungdetect watchdog information kicked by the software watchdog in the application framework layer, and the process state information sent. Hungdetect watchdog, as a consumer of the common node, can regularly (or periodically) check the Hungdetect watchdog information stored in the common node, and the process state information (such as OK or ERROR) sent.
[0343] Further, the Hungdetect watchdog periodically acquires the kick-dog information stored in the public node and the process state information, and determines whether to perform a kernel restart operation according to a preset strategy.
[0344] Optionally, when the Hungdetect watchdog detects an exception of any software watchdog in the application framework layer, the Hungdetect watchdog performs a kernel restart operation to recover the corresponding process in the application framework layer through the kernel restart.
[0345] Optionally, when the Hungdetect watchdog detects exceptions of multiple software watchdogs in the application framework layer, the Hungdetect watchdog performs a kernel restart operation to recover the corresponding process in the application framework layer through the kernel restart.
[0346] Optionally, when the Hungdetect watchdog detects an exception of any software watchdog in the application framework layer for multiple continuous periods, the Hungdetect watchdog performs a kernel restart operation to recover the corresponding process in the application framework layer through the kernel restart.
[0347] For example, for three periods, assume that the Hungdetect watchdog does not acquire the kick-dog information of the System Server WatchDog for three continuous periods, or acquires the process state information sent by the Xcollie for three continuous periods and the process state information is ERROR, and then a kernel restart operation is performed.
[0348] Similarly, in the embodiment, the first hardware watchdog in the hardware layer can detect not only the hardware chip but also the Hungdetect watchdog and the CPU core state watchdog in the kernel layer.
[0349] If the Hungdetect watchdog or the CPU core state watchdog does not perform the kick-dog operation on the first hardware watchdog in time, the first hardware watchdog resets the hardware chip detected thereby, and restarts the whole machine to recover the kernel system through the restart of the whole machine.
[0350] For the details not explained in the scene, refer to the description in the foregoing scene, which will not be repeated here.
[0351] In this way, by setting the detection mechanism between the electronic device layers, the layered and hierarchical recovery of the electronic device is achieved. Since the granularity of the next recovery is greater than that of the upper layer recovery, when the upper layer cannot be successfully recovered, the success rate of the upper layer recovery is improved through the lower layer restart, and the problem that a certain layer of the electronic device repeatedly restarts but cannot be successfully recovered is also avoided.
[0352] In addition, it should be noted that, in order to adapt the watchdog detection method provided in the present application to different chip platforms, so as to realize multi-level dog care and achieve comprehensive coverage of the electronic device, and ensure that the electronic device can be used normally, a pre-packaged adaptation node can also be set in the kernel layer, so that the CPU core state watchdog and Hungdetect watchdog in the kernel layer can be detected by the hardware watchdog provided by different chip platforms.
[0353] For example, because the hardware watchdogs of different platforms require different time to load, in the same time, the dog-feeding information provided by the CPU core state watchdog is not acquired, for different hardware watchdogs, some of them can be considered normal, and some of them can be considered abnormal, and then the dog barking and even dog biting are executed. Therefore, in order to ensure that the technical solution of the present application can adapt to different hardware watchdogs, when the electronic device is started, the closing interface of the hardware watchdog can be called to close it, and after the upper-layer software watchdogs are started, the hardware watchdog is started.
[0354] In addition, in the specific implementation, in order to simplify the calling program and avoid code redundancy, the interfaces for initializing the hardware dog, triggering the dog biting (executing the reset), and stopping the dog feeding can be uniformly packaged, and then the processing logic of the hardware dog currently used by the electronic device is called through the uniform interfaces, so that one set of solutions can adapt to different hardware watchdogs.
[0355] The embodiment also provides a computer storage medium, which stores computer instructions, and when the computer instructions run on an electronic device, the electronic device executes the related method steps to implement the watchdog detection method in the above embodiment.
[0356] The embodiment also provides a computer program product, which, when running on a computer, causes the computer to execute the related steps to implement the watchdog detection method in the above embodiment.
[0357] In addition, the embodiment of the present application also provides a device, which can be a chip, a component or a module. The device can include a processor and a memory connected to each other. The memory is used to store computer execution instructions. When the device runs, the processor can execute the computer execution instructions stored in the memory, so that the chip executes the watchdog detection method in the above method embodiments.
[0358] The electronic device, the computer storage medium, the computer program product or the chip provided in the embodiment can be used to execute the corresponding method provided above, and therefore the beneficial effects achieved thereby can refer to the beneficial effects of the watchdog detection method provided above, which will not be described herein again.
[0359] Through the description of the above embodiments, those skilled in the art can understand that, for the convenience and brevity of description, only the division of the above functional modules is exemplified, and in actual application, the above functions can be completed by different functional modules according to needs, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above.
[0360] In several embodiments provided in the present application, it should be understood that the disclosed device and method can be implemented in other ways. For example, the device embodiments described above are only illustrative, for example, the division of modules or units is only a logical function division, and actual implementation can have another division manner, for example, a plurality of units or components can be combined or integrated into another device, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the displayed or discussed ones can be indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0361] The above description and the above embodiments are only used to illustrate the technical solutions of the present application, but not to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that the technical solutions recorded in the foregoing embodiments can be modified, or some technical features can be replaced by equivalents; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the scope of the technical solutions of the embodiments of the present application.
Claims
1. A watchdog detection method, characterized in that: Used in electronic equipment, including: During the initialization of the system service process, a first watchdog is started; wherein the first watchdog is used to detect the system service process and restart the system service process when the system service process is abnormal; the system service process is located in the application framework layer of the electronic device; Before the system service process is initialized, during the kernel system initialization, the second watchdog is started; After the system service process is started, the second watchdog starts a detection function of the first watchdog; wherein the second watchdog is located in the kernel layer of the electronic device, and the second watchdog is also used to detect the kernel system; The second watchdog restarts the kernel system when the first watchdog fails or the first watchdog cannot restore the system service process.
2. The method according to claim 1, characterized in that Also includes: When the second watchdog detects an abnormality in the kernel system, it restarts the kernel system.
3. The method according to claim 1, characterized in that The second watchdog starts a detection function of the first watchdog, including: If the second watchdog receives the indication information, it starts the detection function of the first watchdog; wherein the indication information is used to instruct the system service process to perform an initialization operation.
4. The method according to claim 1, wherein Also includes: When the system service process is normal, the first watchdog periodically feeds the second watchdog; When the system service process is abnormal, the first watchdog stops feeding the second watchdog; If the second watchdog does not receive the feeding operation of the first watchdog within one or more consecutive detection cycles, it is determined that the first watchdog is abnormal.
5. The method according to claim 1, wherein Also includes: The system service process periodically detects whether the target service is running normally; wherein the target service is running in the system service process; If the target service runs normally, the system service process feeds the first watchdog; If the target service runs abnormally, the system service process stops feeding the first watchdog; If the first watchdog does not receive a dog feeding operation from the system service process within one or more consecutive detection cycles, it is determined that the system service process is abnormal.
6. The method according to claim 5, characterized in that The target service at least includes a window management service, a run management service, and a package management service.
7. The method according to claim 1, characterized in that The second detection period is an integer multiple of the first detection period; wherein, The first detection period is a detection period of the first watchdog on the system service process, and the second detection period is a detection period of the second watchdog on the first watchdog.
8. An electronic device, characterized in that: include: one or more processors; One or more memories; the one or more memories store one or more programs, and when the one or more programs are executed by the one or more processors, the electronic device executes the watchdog detection method according to any one of claims 1 to 7.
9. A computer-readable storage medium comprising a computer program, characterized in that When the computer program is run on an electronic device, the electronic device is enabled to execute the watchdog detection method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Watch-dog implementation method and device based on Nios II system
CN103645962A
Multi-core embedded PLC software restoration method and PLC
CN107315656A