public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sched: Fix rq nr_uninterruptible count
@ 2023-02-28  7:08 zhenggy
  2023-02-28  8:13 ` Slade's Kernel Patch Bot
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: zhenggy @ 2023-02-28  7:08 UTC (permalink / raw)
  To: mingo, peterz, juri.lelli, vincent.guittot, dietmar.eggemann,
	rostedt, bsegall, mgorman, bristot, vschneid
  Cc: linux-kernel

When an uninterrptable task is queue to a differect cpu as where
it is dequeued, the rq nr_uninterruptible will be incorrent, so
fix it.

Signed-off-by: GuoYong Zheng <zhenggy@chinatelecom.cn>
---
 kernel/sched/core.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 25b582b..cd5ef6e 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -4068,6 +4068,7 @@ bool ttwu_state_match(struct task_struct *p, unsigned int state, int *success)
 {
 	unsigned long flags;
 	int cpu, success = 0;
+	struct rq *src_rq, *dst_rq;

 	preempt_disable();
 	if (p == current) {
@@ -4205,6 +4206,16 @@ bool ttwu_state_match(struct task_struct *p, unsigned int state, int *success)
 			atomic_dec(&task_rq(p)->nr_iowait);
 		}

+		if (p->sched_contributes_to_load) {
+			src_rq = cpu_rq(task_cpu(p));
+			dst_rq = cpu_rq(cpu);
+
+			double_rq_lock(src_rq, dst_rq);
+			src_rq->nr_uninterruptible--;
+			dst_rq->nr_uninterruptible++;
+			double_rq_unlock(src_rq, dst_rq);
+		}
+
 		wake_flags |= WF_MIGRATED;
 		psi_ttwu_dequeue(p);
 		set_task_cpu(p, cpu);
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] sched: Fix rq nr_uninterruptible count
  2023-02-28  7:08 [PATCH] sched: Fix rq nr_uninterruptible count zhenggy
@ 2023-02-28  8:13 ` Slade's Kernel Patch Bot
  2023-02-28  8:56 ` Bagas Sanjaya
  2023-02-28  9:27 ` Mike Galbraith
  2 siblings, 0 replies; 6+ messages in thread
From: Slade's Kernel Patch Bot @ 2023-02-28  8:13 UTC (permalink / raw)
  To: zhenggy, mingo, peterz, juri.lelli, vincent.guittot,
	dietmar.eggemann, rostedt, bsegall, mgorman, bristot, vschneid
  Cc: linux-kernel, Slade Watkins

On 2/28/23 02:08, zhenggy wrote:
> When an uninterrptable task is queue to a differect cpu as where
> it is dequeued, the rq nr_uninterruptible will be incorrent, so
> fix it.
> 
> Signed-off-by: GuoYong Zheng <zhenggy@chinatelecom.cn>
> ---
>  kernel/sched/core.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 25b582b..cd5ef6e 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -4068,6 +4068,7 @@ bool ttwu_state_match(struct task_struct *p, unsigned int state, int *success)
>  {
>  	unsigned long flags;
>  	int cpu, success = 0;
> +	struct rq *src_rq, *dst_rq;
> 
>  	preempt_disable();
>  	if (p == current) {
> @@ -4205,6 +4206,16 @@ bool ttwu_state_match(struct task_struct *p, unsigned int state, int *success)
>  			atomic_dec(&task_rq(p)->nr_iowait);
>  		}
> 
> +		if (p->sched_contributes_to_load) {
> +			src_rq = cpu_rq(task_cpu(p));
> +			dst_rq = cpu_rq(cpu);
> +
> +			double_rq_lock(src_rq, dst_rq);
> +			src_rq->nr_uninterruptible--;
> +			dst_rq->nr_uninterruptible++;
> +			double_rq_unlock(src_rq, dst_rq);
> +		}
> +
>  		wake_flags |= WF_MIGRATED;
>  		psi_ttwu_dequeue(p);
>  		set_task_cpu(p, cpu);

This is Slade's kernel patch bot. When scanning his mailbox, I came across this message, which appears to have an odd format for its text ("text/plain; charset=gbk"). Emailed patches should be in ASCII or UTF-8 encoding. If you're using an email client, make sure it's configured to use either of the two formats.

You can learn more in the kernel's documentation here: https://www.kernel.org/doc/html/latest/process/email-clients.html

If you believe this is an error, please address a message to Slade Watkins <srw@sladewatkins.net>.

Thank you,
-- Slade's kernel patch bot

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] sched: Fix rq nr_uninterruptible count
@ 2023-02-28  8:46 zhenggy
  2023-02-28  9:38 ` Nikolay Borisov
  0 siblings, 1 reply; 6+ messages in thread
From: zhenggy @ 2023-02-28  8:46 UTC (permalink / raw)
  To: mingo, juri.lelli, vincent.guittot, dietmar.eggemann, rostedt,
	bsegall, mgorman, srw
  Cc: linux-kernel

When an uninterrptable task is queue to a differect cpu as where
it is dequeued, the rq nr_uninterruptible will be incorrent, so
fix it.

Signed-off-by: GuoYong Zheng <zhenggy@chinatelecom.cn>
---
 kernel/sched/core.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 25b582b..cd5ef6e 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -4068,6 +4068,7 @@ bool ttwu_state_match(struct task_struct *p, unsigned int state, int *success)
 {
 	unsigned long flags;
 	int cpu, success = 0;
+	struct rq *src_rq, *dst_rq;

 	preempt_disable();
 	if (p == current) {
@@ -4205,6 +4206,16 @@ bool ttwu_state_match(struct task_struct *p, unsigned int state, int *success)
 			atomic_dec(&task_rq(p)->nr_iowait);
 		}

+		if (p->sched_contributes_to_load) {
+			src_rq = cpu_rq(task_cpu(p));
+			dst_rq = cpu_rq(cpu);
+
+			double_rq_lock(src_rq, dst_rq);
+			src_rq->nr_uninterruptible--;
+			dst_rq->nr_uninterruptible++;
+			double_rq_unlock(src_rq, dst_rq);
+		}
+
 		wake_flags |= WF_MIGRATED;
 		psi_ttwu_dequeue(p);
 		set_task_cpu(p, cpu);
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] sched: Fix rq nr_uninterruptible count
  2023-02-28  7:08 [PATCH] sched: Fix rq nr_uninterruptible count zhenggy
  2023-02-28  8:13 ` Slade's Kernel Patch Bot
@ 2023-02-28  8:56 ` Bagas Sanjaya
  2023-02-28  9:27 ` Mike Galbraith
  2 siblings, 0 replies; 6+ messages in thread
From: Bagas Sanjaya @ 2023-02-28  8:56 UTC (permalink / raw)
  To: zhenggy, mingo, peterz, juri.lelli, vincent.guittot,
	dietmar.eggemann, rostedt, bsegall, mgorman, bristot, vschneid
  Cc: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1283 bytes --]

On Tue, Feb 28, 2023 at 03:08:58PM +0800, zhenggy wrote:
> When an uninterrptable task is queue to a differect cpu as where
> it is dequeued, the rq nr_uninterruptible will be incorrent, so
> fix it.

tl;dr (too much typos above). Would you like to "massage" the commit
mesage?

> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 25b582b..cd5ef6e 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -4068,6 +4068,7 @@ bool ttwu_state_match(struct task_struct *p, unsigned int state, int *success)
>  {
>  	unsigned long flags;
>  	int cpu, success = 0;
> +	struct rq *src_rq, *dst_rq;
> 
>  	preempt_disable();
>  	if (p == current) {
> @@ -4205,6 +4206,16 @@ bool ttwu_state_match(struct task_struct *p, unsigned int state, int *success)
>  			atomic_dec(&task_rq(p)->nr_iowait);
>  		}
> 
> +		if (p->sched_contributes_to_load) {
> +			src_rq = cpu_rq(task_cpu(p));
> +			dst_rq = cpu_rq(cpu);
> +
> +			double_rq_lock(src_rq, dst_rq);
> +			src_rq->nr_uninterruptible--;
> +			dst_rq->nr_uninterruptible++;
> +			double_rq_unlock(src_rq, dst_rq);
> +		}
> +

Can you explain what the code above does to fix the problem you
mentioned above?

Thanks.

-- 
An old man doll... just what I always wanted! - Clara

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] sched: Fix rq nr_uninterruptible count
  2023-02-28  7:08 [PATCH] sched: Fix rq nr_uninterruptible count zhenggy
  2023-02-28  8:13 ` Slade's Kernel Patch Bot
  2023-02-28  8:56 ` Bagas Sanjaya
@ 2023-02-28  9:27 ` Mike Galbraith
  2 siblings, 0 replies; 6+ messages in thread
From: Mike Galbraith @ 2023-02-28  9:27 UTC (permalink / raw)
  To: zhenggy, mingo, peterz, juri.lelli, vincent.guittot,
	dietmar.eggemann, rostedt, bsegall, mgorman, bristot, vschneid
  Cc: linux-kernel

On Tue, 2023-02-28 at 15:08 +0800, zhenggy wrote:
> When an uninterrptable task is queue to a differect cpu as where
> it is dequeued, the rq nr_uninterruptible will be incorrent, so
> fix it.

That's intentional, see 47-52 of kernel/sched/loadavg.c.

	-Mike

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] sched: Fix rq nr_uninterruptible count
  2023-02-28  8:46 zhenggy
@ 2023-02-28  9:38 ` Nikolay Borisov
  0 siblings, 0 replies; 6+ messages in thread
From: Nikolay Borisov @ 2023-02-28  9:38 UTC (permalink / raw)
  To: zhenggy, mingo, juri.lelli, vincent.guittot, dietmar.eggemann,
	rostedt, bsegall, mgorman, srw
  Cc: linux-kernel



On 28.02.23 г. 10:46 ч., zhenggy wrote:
> When an uninterrptable task is queue to a differect cpu as where
> it is dequeued, the rq nr_uninterruptible will be incorrent, so
> fix it.
> 
> Signed-off-by: GuoYong Zheng <zhenggy@chinatelecom.cn>


    37  *  - cpu_rq()->nr_uninterruptible isn't accurately tracked 
per-CPU because
    38  *    this would add another cross-CPU cacheline miss and atomic 
operation
    39  *    to the wakeup path. Instead we increment on whatever CPU 
the task ran
    40  *    when it went into uninterruptible state and decrement on 
whatever CPU
    41  *    did the wakeup. This means that only the sum of 
nr_uninterruptible over
    42  *    all CPUs yields the correct result.

> ---
>   kernel/sched/core.c | 11 +++++++++++
>   1 file changed, 11 insertions(+)
> 
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 25b582b..cd5ef6e 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -4068,6 +4068,7 @@ bool ttwu_state_match(struct task_struct *p, unsigned int state, int *success)
>   {
>   	unsigned long flags;
>   	int cpu, success = 0;
> +	struct rq *src_rq, *dst_rq;
> 
>   	preempt_disable();
>   	if (p == current) {
> @@ -4205,6 +4206,16 @@ bool ttwu_state_match(struct task_struct *p, unsigned int state, int *success)
>   			atomic_dec(&task_rq(p)->nr_iowait);
>   		}
> 
> +		if (p->sched_contributes_to_load) {
> +			src_rq = cpu_rq(task_cpu(p));
> +			dst_rq = cpu_rq(cpu);
> +
> +			double_rq_lock(src_rq, dst_rq);
> +			src_rq->nr_uninterruptible--;
> +			dst_rq->nr_uninterruptible++;
> +			double_rq_unlock(src_rq, dst_rq);
> +		}
> +
>   		wake_flags |= WF_MIGRATED;
>   		psi_ttwu_dequeue(p);
>   		set_task_cpu(p, cpu);

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-02-28  9:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-28  7:08 [PATCH] sched: Fix rq nr_uninterruptible count zhenggy
2023-02-28  8:13 ` Slade's Kernel Patch Bot
2023-02-28  8:56 ` Bagas Sanjaya
2023-02-28  9:27 ` Mike Galbraith
  -- strict thread matches above, loose matches on Subject: below --
2023-02-28  8:46 zhenggy
2023-02-28  9:38 ` Nikolay Borisov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox