Skip to content

Commit 9b3c4ab

Browse files
author
Peter Zijlstra
committed
sched,rcu: Rework try_invoke_on_locked_down_task()
Give try_invoke_on_locked_down_task() a saner name and have it return an int so that the caller might distinguish between different reasons of failure. Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Acked-by: Paul E. McKenney <[email protected]> Acked-by: Vasily Gorbik <[email protected]> Tested-by: Vasily Gorbik <[email protected]> # on s390 Link: https://lkml.kernel.org/r/[email protected]
1 parent f6ac18f commit 9b3c4ab

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

include/linux/wait.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,7 @@ int autoremove_wake_function(struct wait_queue_entry *wq_entry, unsigned mode, i
11601160
(wait)->flags = 0; \
11611161
} while (0)
11621162

1163-
bool try_invoke_on_locked_down_task(struct task_struct *p, bool (*func)(struct task_struct *t, void *arg), void *arg);
1163+
typedef int (*task_call_f)(struct task_struct *p, void *arg);
1164+
extern int task_call_func(struct task_struct *p, task_call_f func, void *arg);
11641165

11651166
#endif /* _LINUX_WAIT_H */

kernel/rcu/tasks.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@ static void trc_read_check_handler(void *t_in)
928928
}
929929

930930
/* Callback function for scheduler to check locked-down task. */
931-
static bool trc_inspect_reader(struct task_struct *t, void *arg)
931+
static int trc_inspect_reader(struct task_struct *t, void *arg)
932932
{
933933
int cpu = task_cpu(t);
934934
bool in_qs = false;
@@ -939,15 +939,15 @@ static bool trc_inspect_reader(struct task_struct *t, void *arg)
939939

940940
// If no chance of heavyweight readers, do it the hard way.
941941
if (!ofl && !IS_ENABLED(CONFIG_TASKS_TRACE_RCU_READ_MB))
942-
return false;
942+
return -EINVAL;
943943

944944
// If heavyweight readers are enabled on the remote task,
945945
// we can inspect its state despite its currently running.
946946
// However, we cannot safely change its state.
947947
n_heavy_reader_attempts++;
948948
if (!ofl && // Check for "running" idle tasks on offline CPUs.
949949
!rcu_dynticks_zero_in_eqs(cpu, &t->trc_reader_nesting))
950-
return false; // No quiescent state, do it the hard way.
950+
return -EINVAL; // No quiescent state, do it the hard way.
951951
n_heavy_reader_updates++;
952952
if (ofl)
953953
n_heavy_reader_ofl_updates++;
@@ -962,15 +962,15 @@ static bool trc_inspect_reader(struct task_struct *t, void *arg)
962962
t->trc_reader_checked = true;
963963

964964
if (in_qs)
965-
return true; // Already in quiescent state, done!!!
965+
return 0; // Already in quiescent state, done!!!
966966

967967
// The task is in a read-side critical section, so set up its
968968
// state so that it will awaken the grace-period kthread upon exit
969969
// from that critical section.
970970
atomic_inc(&trc_n_readers_need_end); // One more to wait on.
971971
WARN_ON_ONCE(READ_ONCE(t->trc_reader_special.b.need_qs));
972972
WRITE_ONCE(t->trc_reader_special.b.need_qs, true);
973-
return true;
973+
return 0;
974974
}
975975

976976
/* Attempt to extract the state for the specified task. */
@@ -992,7 +992,7 @@ static void trc_wait_for_one_reader(struct task_struct *t,
992992

993993
// Attempt to nail down the task for inspection.
994994
get_task_struct(t);
995-
if (try_invoke_on_locked_down_task(t, trc_inspect_reader, NULL)) {
995+
if (!task_call_func(t, trc_inspect_reader, NULL)) {
996996
put_task_struct(t);
997997
return;
998998
}

kernel/rcu/tree_stall.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,16 +240,16 @@ struct rcu_stall_chk_rdr {
240240
* Report out the state of a not-running task that is stalling the
241241
* current RCU grace period.
242242
*/
243-
static bool check_slow_task(struct task_struct *t, void *arg)
243+
static int check_slow_task(struct task_struct *t, void *arg)
244244
{
245245
struct rcu_stall_chk_rdr *rscrp = arg;
246246

247247
if (task_curr(t))
248-
return false; // It is running, so decline to inspect it.
248+
return -EBUSY; // It is running, so decline to inspect it.
249249
rscrp->nesting = t->rcu_read_lock_nesting;
250250
rscrp->rs = t->rcu_read_unlock_special;
251251
rscrp->on_blkd_list = !list_empty(&t->rcu_node_entry);
252-
return true;
252+
return 0;
253253
}
254254

255255
/*
@@ -283,7 +283,7 @@ static int rcu_print_task_stall(struct rcu_node *rnp, unsigned long flags)
283283
raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
284284
while (i) {
285285
t = ts[--i];
286-
if (!try_invoke_on_locked_down_task(t, check_slow_task, &rscr))
286+
if (task_call_func(t, check_slow_task, &rscr))
287287
pr_cont(" P%d", t->pid);
288288
else
289289
pr_cont(" P%d/%d:%c%c%c%c",

kernel/sched/core.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4110,7 +4110,7 @@ try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags)
41104110
}
41114111

41124112
/**
4113-
* try_invoke_on_locked_down_task - Invoke a function on task in fixed state
4113+
* task_call_func - Invoke a function on task in fixed state
41144114
* @p: Process for which the function is to be invoked, can be @current.
41154115
* @func: Function to invoke.
41164116
* @arg: Argument to function.
@@ -4123,12 +4123,12 @@ try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags)
41234123
* Returns:
41244124
* Whatever @func returns
41254125
*/
4126-
bool try_invoke_on_locked_down_task(struct task_struct *p, bool (*func)(struct task_struct *t, void *arg), void *arg)
4126+
int task_call_func(struct task_struct *p, task_call_f func, void *arg)
41274127
{
41284128
struct rq *rq = NULL;
41294129
unsigned int state;
41304130
struct rq_flags rf;
4131-
bool ret = false;
4131+
int ret;
41324132

41334133
raw_spin_lock_irqsave(&p->pi_lock, rf.flags);
41344134

0 commit comments

Comments
 (0)