{"id":19203354,"url":"https://github.com/rouming/dla","last_synced_at":"2025-07-04T01:04:47.516Z","repository":{"id":23958670,"uuid":"27340772","full_name":"rouming/dla","owner":"rouming","description":"Futex deadlock analyser","archived":false,"fork":false,"pushed_at":"2015-01-06T13:53:55.000Z","size":696,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-23T06:11:20.305Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rouming.png","metadata":{"files":{"readme":"README","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-11-30T15:46:44.000Z","updated_at":"2019-04-08T03:32:43.000Z","dependencies_parsed_at":"2022-07-30T05:08:03.389Z","dependency_job_id":null,"html_url":"https://github.com/rouming/dla","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rouming/dla","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rouming%2Fdla","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rouming%2Fdla/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rouming%2Fdla/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rouming%2Fdla/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rouming","download_url":"https://codeload.github.com/rouming/dla/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rouming%2Fdla/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263427299,"owners_count":23464840,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T12:48:01.017Z","updated_at":"2025-07-04T01:04:47.492Z","avatar_url":"https://github.com/rouming.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"dla: deadlock analyser tool\n\nPurpose:\n  Analyses simple ABBA deadlocks (basically pthread_mutex_lock) from user\n  space, scanning /proc/*/task, reading /proc/*/syscall and /proc/*/status,\n  doing ptrace.  So definitely this tool is a hack which works only on Linux.\n\n  It is not a static analyser, this tool does post-mortem analysis, when\n  something on your system has stuck and you have to understand what exactly\n  and to see the locking dependency.\n\n  The idea behind this is very simple:\n\n    1. if context switch counters have not been updated since last visit\n       the thread has been stuck:\n         # cat /proc/self/status | grep switches\n         voluntary_ctxt_switches:   1\n         nonvoluntary_ctxt_switches:    1\n\n    2. if thread is stuck in futex syscall it becomes suspicious:\n         # sudo cat /proc/*/task/*/syscall | grep '^202'\n         202 0x7fffc8b336dc 0x89 0x1 0x7fffc8b33658 ...\n                                 ^^^\n                                 pthread_cond_wait\n         ....\n         202 0x7fff60dd3c80 0x80 0x0 0x0 ...\n                                 ^^^\n                                 sem_wait\n         ....\n         202 0x601650 0x80 0x2 0x0 0x601650 ...\n                           ^^^\n                           pthread_mutex_lock\n\n    3. according to the glibc 'pthread_mutex_lock' can be found by '0x2' as\n       third param:\n             202 0x601650 0x80 0x2 0x601650 ....\n                               ^^^\n       all these calls are our candidates for further analysis.\n\n    4. for all suspicious threads which were stuck in futex syscalls with '0x2'\n       as third param we have to unwind the stack using 'libunwind' library.\n       If top frame is a '__lll_lock_wait' - that's it, we probably found it.\n\n    5. first param of the futex syscall is an address of lock value, so:\n             202 0x601650 0x80 0x2 0x601650 ....\n                 ^^^^^^^^\n        is a pthread_mutex_t object:\n\n        (gdb) p *(pthread_mutex_t *)0x601650\n        $2 = {\n        __data = {\n        __lock = 2,           \u003c\u003c\u003c\u003c our value\n        __count = 0,\n        __owner = 17716,\n        __nusers = 1,\n        __kind = 0,\n        .....\n\n        what is interesting here is '__owner' value, which points out the thread\n        whom we are waiting for.\n\n\n    6. pick '__owner' value using ptrace and build dependency graph, where\n       deadlock loop can be found.\n\n    7. if loop is found dla tool outputs lock dependency, sleep and jumps to 1.\n\nUsage:\n  dla is just a proof of concept, so it detects deadlocks in cycle and always\n  outputs the result.  To test it you can simply run ./test-deadlock, the\n  application which creates 3 deadlock loops:\n\n  $ ./test-deadlock\n  loop 1 started\n  loop 2 started\n  loop 3 started\n\n  And in the second console\n\n  $ sudo ./dla\n\n  Yes, it requires root because dla scans all processes on the system.\n\n  The output is like this:\n\n----------------------------------------------\n1) lock loopback:\n  tid 21070 (tgid 21063) waits for tid 21070:\n    00007f65cdd1b10c __lll_lock_wait + 0x1c\n    00007f65cdd15885 pthread_mutex_lock + 0x75\n    00000000004009ca thread_start + 0x74\n    00007f65cdd13314 start_thread + 0xc4\n    00007f65cda513ed clone + 0x6d\n\n----------------------------------------------\n2) lock loopback:\n  tid 21065 (tgid 21063) waits for tid 21064:\n    00007f65cdd1b10c __lll_lock_wait + 0x1c\n    00007f65cdd15885 pthread_mutex_lock + 0x75\n    00000000004009ca thread_start + 0x74\n    00007f65cdd13314 start_thread + 0xc4\n    00007f65cda513ed clone + 0x6d\n\n  tid 21064 (tgid 21063) waits for tid 21065:\n    00007f65cdd1b10c __lll_lock_wait + 0x1c\n    00007f65cdd15885 pthread_mutex_lock + 0x75\n    00000000004009ca thread_start + 0x74\n    00007f65cdd13314 start_thread + 0xc4\n    00007f65cda513ed clone + 0x6d\n\ntasks which wait for loopback:\n  tid 21069 (tgid 21063) waits for tid 21068:\n    00007f65cdd1b10c __lll_lock_wait + 0x1c\n    00007f65cdd15885 pthread_mutex_lock + 0x75\n    00000000004009ca thread_start + 0x74\n    00007f65cdd13314 start_thread + 0xc4\n    00007f65cda513ed clone + 0x6d\n\n  tid 21068 (tgid 21063) waits for tid 21066:\n    00007f65cdd1b10c __lll_lock_wait + 0x1c\n    00007f65cdd15885 pthread_mutex_lock + 0x75\n    00000000004009ca thread_start + 0x74\n    00007f65cdd13314 start_thread + 0xc4\n    00007f65cda513ed clone + 0x6d\n\n  tid 21066 (tgid 21063) waits for tid 21065:\n    00007f65cdd1b10c __lll_lock_wait + 0x1c\n    00007f65cdd15885 pthread_mutex_lock + 0x75\n    00000000004009ca thread_start + 0x74\n    00007f65cdd13314 start_thread + 0xc4\n    00007f65cda513ed clone + 0x6d\n\n  tid 21067 (tgid 21063) waits for tid 21066:\n    00007f65cdd1b10c __lll_lock_wait + 0x1c\n    00007f65cdd15885 pthread_mutex_lock + 0x75\n    00000000004009ca thread_start + 0x74\n    00007f65cdd13314 start_thread + 0xc4\n    00007f65cda513ed clone + 0x6d\n\nAuthor:\n  Roman Pen \u003cr.peniaev@gmail.com\u003e, 2014","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frouming%2Fdla","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frouming%2Fdla","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frouming%2Fdla/lists"}