Re: [PATCH v4 2/3] hung_task: show the blocker task if the task is hung on semaphore

From: Andrew Morton
Date: Mon Apr 07 2025 - 16:09:36 EST


On Thu, 20 Mar 2025 14:49:22 +0800 Lance Yang <ioworker0@xxxxxxxxx> wrote:

> Inspired by mutex blocker tracking[1], this patch makes a trade-off to
> balance the overhead and utility of the hung task detector.
>
> Unlike mutexes, semaphores lack explicit ownership tracking, making it
> challenging to identify the root cause of hangs. To address this, we
> introduce a last_holder field to the semaphore structure, which is
> updated when a task successfully calls down() and cleared during up().
>
> The assumption is that if a task is blocked on a semaphore, the holders
> must not have released it. While this does not guarantee that the last
> holder is one of the current blockers, it likely provides a practical hint
> for diagnosing semaphore-related stalls.
>
> With this change, the hung task detector can now show blocker task's info
> like below:

+#ifdef CONFIG_DETECT_HUNG_TASK_BLOCKER
+#ifdef CONFIG_DETECT_HUNG_TASK_BLOCKER
+#ifdef CONFIG_DETECT_HUNG_TASK_BLOCKER
+#ifdef CONFIG_DETECT_HUNG_TASK_BLOCKER
+#ifdef CONFIG_DETECT_HUNG_TASK_BLOCKER
+#ifdef CONFIG_DETECT_HUNG_TASK_BLOCKER
+#ifdef CONFIG_DETECT_HUNG_TASK_BLOCKER
+#ifdef CONFIG_DETECT_HUNG_TASK_BLOCKER

It looks pretty simple to reduce the amount of ifdeffery which this
patch adds.