Skip to content

Thread exit deadlock #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions kernel/sched/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -2798,8 +2798,7 @@ static void __sched_fork(unsigned long clone_flags, struct task_struct *p)
p->rt.time_slice = sched_rr_timeslice;
p->rt.on_rq = 0;
p->rt.on_list = 0;
init_run_list_mos(p);
init_util_list_mos(p);
init_fork_mos(p);

#ifdef CONFIG_PREEMPT_NOTIFIERS
INIT_HLIST_HEAD(&p->preempt_notifiers);
Expand Down
22 changes: 14 additions & 8 deletions kernel/sched/mos.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,13 +345,14 @@ static void uncommit_cpu(struct task_struct *p)
struct mos_rq *mos_rq;
int cpu = p->mos.cpu_home;
int underflow = 0;
unsigned long flags;

if (cpu < 0)
return;
mos_rq = &cpu_rq(cpu)->mos;
p->mos.cpu_home = -1;

raw_spin_lock(&mos_rq->lock);
raw_spin_lock_irqsave(&mos_rq->lock, flags);
if (p->mos.thread_type == mos_thread_type_normal) {
if (mos_rq->compute_commits > 0)
mos_rq->compute_commits--;
Expand All @@ -364,7 +365,7 @@ static void uncommit_cpu(struct task_struct *p)
else
underflow = 1;
}
raw_spin_unlock(&mos_rq->lock);
raw_spin_unlock_irqrestore(&mos_rq->lock, flags);

trace_mos_cpu_uncommit(p, cpu, mos_rq->compute_commits,
mos_rq->utility_commits, underflow);
Expand All @@ -375,11 +376,12 @@ static void commit_cpu(struct task_struct *p, int cpu)
struct mos_rq *mos_rq;
unsigned int newval = 0;
int overflow = 0;
unsigned long flags;

if (cpu < 0)
return;
mos_rq = &cpu_rq(cpu)->mos;
raw_spin_lock(&mos_rq->lock);
raw_spin_lock_irqsave(&mos_rq->lock, flags);
if (p->mos.thread_type == mos_thread_type_normal) {
if (mos_rq->compute_commits < INT_MAX) {
newval = ++mos_rq->compute_commits;
Expand All @@ -395,7 +397,7 @@ static void commit_cpu(struct task_struct *p, int cpu)
} else
overflow = 1;
}
raw_spin_unlock(&mos_rq->lock);
raw_spin_unlock_irqrestore(&mos_rq->lock, flags);
p->mos.cpu_home = cpu;
trace_mos_cpu_commit(p, cpu, mos_rq->compute_commits,
mos_rq->utility_commits, overflow);
Expand Down Expand Up @@ -2991,8 +2993,13 @@ static void task_fork_mos(struct task_struct *p)

p->prio = current->prio;
p->normal_prio = current->prio;
p->mos.thread_type = mos_thread_type_normal;
p->mos.cpu_home = -1;

/* We need to remove the commit placed on the CPU that called clone.
* This occurred in core.c->sched_fork->__select_task_cpu. This needs
* to be done prior to selecting the target CPU for this new thread
* which occurs in core.c->wake_up_new_task.
*/
uncommit_cpu(p);

/*
* We need to set the cpus allowed mask appropriately. If this is
Expand Down Expand Up @@ -3054,8 +3061,7 @@ static void task_fork_mos(struct task_struct *p)

void mos_set_task_cpu(struct task_struct *p, int new_cpu)
{
if (task_cpu(p) != new_cpu &&
cpu_rq(new_cpu)->lwkcpu &&
if (cpu_rq(new_cpu)->lwkcpu &&
p->mos_process &&
new_cpu != p->mos.cpu_home) {
/* Release a previous commit if it exists */
Expand Down
11 changes: 11 additions & 0 deletions kernel/sched/mos.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ static inline bool is_migration_mask_valid_mos(const cpumask_t *mask,
return false;
}

static inline void init_fork_mos(struct task_struct *p)
{
p->mos.cpu_home = -1;
p->mos.thread_type = mos_thread_type_normal;
init_run_list_mos(p);
init_util_list_mos(p);
}

#else

static inline void assimilate_mos(struct rq *rq, struct task_struct *p)
Expand Down Expand Up @@ -236,6 +244,9 @@ static inline bool is_migration_mask_valid_mos(const cpumask_t *mask,
return false;
}

static inline void init_fork_mos(struct task_struct *p)
{}

#endif

#ifdef CONFIG_MOS_MOVE_SYSCALLS
Expand Down