cgroup: fix display of forceidle time at root

Message ID 20230315214029.899573-1-joshdon@google.com
State New
Headers
Series cgroup: fix display of forceidle time at root |

Commit Message

Josh Don March 15, 2023, 9:40 p.m. UTC
  We need to reset forceidle_sum to 0 when reading from root, since the
bstat we accumulate into is stack allocated.

To make this more robust, just replace the existing cputime reset with a
memset of the overall bstat.

Signed-off-by: Josh Don <joshdon@google.com>
---
 kernel/cgroup/rstat.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
  

Comments

Waiman Long March 16, 2023, 2:19 a.m. UTC | #1
On 3/15/23 17:40, Josh Don wrote:
> We need to reset forceidle_sum to 0 when reading from root, since the
> bstat we accumulate into is stack allocated.
>
> To make this more robust, just replace the existing cputime reset with a
> memset of the overall bstat.
>
> Signed-off-by: Josh Don <joshdon@google.com>
> ---
>   kernel/cgroup/rstat.c | 4 +---
>   1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/kernel/cgroup/rstat.c b/kernel/cgroup/rstat.c
> index 831f1f472bb8..0a2b4967e333 100644
> --- a/kernel/cgroup/rstat.c
> +++ b/kernel/cgroup/rstat.c
> @@ -457,9 +457,7 @@ static void root_cgroup_cputime(struct cgroup_base_stat *bstat)
>   	struct task_cputime *cputime = &bstat->cputime;
>   	int i;
>   
> -	cputime->stime = 0;
> -	cputime->utime = 0;
> -	cputime->sum_exec_runtime = 0;
> +	memset(bstat, 0, sizeof(*bstat));
>   	for_each_possible_cpu(i) {
>   		struct kernel_cpustat kcpustat;
>   		u64 *cpustat = kcpustat.cpustat;

How about adding the following fixes tag?

Fixes: 1fcf54deb767 ("sched/core: add forced idle accounting for cgroups")

Cheers,
Longman
  
Josh Don March 16, 2023, 6:52 p.m. UTC | #2
On Wed, Mar 15, 2023 at 7:19 PM Waiman Long <longman@redhat.com> wrote:
>
> How about adding the following fixes tag?
>
> Fixes: 1fcf54deb767 ("sched/core: add forced idle accounting for cgroups")

SGTM, thanks Waiman!
  
Tejun Heo March 17, 2023, 10:20 p.m. UTC | #3
On Wed, Mar 15, 2023 at 02:40:29PM -0700, Josh Don wrote:
> We need to reset forceidle_sum to 0 when reading from root, since the
> bstat we accumulate into is stack allocated.
> 
> To make this more robust, just replace the existing cputime reset with a
> memset of the overall bstat.
> 
> Signed-off-by: Josh Don <joshdon@google.com>

Applied to cgroup/for-6.3-fixes w/ Fixes tag added and stable cc'd.

Thanks.
  

Patch

diff --git a/kernel/cgroup/rstat.c b/kernel/cgroup/rstat.c
index 831f1f472bb8..0a2b4967e333 100644
--- a/kernel/cgroup/rstat.c
+++ b/kernel/cgroup/rstat.c
@@ -457,9 +457,7 @@  static void root_cgroup_cputime(struct cgroup_base_stat *bstat)
 	struct task_cputime *cputime = &bstat->cputime;
 	int i;
 
-	cputime->stime = 0;
-	cputime->utime = 0;
-	cputime->sum_exec_runtime = 0;
+	memset(bstat, 0, sizeof(*bstat));
 	for_each_possible_cpu(i) {
 		struct kernel_cpustat kcpustat;
 		u64 *cpustat = kcpustat.cpustat;