Gatekeeper detection method, system, and electronic device
By introducing a hierarchical watchdog detection mechanism into electronic devices, and using a second-layer watchdog to reset or restart the second service when the first-layer watchdog malfunctions, the problem of software watchdogs being unable to recover service processes is solved, thus achieving stable operation of the equipment.
Patent Information
- Application Number
- CN202210018490.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-07
- Publication Date
- 2025-11-21
- Estimated Expiration
- 2042-01-07
AI Technical Summary
Under uncontrollable interference, the software watchdog may fail to successfully reset the detected business process, thus affecting the normal use of the device.
Introducing a hierarchical watchdog detection mechanism into electronic devices allows for the reset or restart of the second-level service when the first-level watchdog malfunctions, thereby restoring the first-level service and ensuring the hierarchical recovery of the device.
When the first-layer watchdog fails to restore services, the second-layer intervention ensures stable operation of the device, avoiding the problem of the device failing due to repeated resets or restarts.
Smart Images

Figure CN116450389B_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 system 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 business process or hardware when an abnormality occurs in the business process or hardware detected by the watchdog, so as to restore the business process or hardware detected by the watchdog to normal.
[0003] Although the software watchdog can restore the business process detected thereby, in actual application, due to uncontrollable interference factors, the software watchdog can not successfully reset the business process detected thereby, or even the software watchdog fails, thereby affecting normal use of the device. SUMMARY
[0004] In order to solve the above technical problem, the present application provides a watchdog detection method and system and an electronic device. In the watchdog detection system, when a first watchdog in a first layer of the electronic device fails to successfully restore a first business detected thereby, the first business in the first layer can be restored through a second layer (i.e. the next layer), that is, the first business is reloaded and run after the second business is reset or restarted, so that the first business in the first layer is restored to normal. That is, a detection mechanism is provided between the layers of the electronic device, and the technical effect of hierarchical restoration of the electronic device can be achieved.
[0005] In a first aspect, the application provides a watchdog detection system. The watchdog detection system is applied to an electronic device, and the electronic device system architecture comprises a first layer and a second layer, wherein the first layer is an upper layer of the second layer. The watchdog detection system comprises: a first watchdog and a second watchdog, the first watchdog is located in the first layer, and the second watchdog is located in the second layer; wherein the first watchdog is configured to detect a first service in the first layer and reset the first service when the first service is abnormal; the second watchdog is configured to detect a second service in the second layer and reset the second service when the second service is abnormal; and the second watchdog is further configured to detect the first watchdog and reset the second service when the first watchdog is abnormal. In this way, when the first watchdog in the first layer of the electronic device fails to successfully recover the first service detected thereby, the first service in the first layer can be recovered through the second layer (i.e. the next layer), i.e. 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. The detection mechanism is provided between the layers of the electronic device, and the technical effect of hierarchical recovery of the electronic device is achieved.
[0006] When the first watchdog is a software watchdog, the second watchdog can be a software watchdog or a hardware watchdog.
[0007] For example, the electronic device system architecture can be an Android system architecture.
[0008] According to the first aspect, the first watchdog abnormality includes a failure of the first watchdog or the first watchdog failing to recover the first service. In this way, whether the first watchdog fails or the first watchdog fails to successfully recover the first service when the first service is abnormal, the second watchdog can recover the first service by recovering the second service.
[0009] According to the first aspect, or any one of the implementation manners of the first aspect, the first watchdog is configured to perform a feeding operation on the second watchdog at a regular time when the first service is normal, and stop the feeding operation on the second watchdog when the first service is abnormal; and the second watchdog is configured to reset the second service when the feeding operation of the first watchdog is not received within one or continuous multiple detection periods.
[0010] According to the first aspect, or any one of the implementation manners of the first aspect, the first watchdog is configured to send state information of the first service to the second watchdog; wherein the state information of the first service is set to a normal flag by the first watchdog when the first service is normal, and the state information of the first service is set to an abnormal flag by the first watchdog when the first service is abnormal; and the second watchdog is configured to reset the second service when the state information received within one or continuous multiple detection periods is all the abnormal flag.
[0011] According to the first aspect, or any one of the implementations of the first aspect, when the first watchdog and the second watchdog are both software watchdogs, the second detection period is longer than the first detection period; wherein the first detection period is a detection period of the first watchdog on the first service, 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 service is recovered by the first watchdog first, and then the second service is recovered by the second watchdog when the first watchdog fails to successfully recover the first service, so as to ensure the effect of hierarchical recovery of the electronic device.
[0012] According to the first aspect, or any one of the implementations of the first aspect, the second detection period is an integer multiple of the first detection period.
[0013] According to the first aspect, or any one of the implementations of the first aspect, the electronic device system architecture is an Android system architecture; wherein the first layer is an application framework layer, and the second layer is a kernel layer; and / or the first layer is a kernel layer, and the second layer is a hardware layer.
[0014] The second aspect, the present application provides a watchdog detection method. The watchdog detection method is applied to an electronic device, and the electronic device system architecture includes a first layer and a second layer, wherein the first layer is an upper layer of the second layer. The watchdog detection method comprises: a first watchdog detects a first service in the first layer, and resets the first service when the first service is abnormal; wherein the first watchdog is located in the first layer; a second watchdog detects a second service in the second layer, and resets the second service when the second service is abnormal; wherein the second watchdog is located in the second layer; and the second watchdog detects the first watchdog, and resets the second service when the first watchdog is abnormal.
[0015] According to the second aspect, the second watchdog resets the second service when the first watchdog is abnormal, comprising: the second watchdog resets the second service when the first watchdog is invalid or the first watchdog fails to recover the first service.
[0016] According to the second aspect, or any one of the implementations of the second aspect, the watchdog detection method further comprises: the first watchdog performs a feeding operation on the second watchdog at a regular time when the first service is normal; and the first watchdog stops the feeding operation on the second watchdog when the first service is abnormal. Correspondingly, the second watchdog detects the first watchdog, and resets the second service when the first watchdog is abnormal, comprising: the second watchdog resets the second service when the feeding operation of the first watchdog is not received within one or more continuous detection periods.
[0017] According to a second aspect, or any possible implementation mode of the second aspect, the watchdog detection method further comprises: the first watchdog setting the status information of the first service as a normal mark when the first service is normal, and sending the status information of the first service to the second watchdog; and the first watchdog setting the status information of the first service as an abnormal mark when the first service is abnormal, and sending the status information of the first service to the second watchdog. Correspondingly, the second watchdog detects the first watchdog, and resets the second service when the first watchdog is abnormal, comprising: the second watchdog resetting the second service when the status information received by the second watchdog in one or continuous multiple detection periods is all abnormal marks.
[0018] According to the second aspect, or any possible implementation mode of the second aspect, when the first watchdog and the second watchdog are both software watchdogs, the second detection period is longer than the first detection period; wherein the first detection period is a detection period of the first watchdog on the first service, and the second detection period is a detection period of the second watchdog on the first watchdog.
[0019] According to the second aspect, or any possible implementation mode of the second aspect, the second detection period is an integer multiple of the first detection period.
[0020] According to the second aspect, or any possible implementation mode of the second aspect, the electronic device architecture is an Android system architecture; wherein the first layer is an application framework layer, and the second layer is a kernel layer; and / or the first layer is a kernel layer, and the second layer is a hardware layer.
[0021] The second aspect and any possible implementation mode of the second aspect correspond to the first aspect and any possible implementation mode of the first aspect respectively. The technical effects of the second aspect and any possible implementation mode of the second aspect can refer to the technical effects of the first aspect and any possible implementation mode of the first aspect, which will not be described herein.
[0022] In a third 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, when the one or more programs are executed by the one or more processors, the electronic device executes the watchdog detection method of the second aspect and any one of the second aspect.
[0023] The third aspect and any possible implementation mode of the third aspect correspond to the second aspect and any possible implementation mode of the second aspect respectively. The technical effects of the third aspect and any possible implementation mode of the third aspect can refer to the technical effects of the second aspect and any possible implementation mode of the second aspect, which will not be described herein.
[0024] In a fourth aspect, the present application provides a computer readable medium, which comprises a computer program, and when the computer program is run on an electronic device, the computer program causes the electronic device to execute the watchdog detection method in the second aspect and any one of the implementation manners of the second aspect.
[0025] The fourth aspect and any one of the implementation manners of the fourth aspect correspond to the second aspect and any one of the implementation manners of the second aspect respectively. The technical effects corresponding to the fourth aspect and any one of the implementation manners of the fourth aspect can refer to the technical effects corresponding to the second aspect and any one of the implementation manners of the second aspect, which will not be described herein again. BRIEF DESCRIPTION OF DRAWINGS
[0026] Figure 1 A schematic diagram of a hardware structure of an electronic device is exemplarily shown;
[0027] Figure 2 A schematic diagram of a software structure of an electronic device is exemplarily shown;
[0028] Figure 3 A schematic diagram of a system architecture corresponding to the watchdog detection method provided by the embodiment of the present application is exemplarily shown;
[0029] Figure 4 A first schematic diagram of a flow of the watchdog detection method provided by the embodiment of the present application is exemplarily shown;
[0030] Figure 5 A schematic diagram of an application scenario to which the watchdog detection method shown in Figure 4 applies is shown;
[0031] Figure 6 A second schematic diagram of a flow of the watchdog detection method provided by the embodiment of the present application is exemplarily shown;
[0032] Figure 7 A third schematic diagram of a flow of the watchdog detection method provided by the embodiment of the present application is exemplarily shown;
[0033] Figure 8 A schematic diagram of an application scenario to which the watchdog detection method shown in Figure 7 applies is shown;
[0034] Figure 9 A fourth schematic diagram of a flow of the watchdog detection method provided by the embodiment of the present application is exemplarily shown;
[0035] Figure 10 A schematic diagram of an application scenario to which the watchdog detection method shown in Figure 9 applies is shown;
[0036] Figure 11Yet another schematic diagram of an application scenario to which the watchdog detection method exemplarily shown is applicable;
[0037] Figure 12 Yet another schematic diagram of an application scenario to which the watchdog detection method exemplarily shown is applicable;
[0038] Figure 13 One of the CPU core state detection schematic diagrams exemplarily shown;
[0039] Figure 14 One of the CPU core state detection schematic diagrams exemplarily shown;
[0040] Figure 15 Yet another schematic diagram of an application scenario to which the watchdog detection method exemplarily shown is applicable. DETAILED DESCRIPTION
[0041] The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only some of the embodiments of the present application, but not all the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative work fall within the scope of the present application.
[0042] The term "and / or" in the present document is only used to describe the association relationship of the associated objects, and means that there can be three relationships, for example, A and / or B can mean that there are three cases of A alone, A and B together, and B alone.
[0043] 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.
[0044] 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 scheme described as "exemplary" or "for example" in the embodiments of the present application should not be construed as being more preferred or advantageous than other embodiments or design schemes. Rather, the use of the words "exemplary" or "for example" is intended to present the relevant concept in a specific manner.
[0045] 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.
[0046] Figure 1A structural diagram of the 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.
[0047] 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 charge 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.
[0048] 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 integrated into one or more processors.
[0049] 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 instruction fetching and instruction execution.
[0050] 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 realize 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 conforms to 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. It 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 AR devices, and the like.
[0051] In addition, it should be noted that in some embodiments, the processor 110 can be built-in hardware watchdog, for example, a timer in the processor 110 as a hardware watchdog. The processor 110 initializes the timer through the program, writes the 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.
[0052] In some other embodiments, a separate watchdog chip can be provided in the electronic device 100 as a hardware watchdog for detecting the processor 110. The watchdog chip mainly includes a watchdog feeding pin (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.
[0053] 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.
[0054] 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.
[0055] 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.
[0056] 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.
[0057] 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.
[0058] 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.
[0059] 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.
[0060] 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.
[0061] 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.
[0062] 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.
[0063] 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.
[0064] Microphone 170C, also called "microphone", "microphone", is used to convert sound signals into electrical signals.
[0065] 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.
[0066] 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.
[0067] 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.
[0068] 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.
[0069] 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.
[0070] Figure 2 is the software structure block diagram of electronic device 100 of the embodiment of the present application.
[0071] 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.
[0072] Application layer can include a series of application packages.
[0073] AsFigure 2 As shown, the application package can include applications such as camera, gallery, calendar, call, map, navigation, music, video, and SMS.
[0074] The application framework layer provides application programming interfaces (APIs) and a programming framework for applications in the application layer. The application framework layer includes some predefined functions.
[0075] like Figure 2 As shown, the application framework layer may include System Server, System Server Watchdog, SurfaceFlinger, Xcollie (a watchdog for critical system tasks timeouts), Initiation Service, and Initiation Service Watchdog.
[0076] System Server is the provider of basic services for Android and is a fundamental requirement for the operation of the Android system. Some services in the system reside in System Server, such as WMS (Window Manager Server), AMS (Activity Manager System Service), and PMS (Package Manager Server). These services all exist as a thread in the System Server process.
[0077] System Server WatchDog is used to detect problems such as deadlocks and unresponsiveness in the System Server. When the System Server fails, System Server WatchDog kills the System Server process, enabling a soft reboot for self-recovery. The objects detected by System Server WatchDog are mainly divided into two categories: object locks and thread handlers.
[0078] The System Server WatchDog is initialized and started within the System Server process. When the System Server starts, various Android services are registered and started, including the initialization and start of the System ServerWatchDog.
[0079] 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.
[0080] 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.
[0081] In some implementations, SurfaceFlinger can also be set in the system library of the Android system, which is not limited in the present application.
[0082] 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.
[0083] For example, the key process can be SurfaceFlinger, Vold (volume daemon), AudioFlinger, Face Regconize (face recognition), etc.
[0084] 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.
[0085] Init is the first process in the user space of a Linux system, and is also the first process in the user space of an Android system based on a Linux kernel. The Init process is mainly responsible for parsing a property file and initializing a property, parsing a script init.rc, triggering an Action and starting a Service, providing system property service management and completing corresponding trigger events, and maintaining a system-level Service.
[0086] An Init watchdog is used to detect an Init process and reset the Init process when the Init process is abnormal.
[0087] The kernel layer is a layer between hardware and software.
[0088] As shown in FIG. 1, the kernel layer at least includes a Hungdetect watchdog and a CPU core state watchdog. Figure 2 The Hungdetect watchdog is used to detect a kernel system and control a kernel restart when a Kernel Panic occurs.
[0089] In this embodiment, the Hungdetect watchdog is also used to detect a System Server WatchDog, an Xcollie, and an Init watchdog, and control a kernel restart when any of the System Server WatchDog, the Xcollie, and the Init watchdog fails or a service detected by any of the System Server WatchDog, the Xcollie, and the Init watchdog cannot be recovered.
[0090] The CPU core state watchdog is used to detect a running state of each core of a CPU and control a kernel restart when a CPU core state meets a preset kernel restart condition.
[0091] In this embodiment, the hardware watchdog can also detect the Hungdetect watchdog and the CPU core state watchdog, for example, detect a reset action of the Hungdetect watchdog and the CPU core state watchdog. When any of the Hungdetect watchdog and the CPU core state watchdog fails or the Hungdetect watchdog and the CPU core state watchdog cannot successfully restart the kernel, the hardware watchdog can control a whole machine to restart.
[0092]
[0093] 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.
[0094] 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 described herein again.
[0095] 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.
[0096] 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 the form of 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.
[0097] 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.
[0098] It should be noted that the "layer" involved 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.
[0099] 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.
[0100] 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.
[0101] 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.
[0102] 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 marks of the first service acquired within a plurality of (e.g., 3) consecutive detection periods all indicate that the first service is abnormal, the first watchdog performs a reset or restart operation on the first service.
[0103] 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.
[0104] 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.
[0105] 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 marks of the second service acquired within a plurality of (e.g., 3) consecutive detection periods all indicate that the second service is abnormal, the second watchdog performs a reset or restart operation on the second service.
[0106] 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.
[0107] 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.
[0108] 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.
[0109] 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.
[0110] 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.
[0111] 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.
[0112] 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.
[0113] 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.
[0114] 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.
[0115] 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.
[0116] Scenario one
[0117] 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.
[0118] Figure 4 The flowchart of the System Server WatchDog executing the watchdog detection method is shown for illustrative purposes. As shown in Figure 4 The flowchart of the System Server WatchDog executing the watchdog detection method includes the following steps:
[0119] Step 101, initializing the system service watchdog during the startup of the system service process.
[0120] As can be seen from the above 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.
[0121] In step 102, the system service process detects whether it is running normally according to a preset period.
[0122] 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.
[0123] 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.
[0124] In step 103, the system service process sends first feeding information to the system service watchdog.
[0125] 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.
[0126] 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.
[0127] In step 104, the system service watchdog sends second feeding information to the deadlock detection watchdog located in the kernel layer.
[0128] 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.
[0129] 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.
[0130] The embodiment does not limit the timing of steps 103 and 104.
[0131] At step 105, during the feeding dog period, if the system service watchdog does not receive the first feeding dog information sent by the system service process, 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.
[0132] Specifically, in some implementations, in order to avoid frequent reset operations, i.e. restarts, on the system service process, which reduces the impact of the electronic device on the user, the system service watchdog can be set to perform a reset operation on the system service process if it does not receive the first feeding dog information sent by the system service process within a plurality of (e.g. 3) feeding dog periods, or detection periods.
[0133] 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 when it does not receive the first feeding dog information sent by the system service process within n feeding dog periods, and perform a dog bite when it does not receive the first feeding dog information sent by the system service process within (n+m) feeding dog periods.
[0134] For example, n is an integer greater than 0, and m is an integer greater than 0.
[0135] 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.
[0136] 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 abnormal logs through pre-compiled dump logic.
[0137] 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 second feeding dog information sent by the system service watchdog is not received 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.
[0138] 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.
[0139] 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.
[0140] 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.
[0141] 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.
[0142] 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.
[0143] 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.
[0144] 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 .
[0145] Figure 5 An application scenario is shown in the following application scenario diagram. As shown in Figure 5As shown, the application framework layer of the electronic device includes a System Server WatchDog, which is used to detect the System Server process in the application framework layer, such as whether the System Server process has deadlocked or become unresponsive.
[0146] The System Server process periodically checks whether the critical services running within it are functioning correctly. These critical services may include AMS and WMS. When all critical services running within the System Server process are functioning correctly, the System Server process periodically performs the first "feed" operation on the System Server WatchDog. This means the System Server process periodically sends the aforementioned first "feed" information to the System Server WatchDog, or the System Server WatchDog periodically retrieves the first "feed" information from the System Server process. If any critical service running within the System Server process fails to function correctly, the System Server process stops performing the first "feed" operation on the System Server WatchDog.
[0147] If the System Server WatchDog does not receive the first watchdog operation from the System Server process within a detection cycle or within several consecutive detection cycles (e.g., 3 cycles), it will restart the System Server process.
[0148] like Figure 5 As shown, the kernel layer of an electronic device includes a Hungdetect watchdog, which is used to detect whether the kernel system is running normally.
[0149] When the kernel system is running normally, it periodically performs a second "feed" operation on the Hungdetect watchdog timer. This means the kernel system periodically sends the aforementioned third "feed" information to the Hungdetect watchdog timer, or the Hungdetect watchdog timer periodically retrieves the third "feed" information from the kernel system. When the kernel system malfunctions, it stops performing the second "feed" operation on the Hungdetect watchdog timer.
[0150] If the Hungdetect watchdog does not receive a second dog-feed operation from the kernel system within one detection cycle or multiple consecutive detection cycles (e.g., 3 detection cycles), it will restart the kernel system.
[0151] 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.
[0152] 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.
[0153] 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.
[0154] 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. Alternatively, 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.
[0155] 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.
[0156] 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.
[0157] To solve this problem, the Hungdetect watchdog start time in the kernel layer is adjusted. After the System Server starts successfully, the Hungdetect watchdog detection function on the System Server WatchDog is started, rather than being started after the kernel system starts.
[0158] 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:
[0159] Step 11, in the process of initializing the system service process, the System Server WatchDog starts.
[0160] Step 12, the Hungdetect watchdog starts the detection function on the System Server WatchDog.
[0161] Step 13, the Hungdetect watchdog restarts the kernel system when the System Server WatchDog is abnormal.
[0162] 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 Hungdetect watchdog in the kernel layer will not feed the dog operation on the Hungdetect watchdog in the kernel layer. Until the System Server is successfully restarted, the Hungdetect watchdog will continue to feed the dog operation on the Hungdetect watchdog.
[0163] 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.
[0164] 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.
[0165] 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.
[0166] Scenario two
[0167] 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.
[0168] 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:
[0169] Step 201, initializing the system key task timeout detection watchdog, and setting the state information identifying the key process as a normal mark.
[0170] Specifically, the key process mentioned 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.
[0171] 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.
[0172] 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.
[0173] 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.
[0174] 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".
[0175] In addition, in some implementations, "1" can be agreed as the normal mark and "0" can be agreed as the abnormal mark as needed.
[0176] 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.
[0177] 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 call of the start node of the action performed by the key process.
[0178] 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.
[0179] For example, the system critical task timeout detection watchdog can know the start time of the action according to the call of the begin identification bit and know the end time of the action according to the call of the end identification bit.
[0180] In addition, the timeout duration for each action can be set according to the business characteristics and the time required for the action to be normally completed.
[0181] For example, for an action with a completion time of 5 ms (the time from the invocation start node to the invocation end node), the timeout duration can be 5 ms, or 8 ms, or n*5 ms. For example, n is an integer greater than 0.
[0182] 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.
[0183] At step 203, when the execution duration reaches the timeout time corresponding to the action, the system critical task timeout detection watchdog queries whether the end node of the action is invoked.
[0184] Specifically, when the execution duration reaches the timeout time corresponding to the action, but the end node is not invoked, i.e., timeout occurs, step 204 is performed; otherwise, step 206 is performed.
[0185] At step 204, the system critical task timeout detection watchdog modifies the state information of the critical process from the normal mark to the abnormal mark.
[0186] Specifically, when timeout occurs, it indicates that the action executed by the critical process is not completed, which can be caused by an abnormality of the critical process. Therefore, in order to enable the system critical task timeout detection watchdog or the critical process watchdog to perform the reset operation to enable the critical process to return to normal, the state information of the critical process needs to be modified from the normal mark to the abnormal mark, e.g., from "OK" to "ERROR". In this way, after the critical process performs the reset operation and is successfully initialized next time, "ERROR" can be modified back to "OK", and the system critical task timeout detection watchdog can continue to detect the action to be detected.
[0187] At step 205, the system critical task timeout detection watchdog sends the abnormal mark to the kernel layer to enable the deadlock detection watchdog to perform the reset operation.
[0188] It can be understood that, since the application program framework layer is located above the kernel layer, the system critical task timeout detection watchdog located in the application program framework has less impact on the electronic device when performing the reset operation than the deadlock detection watchdog located in the kernel layer. Therefore, in some implementations, before step 205 is performed, the system critical task timeout detection watchdog can perform the reset operation.
[0189] 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.
[0190] 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.
[0191] 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.
[0192] 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.
[0193] Manner 1:
[0194] 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.
[0195] Correspondingly, when the abnormal duration is less than the duration threshold, the system key task timeout detection watchdog re-performs the reset operation; and when the abnormal duration is not less than the duration threshold, step 205 is performed.
[0196] 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.
[0197] Manner 2:
[0198] 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.
[0199] 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, step 205 is executed.
[0200] 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.
[0201] 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.
[0202] 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.
[0203] 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.
[0204] Exemplarily, the preset strategy, i.e., 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, e.g., 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.
[0205] 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.
[0206] 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.
[0207] 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.
[0208] 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 a reset operation.
[0209] It should be noted that the hierarchical recovery mark described above can be set as needed in actual application, which is not limited herein.
[0210] 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.
[0211] 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.
[0212] 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.
[0213] Step 206, stopping detecting the action executed by the key process.
[0214] It can be understood that in actual application, the change of the key process state is shown in Table 1.
[0215] Table 1: Change table of key process state
[0216] Scenario State Initialization (init) Normal End of execution (end) Normal Execution timeout (Timeout) Abnormal
[0217] 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.
[0218] 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 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".
[0219] 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.
[0220] Therefore, the watchdog detection method provided in the embodiment can connect the Hungdetect watchdog of the kernel layer to the Xcollie by detecting the Xcollie, 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 above-mentioned hierarchical recovery principle, and further ensuring the normal use of the electronic device.
[0221] In order to better understand the implementation scheme of the Hungdetect watchdog for detecting the Xcollie, the following will be specifically described in combination with Figure 8 .
[0222] Figure 8An application scenario is shown in the following figure. As shown in the figure, an Xcollie is included in an application framework layer of an electronic device, which is used to detect whether an action performed by a key process SurfaceFlinger is completed, for example, whether a UI operation of a rendering system is completed. Figure 8
[0223] It can be understood that the SurfaceFlinger is started in a System Server process and is responsible for uniformly managing frame buffers of the device. In the process of starting, the SurfaceFlinger creates two threads, 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, the SurfaceFlinger can be used to manage the display subsystem and provide fusion of 2D and 3D layers for multiple applications.
[0224] The Xcollie is used to detect whether an action performed in a key process is completed. The Xcollie can set two threads, one of which (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 to set the state flag of the key process to abnormal according to whether the key process performs the action in time, and the other 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.
[0225] Based on the characteristics of the Xcollie and the SurfaceFlinger, it is continued to refer to Figure 8 The first state flag obtained by the Xcollie from the SurfaceFlinger is specifically obtained by the thread D in the Xcollie.
[0226] For example, in some implementations, the first state flag can be determined by the thread D in the Xcollie according to the console events detected by the thread A and / or the progress information of the rendering by the thread B in the SurfaceFlinger.
[0227] For example, in some other implementations, the information for determining the first state flag can be sent by the thread A and the thread B in the SurfaceFlinger to the Xcollie, and then the thread D in the Xcollie determines the first state flag according to the received information.
[0228] It is continued 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".
[0229] 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 Hungdetect watchdog in the kernel layer is notified to perform a reset operation is determined according to the first status mark identifying the status of the SurfaceFlinger.
[0230] 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.
[0231] 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.
[0232] 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.
[0233] 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.
[0234] 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.
[0235] 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.
[0236] 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.
[0237] It should be noted that, in actual applications, the second status mark can be the same as or different from the first status mark.
[0238] 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.
[0239] 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.
[0240] For example, when the first status mark is an abnormal mark, regardless of whether Xcollie is normal, the second status mark is the same as the first status mark, and is an abnormal mark.
[0241] That is, for the scenario in which Xcollie accesses the Hungdetect, regardless of whether Xcollie can normally run or can restart the SurfaceFlinger process, the Hungdetect watchdog can acquire the second status mark.
[0242] 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.
[0243] 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.
[0244] 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.
[0245] 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.
[0246] 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.
[0247] 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 application framework layer repeatedly restarts the SurfaceFlinger process but cannot be successful can be avoided.
[0248] Scenario three
[0249] 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.
[0250] 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.
[0251] 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:
[0252] In step 301, the public node receives information provided by each software watchdog in the application framework layer.
[0253] 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.
[0254] Correspondingly, the information provided by the software watchdogs mentioned above is related to the characteristics of the software watchdogs in actual application.
[0255] For example, for System Server WatchDog, the provided information can be the second feeding information mentioned in scenario one.
[0256] 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.
[0257] 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 as "null", or in order to facilitate informing the lower public node that it has currently entered an exception, a conventional exception information can be provided.
[0258] 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 exception flag, and when Xcollie and the corresponding key process state are normal, the second state flag provided is a normal flag.
[0259] It should be understood that the above description is only an example for better understanding the technical solutions of the embodiment, and is not the only limitation of the embodiment.
[0260] 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.
[0261] 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.
[0262] 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.
[0263] 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.
[0264] 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.
[0265] 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.
[0266] 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.
[0267] For example, n is an integer greater than 1, and N is an integer greater than n.
[0268] 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.
[0269] 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.
[0270] 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.
[0271] 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.
[0272] 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.
[0273] In step 304, the common node provides a reset instruction to trigger the reset operation of the reset detection watchdog.
[0274] For the description of the reset operation of the reset detection watchdog, please refer to the part of scenario one and scenario two, which will not be repeated here.
[0275] In step 305, the common node provides the agreed feeding dog information to the reset detection watchdog.
[0276] 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.
[0277] Thus, the watchdog detection method provided by the embodiment provides a common node that can make a decision in advance whether to perform a reset by a lower-layer software watchdog when an abnormal service process that cannot be successfully reset by an upper-layer software watchdog occurs, and the common node uniformly interfaces a state mark sent by different upper-layer software watchdogs to identify a service process detected by the upper-layer software watchdogs and an action performed by the service process, and makes a decision by analyzing the state mark according to a preset strategy, so that the layered and hierarchical recovery scheme in the application is more reasonable.
[0278] In addition, according to the business requirement, the common node can make a processing result according to the state mark and the dog feeding information from the different upper-layer software watchdogs, so that the restart operation of the dead detection watchdog on the kernel system is reduced as much as possible without affecting the use of the electronic device by a user, and the resource consumption is reduced.
[0279] In order to better understand the implementation scheme of the multiple software watchdogs in the application program framework layer accessing the Hungdetect watchdog, the following takes the Hungdetect watchdog in the kernel layer simultaneously detecting the System Server WatchDog and the Xcollie in the application program framework layer as an example to explain the watchdog detection method provided by the application.
[0280] Referring to Figure 10 , Figure 10 An application scenario shown for example is schematically shown.
[0281] As Figure 10 shown, the application program framework layer of the electronic device includes the System Server WatchDog, the System Server process detected by the System Server WatchDog, the Xcollie, and the key process corresponding to the Xcollie, such as the SurfaceFlinger; the kernel layer of the electronic device includes the Hungdetect watchdog for detecting whether the kernel system normally runs, and the common node for respectively communicating with the System Server WatchDog in the application program framework layer, the Xcollie, and the Hungdetect watchdog in the kernel layer.
[0282] As to the System Server WatchDog detecting the System Server process, the System Server process performs a first feeding operation on the System Server WatchDog, when to restart the System Server process, and when the System Server WatchDog performs a second feeding operation (the second feeding information in scenario one), which are described in scenario one and will not be repeated here.
[0283] As to the Xcollie detecting the action in the SurfaceFlinger, how the Xcollie obtains the first state mark of the SurfaceFlinger, when to restart the SurfaceFlinger, and when the Xcollie provides the second state mark, which are described in scenario two and will not be repeated here.
[0284] As to the Hungdetect watchdog detecting the kernel system, the kernel system performs a third feeding operation on the Hungdetect watchdog, and when to restart the kernel system, which are described in scenario one or scenario two about the Hungdetect watchdog detecting the kernel system of the current layer, and will not be repeated here.
[0285] The following will be described in combination with Figure 10 It is emphasized that the second feeding operation and the second state mark are written into the common node of the kernel layer, and whether the Hungdetect watchdog performs the reset operation is decided by the common node, instead of being directly given to the Hungdetect watchdog.
[0286] Exemplarily, in the specific implementation, the preset strategy of whether to perform the reset operation by the Hungdetect watchdog can be pre-placed in the common node according to the business requirement.
[0287] Therefore, the common node will decide whether the Hungdetect watchdog needs to perform the reset operation according to the preset strategy, the obtained feeding information, and the state mark.
[0288] As to the above-mentioned obtained feeding information, in some implementation scenarios, the obtained feeding information can be the information describing the normal System Server WatchDog, which indicates that the detected System Server process is also normal, and the feeding of the System Server WatchDog to the Hungdetect watchdog is normal.
[0289] 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.
[0290] 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.
[0291] Correspondingly, the common node can obtain the decision information through processing.
[0292] 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.
[0293] 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.
[0294] 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.
[0295] 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.
[0296] 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 described herein again.
[0297] 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.
[0298] Scenario Four
[0299] 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.
[0300] Figure 11 An application scenario is shown by way of example.
[0301] 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.
[0302] 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.
[0303] 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.
[0304] 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.
[0305] 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.
[0306] Continuing to refer to Figure 11 , the hardware watchdog can not only detect the hardware chip, but 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 mean that the Hungdetect watchdog is invalid, or the Hungdetect watchdog cannot successfully restart the kernel system.
[0307] 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.
[0308] As an optional implementation, the Hungdetect watchdog stops the third feeding operation on the hardware watchdog before triggering the kernel system reset (or restart).
[0309] 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.
[0310] 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.
[0311] Scenario five
[0312] 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.
[0313] Figure 12 An application scenario diagram is shown for illustration.
[0314] As shown in Figure 12 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.
[0315] 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.
[0316] 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.
[0317] 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.
[0318] In this system, each CPU core is bound to a target task, which runs periodically on its assigned CPU core. For example, the target task runs on its assigned CPU core every 30 seconds. A CPU core status watchdog periodically checks, via a first detection task, whether the target tasks bound to each CPU core can be scheduled, thereby determining the running status of each CPU core. For example, the first detection task checks every 30 seconds whether the target tasks bound to each CPU core can be scheduled. If a target task on a CPU core cannot be scheduled, the CPU core status watchdog determines that the CPU core's running status is abnormal; if a target task on a CPU core can be scheduled, the CPU core status watchdog determines that the CPU core's running status is normal.
[0319] like Figure 13 As shown, the CPU of the electronic device includes eight cores: CPU0, CPU1, CPU2, ..., CPU7. Each CPU core is bound to a target task; for example, CPU0 is bound to target task Tast 0, CPU1 to target task Tast 1, CPU2 to target task Tast 2, ..., and CPU7 to target task Tast 7. Each target task runs periodically on its bound CPU core; for example, target task Tast 0 runs periodically on CPU0, target task Tast 1 runs periodically on CPU1, target task Tast 2 runs periodically on CPU2, ..., and target task Tast 7 runs periodically on CPU7.
[0320] The CPU core status watchdog periodically checks, through a first detection task, whether each target task (Tast 0-Tast 7) can be scheduled on its associated CPU core, thereby determining the running status of each CPU core. The first detection task can run on any CPU core. For example, if Tast 0 cannot be scheduled on its associated CPU 0 core, the CPU core status watchdog can determine that the running status of CPU 0 core is abnormal. Conversely, if Tast 7 can be scheduled on its associated CPU 0 core, the CPU core status watchdog can determine that the running status of CPU 7 core is normal. In this way, the CPU core status watchdog can determine the running status of each CPU core.
[0321] 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.
[0322] As another optional implementation, the CPU core state watchdog can determine the running state of the CPU core based on the probe message.
[0323] 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.
[0324] 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.
[0325] 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.
[0326] 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. Figure 14As shown, the CPU of the electronic device includes 8 cores, which are CPU0 core, CPU1 core, CPU2 core, …, and 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 sends a ping message to the CPU0 core in the online state through the second detection task, and can receive a feedback message sent by the CPU0 core in response to the ping message, it is determined that the running state of the CPU0 core is normal. For another example, if the CPU core state watchdog sends a ping message to the CPU1 core in the online state through the second detection task, and cannot receive a feedback message sent by the CPU1 core in response to the ping message, 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.
[0327] 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 meets a preset kernel restart condition, and if so, controls to restart the kernel. The present embodiment does not limit the preset kernel restart condition.
[0328] 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 meets the preset kernel restart condition, and controls to restart the kernel.
[0329] 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 meets the preset kernel restart condition, and controls to restart the kernel. 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 its running state is abnormal, the CPU core state watchdog determines that the running state of each core of the CPU meets the preset kernel restart condition, and controls to restart the kernel.
[0330] 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 probe 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.
[0331] 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.
[0332] As shown in FIG. 1, the electronic device includes a hardware watchdog in a hardware layer of the electronic device. Figure 12
[0333] 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.
[0334] When the hardware watchdog does not receive the second feeding operation from the hardware chip, and 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.
[0335] 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.
[0336] 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.
[0337] 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).
[0338] 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.
[0339] 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.
[0340] 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.
[0341] 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.
[0342] Scenario six
[0343] 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 detect multiple software watchdogs in the application framework layer.
[0344] Figure 15 An application scenario shown by way of example is schematically shown in the figure.
[0345] 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.
[0346] 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.
[0347] 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
[0348] 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.
[0349] 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.
[0350] 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.
[0351] Optionally, when the Hungdetect watchdog detects an exception of any one of the 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.
[0352] 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.
[0353] Optionally, when the Hungdetect watchdog detects that any one of the software watchdogs in the application framework layer is abnormal 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.
[0354] For example, assuming 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, the Hungdetect watchdog performs a kernel restart operation.
[0355] 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.
[0356] 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.
[0357] For details not explained herein, refer to the foregoing description.
[0358] In this way, the layered and hierarchical recovery of the electronic device is achieved by setting the detection mechanism between the electronic device layers. Since the granularity of the next recovery is greater than that of the upper layer recovery, the success rate of the upper layer recovery is improved through the lower layer restart when the upper layer fails to recover successfully, and the problem that a certain layer of the electronic device repeatedly restarts but fails to recover successfully is avoided.
[0359] 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 watching, so as to realize comprehensive coverage of the electronic device, and ensure that the electronic device can be normally used, 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.
[0360] 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 as normal, and some of them can be considered as 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.
[0361] 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.
[0362] The embodiment also provides a computer storage medium, which stores computer instructions, when the computer instructions run on the electronic device, the electronic device executes the related method steps to realize the watchdog detection method in the above embodiment.
[0363] The embodiment also provides a computer program product, when the computer program product runs on the computer, the computer executes the related steps to realize the watchdog detection method in the above embodiment.
[0364] 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.
[0365] The electronic device, the computer storage medium, the computer program product or the chip provided in the embodiment can execute the corresponding method provided in the above, and the beneficial effects that can be achieved are the beneficial effects of the watchdog detection method provided in the above, which will not be described here.
[0366] 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.
[0367] In several embodiments provided in the present application, it should be understood that the disclosed apparatus and method can be implemented in other ways. For example, the apparatus 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.
[0368] 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 system, characterized in that, Applied in electronic devices, the electronic device system architecture includes an application framework layer and a kernel layer, wherein the application framework layer and the kernel layer are software layers; The system includes: a first watchdog, a second watchdog, and a hardware watchdog, wherein the first watchdog is located in the application framework layer, and the second watchdog is located in the kernel layer; wherein... The first watchdog is used to: detect a first service in the application framework layer, and reset the first service when the first service is abnormal; the first service is a System Server process, a SurfaceFlinger process, or an Init process; The second watchdog is used to: detect a second service in the kernel layer, and reset the second service when the second service is abnormal; the second service is the kernel system or each core of the CPU; The second detection cycle is longer than the first detection cycle; the first detection cycle is the detection cycle of the first watchdog on the first service, and the second detection cycle is the detection cycle of the second watchdog on the first watchdog; The hardware watchdog is used to detect the hardware chip of the electronic device and reset the hardware chip when an abnormality is found. The second watchdog is further configured to: detect the first watchdog, and reset the second service when the first watchdog fails or the first watchdog cannot restore the first service; wherein, after the second service is reset, the electronic device reloads and runs the first service, thereby restoring the first service; The hardware watchdog is further configured to: detect the second watchdog, and provide service to the hardware chip when the second watchdog fails or the second watchdog cannot restore the second service; wherein, after resetting the hardware chip, the electronic device reloads and runs the second service so that the second service can be restored.
2. The system according to claim 1, characterized in that, The first watchdog is used to: periodically feed the second watchdog when the first service is normal, and stop feeding the second watchdog when the first service is abnormal; The second watchdog is used to reset the second service when no watchdog feeding operation is received from the first watchdog within one or more consecutive detection cycles.
3. The system according to claim 1, characterized in that, The first watchdog is used to: send the status information of the first service to the second watchdog; wherein, when the first service is normal, the status information of the first service is set to a normal flag by the first watchdog; when the first service is abnormal, the status information of the first service is set to an abnormal flag by the first watchdog. The second watchdog is used to reset the second service when all the status information received within one or more consecutive detection cycles is marked as abnormal.
4. The system according to claim 1, characterized in that, The second detection period is an integer multiple of the first detection period.
5. A watchdog detection method, characterized in that, Applied in electronic devices, the electronic device system architecture includes an application framework layer and a kernel layer, wherein the application framework layer and the kernel layer are software layers; The method includes: The first watchdog detects a first service in the application framework layer and resets the first service when it malfunctions; wherein, the first watchdog is located in the application framework layer; the first service is a System Server process, a SurfaceFlinger process, or an Init process; The second watchdog detects the second service in the kernel layer and resets the second service when it is abnormal; wherein, the second watchdog is located in the kernel layer; the second service is the kernel system or each core of the CPU; The second detection cycle is longer than the first detection cycle; the first detection cycle is the detection cycle of the first watchdog on the first service, and the second detection cycle is the detection cycle of the second watchdog on the first watchdog; The hardware watchdog detects the hardware chip of the electronic device and resets the hardware chip when an abnormality is found. The second watchdog detects the first watchdog, and resets the second service when the first watchdog fails or the first watchdog cannot restore the first service; wherein, after the second service is reset, the electronic device reloads and runs the first service, thereby restoring the first service; The hardware watchdog detects the second watchdog and provides service to the hardware chip when the second watchdog fails or cannot restore the second service; wherein, after resetting the hardware chip, the electronic device reloads and runs the second service so that the second service can be restored.
6. The method according to claim 5, characterized in that, Also includes: When the first service is normal, the first watchdog periodically feeds the second watchdog. When the first service fails, the first watchdog stops feeding the second watchdog. The second watchdog detects the first watchdog, and resets the second service when the first watchdog malfunctions, including: If the second watchdog does not receive a feeding operation from the first watchdog within one or more consecutive detection cycles, the second service will be reset.
7. The method according to claim 5, characterized in that, Also includes: When the first service is normal, the first watchdog sets the status information of the first service to a normal flag and sends the status information of the first service to the second watchdog. When the first service encounters an anomaly, the first watchdog sets the status information of the first service to an anomaly flag and sends the status information of the first service to the second watchdog. The second watchdog detects the first watchdog, and resets the second service when the first watchdog malfunctions, including: If the second watchdog receives an abnormal status information within one or more consecutive detection cycles, the second service will be reset.
8. The method according to claim 5, characterized in that, The second detection period is an integer multiple of the first detection period.
9. 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 that, when executed by the one or more processors, cause the electronic device to perform the watchdog detection method according to any one of claims 5 to 8.
10. 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 performs the watchdog detection method as described in any one of claims 5 to 8.
Citation Information
Patent Citations
Watch-dog implementation method and device based on Nios II system
CN103645962A