Merge branch 'sched-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull scheduler fix from Ingo Molnar:
 "A delayacct statistics correctness fix"

* 'sched-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
  delayacct: Account blkio completion on the correct task
This commit is contained in:
Linus Torvalds 2018-01-17 12:28:22 -08:00
commit 9a4ba2ab08
3 changed files with 33 additions and 23 deletions

View File

@ -71,7 +71,7 @@ extern void delayacct_init(void);
extern void __delayacct_tsk_init(struct task_struct *); extern void __delayacct_tsk_init(struct task_struct *);
extern void __delayacct_tsk_exit(struct task_struct *); extern void __delayacct_tsk_exit(struct task_struct *);
extern void __delayacct_blkio_start(void); extern void __delayacct_blkio_start(void);
extern void __delayacct_blkio_end(void); extern void __delayacct_blkio_end(struct task_struct *);
extern int __delayacct_add_tsk(struct taskstats *, struct task_struct *); extern int __delayacct_add_tsk(struct taskstats *, struct task_struct *);
extern __u64 __delayacct_blkio_ticks(struct task_struct *); extern __u64 __delayacct_blkio_ticks(struct task_struct *);
extern void __delayacct_freepages_start(void); extern void __delayacct_freepages_start(void);
@ -122,10 +122,10 @@ static inline void delayacct_blkio_start(void)
__delayacct_blkio_start(); __delayacct_blkio_start();
} }
static inline void delayacct_blkio_end(void) static inline void delayacct_blkio_end(struct task_struct *p)
{ {
if (current->delays) if (current->delays)
__delayacct_blkio_end(); __delayacct_blkio_end(p);
delayacct_clear_flag(DELAYACCT_PF_BLKIO); delayacct_clear_flag(DELAYACCT_PF_BLKIO);
} }
@ -169,7 +169,7 @@ static inline void delayacct_tsk_free(struct task_struct *tsk)
{} {}
static inline void delayacct_blkio_start(void) static inline void delayacct_blkio_start(void)
{} {}
static inline void delayacct_blkio_end(void) static inline void delayacct_blkio_end(struct task_struct *p)
{} {}
static inline int delayacct_add_tsk(struct taskstats *d, static inline int delayacct_add_tsk(struct taskstats *d,
struct task_struct *tsk) struct task_struct *tsk)

View File

@ -51,16 +51,16 @@ void __delayacct_tsk_init(struct task_struct *tsk)
* Finish delay accounting for a statistic using its timestamps (@start), * Finish delay accounting for a statistic using its timestamps (@start),
* accumalator (@total) and @count * accumalator (@total) and @count
*/ */
static void delayacct_end(u64 *start, u64 *total, u32 *count) static void delayacct_end(spinlock_t *lock, u64 *start, u64 *total, u32 *count)
{ {
s64 ns = ktime_get_ns() - *start; s64 ns = ktime_get_ns() - *start;
unsigned long flags; unsigned long flags;
if (ns > 0) { if (ns > 0) {
spin_lock_irqsave(&current->delays->lock, flags); spin_lock_irqsave(lock, flags);
*total += ns; *total += ns;
(*count)++; (*count)++;
spin_unlock_irqrestore(&current->delays->lock, flags); spin_unlock_irqrestore(lock, flags);
} }
} }
@ -69,17 +69,25 @@ void __delayacct_blkio_start(void)
current->delays->blkio_start = ktime_get_ns(); current->delays->blkio_start = ktime_get_ns();
} }
void __delayacct_blkio_end(void) /*
* We cannot rely on the `current` macro, as we haven't yet switched back to
* the process being woken.
*/
void __delayacct_blkio_end(struct task_struct *p)
{ {
if (current->delays->flags & DELAYACCT_PF_SWAPIN) struct task_delay_info *delays = p->delays;
/* Swapin block I/O */ u64 *total;
delayacct_end(&current->delays->blkio_start, u32 *count;
&current->delays->swapin_delay,
&current->delays->swapin_count); if (p->delays->flags & DELAYACCT_PF_SWAPIN) {
else /* Other block I/O */ total = &delays->swapin_delay;
delayacct_end(&current->delays->blkio_start, count = &delays->swapin_count;
&current->delays->blkio_delay, } else {
&current->delays->blkio_count); total = &delays->blkio_delay;
count = &delays->blkio_count;
}
delayacct_end(&delays->lock, &delays->blkio_start, total, count);
} }
int __delayacct_add_tsk(struct taskstats *d, struct task_struct *tsk) int __delayacct_add_tsk(struct taskstats *d, struct task_struct *tsk)
@ -153,8 +161,10 @@ void __delayacct_freepages_start(void)
void __delayacct_freepages_end(void) void __delayacct_freepages_end(void)
{ {
delayacct_end(&current->delays->freepages_start, delayacct_end(
&current->delays->freepages_delay, &current->delays->lock,
&current->delays->freepages_count); &current->delays->freepages_start,
&current->delays->freepages_delay,
&current->delays->freepages_count);
} }

View File

@ -2056,7 +2056,7 @@ try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags)
p->state = TASK_WAKING; p->state = TASK_WAKING;
if (p->in_iowait) { if (p->in_iowait) {
delayacct_blkio_end(); delayacct_blkio_end(p);
atomic_dec(&task_rq(p)->nr_iowait); atomic_dec(&task_rq(p)->nr_iowait);
} }
@ -2069,7 +2069,7 @@ try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags)
#else /* CONFIG_SMP */ #else /* CONFIG_SMP */
if (p->in_iowait) { if (p->in_iowait) {
delayacct_blkio_end(); delayacct_blkio_end(p);
atomic_dec(&task_rq(p)->nr_iowait); atomic_dec(&task_rq(p)->nr_iowait);
} }
@ -2122,7 +2122,7 @@ static void try_to_wake_up_local(struct task_struct *p, struct rq_flags *rf)
if (!task_on_rq_queued(p)) { if (!task_on_rq_queued(p)) {
if (p->in_iowait) { if (p->in_iowait) {
delayacct_blkio_end(); delayacct_blkio_end(p);
atomic_dec(&rq->nr_iowait); atomic_dec(&rq->nr_iowait);
} }
ttwu_activate(rq, p, ENQUEUE_WAKEUP | ENQUEUE_NOCLOCK); ttwu_activate(rq, p, ENQUEUE_WAKEUP | ENQUEUE_NOCLOCK);