123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- #ifdef CONFIG_SCHEDSTATS
- /*
- * Expects runqueue lock to be held for atomicity of update
- */
- static inline void
- rq_sched_info_arrive(struct rq *rq, unsigned long long delta)
- {
- if (rq) {
- rq->rq_sched_info.run_delay += delta;
- rq->rq_sched_info.pcount++;
- }
- }
- /*
- * Expects runqueue lock to be held for atomicity of update
- */
- static inline void
- rq_sched_info_depart(struct rq *rq, unsigned long long delta)
- {
- if (rq)
- rq->rq_cpu_time += delta;
- }
- static inline void
- rq_sched_info_dequeued(struct rq *rq, unsigned long long delta)
- {
- if (rq)
- rq->rq_sched_info.run_delay += delta;
- }
- # define schedstat_inc(rq, field) do { (rq)->field++; } while (0)
- # define schedstat_add(rq, field, amt) do { (rq)->field += (amt); } while (0)
- # define schedstat_set(var, val) do { var = (val); } while (0)
- #else /* !CONFIG_SCHEDSTATS */
- static inline void
- rq_sched_info_arrive(struct rq *rq, unsigned long long delta)
- {}
- static inline void
- rq_sched_info_dequeued(struct rq *rq, unsigned long long delta)
- {}
- static inline void
- rq_sched_info_depart(struct rq *rq, unsigned long long delta)
- {}
- # define schedstat_inc(rq, field) do { } while (0)
- # define schedstat_add(rq, field, amt) do { } while (0)
- # define schedstat_set(var, val) do { } while (0)
- #endif
- #if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT)
- static inline void sched_info_reset_dequeued(struct task_struct *t)
- {
- t->sched_info.last_queued = 0;
- }
- /*
- * We are interested in knowing how long it was from the *first* time a
- * task was queued to the time that it finally hit a cpu, we call this routine
- * from dequeue_task() to account for possible rq->clock skew across cpus. The
- * delta taken on each cpu would annul the skew.
- */
- static inline void sched_info_dequeued(struct task_struct *t)
- {
- unsigned long long now = task_rq(t)->clock, delta = 0;
- if (unlikely(sched_info_on()))
- if (t->sched_info.last_queued)
- delta = now - t->sched_info.last_queued;
- sched_info_reset_dequeued(t);
- t->sched_info.run_delay += delta;
- rq_sched_info_dequeued(task_rq(t), delta);
- }
- /*
- * Called when a task finally hits the cpu. We can now calculate how
- * long it was waiting to run. We also note when it began so that we
- * can keep stats on how long its timeslice is.
- */
- static void sched_info_arrive(struct task_struct *t)
- {
- unsigned long long now = task_rq(t)->clock, delta = 0;
- if (t->sched_info.last_queued)
- delta = now - t->sched_info.last_queued;
- sched_info_reset_dequeued(t);
- t->sched_info.run_delay += delta;
- t->sched_info.last_arrival = now;
- t->sched_info.pcount++;
- rq_sched_info_arrive(task_rq(t), delta);
- }
- /*
- * This function is only called from enqueue_task(), but also only updates
- * the timestamp if it is already not set. It's assumed that
- * sched_info_dequeued() will clear that stamp when appropriate.
- */
- static inline void sched_info_queued(struct task_struct *t)
- {
- if (unlikely(sched_info_on()))
- if (!t->sched_info.last_queued)
- t->sched_info.last_queued = task_rq(t)->clock;
- }
- /*
- * Called when a process ceases being the active-running process, either
- * voluntarily or involuntarily. Now we can calculate how long we ran.
- * Also, if the process is still in the TASK_RUNNING state, call
- * sched_info_queued() to mark that it has now again started waiting on
- * the runqueue.
- */
- static inline void sched_info_depart(struct task_struct *t)
- {
- unsigned long long delta = task_rq(t)->clock -
- t->sched_info.last_arrival;
- rq_sched_info_depart(task_rq(t), delta);
- if (t->state == TASK_RUNNING)
- sched_info_queued(t);
- }
- /*
- * Called when tasks are switched involuntarily due, typically, to expiring
- * their time slice. (This may also be called when switching to or from
- * the idle task.) We are only called when prev != next.
- */
- static inline void
- __sched_info_switch(struct task_struct *prev, struct task_struct *next)
- {
- struct rq *rq = task_rq(prev);
- /*
- * prev now departs the cpu. It's not interesting to record
- * stats about how efficient we were at scheduling the idle
- * process, however.
- */
- if (prev != rq->idle)
- sched_info_depart(prev);
- if (next != rq->idle)
- sched_info_arrive(next);
- }
- static inline void
- sched_info_switch(struct task_struct *prev, struct task_struct *next)
- {
- if (unlikely(sched_info_on()))
- __sched_info_switch(prev, next);
- }
- #else
- #define sched_info_queued(t) do { } while (0)
- #define sched_info_reset_dequeued(t) do { } while (0)
- #define sched_info_dequeued(t) do { } while (0)
- #define sched_info_switch(t, next) do { } while (0)
- #endif /* CONFIG_SCHEDSTATS || CONFIG_TASK_DELAY_ACCT */
- /*
- * The following are functions that support scheduler-internal time accounting.
- * These functions are generally called at the timer tick. None of this depends
- * on CONFIG_SCHEDSTATS.
- */
- /**
- * account_group_user_time - Maintain utime for a thread group.
- *
- * @tsk: Pointer to task structure.
- * @cputime: Time value by which to increment the utime field of the
- * thread_group_cputime structure.
- *
- * If thread group time is being maintained, get the structure for the
- * running CPU and update the utime field there.
- */
- static inline void account_group_user_time(struct task_struct *tsk,
- cputime_t cputime)
- {
- struct thread_group_cputimer *cputimer = &tsk->signal->cputimer;
- if (!cputimer->running)
- return;
- raw_spin_lock(&cputimer->lock);
- cputimer->cputime.utime += cputime;
- raw_spin_unlock(&cputimer->lock);
- }
- /**
- * account_group_system_time - Maintain stime for a thread group.
- *
- * @tsk: Pointer to task structure.
- * @cputime: Time value by which to increment the stime field of the
- * thread_group_cputime structure.
- *
- * If thread group time is being maintained, get the structure for the
- * running CPU and update the stime field there.
- */
- static inline void account_group_system_time(struct task_struct *tsk,
- cputime_t cputime)
- {
- struct thread_group_cputimer *cputimer = &tsk->signal->cputimer;
- if (!cputimer->running)
- return;
- raw_spin_lock(&cputimer->lock);
- cputimer->cputime.stime += cputime;
- raw_spin_unlock(&cputimer->lock);
- }
- /**
- * account_group_exec_runtime - Maintain exec runtime for a thread group.
- *
- * @tsk: Pointer to task structure.
- * @ns: Time value by which to increment the sum_exec_runtime field
- * of the thread_group_cputime structure.
- *
- * If thread group time is being maintained, get the structure for the
- * running CPU and update the sum_exec_runtime field there.
- */
- static inline void account_group_exec_runtime(struct task_struct *tsk,
- unsigned long long ns)
- {
- struct thread_group_cputimer *cputimer = &tsk->signal->cputimer;
- if (!cputimer->running)
- return;
- raw_spin_lock(&cputimer->lock);
- cputimer->cputime.sum_exec_runtime += ns;
- raw_spin_unlock(&cputimer->lock);
- }
|