On Fri, May 31, 2024 at 5:38 PM <devel-request@lists.crash-utility.osci.io> wrote:
Date: Fri, 31 May 2024 17:19:36 +0800
From: Tao Liu <ltao@redhat.com>
Subject: [Crash-utility] [PATCH v4 13/16] set_context(): check if
        context is already current
To: devel@lists.crash-utility.osci.io
Cc: Alexey Makhalov <alexey.makhalov@broadcom.com>, Mahesh J
        Salgaonkar <mahesh@linux.ibm.com>, "Naveen N . Rao"
        <naveen.n.rao@linux.vnet.ibm.com>, Lianbo Jiang <lijiang@redhat.com>
Message-ID: <20240531091939.97828-14-ltao@redhat.com>
Content-Type: text/plain; charset=UTF-8

From: Alexey Makhalov <alexey.makhalov@broadcom.com>

By doing it we avoid dropping gdb caches unnecessarily.

Cc: Sourabh Jain <sourabhjain@linux.ibm.com>
Cc: Hari Bathini <hbathini@linux.ibm.com>
Cc: Mahesh J Salgaonkar <mahesh@linux.ibm.com>
Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Cc: Lianbo Jiang <lijiang@redhat.com>
Cc: HAGIO KAZUHITO(萩尾 一仁) <k-hagio-ab@nec.com>
Cc: Tao Liu <ltao@redhat.com>
Cc: Alexey Makhalov <alexey.makhalov@broadcom.com>
Signed-off-by: Alexey Makhalov <alexey.makhalov@broadcom.com>
---
 task.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/task.c b/task.c
index 8c00837..3814f6d 100644
--- a/task.c
+++ b/task.c
@@ -5287,6 +5287,9 @@ set_context(ulong task, ulong pid, uint update_gdb_thread)
        struct task_context *tc;
        int found;

+       if (CURRENT_CONTEXT() && CURRENT_TASK() == task)
+               return TRUE;
+

Seems it makes sense.
I would suggest also adding the pid checking as below:

+       if (CURRENT_CONTEXT() && (CURRENT_TASK() == task || CURRENT_PID() == pid))
+               return TRUE;
+
What do you think?

Thanks
Lianbo 

        tc = FIRST_CONTEXT();

         for (i = 0, found = FALSE; i < RUNNING_TASKS(); i++, tc++) {
--
2.40.1