public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sched/core: fix incorrect cpustat[CPUTIME_FORCEIDLE] update
@ 2023-11-17 12:56 Cruz Zhao
  2023-11-17 19:50 ` kernel test robot
  0 siblings, 1 reply; 2+ messages in thread
From: Cruz Zhao @ 2023-11-17 12:56 UTC (permalink / raw)
  To: mingo, peterz, juri.lelli, vincent.guittot, dietmar.eggemann,
	rostedt, bsegall, mgorman, bristot, vschneid, joel
  Cc: linux-kernel

In function __account_forceidle_time(), task_group_account_field()
is called to update kernel_cpustat.cpustat[CPUTIME_FORCEIDLE].
However, p may be not running on current cpu, so update cpustat with
this_cpu_add() is incorrect.

To fix this problem, we get the cpu of p first, and then add delta
to kcpustat_cpu(cpu).cpustat[CPUTIME_FORCEIDLE].

Fixes: 1fcf54deb767 ("sched/core: add forced idle accounting for cgroups")
Signed-off-by: Cruz Zhao <CruzZhao@linux.alibaba.com>
---
 kernel/sched/cputime.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
index af7952f12e6c..6f18fdc4a0dc 100644
--- a/kernel/sched/cputime.c
+++ b/kernel/sched/cputime.c
@@ -239,9 +239,12 @@ void account_idle_time(u64 cputime)
  */
 void __account_forceidle_time(struct task_struct *p, u64 delta)
 {
+	unsigned int cpu = task_cpu(p);
+
 	__schedstat_add(p->stats.core_forceidle_sum, delta);
 
-	task_group_account_field(p, CPUTIME_FORCEIDLE, delta);
+	kcpustat_cpu(cpu).cpustat[CPUTIME_FORCEIDLE] += delta;
+	cgroup_account_cputime_field(p, index, tmp);
 }
 #endif
 
-- 
2.39.3


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

* Re: [PATCH] sched/core: fix incorrect cpustat[CPUTIME_FORCEIDLE] update
  2023-11-17 12:56 [PATCH] sched/core: fix incorrect cpustat[CPUTIME_FORCEIDLE] update Cruz Zhao
@ 2023-11-17 19:50 ` kernel test robot
  0 siblings, 0 replies; 2+ messages in thread
From: kernel test robot @ 2023-11-17 19:50 UTC (permalink / raw)
  To: Cruz Zhao, mingo, peterz, juri.lelli, vincent.guittot,
	dietmar.eggemann, rostedt, bsegall, mgorman, bristot, vschneid,
	joel
  Cc: oe-kbuild-all, linux-kernel

Hi Cruz,

kernel test robot noticed the following build errors:

[auto build test ERROR on tip/sched/core]
[also build test ERROR on linus/master v6.7-rc1 next-20231117]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Cruz-Zhao/sched-core-fix-incorrect-cpustat-CPUTIME_FORCEIDLE-update/20231117-205845
base:   tip/sched/core
patch link:    https://lore.kernel.org/r/20231117125624.16745-1-CruzZhao%40linux.alibaba.com
patch subject: [PATCH] sched/core: fix incorrect cpustat[CPUTIME_FORCEIDLE] update
config: x86_64-buildonly-randconfig-004-20231118 (https://download.01.org/0day-ci/archive/20231118/202311180359.AFGF0rnk-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231118/202311180359.AFGF0rnk-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202311180359.AFGF0rnk-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from kernel/sched/build_policy.c:52:
   kernel/sched/cputime.c: In function '__account_forceidle_time':
>> kernel/sched/cputime.c:247:41: error: 'index' undeclared (first use in this function)
     247 |         cgroup_account_cputime_field(p, index, tmp);
         |                                         ^~~~~
   kernel/sched/cputime.c:247:41: note: each undeclared identifier is reported only once for each function it appears in
>> kernel/sched/cputime.c:247:48: error: 'tmp' undeclared (first use in this function); did you mean 'tms'?
     247 |         cgroup_account_cputime_field(p, index, tmp);
         |                                                ^~~
         |                                                tms


vim +/index +247 kernel/sched/cputime.c

   232	
   233	
   234	#ifdef CONFIG_SCHED_CORE
   235	/*
   236	 * Account for forceidle time due to core scheduling.
   237	 *
   238	 * REQUIRES: schedstat is enabled.
   239	 */
   240	void __account_forceidle_time(struct task_struct *p, u64 delta)
   241	{
   242		unsigned int cpu = task_cpu(p);
   243	
   244		__schedstat_add(p->stats.core_forceidle_sum, delta);
   245	
   246		kcpustat_cpu(cpu).cpustat[CPUTIME_FORCEIDLE] += delta;
 > 247		cgroup_account_cputime_field(p, index, tmp);
   248	}
   249	#endif
   250	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

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

end of thread, other threads:[~2023-11-17 19:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-17 12:56 [PATCH] sched/core: fix incorrect cpustat[CPUTIME_FORCEIDLE] update Cruz Zhao
2023-11-17 19:50 ` kernel test robot

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