CN111538599A - LINUX-based multithreading deadlock problem positioning method and system - Google Patents

LINUX-based multithreading deadlock problem positioning method and system Download PDF

Info

Publication number
CN111538599A
CN111538599A CN202010325506.5A CN202010325506A CN111538599A CN 111538599 A CN111538599 A CN 111538599A CN 202010325506 A CN202010325506 A CN 202010325506A CN 111538599 A CN111538599 A CN 111538599A
Authority
CN
China
Prior art keywords
deadlock
timer
linux
code
lock
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202010325506.5A
Other languages
Chinese (zh)
Inventor
熊兵
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Hangzhou Tuya Information Technology Co Ltd
Original Assignee
Hangzhou Tuya Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Hangzhou Tuya Information Technology Co Ltd filed Critical Hangzhou Tuya Information Technology Co Ltd
Priority to CN202010325506.5A priority Critical patent/CN111538599A/en
Publication of CN111538599A publication Critical patent/CN111538599A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/52Program synchronisation; Mutual exclusion, e.g. by means of semaphores
    • G06F9/524Deadlock detection or avoidance

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The application discloses a multithreading deadlock problem positioning method based on LINUX, which comprises the following steps: starting a timer before the critical section code enters a critical section protected by a lock; in the expiration processing function of the timer, saving the deadlock field and adding debugging information; the phenomenon of deadlock recurs; analyzing output information of the expiration function; and obtaining an analysis result; and positioning the position and the reason of the deadlock according to the analysis result. Compared with the prior art, the method has the following beneficial effects: the present invention locates multithreaded deadlock by linux timer and expiration processing function of the timer. The useless printing information is greatly reduced, and the positioning is convenient.

Description

LINUX-based multithreading deadlock problem positioning method and system
Technical Field
The application relates to the embedded field, in particular to a multithreading deadlock problem positioning method based on LINUX.
Background
Under the condition that a plurality of tasks are not mutually synchronous, a plurality of shared resources (global variables, linked lists and the like) in the linux are simultaneously accessed, so that the linux enters an unstable competition state; the use of locks in linux is to synchronize the access of multiple tasks to shared resources in order to protect these shared resources.
Improper use of the lock may lead to deadlock (the lock cannot be released and other tasks cannot acquire the lock and cannot run). Such as recursive use of a lock (in the case where a lock has been acquired, re-applying for use of the lock); sleep in the code that owns the lock (in the case of acquiring the lock, a function is called that causes the task to sleep); tasks are preempted while lock protected critical section code executes. The location of these deadlock problems requires the use of some debugging means.
The relatively common debugging method is to add printing log information, add different debugging information before entering the critical area and after leaving the critical area, save the debugging information by log files, and then analyze the log files to locate the deadlock problem.
Some locks are frequently acquired and released, and if a method for adding printing log information is used, the log information is excessive, so that log loss is caused. Too much print log information can also make it difficult to analyze and define the problem.
Disclosure of Invention
The main purpose of the present application is to provide a LINUX-based multithreading deadlock problem positioning method, which includes:
starting a timer before the critical section code enters a critical section protected by a lock;
in the expiration processing function of the timer, saving the deadlock field and adding debugging information;
the phenomenon of deadlock recurs;
analyzing output information of the expiration function; and obtaining an analysis result;
and positioning the position and the reason of the deadlock according to the analysis result.
Optionally, the LINUX-based multithreading deadlock problem positioning method further includes:
and finding the corresponding critical section code.
Optionally, in the LINUX-based multithreading deadlock problem positioning method, the timing time of the timer is greater than the running time of the critical section code.
Optionally, in the LINUX-based multithreading deadlock problem positioning method, the debugging information includes: and acquiring the task name of the lock and the code address of the lock.
Optionally, the LINUX-based multithreading deadlock problem positioning method further includes:
and deleting the timer after the critical area code exits the critical area.
Optionally, in the LINUX-based multithreading deadlock problem positioning method, the output information is printing information.
According to another aspect of the present application, there is also provided a LINUX-based multithreading deadlock problem positioning method, including:
the searching module is used for finding the corresponding critical section code;
the timer starting module is used for starting the timer before the code of the critical area enters the critical area protected by the lock;
the storage module is used for storing a deadlock field in an expiration processing function of the timer and adding debugging information;
the deleting module is used for deleting the timer after the critical area code exits the critical area;
the recurrence module is used for recurring the phenomenon of deadlock;
an analysis module for analyzing the output information of the expiration function; and obtaining an analysis result;
and the positioning module is used for positioning the position and the reason of the deadlock according to the analysis result.
The application also discloses a computer device, which comprises a memory, a processor and a computer program stored in the memory and capable of being executed by the processor, wherein the processor realizes the method of any one of the above items when executing the computer program.
The application also discloses a computer-readable storage medium, a non-volatile readable storage medium, having stored therein a computer program which, when executed by a processor, implements the method of any of the above.
The present application also discloses a computer program product comprising computer readable code which, when executed by a computer device, causes the computer device to perform the method of any of the above.
Compared with the prior art, the method has the following beneficial effects:
the present invention locates multithreaded deadlock by linux timer and expiration processing function of the timer. The critical code of lock protection is generally short and short in execution time; before entering a critical zone, a timer is started, the time set by the timer is far longer than the execution time of a critical code, and related debugging information is added into an expiration processing function of the timer; after the critical section code is executed, the timer is deleted (if the timer is deleted before the timer expires, the timer will not expire, and the processing function will not run). Therefore, only under the condition that the lock is not released (deadlock), the expiration processing function of the timer can be called, useless printing information can be greatly reduced, and the problem of positioning is facilitated.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this application, serve to provide a further understanding of the application and to enable other features, objects, and advantages of the application to be more apparent. The drawings and their description illustrate the embodiments of the invention and do not limit it. In the drawings:
FIG. 1 is a schematic flow chart diagram of a LINUX-based multithreading deadlock problem locating method according to one embodiment of the present application;
FIG. 2 is a flow diagram of a LINUX-based multithreaded deadlock problem locating method according to one embodiment of the present application;
FIG. 3 is a schematic diagram of a computer device according to one embodiment of the present application; and
FIG. 4 is a schematic diagram of a computer-readable storage medium according to one embodiment of the present application.
Detailed Description
In order to make the technical solutions better understood by those skilled in the art, 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, and it is obvious that the described embodiments are only partial embodiments of the present application, but not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
It should be noted that the terms "first," "second," and the like in the description and claims of this application and in the drawings described above are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It should be understood that the data so used may be interchanged under appropriate circumstances such that embodiments of the application described herein may be used. Furthermore, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed, but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
It should be noted that the embodiments and features of the embodiments in the present application may be combined with each other without conflict. The present application will be described in detail below with reference to the embodiments with reference to the attached drawings.
Referring to fig. 1-2, an embodiment of the present application provides a LINUX-based method for locating a multithreaded deadlock problem, including:
s2: starting a timer before the critical section code enters a critical section protected by a lock;
s4: in the expiration processing function of the timer, saving the deadlock field and adding debugging information;
s6: the phenomenon of deadlock recurs;
s8: analyzing output information of the expiration function; and obtaining an analysis result;
s10: and positioning the position and the reason of the deadlock according to the analysis result.
For example, before entering the critical section, a timer is started, and the timer timing time (much longer than the critical code running time) is set. In the expiration processing function of the timer, the deadlock field is saved, and some debugging information is added. After the deadlock phenomenon is reproduced, the information output in the timer expiration function is analyzed, and the position and the reason of the deadlock are positioned.
The present invention locates multithreaded deadlock by linux timer and expiration processing function of the timer. The critical code of lock protection is generally short and short in execution time; before entering a critical zone, a timer is started, the time set by the timer is far longer than the execution time of a critical code, and related debugging information is added into an expiration processing function of the timer; after the critical section code is executed, the timer is deleted (if the timer is deleted before the timer expires, the timer will not expire, and the processing function will not run). Therefore, only under the condition that the lock is not released (deadlock), the expiration processing function of the timer can be called, useless printing information can be greatly reduced, and the problem of positioning is facilitated.
In an embodiment of the present application, the LINUX-based multithreading deadlock problem positioning method further includes:
and finding the corresponding critical section code.
For example, find the corresponding critical section code, before entering the critical section, start a timer, and set the timer timing time (much longer than the critical code runtime). In the expiration processing function of the timer, the deadlock field is saved, and some debugging information is added. After the deadlock phenomenon is reproduced, the information output in the timer expiration function is analyzed, and the position and the reason of the deadlock are positioned.
In an embodiment of the present application, the debugging information includes: and acquiring the task name of the lock and the code address of the lock.
For example, find the corresponding critical section code, before entering the critical section, start a timer, and set the timer timing time (much longer than the critical code runtime). In the expiration processing function of the timer, the deadlock field is saved, the task name of the acquired lock is added, and the code address of the lock is acquired. After the deadlock phenomenon is reproduced, the information output in the timer expiration function is analyzed, and the position and the reason of the deadlock are positioned.
In an embodiment of the present application, after the critical section code exits the critical section, the timer is deleted.
For example, find the corresponding critical section code, before entering the critical section, start a timer, and set the timer timing time (much longer than the critical code runtime). In the expiration processing function of the timer, the deadlock field is saved, the task name of the acquired lock is added, and the code address of the lock is acquired. And deleting the timer after the code exits the critical area. After the deadlock phenomenon is reproduced, the information output in the timer expiration function is analyzed, and the position and the reason of the deadlock are positioned.
In an embodiment of the present application, the output information is print information.
For example, find the corresponding critical section code, before entering the critical section, start a timer, and set the timer timing time (much longer than the critical code runtime). In the expiration processing function of the timer, the deadlock field is saved, and some debugging information (such as a task name for acquiring the lock, a code address for acquiring the lock, and the like) is added. And deleting the timer after the code exits the critical area. After the deadlock phenomenon is reproduced, the printing information output in the timer expiration function is analyzed, and the position and the reason of the deadlock are positioned.
In an embodiment of the present application, a LINUX-based multithreading deadlock problem positioning method is further provided, including:
the searching module is used for finding the corresponding critical section code;
the timer starting module is used for starting the timer before the code of the critical area enters the critical area protected by the lock;
the storage module is used for storing a deadlock field in an expiration processing function of the timer and adding debugging information;
the deleting module is used for deleting the timer after the critical area code exits the critical area;
the recurrence module is used for recurring the phenomenon of deadlock;
an analysis module for analyzing the output information of the expiration function; and obtaining an analysis result;
and the positioning module is used for positioning the position and the reason of the deadlock according to the analysis result.
Compared with the prior art, the method has the following beneficial effects:
the present invention locates multithreaded deadlock by linux timer and expiration processing function of the timer. The critical code of lock protection is generally short and short in execution time; before entering a critical zone, a timer is started, the time set by the timer is far longer than the execution time of a critical code, and related debugging information is added into an expiration processing function of the timer; after the critical section code is executed, the timer is deleted (if the timer is deleted before the timer expires, the timer will not expire, and the processing function will not run). Therefore, only under the condition that the lock is not released (deadlock), the expiration processing function of the timer can be called, useless printing information can be greatly reduced, and the problem of positioning is facilitated.
Referring to fig. 3, the present application further provides a computer device including a memory, a processor, and a computer program stored in the memory and executable by the processor, wherein the processor implements the method of any one of the above methods when executing the computer program.
Referring to fig. 4, a computer-readable storage medium, a non-volatile readable storage medium, having stored therein a computer program which, when executed by a processor, implements any of the methods described above.
A computer program product comprising computer readable code which, when executed by a computer device, causes the computer device to perform the method of any of the above.
It will be apparent to those skilled in the art that the modules or steps of the present invention described above may be implemented by a general purpose computing device, they may be centralized on a single computing device or distributed across a network of multiple computing devices, and they may alternatively be implemented by program code executable by a computing device, such that they may be stored in a storage device and executed by a computing device, or fabricated separately as individual integrated circuit modules, or fabricated as a single integrated circuit module from multiple modules or steps. Thus, the present invention is not limited to any specific combination of hardware and software.
The above description is only a preferred embodiment of the present application and is not intended to limit the present application, and various modifications and changes may be made by those skilled in the art. Any modification, equivalent replacement, improvement and the like made within the spirit and principle of the present application shall be included in the protection scope of the present application.

Claims (10)

1. A multithreading deadlock problem positioning method based on LINUX is characterized by comprising the following steps:
starting a timer before the critical section code enters a critical section protected by a lock;
in the expiration processing function of the timer, saving the deadlock field and adding debugging information;
the phenomenon of deadlock recurs;
analyzing output information of the expiration function; and obtaining an analysis result;
and positioning the position and the reason of the deadlock according to the analysis result.
2. The LINUX-based multi-thread deadlock problem positioning method of claim 1, further comprising:
and finding the corresponding critical section code.
3. The LINUX-based multi-threaded deadlock problem location method of claim 2, wherein a timing time of the timer is greater than a running time of the critical section code.
4. The LINUX-based multithreaded deadlock problem locating method of claim 3, wherein the debugging information comprises: and acquiring the task name of the lock and the code address of the lock.
5. The LINUX-based multithreaded deadlock problem positioning method of claim 4, further comprising:
and deleting the timer after the critical area code exits the critical area.
6. The LINUX-based multithreaded deadlock problem locating method of claim 5, wherein the output information is print information.
7. A multithreading deadlock problem positioning method based on LINUX is characterized by comprising the following steps:
the searching module is used for finding the corresponding critical section code;
the timer starting module is used for starting the timer before the code of the critical area enters the critical area protected by the lock;
the storage module is used for storing a deadlock field in an expiration processing function of the timer and adding debugging information;
the deleting module is used for deleting the timer after the critical area code exits the critical area;
the recurrence module is used for recurring the phenomenon of deadlock;
an analysis module for analyzing the output information of the expiration function; and obtaining an analysis result;
and the positioning module is used for positioning the position and the reason of the deadlock according to the analysis result.
8. A computer device comprising a memory, a processor and a computer program stored in the memory and executable by the processor, wherein the processor implements the method of any one of claims 1-6 when executing the computer program.
9. A computer-readable storage medium, a non-transitory readable storage medium, having stored therein a computer program, characterized in that the computer program, when executed by a processor, implements the method according to any one of claims 1-6.
10. A computer program product comprising computer readable code that, when executed by a computer device, causes the computer device to perform the method of any of claims 1-6.
CN202010325506.5A 2020-04-23 2020-04-23 LINUX-based multithreading deadlock problem positioning method and system Pending CN111538599A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010325506.5A CN111538599A (en) 2020-04-23 2020-04-23 LINUX-based multithreading deadlock problem positioning method and system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010325506.5A CN111538599A (en) 2020-04-23 2020-04-23 LINUX-based multithreading deadlock problem positioning method and system

Publications (1)

Publication Number Publication Date
CN111538599A true CN111538599A (en) 2020-08-14

Family

ID=71977179

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010325506.5A Pending CN111538599A (en) 2020-04-23 2020-04-23 LINUX-based multithreading deadlock problem positioning method and system

Country Status (1)

Country Link
CN (1) CN111538599A (en)

Citations (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPH1021098A (en) * 1996-06-29 1998-01-23 Nec Corp Exclusive control unit
CN1622526A (en) * 2003-11-26 2005-06-01 华为技术有限公司 A solution method of data transmission deadlock
US20060136886A1 (en) * 2004-12-16 2006-06-22 Bret Patterson Process and implementation for interrupting locked threads
CN1932776A (en) * 2006-09-29 2007-03-21 上海科泰世纪科技有限公司 Automatic operating method for interface test in embedded operating system
CN101895440A (en) * 2010-07-22 2010-11-24 北京天融信科技有限公司 Security gateway and failure detection method thereof
CN102088470A (en) * 2009-12-07 2011-06-08 中兴通讯股份有限公司 Method and device for deadlock detection and self-recovery of file transfer protocol (FTP) in communication system
CN103761182A (en) * 2013-12-26 2014-04-30 上海华为技术有限公司 Method and device for deadlock detection
CN104636259A (en) * 2015-03-18 2015-05-20 厦门雅迅网络股份有限公司 Function execution timeout and deadlock detection method based on dynamic tracking of operating period
CN105243023A (en) * 2015-11-24 2016-01-13 无锡江南计算技术研究所 Method for detecting errors generated during parallel running
CN107273263A (en) * 2017-05-26 2017-10-20 努比亚技术有限公司 A kind of analysis method of misoperation, application terminal and monitoring server
CN109189582A (en) * 2018-07-20 2019-01-11 新华三技术有限公司合肥分公司 A kind of method and device detecting semaphore time-out reason

Patent Citations (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPH1021098A (en) * 1996-06-29 1998-01-23 Nec Corp Exclusive control unit
CN1622526A (en) * 2003-11-26 2005-06-01 华为技术有限公司 A solution method of data transmission deadlock
US20060136886A1 (en) * 2004-12-16 2006-06-22 Bret Patterson Process and implementation for interrupting locked threads
CN1932776A (en) * 2006-09-29 2007-03-21 上海科泰世纪科技有限公司 Automatic operating method for interface test in embedded operating system
CN102088470A (en) * 2009-12-07 2011-06-08 中兴通讯股份有限公司 Method and device for deadlock detection and self-recovery of file transfer protocol (FTP) in communication system
CN101895440A (en) * 2010-07-22 2010-11-24 北京天融信科技有限公司 Security gateway and failure detection method thereof
CN103761182A (en) * 2013-12-26 2014-04-30 上海华为技术有限公司 Method and device for deadlock detection
CN104636259A (en) * 2015-03-18 2015-05-20 厦门雅迅网络股份有限公司 Function execution timeout and deadlock detection method based on dynamic tracking of operating period
CN105243023A (en) * 2015-11-24 2016-01-13 无锡江南计算技术研究所 Method for detecting errors generated during parallel running
CN107273263A (en) * 2017-05-26 2017-10-20 努比亚技术有限公司 A kind of analysis method of misoperation, application terminal and monitoring server
CN109189582A (en) * 2018-07-20 2019-01-11 新华三技术有限公司合肥分公司 A kind of method and device detecting semaphore time-out reason

Similar Documents

Publication Publication Date Title
US7653791B2 (en) Realtime-safe read copy update with per-processor read/write locks
US9003420B2 (en) Resolving RCU-scheduler deadlocks
US7734879B2 (en) Efficiently boosting priority of read-copy update readers in a real-time data processing system
US8495641B2 (en) Efficiently boosting priority of read-copy update readers while resolving races with exiting and unlocking processes
US8060880B2 (en) System using backward inter-procedural analysis for determining alternative coarser grained lock when finer grained locks exceeding threshold
US8924655B2 (en) In-kernel SRCU implementation with reduced OS jitter
US9569254B2 (en) Automatic checkpointing and partial rollback in software transaction memory
US9389925B2 (en) Achieving low grace period latencies despite energy efficiency
US20060130061A1 (en) Use of rollback RCU with read-side modifications to RCU-protected data structures
CN108319495B (en) Task processing method and device
US11269692B2 (en) Efficient sequencer for multiple concurrently-executing threads of execution
CN110232095B (en) Data synchronization method, device, storage medium and server
CN110737437A (en) compiling method and device based on code integration
CN110245074B (en) Log record generation method and device, storage medium and server
US20060224949A1 (en) Exclusion control method and information processing apparatus
CN111538599A (en) LINUX-based multithreading deadlock problem positioning method and system
Wang et al. Real-time middleware for cyber-physical event processing
Roch et al. On-line adaptive parallel prefix computation
CN112612582B (en) Semaphore function implementation method and device
Liu et al. Efficient work-stealing with blocking deques
CN112732424A (en) Multitasking method, system and medium
CN117608775A (en) Task scheduling method and device and electronic equipment
CN115454613A (en) Distributed processing method, node and distributed database system of DDL task
CN113504983A (en) Method and device for arranging template resources
CN116361001A (en) Shared resource allocation and use method and system

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication

Application publication date: 20200814