Large diffs are not rendered by default.

@@ -7,6 +7,7 @@
#include <linux/ktime.h>
#include <linux/init.h>
#include <linux/uaccess.h>
#include <linux/percpu.h>

#include "sched.h"
#include "atlas_common.h"
@@ -81,17 +82,19 @@ size_t print_atlas_job(const struct atlas_job const *job, char *buf,
if (job != NULL) {
return scnprintf(buf, size,
"Job %5llu %8lld - %8lld (%8lld/%4lld/%4lld) "
"%s/%5d %s %7s %d %d\n",
"%s/%5d %*pb/%*pb %7s %7s %d %d %7s\n",
job->id, ktime_to_ms(job_start(job)),
ktime_to_ms(job->sdeadline),
ktime_to_ms(job->deadline),
ktime_to_ms(job->sexectime),
ktime_to_ms(job->rexectime), job->tsk->comm,
task_tid(job->tsk),
!task_on_rq_queued(job->tsk) ? "blocked"
: " ",
cpumask_pr_args(tsk_cpus_allowed(job->tsk)),
cpumask_pr_args(&job->tsk->atlas.last_mask),
!task_on_rq_queued(job->tsk) ? "blocked" : "",
task_sched_name(job->tsk), job->original_cpu,
task_cpu(job->tsk));
task_cpu(job->tsk),
job->started ? "started" : "");
}
return 0;
}
@@ -135,7 +138,6 @@ size_t print_rqs(char *buf, size_t size)
int cpu;
for_each_possible_cpu(cpu) /*online?*/
{
unsigned long flags;
struct rq *rq = cpu_rq(cpu);
offset += print_rq(rq, &buf[offset], size - offset);
}
@@ -185,6 +187,7 @@ static int __init init_atlas_debugfs(void)
return -1;

for (flag = SYS_NEXT; flag < NUM_FLAGS; ++flag) {
atlas_debug_flags[flag] = 0;
atlas_debug_files[flag] = debugfs_create_bool(
flag2string(flag), mode, atlas_debug,
&atlas_debug_flags[flag]);
@@ -206,3 +209,38 @@ void deinit_atlas_debugfs(void)
}

fs_initcall(init_atlas_debugfs);

static const size_t buf_size = 8192 * 2;
DEFINE_PER_CPU(char *, atlas_buf);

static int __init atlasbuf(void)
{
int cpu;
int ret = 0;
for_each_possible_cpu(cpu)
{
per_cpu(atlas_buf, cpu) = kmalloc(buf_size, GFP_KERNEL);
printk(KERN_INFO "ATLAS debug buffer %p\n",
per_cpu(atlas_buf, cpu));
if (per_cpu(atlas_buf, cpu) == NULL)
ret = -ENOMEM;
}

return ret;
}
core_initcall(atlasbuf);

void debug_rq(struct rq *rq)
{
char **buf = this_cpu_ptr(&atlas_buf);

if (*buf == NULL)
return;

(*buf)[0] = 0;
if (rq == NULL)
rq = this_rq();
print_rq(rq, *buf, buf_size);
printk_deferred(KERN_EMERG "%s\n", *buf);
}

@@ -84,7 +84,9 @@ static inline const char *job_rq_name(struct atlas_job *job)

static inline const char *task_sched_name(struct task_struct *tsk)
{
if (tsk->sched_class == &stop_sched_class)
if (tsk == NULL)
return "(null)";
else if (tsk->sched_class == &stop_sched_class)
return "STOP";
else if (tsk->sched_class == &dl_sched_class)
return "DEADLINE";
@@ -111,6 +113,21 @@ static unsigned rq_nr_jobs(const struct rb_root *root)
return nr_jobs;
}

static unsigned task_nr_jobs(struct task_struct *tsk)
{
unsigned nr_jobs = 0;
struct rq * rq = task_rq(tsk);
struct atlas_rq * atlas_rq = &rq->atlas;
struct atlas_job * job;

for (job = pick_first_job(&atlas_rq->jobs[ATLAS]); job;
job = pick_next_job(job)) {
nr_jobs += job->tsk == tsk;
}

return nr_jobs;
}

static inline pid_t task_tid(struct task_struct *tsk)
{
struct pid_namespace *ns;
@@ -123,7 +140,7 @@ static inline pid_t task_tid(struct task_struct *tsk)
return task_pid_nr(tsk);
}

extern void sched_log(const char *fmt, ...);
void debug_rq(struct rq *rq);

#define RQ_FMT "%d (%d %u/%lu %d/%d/%d %d)%s"
#define RQ_ARG(rq) \
@@ -135,7 +152,8 @@ extern void sched_log(const char *fmt, ...);
(rq->atlas.timer_target == ATLAS_SLACK) ? " (slack)" \
: ""

#define JOB_FMT "Job %s/%d/%lld (e: %lld/%lld/%lld, d: %lld/%lld, %s %d)"
#define JOB_FMT \
"Job %s/%d/%lld (e: %lld/%lld/%lld, d: %lld/%lld, %s/%s %d/%d%s)"
#define JOB_ARG(job) \
(job) ? (job)->tsk->comm : "(none)", (job) ? task_tid(job->tsk) : 0, \
(job) ? job->id : -1, \
@@ -144,7 +162,10 @@ extern void sched_log(const char *fmt, ...);
(job) ? ktime_to_ms((job)->exectime) : -1, \
(job) ? ktime_to_ms((job)->sdeadline) : -1, \
(job) ? ktime_to_ms((job)->deadline) : -1, \
job_rq_name(job), job->original_cpu
(job) ? task_sched_name(job->tsk) : "(no job)", \
job_rq_name(job), (job) ? job->original_cpu : 0, \
((job) && (job)->tsk) ? task_cpu((job)->tsk) : -1, \
((job) && (job)->started) ? " started" : ""

#define atlas_debug_(flag, fmt, ...) \
do { \
@@ -157,10 +178,11 @@ extern void sched_log(const char *fmt, ...);
#define atlas_debug(flag, fmt, ...) \
do { \
if (is_flag_enabled(flag)) { \
printk_deferred(KERN_DEBUG "CPU %d/%d [" #flag \
printk_deferred(KERN_DEBUG "CPU %d/%d/%s [" #flag \
"](%d): " fmt "\n", \
smp_processor_id(), task_tid(current), \
__LINE__, ##__VA_ARGS__); \
task_sched_name(current), __LINE__, \
##__VA_ARGS__); \
} \
} while (0)

@@ -1355,7 +1355,7 @@ int select_task_rq(struct task_struct *p, int cpu, int sd_flags, int wake_flags)
cpu = p->sched_class->select_task_rq(p, cpu, sd_flags, wake_flags);

#ifdef CONFIG_ATLAS
if (atlas_task(p) || task_has_jobs(p))
if (atlas_task(p))
cpu = p->sched_class->select_task_rq(p, cpu, sd_flags,
wake_flags);
#endif
@@ -1830,9 +1830,12 @@ static void __sched_fork(unsigned long clone_flags, struct task_struct *p)
p->atlas.nr_jobs[CFS] = 0;

p->atlas.last_cpu = -1;
p->atlas.last_mask = CPU_MASK_NONE;
cpumask_copy(&p->atlas.last_mask, &p->cpus_allowed);

hrtimer_init(&p->atlas.timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS_PINNED);
p->atlas.horizon = 0;
p->atlas.reservation = 0;

hrtimer_init(&p->atlas.timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
p->atlas.timer.function = &atlas_timer_task_function;
#endif

@@ -4804,6 +4807,7 @@ void do_set_cpus_allowed(struct task_struct *p, const struct cpumask *new_mask)
p->sched_class->set_cpus_allowed(p, new_mask);

#ifdef CONFIG_ATLAS
cpumask_copy(&p->atlas.last_mask, new_mask);
if (task_can_migrate(p)) {
cpumask_copy(&p->cpus_allowed, new_mask);
p->nr_cpus_allowed = cpumask_weight(new_mask);