All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sched/core: fix incorrect parameter burst in cpu_max_write()
@ 2024-04-24 13:24 Cheng Yu
  2024-05-02  8:57 ` Vincent Guittot
  2024-05-17  8:06 ` [tip: sched/urgent] sched/core: Fix incorrect initialization of the 'burst' parameter " tip-bot2 for Cheng Yu
  0 siblings, 2 replies; 3+ messages in thread
From: Cheng Yu @ 2024-04-24 13:24 UTC (permalink / raw
  To: mingo, peterz, juri.lelli, vincent.guittot, dietmar.eggemann,
	rostedt, bsegall, mgorman, bristot, vschneid, changhuaixin,
	shanpeic, dtcccc, tj, linux-kernel
  Cc: zhangqiao22, judy.chenhui, yusongping, serein.chengyu

In the cgroup v2 cpu subsystem, assuming we have a
cgroup named test, we set cpu.max and cpu.max.burst:
    # echo 1000000 > /sys/fs/cgroup/test/cpu.max
    # echo 1000000 > /sys/fs/cgroup/test/cpu.max.burst
then we check cpu.max and cpu.max.burst:
    # cat /sys/fs/cgroup/test/cpu.max
    1000000 100000
    # cat /sys/fs/cgroup/test/cpu.max.burst
    1000000

Next we set cpu.max again and check cpu.max and
cpu.max.burst:
    # echo 2000000 > /sys/fs/cgroup/test/cpu.max
    # cat /sys/fs/cgroup/test/cpu.max
    2000000 100000
    # cat /sys/fs/cgroup/test/cpu.max.burst
    1000
we found that the cpu.max.burst value changed unexpectedly.

In cpu_max_write(), the unit of the burst value returned
by tg_get_cfs_burst() is microseconds, while in cpu_max_write(),
the burst unit used for calculation should be nanoseconds,
which leads to the bug.

To fix it, we get the burst value directly from
tg->cfs_bandwidth.burst.

Reported-by: Qixin Liao <liaoqixin@huawei.com>
Fixes: f4183717b370 ("sched/fair: Introduce the burstable CFS controller")
Signed-off-by: Cheng Yu <serein.chengyu@huawei.com>
Signed-off-by: Zhang Qiao <zhangqiao22@huawei.com>
---
 kernel/sched/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 7019a40457a6..d211d40a2edc 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -11402,7 +11402,7 @@ static ssize_t cpu_max_write(struct kernfs_open_file *of,
 {
 	struct task_group *tg = css_tg(of_css(of));
 	u64 period = tg_get_cfs_period(tg);
-	u64 burst = tg_get_cfs_burst(tg);
+	u64 burst = tg->cfs_bandwidth.burst;
 	u64 quota;
 	int ret;
 
-- 
2.25.1


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

* Re: [PATCH] sched/core: fix incorrect parameter burst in cpu_max_write()
  2024-04-24 13:24 [PATCH] sched/core: fix incorrect parameter burst in cpu_max_write() Cheng Yu
@ 2024-05-02  8:57 ` Vincent Guittot
  2024-05-17  8:06 ` [tip: sched/urgent] sched/core: Fix incorrect initialization of the 'burst' parameter " tip-bot2 for Cheng Yu
  1 sibling, 0 replies; 3+ messages in thread
From: Vincent Guittot @ 2024-05-02  8:57 UTC (permalink / raw
  To: Cheng Yu
  Cc: mingo, peterz, juri.lelli, dietmar.eggemann, rostedt, bsegall,
	mgorman, bristot, vschneid, changhuaixin, shanpeic, dtcccc, tj,
	linux-kernel, zhangqiao22, judy.chenhui, yusongping

On Wed, 24 Apr 2024 at 15:29, Cheng Yu <serein.chengyu@huawei.com> wrote:
>
> In the cgroup v2 cpu subsystem, assuming we have a
> cgroup named test, we set cpu.max and cpu.max.burst:
>     # echo 1000000 > /sys/fs/cgroup/test/cpu.max
>     # echo 1000000 > /sys/fs/cgroup/test/cpu.max.burst
> then we check cpu.max and cpu.max.burst:
>     # cat /sys/fs/cgroup/test/cpu.max
>     1000000 100000
>     # cat /sys/fs/cgroup/test/cpu.max.burst
>     1000000
>
> Next we set cpu.max again and check cpu.max and
> cpu.max.burst:
>     # echo 2000000 > /sys/fs/cgroup/test/cpu.max
>     # cat /sys/fs/cgroup/test/cpu.max
>     2000000 100000
>     # cat /sys/fs/cgroup/test/cpu.max.burst
>     1000
> we found that the cpu.max.burst value changed unexpectedly.
>
> In cpu_max_write(), the unit of the burst value returned
> by tg_get_cfs_burst() is microseconds, while in cpu_max_write(),
> the burst unit used for calculation should be nanoseconds,
> which leads to the bug.
>
> To fix it, we get the burst value directly from
> tg->cfs_bandwidth.burst.
>
> Reported-by: Qixin Liao <liaoqixin@huawei.com>
> Fixes: f4183717b370 ("sched/fair: Introduce the burstable CFS controller")
> Signed-off-by: Cheng Yu <serein.chengyu@huawei.com>
> Signed-off-by: Zhang Qiao <zhangqiao22@huawei.com>

Reviewed-by: Vincent Guittot <vincent.guittot@linaro.org>
Tested-by: Vincent Guittot <vincent.guittot@linaro.org>

> ---
>  kernel/sched/core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 7019a40457a6..d211d40a2edc 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -11402,7 +11402,7 @@ static ssize_t cpu_max_write(struct kernfs_open_file *of,
>  {
>         struct task_group *tg = css_tg(of_css(of));
>         u64 period = tg_get_cfs_period(tg);
> -       u64 burst = tg_get_cfs_burst(tg);
> +       u64 burst = tg->cfs_bandwidth.burst;
>         u64 quota;
>         int ret;
>
> --
> 2.25.1
>
>

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

* [tip: sched/urgent] sched/core: Fix incorrect initialization of the 'burst' parameter in cpu_max_write()
  2024-04-24 13:24 [PATCH] sched/core: fix incorrect parameter burst in cpu_max_write() Cheng Yu
  2024-05-02  8:57 ` Vincent Guittot
@ 2024-05-17  8:06 ` tip-bot2 for Cheng Yu
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot2 for Cheng Yu @ 2024-05-17  8:06 UTC (permalink / raw
  To: linux-tip-commits
  Cc: Qixin Liao, Cheng Yu, Zhang Qiao, Ingo Molnar, Vincent Guittot,
	x86, linux-kernel

The following commit has been merged into the sched/urgent branch of tip:

Commit-ID:     49217ea147df7647cb89161b805c797487783fc0
Gitweb:        https://git.kernel.org/tip/49217ea147df7647cb89161b805c797487783fc0
Author:        Cheng Yu <serein.chengyu@huawei.com>
AuthorDate:    Wed, 24 Apr 2024 21:24:38 +08:00
Committer:     Ingo Molnar <mingo@kernel.org>
CommitterDate: Fri, 17 May 2024 09:53:54 +02:00

sched/core: Fix incorrect initialization of the 'burst' parameter in cpu_max_write()

In the cgroup v2 CPU subsystem, assuming we have a
cgroup named 'test', and we set cpu.max and cpu.max.burst:

    # echo 1000000 > /sys/fs/cgroup/test/cpu.max
    # echo 1000000 > /sys/fs/cgroup/test/cpu.max.burst

then we check cpu.max and cpu.max.burst:

    # cat /sys/fs/cgroup/test/cpu.max
    1000000 100000
    # cat /sys/fs/cgroup/test/cpu.max.burst
    1000000

Next we set cpu.max again and check cpu.max and
cpu.max.burst:

    # echo 2000000 > /sys/fs/cgroup/test/cpu.max
    # cat /sys/fs/cgroup/test/cpu.max
    2000000 100000

    # cat /sys/fs/cgroup/test/cpu.max.burst
    1000

... we find that the cpu.max.burst value changed unexpectedly.

In cpu_max_write(), the unit of the burst value returned
by tg_get_cfs_burst() is microseconds, while in cpu_max_write(),
the burst unit used for calculation should be nanoseconds,
which leads to the bug.

To fix it, get the burst value directly from tg->cfs_bandwidth.burst.

Fixes: f4183717b370 ("sched/fair: Introduce the burstable CFS controller")
Reported-by: Qixin Liao <liaoqixin@huawei.com>
Signed-off-by: Cheng Yu <serein.chengyu@huawei.com>
Signed-off-by: Zhang Qiao <zhangqiao22@huawei.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Reviewed-by: Vincent Guittot <vincent.guittot@linaro.org>
Tested-by: Vincent Guittot <vincent.guittot@linaro.org>
Link: https://lore.kernel.org/r/20240424132438.514720-1-serein.chengyu@huawei.com
---
 kernel/sched/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 1a91438..f88f505 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -11402,7 +11402,7 @@ static ssize_t cpu_max_write(struct kernfs_open_file *of,
 {
 	struct task_group *tg = css_tg(of_css(of));
 	u64 period = tg_get_cfs_period(tg);
-	u64 burst = tg_get_cfs_burst(tg);
+	u64 burst = tg->cfs_bandwidth.burst;
 	u64 quota;
 	int ret;
 

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

end of thread, other threads:[~2024-05-17  8:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-24 13:24 [PATCH] sched/core: fix incorrect parameter burst in cpu_max_write() Cheng Yu
2024-05-02  8:57 ` Vincent Guittot
2024-05-17  8:06 ` [tip: sched/urgent] sched/core: Fix incorrect initialization of the 'burst' parameter " tip-bot2 for Cheng Yu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.