From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933349AbdKCRFU (ORCPT ); Fri, 3 Nov 2017 13:05:20 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:56190 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1756252AbdKCRFK (ORCPT ); Fri, 3 Nov 2017 13:05:10 -0400 From: Chris Metcalf To: Davidlohr Bueso , Oleg Nesterov , Steven Rostedt , Ingo Molnar , Peter Zijlstra , Andrew Morton , Rik van Riel , Tejun Heo , Frederic Weisbecker , Thomas Gleixner , "Paul E. McKenney" , Christoph Lameter , Viresh Kumar , Catalin Marinas , Will Deacon , Andy Lutomirski , Michal Hocko , linux-kernel@vger.kernel.org Cc: Chris Metcalf Subject: [PATCH v16 04/13] Add try_get_task_struct_on_cpu() to scheduler for task isolation Date: Fri, 3 Nov 2017 13:04:43 -0400 Message-Id: <1509728692-10460-5-git-send-email-cmetcalf@mellanox.com> X-Mailer: git-send-email 2.1.2 In-Reply-To: <1509728692-10460-1-git-send-email-cmetcalf@mellanox.com> References: <1509728692-10460-1-git-send-email-cmetcalf@mellanox.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Task isolation wants to be able to verify that a remote core is running an isolated task to determine if it should generate a diagnostic, and also possibly interrupt it. This API returns a pointer to the task_struct of the task that was running on the specified core at the moment of the request; it uses try_get_task_struct() to increment the ref count on the returned task_struct so that the caller can examine it even if the actual remote task has already exited by that point. Signed-off-by: Chris Metcalf --- include/linux/sched/task.h | 1 + kernel/sched/core.c | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/include/linux/sched/task.h b/include/linux/sched/task.h index 270ff76d43d9..6785db926857 100644 --- a/include/linux/sched/task.h +++ b/include/linux/sched/task.h @@ -97,6 +97,7 @@ static inline void put_task_struct(struct task_struct *t) struct task_struct *task_rcu_dereference(struct task_struct **ptask); struct task_struct *try_get_task_struct(struct task_struct **ptask); +struct task_struct *try_get_task_struct_on_cpu(int cpu); #ifdef CONFIG_ARCH_WANTS_DYNAMIC_TASK_STRUCT diff --git a/kernel/sched/core.c b/kernel/sched/core.c index d17c5da523a0..2728154057ae 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -670,6 +670,17 @@ bool sched_can_stop_tick(struct rq *rq) } #endif /* CONFIG_NO_HZ_FULL */ +/* + * Return a pointer to the task_struct for the task that is running on + * the specified cpu at the time of the call (note that the task may have + * exited by the time the caller inspects the resulting task_struct). + * Caller must put_task_struct() with the pointer when finished with it. + */ +struct task_struct *try_get_task_struct_on_cpu(int cpu) +{ + return try_get_task_struct(&cpu_rq(cpu)->curr); +} + void sched_avg_update(struct rq *rq) { s64 period = sched_avg_period(); -- 2.1.2