cregit-Linux how code gets into the kernel

Release 4.15 kernel/sched/core.c

Directory: kernel/sched
/*
 *  kernel/sched/core.c
 *
 *  Core kernel scheduler code and related syscalls
 *
 *  Copyright (C) 1991-2002  Linus Torvalds
 */
#include <linux/sched.h>
#include <linux/sched/clock.h>
#include <uapi/linux/sched/types.h>
#include <linux/sched/loadavg.h>
#include <linux/sched/hotplug.h>
#include <linux/wait_bit.h>
#include <linux/cpuset.h>
#include <linux/delayacct.h>
#include <linux/init_task.h>
#include <linux/context_tracking.h>
#include <linux/rcupdate_wait.h>
#include <linux/compat.h>

#include <linux/blkdev.h>
#include <linux/kprobes.h>
#include <linux/mmu_context.h>
#include <linux/module.h>
#include <linux/nmi.h>
#include <linux/prefetch.h>
#include <linux/profile.h>
#include <linux/security.h>
#include <linux/syscalls.h>
#include <linux/sched/isolation.h>

#include <asm/switch_to.h>
#include <asm/tlb.h>
#ifdef CONFIG_PARAVIRT
#include <asm/paravirt.h>
#endif

#include "sched.h"
#include "../workqueue_internal.h"
#include "../smpboot.h"


#define CREATE_TRACE_POINTS
#include <trace/events/sched.h>

DEFINE_PER_CPU_SHARED_ALIGNED(struct rq, runqueues);

#if defined(CONFIG_SCHED_DEBUG) && defined(HAVE_JUMP_LABEL)
/*
 * Debugging: various feature bits
 *
 * If SCHED_DEBUG is disabled, each compilation unit has its own copy of
 * sysctl_sched_features, defined in sched.h, to allow constants propagation
 * at compile time and compiler optimization based on features default.
 */

#define SCHED_FEAT(name, enabled)	\
	(1UL << __SCHED_FEAT_##name) * enabled |

const_debug unsigned int sysctl_sched_features =
#include "features.h"
	0;

#undef SCHED_FEAT
#endif

/*
 * Number of tasks to iterate in a single balance run.
 * Limited because this is done with IRQs disabled.
 */

const_debug unsigned int sysctl_sched_nr_migrate = 32;

/*
 * period over which we average the RT time consumption, measured
 * in ms.
 *
 * default: 1s
 */

const_debug unsigned int sysctl_sched_time_avg = MSEC_PER_SEC;

/*
 * period over which we measure -rt task CPU usage in us.
 * default: 1s
 */

unsigned int sysctl_sched_rt_period = 1000000;


__read_mostly int scheduler_running;

/*
 * part of the period that we allow rt tasks to run in us.
 * default: 0.95s
 */

int sysctl_sched_rt_runtime = 950000;

/*
 * __task_rq_lock - lock the rq @p resides on.
 */

struct rq *__task_rq_lock(struct task_struct *p, struct rq_flags *rf) __acquires(rq->lock) { struct rq *rq; lockdep_assert_held(&p->pi_lock); for (;;) { rq = task_rq(p); raw_spin_lock(&rq->lock); if (likely(rq == task_rq(p) && !task_on_rq_migrating(p))) { rq_pin_lock(rq, rf); return rq; } raw_spin_unlock(&rq->lock); while (unlikely(task_on_rq_migrating(p))) cpu_relax(); } }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra10697.25%266.67%
Matt Fleming32.75%133.33%
Total109100.00%3100.00%

/* * task_rq_lock - lock p->pi_lock and lock the rq @p resides on. */
struct rq *task_rq_lock(struct task_struct *p, struct rq_flags *rf) __acquires(p->pi_lock) __acquires(rq->lock) { struct rq *rq; for (;;) { raw_spin_lock_irqsave(&p->pi_lock, rf->flags); rq = task_rq(p); raw_spin_lock(&rq->lock); /* * move_queued_task() task_rq_lock() * * ACQUIRE (rq->lock) * [S] ->on_rq = MIGRATING [L] rq = task_rq() * WMB (__set_task_cpu()) ACQUIRE (rq->lock); * [S] ->cpu = new_cpu [L] task_rq() * [L] ->on_rq * RELEASE (rq->lock) * * If we observe the old cpu in task_rq_lock, the acquire of * the old rq->lock will fully serialize against the stores. * * If we observe the new CPU in task_rq_lock, the acquire will * pair with the WMB to ensure we must then also see migrating. */ if (likely(rq == task_rq(p) && !task_on_rq_migrating(p))) { rq_pin_lock(rq, rf); return rq; } raw_spin_unlock(&rq->lock); raw_spin_unlock_irqrestore(&p->pi_lock, rf->flags); while (unlikely(task_on_rq_migrating(p))) cpu_relax(); } }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra8765.91%240.00%
Ingo Molnar4433.33%240.00%
Matt Fleming10.76%120.00%
Total132100.00%5100.00%

/* * RQ-clock updating methods: */
static void update_rq_clock_task(struct rq *rq, s64 delta) { /* * In theory, the compile should just see 0 here, and optimize out the call * to sched_rt_avg_update. But I don't trust it... */ #if defined(CONFIG_IRQ_TIME_ACCOUNTING) || defined(CONFIG_PARAVIRT_TIME_ACCOUNTING) s64 steal = 0, irq_delta = 0; #endif #ifdef CONFIG_IRQ_TIME_ACCOUNTING irq_delta = irq_time_read(cpu_of(rq)) - rq->prev_irq_time; /* * Since irq_time is only updated on {soft,}irq_exit, we might run into * this case when a previous update_rq_clock() happened inside a * {soft,}irq region. * * When this happens, we stop ->clock_task and only update the * prev_irq_time stamp to account for the part that fit, so that a next * update will consume the rest. This ensures ->clock_task is * monotonic. * * It does however cause some slight miss-attribution of {soft,}irq * time, a more accurate solution would be to update the irq_time using * the current rq->clock timestamp, except that would require using * atomic ops. */ if (irq_delta > delta) irq_delta = delta; rq->prev_irq_time += irq_delta; delta -= irq_delta; #endif #ifdef CONFIG_PARAVIRT_TIME_ACCOUNTING if (static_key_false((&paravirt_steal_rq_enabled))) { steal = paravirt_steal_clock(cpu_of(rq)); steal -= rq->prev_steal_time_rq; if (unlikely(steal > delta)) steal = delta; rq->prev_steal_time_rq += steal; delta -= steal; } #endif rq->clock_task += delta; #if defined(CONFIG_IRQ_TIME_ACCOUNTING) || defined(CONFIG_PARAVIRT_TIME_ACCOUNTING) if ((irq_delta + steal) && sched_feat(NONTASK_CAPACITY)) sched_rt_avg_update(rq, irq_delta + steal); #endif }

Contributors

PersonTokensPropCommitsCommitProp
Ingo Molnar174100.00%1100.00%
Total174100.00%1100.00%


void update_rq_clock(struct rq *rq) { s64 delta; lockdep_assert_held(&rq->lock); if (rq->clock_update_flags & RQCF_ACT_SKIP) return; #ifdef CONFIG_SCHED_DEBUG if (sched_feat(WARN_DOUBLE_CLOCK)) SCHED_WARN_ON(rq->clock_update_flags & RQCF_UPDATED); rq->clock_update_flags |= RQCF_UPDATED; #endif delta = sched_clock_cpu(cpu_of(rq)) - rq->clock; if (delta < 0) return; rq->clock += delta; update_rq_clock_task(rq, delta); }

Contributors

PersonTokensPropCommitsCommitProp
Ingo Molnar5762.64%125.00%
Peter Zijlstra3437.36%375.00%
Total91100.00%4100.00%

#ifdef CONFIG_SCHED_HRTICK /* * Use HR-timers to deliver accurate preemption points. */
static void hrtick_clear(struct rq *rq) { if (hrtimer_active(&rq->hrtick_timer)) hrtimer_cancel(&rq->hrtick_timer); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra2689.66%350.00%
Gregory Haskins13.45%116.67%
Linus Torvalds13.45%116.67%
Steven Rostedt13.45%116.67%
Total29100.00%6100.00%

/* * High-resolution timer tick. * Runs from hardirq context with interrupts disabled. */
static enum hrtimer_restart hrtick(struct hrtimer *timer) { struct rq *rq = container_of(timer, struct rq, hrtick_timer); struct rq_flags rf; WARN_ON_ONCE(cpu_of(rq) != smp_processor_id()); rq_lock(rq, &rf); update_rq_clock(rq); rq->curr->sched_class->task_tick(rq, rq->curr, 1); rq_unlock(rq, &rf); return HRTIMER_NORESTART; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra6578.31%750.00%
Paul Turner910.84%17.14%
Mel Gorman33.61%17.14%
Peter Williams22.41%17.14%
Mike Galbraith11.20%17.14%
Ingo Molnar11.20%17.14%
Nikhil P Rao11.20%17.14%
Rik Van Riel11.20%17.14%
Total83100.00%14100.00%

#ifdef CONFIG_SMP
static void __hrtick_restart(struct rq *rq) { struct hrtimer *timer = &rq->hrtick_timer; hrtimer_start_expires(timer, HRTIMER_MODE_ABS_PINNED); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra1242.86%120.00%
Mel Gorman828.57%120.00%
Jason Baron517.86%120.00%
Thomas Gleixner27.14%120.00%
Paul Turner13.57%120.00%
Total28100.00%5100.00%

/* * called from hardirq (IPI) context */
static void __hrtick_start(void *arg) { struct rq *rq = arg; struct rq_flags rf; rq_lock(rq, &rf); __hrtick_restart(rq); rq->hrtick_csd_pending = 0; rq_unlock(rq, &rf); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra3675.00%654.55%
Paul Turner1020.83%327.27%
Ingo Molnar24.17%218.18%
Total48100.00%11100.00%

/* * Called to set the hrtick timer state. * * called with rq->lock held and irqs disabled */
void hrtick_start(struct rq *rq, u64 delay) { struct hrtimer *timer = &rq->hrtick_timer; ktime_t time; s64 delta; /* * Don't schedule slices shorter than 10000ns, that just * doesn't make sense and can cause timer DoS. */ delta = max_t(s64, delay, 10000LL); time = ktime_add_ns(timer->base->get_time(), delta); hrtimer_set_expires(timer, time); if (rq == this_rq()) { __hrtick_restart(rq); } else if (!rq->hrtick_csd_pending) { smp_call_function_single_async(cpu_of(rq), &rq->hrtick_csd); rq->hrtick_csd_pending = 1; } }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra6864.76%942.86%
xiaofeng.yan2019.05%14.76%
Ingo Molnar76.67%314.29%
Steven Rostedt32.86%14.76%
Andrew Morton10.95%14.76%
Paul Turner10.95%14.76%
Gregory Haskins10.95%14.76%
Frédéric Weisbecker10.95%14.76%
Tejun Heo10.95%14.76%
Paul Mackerras10.95%14.76%
Linus Torvalds10.95%14.76%
Total105100.00%21100.00%

#else /* * Called to set the hrtick timer state. * * called with rq->lock held and irqs disabled */
void hrtick_start(struct rq *rq, u64 delay) { /* * Don't schedule slices shorter than 10000ns, that just * doesn't make sense. Rely on vruntime for fairness. */ delay = max_t(u64, delay, 10000LL); hrtimer_start(&rq->hrtick_timer, ns_to_ktime(delay), HRTIMER_MODE_REL_PINNED); }

Contributors

PersonTokensPropCommitsCommitProp
Wanpeng Li1230.00%110.00%
Peter Zijlstra1127.50%220.00%
Tejun Heo820.00%110.00%
Alexey Dobriyan37.50%110.00%
Ingo Molnar25.00%110.00%
Mathieu Desnoyers12.50%110.00%
Thomas Gleixner12.50%110.00%
Rusty Russell12.50%110.00%
Linus Torvalds12.50%110.00%
Total40100.00%10100.00%

#endif /* CONFIG_SMP */
static void init_rq_hrtick(struct rq *rq) { #ifdef CONFIG_SMP rq->hrtick_csd_pending = 0; rq->hrtick_csd.flags = 0; rq->hrtick_csd.func = __hrtick_start; rq->hrtick_csd.info = rq; #endif hrtimer_init(&rq->hrtick_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); rq->hrtick_timer.function = hrtick; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra3146.97%228.57%
Tejun Heo2131.82%114.29%
Gregory Haskins812.12%114.29%
Linus Torvalds34.55%114.29%
Alexey Dobriyan23.03%114.29%
Rusty Russell11.52%114.29%
Total66100.00%7100.00%

#else /* CONFIG_SCHED_HRTICK */
static inline void hrtick_clear(struct rq *rq) { }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra11100.00%2100.00%
Total11100.00%2100.00%


static inline void init_rq_hrtick(struct rq *rq) { }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra11100.00%2100.00%
Total11100.00%2100.00%

#endif /* CONFIG_SCHED_HRTICK */ /* * cmpxchg based fetch_or, macro so it works for different integer types */ #define fetch_or(ptr, mask) \ ({ \ typeof(ptr) _ptr = (ptr); \ typeof(mask) _mask = (mask); \ typeof(*_ptr) _old, _val = *_ptr; \ \ for (;;) { \ _old = cmpxchg(_ptr, _val, _val | _mask); \ if (_old == _val) \ break; \ _val = _old; \ } \ _old; \ }) #if defined(CONFIG_SMP) && defined(TIF_POLLING_NRFLAG) /* * Atomically set TIF_NEED_RESCHED and test for TIF_POLLING_NRFLAG, * this avoids any races wrt polling state changes and thereby avoids * spurious IPIs. */
static bool set_nr_and_not_polling(struct task_struct *p) { struct thread_info *ti = task_thread_info(p); return !(fetch_or(&ti->flags, _TIF_NEED_RESCHED) & _TIF_POLLING_NRFLAG); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra37100.00%1100.00%
Total37100.00%1100.00%

/* * Atomically set TIF_NEED_RESCHED if TIF_POLLING_NRFLAG is set. * * If this returns true, then the idle task promises to call * sched_ttwu_pending() and reschedule soon. */
static bool set_nr_if_polling(struct task_struct *p) { struct thread_info *ti = task_thread_info(p); typeof(ti->flags) old, val = READ_ONCE(ti->flags); for (;;) { if (!(val & _TIF_POLLING_NRFLAG)) return false; if (val & _TIF_NEED_RESCHED) return true; old = cmpxchg(&ti->flags, val, val | _TIF_NEED_RESCHED); if (old == val) break; val = old; } return true; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra9398.94%150.00%
Jason Low11.06%150.00%
Total94100.00%2100.00%

#else
static bool set_nr_and_not_polling(struct task_struct *p) { set_tsk_need_resched(p); return true; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra19100.00%1100.00%
Total19100.00%1100.00%

#ifdef CONFIG_SMP
static bool set_nr_if_polling(struct task_struct *p) { return false; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra14100.00%1100.00%
Total14100.00%1100.00%

#endif #endif
void wake_q_add(struct wake_q_head *head, struct task_struct *task) { struct wake_q_node *node = &task->wake_q; /* * Atomically grab the task, if ->wake_q is !nil already it means * its already queued (either by us or someone else) and will get the * wakeup due to that. * * This cmpxchg() implies a full barrier, which pairs with the write * barrier implied by the wakeup in wake_up_q(). */ if (cmpxchg(&node->next, NULL, WAKE_Q_TAIL)) return; get_task_struct(task); /* * The head is context local, there can be no concurrency. */ *head->lastp = node; head->lastp = &node->next; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra6298.41%150.00%
Davidlohr Bueso A11.59%150.00%
Total63100.00%2100.00%


void wake_up_q(struct wake_q_head *head) { struct wake_q_node *node = head->first; while (node != WAKE_Q_TAIL) { struct task_struct *task; task = container_of(node, struct task_struct, wake_q); BUG_ON(!task); /* Task can safely be re-inserted now: */ node = node->next; task->wake_q.next = NULL; /* * wake_up_process() implies a wmb() to pair with the queueing * in wake_q_add() so as not to miss wakeups. */ wake_up_process(task); put_task_struct(task); } }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra7598.68%150.00%
Ingo Molnar11.32%150.00%
Total76100.00%2100.00%

/* * resched_curr - mark rq's current task 'to be rescheduled now'. * * On UP this means the setting of the need_resched flag, on SMP it * might also involve a cross-CPU call to trigger the scheduler on * the target CPU. */
void resched_curr(struct rq *rq) { struct task_struct *curr = rq->curr; int cpu; lockdep_assert_held(&rq->lock); if (test_tsk_need_resched(curr)) return; cpu = cpu_of(rq); if (cpu == smp_processor_id()) { set_tsk_need_resched(curr); set_preempt_need_resched(); return; } if (set_nr_and_not_polling(curr)) smp_send_reschedule(cpu); else trace_sched_wake_idle_without_ipi(cpu); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra3745.68%545.45%
Kirill V Tkhai1822.22%19.09%
Ingo Molnar1214.81%218.18%
Andrew Lutomirski67.41%19.09%
Gregory Haskins56.17%19.09%
Rusty Russell33.70%19.09%
Total81100.00%11100.00%


void resched_cpu(int cpu) { struct rq *rq = cpu_rq(cpu); unsigned long flags; raw_spin_lock_irqsave(&rq->lock, flags); resched_curr(rq); raw_spin_unlock_irqrestore(&rq->lock, flags); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra4289.36%457.14%
Kirill V Tkhai24.26%114.29%
Paul E. McKenney24.26%114.29%
Alexey Dobriyan12.13%114.29%
Total47100.00%7100.00%

#ifdef CONFIG_SMP #ifdef CONFIG_NO_HZ_COMMON /* * In the semi idle case, use the nearest busy CPU for migrating timers * from an idle CPU. This is good for power-savings. * * We don't do similar optimization for completely idle system, as * selecting an idle CPU will add more delays to the timers than intended * (as that CPU's timer base may not be uptodate wrt jiffies etc). */
int get_nohz_timer_target(void) { int i, cpu = smp_processor_id(); struct sched_domain *sd; if (!idle_cpu(cpu) && housekeeping_cpu(cpu, HK_FLAG_TIMER)) return cpu; rcu_read_lock(); for_each_domain(cpu, sd) { for_each_cpu(i, sched_domain_span(sd)) { if (cpu == i) continue; if (!idle_cpu(i) && housekeeping_cpu(i, HK_FLAG_TIMER)) { cpu = i; goto unlock; } } } if (!housekeeping_cpu(cpu, HK_FLAG_TIMER)) cpu = housekeeping_any_cpu(HK_FLAG_TIMER); unlock: rcu_read_unlock(); return cpu; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra5649.56%746.67%
Vatika Harlalka1815.93%16.67%
Frédéric Weisbecker1210.62%213.33%
Viresh Kumar119.73%16.67%
Wanpeng Li87.08%16.67%
Suresh B. Siddha54.42%213.33%
Thomas Gleixner32.65%16.67%
Total113100.00%15100.00%

/* * When add_timer_on() enqueues a timer into the timer wheel of an * idle CPU then this timer might expire before the next timer event * which is scheduled to wake up that CPU. In case of a completely * idle system the next event might even be infinite time into the * future. wake_up_idle_cpu() ensures that the CPU is woken up and * leaves the inner idle loop so the newly added timer is taken into * account when the CPU goes back to idle and evaluates the timer * wheel for the next timer event. */
static void wake_up_idle_cpu(int cpu) { struct rq *rq = cpu_rq(cpu); if (cpu == smp_processor_id()) return; if (set_nr_and_not_polling(rq->idle)) smp_send_reschedule(cpu); else trace_sched_wake_idle_without_ipi(cpu); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra3472.34%555.56%
Andrew Lutomirski714.89%222.22%
Alexey Dobriyan510.64%111.11%
Frédéric Weisbecker12.13%111.11%
Total47100.00%9100.00%


static bool wake_up_full_nohz_cpu(int cpu) { /* * We just need the target to call irq_exit() and re-evaluate * the next tick. The nohz full kick at least implies that. * If needed we can still optimize that later with an * empty IRQ. */ if (cpu_is_offline(cpu)) return true; /* Don't try to wake offline CPUs. */ if (tick_nohz_full_cpu(cpu)) { if (cpu != smp_processor_id() || tick_nohz_tick_stopped()) tick_nohz_full_kick_cpu(cpu); return true; } return false; }

Contributors

PersonTokensPropCommitsCommitProp
Frédéric Weisbecker4078.43%375.00%
Paul E. McKenney1121.57%125.00%
Total51100.00%4100.00%

/* * Wake up the specified CPU. If the CPU is going offline, it is the * caller's responsibility to deal with the lost wakeup, for example, * by hooking into the CPU_DEAD notifier like timers and hrtimers do. */
void wake_up_nohz_cpu(int cpu) { if (!wake_up_full_nohz_cpu(cpu)) wake_up_idle_cpu(cpu); }

Contributors

PersonTokensPropCommitsCommitProp
Frédéric Weisbecker21100.00%2100.00%
Total21100.00%2100.00%


static inline bool got_nohz_idle_kick(void) { int cpu = smp_processor_id(); if (!test_bit(NOHZ_BALANCE_KICK, nohz_flags(cpu))) return false; if (idle_cpu(cpu) && !need_resched()) return true; /* * We can't run Idle Load Balance on this CPU for this time so we * cancel it and clear NOHZ_BALANCE_KICK */ clear_bit(NOHZ_BALANCE_KICK, nohz_flags(cpu)); return false; }

Contributors

PersonTokensPropCommitsCommitProp
Vincent Guittot2949.15%116.67%
Peter Zijlstra2338.98%466.67%
Suresh B. Siddha711.86%116.67%
Total59100.00%6100.00%

#else /* CONFIG_NO_HZ_COMMON */
static inline bool got_nohz_idle_kick(void) { return false; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra12100.00%1100.00%
Total12100.00%1100.00%

#endif /* CONFIG_NO_HZ_COMMON */ #ifdef CONFIG_NO_HZ_FULL
bool sched_can_stop_tick(struct rq *rq) { int fifo_nr_running; /* Deadline tasks, even if single, need the tick */ if (rq->dl.dl_nr_running) return false; /* * If there are more than one RR tasks, we need the tick to effect the * actual RR behaviour. */ if (rq->rt.rr_nr_running) { if (rq->rt.rr_nr_running == 1) return true; else return false; } /* * If there's no RR tasks, but FIFO tasks, we can skip the tick, no * forced preemption between FIFO tasks. */ fifo_nr_running = rq->rt.rt_nr_running - rq->rt.rr_nr_running; if (fifo_nr_running) return true; /* * If there are no DL,RR/FIFO tasks, there must only be CFS tasks left; * if there's more than one we need the tick for involuntary * preemption. */ if (rq->nr_running > 1) return false; return true; }

Contributors

PersonTokensPropCommitsCommitProp
Frédéric Weisbecker5358.89%250.00%
Peter Zijlstra2426.67%125.00%
Rik Van Riel1314.44%125.00%
Total90100.00%4100.00%

#endif /* CONFIG_NO_HZ_FULL */
void sched_avg_update(struct rq *rq) { s64 period = sched_avg_period(); while ((s64)(rq_clock(rq) - rq->age_stamp) > period) { /* * Inline assembly required to prevent the compiler * optimising this loop into a divmod call. * See __iter_div_u64_rem() for another example of this. */ asm("" : "+rm" (rq->age_stamp)); rq->age_stamp += period; rq->rt_avg /= 2; } }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra3264.00%220.00%
Andrew Morton510.00%110.00%
Frédéric Weisbecker36.00%110.00%
Mike Galbraith36.00%110.00%
Gregory Haskins24.00%110.00%
Ingo Molnar24.00%220.00%
Alexey Dobriyan24.00%110.00%
Tejun Heo12.00%110.00%
Total50100.00%10100.00%

#endif /* CONFIG_SMP */ #if defined(CONFIG_RT_GROUP_SCHED) || (defined(CONFIG_FAIR_GROUP_SCHED) && \ (defined(CONFIG_SMP) || defined(CONFIG_CFS_BANDWIDTH))) /* * Iterate task_group tree rooted at *from, calling @down when first entering a * node and @up when leaving it for the final time. * * Caller must hold rcu_lock or sufficient equivalent. */
int walk_tg_tree_from(struct task_group *from, tg_visitor down, tg_visitor up, void *data) { struct task_group *parent, *child; int ret; parent = from; down: ret = (*down)(parent, data); if (ret) goto out; list_for_each_entry_rcu(child, &parent->children, siblings) { parent = child; goto down; up: continue; } ret = (*up)(parent, data); if (ret || parent == from) goto out; child = parent; parent = parent->parent; if (parent) goto up; out: return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra8973.55%562.50%
Tejun Heo1613.22%112.50%
Andrew Morton1310.74%112.50%
Gregory Haskins32.48%112.50%
Total121100.00%8100.00%


int tg_nop(struct task_group *tg, void *data) { return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra1164.71%133.33%
Peter Williams423.53%133.33%
Gregory Haskins211.76%133.33%
Total17100.00%3100.00%

#endif
static void set_load_weight(struct task_struct *p, bool update_load) { int prio = p->static_prio - MAX_RT_PRIO; struct load_weight *load = &p->se.load; /* * SCHED_IDLE tasks get minimal weight: */ if (idle_policy(p->policy)) { load->weight = scale_load(WEIGHT_IDLEPRIO); load->inv_weight = WMULT_IDLEPRIO; return; } /* * SCHED_OTHER tasks have to update their load when changing their * weight */ if (update_load && p->sched_class == &fair_sched_class) { reweight_task(p, prio); } else { load->weight = scale_load(sched_prio_to_weight[prio]); load->inv_weight = sched_prio_to_wmult[prio]; } }

Contributors

PersonTokensPropCommitsCommitProp
Vincent Guittot2725.00%17.69%
Ingo Molnar2523.15%215.38%
Nikhil P Rao2220.37%215.38%
Peter Zijlstra2119.44%323.08%
Gregory Haskins43.70%17.69%
Henrik Austad32.78%17.69%
Steven Rostedt32.78%17.69%
Andi Kleen21.85%17.69%
Tejun Heo10.93%17.69%
Total108100.00%13100.00%


static inline void enqueue_task(struct rq *rq, struct task_struct *p, int flags) { if (!(flags & ENQUEUE_NOCLOCK)) update_rq_clock(rq); if (!(flags & ENQUEUE_RESTORE)) sched_info_queued(rq, p); p->sched_class->enqueue_task(rq, p, flags); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra3047.62%538.46%
Alexey Dobriyan1320.63%17.69%
Ingo Molnar1015.87%17.69%
Steven Rostedt46.35%215.38%
Mike Galbraith34.76%215.38%
Michael S. Tsirkin23.17%17.69%
Tejun Heo11.59%17.69%
Total63100.00%13100.00%


static inline void dequeue_task(struct rq *rq, struct task_struct *p, int flags) { if (!(flags & DEQUEUE_NOCLOCK)) update_rq_clock(rq); if (!(flags & DEQUEUE_SAVE)) sched_info_dequeued(rq, p); p->sched_class->dequeue_task(rq, p, flags); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra4673.02%853.33%
Ingo Molnar914.29%213.33%
Michael S. Tsirkin23.17%16.67%
Tejun Heo23.17%16.67%
Mike Galbraith23.17%16.67%
Ankita Garg11.59%16.67%
Andrew Morton11.59%16.67%
Total63100.00%15100.00%


void activate_task(struct rq *rq, struct task_struct *p, int flags) { if (task_contributes_to_load(p)) rq->nr_uninterruptible--; enqueue_task(rq, p, flags); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra39100.00%3100.00%
Total39100.00%3100.00%


void deactivate_task(struct rq *rq, struct task_struct *p, int flags) { if (task_contributes_to_load(p)) rq->nr_uninterruptible++; dequeue_task(rq, p, flags); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra2871.79%360.00%
Mike Galbraith1025.64%120.00%
Andrew Morton12.56%120.00%
Total39100.00%5100.00%

/* * __normal_prio - return the priority that is based on the static prio */
static inline int __normal_prio(struct task_struct *p) { return p->static_prio; }

Contributors

PersonTokensPropCommitsCommitProp
Frédéric Weisbecker952.94%125.00%
Peter Williams423.53%125.00%
Venkatesh Pallipadi317.65%125.00%
Peter Zijlstra15.88%125.00%
Total17100.00%4100.00%

/* * Calculate the expected normal priority: i.e. priority * without taking RT-inheritance into account. Might be * boosted by interactivity modifiers. Changes upon fork, * setprio syscalls, and whenever the interactivity * estimator recalculates. */
static inline int normal_prio(struct task_struct *p) { int prio; if (task_has_dl_policy(p)) prio = MAX_DL_PRIO-1; else if (task_has_rt_policy(p)) prio = MAX_RT_PRIO-1 - p->rt_priority; else prio = __normal_prio(p); return prio; }

Contributors

PersonTokensPropCommitsCommitProp
Frédéric Weisbecker2543.86%19.09%
Dario Faggioli1424.56%19.09%
Mike Galbraith712.28%327.27%
Andrew Morton58.77%19.09%
Ingo Molnar35.26%218.18%
Lennart Poettering11.75%19.09%
Nicholas Piggin11.75%19.09%
Peter Williams11.75%19.09%
Total57100.00%11100.00%

/* * Calculate the current priority, i.e. the priority * taken into account by the scheduler. This value might * be boosted by RT tasks, or might be boosted by * interactivity modifiers. Will be RT if the task got * RT-boosted. If not then it returns p->normal_prio. */
static int effective_prio(struct task_struct *p) { p->normal_prio = normal_prio(p); /* * If we are RT tasks or we were boosted to RT priority, * keep the priority unchanged. Otherwise, update priority * to the normal priority: */ if (!rt_prio(p->prio)) return p->normal_prio; return p->prio; }

Contributors

PersonTokensPropCommitsCommitProp
Frédéric Weisbecker3278.05%116.67%
Peter Zijlstra37.32%116.67%
Mike Galbraith24.88%116.67%
Hiroshi Shimamoto24.88%116.67%
Ingo Molnar12.44%116.67%
Gregory Haskins12.44%116.67%
Total41100.00%6100.00%

/** * task_curr - is this task currently executing on a CPU? * @p: the task in question. * * Return: 1 if the task is currently executing. 0 otherwise. */
inline int task_curr(const struct task_struct *p) { return cpu_curr(task_cpu(p)) == p; }

Contributors

PersonTokensPropCommitsCommitProp
Frédéric Weisbecker1356.52%125.00%
Ingo Molnar521.74%125.00%
Glauber de Oliveira Costa313.04%125.00%
Gregory Haskins28.70%125.00%
Total23100.00%4100.00%

/* * switched_from, switched_to and prio_changed must _NOT_ drop rq->lock, * use the balance_callback list if you want balancing. * * this means any call to check_class_changed() must be followed by a call to * balance_callback(). */
static inline void check_class_changed(struct rq *rq, struct task_struct *p, const struct sched_class *prev_class, int oldprio) { if (prev_class != p->sched_class) { if (prev_class->switched_from) prev_class->switched_from(rq, p); p->sched_class->switched_to(rq, p); } else if (oldprio != p->prio || dl_task(p)) p->sched_class->prio_changed(rq, p, oldprio); }

Contributors

PersonTokensPropCommitsCommitProp
Frédéric Weisbecker5662.92%110.00%
Peter Zijlstra1112.36%330.00%
Glauber de Oliveira Costa88.99%110.00%
Dario Faggioli55.62%110.00%
Ingo Molnar44.49%110.00%
Steven Rostedt22.25%110.00%
Tejun Heo22.25%110.00%
Venkatesh Pallipadi11.12%110.00%
Total89100.00%10100.00%


void check_preempt_curr(struct rq *rq, struct task_struct *p, int flags) { const struct sched_class *class; if (p->sched_class == rq->curr->sched_class) { rq->curr->sched_class->check_preempt_curr(rq, p, flags); } else { for_each_class(class) { if (class == rq->curr->sched_class) break; if (class == p->sched_class) { resched_curr(rq); break; } } } /* * A queue event has occurred, and we're going to schedule. In * this case, we can save a useless back to back clock update. */ if (task_on_rq_queued(rq->curr) && test_tsk_need_resched(rq->curr)) rq_clock_skip_update(rq, true); }

Contributors

PersonTokensPropCommitsCommitProp
Frédéric Weisbecker8676.11%18.33%
Peter Zijlstra1715.04%433.33%
Kirill Tkhai32.65%18.33%
Steven Rostedt21.77%216.67%
Mike Galbraith21.77%18.33%
Glauber de Oliveira Costa10.88%18.33%
Ingo Molnar10.88%18.33%
Kirill V Tkhai10.88%18.33%
Total113100.00%12100.00%

#ifdef CONFIG_SMP /* * This is how migration works: * * 1) we invoke migration_cpu_stop() on the target CPU using * stop_one_cpu(). * 2) stopper starts to run (implicitly forcing the migrated thread * off the CPU) * 3) it checks whether the migrated task is still in the wrong runqueue. * 4) if it's in the wrong runqueue then the migration thread removes * it and puts it into the right queue. * 5) stopper completes and stop_one_cpu() returns and the migration * is done. */ /* * move_queued_task - move a queued task to new rq. * * Returns (locked) new rq. Old rq's lock is released. */
static struct rq *move_queued_task(struct rq *rq, struct rq_flags *rf, struct task_struct *p, int new_cpu) { lockdep_assert_held(&rq->lock); p->on_rq = TASK_ON_RQ_MIGRATING; dequeue_task(rq, p, DEQUEUE_NOCLOCK); set_task_cpu(p, new_cpu); rq_unlock(rq, rf); rq = cpu_rq(new_cpu); rq_lock(rq, rf); BUG_ON(task_cpu(p) != new_cpu); enqueue_task(rq, p, 0); p->on_rq = TASK_ON_RQ_QUEUED; check_preempt_curr(rq, p, 0); return rq; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra6859.65%541.67%
Frédéric Weisbecker2017.54%18.33%
Joonwoo Park1210.53%18.33%
Avi Kivity43.51%18.33%
Paul Turner43.51%18.33%
Andrew Morton32.63%18.33%
Venkatesh Pallipadi21.75%18.33%
Kirill Tkhai10.88%18.33%
Total114100.00%12100.00%

struct migration_arg { struct task_struct *task; int dest_cpu; }; /* * Move (not current) task off this CPU, onto the destination CPU. We're doing * this because either it can't run here any more (set_cpus_allowed() * away from this CPU, or CPU going down), or because we're * attempting to rebalance this task on exec (sched_exec). * * So we race with normal scheduler movements, but that's OK, as long * as the task is no longer on this CPU. */
static struct rq *__migrate_task(struct rq *rq, struct rq_flags *rf, struct task_struct *p, int dest_cpu) { if (p->flags & PF_KTHREAD) { if (unlikely(!cpu_online(dest_cpu))) return rq; } else { if (unlikely(!cpu_active(dest_cpu))) return rq; } /* Affinity changed (again). */ if (!cpumask_test_cpu(dest_cpu, &p->cpus_allowed)) return rq; update_rq_clock(rq); rq = move_queued_task(rq, rf, p, dest_cpu); return rq; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra7571.43%571.43%
Tejun Heo2725.71%114.29%
Ingo Molnar32.86%114.29%
Total105100.00%7100.00%

/* * migration_cpu_stop - this will be executed by a highprio stopper thread * and performs thread migration by bumping thread off CPU then * 'pushing' onto another runqueue. */
static int migration_cpu_stop(void *data) { struct migration_arg *arg = data; struct task_struct *p = arg->task; struct rq *rq = this_rq(); struct rq_flags rf; /* * The original target CPU might have gone down and we might * be on another CPU but it doesn't matter. */ local_irq_disable(); /* * We need to explicitly wake pending tasks before running * __migrate_task() such that we will not miss enforcing cpus_allowed * during wakeups, see set_cpus_allowed_ptr()'s TASK_WAKING test. */ sched_ttwu_pending(); raw_spin_lock(&p->pi_lock); rq_lock(rq, &rf); /* * If task_rq(p) != rq, it cannot be migrated here, because we're * holding rq->lock, if p->on_rq == 0 it cannot get enqueued because * we're holding p->pi_lock. */ if (task_rq(p) == rq) { if (task_on_rq_queued(p)) rq = __migrate_task(rq, &rf, p, arg->dest_cpu); else p->wake_cpu = arg->dest_cpu; } rq_unlock(rq, &rf); raw_spin_unlock(&p->pi_lock); local_irq_enable(); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra11388.28%571.43%
Cheng Chao1410.94%114.29%
Ingo Molnar10.78%114.29%
Total128100.00%7100.00%

/* * sched_class::set_cpus_allowed must do the below, but is not required to * actually call this function. */
void set_cpus_allowed_common(struct task_struct *p, const struct cpumask *new_mask) { cpumask_copy(&p->cpus_allowed, new_mask); p->nr_cpus_allowed = cpumask_weight(new_mask); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra35100.00%3100.00%
Total35100.00%3100.00%


void do_set_cpus_allowed(struct task_struct *p, const struct cpumask *new_mask) { struct rq *rq = task_rq(p); bool queued, running; lockdep_assert_held(&p->pi_lock); queued = task_on_rq_queued(p); running = task_current(rq, p); if (queued) { /* * Because __kthread_bind() calls this on blocked tasks without * holding rq->lock. */ lockdep_assert_held(&rq->lock); dequeue_task(rq, p, DEQUEUE_SAVE | DEQUEUE_NOCLOCK); } if (running) put_prev_task(rq, p); p->sched_class->set_cpus_allowed(p, new_mask); if (queued) enqueue_task(rq, p, ENQUEUE_RESTORE | ENQUEUE_NOCLOCK); if (running) set_curr_task(rq, p); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra12193.80%685.71%
Vincent Guittot86.20%114.29%
Total129100.00%7100.00%

/* * Change a given task's CPU affinity. Migrate the thread to a * proper CPU and schedule it away if the CPU it's executing on * is removed from the allowed bitmask. * * NOTE: the caller must have a valid reference to the task, the * task must not exit() & deallocate itself prematurely. The * call is not atomic; no spinlocks may be held. */
static int __set_cpus_allowed_ptr(struct task_struct *p, const struct cpumask *new_mask, bool check) { const struct cpumask *cpu_valid_mask = cpu_active_mask; unsigned int dest_cpu; struct rq_flags rf; struct rq *rq; int ret = 0; rq = task_rq_lock(p, &rf); update_rq_clock(rq); if (p->flags & PF_KTHREAD) { /* * Kernel threads are allowed on online && !active CPUs */ cpu_valid_mask = cpu_online_mask; } /* * Must re-check here, to close a race against __kthread_bind(), * sched_setaffinity() is not guaranteed to observe the flag. */ if (check && (p->flags & PF_NO_SETAFFINITY)) { ret = -EINVAL; goto out; } if (cpumask_equal(&p->cpus_allowed, new_mask)) goto out; if (!cpumask_intersects(new_mask, cpu_valid_mask)) { ret = -EINVAL; goto out; } do_set_cpus_allowed(p, new_mask); if (p->flags & PF_KTHREAD) { /* * For kernel threads that do indeed end up on online && * !active we want to ensure they are strict per-CPU threads. */ WARN_ON(cpumask_intersects(new_mask, cpu_online_mask) && !cpumask_intersects(new_mask, cpu_active_mask) && p->nr_cpus_allowed != 1); } /* Can the task run on the task's current CPU? If so, we're done */ if (cpumask_test_cpu(task_cpu(p), new_mask)) goto out; dest_cpu = cpumask_any_and(cpu_valid_mask, new_mask); if (task_running(rq, p) || p->state == TASK_WAKING) { struct migration_arg arg = { p, dest_cpu }; /* Need help from migration thread: drop lock and wait. */ task_rq_unlock(rq, p, &rf); stop_one_cpu(cpu_of(rq), migration_cpu_stop, &arg); tlb_migrate_finish(p->mm); return 0; } else if (task_on_rq_queued(p)) { /* * OK, since we're going to drop the lock immediately * afterwards anyway. */ rq = move_queued_task(rq, &rf, p, dest_cpu); } out: task_rq_unlock(rq, p, &rf); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra25484.11%956.25%
Frédéric Weisbecker3210.60%16.25%
Wanpeng Li51.66%16.25%
Ingo Molnar51.66%212.50%
Mel Gorman41.32%16.25%
Avi Kivity10.33%16.25%
Nicholas Piggin10.33%16.25%
Total302100.00%16100.00%


int set_cpus_allowed_ptr(struct task_struct *p, const struct cpumask *new_mask) { return __set_cpus_allowed_ptr(p, new_mask, false); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra26100.00%1100.00%
Total26100.00%1100.00%

EXPORT_SYMBOL_GPL(set_cpus_allowed_ptr);
void set_task_cpu(struct task_struct *p, unsigned int new_cpu) { #ifdef CONFIG_SCHED_DEBUG /* * We should never call set_task_cpu() on a blocked task, * ttwu() will sort out the placement. */ WARN_ON_ONCE(p->state != TASK_RUNNING && p->state != TASK_WAKING && !p->on_rq); /* * Migrating fair class task must have p->on_rq = TASK_ON_RQ_MIGRATING, * because schedstat_wait_{start,end} rebase migrating task's wait_start * time relying on p->on_rq. */ WARN_ON_ONCE(p->state == TASK_RUNNING && p->sched_class == &fair_sched_class && (p->on_rq && !task_on_rq_migrating(p))); #ifdef CONFIG_LOCKDEP /* * The caller should hold either p->pi_lock or rq->lock, when changing * a task's CPU. ->pi_lock for waking tasks, rq->lock for runnable tasks. * * sched_move_task() holds both and thus holding either pins the cgroup, * see task_group(). * * Furthermore, all task_rq users should acquire both locks, see * task_rq_lock(). */ WARN_ON_ONCE(debug_locks && !(lockdep_is_held(&p->pi_lock) || lockdep_is_held(&task_rq(p)->lock))); #endif /* * Clearly, migrating tasks to offline CPUs is a fairly daft thing. */ WARN_ON_ONCE(!cpu_online(new_cpu)); #endif trace_sched_migrate_task(p, new_cpu); if (task_cpu(p) != new_cpu) { if (p->sched_class->migrate_task_rq) p->sched_class->migrate_task_rq(p); p->se.nr_migrations++; perf_event_task_migrate(p); } __set_task_cpu(p, new_cpu); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra9456.63%323.08%
Joonwoo Park2917.47%17.69%
Frédéric Weisbecker1911.45%17.69%
Ingo Molnar159.04%430.77%
Andrew Morton53.01%17.69%
Linus Torvalds21.20%17.69%
Venkatesh Pallipadi10.60%17.69%
Lucas De Marchi10.60%17.69%
Total166100.00%13100.00%


static void __migrate_swap_task(struct task_struct *p, int cpu) { if (task_on_rq_queued(p)) { struct rq *src_rq, *dst_rq; struct rq_flags srf, drf; src_rq = task_rq(p); dst_rq = cpu_rq(cpu); rq_pin_lock(src_rq, &srf); rq_pin_lock(dst_rq, &drf); p->on_rq = TASK_ON_RQ_MIGRATING; deactivate_task(src_rq, p, 0); set_task_cpu(p, cpu); activate_task(dst_rq, p, 0); p->on_rq = TASK_ON_RQ_QUEUED; check_preempt_curr(dst_rq, p, 0); rq_unpin_lock(dst_rq, &drf); rq_unpin_lock(src_rq, &srf); } else { /* * Task isn't running anymore; make it appear like we migrated * it before it went to sleep. This means on wakeup we make the * previous CPU our target instead of where it really is. */ p->wake_cpu = cpu; } }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra7956.83%318.75%
Frédéric Weisbecker2215.83%16.25%
Joonwoo Park128.63%16.25%
Tang Chen107.19%16.25%
Ingo Molnar75.04%425.00%
Steven Rostedt42.88%16.25%
Glauber de Oliveira Costa21.44%212.50%
Peter Williams10.72%16.25%
Lennart Poettering10.72%16.25%
Gregory Haskins10.72%16.25%
Total139100.00%16100.00%

struct migration_swap_arg { struct task_struct *src_task, *dst_task; int src_cpu, dst_cpu; };
static int migrate_swap_stop(void *data) { struct migration_swap_arg *arg = data; struct rq *src_rq, *dst_rq; int ret = -EAGAIN; if (!cpu_active(arg->src_cpu) || !cpu_active(arg->dst_cpu)) return -EAGAIN; src_rq = cpu_rq(arg->src_cpu); dst_rq = cpu_rq(arg->dst_cpu); double_raw_lock(&arg->src_task->pi_lock, &arg->dst_task->pi_lock); double_rq_lock(src_rq, dst_rq); if (task_cpu(arg->dst_task) != arg->dst_cpu) goto unlock; if (task_cpu(arg->src_task) != arg->src_cpu) goto unlock; if (!cpumask_test_cpu(arg->dst_cpu, &arg->src_task->cpus_allowed)) goto unlock; if (!cpumask_test_cpu(arg->src_cpu, &arg->dst_task->cpus_allowed)) goto unlock; __migrate_swap_task(arg->src_task, arg->dst_cpu); __migrate_swap_task(arg->dst_task, arg->src_cpu); ret = 0; unlock: double_rq_unlock(src_rq, dst_rq); raw_spin_unlock(&arg->dst_task->pi_lock); raw_spin_unlock(&arg->src_task->pi_lock); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra16472.89%853.33%
Frédéric Weisbecker3816.89%16.67%
Ingo Molnar62.67%16.67%
Gregory Haskins52.22%16.67%
Steven Rostedt41.78%16.67%
Tang Chen41.78%16.67%
Glauber de Oliveira Costa20.89%16.67%
Hiroshi Shimamoto20.89%16.67%
Total225100.00%15100.00%

/* * Cross migrate two tasks */
int migrate_swap(struct task_struct *cur, struct task_struct *p) { struct migration_swap_arg arg; int ret = -EINVAL; arg = (struct migration_swap_arg){ .src_task = cur, .src_cpu = task_cpu(cur), .dst_task = p, .dst_cpu = task_cpu(p), }; if (arg.src_cpu == arg.dst_cpu) goto out; /* * These three tests are all lockless; this is OK since all of them * will be re-checked with proper locks held further down the line. */ if (!cpu_active(arg.src_cpu) || !cpu_active(arg.dst_cpu)) goto out; if (!cpumask_test_cpu(arg.dst_cpu, &arg.src_task->cpus_allowed)) goto out; if (!cpumask_test_cpu(arg.src_cpu, &arg.dst_task->cpus_allowed)) goto out; trace_sched_swap_numa(cur, arg.src_cpu, p, arg.dst_cpu); ret = stop_two_cpus(arg.dst_cpu, arg.src_cpu, migrate_swap_stop, &arg); out: return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra10862.79%635.29%
Frédéric Weisbecker3017.44%15.88%
Ingo Molnar158.72%317.65%
Andrew Morton74.07%15.88%
Gregory Haskins42.33%15.88%
Hiroshi Shimamoto21.16%15.88%
Linus Torvalds21.16%211.76%
Nicholas Piggin21.16%15.88%
Pavel Emelyanov21.16%15.88%
Total172100.00%17100.00%

/* * wait_task_inactive - wait for a thread to unschedule. * * If @match_state is nonzero, it's the @p->state value just checked and * not expected to change. If it changes, i.e. @p might have woken up, * then return zero. When we succeed in waiting for @p to be off its CPU, * we return a positive number (its total switch count). If a second call * a short while later returns the same number, the caller can be sure that * @p has remained unscheduled the whole time. * * The caller must ensure that the task *will* unschedule sometime soon, * else this function might spin for a *long* time. This function can't * be called with interrupts off, or it may introduce deadlock with * smp_call_function() if an IPI is sent by the same process we are * waiting to become inactive. */
unsigned long wait_task_inactive(struct task_struct *p, long match_state) { int running, queued; struct rq_flags rf; unsigned long ncsw; struct rq *rq; for (;;) { /* * We do the initial early heuristics without holding * any task-queue locks at all. We'll only try to get * the runqueue lock when things look like they will * work out! */ rq = task_rq(p); /* * If the task is actively running on another CPU * still, just relax and busy-wait without holding * any locks. * * NOTE! Since we don't hold any locks, it's not * even sure that "rq" stays as the right runqueue! * But we don't care, since "task_running()" will * return false if the runqueue has changed and p * is actually now running somewhere else! */ while (task_running(rq, p)) { if (match_state && unlikely(p->state != match_state)) return 0; cpu_relax(); } /* * Ok, time to look more closely! We need the rq * lock now, to be *sure*. If we're wrong, we'll * just go back and repeat. */ rq = task_rq_lock(p, &rf); trace_sched_wait_task(p); running = task_running(rq, p); queued = task_on_rq_queued(p); ncsw = 0; if (!match_state || p->state == match_state) ncsw = p->nvcsw | LONG_MIN; /* sets MSB */ task_rq_unlock(rq, p, &rf); /* * If it changed from the expected state, bail out now. */ if (unlikely(!ncsw)) break; /* * Was it really running after all now that we * checked with the proper locks actually held? * * Oops. Go back and try again.. */ if (unlikely(running)) { cpu_relax(); continue; } /* * It's not enough that it's not actively running, * it must be off the runqueue _entirely_, and not * preempted! * * So if it was still runnable (but just not actively * running right now), it's preempted, and we should * yield - it could be a while. */ if (unlikely(queued)) { ktime_t to = NSEC_PER_SEC / HZ; set_current_state(TASK_UNINTERRUPTIBLE); schedule_hrtimeout(&to, HRTIMER_MODE_REL); continue; } /* * Ahh, all good. It wasn't running, and it wasn't * runnable, which means that it will never become * running in the future either. We're all done! */ break; } return ncsw; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra11656.86%522.73%
Frédéric Weisbecker4522.06%29.09%
Andrew Morton94.41%14.55%
Ingo Molnar83.92%418.18%
Steven Rostedt62.94%29.09%
Nicholas Piggin52.45%29.09%
Jason Low52.45%14.55%
Linus Torvalds41.96%29.09%
Thomas Gleixner31.47%14.55%
Avi Kivity20.98%14.55%
Roland McGrath10.49%14.55%
Total204100.00%22100.00%

/*** * kick_process - kick a running thread to enter/exit the kernel * @p: the to-be-kicked thread * * Cause a process which is running on another CPU to enter * kernel-mode, without any delay. (to get signals handled.) * * NOTE: this function doesn't have to take the runqueue lock, * because all it wants to ensure is that the remote task enters * the kernel. If the IPI races and the task has been migrated * to another CPU then no harm is done and the purpose has been * achieved as well. */
void kick_process(struct task_struct *p) { int cpu; preempt_disable(); cpu = task_cpu(p); if ((cpu != smp_processor_id()) && task_curr(p)) smp_send_reschedule(cpu); preempt_enable(); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra2657.78%233.33%
Steven Rostedt1124.44%116.67%
Avi Kivity48.89%116.67%
Andrew Morton36.67%116.67%
Ingo Molnar12.22%116.67%
Total45100.00%6100.00%

EXPORT_SYMBOL_GPL(kick_process); /* * ->cpus_allowed is protected by both rq->lock and p->pi_lock * * A few notes on cpu_active vs cpu_online: * * - cpu_active must be a subset of cpu_online * * - on cpu-up we allow per-cpu kthreads on the online && !active cpu, * see __set_cpus_allowed_ptr(). At this point the newly online * CPU isn't yet part of the sched domains, and balancing will not * see it. * * - on CPU-down we clear cpu_active() to mask the sched domains and * avoid the load balancer to place new tasks on the to be removed * CPU. Existing tasks will remain running there and will be taken * off. * * This means that fallback selection must not select !active CPUs. * And can assume that any active CPU must be online. Conversely * select_task_rq() below may allow selection of !active CPUs in order * to satisfy the above rules. */
static int select_fallback_rq(int cpu, struct task_struct *p) { int nid = cpu_to_node(cpu); const struct cpumask *nodemask = NULL; enum { cpuset, possible, fail } state = cpuset; int dest_cpu; /* * If the node that the CPU is on has been offlined, cpu_to_node() * will return -1. There is no CPU on the node, and we should * select the CPU on the other node. */ if (nid != -1) { nodemask = cpumask_of_node(nid); /* Look for allowed, online CPU in same node. */ for_each_cpu(dest_cpu, nodemask) { if (!cpu_active(dest_cpu)) continue; if (cpumask_test_cpu(dest_cpu, &p->cpus_allowed)) return dest_cpu; } } for (;;) { /* Any allowed, online CPU? */ for_each_cpu(dest_cpu, &p->cpus_allowed) { if (!(p->flags & PF_KTHREAD) && !cpu_active(dest_cpu)) continue; if (!cpu_online(dest_cpu)) continue; goto out; } /* No more Mr. Nice Guy. */ switch (state) { case cpuset: if (IS_ENABLED(CONFIG_CPUSETS)) { cpuset_cpus_allowed_fallback(p); state = possible; break; } /* Fall-through */ case possible: do_set_cpus_allowed(p, cpu_possible_mask); state = fail; break; case fail: BUG(); break; } } out: if (state != cpuset) { /* * Don't tell them about moving exiting tasks or * kernel threads (both mm NULL), since they never * leave kernel. */ if (p->mm && printk_ratelimit()) { printk_deferred("process %d (%s) no longer affine to cpu%d\n", task_pid_nr(p), p->comm, cpu); } } return dest_cpu; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra18076.92%642.86%
Tejun Heo187.69%17.14%
Oleg Nesterov104.27%17.14%
Frédéric Weisbecker104.27%214.29%
Avi Kivity93.85%17.14%
Ingo Molnar62.56%214.29%
Rick Lindsley10.43%17.14%
Total234100.00%14100.00%

/* * The caller (fork, wakeup) owns p->pi_lock, ->cpus_allowed is stable. */
static inline int select_task_rq(struct task_struct *p, int cpu, int sd_flags, int wake_flags) { lockdep_assert_held(&p->pi_lock); if (p->nr_cpus_allowed > 1) cpu = p->sched_class->select_task_rq(p, cpu, sd_flags, wake_flags); else cpu = cpumask_any(&p->cpus_allowed); /* * In order not to call set_task_cpu() on a blocking task we need * to rely on ttwu() to place the task on a valid ->cpus_allowed * CPU. * * Since this is common to all placement strategies, this lives here. * * [ this allows ->select_task() to simply return task_cpu(p) and * not worry about this generic constraint ] */ if (unlikely(!cpumask_test_cpu(cpu, &p->cpus_allowed) || !cpu_online(cpu))) cpu = select_fallback_rq(task_cpu(p), p); return cpu; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra7471.84%950.00%
Ingo Molnar1817.48%527.78%
Frédéric Weisbecker76.80%15.56%
Arjan van de Ven21.94%15.56%
Rick Lindsley10.97%15.56%
Avi Kivity10.97%15.56%
Total103100.00%18100.00%


static void update_avg(u64 *avg, u64 sample) { s64 diff = sample - *avg; *avg += diff >> 3; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra2692.86%133.33%
Frédéric Weisbecker13.57%133.33%
Arjan van de Ven13.57%133.33%
Total28100.00%3100.00%


void sched_set_stop_task(int cpu, struct task_struct *stop) { struct sched_param param = { .sched_priority = MAX_RT_PRIO - 1 }; struct task_struct *old_stop = cpu_rq(cpu)->stop; if (stop) { /* * Make it appear like a SCHED_FIFO task, its something * userspace knows about and won't get confused about. * * Also, it will make PI more or less work without too * much confusion -- but then, stop work should not * rely on PI working anyway. */ sched_setscheduler_nocheck(stop, SCHED_FIFO, &param); stop->sched_class = &stop_sched_class; } cpu_rq(cpu)->stop = stop; if (old_stop) { /* * Reset it back to a normal scheduling class so that * it can die in pieces. */ old_stop->sched_class = &rt_sched_class; } }

Contributors

PersonTokensPropCommitsCommitProp
Nico Pitre85100.00%1100.00%
Total85100.00%1100.00%

#else
static inline int __set_cpus_allowed_ptr(struct task_struct *p, const struct cpumask *new_mask, bool check) { return set_cpus_allowed_ptr(p, new_mask); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra29100.00%1100.00%
Total29100.00%1100.00%

#endif /* CONFIG_SMP */
static void ttwu_stat(struct task_struct *p, int cpu, int wake_flags) { struct rq *rq; if (!schedstat_enabled()) return; rq = this_rq(); #ifdef CONFIG_SMP if (cpu == rq->cpu) { schedstat_inc(rq->ttwu_local); schedstat_inc(p->se.statistics.nr_wakeups_local); } else { struct sched_domain *sd; schedstat_inc(p->se.statistics.nr_wakeups_remote); rcu_read_lock(); for_each_domain(rq->cpu, sd) { if (cpumask_test_cpu(cpu, sched_domain_span(sd))) { schedstat_inc(sd->ttwu_wake_remote); break; } } rcu_read_unlock(); } if (wake_flags & WF_MIGRATED) schedstat_inc(p->se.statistics.nr_wakeups_migrate); #endif /* CONFIG_SMP */ schedstat_inc(rq->ttwu_count); schedstat_inc(p->se.statistics.nr_wakeups); if (wake_flags & WF_SYNC) schedstat_inc(p->se.statistics.nr_wakeups_sync); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra8246.86%330.00%
Chuansheng Liu4626.29%110.00%
Josh Poimboeuf2313.14%220.00%
Andrew Lutomirski84.57%110.00%
Ingo Molnar84.57%220.00%
Frédéric Weisbecker84.57%110.00%
Total175100.00%10100.00%


static inline void ttwu_activate(struct rq *rq, struct task_struct *p, int en_flags) { activate_task(rq, p, en_flags); p->on_rq = TASK_ON_RQ_QUEUED; /* If a worker is waking up, notify the workqueue: */ if (p->flags & PF_WQ_WORKER) wq_worker_waking_up(p, cpu_of(rq)); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra3361.11%743.75%
Ingo Molnar814.81%318.75%
Andrew Morton611.11%212.50%
Frédéric Weisbecker47.41%16.25%
Nicholas Piggin11.85%16.25%
Linus Torvalds11.85%16.25%
Tejun Heo11.85%16.25%
Total54100.00%16100.00%

/* * Mark the task runnable and perform wakeup-preemption. */
static void ttwu_do_wakeup(struct rq *rq, struct task_struct *p, int wake_flags, struct rq_flags *rf) { check_preempt_curr(rq, p, wake_flags); p->state = TASK_RUNNING; trace_sched_wakeup(p); #ifdef CONFIG_SMP if (p->sched_class->task_woken) { /* * Our task @p is fully woken up and running; so its safe to * drop the rq->lock, hereafter rq is only used for statistics. */ rq_unpin_lock(rq, rf); p->sched_class->task_woken(rq, p); rq_repin_lock(rq, rf); } if (rq->idle_stamp) { u64 delta = rq_clock(rq) - rq->idle_stamp; u64 max = 2*rq->max_idle_balance_cost; update_avg(&rq->avg_idle, delta); if (rq->avg_idle > max) rq->avg_idle = max; rq->idle_stamp = 0; } #endif }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra8861.11%838.10%
Roland McGrath128.33%14.76%
Tejun Heo106.94%14.76%
Gregory Haskins96.25%14.76%
Matt Fleming74.86%14.76%
Frédéric Weisbecker53.47%14.76%
Linus Torvalds32.08%14.76%
Ingo Molnar32.08%29.52%
Mathieu Desnoyers21.39%14.76%
Andrew Morton21.39%14.76%
Gautham R. Shenoy10.69%14.76%
Nicholas Piggin10.69%14.76%
Thomas Gleixner10.69%14.76%
Total144100.00%21100.00%


static void ttwu_do_activate(struct rq *rq, struct task_struct *p, int wake_flags, struct rq_flags *rf) { int en_flags = ENQUEUE_WAKEUP | ENQUEUE_NOCLOCK; lockdep_assert_held(&rq->lock); #ifdef CONFIG_SMP if (p->sched_contributes_to_load) rq->nr_uninterruptible--; if (wake_flags & WF_MIGRATED) en_flags |= ENQUEUE_MIGRATED; #endif ttwu_activate(rq, p, en_flags); ttwu_do_wakeup(rq, p, wake_flags, rf); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra5362.35%1161.11%
Frédéric Weisbecker1011.76%15.56%
Ingo Molnar1011.76%211.11%
Andrew Morton55.88%15.56%
Matt Fleming44.71%15.56%
Linus Torvalds22.35%15.56%
Zachary Amsden11.18%15.56%
Total85100.00%18100.00%

/* * Called in case the task @p isn't fully descheduled from its runqueue, * in this case we must do a remote wakeup. Its a 'light' wakeup though, * since all we need to do is flip p->state to TASK_RUNNING, since * the task is still ->on_rq. */
static int ttwu_remote(struct task_struct *p, int wake_flags) { struct rq_flags rf; struct rq *rq; int ret = 0; rq = __task_rq_lock(p, &rf); if (task_on_rq_queued(p)) { /* check_preempt_curr() may use rq clock */ update_rq_clock(rq); ttwu_do_wakeup(rq, p, wake_flags, &rf); ret = 1; } __task_rq_unlock(rq, &rf); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra6176.25%1062.50%
Oleg Nesterov67.50%16.25%
Andrew Morton45.00%16.25%
Frédéric Weisbecker45.00%16.25%
Tejun Heo33.75%16.25%
Ingo Molnar11.25%16.25%
Matt Fleming11.25%16.25%
Total80100.00%16100.00%

#ifdef CONFIG_SMP
void sched_ttwu_pending(void) { struct rq *rq = this_rq(); struct llist_node *llist = llist_del_all(&rq->wake_list); struct task_struct *p, *t; struct rq_flags rf; if (!llist) return; rq_lock_irqsave(rq, &rf); update_rq_clock(rq); llist_for_each_entry_safe(p, t, llist, wake_entry) ttwu_do_activate(rq, p, p->sched_remote_wakeup ? WF_MIGRATED : 0, &rf); rq_unlock_irqrestore(rq, &rf); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra4850.53%952.94%
Byungchul Park1616.84%15.88%
Juri Lelli1313.68%15.88%
Matt Fleming1010.53%15.88%
Ingo Molnar33.16%211.76%
Andrew Morton22.11%15.88%
Jeremy Fitzhardinge22.11%15.88%
Frédéric Weisbecker11.05%15.88%
Total95100.00%17100.00%


void scheduler_ipi(void) { /* * Fold TIF_NEED_RESCHED into the preempt_count; anybody setting * TIF_NEED_RESCHED remotely (for the first time) will also send * this IPI. */ preempt_fold_need_resched(); if (llist_empty(&this_rq()->wake_list) && !got_nohz_idle_kick()) return; /* * Not all reschedule IPI handlers call irq_enter/irq_exit, since * traditionally all their work was done from the interrupt return * path. Now that we actually do some work, we need to make sure * we do call them. * * Some archs already do call them, luckily irq_enter/exit nest * properly. * * Arguably we should visit all archs and update all handlers, * however a fair share of IPIs are still resched only so this would * somewhat pessimize the simple resched case. */ irq_enter(); sched_ttwu_pending(); /* * Check if someone kicked us for doing the nohz idle load balance. */ if (unlikely(got_nohz_idle_kick())) { this_rq()->idle_balance = 1; raise_softirq_irqoff(SCHED_SOFTIRQ); } irq_exit(); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra4880.00%342.86%
Thomas Gleixner46.67%114.29%
Frédéric Weisbecker46.67%114.29%
Oleg Nesterov35.00%114.29%
Andrew Morton11.67%114.29%
Total60100.00%7100.00%


static void ttwu_queue_remote(struct task_struct *p, int cpu, int wake_flags) { struct rq *rq = cpu_rq(cpu); p->sched_remote_wakeup = !!(wake_flags & WF_MIGRATED); if (llist_add(&p->wake_entry, &cpu_rq(cpu)->wake_list)) { if (!set_nr_if_polling(rq->idle)) smp_send_reschedule(cpu); else trace_sched_wake_idle_without_ipi(cpu); } }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra6581.25%763.64%
Dario Faggioli78.75%19.09%
Frédéric Weisbecker56.25%19.09%
Juri Lelli22.50%19.09%
Kirill Tkhai11.25%19.09%
Total80100.00%11100.00%


void wake_up_if_idle(int cpu) { struct rq *rq = cpu_rq(cpu); struct rq_flags rf; rcu_read_lock(); if (!is_idle_task(rcu_dereference(rq->curr))) goto out; if (set_nr_if_polling(rq->idle)) { trace_sched_wake_idle_without_ipi(cpu); } else { rq_lock_irqsave(rq, &rf); if (is_idle_task(rq->curr)) smp_send_reschedule(cpu); /* Else CPU is not idle, do nothing here: */ rq_unlock_irqrestore(rq, &rf); } out: rcu_read_unlock(); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra7679.17%640.00%
Juri Lelli88.33%16.67%
Rik Van Riel44.17%213.33%
Mel Gorman33.12%213.33%
Andrew Morton22.08%213.33%
Tejun Heo22.08%16.67%
Ingo Molnar11.04%16.67%
Total96100.00%15100.00%


bool cpus_share_cache(int this_cpu, int that_cpu) { return per_cpu(sd_llc_id, this_cpu) == per_cpu(sd_llc_id, that_cpu); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra2076.92%133.33%
Mel Gorman519.23%133.33%
Andrew Morton13.85%133.33%
Total26100.00%3100.00%

#endif /* CONFIG_SMP */
static void ttwu_queue(struct task_struct *p, int cpu, int wake_flags) { struct rq *rq = cpu_rq(cpu); struct rq_flags rf; #if defined(CONFIG_SMP) if (sched_feat(TTWU_QUEUE) && !cpus_share_cache(smp_processor_id(), cpu)) { sched_clock_cpu(cpu); /* Sync clocks across CPUs */ ttwu_queue_remote(p, cpu, wake_flags); return; } #endif rq_lock(rq, &rf); update_rq_clock(rq); ttwu_do_activate(rq, p, wake_flags, &rf); rq_unlock(rq, &rf); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra6157.55%956.25%
Andi Kleen2624.53%16.25%
Matt Fleming98.49%16.25%
Kirill Tkhai54.72%16.25%
Ingo Molnar21.89%212.50%
Andrew Morton21.89%16.25%
Thomas Gleixner10.94%16.25%
Total106100.00%16100.00%

/* * Notes on Program-Order guarantees on SMP systems. * * MIGRATION * * The basic program-order guarantee on SMP systems is that when a task [t] * migrates, all its activity on its old CPU [c0] happens-before any subsequent * execution on its new CPU [c1]. * * For migration (of runnable tasks) this is provided by the following means: * * A) UNLOCK of the rq(c0)->lock scheduling out task t * B) migration for t is required to synchronize *both* rq(c0)->lock and * rq(c1)->lock (if not at the same time, then in that order). * C) LOCK of the rq(c1)->lock scheduling in task * * Transitivity guarantees that B happens after A and C after B. * Note: we only require RCpc transitivity. * Note: the CPU doing B need not be c0 or c1 * * Example: * * CPU0 CPU1 CPU2 * * LOCK rq(0)->lock * sched-out X * sched-in Y * UNLOCK rq(0)->lock * * LOCK rq(0)->lock // orders against CPU0 * dequeue X * UNLOCK rq(0)->lock * * LOCK rq(1)->lock * enqueue X * UNLOCK rq(1)->lock * * LOCK rq(1)->lock // orders against CPU2 * sched-out Z * sched-in X * UNLOCK rq(1)->lock * * * BLOCKING -- aka. SLEEP + WAKEUP * * For blocking we (obviously) need to provide the same guarantee as for * migration. However the means are completely different as there is no lock * chain to provide order. Instead we do: * * 1) smp_store_release(X->on_cpu, 0) * 2) smp_cond_load_acquire(!X->on_cpu) * * Example: * * CPU0 (schedule) CPU1 (try_to_wake_up) CPU2 (schedule) * * LOCK rq(0)->lock LOCK X->pi_lock * dequeue X * sched-out X * smp_store_release(X->on_cpu, 0); * * smp_cond_load_acquire(&X->on_cpu, !VAL); * X->state = WAKING * set_task_cpu(X,2) * * LOCK rq(2)->lock * enqueue X * X->state = RUNNING * UNLOCK rq(2)->lock * * LOCK rq(2)->lock // orders against CPU1 * sched-out Z * sched-in X * UNLOCK rq(2)->lock * * UNLOCK X->pi_lock * UNLOCK rq(0)->lock * * * However; for wakeups there is a second guarantee we must provide, namely we * must observe the state that lead to our wakeup. That is, not only must our * task observe its own prior state, it must also observe the stores prior to * its wakeup. * * This means that any means of doing remote wakeups must order the CPU doing * the wakeup against the CPU the task is going to end up running on. This, * however, is already required for the regular Program-Order guarantee above, * since the waking CPU is the one issueing the ACQUIRE (smp_cond_load_acquire). * */ /** * try_to_wake_up - wake up a thread * @p: the thread to be awakened * @state: the mask of task states that can be woken * @wake_flags: wake modifier flags (WF_*) * * If (@state & @p->state) @p->state = TASK_RUNNING. * * If the task was not queued/runnable, also place it back on a runqueue. * * Atomic against schedule() which would dequeue a task, also see * set_current_state(). * * Return: %true if @p->state changes (an actual wakeup was done), * %false otherwise. */
static int try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags) { unsigned long flags; int cpu, success = 0; /* * If we are going to wake up a thread waiting for CONDITION we * need to ensure that CONDITION=1 done by the caller can not be * reordered with p->state check below. This pairs with mb() in * set_current_state() the waiting thread does. */ raw_spin_lock_irqsave(&p->pi_lock, flags); smp_mb__after_spinlock(); if (!(p->state & state)) goto out; trace_sched_waking(p); /* We're going to change ->state: */ success = 1; cpu = task_cpu(p); /* * Ensure we load p->on_rq _after_ p->state, otherwise it would * be possible to, falsely, observe p->on_rq == 0 and get stuck * in smp_cond_load_acquire() below. * * sched_ttwu_pending() try_to_wake_up() * [S] p->on_rq = 1; [L] P->state * UNLOCK rq->lock -----. * \ * +--- RMB * schedule() / * LOCK rq->lock -----' * UNLOCK rq->lock * * [task p] * [S] p->state = UNINTERRUPTIBLE [L] p->on_rq * * Pairs with the UNLOCK+LOCK on rq->lock from the * last wakeup of our task and the schedule that got our task * current. */ smp_rmb(); if (p->on_rq && ttwu_remote(p, wake_flags)) goto stat; #ifdef CONFIG_SMP /* * Ensure we load p->on_cpu _after_ p->on_rq, otherwise it would be * possible to, falsely, observe p->on_cpu == 0. * * One must be running (->on_cpu == 1) in order to remove oneself * from the runqueue. * * [S] ->on_cpu = 1; [L] ->on_rq * UNLOCK rq->lock * RMB * LOCK rq->lock * [S] ->on_rq = 0; [L] ->on_cpu * * Pairs with the full barrier implied in the UNLOCK+LOCK on rq->lock * from the consecutive calls to schedule(); the first switching to our * task, the second putting it to sleep. */ smp_rmb(); /* * If the owning (remote) CPU is still in the middle of schedule() with * this task as prev, wait until its done referencing the task. * * Pairs with the smp_store_release() in finish_lock_switch(). * * This ensures that tasks getting woken will be fully ordered against * their previous state and preserve Program Order. */ smp_cond_load_acquire(&p->on_cpu, !VAL); p->sched_contributes_to_load = !!task_contributes_to_load(p); p->state = TASK_WAKING; if (p->in_iowait) { delayacct_blkio_end(p); atomic_dec(&task_rq(p)->nr_iowait); } cpu = select_task_rq(p, p->wake_cpu, SD_BALANCE_WAKE, wake_flags); if (task_cpu(p) != cpu) { wake_flags |= WF_MIGRATED; set_task_cpu(p, cpu); } #else /* CONFIG_SMP */ if (p->in_iowait) { delayacct_blkio_end(p); atomic_dec(&task_rq(p)->nr_iowait); } #endif /* CONFIG_SMP */ ttwu_queue(p, cpu, wake_flags); stat: ttwu_stat(p, cpu, wake_flags); out: raw_spin_unlock_irqrestore(&p->pi_lock, flags); return success; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra13853.91%1745.95%
Tejun Heo5119.92%25.41%
Andrew Morton187.03%410.81%
Thomas Gleixner103.91%12.70%
Dario Faggioli103.91%12.70%
Frédéric Weisbecker62.34%12.70%
Josh Snyder62.34%12.70%
Ingo Molnar62.34%410.81%
Balbir Singh41.56%12.70%
Gregory Haskins31.17%12.70%
Juri Lelli10.39%12.70%
Rik Van Riel10.39%12.70%
Rusty Russell10.39%12.70%
Jack Steiner10.39%12.70%
Total256100.00%37100.00%

/** * try_to_wake_up_local - try to wake up a local task with rq lock held * @p: the thread to be awakened * @rf: request-queue flags for pinning * * Put @p on the run-queue if it's not already there. The caller must * ensure that this_rq() is locked, @p is bound to this_rq() and not * the current task. */
static void try_to_wake_up_local(struct task_struct *p, struct rq_flags *rf) { struct rq *rq = task_rq(p); if (WARN_ON_ONCE(rq != this_rq()) || WARN_ON_ONCE(p == current)) return; lockdep_assert_held(&rq->lock); if (!raw_spin_trylock(&p->pi_lock)) { /* * This is OK, because current is on_cpu, which avoids it being * picked for load-balance and preemption/IRQs are still * disabled avoiding further scheduler activity on it and we've * not yet picked a replacement task. */ rq_unlock(rq, rf); raw_spin_lock(&p->pi_lock); rq_relock(rq, rf); } if (!(p->state & TASK_NORMAL)) goto out; trace_sched_waking(p); if (!task_on_rq_queued(p)) { if (p->in_iowait) { delayacct_blkio_end(p); atomic_dec(&rq->nr_iowait); } ttwu_activate(rq, p, ENQUEUE_WAKEUP | ENQUEUE_NOCLOCK); } ttwu_do_wakeup(rq, p, 0, rf); ttwu_stat(p, smp_processor_id(), 0); out: raw_spin_unlock(&p->pi_lock); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra10457.78%1144.00%
Tejun Heo2111.67%28.00%
Andi Kleen158.33%14.00%
Mel Gorman84.44%14.00%
Frédéric Weisbecker73.89%14.00%
Matt Fleming63.33%14.00%
Dario Faggioli42.22%14.00%
Juri Lelli31.67%14.00%
Josh Snyder31.67%14.00%
Steven Rostedt21.11%14.00%
Ingo Molnar21.11%14.00%
Thomas Gleixner21.11%14.00%
Andrew Morton21.11%14.00%
Rick Lindsley10.56%14.00%
Total180100.00%25100.00%

/** * wake_up_process - Wake up a specific process * @p: The process to be woken up. * * Attempt to wake up the nominated process and move it to the set of runnable * processes. * * Return: 1 if the process was woken up, 0 if it was already running. * * It may be assumed that this function implies a write memory barrier before * changing the task state if and only if any tasks are woken up. */
int wake_up_process(struct task_struct *p) { return try_to_wake_up(p, TASK_NORMAL, 0); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra1155.00%333.33%
Dario Faggioli525.00%222.22%
Frédéric Weisbecker15.00%111.11%
Venkatesh Pallipadi15.00%111.11%
Rick Lindsley15.00%111.11%
Jack Steiner15.00%111.11%
Total20100.00%9100.00%

EXPORT_SYMBOL(wake_up_process);
int wake_up_state(struct task_struct *p, unsigned int state) { return try_to_wake_up(p, state, 0); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra2083.33%360.00%
Venkatesh Pallipadi28.33%120.00%
Dario Faggioli28.33%120.00%
Total24100.00%5100.00%

/* * Perform scheduler related setup for a newly forked process p. * p is forked by current. * * __sched_fork() is basic setup used by init_idle() too: */
static void __sched_fork(unsigned long clone_flags, struct task_struct *p) { p->on_rq = 0; p->se.on_rq = 0; p->se.exec_start = 0; p->se.sum_exec_runtime = 0; p->se.prev_sum_exec_runtime = 0; p->se.nr_migrations = 0; p->se.vruntime = 0; INIT_LIST_HEAD(&p->se.group_node); #ifdef CONFIG_FAIR_GROUP_SCHED p->se.cfs_rq = NULL; #endif #ifdef CONFIG_SCHEDSTATS /* Even if schedstat is disabled, there should not be garbage */ memset(&p->se.statistics, 0, sizeof(p->se.statistics)); #endif RB_CLEAR_NODE(&p->dl.rb_node); init_dl_task_timer(&p->dl); init_dl_inactive_task_timer(&p->dl); __dl_clear_params(p); INIT_LIST_HEAD(&p->rt.run_list); p->rt.timeout = 0; p->rt.time_slice = sched_rr_timeslice; p->rt.on_rq = 0; p->rt.on_list = 0; #ifdef CONFIG_PREEMPT_NOTIFIERS INIT_HLIST_HEAD(&p->preempt_notifiers); #endif #ifdef CONFIG_NUMA_BALANCING if (p->mm && atomic_read(&p->mm->mm_users) == 1) { p->mm->numa_next_scan = jiffies + msecs_to_jiffies(sysctl_numa_balancing_scan_delay); p->mm->numa_scan_seq = 0; } if (clone_flags & CLONE_VM) p->numa_preferred_nid = current->numa_preferred_nid; else p->numa_preferred_nid = -1; p->node_stamp = 0ULL; p->numa_scan_seq = p->mm ? p->mm->numa_scan_seq : 0; p->numa_scan_period = sysctl_numa_balancing_scan_delay; p->numa_work.next = &p->numa_work; p->numa_faults = NULL; p->last_task_numa_placement = 0; p->last_sum_exec_runtime = 0; p->numa_group = NULL; #endif /* CONFIG_NUMA_BALANCING */ }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra21262.91%1137.93%
Dario Faggioli6218.40%310.34%
Frédéric Weisbecker205.93%26.90%
Byungchul Park133.86%13.45%
Luca Abeni82.37%13.45%
Thomas Gleixner51.48%13.45%
Mike Galbraith30.89%13.45%
Steven Rostedt20.59%13.45%
Juri Lelli20.59%13.45%
Venkatesh Pallipadi20.59%13.45%
Gregory Haskins20.59%13.45%
Ingo Molnar20.59%26.90%
Andrew Morton20.59%13.45%
Suresh B. Siddha10.30%13.45%
Mel Gorman10.30%13.45%
Total337100.00%29100.00%

DEFINE_STATIC_KEY_FALSE(sched_numa_balancing); #ifdef CONFIG_NUMA_BALANCING
void set_numabalancing_state(bool enabled) { if (enabled) static_branch_enable(&sched_numa_balancing); else static_branch_disable(&sched_numa_balancing); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra1144.00%240.00%
Srikar Dronamraju624.00%120.00%
Dario Faggioli520.00%120.00%
Avi Kivity312.00%120.00%
Total25100.00%5100.00%

#ifdef CONFIG_PROC_SYSCTL
int sysctl_numa_balancing(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos) { struct ctl_table t; int err; int state = static_branch_likely(&sched_numa_balancing); if (write && !capable(CAP_SYS_ADMIN)) return -EPERM; t = *table; t.data = &state; err = proc_dointvec_minmax(&t, write, buffer, lenp, ppos); if (err < 0) return err; if (write) set_numabalancing_state(state); return err; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra8076.19%430.77%
Dario Faggioli1312.38%17.69%
Srikar Dronamraju54.76%215.38%
Linus Torvalds21.90%215.38%
Frédéric Weisbecker21.90%17.69%
Mike Galbraith10.95%17.69%
Ingo Molnar10.95%17.69%
Tejun Heo10.95%17.69%
Total105100.00%13100.00%

#endif #endif #ifdef CONFIG_SCHEDSTATS DEFINE_STATIC_KEY_FALSE(sched_schedstats); static bool __initdata __sched_schedstats = false;
static void set_schedstats(bool enabled) { if (enabled) static_branch_enable(&sched_schedstats); else static_branch_disable(&sched_schedstats); }

Contributors

PersonTokensPropCommitsCommitProp
Mel Gorman1661.54%114.29%
Peter Zijlstra519.23%228.57%
Linus Torvalds27.69%114.29%
Dario Faggioli13.85%114.29%
Martin Schwidefsky13.85%114.29%
Hidetoshi Seto13.85%114.29%
Total26100.00%7100.00%


void force_schedstat_enabled(void) { if (!schedstat_enabled()) { pr_info("kernel profiling enabled schedstats, disable via kernel.sched_schedstats.\n"); static_branch_enable(&sched_schedstats); } }

Contributors

PersonTokensPropCommitsCommitProp
Mel Gorman1661.54%114.29%
Dario Faggioli415.38%114.29%
Peter Zijlstra27.69%114.29%
Hidetoshi Seto13.85%114.29%
Andrew Morton13.85%114.29%
Dmitry Adamushko13.85%114.29%
Frédéric Weisbecker13.85%114.29%
Total26100.00%7100.00%


static int __init setup_schedstats(char *str) { int ret = 0; if (!str) goto out; /* * This code is called before jump labels have been set up, so we can't * change the static branch directly just yet. Instead set a temporary * variable so init_schedstats() can do it later. */ if (!strcmp(str, "enable")) { __sched_schedstats = true; ret = 1; } else if (!strcmp(str, "disable")) { __sched_schedstats = false; ret = 1; } out: if (!ret) pr_warn("Unable to parse schedstats=\n"); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Mel Gorman5162.96%114.29%
Peter Zijlstra1012.35%342.86%
Dario Faggioli911.11%114.29%
Frédéric Weisbecker67.41%114.29%
Josh Poimboeuf56.17%114.29%
Total81100.00%7100.00%

__setup("schedstats=", setup_schedstats);
static void __init init_schedstats(void) { set_schedstats(__sched_schedstats); }

Contributors

PersonTokensPropCommitsCommitProp
Josh Poimboeuf14100.00%1100.00%
Total14100.00%1100.00%

#ifdef CONFIG_PROC_SYSCTL
int sysctl_schedstats(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos) { struct ctl_table t; int err; int state = static_branch_likely(&sched_schedstats); if (write && !capable(CAP_SYS_ADMIN)) return -EPERM; t = *table; t.data = &state; err = proc_dointvec_minmax(&t, write, buffer, lenp, ppos); if (err < 0) return err; if (write) set_schedstats(state); return err; }

Contributors

PersonTokensPropCommitsCommitProp
Mel Gorman7773.33%19.09%
Peter Zijlstra1312.38%19.09%
Dario Faggioli54.76%19.09%
Frédéric Weisbecker21.90%19.09%
Linus Torvalds21.90%218.18%
Gregory Haskins21.90%19.09%
Suresh B. Siddha10.95%19.09%
Andrew Morton10.95%19.09%
Mike Galbraith10.95%19.09%
Robert Love10.95%19.09%
Total105100.00%11100.00%

#endif /* CONFIG_PROC_SYSCTL */ #else /* !CONFIG_SCHEDSTATS */
static inline void init_schedstats(void) {}

Contributors

PersonTokensPropCommitsCommitProp
Josh Poimboeuf8100.00%1100.00%
Total8100.00%1100.00%

#endif /* CONFIG_SCHEDSTATS */ /* * fork()/clone()-time setup: */
int sched_fork(unsigned long clone_flags, struct task_struct *p) { unsigned long flags; int cpu = get_cpu(); __sched_fork(clone_flags, p); /* * We mark the process as NEW here. This guarantees that * nobody will actually run it, and a signal or other external * event cannot wake it up and insert it on the runqueue either. */ p->state = TASK_NEW; /* * Make sure we do not leak PI boosting priority to the child. */ p->prio = current->normal_prio; /* * Revert to default priority/policy on fork if requested. */ if (unlikely(p->sched_reset_on_fork)) { if (task_has_dl_policy(p) || task_has_rt_policy(p)) { p->policy = SCHED_NORMAL; p->static_prio = NICE_TO_PRIO(0); p->rt_priority = 0; } else if (PRIO_TO_NICE(p->static_prio) < 0) p->static_prio = NICE_TO_PRIO(0); p->prio = p->normal_prio = __normal_prio(p); set_load_weight(p, false); /* * We don't need the reset flag anymore after the fork. It has * fulfilled its duty: */ p->sched_reset_on_fork = 0; } if (dl_prio(p->prio)) { put_cpu(); return -EAGAIN; } else if (rt_prio(p->prio)) { p->sched_class = &rt_sched_class; } else { p->sched_class = &fair_sched_class; } init_entity_runnable_average(&p->se); /* * The child is not yet in the pid-hash so no cgroup attach races, * and the cgroup is pinned to this child due to cgroup_fork() * is ran before sched_fork(). * * Silence PROVE_RCU. */ raw_spin_lock_irqsave(&p->pi_lock, flags); /* * We're setting the CPU for the first time, we don't migrate, * so use __set_task_cpu(). */ __set_task_cpu(p, cpu); if (p->sched_class->task_fork) p->sched_class->task_fork(p); raw_spin_unlock_irqrestore(&p->pi_lock, flags); #ifdef CONFIG_SCHED_INFO if (likely(sched_info_on())) memset(&p->sched_info, 0, sizeof(p->sched_info)); #endif #if defined(CONFIG_SMP) p->on_cpu = 0; #endif init_task_preempt_count(p); #ifdef CONFIG_SMP plist_node_init(&p->pushable_tasks, MAX_PRIO); RB_CLEAR_NODE(&p->pushable_dl_tasks); #endif put_cpu(); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra19861.68%923.68%
Dario Faggioli6119.00%25.26%
Frédéric Weisbecker175.30%37.89%
Mel Gorman61.87%12.63%
Tim Chen41.25%12.63%
Linus Torvalds41.25%25.26%
Ingo Molnar30.93%25.26%
Con Kolivas20.62%12.63%
Andrew Morton20.62%12.63%
Thomas Gleixner20.62%12.63%
Hidetoshi Seto20.62%12.63%
Stanislaw Gruszka20.62%12.63%
Vincent Guittot20.62%12.63%
Dmitry Adamushko20.62%12.63%
Oleg Nesterov20.62%12.63%
Laurent Vivier20.62%12.63%
Avi Kivity20.62%12.63%
Martin Schwidefsky10.31%12.63%
Jack Steiner10.31%12.63%
Martin J. Bligh10.31%12.63%
Robert Love10.31%12.63%
Venkatesh Pallipadi10.31%12.63%
Lucas De Marchi10.31%12.63%
Christoph Lameter10.31%12.63%
Steven Rostedt10.31%12.63%
Total321100.00%38100.00%


unsigned long to_ratio(u64 period, u64 runtime) { if (runtime == RUNTIME_INF) return BW_UNIT; /* * Doing this here saves a lot of checks in all * the calling paths, and returning zero seems * safe for them anyway. */ if (period == 0) return 0; return div64_u64(runtime << BW_SHIFT, period); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra3175.61%116.67%
Frédéric Weisbecker37.32%116.67%
Dario Faggioli37.32%116.67%
Luca Abeni24.88%116.67%
Morten Rasmussen12.44%116.67%
Andrew Morton12.44%116.67%
Total41100.00%6100.00%

/* * wake_up_new_task - wake up a newly created task for the first time. * * This function will do some initial scheduler statistics housekeeping * that must be done for every newly created context, then puts the task * on the runqueue and wakes it. */
void wake_up_new_task(struct task_struct *p) { struct rq_flags rf; struct rq *rq; raw_spin_lock_irqsave(&p->pi_lock, rf.flags); p->state = TASK_RUNNING; #ifdef CONFIG_SMP /* * Fork balancing, do it here and not earlier because: * - cpus_allowed can change in the fork path * - any previously selected CPU might disappear through hotplug * * Use __set_task_cpu() to avoid calling sched_class::migrate_task_rq, * as we're not fully set-up yet. */ __set_task_cpu(p, select_task_rq(p, task_cpu(p), SD_BALANCE_FORK, 0)); #endif rq = __task_rq_lock(p, &rf); update_rq_clock(rq); post_init_entity_util_avg(&p->se); activate_task(rq, p, ENQUEUE_NOCLOCK); p->on_rq = TASK_ON_RQ_QUEUED; trace_sched_wakeup_new(p); check_preempt_curr(rq, p, WF_FORK); #ifdef CONFIG_SMP if (p->sched_class->task_woken) { /* * Nothing relies on rq->lock after this, so its fine to * drop it. */ rq_unpin_lock(rq, &rf); p->sched_class->task_woken(rq, p); rq_repin_lock(rq, &rf); } #endif task_rq_unlock(rq, p, &rf); }

Contributors

PersonTokensPropCommitsCommitProp
Nico Pitre13077.84%17.14%
Peter Zijlstra148.38%428.57%
Dario Faggioli84.79%17.14%
Ingo Molnar42.40%321.43%
Matthew Wilcox42.40%17.14%
Frédéric Weisbecker42.40%17.14%
Con Kolivas10.60%17.14%
Thomas Gleixner10.60%17.14%
Laurent Vivier10.60%17.14%
Total167100.00%14100.00%

#ifdef CONFIG_PREEMPT_NOTIFIERS static struct static_key preempt_notifier_key = STATIC_KEY_INIT_FALSE;
void preempt_notifier_inc(void) { static_key_slow_inc(&preempt_notifier_key); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra969.23%250.00%
Dario Faggioli215.38%125.00%
Linus Torvalds215.38%125.00%
Total13100.00%4100.00%

EXPORT_SYMBOL_GPL(preempt_notifier_inc);
void preempt_notifier_dec(void) { static_key_slow_dec(&preempt_notifier_key); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra1076.92%360.00%
Dario Faggioli215.38%120.00%
Alex Shi17.69%120.00%
Total13100.00%5100.00%

EXPORT_SYMBOL_GPL(preempt_notifier_dec); /** * preempt_notifier_register - tell me when current is being preempted & rescheduled * @notifier: notifier struct to register */
void preempt_notifier_register(struct preempt_notifier *notifier) { if (!static_key_false(&preempt_notifier_key)) WARN(1, "registering preempt_notifier while notifiers disabled\n"); hlist_add_head(&notifier->link, &current->preempt_notifiers); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra2461.54%225.00%
Dario Faggioli615.38%112.50%
Linus Torvalds410.26%225.00%
Arnaldo Carvalho de Melo25.13%112.50%
Ingo Molnar25.13%112.50%
Linus Torvalds (pre-git)12.56%112.50%
Total39100.00%8100.00%

EXPORT_SYMBOL_GPL(preempt_notifier_register); /** * preempt_notifier_unregister - no longer interested in preemption notifications * @notifier: notifier struct to unregister * * This is *not* safe to call from within a preemption notifier. */
void preempt_notifier_unregister(struct preempt_notifier *notifier) { hlist_del(&notifier->link); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra950.00%125.00%
Stanislaw Gruszka422.22%125.00%
Mel Gorman422.22%125.00%
Frédéric Weisbecker15.56%125.00%
Total18100.00%4100.00%

EXPORT_SYMBOL_GPL(preempt_notifier_unregister);
static void __fire_sched_in_preempt_notifiers(struct task_struct *curr) { struct preempt_notifier *notifier; hlist_for_each_entry(notifier, &curr->preempt_notifiers, link) notifier->ops->sched_in(notifier, raw_smp_processor_id()); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra1644.44%110.00%
Dario Faggioli822.22%110.00%
Linus Torvalds38.33%110.00%
Frédéric Weisbecker38.33%110.00%
Ingo Molnar25.56%220.00%
Oleg Nesterov12.78%110.00%
Mel Gorman12.78%110.00%
Jack Steiner12.78%110.00%
Thomas Gleixner12.78%110.00%
Total36100.00%10100.00%


static __always_inline void fire_sched_in_preempt_notifiers(struct task_struct *curr) { if (static_key_false(&preempt_notifier_key)) __fire_sched_in_preempt_notifiers(curr); }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds1352.00%116.67%
Stanislaw Gruszka624.00%116.67%
Dario Faggioli28.00%116.67%
Peter Zijlstra28.00%116.67%
Ingo Molnar14.00%116.67%
Oleg Nesterov14.00%116.67%
Total25100.00%6100.00%


static void __fire_sched_out_preempt_notifiers(struct task_struct *curr, struct task_struct *next) { struct preempt_notifier *notifier; hlist_for_each_entry(notifier, &curr->preempt_notifiers, link) notifier->ops->sched_out(notifier, next); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra2767.50%541.67%
Ingo Molnar410.00%216.67%
Dario Faggioli410.00%18.33%
Linus Torvalds37.50%216.67%
Davide Libenzi12.50%18.33%
Glauber de Oliveira Costa12.50%18.33%
Total40100.00%12100.00%


static __always_inline void fire_sched_out_preempt_notifiers(struct task_struct *curr, struct task_struct *next) { if (static_key_false(&preempt_notifier_key)) __fire_sched_out_preempt_notifiers(curr, next); }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds2062.50%114.29%
Peter Zijlstra618.75%342.86%
Dario Faggioli412.50%114.29%
Ingo Molnar13.12%114.29%
Thomas Gleixner13.12%114.29%
Total32100.00%7100.00%

#else /* !CONFIG_PREEMPT_NOTIFIERS */
static inline void fire_sched_in_preempt_notifiers(struct task_struct *curr) { }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra763.64%133.33%
Dario Faggioli327.27%133.33%
Linus Torvalds19.09%133.33%
Total11100.00%3100.00%


static inline void fire_sched_out_preempt_notifiers(struct task_struct *curr, struct task_struct *next) { }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra1275.00%240.00%
Oleg Nesterov212.50%120.00%
Dario Faggioli16.25%120.00%
Linus Torvalds16.25%120.00%
Total16100.00%5100.00%

#endif /* CONFIG_PREEMPT_NOTIFIERS */ /** * prepare_task_switch - prepare to switch tasks * @rq: the runqueue preparing to switch * @prev: the current task that is being switched out * @next: the task we are going to switch to. * * This is called with the rq lock held and interrupts off. It must * be paired with a subsequent finish_task_switch after the context * switch. * * prepare_task_switch sets up locking and calls architecture specific * hooks. */
static inline void prepare_task_switch(struct rq *rq, struct task_struct *prev, struct task_struct *next) { sched_info_switch(rq, prev, next); perf_event_task_sched_out(prev, next); fire_sched_out_preempt_notifiers(prev, next); prepare_lock_switch(rq, next); prepare_arch_switch(next); }

Contributors

PersonTokensPropCommitsCommitProp
Dario Faggioli1933.33%15.88%
Peter Zijlstra1933.33%423.53%
Mike Galbraith47.02%15.88%
Masami Hiramatsu35.26%15.88%
Guillaume Chazarain23.51%15.88%
Ingo Molnar23.51%15.88%
Linus Torvalds23.51%211.76%
Thomas Gleixner11.75%15.88%
Martin Schwidefsky11.75%15.88%
Davide Libenzi11.75%15.88%
Bob Miller11.75%15.88%
Benjamin LaHaise11.75%15.88%
Steven Rostedt11.75%15.88%
Total57100.00%17100.00%

/** * finish_task_switch - clean up after a task-switch * @prev: the thread we just switched away from. * * finish_task_switch must be called after the context switch, paired * with a prepare_task_switch call before the context switch. * finish_task_switch will reconcile locking set up by prepare_task_switch, * and do any other architecture-specific cleanup actions. * * Note that we may have delayed dropping an mm in context_switch(). If * so, we finish that here outside of the runqueue lock. (Doing it * with the lock held can cause deadlocks; see schedule() for * details.) * * The context switch have flipped the stack from under us and restored the * local variables which were saved when this task called schedule() in the * past. prev == current is still correct but we need to recalculate this_rq * because prev may have moved to another CPU. */
static struct rq *finish_task_switch(struct task_struct *prev) __releases(rq->lock) { struct rq *rq = this_rq(); struct mm_struct *mm = rq->prev_mm; long prev_state; /* * The previous task will have left us with a preempt_count of 2 * because it left us after: * * schedule() * preempt_disable(); // 1 * __schedule() * raw_spin_lock_irq(&rq->lock) // 2 * * Also, see FORK_PREEMPT_COUNT. */ if (WARN_ONCE(preempt_count() != 2*PREEMPT_DISABLE_OFFSET, "corrupted preempt_count: %s/%d/0x%x\n", current->comm, current->pid, preempt_count())) preempt_count_set(FORK_PREEMPT_COUNT); rq->prev_mm = NULL; /* * A task struct has one reference for the use as "current". * If a task dies, then it sets TASK_DEAD in tsk->state and calls * schedule one last time. The schedule call will never return, and * the scheduled task must drop that reference. * * We must observe prev->state before clearing prev->on_cpu (in * finish_lock_switch), otherwise a concurrent wakeup can get prev * running on another CPU and we could rave with its RUNNING -> DEAD * transition, resulting in a double drop. */ prev_state = prev->state; vtime_task_switch(prev); perf_event_task_sched_in(prev, current); /* * The membarrier system call requires a full memory barrier * after storing to rq->curr, before going back to user-space. * * TODO: This smp_mb__after_unlock_lock can go away if PPC end * up adding a full barrier to switch_mm(), or we should figure * out if a smp_mb__after_unlock_lock is really the proper API * to use. */ smp_mb__after_unlock_lock(); finish_lock_switch(rq, prev); finish_arch_post_lock_switch(); fire_sched_in_preempt_notifiers(current); if (mm) mmdrop(mm); if (unlikely(prev_state == TASK_DEAD)) { if (prev->sched_class->task_dead) prev->sched_class->task_dead(prev); /* * Remove function-return probe instances associated with this * task and put them back on the free list. */ kprobe_flush_task(prev); /* Task is done with its stack. */ put_task_stack(prev); put_task_struct(prev); } tick_nohz_task_switch(); return rq; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra9554.60%725.93%
Dario Faggioli2715.52%13.70%
Ingo Molnar74.02%311.11%
Andrew Lutomirski63.45%13.70%
Stanislaw Gruszka63.45%13.70%
Linus Torvalds63.45%311.11%
Venkatesh Pallipadi52.87%13.70%
Mathieu Desnoyers42.30%13.70%
Frédéric Weisbecker42.30%27.41%
Srivatsa Vaddagiri42.30%13.70%
Andrew Morton21.15%13.70%
Thomas Gleixner21.15%13.70%
Peter Williams21.15%13.70%
Mel Gorman21.15%13.70%
Oleg Nesterov21.15%27.41%
Total174100.00%27100.00%

#ifdef CONFIG_SMP /* rq->lock is NOT held, but preemption is disabled */
static void __balance_callback(struct rq *rq) { struct callback_head *head, *next; void (*func)(struct rq *rq); unsigned long flags; raw_spin_lock_irqsave(&rq->lock, flags); head = rq->balance_callback; rq->balance_callback = NULL; while (head) { func = (void (*)(struct rq *))head->func; next = head->next; head->next = NULL; head = next; func(rq); } raw_spin_unlock_irqrestore(&rq->lock, flags); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra7971.17%16.67%
Dario Faggioli1311.71%16.67%
Ingo Molnar54.50%320.00%
Linus Torvalds43.60%320.00%
Christoph Lameter21.80%16.67%
Frédéric Weisbecker21.80%213.33%
Martin J. Bligh21.80%16.67%
Thomas Gleixner21.80%16.67%
Laurent Vivier10.90%16.67%
Aaron Tomlin10.90%16.67%
Total111100.00%15100.00%


static inline void balance_callback(struct rq *rq) { if (unlikely(rq->balance_callback)) __balance_callback(rq); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra1350.00%240.00%
Linus Torvalds830.77%120.00%
Dario Faggioli415.38%120.00%
Ingo Molnar13.85%120.00%
Total26100.00%5100.00%

#else
static inline void balance_callback(struct rq *rq) { }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra654.55%233.33%
Dario Faggioli218.18%116.67%
Mel Gorman19.09%116.67%
Oleg Nesterov19.09%116.67%
Linus Torvalds19.09%116.67%
Total11100.00%6100.00%

#endif /** * schedule_tail - first thing a freshly forked thread must call. * @prev: the thread we just switched away from. */
asmlinkage __visible void schedule_tail(struct task_struct *prev) __releases(rq->lock) { struct rq *rq; /* * New tasks start with FORK_PREEMPT_COUNT, see there and * finish_task_switch() for details. * * finish_task_switch() will drop rq->lock() and lower preempt_count * and the preempt_enable() will end up enabling preemption (on * PREEMPT_COUNT kernels). */ rq = finish_task_switch(prev); balance_callback(rq); preempt_enable(); if (current->set_child_tid) put_user(task_pid_vnr(current), current->set_child_tid); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra2035.09%212.50%
Dario Faggioli1119.30%16.25%
Thomas Gleixner915.79%318.75%
Ingo Molnar58.77%318.75%
Mike Galbraith35.26%16.25%
Oleg Nesterov23.51%16.25%
Linus Torvalds23.51%16.25%
Guillaume Chazarain23.51%16.25%
Bob Miller11.75%16.25%
Robert Love11.75%16.25%
Davide Libenzi11.75%16.25%
Total57100.00%16100.00%

/* * context_switch - switch to the new MM and the new thread's register state. */ static __always_inline struct rq * context_switch(struct rq *rq, struct task_struct *prev, struct task_struct *next, struct rq_flags *rf) { struct mm_struct *mm, *oldmm; prepare_task_switch(rq, prev, next); mm = next->mm; oldmm = prev->active_mm; /* * For paravirt, this is coupled with an exit in switch_to to * combine the page table reload and the switch backend into * one hypercall. */ arch_start_context_switch(prev); if (!mm) { next->active_mm = oldmm; mmgrab(oldmm); enter_lazy_tlb(oldmm, next); } else switch_mm_irqs_off(oldmm, mm, next); if (!prev->mm) { prev->active_mm = NULL; rq->prev_mm = oldmm; } rq->clock_update_flags &= ~(RQCF_ACT_SKIP|RQCF_REQ_SKIP); /* * Since the runqueue lock will be released by the next * task (which is an invalid locking op but in the case * of the scheduler it's an obvious special-case), so we * do an early lockdep release here: */ rq_unpin_lock(rq, rf); spin_release(&rq->lock.dep_map, 1, _THIS_IP_); /* Here we just switch the register state and the stack. */ switch_to(prev, next, prev); barrier(); return finish_task_switch(prev); } /* * nr_running and nr_context_switches: * * externally visible scheduler statistics: current number of runnable * threads, total number of context switches performed since bootup. */
unsigned long nr_running(void) { unsigned long i, sum = 0; for_each_online_cpu(i) sum += cpu_rq(i)->nr_running; return sum; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra2681.25%120.00%
Dario Faggioli26.25%120.00%
Thomas Gleixner26.25%120.00%
Ingo Molnar13.12%120.00%
Josh Poimboeuf13.12%120.00%
Total32100.00%5100.00%

/* * Check if only the current task is running on the CPU. * * Caution: this function does not check that the caller has disabled * preemption, thus the result might have a time-of-check-to-time-of-use * race. The caller is responsible to use it correctly, for example: * * - from a non-preemptable section (of course) * * - from a thread that is bound to a single CPU * * - in a loop with very short iterations (e.g. a polling loop) */
bool single_task_running(void) { return raw_rq()->nr_running == 1; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra1173.33%250.00%
Dario Faggioli320.00%125.00%
Dominik Dingel16.67%125.00%
Total15100.00%4100.00%

EXPORT_SYMBOL(single_task_running);
unsigned long long nr_context_switches(void) { int i; unsigned long long sum = 0; for_each_possible_cpu(i) sum += cpu_rq(i)->nr_switches; return sum; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra2057.14%116.67%
Dario Faggioli822.86%116.67%
Linus Torvalds38.57%116.67%
Andi Kleen25.71%116.67%
Thomas Gleixner12.86%116.67%
Andrew Morton12.86%116.67%
Total35100.00%6100.00%

/* * IO-wait accounting, and how its mostly bollocks (on SMP). * * The idea behind IO-wait account is to account the idle time that we could * have spend running if it were not for IO. That is, if we were to improve the * storage performance, we'd have a proportional reduction in IO-wait time. * * This all works nicely on UP, where, when a task blocks on IO, we account * idle time as IO-wait, because if the storage were faster, it could've been * running and we'd not be idle. * * This has been extended to SMP, by doing the same for each CPU. This however * is broken. * * Imagine for instance the case where two tasks block on one CPU, only the one * CPU will have IO-wait accounted, while the other has regular idle. Even * though, if the storage were faster, both could've ran at the same time, * utilising both CPUs. * * This means, that when looking globally, the current IO-wait accounting on * SMP is a lower bound, by reason of under accounting. * * Worse, since the numbers are provided per CPU, they are sometimes * interpreted per CPU, and that is nonsensical. A blocked task isn't strictly * associated with any one particular CPU, it can wake to another CPU than it * blocked on. This means the per CPU IO-wait number is meaningless. * * Task CPU affinities can make all that even more 'interesting'. */
unsigned long nr_iowait(void) { unsigned long i, sum = 0; for_each_possible_cpu(i) sum += atomic_read(&cpu_rq(i)->nr_iowait); return sum; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra2158.33%114.29%
Thomas Gleixner616.67%114.29%
Dario Faggioli38.33%114.29%
Arnaldo Carvalho de Melo25.56%114.29%
Frédéric Weisbecker25.56%114.29%
Dean Nelson12.78%114.29%
Steven Rostedt12.78%114.29%
Total36100.00%7100.00%

/* * Consumers of these two interfaces, like for example the cpufreq menu * governor are using nonsensical data. Boosting frequency for a CPU that has * IO-wait which might not even end up running the task when it does become * runnable. */
unsigned long nr_iowait_cpu(int cpu) { struct rq *this = cpu_rq(cpu); return atomic_read(&this->nr_iowait); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra2278.57%125.00%
Andrew Lutomirski27.14%125.00%
Dario Faggioli27.14%125.00%
Josh Poimboeuf27.14%125.00%
Total28100.00%4100.00%


void get_iowait_load(unsigned long *nr_waiters, unsigned long *load) { struct rq *rq = this_rq(); *nr_waiters = atomic_read(&rq->nr_iowait); *load = rq->load.weight; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra3069.77%112.50%
Dario Faggioli36.98%112.50%
Linus Torvalds36.98%112.50%
Guillaume Chazarain24.65%112.50%
Ingo Molnar24.65%112.50%
Thomas Gleixner12.33%112.50%
Josh Poimboeuf12.33%112.50%
Frédéric Weisbecker12.33%112.50%
Total43100.00%8100.00%

#ifdef CONFIG_SMP /* * sched_exec - execve() is a valuable balancing opportunity, because at * this point the task has the smallest effective memory and cache footprint. */
void sched_exec(void) { struct task_struct *p = current; unsigned long flags; int dest_cpu; raw_spin_lock_irqsave(&p->pi_lock, flags); dest_cpu = p->sched_class->select_task_rq(p, task_cpu(p), SD_BALANCE_EXEC, 0); if (dest_cpu == smp_processor_id()) goto unlock; if (likely(cpu_active(dest_cpu))) { struct migration_arg arg = { p, dest_cpu }; raw_spin_unlock_irqrestore(&p->pi_lock, flags); stop_one_cpu(task_cpu(p), migration_cpu_stop, &arg); return; } unlock: raw_spin_unlock_irqrestore(&p->pi_lock, flags); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra8067.23%17.14%
Dario Faggioli1815.13%17.14%
Oleg Nesterov65.04%214.29%
Linus Torvalds32.52%214.29%
Ingo Molnar32.52%214.29%
Frédéric Weisbecker21.68%17.14%
Arnaldo Carvalho de Melo21.68%17.14%
Thomas Gleixner21.68%17.14%
Christoph Lameter10.84%17.14%
Laurent Vivier10.84%17.14%
Martin J. Bligh10.84%17.14%
Total119100.00%14100.00%

#endif DEFINE_PER_CPU(struct kernel_stat, kstat); DEFINE_PER_CPU(struct kernel_cpustat, kernel_cpustat); EXPORT_PER_CPU_SYMBOL(kstat); EXPORT_PER_CPU_SYMBOL(kernel_cpustat); /* * The function fair_sched_class.update_curr accesses the struct curr * and its field curr->exec_start; when called from task_sched_runtime(), * we observe a high rate of cache misses in practice. * Prefetching this data results in improved performance. */
static inline void prefetch_curr_exec_start(struct task_struct *p) { #ifdef CONFIG_FAIR_GROUP_SCHED struct sched_entity *curr = (&p->se)->cfs_rq->curr; #else struct sched_entity *curr = (&task_rq(p)->cfs)->curr; #endif prefetch(curr); prefetch(&curr->exec_start); }

Contributors

PersonTokensPropCommitsCommitProp
Giovanni Gherdovich5381.54%112.50%
Dario Faggioli34.62%112.50%
Ingo Molnar23.08%112.50%
Masami Hiramatsu23.08%112.50%
Peter Zijlstra23.08%112.50%
Thomas Gleixner11.54%112.50%
Frédéric Weisbecker11.54%112.50%
Dean Nelson11.54%112.50%
Total65100.00%8100.00%

/* * Return accounted runtime for the task. * In case the task is currently running, return the runtime plus current's * pending runtime that have not been accounted yet. */
unsigned long long task_sched_runtime(struct task_struct *p) { struct rq_flags rf; struct rq *rq; u64 ns; #if defined(CONFIG_64BIT) && defined(CONFIG_SMP) /* * 64-bit doesn't need locks to atomically read a 64bit value. * So we have a optimization chance when the task's delta_exec is 0. * Reading ->on_cpu is racy, but this is ok. * * If we race with it leaving CPU, we'll take a lock. So we're correct. * If we race with it entering CPU, unaccounted time is 0. This is * indistinguishable from the read occurring a few cycles earlier. * If we see ->on_cpu without ->on_rq, the task is leaving, and has * been accounted, so we're correct here as well. */ if (!p->on_cpu || !task_on_rq_queued(p)) return p->se.sum_exec_runtime; #endif rq = task_rq_lock(p, &rf); /* * Must be ->curr _and_ ->on_rq. If dequeued, we would * project cycles that may never be accounted to this * thread, breaking clock_gettime(). */ if (task_current(rq, p) && task_on_rq_queued(p)) { prefetch_curr_exec_start(p); update_rq_clock(rq); p->sched_class->update_curr(rq); } ns = p->se.sum_exec_runtime; task_rq_unlock(rq, p, &rf); return ns; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra7358.40%626.09%
Dario Faggioli2520.00%28.70%
Oleg Nesterov97.20%28.70%
Linus Torvalds (pre-git)32.40%28.70%
Giovanni Gherdovich32.40%14.35%
Ingo Molnar21.60%28.70%
Matt Mackall21.60%14.35%
Srivatsa Vaddagiri21.60%14.35%
Greg Kroah-Hartman21.60%28.70%
Thomas Gleixner10.80%14.35%
Steven Rostedt10.80%14.35%
Christian Bornträger10.80%14.35%
Frédéric Weisbecker10.80%14.35%
Total125100.00%23100.00%

/* * This function gets called by the timer code, with HZ frequency. * We call it with interrupts disabled. */
void scheduler_tick(void) { int cpu = smp_processor_id(); struct rq *rq = cpu_rq(cpu); struct task_struct *curr = rq->curr; struct rq_flags rf; sched_clock_tick(); rq_lock(rq, &rf); update_rq_clock(rq); curr->sched_class->task_tick(rq, curr, 0); cpu_load_update_active(rq); calc_global_load_tick(rq); rq_unlock(rq, &rf); perf_event_task_tick(); #ifdef CONFIG_SMP rq->idle_balance = idle_cpu(cpu); trigger_load_balance(rq); #endif rq_last_tick_reset(rq); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra5247.27%313.04%
Dario Faggioli3128.18%14.35%
Ingo Molnar54.55%417.39%
Linus Torvalds43.64%28.70%
Thomas Gleixner32.73%313.04%
Peter Williams21.82%14.35%
Andrew Lutomirski21.82%14.35%
Andrew Morton21.82%14.35%
Frédéric Weisbecker21.82%28.70%
Arnaldo Carvalho de Melo21.82%14.35%
Kirill Tkhai21.82%14.35%
Guillaume Chazarain10.91%14.35%
Bob Miller10.91%14.35%
Oleg Nesterov10.91%14.35%
Total110100.00%23100.00%

#ifdef CONFIG_NO_HZ_FULL /** * scheduler_tick_max_deferment * * Keep at least one tick per second when a single * active task is running because the scheduler doesn't * yet completely support full dynticks environment. * * This makes sure that uptime, CFS vruntime, load * balancing, etc... continue to move forward, even * with a very low granularity. * * Return: Maximum deferment in nanoseconds. */
u64 scheduler_tick_max_deferment(void) { struct rq *rq = this_rq(); unsigned long next, now = READ_ONCE(jiffies); next = rq->last_sched_tick + HZ; if (time_before_eq(next, now)) return 0; return jiffies_to_nsecs(next - now); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra4481.48%218.18%
Linus Torvalds23.70%218.18%
Frédéric Weisbecker23.70%218.18%
Dario Faggioli23.70%19.09%
Oleg Nesterov11.85%19.09%
Linus Torvalds (pre-git)11.85%19.09%
Ingo Molnar11.85%19.09%
Heiko Carstens11.85%19.09%
Total54100.00%11100.00%

#endif #if defined(CONFIG_PREEMPT) && (defined(CONFIG_DEBUG_PREEMPT) || \ defined(CONFIG_PREEMPT_TRACER)) /* * If the value passed in is equal to the current preempt count * then we just disabled preemption. Start timing the latency. */
static inline void preempt_latency_start(int val) { if (preempt_count() == val) { unsigned long ip = get_lock_parent_ip(); #ifdef CONFIG_DEBUG_PREEMPT current->preempt_disable_ip = ip; #endif trace_preempt_off(CALLER_ADDR0, ip); } }

Contributors

PersonTokensPropCommitsCommitProp
Steven Rostedt3272.73%112.50%
Dario Faggioli36.82%112.50%
Peter Zijlstra36.82%112.50%
Davide Libenzi24.55%112.50%
Thomas Gleixner12.27%112.50%
Matt Mackall12.27%112.50%
Frédéric Weisbecker12.27%112.50%
Oleg Nesterov12.27%112.50%
Total44100.00%8100.00%


void preempt_count_add(int val) { #ifdef CONFIG_DEBUG_PREEMPT /* * Underflow? */ if (DEBUG_LOCKS_WARN_ON((preempt_count() < 0))) return; #endif __preempt_count_add(val); #ifdef CONFIG_DEBUG_PREEMPT /* * Spinlock count overflowing soon? */ DEBUG_LOCKS_WARN_ON((preempt_count() & PREEMPT_MASK) >= PREEMPT_MASK - 10); #endif preempt_latency_start(val); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra3154.39%18.33%
Dario Faggioli1119.30%18.33%
Linus Torvalds35.26%18.33%
Dongsheng Yang23.51%18.33%
Oleg Nesterov23.51%18.33%
Steven Rostedt23.51%18.33%
Linus Torvalds (pre-git)23.51%216.67%
Andi Kleen11.75%18.33%
Dean Nelson11.75%18.33%
Rusty Russell11.75%18.33%
Paul E. McKenney11.75%18.33%
Total57100.00%12100.00%

EXPORT_SYMBOL(preempt_count_add); NOKPROBE_SYMBOL(preempt_count_add); /* * If the value passed in equals to the current preempt count * then we just enabled preemption. Stop timing the latency. */
static inline void preempt_latency_stop(int val) { if (preempt_count() == val) trace_preempt_on(CALLER_ADDR0, get_lock_parent_ip()); }

Contributors

PersonTokensPropCommitsCommitProp
Steven Rostedt1560.00%150.00%
Giovanni Gherdovich1040.00%150.00%
Total25100.00%2100.00%


void preempt_count_sub(int val) { #ifdef CONFIG_DEBUG_PREEMPT /* * Underflow? */ if (DEBUG_LOCKS_WARN_ON(val > preempt_count())) return; /* * Is the spinlock portion underflowing? */ if (DEBUG_LOCKS_WARN_ON((val < PREEMPT_MASK) && !(preempt_count() & PREEMPT_MASK))) return; #endif preempt_latency_stop(val); __preempt_count_sub(val); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra3257.14%327.27%
Dario Faggioli1425.00%218.18%
Giovanni Gherdovich35.36%19.09%
Steven Rostedt35.36%218.18%
Linus Torvalds (pre-git)23.57%19.09%
Ingo Molnar11.79%19.09%
Frédéric Weisbecker11.79%19.09%
Total56100.00%11100.00%

EXPORT_SYMBOL(preempt_count_sub); NOKPROBE_SYMBOL(preempt_count_sub); #else
static inline void preempt_latency_start(int val) { }

Contributors

PersonTokensPropCommitsCommitProp
Steven Rostedt666.67%125.00%
Peter Zijlstra111.11%125.00%
Dario Faggioli111.11%125.00%
Ingo Molnar111.11%125.00%
Total9100.00%4100.00%


static inline void preempt_latency_stop(int val) { }

Contributors

PersonTokensPropCommitsCommitProp
Steven Rostedt888.89%150.00%
Dario Faggioli111.11%150.00%
Total9100.00%2100.00%

#endif
static inline unsigned long get_preempt_disable_ip(struct task_struct *p) { #ifdef CONFIG_DEBUG_PREEMPT return p->preempt_disable_ip; #else return 0; #endif }

Contributors

PersonTokensPropCommitsCommitProp
Ingo Molnar2692.86%250.00%
Peter Zijlstra13.57%125.00%
Dario Faggioli13.57%125.00%
Total28100.00%4100.00%

/* * Print scheduling while atomic bug: */
static noinline void __schedule_bug(struct task_struct *prev) { /* Save this before calling printk(), since that will clobber it */ unsigned long preempt_disable_ip = get_preempt_disable_ip(current); if (oops_in_progress) return; printk(KERN_ERR "BUG: scheduling while atomic: %s/%d/0x%08x\n", prev->comm, prev->pid, preempt_count()); debug_show_held_locks(prev); print_modules(); if (irqs_disabled()) print_irqtrace_events(prev); if (IS_ENABLED(CONFIG_DEBUG_PREEMPT) && in_atomic_preempt_off()) { pr_err("Preemption disabled at:"); print_ip_sym(preempt_disable_ip); pr_cont("\n"); } if (panic_on_warn) panic("scheduling while atomic\n"); dump_stack(); add_taint(TAINT_WARN, LOCKDEP_STILL_OK); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra4743.52%211.11%
Dario Faggioli1513.89%15.56%
Vegard Nossum1211.11%15.56%
Oleg Nesterov76.48%15.56%
Daniel Bristot de Oliveira65.56%15.56%
Linus Torvalds32.78%15.56%
Brian Silverman32.78%15.56%
Andrew Morton32.78%15.56%
Kirill Tkhai21.85%15.56%
Arnaldo Carvalho de Melo21.85%15.56%
Frédéric Weisbecker21.85%211.11%
Peter Williams21.85%15.56%
Rusty Russell10.93%15.56%
Anton Blanchard10.93%15.56%
Ingo Molnar10.93%15.56%
Guillaume Chazarain10.93%15.56%
Total108100.00%18100.00%

/* * Various schedule()-time debugging checks and statistics: */
static inline void schedule_debug(struct task_struct *prev) { #ifdef CONFIG_SCHED_STACK_END_CHECK if (task_stack_end_corrupted(prev)) panic("corrupted stack end detected inside scheduler\n"); #endif if (unlikely(in_atomic_preempt_off())) { __schedule_bug(prev); preempt_count_set(PREEMPT_DISABLED); } rcu_sleep_check(); profile_hit(SCHED_PROFILING, __builtin_return_address(0)); schedstat_inc(this_rq()->sched_count); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra4158.57%323.08%
Dario Faggioli1115.71%17.69%
Jann Horn68.57%17.69%
Dongsheng Yang22.86%17.69%
Oleg Nesterov22.86%17.69%
Heiko Carstens22.86%17.69%
Thomas Gleixner22.86%17.69%
Ingo Molnar22.86%215.38%
Keith Owens11.43%17.69%
Josh Poimboeuf11.43%17.69%
Total70100.00%13100.00%

/* * Pick up the highest-prio task: */
static inline struct task_struct * pick_next_task(struct rq *rq, struct task_struct *prev, struct rq_flags *rf) { const struct sched_class *class; struct task_struct *p; /* * Optimization: we know that if all tasks are in the fair class we can * call that function directly, but only if the @prev task wasn't of a * higher scheduling class, because otherwise those loose the * opportunity to pull in more work from other CPUs. */ if (likely((prev->sched_class == &idle_sched_class || prev->sched_class == &fair_sched_class) && rq->nr_running == rq->cfs.h_nr_running)) { p = fair_sched_class.pick_next_task(rq, prev, rf); if (unlikely(p == RETRY_TASK)) goto again; /* Assumes fair_sched_class->next == idle_sched_class */ if (unlikely(!p)) p = idle_sched_class.pick_next_task(rq, prev, rf); return p; } again: for_each_class(class) { p = class->pick_next_task(rq, prev, rf); if (p) { if (unlikely(p == RETRY_TASK)) goto again; return p; } } /* The idle class should always have a runnable task: */ BUG(); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra8149.09%414.81%
Dario Faggioli2515.15%27.41%
Steven Rostedt1810.91%13.70%
Ingo Molnar159.09%829.63%
Matt Fleming63.64%13.70%
Linus Torvalds63.64%27.41%
Thomas Gleixner42.42%27.41%
Rusty Russell31.82%27.41%
Andrew Lutomirski21.21%13.70%
Dongsheng Yang21.21%13.70%
Robert Love10.61%13.70%
Juri Lelli10.61%13.70%
Linus Torvalds (pre-git)10.61%13.70%
Total165100.00%27100.00%

/* * __schedule() is the main scheduler function. * * The main means of driving the scheduler and thus entering this function are: * * 1. Explicit blocking: mutex, semaphore, waitqueue, etc. * * 2. TIF_NEED_RESCHED flag is checked on interrupt and userspace return * paths. For example, see arch/x86/entry_64.S. * * To drive preemption between tasks, the scheduler sets the flag in timer * interrupt handler scheduler_tick(). * * 3. Wakeups don't really cause entry into schedule(). They add a * task to the run-queue and that's it. * * Now, if the new task added to the run-queue preempts the current * task, then the wakeup sets TIF_NEED_RESCHED and schedule() gets * called on the nearest possible occasion: * * - If the kernel is preemptible (CONFIG_PREEMPT=y): * * - in syscall or exception context, at the next outmost * preempt_enable(). (this might be as soon as the wake_up()'s * spin_unlock()!) * * - in IRQ context, return from interrupt-handler to * preemptible context * * - If the kernel is not preemptible (CONFIG_PREEMPT is not set) * then at the next: * * - cond_resched() call * - explicit schedule() call * - return from syscall or exception to user-space * - return from interrupt-handler to user-space * * WARNING: must be called with preemption disabled! */
static void __sched notrace __schedule(bool preempt) { struct task_struct *prev, *next; unsigned long *switch_count; struct rq_flags rf; struct rq *rq; int cpu; cpu = smp_processor_id(); rq = cpu_rq(cpu); prev = rq->curr; schedule_debug(prev); if (sched_feat(HRTICK)) hrtick_clear(rq); local_irq_disable(); rcu_note_context_switch(preempt); /* * Make sure that signal_pending_state()->signal_pending() below * can't be reordered with __set_current_state(TASK_INTERRUPTIBLE) * done by the caller to avoid the race with signal_wake_up(). */ rq_lock(rq, &rf); smp_mb__after_spinlock(); /* Promote REQ to ACT */ rq->clock_update_flags <<= 1; update_rq_clock(rq); switch_count = &prev->nivcsw; if (!preempt && prev->state) { if (unlikely(signal_pending_state(prev->state, prev))) { prev->state = TASK_RUNNING; } else { deactivate_task(rq, prev, DEQUEUE_SLEEP | DEQUEUE_NOCLOCK); prev->on_rq = 0; if (prev->in_iowait) { atomic_inc(&rq->nr_iowait); delayacct_blkio_start(); } /* * If a worker went to sleep, notify and ask workqueue * whether it wants to wake up a task to maintain * concurrency. */ if (prev->flags & PF_WQ_WORKER) { struct task_struct *to_wakeup; to_wakeup = wq_worker_sleeping(prev); if (to_wakeup) try_to_wake_up_local(to_wakeup, &rf); } } switch_count = &prev->nvcsw; } next = pick_next_task(rq, prev, &rf); clear_tsk_need_resched(prev); clear_preempt_need_resched(); if (likely(prev != next)) { rq->nr_switches++; rq->curr = next; /* * The membarrier system call requires each architecture * to have a full memory barrier after updating * rq->curr, before returning to user-space. For TSO * (e.g. x86), the architecture must provide its own * barrier in switch_mm(). For weakly ordered machines * for which spin_unlock() acts as a full memory * barrier, finish_lock_switch() in common code takes * care of this barrier. For weakly ordered machines for * which spin_unlock() acts as a RELEASE barrier (only * arm64 and PowerPC), arm64 has a full barrier in * switch_to(), and PowerPC has * smp_mb__after_unlock_lock() before * finish_lock_switch(). */ ++*switch_count; trace_sched_switch(preempt, prev, next); /* Also unlocks the rq: */ rq = context_switch(rq, prev, next, &rf); } else { rq->clock_update_flags &= ~(RQCF_ACT_SKIP|RQCF_REQ_SKIP); rq_unlock_irq(rq, &rf); } balance_callback(rq); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra16450.93%1121.57%
Dario Faggioli5517.08%47.84%
Matt Fleming257.76%35.88%
Tejun Heo113.42%11.96%
Brian Silverman72.17%11.96%
Ingo Molnar61.86%47.84%
Linus Torvalds (pre-git)51.55%35.88%
Vegard Nossum51.55%11.96%
Thomas Gleixner51.55%23.92%
Dongsheng Yang41.24%11.96%
Steven Rostedt41.24%11.96%
Jann Horn30.93%11.96%
Daniel Bristot de Oliveira30.93%11.96%
Andrew Morton30.93%11.96%
Paul E. McKenney30.93%23.92%
Oleg Nesterov20.62%11.96%
Olivier Croquette20.62%11.96%
Linus Torvalds20.62%11.96%
Rusty Russell20.62%11.96%
Greg Kroah-Hartman20.62%23.92%
Juri Lelli20.62%11.96%
Andi Kleen10.31%11.96%
Matt Mackall10.31%11.96%
Robert Love10.31%11.96%
Josh Poimboeuf10.31%11.96%
Lennart Poettering10.31%11.96%
Harald Gustafsson10.31%11.96%
Mathieu Desnoyers10.31%11.96%
Total322100.00%51100.00%


void __noreturn do_task_dead(void) { /* * The setting of TASK_RUNNING by try_to_wake_up() may be delayed * when the following two conditions become true. * - There is race condition of mmap_sem (It is acquired by * exit_mm()), and * - SMI occurs before setting TASK_RUNINNG. * (or hypervisor of virtual machine switches to other guest) * As a result, we may become TASK_RUNNING after becoming TASK_DEAD * * To avoid it, we have to wait for releasing tsk->pi_lock which * is held by try_to_wake_up() */ raw_spin_lock_irq(&current->pi_lock); raw_spin_unlock_irq(&current->pi_lock); /* Causes final put_task_struct in finish_task_switch(): */ __set_current_state(TASK_DEAD); /* Tell freezer to ignore us: */ current->flags |= PF_NOFREEZE; __schedule(false); BUG(); /* Avoid "noreturn function does return" - but don't continue if BUG() is a NOP: */ for (;;) cpu_relax(); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra3767.27%337.50%
Paul E. McKenney814.55%112.50%
Dario Faggioli47.27%112.50%
Ingo Molnar35.45%112.50%
Dongsheng Yang23.64%112.50%
Peter Williams11.82%112.50%
Total55100.00%8100.00%


static inline void sched_submit_work(struct task_struct *tsk) { if (!tsk->state || tsk_is_pi_blocked(tsk)) return; /* * If we are going to sleep and we have plugged IO queued, * make sure to submit it to avoid deadlocks. */ if (blk_needs_flush_plug(tsk)) blk_schedule_flush_plug(tsk); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra1539.47%111.11%
Dario Faggioli1334.21%111.11%
Paul E. McKenney37.89%222.22%
Linus Torvalds37.89%111.11%
Andrew Morton12.63%111.11%
Rick Lindsley12.63%111.11%
Ingo Molnar12.63%111.11%
Rusty Russell12.63%111.11%
Total38100.00%9100.00%


asmlinkage __visible void __sched schedule(void) { struct task_struct *tsk = current; sched_submit_work(tsk); do { preempt_disable(); __schedule(false); sched_preempt_enable_no_resched(); } while (need_resched()); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra3378.57%342.86%
Thomas Gleixner511.90%114.29%
Dario Faggioli24.76%114.29%
Wanpeng Li12.38%114.29%
Rusty Russell12.38%114.29%
Total42100.00%7100.00%

EXPORT_SYMBOL(schedule); /* * synchronize_rcu_tasks() makes sure that no task is stuck in preempted * state (have scheduled out non-voluntarily) by making sure that all * tasks have either left the run queue or have gone into user space. * As idle tasks do not do either, they must not ever be preempted * (schedule out non-voluntarily). * * schedule_idle() is similar to schedule_preempt_disable() except that it * never enables preemption because it does not call sched_submit_work(). */
void __sched schedule_idle(void) { /* * As this skips calling sched_submit_work(), which the idle task does * regardless because that function is a nop when the task is in a * TASK_RUNNING state, make sure this isn't used someplace that the * current task can be in any other state. Note, idle is always in the * TASK_RUNNING state. */ WARN_ON_ONCE(current->state); do { __schedule(false); } while (need_resched()); }

Contributors

PersonTokensPropCommitsCommitProp
Steven Rostedt2170.00%233.33%
Dario Faggioli413.33%233.33%
Peter Zijlstra310.00%116.67%
Tejun Heo26.67%116.67%
Total30100.00%6100.00%

#ifdef CONFIG_CONTEXT_TRACKING
asmlinkage __visible void __sched schedule_user(void) { /* * If we come here after a random call to set_need_resched(), * or we have been woken up remotely but the IPI has not yet arrived, * we haven't yet exited the RCU idle mode. Do it here manually until * we find a better solution. * * NB: There are buggy callers of this function. Ideally we * should warn if prev_state != CONTEXT_USER, but that will trigger * too frequently to make sense yet. */ enum ctx_state prev_state = exception_enter(); schedule(); exception_exit(prev_state); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra1661.54%125.00%
Tejun Heo415.38%125.00%
Dario Faggioli415.38%125.00%
Keith Owens27.69%125.00%
Total26100.00%4100.00%

#endif /** * schedule_preempt_disabled - called with preemption disabled * * Returns with preemption disabled. Note: preempt_count must be 1 */
void __sched schedule_preempt_disabled(void) { sched_preempt_enable_no_resched(); schedule(); preempt_disable(); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra1376.47%133.33%
Tejun Heo317.65%133.33%
Dario Faggioli15.88%133.33%
Total17100.00%3100.00%


static void __sched notrace preempt_schedule_common(void) { do { /* * Because the function tracer can trace preempt_count_sub() * and it also uses preempt_enable/disable_notrace(), if * NEED_RESCHED is set, the preempt_enable_notrace() called * by the function tracer will call this function again and * cause infinite recursion. * * Preemption must be disabled here before the function * tracer can trace. Break up preempt_disable() into two * calls. One to disable preemption without fear of being * traced. The other to still record the preemption latency, * which can also be traced by the function tracer. */ preempt_disable_notrace(); preempt_latency_start(1); __schedule(true); preempt_latency_stop(1); preempt_enable_no_resched_notrace(); /* * Check again in case we missed a preemption opportunity * between schedule and now. */ } while (need_resched()); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra2252.38%440.00%
Dario Faggioli1023.81%110.00%
Steven Rostedt511.90%110.00%
Brian Silverman24.76%110.00%
David Chinner12.38%110.00%
Rick Lindsley12.38%110.00%
Lennart Poettering12.38%110.00%
Total42100.00%10100.00%

#ifdef CONFIG_PREEMPT /* * this is the entry point to schedule() from in-kernel preemption * off of preempt_enable. Kernel preemptions off return from interrupt * occur there and call schedule directly. */
asmlinkage __visible void __sched notrace preempt_schedule(void) { /* * If there is a non-zero preempt_count or interrupts are disabled, * we do not want to preempt the current task. Just return.. */ if (likely(!preemptible())) return; preempt_schedule_common(); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra2184.00%250.00%
Dario Faggioli312.00%125.00%
Linus Torvalds14.00%125.00%
Total25100.00%4100.00%

NOKPROBE_SYMBOL(preempt_schedule); EXPORT_SYMBOL(preempt_schedule); /** * preempt_schedule_notrace - preempt_schedule called by tracing * * The tracing infrastructure uses preempt_enable_notrace to prevent * recursion and tracing preempt enabling caused by the tracing * infrastructure itself. But as tracing can happen in areas coming * from userspace or just about to enter userspace, a preempt enable * can occur before user_exit() is called. This will cause the scheduler * to be called when the system is still in usermode. * * To prevent this, the preempt_enable_notrace will use this function * instead of preempt_schedule() to exit user context if needed before * calling the scheduler. */
asmlinkage __visible void __sched notrace preempt_schedule_notrace(void) { enum ctx_state prev_ctx; if (likely(!preemptible())) return; do { /* * Because the function tracer can trace preempt_count_sub() * and it also uses preempt_enable/disable_notrace(), if * NEED_RESCHED is set, the preempt_enable_notrace() called * by the function tracer will call this function again and * cause infinite recursion. * * Preemption must be disabled here before the function * tracer can trace. Break up preempt_disable() into two * calls. One to disable preemption without fear of being * traced. The other to still record the preemption latency, * which can also be traced by the function tracer. */ preempt_disable_notrace(); preempt_latency_start(1); /* * Needs preempt disabled in case user_exit() is traced * and the tracer calls preempt_enable_notrace() causing * an infinite recursion. */ prev_ctx = exception_enter(); __schedule(true); exception_exit(prev_ctx); preempt_latency_stop(1); preempt_enable_no_resched_notrace(); } while (need_resched()); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra3958.21%450.00%
Steven Rostedt1928.36%225.00%
Dario Faggioli710.45%112.50%
Thomas Gleixner22.99%112.50%
Total67100.00%8100.00%

EXPORT_SYMBOL_GPL(preempt_schedule_notrace); #endif /* CONFIG_PREEMPT */ /* * this is the entry point to schedule() from kernel preemption * off of irq context. * Note, that this is called and return with irqs disabled. This will * protect us against recursive calling from irq. */
asmlinkage __visible void __sched preempt_schedule_irq(void) { enum ctx_state prev_state; /* Catch callers which need to be fixed */ BUG_ON(preempt_count() || !irqs_disabled()); prev_state = exception_enter(); do { preempt_disable(); local_irq_enable(); __schedule(true); local_irq_disable(); sched_preempt_enable_no_resched(); } while (need_resched()); exception_exit(prev_state); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra4878.69%337.50%
Dario Faggioli711.48%112.50%
Steven Rostedt23.28%112.50%
Wanpeng Li23.28%112.50%
Rusty Russell11.64%112.50%
Rick Lindsley11.64%112.50%
Total61100.00%8100.00%


int default_wake_function(wait_queue_entry_t *curr, unsigned mode, int wake_flags, void *key) { return try_to_wake_up(curr->private, mode, wake_flags); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra1445.16%112.50%
Dario Faggioli1238.71%337.50%
Linus Torvalds26.45%112.50%
Steven Rostedt13.23%112.50%
Robert Love13.23%112.50%
Ingo Molnar13.23%112.50%
Total31100.00%8100.00%

EXPORT_SYMBOL(default_wake_function); #ifdef CONFIG_RT_MUTEXES
static inline int __rt_effective_prio(struct task_struct *pi_task, int prio) { if (pi_task) prio = min(prio, pi_task->prio); return prio; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra3296.97%150.00%
Dario Faggioli13.03%150.00%
Total33100.00%2100.00%


static inline int rt_effective_prio(struct task_struct *p, int prio) { struct task_struct *pi_task = rt_mutex_get_top_task(p); return __rt_effective_prio(pi_task, prio); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra33100.00%1100.00%
Total33100.00%1100.00%

/* * rt_mutex_setprio - set the current priority of a task * @p: task to boost * @pi_task: donor task * * This function changes the 'effective' priority of a task. It does * not touch ->normal_prio like __setscheduler(). * * Used by the rt_mutex code to implement priority inheritance * logic. Call site only calls if the priority of the task changed. */
void rt_mutex_setprio(struct task_struct *p, struct task_struct *pi_task) { int prio, oldprio, queued, running, queue_flag = DEQUEUE_SAVE | DEQUEUE_MOVE | DEQUEUE_NOCLOCK; const struct sched_class *prev_class; struct rq_flags rf; struct rq *rq; /* XXX used to be waiter->prio, not waiter->task->prio */ prio = __rt_effective_prio(pi_task, p->normal_prio); /* * If nothing changed; bail early. */ if (p->pi_top_task == pi_task && prio == p->prio && !dl_prio(prio)) return; rq = __task_rq_lock(p, &rf); update_rq_clock(rq); /* * Set under pi_lock && rq->lock, such that the value can be used under * either lock. * * Note that there is loads of tricky to make this pointer cache work * right. rt_mutex_slowunlock()+rt_mutex_postunlock() work together to * ensure a task is de-boosted (pi_task is set to NULL) before the * task is allowed to run again (and can exit). This ensures the pointer * points to a blocked task -- which guaratees the task is present. */ p->pi_top_task = pi_task; /* * For FIFO/RR we only need to set prio, if that matches we're done. */ if (prio == p->prio && !dl_prio(prio)) goto out_unlock; /* * Idle task boosting is a nono in general. There is one * exception, when PREEMPT_RT and NOHZ is active: * * The idle task calls get_next_timer_interrupt() and holds * the timer wheel base->lock on the CPU and another CPU wants * to access the timer (probably to cancel it). We can safely * ignore the boosting request, as the idle CPU runs this code * with interrupts disabled and will complete the lock * protected section without being interrupted. So there is no * real need to boost. */ if (unlikely(p == rq->idle)) { WARN_ON(p != rq->curr); WARN_ON(p->pi_blocked_on); goto out_unlock; } trace_sched_pi_setprio(p, pi_task); oldprio = p->prio; if (oldprio == prio) queue_flag &= ~DEQUEUE_MOVE; prev_class = p->sched_class; queued = task_on_rq_queued(p); running = task_current(rq, p); if (queued) dequeue_task(rq, p, queue_flag); if (running) put_prev_task(rq, p); /* * Boosting condition are: * 1. -rt task is running and holds mutex A * --> -dl task blocks on mutex A * * 2. -dl task is running and holds mutex A * --> -dl task blocks on mutex A and could preempt the * running task */ if (dl_prio(prio)) { if (!dl_prio(p->normal_prio) || (pi_task && dl_entity_preempt(&pi_task->dl, &p->dl))) { p->dl.dl_boosted = 1; queue_flag |= ENQUEUE_REPLENISH; } else p->dl.dl_boosted = 0; p->sched_class = &dl_sched_class; } else if (rt_prio(prio)) { if (dl_prio(oldprio)) p->dl.dl_boosted = 0; if (oldprio < prio) queue_flag |= ENQUEUE_HEAD; p->sched_class = &rt_sched_class; } else { if (dl_prio(oldprio)) p->dl.dl_boosted = 0; if (rt_prio(oldprio)) p->rt.timeout = 0; p->sched_class = &fair_sched_class; } p->prio = prio; if (queued) enqueue_task(rq, p, queue_flag); if (running) set_curr_task(rq, p); check_class_changed(rq, p, prev_class, oldprio); out_unlock: /* Avoid rq from going away on us: */ preempt_disable(); __task_rq_unlock(rq, &rf); balance_callback(rq); preempt_enable(); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra26761.24%1334.21%
Dario Faggioli10022.94%25.26%
Thomas Gleixner163.67%25.26%
Vincent Guittot81.83%12.63%
Chris Wright71.61%12.63%
Steven Rostedt61.38%25.26%
Linus Torvalds51.15%12.63%
Heiko Carstens40.92%12.63%
Dean Nelson40.92%12.63%
Kirill Tkhai30.69%12.63%
Srivatsa Vaddagiri30.69%12.63%
Ingo Molnar20.46%25.26%
Juri Lelli20.46%12.63%
Linus Torvalds (pre-git)20.46%25.26%
Namhyung Kim10.23%12.63%
Darren Hart10.23%12.63%
Con Kolivas10.23%12.63%
Oleg Nesterov10.23%12.63%
Olivier Croquette10.23%12.63%
Jens Axboe10.23%12.63%
Rusty Russell10.23%12.63%
Total436100.00%38100.00%

#else
static inline int rt_effective_prio(struct task_struct *p, int prio) { return prio; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra18100.00%1100.00%
Total18100.00%1100.00%

#endif
void set_user_nice(struct task_struct *p, long nice) { bool queued, running; int old_prio, delta; struct rq_flags rf; struct rq *rq; if (task_nice(p) == nice || nice < MIN_NICE || nice > MAX_NICE) return; /* * We have to be careful, if called from sys_setpriority(), * the task might be in the middle of scheduling on another CPU. */ rq = task_rq_lock(p, &rf); update_rq_clock(rq); /* * The RT priorities are set via sched_setscheduler(), but we still * allow the 'normal' nice value to be set - but as expected * it wont have any effect on scheduling until the task is * SCHED_DEADLINE, SCHED_FIFO or SCHED_RR: */ if (task_has_dl_policy(p) || task_has_rt_policy(p)) { p->static_prio = NICE_TO_PRIO(nice); goto out_unlock; } queued = task_on_rq_queued(p); running = task_current(rq, p); if (queued) dequeue_task(rq, p, DEQUEUE_SAVE | DEQUEUE_NOCLOCK); if (running) put_prev_task(rq, p); p->static_prio = NICE_TO_PRIO(nice); set_load_weight(p, true); old_prio = p->prio; p->prio = effective_prio(p); delta = p->prio - old_prio; if (queued) { enqueue_task(rq, p, ENQUEUE_RESTORE | ENQUEUE_NOCLOCK); /* * If the task increased its priority or is running and * lowered its priority, then reschedule its CPU: */ if (delta < 0 || (delta > 0 && task_running(rq, p))) resched_curr(rq); } if (running) set_curr_task(rq, p); out_unlock: task_rq_unlock(rq, p, &rf); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra16769.87%1150.00%
Dario Faggioli5623.43%29.09%
Ingo Molnar31.26%14.55%
Andrew Morton31.26%14.55%
Rusty Russell31.26%29.09%
Chris Wright20.84%14.55%
Linus Torvalds (pre-git)20.84%29.09%
Vincent Guittot20.84%14.55%
Srivatsa Vaddagiri10.42%14.55%
Total239100.00%22100.00%

EXPORT_SYMBOL(set_user_nice); /* * can_nice - check if a task can reduce its nice value * @p: task * @nice: nice value */
int can_nice(const struct task_struct *p, const int nice) { /* Convert nice value [19,-20] to rlimit style value [1,40]: */ int nice_rlim = nice_to_rlimit(nice); return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) || capable(CAP_SYS_NICE)); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra2560.98%240.00%
Dario Faggioli1331.71%120.00%
Dean Nelson24.88%120.00%
Ingo Molnar12.44%120.00%
Total41100.00%5100.00%

#ifdef __ARCH_WANT_SYS_NICE /* * sys_nice - change the priority of the current process. * @increment: priority increment * * sys_setpriority is a more generic, but much slower function that * does similar things. */ SYSCALL_DEFINE1(nice, int, increment) { long nice, retval; /* * Setpriority might change our priority at the same moment. * We don't have to worry. Conceptually one call occurs first * and we have a single winner. */ increment = clamp(increment, -NICE_WIDTH, NICE_WIDTH); nice = task_nice(current) + increment; nice = clamp_val(nice, MIN_NICE, MAX_NICE); if (increment < 0 && !can_nice(current, nice)) return -EPERM; retval = security_task_setnice(current, nice); if (retval) return retval; set_user_nice(current, nice); return 0; } #endif /** * task_prio - return the priority value of a given task. * @p: the task in question. * * Return: The priority value as seen by users in /proc. * RT tasks are offset by -200. Normal tasks are centered * around 0, value goes from -16 to +15. */
int task_prio(const struct task_struct *p) { return p->prio - MAX_RT_PRIO; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra950.00%125.00%
Dario Faggioli527.78%125.00%
Thomas Gleixner316.67%125.00%
Linus Torvalds (pre-git)15.56%125.00%
Total18100.00%4100.00%

/** * idle_cpu - is a given CPU idle currently? * @cpu: the processor in question. * * Return: 1 if the CPU is currently idle. 0 otherwise. */
int idle_cpu(int cpu) { struct rq *rq = cpu_rq(cpu); if (rq->curr != rq->idle) return 0; if (rq->nr_running) return 0; #ifdef CONFIG_SMP if (!llist_empty(&rq->wake_list)) return 0; #endif return 1; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra3251.61%120.00%
Dario Faggioli2133.87%240.00%
Thomas Gleixner812.90%120.00%
Dean Nelson11.61%120.00%
Total62100.00%5100.00%

/** * idle_task - return the idle task for a given CPU. * @cpu: the processor in question. * * Return: The idle task for the CPU @cpu. */
struct task_struct *idle_task(int cpu) { return cpu_rq(cpu)->idle; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra1372.22%133.33%
Dario Faggioli316.67%133.33%
Kirill Tkhai211.11%133.33%
Total18100.00%3100.00%

/** * find_process_by_pid - find a process with a matching PID value. * @pid: the pid in question. * * The task of @pid, if found. %NULL otherwise. */
static struct task_struct *find_process_by_pid(pid_t pid) { return pid ? find_task_by_vpid(pid) : current; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra1990.48%150.00%
Dario Faggioli29.52%150.00%
Total21100.00%2100.00%

/* * sched_setparam() passes in -1 for its policy, to let the functions * it calls know not to change it. */ #define SETPARAM_POLICY -1
static void __setscheduler_params(struct task_struct *p, const struct sched_attr *attr) { int policy = attr->sched_policy; if (policy == SETPARAM_POLICY) policy = p->policy; p->policy = policy; if (dl_policy(policy)) __setparam_dl(p, attr); else if (fair_policy(policy)) p->static_prio = NICE_TO_PRIO(attr->sched_nice); /* * __sched_setscheduler() ensures attr->sched_priority == 0 when * !rt_policy. Always setting this ensures that things like * getparam()/getattr() don't report silly values for !rt tasks. */ p->rt_priority = attr->sched_priority; p->normal_prio = normal_prio(p); set_load_weight(p, true); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra6363.00%114.29%
Dario Faggioli2626.00%228.57%
Thomas Gleixner77.00%228.57%
Vincent Guittot22.00%114.29%
Henrik Austad22.00%114.29%
Total100100.00%7100.00%

/* Actually do priority change: must hold pi & rq lock. */
static void __setscheduler(struct rq *rq, struct task_struct *p, const struct sched_attr *attr, bool keep_boost) { __setscheduler_params(p, attr); /* * Keep a potential priority boosting if called from * sched_setscheduler(). */ p->prio = normal_prio(p); if (keep_boost) p->prio = rt_effective_prio(p, p->prio); if (dl_prio(p->prio)) p->sched_class = &dl_sched_class; else if (rt_prio(p->prio)) p->sched_class = &rt_sched_class; else p->sched_class = &fair_sched_class; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra8383.00%450.00%
Dario Faggioli1414.00%225.00%
Thomas Gleixner22.00%112.50%
Heiko Carstens11.00%112.50%
Total100100.00%8100.00%

/* * Check the target process has a UID that matches the current process's: */
static bool check_same_owner(struct task_struct *p) { const struct cred *cred = current_cred(), *pcred; bool match; rcu_read_lock(); pcred = __task_cred(p); match = (uid_eq(cred->euid, pcred->euid) || uid_eq(cred->euid, pcred->uid)); rcu_read_unlock(); return match; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra5783.82%250.00%
Dario Faggioli1116.18%250.00%
Total68100.00%4100.00%


static int __sched_setscheduler(struct task_struct *p, const struct sched_attr *attr, bool user, bool pi) { int newprio = dl_policy(attr->sched_policy) ? MAX_DL_PRIO - 1 : MAX_RT_PRIO - 1 - attr->sched_priority; int retval, oldprio, oldpolicy = -1, queued, running; int new_effective_prio, policy = attr->sched_policy; const struct sched_class *prev_class; struct rq_flags rf; int reset_on_fork; int queue_flags = DEQUEUE_SAVE | DEQUEUE_MOVE | DEQUEUE_NOCLOCK; struct rq *rq; /* The pi code expects interrupts enabled */ BUG_ON(pi && in_interrupt()); recheck: /* Double check policy once rq lock held: */ if (policy < 0) { reset_on_fork = p->sched_reset_on_fork; policy = oldpolicy = p->policy; } else { reset_on_fork = !!(attr->sched_flags & SCHED_FLAG_RESET_ON_FORK); if (!valid_policy(policy)) return -EINVAL; } if (attr->sched_flags & ~(SCHED_FLAG_RESET_ON_FORK | SCHED_FLAG_RECLAIM)) return -EINVAL; /* * Valid priorities for SCHED_FIFO and SCHED_RR are * 1..MAX_USER_RT_PRIO-1, valid priority for SCHED_NORMAL, * SCHED_BATCH and SCHED_IDLE is 0. */ if ((p->mm && attr->sched_priority > MAX_USER_RT_PRIO-1) || (!p->mm && attr->sched_priority > MAX_RT_PRIO-1)) return -EINVAL; if ((dl_policy(policy) && !__checkparam_dl(attr)) || (rt_policy(policy) != (attr->sched_priority != 0))) return -EINVAL; /* * Allow unprivileged RT tasks to decrease priority: */ if (user && !capable(CAP_SYS_NICE)) { if (fair_policy(policy)) { if (attr->sched_nice < task_nice(p) && !can_nice(p, attr->sched_nice)) return -EPERM; } if (rt_policy(policy)) { unsigned long rlim_rtprio = task_rlimit(p, RLIMIT_RTPRIO); /* Can't set/change the rt policy: */ if (policy != p->policy && !rlim_rtprio) return -EPERM; /* Can't increase priority: */ if (attr->sched_priority > p->rt_priority && attr->sched_priority > rlim_rtprio) return -EPERM; } /* * Can't set/change SCHED_DEADLINE policy at all for now * (safest behavior); in the future we would like to allow * unprivileged DL tasks to increase their relative deadline * or reduce their runtime (both ways reducing utilization) */ if (dl_policy(policy)) return -EPERM; /* * Treat SCHED_IDLE as nice 20. Only allow a switch to * SCHED_NORMAL if the RLIMIT_NICE would normally permit it. */ if (idle_policy(p->policy) && !idle_policy(policy)) { if (!can_nice(p, task_nice(p))) return -EPERM; } /* Can't change other user's priorities: */ if (!check_same_owner(p)) return -EPERM; /* Normal users shall not reset the sched_reset_on_fork flag: */ if (p->sched_reset_on_fork && !reset_on_fork) return -EPERM; } if (user) { retval = security_task_setscheduler(p); if (retval) return retval; } /* * Make sure no PI-waiters arrive (or leave) while we are * changing the priority of the task: * * To be able to change p->policy safely, the appropriate * runqueue lock must be held. */ rq = task_rq_lock(p, &rf); update_rq_clock(rq); /* * Changing the policy of the stop threads its a very bad idea: */ if (p == rq->stop) { task_rq_unlock(rq, p, &rf); return -EINVAL; } /* * If not changing anything there's no need to proceed further, * but store a possible modification of reset_on_fork. */ if (unlikely(policy == p->policy)) { if (fair_policy(policy) && attr->sched_nice != task_nice(p)) goto change; if (rt_policy(policy) && attr->sched_priority != p->rt_priority) goto change; if (dl_policy(policy) && dl_param_changed(p, attr)) goto change; p->sched_reset_on_fork = reset_on_fork; task_rq_unlock(rq, p, &rf); return 0; } change: if (user) { #ifdef CONFIG_RT_GROUP_SCHED /* * Do not allow realtime tasks into groups that have no runtime * assigned. */ if (rt_bandwidth_enabled() && rt_policy(policy) && task_group(p)->rt_bandwidth.rt_runtime == 0 && !task_group_is_autogroup(task_group(p))) { task_rq_unlock(rq, p, &rf); return -EPERM; } #endif #ifdef CONFIG_SMP if (dl_bandwidth_enabled() && dl_policy(policy)) { cpumask_t *span = rq->rd->span; /* * Don't allow tasks with an affinity mask smaller than * the entire root_domain to become SCHED_DEADLINE. We * will also fail if there's no bandwidth available. */ if (!cpumask_subset(span, &p->cpus_allowed) || rq->rd->dl_bw.bw == 0) { task_rq_unlock(rq, p, &rf); return -EPERM; } } #endif } /* Re-check policy now with rq lock held: */ if (unlikely(oldpolicy != -1 && oldpolicy != p->policy)) { policy = oldpolicy = -1; task_rq_unlock(rq, p, &rf); goto recheck; } /* * If setscheduling to SCHED_DEADLINE (or changing the parameters * of a SCHED_DEADLINE task) we need to check if enough bandwidth * is available. */ if ((dl_policy(policy) || dl_task(p)) && sched_dl_overflow(p, policy, attr)) { task_rq_unlock(rq, p, &rf); return -EBUSY; } p->sched_reset_on_fork = reset_on_fork; oldprio = p->prio; if (pi) { /* * Take priority boosted tasks into account. If the new * effective priority is unchanged, we just store the new * normal parameters and do not touch the scheduler class and * the runqueue. This will be done when the task deboost * itself. */ new_effective_prio = rt_effective_prio(p, newprio); if (new_effective_prio == oldprio) queue_flags &= ~DEQUEUE_MOVE; } queued = task_on_rq_queued(p); running = task_current(rq, p); if (queued) dequeue_task(rq, p, queue_flags); if (running) put_prev_task(rq, p); prev_class = p->sched_class; __setscheduler(rq, p, attr, pi); if (queued) { /* * We enqueue to tail when the priority of a task is * increased (user space view). */ if (oldprio < p->prio) queue_flags |= ENQUEUE_HEAD; enqueue_task(rq, p, queue_flags); } if (running) set_curr_task(rq, p); check_class_changed(rq, p, prev_class, oldprio); /* Avoid rq from going away on us: */ preempt_disable(); task_rq_unlock(rq, p, &rf); if (pi) rt_mutex_adjust_pi(p); /* Run balance callbacks after we've adjusted the PI chain: */ balance_callback(rq); preempt_enable(); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra63466.32%1321.67%
Dario Faggioli19820.71%46.67%
Ingo Molnar171.78%711.67%
Linus Torvalds (pre-git)141.46%23.33%
Henrik Austad90.94%11.67%
Vincent Guittot90.94%11.67%
Linus Torvalds80.84%23.33%
Andrew Morton60.63%35.00%
Anton Blanchard60.63%11.67%
Greg Kroah-Hartman60.63%23.33%
Rick Lindsley50.52%11.67%
Thomas Gleixner40.42%23.33%
Heiko Carstens40.42%11.67%
Robert Love40.42%11.67%
David P. Quigley40.42%11.67%
Paul Jackson30.31%11.67%
Steven Rostedt30.31%11.67%
Rusty Russell30.31%23.33%
Arjan van de Ven20.21%11.67%
Luca Abeni20.21%11.67%
Con Kolivas20.21%11.67%
Motohiro Kosaki20.21%11.67%
Oleg Nesterov20.21%23.33%
Andi Kleen20.21%11.67%
Mike Galbraith10.10%11.67%
David Howells10.10%11.67%
Yong Zhang10.10%11.67%
Nico Pitre10.10%11.67%
Christian Ehrhardt10.10%11.67%
Jens Axboe10.10%11.67%
Olivier Croquette10.10%11.67%
Total956100.00%60100.00%


static int _sched_setscheduler(struct task_struct *p, int policy, const struct sched_param *param, bool check) { struct sched_attr attr = { .sched_policy = policy, .sched_priority = param->sched_priority, .sched_nice = PRIO_TO_NICE(p->static_prio), }; /* Fixup the legacy SCHED_RESET_ON_FORK hack. */ if ((policy != SETPARAM_POLICY) && (policy & SCHED_RESET_ON_FORK)) { attr.sched_flags |= SCHED_FLAG_RESET_ON_FORK; policy &= ~SCHED_RESET_ON_FORK; attr.sched_policy = policy; } return __sched_setscheduler(p, &attr, check, true); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra8283.67%220.00%
Dario Faggioli77.14%220.00%
Linus Torvalds (pre-git)66.12%330.00%
Richard Weinberger11.02%110.00%
Mike Galbraith11.02%110.00%
Ingo Molnar11.02%110.00%
Total98100.00%10100.00%

/** * sched_setscheduler - change the scheduling policy and/or RT priority of a thread. * @p: the task in question. * @policy: new policy. * @param: structure containing the new RT priority. * * Return: 0 on success. An error code otherwise. * * NOTE that the task may be already dead. */
int sched_setscheduler(struct task_struct *p, int policy, const struct sched_param *param) { return _sched_setscheduler(p, policy, param, true); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra2167.74%116.67%
Anton Blanchard39.68%116.67%
Dario Faggioli39.68%116.67%
Ingo Molnar26.45%116.67%
Andrew Morton13.23%116.67%
Matt Mackall13.23%116.67%
Total31100.00%6100.00%

EXPORT_SYMBOL_GPL(sched_setscheduler);
int sched_setattr(struct task_struct *p, const struct sched_attr *attr) { return __sched_setscheduler(p, attr, true, true); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra2071.43%240.00%
Dario Faggioli517.86%120.00%
Dean Nelson27.14%120.00%
Anton Blanchard13.57%120.00%
Total28100.00%5100.00%

EXPORT_SYMBOL_GPL(sched_setattr); /** * sched_setscheduler_nocheck - change the scheduling policy and/or RT priority of a thread from kernelspace. * @p: the task in question. * @policy: new policy. * @param: structure containing the new RT priority. * * Just like sched_setscheduler, only don't bother checking if the * current context has permission. For example, this is needed in * stop_machine(): we create temporary high priority worker threads, * but our caller might not have that capability. * * Return: 0 on success. An error code otherwise. */
int sched_setscheduler_nocheck(struct task_struct *p, int policy, const struct sched_param *param) { return _sched_setscheduler(p, policy, param, false); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra2787.10%233.33%
Jens Axboe13.23%116.67%
Greg Kroah-Hartman13.23%116.67%
Andrew Morton13.23%116.67%
Dario Faggioli13.23%116.67%
Total31100.00%6100.00%

EXPORT_SYMBOL_GPL(sched_setscheduler_nocheck);
static int do_sched_setscheduler(pid_t pid, int policy, struct sched_param __user *param) { struct sched_param lparam; struct task_struct *p; int retval; if (!param || pid < 0) return -EINVAL; if (copy_from_user(&lparam, param, sizeof(struct sched_param))) return -EFAULT; rcu_read_lock(); retval = -ESRCH; p = find_process_by_pid(pid); if (p != NULL) retval = sched_setscheduler(p, policy, &lparam); rcu_read_unlock(); return retval; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra4847.06%16.25%
Dario Faggioli2928.43%16.25%
Greg Kroah-Hartman65.88%212.50%
Anton Blanchard43.92%16.25%
Andrew Morton43.92%212.50%
Rusty Russell21.96%16.25%
Rick Lindsley21.96%16.25%
Eric Paris10.98%16.25%
Eric W. Biedermann10.98%16.25%
Linus Torvalds (pre-git)10.98%16.25%
Christian Bornträger10.98%16.25%
David Howells10.98%16.25%
Mike Galbraith10.98%16.25%
Thomas Gleixner10.98%16.25%
Total102100.00%16100.00%

/* * Mimics kernel/events/core.c perf_copy_attr(). */
static int sched_copy_attr(struct sched_attr __user *uattr, struct sched_attr *attr) { u32 size; int ret; if (!access_ok(VERIFY_WRITE, uattr, SCHED_ATTR_SIZE_VER0)) return -EFAULT; /* Zero the full structure, so that a short copy will be nice: */ memset(attr, 0, sizeof(*attr)); ret = get_user(size, &uattr->size); if (ret) return ret; /* Bail out on silly large: */ if (size > PAGE_SIZE) goto err_size; /* ABI compatibility quirk: */ if (!size) size = SCHED_ATTR_SIZE_VER0; if (size < SCHED_ATTR_SIZE_VER0) goto err_size; /* * If we're handed a bigger struct than we know of, * ensure all the unknown bits are 0 - i.e. new * user-space does not rely on any kernel feature * extensions we dont know about yet. */ if (size > sizeof(*attr)) { unsigned char __user *addr; unsigned char __user *end; unsigned char val; addr = (void __user *)uattr + sizeof(*attr); end = (void __user *)uattr + size; for (; addr < end; addr++) { ret = get_user(val, addr); if (ret) return ret; if (val) goto err_size; } size = sizeof(*attr); } ret = copy_from_user(attr, uattr, size); if (ret) return -EFAULT; /* * XXX: Do we want to be lenient like existing syscalls; or do we want * to be strict and return an error on out-of-bounds values? */ attr->sched_nice = clamp(attr->sched_nice, MIN_NICE, MAX_NICE); return 0; err_size: put_user(sizeof(*attr), &uattr->size); return -E2BIG; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra12046.69%417.39%
Dario Faggioli8934.63%14.35%
Ingo Molnar103.89%313.04%
Mike Galbraith83.11%14.35%
Linus Torvalds (pre-git)72.72%417.39%
Andi Kleen62.33%14.35%
Rusty Russell51.95%28.70%
Andrew Morton41.56%28.70%
Michael Kerrisk31.17%14.35%
Anton Blanchard20.78%14.35%
Thomas Gleixner10.39%14.35%
Robert Love10.39%14.35%
Vegard Nossum10.39%14.35%
Total257100.00%23100.00%

/** * sys_sched_setscheduler - set/change the scheduler policy and RT priority * @pid: the pid in question. * @policy: new policy. * @param: structure containing the new RT priority. * * Return: 0 on success. An error code otherwise. */ SYSCALL_DEFINE3(sched_setscheduler, pid_t, pid, int, policy, struct sched_param __user *, param) { if (policy < 0) return -EINVAL; return do_sched_setscheduler(pid, policy, param); } /** * sys_sched_setparam - set/change the RT priority of a thread * @pid: the pid in question. * @param: structure containing the new RT priority. * * Return: 0 on success. An error code otherwise. */ SYSCALL_DEFINE2(sched_setparam, pid_t, pid, struct sched_param __user *, param) { return do_sched_setscheduler(pid, SETPARAM_POLICY, param); } /** * sys_sched_setattr - same as above, but with extended sched_attr * @pid: the pid in question. * @uattr: structure containing the extended parameters. * @flags: for future extension. */ SYSCALL_DEFINE3(sched_setattr, pid_t, pid, struct sched_attr __user *, uattr, unsigned int, flags) { struct sched_attr attr; struct task_struct *p; int retval; if (!uattr || pid < 0 || flags) return -EINVAL; retval = sched_copy_attr(uattr, &attr); if (retval) return retval; if ((int)attr.sched_policy < 0) return -EINVAL; rcu_read_lock(); retval = -ESRCH; p = find_process_by_pid(pid); if (p != NULL) retval = sched_setattr(p, &attr); rcu_read_unlock(); return retval; } /** * sys_sched_getscheduler - get the policy (scheduling class) of a thread * @pid: the pid in question. * * Return: On success, the policy of the thread. Otherwise, a negative error * code. */ SYSCALL_DEFINE1(sched_getscheduler, pid_t, pid) { struct task_struct *p; int retval; if (pid < 0) return -EINVAL; retval = -ESRCH; rcu_read_lock(); p = find_process_by_pid(pid); if (p) { retval = security_task_getscheduler(p); if (!retval) retval = p->policy | (p->sched_reset_on_fork ? SCHED_RESET_ON_FORK : 0); } rcu_read_unlock(); return retval; } /** * sys_sched_getparam - get the RT priority of a thread * @pid: the pid in question. * @param: structure containing the RT priority. * * Return: On success, 0 and the RT priority is in @param. Otherwise, an error * code. */ SYSCALL_DEFINE2(sched_getparam, pid_t, pid, struct sched_param __user *, param) { struct sched_param lp = { .sched_priority = 0 }; struct task_struct *p; int retval; if (!param || pid < 0) return -EINVAL; rcu_read_lock(); p = find_process_by_pid(pid); retval = -ESRCH; if (!p) goto out_unlock; retval = security_task_getscheduler(p); if (retval) goto out_unlock; if (task_has_rt_policy(p)) lp.sched_priority = p->rt_priority; rcu_read_unlock(); /* * This one might sleep, we cannot do it with a spinlock held ... */ retval = copy_to_user(param, &lp, sizeof(*param)) ? -EFAULT : 0; return retval; out_unlock: rcu_read_unlock(); return retval; }
static int sched_read_attr(struct sched_attr __user *uattr, struct sched_attr *attr, unsigned int usize) { int ret; if (!access_ok(VERIFY_WRITE, uattr, usize)) return -EFAULT; /* * If we're handed a smaller struct than we know of, * ensure all the unknown bits are 0 - i.e. old * user-space does not get uncomplete information. */ if (usize < sizeof(*attr)) { unsigned char *addr; unsigned char *end; addr = (void *)attr + usize; end = (void *)attr + sizeof(*attr); for (; addr < end; addr++) { if (*addr) return -EFBIG; } attr->size = usize; } ret = copy_to_user(uattr, attr, attr->size); if (ret) return -EFAULT; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra9971.74%111.11%
Dario Faggioli2618.84%111.11%
Christian Ehrhardt32.17%111.11%
Nicholas Piggin32.17%111.11%
Robert Love32.17%111.11%
Linus Torvalds (pre-git)10.72%111.11%
Thomas Gleixner10.72%111.11%
Heiko Carstens10.72%111.11%
Ingo Molnar10.72%111.11%
Total138100.00%9100.00%

/** * sys_sched_getattr - similar to sched_getparam, but with sched_attr * @pid: the pid in question. * @uattr: structure containing the extended parameters. * @size: sizeof(attr) for fwd/bwd comp. * @flags: for future extension. */ SYSCALL_DEFINE4(sched_getattr, pid_t, pid, struct sched_attr __user *, uattr, unsigned int, size, unsigned int, flags) { struct sched_attr attr = { .size = sizeof(struct sched_attr), }; struct task_struct *p; int retval; if (!uattr || pid < 0 || size > PAGE_SIZE || size < SCHED_ATTR_SIZE_VER0 || flags) return -EINVAL; rcu_read_lock(); p = find_process_by_pid(pid); retval = -ESRCH; if (!p) goto out_unlock; retval = security_task_getscheduler(p); if (retval) goto out_unlock; attr.sched_policy = p->policy; if (p->sched_reset_on_fork) attr.sched_flags |= SCHED_FLAG_RESET_ON_FORK; if (task_has_dl_policy(p)) __getparam_dl(p, &attr); else if (task_has_rt_policy(p)) attr.sched_priority = p->rt_priority; else attr.sched_nice = task_nice(p); rcu_read_unlock(); retval = sched_read_attr(uattr, &attr, size); return retval; out_unlock: rcu_read_unlock(); return retval; }
long sched_setaffinity(pid_t pid, const struct cpumask *in_mask) { cpumask_var_t cpus_allowed, new_mask; struct task_struct *p; int retval; rcu_read_lock(); p = find_process_by_pid(pid); if (!p) { rcu_read_unlock(); return -ESRCH; } /* Prevent p going away */ get_task_struct(p); rcu_read_unlock(); if (p->flags & PF_NO_SETAFFINITY) { retval = -EINVAL; goto out_put_task; } if (!alloc_cpumask_var(&cpus_allowed, GFP_KERNEL)) { retval = -ENOMEM; goto out_put_task; } if (!alloc_cpumask_var(&new_mask, GFP_KERNEL)) { retval = -ENOMEM; goto out_free_cpus_allowed; } retval = -EPERM; if (!check_same_owner(p)) { rcu_read_lock(); if (!ns_capable(__task_cred(p)->user_ns, CAP_SYS_NICE)) { rcu_read_unlock(); goto out_free_new_mask; } rcu_read_unlock(); } retval = security_task_setscheduler(p); if (retval) goto out_free_new_mask; cpuset_cpus_allowed(p, cpus_allowed); cpumask_and(new_mask, in_mask, cpus_allowed); /* * Since bandwidth control happens on root_domain basis, * if admission test is enabled, we only admit -deadline * tasks allowed to run on all the CPUs in the task's * root_domain. */ #ifdef CONFIG_SMP if (task_has_dl_policy(p) && dl_bandwidth_enabled()) { rcu_read_lock(); if (!cpumask_subset(task_rq(p)->rd->span, new_mask)) { retval = -EBUSY; rcu_read_unlock(); goto out_free_new_mask; } rcu_read_unlock(); } #endif again: retval = __set_cpus_allowed_ptr(p, new_mask, true); if (!retval) { cpuset_cpus_allowed(p, cpus_allowed); if (!cpumask_subset(new_mask, cpus_allowed)) { /* * We must have raced with a concurrent cpuset * update. Just reset the cpus_allowed to the * cpuset's cpus_allowed */ cpumask_copy(new_mask, cpus_allowed); goto again; } } out_free_new_mask: free_cpumask_var(new_mask); out_free_cpus_allowed: free_cpumask_var(cpus_allowed); out_put_task: put_task_struct(p); return retval; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra19761.18%513.89%
Dario Faggioli7422.98%12.78%
Andrew Morton103.11%616.67%
Mike Galbraith82.48%25.56%
Linus Torvalds61.86%25.56%
Linus Torvalds (pre-git)51.55%411.11%
Dean Nelson30.93%12.78%
Ingo Molnar30.93%38.33%
Anton Blanchard20.62%12.78%
Thomas Gleixner20.62%25.56%
Con Kolivas20.62%12.78%
Rick Lindsley20.62%12.78%
Mel Gorman20.62%12.78%
Jens Axboe10.31%12.78%
Oleg Nesterov10.31%12.78%
David P. Quigley10.31%12.78%
Heiko Carstens10.31%12.78%
Paul E. McKenney10.31%12.78%
Robert Love10.31%12.78%
Total322100.00%36100.00%


static int get_user_cpu_mask(unsigned long __user *user_mask_ptr, unsigned len, struct cpumask *new_mask) { if (len < cpumask_size()) cpumask_clear(new_mask); else if (len > cpumask_size()) len = cpumask_size(); return copy_from_user(new_mask, user_mask_ptr, len) ? -EFAULT : 0; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra3660.00%110.00%
Dario Faggioli711.67%110.00%
Kirill Tkhai58.33%110.00%
Mike Galbraith46.67%110.00%
Juri Lelli35.00%220.00%
Linus Torvalds (pre-git)35.00%220.00%
Oleg Nesterov11.67%110.00%
Andrew Morton11.67%110.00%
Total60100.00%10100.00%

/** * sys_sched_setaffinity - set the CPU affinity of a process * @pid: pid of the process * @len: length in bytes of the bitmask pointed to by user_mask_ptr * @user_mask_ptr: user-space pointer to the new CPU mask * * Return: 0 on success. An error code otherwise. */ SYSCALL_DEFINE3(sched_setaffinity, pid_t, pid, unsigned int, len, unsigned long __user *, user_mask_ptr) { cpumask_var_t new_mask; int retval; if (!alloc_cpumask_var(&new_mask, GFP_KERNEL)) return -ENOMEM; retval = get_user_cpu_mask(user_mask_ptr, len, new_mask); if (retval == 0) retval = sched_setaffinity(pid, new_mask); free_cpumask_var(new_mask); return retval; }
long sched_getaffinity(pid_t pid, struct cpumask *mask) { struct task_struct *p; unsigned long flags; int retval; rcu_read_lock(); retval = -ESRCH; p = find_process_by_pid(pid); if (!p) goto out_unlock; retval = security_task_getscheduler(p); if (retval) goto out_unlock; raw_spin_lock_irqsave(&p->pi_lock, flags); cpumask_and(mask, &p->cpus_allowed, cpu_active_mask); raw_spin_unlock_irqrestore(&p->pi_lock, flags); out_unlock: rcu_read_unlock(); return retval; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra4948.04%18.33%
Dario Faggioli2524.51%18.33%
Juri Lelli1413.73%325.00%
Linus Torvalds (pre-git)54.90%325.00%
Mike Galbraith54.90%18.33%
Ingo Molnar21.96%18.33%
Kirill Tkhai10.98%18.33%
Neil Brown10.98%18.33%
Total102100.00%12100.00%

/** * sys_sched_getaffinity - get the CPU affinity of a process * @pid: pid of the process * @len: length in bytes of the bitmask pointed to by user_mask_ptr * @user_mask_ptr: user-space pointer to hold the current CPU mask * * Return: size of CPU mask copied to user_mask_ptr on success. An * error code otherwise. */ SYSCALL_DEFINE3(sched_getaffinity, pid_t, pid, unsigned int, len, unsigned long __user *, user_mask_ptr) { int ret; cpumask_var_t mask; if ((len * BITS_PER_BYTE) < nr_cpu_ids) return -EINVAL; if (len & (sizeof(unsigned long)-1)) return -EINVAL; if (!alloc_cpumask_var(&mask, GFP_KERNEL)) return -ENOMEM; ret = sched_getaffinity(pid, mask); if (ret == 0) { size_t retlen = min_t(size_t, len, cpumask_size()); if (copy_to_user(user_mask_ptr, mask, retlen)) ret = -EFAULT; else ret = retlen; } free_cpumask_var(mask); return ret; } /** * sys_sched_yield - yield the current processor to other threads. * * This function yields the current CPU to other tasks. If there are no * other threads running on this CPU then this function will return. * * Return: 0. */ SYSCALL_DEFINE0(sched_yield) { struct rq_flags rf; struct rq *rq; local_irq_disable(); rq = this_rq(); rq_lock(rq, &rf); schedstat_inc(rq->yld_count); current->sched_class->yield_task(rq); /* * Since we are going to call schedule() anyway, there's * no need to preempt or enable interrupts: */ preempt_disable(); rq_unlock(rq, &rf); sched_preempt_enable_no_resched(); schedule(); return 0; } #ifndef CONFIG_PREEMPT
int __sched _cond_resched(void) { if (should_resched(0)) { preempt_schedule_common(); return 1; } rcu_all_qs(); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra1344.83%120.00%
Dario Faggioli931.03%120.00%
Konstantin Khlebnikov310.34%120.00%
Paul E. McKenney310.34%120.00%
Andrew Morton13.45%120.00%
Total29100.00%5100.00%

EXPORT_SYMBOL(_cond_resched); #endif /* * __cond_resched_lock() - if a reschedule is pending, drop the given lock, * call schedule, and on return reacquire the lock. * * This works OK both with and without CONFIG_PREEMPT. We do strange low-level * operations here to prevent schedule() from being called twice (once via * spin_unlock(), once by hand). */
int __cond_resched_lock(spinlock_t *lock) { int resched = should_resched(PREEMPT_LOCK_OFFSET); int ret = 0; lockdep_assert_held(lock); if (spin_needbreak(lock) || resched) { spin_unlock(lock); if (resched) preempt_schedule_common(); else cpu_relax(); ret = 1; spin_lock(lock); } return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra4060.61%228.57%
Dario Faggioli1116.67%114.29%
Kirill Tkhai1015.15%114.29%
Mark Rutland34.55%114.29%
Konstantin Khlebnikov11.52%114.29%
Rik Van Riel11.52%114.29%
Total66100.00%7100.00%

EXPORT_SYMBOL(__cond_resched_lock);
int __sched __cond_resched_softirq(void) { BUG_ON(!in_softirq()); if (should_resched(SOFTIRQ_DISABLE_OFFSET)) { local_bh_enable(); preempt_schedule_common(); local_bh_disable(); return 1; } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra3076.92%116.67%
Kirill Tkhai512.82%116.67%
Dario Faggioli12.56%116.67%
Andrew Morton12.56%116.67%
Rick Lindsley12.56%116.67%
Konstantin Khlebnikov12.56%116.67%
Total39100.00%6100.00%

EXPORT_SYMBOL(__cond_resched_softirq); /** * yield - yield the current processor to other threads. * * Do not ever use this function, there's a 99% chance you're doing it wrong. * * The scheduler is at all times free to pick the calling task as the most * eligible task to run, if removing the yield() call from your code breaks * it, its already broken. * * Typical broken usage is: * * while (!event) * yield(); * * where one assumes that yield() will let 'the other' process run that will * make event true. If the current task is a SCHED_FIFO task that will never * happen. Never use yield() as a progress guarantee!! * * If you want to use yield() to wait for something, use wait_event(). * If you want to use yield() to be 'nice' for others, use cond_resched(). * If you still want to use yield(), do not! */
void __sched yield(void) { set_current_state(TASK_RUNNING); sys_sched_yield(); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra1062.50%133.33%
Dario Faggioli318.75%133.33%
Rick Lindsley318.75%133.33%
Total16100.00%3100.00%

EXPORT_SYMBOL(yield); /** * yield_to - yield the current processor to another thread in * your thread group, or accelerate that thread toward the * processor it's on. * @p: target task * @preempt: whether task preemption is allowed or not * * It's the caller's job to ensure that the target task struct * can't go away on us before we can do any checks. * * Return: * true (>0) if we indeed boosted the target task. * false (0) if we failed to boost the target. * -ESRCH if there's no task to yield to. */
int __sched yield_to(struct task_struct *p, bool preempt) { struct task_struct *curr = current; struct rq *rq, *p_rq; unsigned long flags; int yielded = 0; local_irq_save(flags); rq = this_rq(); again: p_rq = task_rq(p); /* * If we're the only runnable task on the rq and target rq also * has only one task, there's absolutely no point in yielding. */ if (rq->nr_running == 1 && p_rq->nr_running == 1) { yielded = -ESRCH; goto out_irq; } double_rq_lock(rq, p_rq); if (task_rq(p) != p_rq) { double_rq_unlock(rq, p_rq); goto again; } if (!curr->sched_class->yield_to_task) goto out_unlock; if (curr->sched_class != p->sched_class) goto out_unlock; if (task_running(p_rq, p) || p->state) goto out_unlock; yielded = curr->sched_class->yield_to_task(rq, p, preempt); if (yielded) { schedstat_inc(rq->yld_count); /* * Make p's CPU reschedule; pick_next_entity takes care of * fairness. */ if (preempt && rq != p_rq) resched_curr(p_rq); } out_unlock: double_rq_unlock(rq, p_rq); out_irq: local_irq_restore(flags); if (yielded > 0) schedule(); return yielded; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra15369.23%311.54%
Dario Faggioli2812.67%13.85%
Kirill Tkhai62.71%27.69%
Nicholas Piggin62.71%27.69%
Motohiro Kosaki31.36%13.85%
Milton D. Miller II31.36%13.85%
Andrew Morton31.36%27.69%
Robert Love31.36%13.85%
Gregory Haskins31.36%13.85%
Tetsuo Handa20.90%13.85%
Heiko Carstens20.90%27.69%
Ingo Molnar20.90%27.69%
David Howells10.45%13.85%
Oleg Nesterov10.45%13.85%
Linus Torvalds (pre-git)10.45%13.85%
David P. Quigley10.45%13.85%
Thomas Gleixner10.45%13.85%
Mike Galbraith10.45%13.85%
Josh Poimboeuf10.45%13.85%
Total221100.00%26100.00%

EXPORT_SYMBOL_GPL(yield_to);
int io_schedule_prepare(void) { int old_iowait = current->in_iowait; current->in_iowait = 1; blk_schedule_flush_plug(current); return old_iowait; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra1553.57%114.29%
Tejun Heo725.00%114.29%
Nicholas Piggin27.14%114.29%
Gregory Haskins13.57%114.29%
Thomas Gleixner13.57%114.29%
Andrew Morton13.57%114.29%
Dario Faggioli13.57%114.29%
Total28100.00%7100.00%


void io_schedule_finish(int token) { current->in_iowait = token; }

Contributors

PersonTokensPropCommitsCommitProp
Tejun Heo14100.00%1100.00%
Total14100.00%1100.00%

/* * This task is about to go to sleep on IO. Increment rq->nr_iowait so * that process accounting knows that this is a task in IO wait state. */
long __sched io_schedule_timeout(long timeout) { int token; long ret; token = io_schedule_prepare(); ret = schedule_timeout(timeout); io_schedule_finish(token); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Tejun Heo2365.71%120.00%
Peter Zijlstra822.86%120.00%
Dario Faggioli25.71%120.00%
Linus Torvalds (pre-git)12.86%120.00%
Milton D. Miller II12.86%120.00%
Total35100.00%5100.00%

EXPORT_SYMBOL(io_schedule_timeout);
void io_schedule(void) { int token; token = io_schedule_prepare(); schedule(); io_schedule_finish(token); }

Contributors

PersonTokensPropCommitsCommitProp
Tejun Heo23100.00%1100.00%
Total23100.00%1100.00%

EXPORT_SYMBOL(io_schedule); /** * sys_sched_get_priority_max - return maximum RT priority. * @policy: scheduling class. * * Return: On success, this syscall returns the maximum * rt_priority that can be used by a given scheduling class. * On failure, a negative error code is returned. */ SYSCALL_DEFINE1(sched_get_priority_max, int, policy) { int ret = -EINVAL; switch (policy) { case SCHED_FIFO: case SCHED_RR: ret = MAX_USER_RT_PRIO-1; break; case SCHED_DEADLINE: case SCHED_NORMAL: case SCHED_BATCH: case SCHED_IDLE: ret = 0; break; } return ret; } /** * sys_sched_get_priority_min - return minimum RT priority. * @policy: scheduling class. * * Return: On success, this syscall returns the minimum * rt_priority that can be used by a given scheduling class. * On failure, a negative error code is returned. */ SYSCALL_DEFINE1(sched_get_priority_min, int, policy) { int ret = -EINVAL; switch (policy) { case SCHED_FIFO: case SCHED_RR: ret = 1; break; case SCHED_DEADLINE: case SCHED_NORMAL: case SCHED_BATCH: case SCHED_IDLE: ret = 0; } return ret; }
static int sched_rr_get_interval(pid_t pid, struct timespec64 *t) { struct task_struct *p; unsigned int time_slice; struct rq_flags rf; struct rq *rq; int retval; if (pid < 0) return -EINVAL; retval = -ESRCH; rcu_read_lock(); p = find_process_by_pid(pid); if (!p) goto out_unlock; retval = security_task_getscheduler(p); if (retval) goto out_unlock; rq = task_rq_lock(p, &rf); time_slice = 0; if (p->sched_class->get_rr_interval) time_slice = p->sched_class->get_rr_interval(rq, p); task_rq_unlock(rq, p, &rf); rcu_read_unlock(); jiffies_to_timespec64(time_slice, t); return 0; out_unlock: rcu_read_unlock(); return retval; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra8054.05%327.27%
Dario Faggioli3020.27%19.09%
Al Viro2416.22%19.09%
Mel Gorman74.73%218.18%
Nicholas Piggin32.03%19.09%
Thomas Gleixner21.35%19.09%
Heiko Carstens10.68%19.09%
Ingo Molnar10.68%19.09%
Total148100.00%11100.00%

/** * sys_sched_rr_get_interval - return the default timeslice of a process. * @pid: pid of the process. * @interval: userspace pointer to the timeslice value. * * this syscall writes the default timeslice value of a given process * into the user-space timespec buffer. A value of '0' means infinity. * * Return: On success, 0 and the timeslice is in @interval. Otherwise, * an error code. */ SYSCALL_DEFINE2(sched_rr_get_interval, pid_t, pid, struct timespec __user *, interval) { struct timespec64 t; int retval = sched_rr_get_interval(pid, &t); if (retval == 0) retval = put_timespec64(&t, interval); return retval; } #ifdef CONFIG_COMPAT COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval, compat_pid_t, pid, struct compat_timespec __user *, interval) { struct timespec64 t; int retval = sched_rr_get_interval(pid, &t); if (retval == 0) retval = compat_put_timespec64(&t, interval); return retval; } #endif
void sched_show_task(struct task_struct *p) { unsigned long free = 0; int ppid; if (!try_get_task_stack(p)) return; printk(KERN_INFO "%-15.15s %c", p->comm, task_state_to_char(p)); if (p->state == TASK_RUNNING) printk(KERN_CONT " running task "); #ifdef CONFIG_DEBUG_STACK_USAGE free = stack_not_used(p); #endif ppid = 0; rcu_read_lock(); if (pid_alive(p)) ppid = task_pid_nr(rcu_dereference(p->real_parent)); rcu_read_unlock(); printk(KERN_CONT "%5lu %5d %6d 0x%08lx\n", free, task_pid_nr(p), ppid, (unsigned long)task_thread_info(p)->flags); print_worker_info(KERN_INFO, p); show_stack(p, NULL); put_task_stack(p); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra5236.36%15.88%
Juri Lelli2718.88%317.65%
Dario Faggioli2618.18%15.88%
Tetsuo Handa128.39%15.88%
Nicholas Piggin74.90%15.88%
Xie XiuQi42.80%15.88%
Mike Galbraith32.10%15.88%
Linus Torvalds (pre-git)32.10%211.76%
Greg Kroah-Hartman32.10%15.88%
Rusty Russell21.40%15.88%
Joe Perches10.70%15.88%
Thomas Gleixner10.70%15.88%
Milton D. Miller II10.70%15.88%
Kirill Tkhai10.70%15.88%
Total143100.00%17100.00%

EXPORT_SYMBOL_GPL(sched_show_task);
static inline bool state_filter_match(unsigned long state_filter, struct task_struct *p) { /* no filter, everything matches */ if (!state_filter) return true; /* filter, but doesn't match */ if (!(p->state & state_filter)) return false; /* * When looking for TASK_UNINTERRUPTIBLE skip TASK_IDLE (allows * TASK_KILLABLE). */ if (state_filter == TASK_UNINTERRUPTIBLE && p->state == TASK_IDLE) return false; return true; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra59100.00%1100.00%
Total59100.00%1100.00%


void show_state_filter(unsigned long state_filter) { struct task_struct *g, *p; #if BITS_PER_LONG == 32 printk(KERN_INFO " task PC stack pid father\n"); #else printk(KERN_INFO " task PC stack pid father\n"); #endif rcu_read_lock(); for_each_process_thread(g, p) { /* * reset the NMI-timeout, listing all files on a slow * console might take a lot of time: * Also, reset softlockup watchdogs on all CPUs, because * another CPU might be blocked waiting for us to process * an IPI. */ touch_nmi_watchdog(); touch_all_softlockup_watchdogs(); if (state_filter_match(state_filter, p)) sched_show_task(p); } #ifdef CONFIG_SCHED_DEBUG if (!state_filter) sysrq_sched_debug_show(); #endif rcu_read_unlock(); /* * Only show locks if all tasks are dumped: */ if (!state_filter) debug_show_all_locks(); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra5052.63%216.67%
Juri Lelli1212.63%216.67%
Dario Faggioli1212.63%18.33%
Nicholas Piggin55.26%18.33%
Rabin Vincent55.26%18.33%
Andrey Ryabinin44.21%18.33%
Gregory Haskins44.21%216.67%
Andrew Morton22.11%18.33%
Ingo Molnar11.05%18.33%
Total95100.00%12100.00%

/** * init_idle - set up an idle thread for a given CPU * @idle: task in question * @cpu: CPU the idle task belongs to * * NOTE: this function does not set the idle thread's NEED_RESCHED * flag, to make booting more robust. */
void init_idle(struct task_struct *idle, int cpu) { struct rq *rq = cpu_rq(cpu); unsigned long flags; raw_spin_lock_irqsave(&idle->pi_lock, flags); raw_spin_lock(&rq->lock); __sched_fork(0, idle); idle->state = TASK_RUNNING; idle->se.exec_start = sched_clock(); idle->flags |= PF_IDLE; kasan_unpoison_task_stack(idle); #ifdef CONFIG_SMP /* * Its possible that init_idle() gets called multiple times on a task, * in that case do_set_cpus_allowed() will not do the right thing. * * And since this is boot we can forgo the serialization. */ set_cpus_allowed_common(idle, cpumask_of(cpu)); #endif /* * We're having a chicken and egg problem, even though we are * holding rq->lock, the CPU isn't yet set to this CPU so the * lockdep check in task_group() will fail. * * Similar case to sched_fork(). / Alternatively we could * use task_rq_lock() here and obtain the other rq->lock. * * Silence PROVE_RCU */ rcu_read_lock(); __set_task_cpu(idle, cpu); rcu_read_unlock(); rq->curr = rq->idle = idle; idle->on_rq = TASK_ON_RQ_QUEUED; #ifdef CONFIG_SMP idle->on_cpu = 1; #endif raw_spin_unlock(&rq->lock); raw_spin_unlock_irqrestore(&idle->pi_lock, flags); /* Set the preempt count _outside_ the spinlocks! */ init_idle_preempt_count(idle, cpu); /* * The idle tasks have their own, simple scheduling class: */ idle->sched_class = &idle_sched_class; ftrace_graph_init_idle_task(idle, cpu); vtime_init_idle(idle, cpu); #ifdef CONFIG_SMP sprintf(idle->comm, "%s/%d", INIT_TASK_COMM, cpu); #endif }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra9949.25%527.78%
Dario Faggioli2813.93%15.56%
Kirill Tkhai2713.43%15.56%
Wanpeng Li209.95%15.56%
Gregory Haskins125.97%211.11%
Nicholas Piggin52.49%15.56%
Ingo Molnar31.49%211.11%
Linus Torvalds21.00%15.56%
Andrew Morton21.00%15.56%
Milton D. Miller II10.50%15.56%
Rick Lindsley10.50%15.56%
Nathan Lynch10.50%15.56%
Total201100.00%18100.00%

#ifdef CONFIG_SMP
int cpuset_cpumask_can_shrink(const struct cpumask *cur, const struct cpumask *trial) { int ret = 1; if (!cpumask_weight(cur)) return ret; ret = dl_cpuset_cpumask_can_shrink(cur, trial); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra1942.22%436.36%
Dario Faggioli1635.56%19.09%
Nico Pitre36.67%19.09%
Milton D. Miller II24.44%19.09%
Gregory Haskins24.44%19.09%
Kirill Tkhai12.22%19.09%
Ingo Molnar12.22%19.09%
Nicholas Piggin12.22%19.09%
Total45100.00%11100.00%


int task_can_attach(struct task_struct *p, const struct cpumask *cs_cpus_allowed) { int ret = 0; /* * Kthreads which disallow setaffinity shouldn't be moved * to a new cpuset; we don't want to change their CPU * affinity and isolating such threads by their set of * allowed nodes is unnecessary. Thus, cpusets are not * applicable for such threads. This prevents checking for * success of set_cpus_allowed_ptr() on all attached tasks * before cpus_allowed may be changed. */ if (p->flags & PF_NO_SETAFFINITY) { ret = -EINVAL; goto out; } if (dl_task(p) && !cpumask_intersects(task_rq(p)->rd->span, cs_cpus_allowed)) ret = dl_task_can_attach(p, cs_cpus_allowed); out: return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra4255.26%330.00%
Dario Faggioli2330.26%110.00%
Milton D. Miller II56.58%220.00%
Ingo Molnar45.26%330.00%
Nico Pitre22.63%110.00%
Total76100.00%10100.00%

bool sched_smp_initialized __read_mostly; #ifdef CONFIG_NUMA_BALANCING /* Migrate current task p to target_cpu */
int migrate_task_to(struct task_struct *p, int target_cpu) { struct migration_arg arg = { p, target_cpu }; int curr_cpu = task_cpu(p); if (curr_cpu == target_cpu) return 0; if (!cpumask_test_cpu(target_cpu, &p->cpus_allowed)) return -EINVAL; /* TODO: This is not properly updating schedstats */ trace_sched_move_numa(p, curr_cpu, target_cpu); return stop_one_cpu(curr_cpu, migration_cpu_stop, &arg); }

Contributors

PersonTokensPropCommitsCommitProp
Dario Faggioli5671.79%111.11%
Ingo Molnar56.41%222.22%
Mel Gorman45.13%111.11%
Nicholas Piggin45.13%111.11%
Peter Zijlstra45.13%111.11%
Tejun Heo33.85%111.11%
Gregory Haskins11.28%111.11%
Linus Torvalds (pre-git)11.28%111.11%
Total78100.00%9100.00%

/* * Requeue a task on a given node and accurately track the number of NUMA * tasks on the runqueues */
void sched_setnuma(struct task_struct *p, int nid) { bool queued, running; struct rq_flags rf; struct rq *rq; rq = task_rq_lock(p, &rf); queued = task_on_rq_queued(p); running = task_current(rq, p); if (queued) dequeue_task(rq, p, DEQUEUE_SAVE); if (running) put_prev_task(rq, p); p->numa_preferred_nid = nid; if (queued) enqueue_task(rq, p, ENQUEUE_RESTORE | ENQUEUE_NOCLOCK); if (running) set_curr_task(rq, p); task_rq_unlock(rq, p, &rf); }

Contributors

PersonTokensPropCommitsCommitProp
Dario Faggioli5848.74%14.76%
Peter Zijlstra1512.61%419.05%
Nicholas Piggin119.24%29.52%
Alex Shi86.72%14.76%
Vincent Guittot86.72%14.76%
Kirill Tkhai43.36%14.76%
Linus Torvalds (pre-git)32.52%29.52%
Suresh B. Siddha32.52%14.76%
Ingo Molnar21.68%29.52%
Eduard - Gabriel Munteanu21.68%14.76%
Rusty Russell21.68%29.52%
Joe Perches10.84%14.76%
Milton D. Miller II10.84%14.76%
Greg Kroah-Hartman10.84%14.76%
Total119100.00%21100.00%

#endif /* CONFIG_NUMA_BALANCING */ #ifdef CONFIG_HOTPLUG_CPU /* * Ensure that the idle task is using init_mm right before its CPU goes * offline. */
void idle_task_exit(void) { struct mm_struct *mm = current->active_mm; BUG_ON(cpu_online(smp_processor_id())); if (mm != &init_mm) { switch_mm(mm, &init_mm, current); finish_arch_post_lock_switch(); } mmdrop(mm); }

Contributors

PersonTokensPropCommitsCommitProp
Dario Faggioli2955.77%18.33%
Linus Torvalds (pre-git)59.62%18.33%
Andrew Morton59.62%325.00%
Nicholas Piggin47.69%216.67%
Martin Schwidefsky47.69%18.33%
Ingo Molnar35.77%216.67%
Rusty Russell11.92%18.33%
Andrew Lutomirski11.92%18.33%
Total52100.00%12100.00%

/* * Since this CPU is going 'away' for a while, fold any nr_active delta * we might have. Assumes we're called after migrate_tasks() so that the * nr_active count is stable. We need to take the teardown thread which * is calling this into account, so we hand in adjust = 1 to the load * calculation. * * Also see the comment "Global load-average calculations". */
static void calc_load_migrate(struct rq *rq) { long delta = calc_load_fold_active(rq, 1); if (delta) atomic_long_add(delta, &calc_load_tasks); }

Contributors

PersonTokensPropCommitsCommitProp
Dario Faggioli1751.52%111.11%
Andrew Morton721.21%222.22%
Gregory Haskins26.06%111.11%
Nicholas Piggin26.06%111.11%
Thomas Gleixner26.06%111.11%
Linus Torvalds (pre-git)13.03%111.11%
Milton D. Miller II13.03%111.11%
Ingo Molnar13.03%111.11%
Total33100.00%9100.00%


static void put_prev_task_fake(struct rq *rq, struct task_struct *prev) { }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra1280.00%150.00%
Dario Faggioli320.00%150.00%
Total15100.00%2100.00%

static const struct sched_class fake_sched_class = { .put_prev_task = put_prev_task_fake, }; static struct task_struct fake_task = { /* * Avoid pull_{rt,dl}_task() */ .prio = MAX_PRIO + 1, .sched_class = &fake_sched_class, }; /* * Migrate all tasks from the rq, sleeping tasks will be migrated by * try_to_wake_up()->select_task_rq(). * * Called with rq->lock held even though we'er in stop_machine() and * there's no concurrency possible, we hold the required locks anyway * because of lock validation efforts. */
static void migrate_tasks(struct rq *dead_rq, struct rq_flags *rf) { struct rq *rq = dead_rq; struct task_struct *next, *stop = rq->stop; struct rq_flags orf = *rf; int dest_cpu; /* * Fudge the rq selection such that the below task selection loop * doesn't get stuck on the currently eligible stop task. * * We're currently inside stop_machine() and the rq is either stuck * in the stop_machine_cpu_stop() loop, or we're executing this code, * either way we should never end up calling schedule() until we're * done here. */ rq->stop = NULL; /* * put_prev_task() and pick_next_task() sched * class method both need to have an up-to-date * value of rq->clock[_task] */ update_rq_clock(rq); for (;;) { /* * There's this thread running, bail when that's the only * remaining thread: */ if (rq->nr_running == 1) break; /* * pick_next_task() assumes pinned rq->lock: */ next = pick_next_task(rq, &fake_task, rf); BUG_ON(!next); put_prev_task(rq, next); /* * Rules for changing task_struct::cpus_allowed are holding * both pi_lock and rq->lock, such that holding either * stabilizes the mask. * * Drop rq->lock is not quite as disastrous as it usually is * because !cpu_active at this point, which means load-balance * will not interfere. Also, stop-machine. */ rq_unlock(rq, rf); raw_spin_lock(&next->pi_lock); rq_relock(rq, rf); /* * Since we're inside stop-machine, _nothing_ should have * changed the task, WARN if weird stuff happened, because in * that case the above rq->lock drop is a fail too. */ if (WARN_ON(task_rq(next) != rq || !task_on_rq_queued(next))) { raw_spin_unlock(&next->pi_lock); continue; } /* Find suitable destination for @next, with force if needed. */ dest_cpu = select_fallback_rq(dead_rq->cpu, next); rq = __migrate_task(rq, rf, next, dest_cpu); if (rq != dead_rq) { rq_unlock(rq, rf); rq = dead_rq; *rf = orf; rq_relock(rq, rf); } raw_spin_unlock(&next->pi_lock); } rq->stop = stop; }

Contributors

PersonTokensPropCommitsCommitProp
Dario Faggioli7131.70%14.00%
Peter Zijlstra4821.43%520.00%
Wanpeng Li4720.98%14.00%
Gregory Haskins2511.16%416.00%
Andrew Morton135.80%416.00%
Nicholas Piggin73.12%312.00%
Ingo Molnar62.68%312.00%
Matt Fleming41.79%14.00%
Tejun Heo10.45%14.00%
Rusty Russell10.45%14.00%
Linus Torvalds (pre-git)10.45%14.00%
Total224100.00%25100.00%

#endif /* CONFIG_HOTPLUG_CPU */
void set_rq_online(struct rq *rq) { if (!rq->online) { const struct sched_class *class; cpumask_set_cpu(rq->cpu, rq->rd->online); rq->online = 1; for_each_class(class) { if (class->rq_online) class->rq_online(rq); } } }

Contributors

PersonTokensPropCommitsCommitProp
Dario Faggioli4063.49%17.14%
Peter Zijlstra711.11%321.43%
Linus Torvalds (pre-git)46.35%321.43%
Gautham R. Shenoy46.35%17.14%
Andrew Morton23.17%17.14%
Paul E. McKenney23.17%17.14%
Gregory Haskins11.59%17.14%
Ingo Molnar11.59%17.14%
Nicholas Piggin11.59%17.14%
John Hawkes11.59%17.14%
Total63100.00%14100.00%


void set_rq_offline(struct rq *rq) { if (rq->online) { const struct sched_class *class; for_each_class(class) { if (class->rq_offline) class->rq_offline(rq); } cpumask_clear_cpu(rq->cpu, rq->rd->online); rq->online = 0; } }

Contributors

PersonTokensPropCommitsCommitProp
Dario Faggioli4470.97%112.50%
Peter Zijlstra58.06%112.50%
Nathan Lynch58.06%112.50%
Nicholas Piggin46.45%112.50%
John Hawkes11.61%112.50%
Rusty Russell11.61%112.50%
Andrew Morton11.61%112.50%
Ingo Molnar11.61%112.50%
Total62100.00%8100.00%


static void set_cpu_rq_start_time(unsigned int cpu) { struct rq *rq = cpu_rq(cpu); rq->age_stamp = sched_clock_cpu(cpu); }

Contributors

PersonTokensPropCommitsCommitProp
Dario Faggioli1655.17%114.29%
Corey Minyard413.79%114.29%
Thomas Gleixner413.79%228.57%
Ingo Molnar26.90%114.29%
Tejun Heo26.90%114.29%
Peter Zijlstra13.45%114.29%
Total29100.00%7100.00%

/* * used to mark begin/end of suspend/resume: */ static int num_cpus_frozen; /* * Update cpusets according to cpu_active mask. If cpusets are * disabled, cpuset_update_active_cpus() becomes a simple wrapper * around partition_sched_domains(). * * If we come here as part of a suspend/resume, don't touch cpusets because we * want to restore it back to its original state upon resume anyway. */
static void cpuset_cpu_active(void) { if (cpuhp_tasks_frozen) { /* * num_cpus_frozen tracks how many CPUs are involved in suspend * resume sequence. As long as this is not the last online * operation in the resume sequence, just build a single sched * domain, ignoring cpusets. */ partition_sched_domains(1, NULL, NULL); if (--num_cpus_frozen) return; /* * This is the last CPU online operation. So fall through and * restore the original sched domains by considering the * cpuset configurations. */ cpuset_force_rebuild(); } cpuset_update_active_cpus(); }

Contributors

PersonTokensPropCommitsCommitProp
Dario Faggioli1232.43%110.00%
Peter Zijlstra924.32%220.00%
Rusty Russell513.51%110.00%
Thomas Gleixner513.51%330.00%
Dinakar Guniguntala410.81%110.00%
Srivatsa Vaddagiri12.70%110.00%
Rakib Mullick12.70%110.00%
Total37100.00%10100.00%


static int cpuset_cpu_inactive(unsigned int cpu) { if (!cpuhp_tasks_frozen) { if (dl_cpu_busy(cpu)) return -EBUSY; cpuset_update_active_cpus(); } else { num_cpus_frozen++; partition_sched_domains(1, NULL, NULL); } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Gleixner1428.57%320.00%
Dario Faggioli1224.49%16.67%
Juri Lelli1020.41%16.67%
Peter Zijlstra48.16%426.67%
Nicholas Piggin36.12%16.67%
Suresh B. Siddha24.08%16.67%
Rusty Russell12.04%16.67%
Nico Pitre12.04%16.67%
Hidetoshi Seto12.04%16.67%
Rakib Mullick12.04%16.67%
Total49100.00%15100.00%


int sched_cpu_activate(unsigned int cpu) { struct rq *rq = cpu_rq(cpu); struct rq_flags rf; set_cpu_active(cpu, true); if (sched_smp_initialized) { sched_domains_numa_masks_set(cpu); cpuset_cpu_active(); } /* * Put the rq online, if not already. This happens: * * 1) In the early boot process, because we build the real domains * after all CPUs have been brought up. * * 2) At runtime, if cpuset_cpu_active() fails to rebuild the * domains. */ rq_lock_irqsave(rq, &rf); if (rq->rd) { BUG_ON(!cpumask_test_cpu(cpu, rq->rd->span)); set_rq_online(rq); } rq_unlock_irqrestore(rq, &rf); update_max_interval(); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Gleixner8387.37%350.00%
Peter Zijlstra99.47%116.67%
Dario Faggioli22.11%116.67%
Ingo Molnar11.05%116.67%
Total95100.00%6100.00%


int sched_cpu_deactivate(unsigned int cpu) { int ret; set_cpu_active(cpu, false); /* * We've cleared cpu_active_mask, wait for all preempt-disabled and RCU * users of this state to go away such that all new such users will * observe it. * * Do sync before park smpboot threads to take care the rcu boost case. */ synchronize_rcu_mult(call_rcu, call_rcu_sched); if (!sched_smp_initialized) return 0; ret = cpuset_cpu_inactive(cpu); if (ret) { set_cpu_active(cpu, true); return ret; } sched_domains_numa_masks_clear(cpu); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Gleixner5887.88%250.00%
Peter Zijlstra710.61%125.00%
Paul E. McKenney11.52%125.00%
Total66100.00%4100.00%


static void sched_rq_cpu_starting(unsigned int cpu) { struct rq *rq = cpu_rq(cpu); rq->calc_load_update = calc_load_update; update_max_interval(); }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Gleixner29100.00%1100.00%
Total29100.00%1100.00%


int sched_cpu_starting(unsigned int cpu) { set_cpu_rq_start_time(cpu); sched_rq_cpu_starting(cpu); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Gleixner1254.55%240.00%
Dario Faggioli522.73%120.00%
Rusty Russell418.18%120.00%
Srivatsa Vaddagiri14.55%120.00%
Total22100.00%5100.00%

#ifdef CONFIG_HOTPLUG_CPU
int sched_cpu_dying(unsigned int cpu) { struct rq *rq = cpu_rq(cpu); struct rq_flags rf; /* Handle pending wakeups and then migrate everything off */ sched_ttwu_pending(); rq_lock_irqsave(rq, &rf); if (rq->rd) { BUG_ON(!cpumask_test_cpu(cpu, rq->rd->span)); set_rq_offline(rq); } migrate_tasks(rq, &rf); BUG_ON(rq->nr_running != 1); rq_unlock_irqrestore(rq, &rf); calc_load_migrate(rq); update_max_interval(); nohz_balance_exit_idle(cpu); hrtick_clear(rq); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Gleixner6055.05%327.27%
Juri Lelli2321.10%19.09%
Peter Zijlstra1311.93%218.18%
Dario Faggioli54.59%19.09%
Suresh B. Siddha43.67%218.18%
Nicholas Piggin32.75%19.09%
Rusty Russell10.92%19.09%
Total109100.00%11100.00%

#endif #ifdef CONFIG_SCHED_SMT DEFINE_STATIC_KEY_FALSE(sched_smt_present);
static void sched_init_smt(void) { /* * We've enumerated all CPUs and will assume that if any CPU * has SMT siblings, CPU0 will too. */ if (cpumask_weight(cpu_smt_mask(0)) > 1) static_branch_enable(&sched_smt_present); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra27100.00%1100.00%
Total27100.00%1100.00%

#else
static inline void sched_init_smt(void) { }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra8100.00%1100.00%
Total8100.00%1100.00%

#endif
void __init sched_init_smp(void) { sched_init_numa(); /* * There's no userspace yet to cause hotplug operations; hence all the * CPU masks are stable and all blatant races in the below code cannot * happen. */ mutex_lock(&sched_domains_mutex); sched_init_domains(cpu_active_mask); mutex_unlock(&sched_domains_mutex); /* Move init over to a non-isolated CPU */ if (set_cpus_allowed_ptr(current, housekeeping_cpumask(HK_FLAG_DOMAIN)) < 0) BUG(); sched_init_granularity(); init_sched_rt_class(); init_sched_dl_class(); sched_init_smt(); sched_smp_initialized = true; }

Contributors

PersonTokensPropCommitsCommitProp
Dario Faggioli4266.67%19.09%
Thomas Gleixner46.35%19.09%
Peter Zijlstra46.35%218.18%
Frédéric Weisbecker46.35%19.09%
Paul Jackson34.76%19.09%
Rusty Russell23.17%19.09%
Ingo Molnar11.59%19.09%
Heiko Carstens11.59%19.09%
Christoph Lameter11.59%19.09%
Suresh B. Siddha11.59%19.09%
Total63100.00%11100.00%


static int __init migration_init(void) { sched_rq_cpu_starting(smp_processor_id()); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Gleixner1794.44%266.67%
Dario Faggioli15.56%133.33%
Total18100.00%3100.00%

early_initcall(migration_init); #else
void __init sched_init_smp(void) { sched_init_granularity(); }

Contributors

PersonTokensPropCommitsCommitProp
Dario Faggioli11100.00%1100.00%
Total11100.00%1100.00%

#endif /* CONFIG_SMP */
int in_sched_functions(unsigned long addr) { return in_lock_functions(addr) || (addr >= (unsigned long)__sched_text_start && addr < (unsigned long)__sched_text_end); }

Contributors

PersonTokensPropCommitsCommitProp
Dario Faggioli3193.94%133.33%
Peter Zijlstra13.03%133.33%
Paul Jackson13.03%133.33%
Total33100.00%3100.00%

#ifdef CONFIG_CGROUP_SCHED /* * Default task group. * Every task in system belongs to this group at bootup. */ struct task_group root_task_group; LIST_HEAD(task_groups); /* Cacheline aligned slab cache for task_group */ static struct kmem_cache *task_group_cache __read_mostly; #endif DECLARE_PER_CPU(cpumask_var_t, load_balance_mask); DECLARE_PER_CPU(cpumask_var_t, select_idle_mask);
void __init sched_init(void) { int i, j; unsigned long alloc_size = 0, ptr; sched_clock_init(); wait_bit_init(); #ifdef CONFIG_FAIR_GROUP_SCHED alloc_size += 2 * nr_cpu_ids * sizeof(void **); #endif #ifdef CONFIG_RT_GROUP_SCHED alloc_size += 2 * nr_cpu_ids * sizeof(void **); #endif if (alloc_size) { ptr = (unsigned long)kzalloc(alloc_size, GFP_NOWAIT); #ifdef CONFIG_FAIR_GROUP_SCHED root_task_group.se = (struct sched_entity **)ptr; ptr += nr_cpu_ids * sizeof(void **); root_task_group.cfs_rq = (struct cfs_rq **)ptr; ptr += nr_cpu_ids * sizeof(void **); #endif /* CONFIG_FAIR_GROUP_SCHED */ #ifdef CONFIG_RT_GROUP_SCHED root_task_group.rt_se = (struct sched_rt_entity **)ptr; ptr += nr_cpu_ids * sizeof(void **); root_task_group.rt_rq = (struct rt_rq **)ptr; ptr += nr_cpu_ids * sizeof(void **); #endif /* CONFIG_RT_GROUP_SCHED */ } #ifdef CONFIG_CPUMASK_OFFSTACK for_each_possible_cpu(i) { per_cpu(load_balance_mask, i) = (cpumask_var_t)kzalloc_node( cpumask_size(), GFP_KERNEL, cpu_to_node(i)); per_cpu(select_idle_mask, i) = (cpumask_var_t)kzalloc_node( cpumask_size(), GFP_KERNEL, cpu_to_node(i)); } #endif /* CONFIG_CPUMASK_OFFSTACK */ init_rt_bandwidth(&def_rt_bandwidth, global_rt_period(), global_rt_runtime()); init_dl_bandwidth(&def_dl_bandwidth, global_rt_period(), global_rt_runtime()); #ifdef CONFIG_SMP init_defrootdomain(); #endif #ifdef CONFIG_RT_GROUP_SCHED init_rt_bandwidth(&root_task_group.rt_bandwidth, global_rt_period(), global_rt_runtime()); #endif /* CONFIG_RT_GROUP_SCHED */ #ifdef CONFIG_CGROUP_SCHED task_group_cache = KMEM_CACHE(task_group, 0); list_add(&root_task_group.list, &task_groups); INIT_LIST_HEAD(&root_task_group.children); INIT_LIST_HEAD(&root_task_group.siblings); autogroup_init(&init_task); #endif /* CONFIG_CGROUP_SCHED */ for_each_possible_cpu(i) { struct rq *rq; rq = cpu_rq(i); raw_spin_lock_init(&rq->lock); rq->nr_running = 0; rq->calc_load_active = 0; rq->calc_load_update = jiffies + LOAD_FREQ; init_cfs_rq(&rq->cfs); init_rt_rq(&rq->rt); init_dl_rq(&rq->dl); #ifdef CONFIG_FAIR_GROUP_SCHED root_task_group.shares = ROOT_TASK_GROUP_LOAD; INIT_LIST_HEAD(&rq->leaf_cfs_rq_list); rq->tmp_alone_branch = &rq->leaf_cfs_rq_list; /* * How much CPU bandwidth does root_task_group get? * * In case of task-groups formed thr' the cgroup filesystem, it * gets 100% of the CPU resources in the system. This overall * system CPU resource is divided among the tasks of * root_task_group and its child task-groups in a fair manner, * based on each entity's (task or task-group's) weight * (se->load.weight). * * In other words, if root_task_group has 10 tasks of weight * 1024) and two child groups A0 and A1 (of weight 1024 each), * then A0's share of the CPU resource is: * * A0's bandwidth = 1024 / (10*1024 + 1024 + 1024) = 8.33% * * We achieve this by letting root_task_group's tasks sit * directly in rq->cfs (i.e root_task_group->se[] = NULL). */ init_cfs_bandwidth(&root_task_group.cfs_bandwidth); init_tg_cfs_entry(&root_task_group, &rq->cfs, NULL, i, NULL); #endif /* CONFIG_FAIR_GROUP_SCHED */ rq->rt.rt_runtime = def_rt_bandwidth.rt_runtime; #ifdef CONFIG_RT_GROUP_SCHED init_tg_rt_entry(&root_task_group, &rq->rt, NULL, i, NULL); #endif for (j = 0; j < CPU_LOAD_IDX_MAX; j++) rq->cpu_load[j] = 0; #ifdef CONFIG_SMP rq->sd = NULL; rq->rd = NULL; rq->cpu_capacity = rq->cpu_capacity_orig = SCHED_CAPACITY_SCALE; rq->balance_callback = NULL; rq->active_balance = 0; rq->next_balance = jiffies; rq->push_cpu = 0; rq->cpu = i; rq->online = 0; rq->idle_stamp = 0; rq->avg_idle = 2*sysctl_sched_migration_cost; rq->max_idle_balance_cost = sysctl_sched_migration_cost; INIT_LIST_HEAD(&rq->cfs_tasks); rq_attach_root(rq, &def_root_domain); #ifdef CONFIG_NO_HZ_COMMON rq->last_load_update_tick = jiffies; rq->nohz_flags = 0; #endif #ifdef CONFIG_NO_HZ_FULL rq->last_sched_tick = 0; #endif #endif /* CONFIG_SMP */ init_rq_hrtick(rq); atomic_set(&rq->nr_iowait, 0); } set_load_weight(&init_task, false); /* * The boot idle thread does lazy MMU switching as well: */ mmgrab(&init_mm); enter_lazy_tlb(&init_mm, current); /* * Make us the idle thread. Technically, schedule() should not be * called from this thread, however somewhere below it might be, * but because we are the idle thread, we just pick up running again * when this runqueue becomes "idle". */ init_idle(current, smp_processor_id()); calc_load_update = jiffies + LOAD_FREQ; #ifdef CONFIG_SMP idle_thread_set_boot_cpu(); set_cpu_rq_start_time(smp_processor_id()); #endif init_sched_fair_class(); init_schedstats(); scheduler_running = 1; }

Contributors

PersonTokensPropCommitsCommitProp
Dario Faggioli50268.96%11.54%
Peter Zijlstra547.42%1523.08%
Mike Travis172.34%11.54%
Vincent Guittot152.06%34.62%
Alex Thorlton121.65%11.54%
Ingo Molnar111.51%57.69%
Suresh B. Siddha111.51%11.54%
Srivatsa S. Bhat101.37%23.08%
Waiman Long91.24%11.54%
Andrew Morton70.96%34.62%
Maksim Krasnyanskiy70.96%34.62%
Rusty Russell70.96%34.62%
Adrian Bunk70.96%11.54%
Frédéric Weisbecker60.82%11.54%
Venkatesh Pallipadi60.82%11.54%
Paul Jackson40.55%11.54%
Gautham R. Shenoy40.55%23.08%
Dhaval Giani40.55%11.54%
Li Zefan40.55%23.08%
Srivatsa Vaddagiri30.41%11.54%
Mike Galbraith30.41%11.54%
Josh Poimboeuf30.41%11.54%
Heiko Carstens30.41%11.54%
Milton D. Miller II30.41%11.54%
William Lee Irwin III20.27%11.54%
Nicholas Piggin20.27%11.54%
Tang Chen20.27%11.54%
Corey Minyard20.27%11.54%
Nico Pitre20.27%23.08%
Thomas Gleixner10.14%11.54%
Vegard Nossum10.14%11.54%
Paul Turner10.14%11.54%
Avi Kivity10.14%11.54%
Linus Torvalds10.14%11.54%
John Hawkes10.14%11.54%
Total728100.00%65100.00%

#ifdef CONFIG_DEBUG_ATOMIC_SLEEP
static inline int preempt_count_equals(int preempt_offset) { int nested = preempt_count() + rcu_preempt_depth(); return (nested == preempt_offset); }

Contributors

PersonTokensPropCommitsCommitProp
Dario Faggioli2492.31%150.00%
Mike Travis27.69%150.00%
Total26100.00%2100.00%


void __might_sleep(const char *file, int line, int preempt_offset) { /* * Blocking primitives will set (and therefore destroy) current->state, * since we will exit with TASK_RUNNING make sure we enter with it, * otherwise we will destroy state. */ WARN_ONCE(current->state != TASK_RUNNING && current->task_state_change, "do not call blocking ops when !TASK_RUNNING; " "state=%lx set at [<%p>] %pS\n", current->state, (void *)current->task_state_change, (void *)current->task_state_change); ___might_sleep(file, line, preempt_offset); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra4064.52%545.45%
Dario Faggioli1320.97%19.09%
Linus Torvalds46.45%19.09%
Srivatsa Vaddagiri23.23%218.18%
Li Zefan23.23%19.09%
Ingo Molnar11.61%19.09%
Total62100.00%11100.00%

EXPORT_SYMBOL(__might_sleep);
void ___might_sleep(const char *file, int line, int preempt_offset) { /* Ratelimiting timestamp: */ static unsigned long prev_jiffy; unsigned long preempt_disable_ip; /* WARN_ON_ONCE() by default, no rate limit required: */ rcu_sleep_check(); if ((preempt_count_equals(preempt_offset) && !irqs_disabled() && !is_idle_task(current)) || system_state == SYSTEM_BOOTING || system_state > SYSTEM_RUNNING || oops_in_progress) return; if (time_before(jiffies, prev_jiffy + HZ) && prev_jiffy) return; prev_jiffy = jiffies; /* Save this before calling printk(), since that will clobber it: */ preempt_disable_ip = get_preempt_disable_ip(current); printk(KERN_ERR "BUG: sleeping function called from invalid context at %s:%d\n", file, line); printk(KERN_ERR "in_atomic(): %d, irqs_disabled(): %d, pid: %d, name: %s\n", in_atomic(), irqs_disabled(), current->pid, current->comm); if (task_stack_end_corrupted(current)) printk(KERN_EMERG "Thread overran stack, or stack corrupted\n"); debug_show_held_locks(current); if (irqs_disabled()) print_irqtrace_events(current); if (IS_ENABLED(CONFIG_DEBUG_PREEMPT) && !preempt_count_equals(preempt_offset)) { pr_err("Preemption disabled at:"); print_ip_sym(preempt_disable_ip); pr_cont("\n"); } dump_stack(); add_taint(TAINT_WARN, LOCKDEP_STILL_OK); }

Contributors

PersonTokensPropCommitsCommitProp
Dario Faggioli7038.04%15.00%
Peter Zijlstra3217.39%630.00%
Thomas Gleixner2614.13%315.00%
Vegard Nossum2111.41%210.00%
Andi Kleen158.15%15.00%
Eric Sandeen73.80%15.00%
Srivatsa Vaddagiri52.72%210.00%
Rusty Russell31.63%15.00%
Ingo Molnar31.63%15.00%
Arnaldo Carvalho de Melo10.54%15.00%
Suresh B. Siddha10.54%15.00%
Total184100.00%20100.00%

EXPORT_SYMBOL(___might_sleep); #endif #ifdef CONFIG_MAGIC_SYSRQ
void normalize_rt_tasks(void) { struct task_struct *g, *p; struct sched_attr attr = { .sched_policy = SCHED_NORMAL, }; read_lock(&tasklist_lock); for_each_process_thread(g, p) { /* * Only normalize user tasks: */ if (p->flags & PF_KTHREAD) continue; p->se.exec_start = 0; schedstat_set(p->se.statistics.wait_start, 0); schedstat_set(p->se.statistics.sleep_start, 0); schedstat_set(p->se.statistics.block_start, 0); if (!dl_task(p) && !rt_task(p)) { /* * Renice negative nice level userspace * tasks back to 0: */ if (task_nice(p) < 0) set_user_nice(p, 0); continue; } __sched_setscheduler(p, &attr, false, false); } read_unlock(&tasklist_lock); }

Contributors

PersonTokensPropCommitsCommitProp
Dario Faggioli9966.44%15.56%
Peter Zijlstra1912.75%738.89%
Oleg Nesterov85.37%211.11%
Josh Poimboeuf64.03%15.56%
Srivatsa Vaddagiri53.36%211.11%
Jason Wessel42.68%15.56%
Ingo Molnar32.01%15.56%
Dmitry Adamushko21.34%15.56%
Linus Torvalds21.34%15.56%
Dongsheng Yang10.67%15.56%
Total149100.00%18100.00%

#endif /* CONFIG_MAGIC_SYSRQ */ #if defined(CONFIG_IA64) || defined(CONFIG_KGDB_KDB) /* * These functions are only useful for the IA64 MCA handling, or kdb. * * They can only be called when the whole system has been * stopped - every CPU needs to be quiescent, and no scheduling * activity can take place. Using them for anything else would * be a serious bug, and as a result, they aren't even visible * under any other configuration. */ /** * curr_task - return the current task for a given CPU. * @cpu: the processor in question. * * ONLY VALID WHEN THE WHOLE SYSTEM IS STOPPED! * * Return: The current task for @cpu. */
struct task_struct *curr_task(int cpu) { return cpu_curr(cpu); }

Contributors

PersonTokensPropCommitsCommitProp
Dario Faggioli850.00%116.67%
Peter Zijlstra743.75%466.67%
Srivatsa Vaddagiri16.25%116.67%
Total16100.00%6100.00%

#endif /* defined(CONFIG_IA64) || defined(CONFIG_KGDB_KDB) */ #ifdef CONFIG_IA64 /** * set_curr_task - set the current task for a given CPU. * @cpu: the processor in question. * @p: the task pointer to set. * * Description: This function must only be used when non-maskable interrupts * are serviced on a separate stack. It allows the architecture to switch the * notion of the current task on a CPU in a non-blocking manner. This function * must be called with all CPU's synchronized, and interrupts disabled, the * and caller must save the original value of the current task (see * curr_task() above) and restore that value before reenabling interrupts and * re-starting the system. * * ONLY VALID WHEN THE WHOLE SYSTEM IS STOPPED! */
void ia64_set_curr_task(int cpu, struct task_struct *p) { cpu_curr(cpu) = p; }

Contributors

PersonTokensPropCommitsCommitProp
Dario Faggioli1365.00%120.00%
Peter Zijlstra630.00%360.00%
Frédéric Weisbecker15.00%120.00%
Total20100.00%5100.00%

#endif #ifdef CONFIG_CGROUP_SCHED /* task_group_lock serializes the addition/removal of task groups */ static DEFINE_SPINLOCK(task_group_lock);
static void sched_free_group(struct task_group *tg) { free_fair_sched_group(tg); free_rt_sched_group(tg); autogroup_free(tg); kmem_cache_free(task_group_cache, tg); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra1442.42%342.86%
Dario Faggioli1339.39%114.29%
Waiman Long39.09%114.29%
Dhaval Giani26.06%114.29%
Srivatsa Vaddagiri13.03%114.29%
Total33100.00%7100.00%

/* allocate runqueue etc for a new task group */
struct task_group *sched_create_group(struct task_group *parent) { struct task_group *tg; tg = kmem_cache_alloc(task_group_cache, GFP_KERNEL | __GFP_ZERO); if (!tg) return ERR_PTR(-ENOMEM); if (!alloc_fair_sched_group(tg, parent)) goto err; if (!alloc_rt_sched_group(tg, parent)) goto err; return tg; err: sched_free_group(tg); return ERR_PTR(-ENOMEM); }

Contributors

PersonTokensPropCommitsCommitProp
Dario Faggioli4959.04%110.00%
Peter Zijlstra2530.12%770.00%
Srivatsa Vaddagiri56.02%110.00%
Waiman Long44.82%110.00%
Total83100.00%10100.00%


void sched_online_group(struct task_group *tg, struct task_group *parent) { unsigned long flags; spin_lock_irqsave(&task_group_lock, flags); list_add_rcu(&tg->list, &task_groups); /* Root should already exist: */ WARN_ON(!parent); tg->parent = parent; INIT_LIST_HEAD(&tg->children); list_add_rcu(&tg->siblings, &parent->children); spin_unlock_irqrestore(&task_group_lock, flags); online_fair_sched_group(tg); }

Contributors

PersonTokensPropCommitsCommitProp
Dario Faggioli6070.59%19.09%
Peter Zijlstra1922.35%654.55%
Mike Galbraith33.53%19.09%
Ingo Molnar22.35%218.18%
Srivatsa Vaddagiri11.18%19.09%
Total85100.00%11100.00%

/* rcu callback to free various structures associated with a task group */
static void sched_free_group_rcu(struct rcu_head *rhp) { /* Now it should be safe to free those cfs_rqs: */ sched_free_group(container_of(rhp, struct task_group, rcu)); }

Contributors

PersonTokensPropCommitsCommitProp
Dario Faggioli1768.00%116.67%
Peter Zijlstra728.00%466.67%
Ingo Molnar14.00%116.67%
Total25100.00%6100.00%


void sched_destroy_group(struct task_group *tg) { /* Wait for possible concurrent references to cfs_rqs complete: */ call_rcu(&tg->rcu, sched_free_group_rcu); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra1152.38%571.43%
Dario Faggioli942.86%114.29%
Ingo Molnar14.76%114.29%
Total21100.00%7100.00%


void sched_offline_group(struct task_group *tg) { unsigned long flags; /* End participation in shares distribution: */ unregister_fair_sched_group(tg); spin_lock_irqsave(&task_group_lock, flags); list_del_rcu(&tg->list); list_del_rcu(&tg->siblings); spin_unlock_irqrestore(&task_group_lock, flags); }

Contributors

PersonTokensPropCommitsCommitProp
Dario Faggioli2751.92%220.00%
Peter Zijlstra1019.23%440.00%
Juri Lelli611.54%110.00%
Srivatsa Vaddagiri47.69%110.00%
Kirill Tkhai47.69%110.00%
Ingo Molnar11.92%110.00%
Total52100.00%10100.00%


static void sched_change_group(struct task_struct *tsk, int type) { struct task_group *tg; /* * All callers are synchronized by task_rq_lock(); we do not use RCU * which is pointless here. Thus, we pass "true" to task_css_check() * to prevent lockdep warnings. */ tg = container_of(task_css_check(tsk, cpu_cgrp_id, true), struct task_group, css); tg = autogroup_task_group(tsk, tg); tsk->sched_task_group = tg; #ifdef CONFIG_FAIR_GROUP_SCHED if (tsk->sched_class->task_change_group) tsk->sched_class->task_change_group(tsk, type); else #endif set_task_rq(tsk, task_cpu(tsk)); }

Contributors

PersonTokensPropCommitsCommitProp
Vincent Guittot5359.55%17.69%
Peter Zijlstra1213.48%538.46%
Dario Faggioli77.87%17.69%
Clark Williams66.74%17.69%
Kirill Tkhai55.62%215.38%
Srivatsa Vaddagiri44.49%215.38%
Juri Lelli22.25%17.69%
Total89100.00%13100.00%

/* * Change task's runqueue when it moves between groups. * * The caller of this function should have put the task in its new group by * now. This function just updates tsk->se.cfs_rq and tsk->se.parent to reflect * its new group. */
void sched_move_task(struct task_struct *tsk) { int queued, running, queue_flags = DEQUEUE_SAVE | DEQUEUE_MOVE | DEQUEUE_NOCLOCK; struct rq_flags rf; struct rq *rq; rq = task_rq_lock(tsk, &rf); update_rq_clock(rq); running = task_current(rq, tsk); queued = task_on_rq_queued(tsk); if (queued) dequeue_task(rq, tsk, queue_flags); if (running) put_prev_task(rq, tsk); sched_change_group(tsk, TASK_MOVE_GROUP); if (queued) enqueue_task(rq, tsk, queue_flags); if (running) set_curr_task(rq, tsk); task_rq_unlock(rq, tsk, &rf); }

Contributors

PersonTokensPropCommitsCommitProp
Dario Faggioli5643.75%17.14%
Peter Zijlstra5139.84%964.29%
Vincent Guittot97.03%214.29%
Srivatsa Vaddagiri64.69%17.14%
Kirill Tkhai64.69%17.14%
Total128100.00%14100.00%


static inline struct task_group *css_tg(struct cgroup_subsys_state *css) { return css ? container_of(css, struct task_group, css) : NULL; }

Contributors

PersonTokensPropCommitsCommitProp
Srivatsa Vaddagiri1965.52%133.33%
Tejun Heo827.59%133.33%
Peter Zijlstra26.90%133.33%
Total29100.00%3100.00%


static struct cgroup_subsys_state * cpu_cgroup_css_alloc(struct cgroup_subsys_state *parent_css) { struct task_group *parent = css_tg(parent_css); struct task_group *tg; if (!parent) { /* This is early initialization for the top cgroup */ return &root_task_group.css; } tg = sched_create_group(parent); if (IS_ERR(tg)) return ERR_PTR(-ENOMEM); return &tg->css; }

Contributors

PersonTokensPropCommitsCommitProp
Srivatsa Vaddagiri3652.17%330.00%
Tejun Heo1318.84%220.00%
Dhaval Giani913.04%220.00%
Konstantin Khlebnikov710.14%110.00%
Peter Zijlstra34.35%110.00%
Yong Zhang11.45%110.00%
Total69100.00%10100.00%

/* Expose task group only after completing cgroup initialization */
static int cpu_cgroup_css_online(struct cgroup_subsys_state *css) { struct task_group *tg = css_tg(css); struct task_group *parent = css_tg(css->parent); if (parent) sched_online_group(tg, parent); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Konstantin Khlebnikov3778.72%150.00%
Li Zefan1021.28%150.00%
Total47100.00%2100.00%


static void cpu_cgroup_css_released(struct cgroup_subsys_state *css) { struct task_group *tg = css_tg(css); sched_offline_group(tg); }

Contributors

PersonTokensPropCommitsCommitProp
Srivatsa Vaddagiri1038.46%116.67%
Peter Zijlstra830.77%350.00%
Paul Turner415.38%116.67%
Tejun Heo415.38%116.67%
Total26100.00%6100.00%


static void cpu_cgroup_css_free(struct cgroup_subsys_state *css) { struct task_group *tg = css_tg(css); /* * Relies on the RCU grace period between css_released() and this. */ sched_free_group(tg); }

Contributors

PersonTokensPropCommitsCommitProp
Li Zefan2074.07%133.33%
Tejun Heo414.81%133.33%
Peter Zijlstra311.11%133.33%
Total27100.00%3100.00%

/* * This is called before wake_up_new_task(), therefore we really only * have to set its group bits, all the other stuff does not apply. */
static void cpu_cgroup_fork(struct task_struct *task) { struct rq_flags rf; struct rq *rq; rq = task_rq_lock(task, &rf); update_rq_clock(rq); sched_change_group(task, TASK_SET_GROUP); task_rq_unlock(rq, task, &rf); }

Contributors

PersonTokensPropCommitsCommitProp
Vincent Guittot3057.69%133.33%
Kirill Tkhai1732.69%133.33%
Peter Zijlstra59.62%133.33%
Total52100.00%3100.00%


static int cpu_cgroup_can_attach(struct cgroup_taskset *tset) { struct task_struct *task; struct cgroup_subsys_state *css; int ret = 0; cgroup_taskset_for_each(task, css, tset) { #ifdef CONFIG_RT_GROUP_SCHED if (!sched_rt_can_attach(css_tg(css), task)) return -EINVAL; #else /* We don't support RT-tasks being in separate groups */ if (task->sched_class != &fair_sched_class) return -EINVAL; #endif /* * Serialize against wake_up_new_task() such that if its * running, we're sure to observe its full state. */ raw_spin_lock_irq(&task->pi_lock); /* * Avoid calling sched_move_task() before wake_up_new_task() * has happened. This would lead to problems with PELT, due to * move wanting to detach+attach while we're not attached yet. */ if (task->state == TASK_NEW) ret = -EINVAL; raw_spin_unlock_irq(&task->pi_lock); if (ret) break; } return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra6153.98%436.36%
Tejun Heo2723.89%327.27%
Srivatsa Vaddagiri2320.35%327.27%
Dhaval Giani21.77%19.09%
Total113100.00%11100.00%


static void cpu_cgroup_attach(struct cgroup_taskset *tset) { struct task_struct *task; struct cgroup_subsys_state *css; cgroup_taskset_for_each(task, css, tset) sched_move_task(task); }

Contributors

PersonTokensPropCommitsCommitProp
Tejun Heo2264.71%250.00%
Srivatsa Vaddagiri720.59%125.00%
Dhaval Giani514.71%125.00%
Total34100.00%4100.00%

#ifdef CONFIG_FAIR_GROUP_SCHED
static int cpu_shares_write_u64(struct cgroup_subsys_state *css, struct cftype *cftype, u64 shareval) { return sched_group_set_shares(css_tg(css), scale_load(shareval)); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra1236.36%228.57%
Srivatsa Vaddagiri1133.33%114.29%
Paul Menage412.12%228.57%
Tejun Heo412.12%114.29%
Nikhil P Rao26.06%114.29%
Total33100.00%7100.00%


static u64 cpu_shares_read_u64(struct cgroup_subsys_state *css, struct cftype *cft) { struct task_group *tg = css_tg(css); return (u64) scale_load_down(tg->shares); }

Contributors

PersonTokensPropCommitsCommitProp
Srivatsa Vaddagiri1643.24%116.67%
Peter Zijlstra1540.54%233.33%
Tejun Heo410.81%116.67%
Paul Menage12.70%116.67%
Nikhil P Rao12.70%116.67%
Total37100.00%6100.00%

#ifdef CONFIG_CFS_BANDWIDTH static DEFINE_MUTEX(cfs_constraints_mutex); const u64 max_cfs_quota_period = 1 * NSEC_PER_SEC; /* 1s */ const u64 min_cfs_quota_period = 1 * NSEC_PER_MSEC; /* 1ms */ static int __cfs_schedulable(struct task_group *tg, u64 period, u64 runtime);
static int tg_set_cfs_bandwidth(struct task_group *tg, u64 period, u64 quota) { int i, ret = 0, runtime_enabled, runtime_was_enabled; struct cfs_bandwidth *cfs_b = &tg->cfs_bandwidth; if (tg == &root_task_group) return -EINVAL; /* * Ensure we have at some amount of bandwidth every period. This is * to prevent reaching a state of large arrears when throttled via * entity_tick() resulting in prolonged exit starvation. */ if (quota < min_cfs_quota_period || period < min_cfs_quota_period) return -EINVAL; /* * Likewise, bound things on the otherside by preventing insane quota * periods. This also allows us to normalize in computing quota * feasibility. */ if (period > max_cfs_quota_period) return -EINVAL; /* * Prevent race between setting of cfs_rq->runtime_enabled and * unthrottle_offline_cfs_rqs(). */ get_online_cpus(); mutex_lock(&cfs_constraints_mutex); ret = __cfs_schedulable(tg, period, quota); if (ret) goto out_unlock; runtime_enabled = quota != RUNTIME_INF; runtime_was_enabled = cfs_b->quota != RUNTIME_INF; /* * If we need to toggle cfs_bandwidth_used, off->on must occur * before making related changes, and on->off must occur afterwards */ if (runtime_enabled && !runtime_was_enabled) cfs_bandwidth_usage_inc(); raw_spin_lock_irq(&cfs_b->lock); cfs_b->period = ns_to_ktime(period); cfs_b->quota = quota; __refill_cfs_bandwidth_runtime(cfs_b); /* Restart the period timer (if active) to handle new period expiry: */ if (runtime_enabled) start_cfs_bandwidth(cfs_b); raw_spin_unlock_irq(&cfs_b->lock); for_each_online_cpu(i) { struct cfs_rq *cfs_rq = tg->cfs_rq[i]; struct rq *rq = cfs_rq->rq; struct rq_flags rf; rq_lock_irq(rq, &rf); cfs_rq->runtime_enabled = runtime_enabled; cfs_rq->runtime_remaining = 0; if (cfs_rq->throttled) unthrottle_cfs_rq(cfs_rq); rq_unlock_irq(rq, &rf); } if (runtime_was_enabled && !runtime_enabled) cfs_bandwidth_usage_dec(); out_unlock: mutex_unlock(&cfs_constraints_mutex); put_online_cpus(); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra12446.27%942.86%
Paul Turner11342.16%733.33%
Ben Segall186.72%14.76%
Kirill Tkhai82.99%14.76%
Dhaval Giani31.12%14.76%
Ingo Molnar10.37%14.76%
Thomas Gleixner10.37%14.76%
Total268100.00%21100.00%


int tg_set_cfs_quota(struct task_group *tg, long cfs_quota_us) { u64 quota, period; period = ktime_to_ns(tg->cfs_bandwidth.period); if (cfs_quota_us < 0) quota = RUNTIME_INF; else quota = (u64)cfs_quota_us * NSEC_PER_USEC; return tg_set_cfs_bandwidth(tg, period, quota); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra3864.41%266.67%
Paul Turner2135.59%133.33%
Total59100.00%3100.00%


long tg_get_cfs_quota(struct task_group *tg) { u64 quota_us; if (tg->cfs_bandwidth.quota == RUNTIME_INF) return -1; quota_us = tg->cfs_bandwidth.quota; do_div(quota_us, NSEC_PER_USEC); return quota_us; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra3884.44%375.00%
Paul Turner715.56%125.00%
Total45100.00%4100.00%


int tg_set_cfs_period(struct task_group *tg, long cfs_period_us) { u64 quota, period; period = (u64)cfs_period_us * NSEC_PER_USEC; quota = tg->cfs_bandwidth.quota; return tg_set_cfs_bandwidth(tg, period, quota); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra3475.56%266.67%
Paul Turner1124.44%133.33%
Total45100.00%3100.00%


long tg_get_cfs_period(struct task_group *tg) { u64 cfs_period_us; cfs_period_us = ktime_to_ns(tg->cfs_bandwidth.period); do_div(cfs_period_us, NSEC_PER_USEC); return cfs_period_us; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra2676.47%250.00%
Paul Turner617.65%125.00%
Dhaval Giani25.88%125.00%
Total34100.00%4100.00%


static s64 cpu_cfs_quota_read_s64(struct cgroup_subsys_state *css, struct cftype *cft) { return tg_get_cfs_quota(css_tg(css)); }

Contributors

PersonTokensPropCommitsCommitProp
Srivatsa Vaddagiri1144.00%125.00%
Paul Turner520.00%125.00%
Peter Zijlstra520.00%125.00%
Tejun Heo416.00%125.00%
Total25100.00%4100.00%


static int cpu_cfs_quota_write_s64(struct cgroup_subsys_state *css, struct cftype *cftype, s64 cfs_quota_us) { return tg_set_cfs_quota(css_tg(css), cfs_quota_us); }

Contributors

PersonTokensPropCommitsCommitProp
Paul Turner1343.33%125.00%
Srivatsa Vaddagiri1136.67%125.00%
Tejun Heo413.33%125.00%
Dhaval Giani26.67%125.00%
Total30100.00%4100.00%


static u64 cpu_cfs_period_read_u64(struct cgroup_subsys_state *css, struct cftype *cft) { return tg_get_cfs_period(css_tg(css)); }

Contributors

PersonTokensPropCommitsCommitProp
Srivatsa Vaddagiri1352.00%133.33%
Paul Turner832.00%133.33%
Tejun Heo416.00%133.33%
Total25100.00%3100.00%


static int cpu_cfs_period_write_u64(struct cgroup_subsys_state *css, struct cftype *cftype, u64 cfs_period_us) { return tg_set_cfs_period(css_tg(css), cfs_period_us); }

Contributors

PersonTokensPropCommitsCommitProp
Srivatsa Vaddagiri1240.00%120.00%
Paul Turner930.00%120.00%
Tejun Heo413.33%120.00%
Peter Zijlstra310.00%120.00%
Dhaval Giani26.67%120.00%
Total30100.00%5100.00%

struct cfs_schedulable_data { struct task_group *tg; u64 period, quota; }; /* * normalize group quota/period to be quota/max_period * note: units are usecs */
static u64 normalize_cfs_quota(struct task_group *tg, struct cfs_schedulable_data *d) { u64 quota, period; if (tg == d->tg) { period = d->period; quota = d->quota; } else { period = tg_get_cfs_period(tg); quota = tg_get_cfs_quota(tg); } /* note: these should typically be equivalent */ if (quota == RUNTIME_INF || quota == -1) return RUNTIME_INF; return to_ratio(period, quota); }

Contributors

PersonTokensPropCommitsCommitProp
Paul Turner7084.34%150.00%
Srivatsa Vaddagiri1315.66%150.00%
Total83100.00%2100.00%


static int tg_cfs_schedulable_down(struct task_group *tg, void *data) { struct cfs_schedulable_data *d = data; struct cfs_bandwidth *cfs_b = &tg->cfs_bandwidth; s64 quota = 0, parent_quota = -1; if (!tg->parent) { quota = RUNTIME_INF; } else { struct cfs_bandwidth *parent_b = &tg->parent->cfs_bandwidth; quota = normalize_cfs_quota(tg, d); parent_quota = parent_b->hierarchical_quota; /* * Ensure max(child_quota) <= parent_quota, inherit when no * limit is set: */ if (quota == RUNTIME_INF) quota = parent_quota; else if (parent_quota != RUNTIME_INF && quota > parent_quota) return -EINVAL; } cfs_b->hierarchical_quota = quota; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Paul Turner9478.33%116.67%
Peter Zijlstra2319.17%350.00%
Zhihui Zhang21.67%116.67%
Ingo Molnar10.83%116.67%
Total120100.00%6100.00%


static int __cfs_schedulable(struct task_group *tg, u64 period, u64 quota) { int ret; struct cfs_schedulable_data data = { .tg = tg, .period = period, .quota = quota, }; if (quota != RUNTIME_INF) { do_div(data.period, NSEC_PER_USEC); do_div(data.quota, NSEC_PER_USEC); } rcu_read_lock(); ret = walk_tg_tree(tg_cfs_schedulable_down, tg_nop, &data); rcu_read_unlock(); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Paul Turner7180.68%240.00%
Srivatsa Vaddagiri1314.77%120.00%
Nikhil P Rao22.27%120.00%
Paul Menage22.27%120.00%
Total88100.00%5100.00%


static int cpu_cfs_stat_show(struct seq_file *sf, void *v) { struct task_group *tg = css_tg(seq_css(sf)); struct cfs_bandwidth *cfs_b = &tg->cfs_bandwidth; seq_printf(sf, "nr_periods %d\n", cfs_b->nr_periods); seq_printf(sf, "nr_throttled %d\n", cfs_b->nr_throttled); seq_printf(sf, "throttled_time %llu\n", cfs_b->throttled_time); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Nikhil P Rao3547.30%225.00%
Tejun Heo1925.68%450.00%
Srivatsa Vaddagiri1722.97%112.50%
Peter Zijlstra34.05%112.50%
Total74100.00%8100.00%

#endif /* CONFIG_CFS_BANDWIDTH */ #endif /* CONFIG_FAIR_GROUP_SCHED */ #ifdef CONFIG_RT_GROUP_SCHED
static int cpu_rt_runtime_write(struct cgroup_subsys_state *css, struct cftype *cft, s64 val) { return sched_group_set_rt_runtime(css_tg(css), val); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra2376.67%240.00%
Tejun Heo413.33%120.00%
Paul Menage26.67%120.00%
Mirco Tischler13.33%120.00%
Total30100.00%5100.00%


static s64 cpu_rt_runtime_read(struct cgroup_subsys_state *css, struct cftype *cft) { return sched_group_rt_runtime(css_tg(css)); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra1976.00%250.00%
Tejun Heo416.00%125.00%
Paul Menage28.00%125.00%
Total25100.00%4100.00%


static int cpu_rt_period_write_uint(struct cgroup_subsys_state *css, struct cftype *cftype, u64 rt_period_us) { return sched_group_set_rt_period(css_tg(css), rt_period_us); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra2686.67%150.00%
Tejun Heo413.33%150.00%
Total30100.00%2100.00%


static u64 cpu_rt_period_read_uint(struct cgroup_subsys_state *css, struct cftype *cft) { return sched_group_rt_period(css_tg(css)); }

Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra2184.00%150.00%
Tejun Heo416.00%150.00%
Total25100.00%2100.00%

#endif /* CONFIG_RT_GROUP_SCHED */ static struct cftype cpu_legacy_files[] = { #ifdef CONFIG_FAIR_GROUP_SCHED { .name = "shares", .read_u64 = cpu_shares_read_u64, .write_u64 = cpu_shares_write_u64, }, #endif #ifdef CONFIG_CFS_BANDWIDTH { .name = "cfs_quota_us", .read_s64 = cpu_cfs_quota_read_s64, .write_s64 = cpu_cfs_quota_write_s64, }, { .name = "cfs_period_us", .read_u64 = cpu_cfs_period_read_u64, .write_u64 = cpu_cfs_period_write_u64, }, { .name = "stat", .seq_show = cpu_cfs_stat_show, }, #endif #ifdef CONFIG_RT_GROUP_SCHED { .name = "rt_runtime_us", .read_s64 = cpu_rt_runtime_read, .write_s64 = cpu_rt_runtime_write, }, { .name = "rt_period_us", .read_u64 = cpu_rt_period_read_uint, .write_u64 = cpu_rt_period_write_uint, }, #endif { } /* Terminate */ };
static int cpu_extra_stat_show(struct seq_file *sf, struct cgroup_subsys_state *css) { #ifdef CONFIG_CFS_BANDWIDTH { struct task_group *tg = css_tg(css); struct cfs_bandwidth *cfs_b = &tg->cfs_bandwidth; u64 throttled_usec; throttled_usec = cfs_b->throttled_time; do_div(throttled_usec, NSEC_PER_USEC); seq_printf(sf, "nr_periods %d\n" "nr_throttled %d\n" "throttled_usec %llu\n", cfs_b->nr_periods, cfs_b->nr_throttled, throttled_usec); } #endif return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Tejun Heo7896.30%266.67%
Srivatsa Vaddagiri33.70%133.33%
Total81100.00%3100.00%

#ifdef CONFIG_FAIR_GROUP_SCHED
static u64 cpu_weight_read_u64(struct cgroup_subsys_state *css, struct cftype *cft) { struct task_group *tg = css_tg(css); u64 weight = scale_load_down(tg->shares); return DIV_ROUND_CLOSEST_ULL(weight * CGROUP_WEIGHT_DFL, 1024); }

Contributors

PersonTokensPropCommitsCommitProp
Tejun Heo46100.00%1100.00%
Total46100.00%1100.00%


static int cpu_weight_write_u64(struct cgroup_subsys_state *css, struct cftype *cft, u64 weight) { /* * cgroup weight knobs should use the common MIN, DFL and MAX * values which are 1, 100 and 10000 respectively. While it loses * a bit of range on both ends, it maps pretty well onto the shares * value used by scheduler and the round-trip conversions preserve * the original value over the entire range. */ if (weight < CGROUP_WEIGHT_MIN || weight > CGROUP_WEIGHT_MAX) return -ERANGE; weight = DIV_ROUND_CLOSEST_ULL(weight * 1024, CGROUP_WEIGHT_DFL); return sched_group_set_shares(css_tg(css), scale_load(weight)); }

Contributors

PersonTokensPropCommitsCommitProp
Tejun Heo5898.31%150.00%
Konstantin Khlebnikov11.69%150.00%
Total59100.00%2100.00%


static s64 cpu_weight_nice_read_s64(struct cgroup_subsys_state *css, struct cftype *cft) { unsigned long weight = scale_load_down(css_tg(css)->shares); int last_delta = INT_MAX; int prio, delta; /* find the closest nice value to the current weight */ for (prio = 0; prio < ARRAY_SIZE(sched_prio_to_weight); prio++) { delta = abs(sched_prio_to_weight[prio] - weight); if (delta >= last_delta) break; last_delta = delta; } return PRIO_TO_NICE(prio - 1 + MAX_RT_PRIO); }

Contributors

PersonTokensPropCommitsCommitProp
Tejun Heo9097.83%150.00%
Li Zefan22.17%150.00%
Total92100.00%2100.00%


static int cpu_weight_nice_write_s64(struct cgroup_subsys_state *css, struct cftype *cft, s64 nice) { unsigned long weight; if (nice < MIN_NICE || nice > MAX_NICE) return -ERANGE; weight = sched_prio_to_weight[NICE_TO_PRIO(nice) - MAX_RT_PRIO]; return sched_group_set_shares(css_tg(css), scale_load(weight)); }

Contributors

PersonTokensPropCommitsCommitProp
Tejun Heo63100.00%1100.00%
Total63100.00%1100.00%

#endif
static void __maybe_unused cpu_period_quota_print(struct seq_file *sf, long period, long quota) { if (quota < 0) seq_puts(sf, "max"); else seq_printf(sf, "%ld", quota); seq_printf(sf, " %ld\n", period); }

Contributors

PersonTokensPropCommitsCommitProp
Tejun Heo50100.00%1100.00%
Total50100.00%1100.00%

/* caller should put the current value in *@periodp before calling */
static int __maybe_unused cpu_period_quota_parse(char *buf, u64 *periodp, u64 *quotap) { char tok[21]; /* U64_MAX */ if (!sscanf(buf, "%s %llu", tok, periodp)) return -EINVAL; *periodp *= NSEC_PER_USEC; if (sscanf(tok, "%llu", quotap)) *quotap *= NSEC_PER_USEC; else if (!strcmp(tok, "max")) *quotap = RUNTIME_INF; else return -EINVAL; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Tejun Heo89100.00%1100.00%
Total89100.00%1100.00%

#ifdef CONFIG_CFS_BANDWIDTH
static int cpu_max_show(struct seq_file *sf, void *v) { struct task_group *tg = css_tg(seq_css(sf)); cpu_period_quota_print(sf, tg_get_cfs_period(tg), tg_get_cfs_quota(tg)); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Tejun Heo46100.00%1100.00%
Total46100.00%1100.00%


static ssize_t cpu_max_write(struct kernfs_open_file *of, char *buf, size_t nbytes, loff_t off) { struct task_group *tg = css_tg(of_css(of)); u64 period = tg_get_cfs_period(tg); u64 quota; int ret; ret = cpu_period_quota_parse(buf, &period, &quota); if (!ret) ret = tg_set_cfs_bandwidth(tg, period, quota); return ret ?: nbytes; }

Contributors

PersonTokensPropCommitsCommitProp
Tejun Heo83100.00%1100.00%
Total83100.00%1100.00%

#endif static struct cftype cpu_files[] = { #ifdef CONFIG_FAIR_GROUP_SCHED { .name = "weight", .flags = CFTYPE_NOT_ON_ROOT, .read_u64 = cpu_weight_read_u64, .write_u64 = cpu_weight_write_u64, }, { .name = "weight.nice", .flags = CFTYPE_NOT_ON_ROOT, .read_s64 = cpu_weight_nice_read_s64, .write_s64 = cpu_weight_nice_write_s64, }, #endif #ifdef CONFIG_CFS_BANDWIDTH { .name = "max", .flags = CFTYPE_NOT_ON_ROOT, .seq_show = cpu_max_show, .write = cpu_max_write, }, #endif { } /* terminate */ }; struct cgroup_subsys cpu_cgrp_subsys = { .css_alloc = cpu_cgroup_css_alloc, .css_online = cpu_cgroup_css_online, .css_released = cpu_cgroup_css_released, .css_free = cpu_cgroup_css_free, .css_extra_stat_show = cpu_extra_stat_show, .fork = cpu_cgroup_fork, .can_attach = cpu_cgroup_can_attach, .attach = cpu_cgroup_attach, .legacy_cftypes = cpu_legacy_files, .dfl_cftypes = cpu_files, .early_init = true, .threaded = true, }; #endif /* CONFIG_CGROUP_SCHED */
void dump_cpu_task(int cpu) { pr_info("Task dump for CPU %d:\n", cpu); sched_show_task(cpu_curr(cpu)); }

Contributors

PersonTokensPropCommitsCommitProp
Paul E. McKenney23100.00%1100.00%
Total23100.00%1100.00%

/* * Nice levels are multiplicative, with a gentle 10% change for every * nice level changed. I.e. when a CPU-bound task goes from nice 0 to * nice 1, it will get ~10% less CPU time than another CPU-bound task * that remained on nice 0. * * The "10% effect" is relative and cumulative: from _any_ nice level, * if you go up 1 level, it's -10% CPU usage, if you go down 1 level * it's +10% CPU usage. (to achieve that we use a multiplier of 1.25. * If a task goes up by ~10% and another task goes down by ~10% then * the relative distance between them is ~25%.) */ const int sched_prio_to_weight[40] = { /* -20 */ 88761, 71755, 56483, 46273, 36291, /* -15 */ 29154, 23254, 18705, 14949, 11916, /* -10 */ 9548, 7620, 6100, 4904, 3906, /* -5 */ 3121, 2501, 1991, 1586, 1277, /* 0 */ 1024, 820, 655, 526, 423, /* 5 */ 335, 272, 215, 172, 137, /* 10 */ 110, 87, 70, 56, 45, /* 15 */ 36, 29, 23, 18, 15, }; /* * Inverse (2^32/x) values of the sched_prio_to_weight[] array, precalculated. * * In cases where the weight does not change often, we can use the * precalculated inverse to speed up arithmetics by turning divisions * into multiplications: */ const u32 sched_prio_to_wmult[40] = { /* -20 */ 48388, 59856, 76040, 92818, 118348, /* -15 */ 147320, 184698, 229616, 287308, 360437, /* -10 */ 449829, 563644, 704093, 875809, 1099582, /* -5 */ 1376151, 1717300, 2157191, 2708050, 3363326, /* 0 */ 4194304, 5237765, 6557202, 8165337, 10153587, /* 5 */ 12820798, 15790321, 19976592, 24970740, 31350126, /* 10 */ 39045157, 49367440, 61356676, 76695844, 95443717, /* 15 */ 119304647, 148102320, 186737708, 238609294, 286331153, };

Overall Contributors

PersonTokensPropCommitsCommitProp
Peter Zijlstra1087847.97%20326.30%
Dario Faggioli331414.62%60.78%
Tejun Heo11575.10%253.24%
Ingo Molnar7763.42%516.61%
Frédéric Weisbecker7573.34%263.37%
Paul Turner5482.42%111.42%
Thomas Gleixner4892.16%354.53%
Srivatsa Vaddagiri3131.38%50.65%
Andi Kleen2711.20%50.65%
Mel Gorman2331.03%81.04%
Nico Pitre2281.01%50.65%
Andrew Morton2140.94%192.46%
Vincent Guittot2040.90%60.78%
Steven Rostedt2020.89%131.68%
Linus Torvalds1870.82%192.46%
Juri Lelli1670.74%81.04%
Kirill Tkhai1370.60%81.04%
Gregory Haskins1130.50%91.17%
Al Viro1120.49%10.13%
Josh Poimboeuf1010.45%40.52%
Linus Torvalds (pre-git)1010.45%182.33%
Nicholas Piggin1000.44%101.30%
Wanpeng Li950.42%50.65%
Mike Galbraith940.41%131.68%
Matt Fleming900.40%30.39%
Oleg Nesterov860.38%121.55%
Rusty Russell760.34%172.20%
Nikhil P Rao730.32%30.39%
Giovanni Gherdovich700.31%10.13%
Paul E. McKenney660.29%101.30%
Konstantin Khlebnikov560.25%20.26%
Joonwoo Park530.23%10.13%
Chuansheng Liu460.20%10.13%
Li Zefan440.19%20.26%
Vegard Nossum410.18%40.52%
Andrew Lutomirski410.18%70.91%
Suresh B. Siddha380.17%81.04%
Dhaval Giani330.15%60.78%
Byungchul Park290.13%20.26%
Avi Kivity290.13%10.13%
Heiko Carstens290.13%40.52%
Greg Kroah-Hartman280.12%20.26%
Venkatesh Pallipadi280.12%70.91%
Alexey Dobriyan260.11%10.13%
Anton Blanchard240.11%10.13%
Rick Lindsley240.11%10.13%
Robert Love240.11%20.26%
Waiman Long240.11%10.13%
Paul Menage220.10%40.52%
Kirill V Tkhai220.10%10.13%
Dean Nelson200.09%10.13%
xiaofeng.yan200.09%10.13%
Rik Van Riel200.09%40.52%
Stanislaw Gruszka200.09%20.26%
Peter Williams190.08%20.26%
Milton D. Miller II190.08%40.52%
Mike Travis190.08%10.13%
Vatika Harlalka180.08%10.13%
Ben Segall180.08%10.13%
Glauber de Oliveira Costa170.07%20.26%
Paul Jackson160.07%20.26%
Tang Chen160.07%20.26%
Srikar Dronamraju160.07%20.26%
Tetsuo Handa150.07%20.26%
Cheng Chao140.06%10.13%
Patrick Bellasi140.06%10.13%
Henrik Austad140.06%10.13%
Arnaldo Carvalho de Melo140.06%20.26%
Dongsheng Yang140.06%30.39%
Roland McGrath130.06%10.13%
Alex Thorlton120.05%10.13%
Brian Silverman120.05%10.13%
Luca Abeni120.05%30.39%
Dmitry Adamushko110.05%30.39%
Viresh Kumar110.05%10.13%
Srivatsa S. Bhat100.04%20.26%
Mathieu Desnoyers100.04%20.26%
Guillaume Chazarain90.04%10.13%
Josh Snyder90.04%10.13%
Chris Wright90.04%10.13%
Jann Horn90.04%10.13%
Con Kolivas90.04%30.39%
Alex Shi90.04%20.26%
Gautham R. Shenoy90.04%40.52%
Daniel Bristot de Oliveira90.04%10.13%
Jens Axboe80.04%10.13%
Mark Brown80.04%10.13%
Adrian Bunk80.04%10.13%
Maksim Krasnyanskiy70.03%30.39%
Eric Sandeen70.03%10.13%
David P. Quigley70.03%10.13%
Martin Schwidefsky70.03%30.39%
Nathan Lynch60.03%10.13%
Clark Williams60.03%10.13%
Laurent Vivier60.03%10.13%
Matt Mackall60.03%10.13%
Lennart Poettering60.03%10.13%
Corey Minyard60.03%10.13%
Jason Low60.03%20.26%
Hiroshi Shimamoto60.03%10.13%
Hidetoshi Seto60.03%20.26%
Motohiro Kosaki50.02%20.26%
Jack Steiner50.02%10.13%
Christian Ehrhardt50.02%10.13%
Jason Baron50.02%10.13%
Christoph Lameter50.02%30.39%
William Lee Irwin III50.02%20.26%
Christian Bornträger50.02%10.13%
Rabin Vincent50.02%10.13%
Mark Rutland50.02%10.13%
Yong Zhang50.02%30.39%
Bob Miller50.02%10.13%
Masami Hiramatsu50.02%20.26%
Arjan van de Ven50.02%20.26%
Davide Libenzi50.02%10.13%
Olivier Croquette40.02%10.13%
Xie XiuQi40.02%10.13%
Tim Chen40.02%10.13%
Balbir Singh40.02%10.13%
Jason Wessel40.02%10.13%
Dinakar Guniguntala40.02%10.13%
Matthew Wilcox40.02%10.13%
David Howells40.02%20.26%
Andrey Ryabinin40.02%10.13%
Martin J. Bligh40.02%10.13%
Michael S. Tsirkin40.02%10.13%
Keith Owens30.01%10.13%
Davidlohr Bueso A30.01%20.26%
John Hawkes30.01%10.13%
Michael Kerrisk30.01%10.13%
Arnd Bergmann30.01%10.13%
Rakib Mullick20.01%10.13%
Eduard - Gabriel Munteanu20.01%10.13%
Pavel Emelyanov20.01%10.13%
Dave Jones20.01%10.13%
Zhihui Zhang20.01%10.13%
Joe Perches20.01%10.13%
Aaron Tomlin20.01%10.13%
Jeremy Fitzhardinge20.01%10.13%
Lucas De Marchi20.01%10.13%
Gerald Schaefer20.01%10.13%
Benjamin LaHaise20.01%10.13%
Namhyung Kim20.01%20.26%
Dominik Dingel10.00%10.13%
Randy Dunlap10.00%10.13%
Eric Paris10.00%10.13%
David Chinner10.00%10.13%
Paul Mackerras10.00%10.13%
Ankita Garg10.00%10.13%
Neil Brown10.00%10.13%
Zachary Amsden10.00%10.13%
Yacine Belkadi10.00%10.13%
Darren Hart10.00%10.13%
Morten Rasmussen10.00%10.13%
Harald Gustafsson10.00%10.13%
Eric W. Biedermann10.00%10.13%
Carsten Emde10.00%10.13%
Mirco Tischler10.00%10.13%
Jonathan Corbet10.00%10.13%
Richard Weinberger10.00%10.13%
Total22675100.00%772100.00%
Directory: kernel/sched
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.