Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755984AbbBPSxb (ORCPT ); Mon, 16 Feb 2015 13:53:31 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59726 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755413AbbBPSxZ (ORCPT ); Mon, 16 Feb 2015 13:53:25 -0500 From: Josh Poimboeuf To: Andrew Morton , Ingo Molnar , Peter Zijlstra Cc: Jiri Kosina , Seth Jennings , linux-kernel@vger.kernel.org Subject: [PATCH 1/3] sched: add sched_task_call() Date: Mon, 16 Feb 2015 12:52:34 -0600 Message-Id: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2051 Lines: 62 Add a sched_task_call() to allow a callback function to be called with the task's rq locked. It guarantees that a task remains either active or inactive during the function call, without having to expose rq locking details outside of the scheduler. Signed-off-by: Josh Poimboeuf --- include/linux/sched.h | 4 ++++ kernel/sched/core.c | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/include/linux/sched.h b/include/linux/sched.h index 41c60e5..9b61e66 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -2506,6 +2506,10 @@ static inline void set_task_comm(struct task_struct *tsk, const char *from) } extern char *get_task_comm(char *to, struct task_struct *tsk); +typedef void (*sched_task_call_func_t)(struct task_struct *tsk, void *data); +extern void sched_task_call(sched_task_call_func_t func, + struct task_struct *tsk, void *data); + #ifdef CONFIG_SMP void scheduler_ipi(void); extern unsigned long wait_task_inactive(struct task_struct *, long match_state); diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 13049aa..c83a451 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -1338,6 +1338,23 @@ void kick_process(struct task_struct *p) EXPORT_SYMBOL_GPL(kick_process); #endif /* CONFIG_SMP */ +/*** + * sched_task_call - call a function with a task's state locked + * + * The task is guaranteed to remain either active or inactive during the + * function call. + */ +void sched_task_call(sched_task_call_func_t func, struct task_struct *p, + void *data) +{ + unsigned long flags; + struct rq *rq; + + rq = task_rq_lock(p, &flags); + func(p, data); + task_rq_unlock(rq, p, &flags); +} + #ifdef CONFIG_SMP /* * ->cpus_allowed is protected by both rq->lock and p->pi_lock -- 2.1.0 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/