All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] sched/core: add forced idle accounting for cgroups
@ 2022-05-20 23:51 Josh Don
  2022-05-21  1:31 ` kernel test robot
                   ` (3 more replies)
  0 siblings, 4 replies; 12+ messages in thread
From: Josh Don @ 2022-05-20 23:51 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
	Tejun Heo
  Cc: Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
	Daniel Bristot de Oliveira, Valentin Schneider, linux-kernel,
	Cruz Zhao, Josh Don

4feee7d1260 previously added per-task forced idle accounting. This patch
extends this to also include cgroups.

rstat is used for cgroup accounting, except for the root, which uses
kcpustat in order to bypass the need for doing an rstat flush when
reading root stats.

Only cgroup v2 is supported. Similar to the task accounting, the cgroup
accounting requires that schedstats is enabled.

Signed-off-by: Josh Don <joshdon@google.com>
---
v2: Per Tejun's suggestion, move the forceidle stat to cgroup_base_stat
directly.

 include/linux/cgroup-defs.h |  4 ++++
 include/linux/kernel_stat.h |  7 +++++++
 kernel/cgroup/rstat.c       | 40 +++++++++++++++++++++++++++++++------
 kernel/sched/core_sched.c   |  6 +++++-
 kernel/sched/cputime.c      | 11 ++++++++++
 5 files changed, 61 insertions(+), 7 deletions(-)

diff --git a/include/linux/cgroup-defs.h b/include/linux/cgroup-defs.h
index 1bfcfb1af352..025fd0e84a31 100644
--- a/include/linux/cgroup-defs.h
+++ b/include/linux/cgroup-defs.h
@@ -287,6 +287,10 @@ struct css_set {
 
 struct cgroup_base_stat {
 	struct task_cputime cputime;
+
+#ifdef CONFIG_SCHED_CORE
+	u64 forceidle_sum;
+#endif
 };
 
 /*
diff --git a/include/linux/kernel_stat.h b/include/linux/kernel_stat.h
index 69ae6b278464..94f435ce1df0 100644
--- a/include/linux/kernel_stat.h
+++ b/include/linux/kernel_stat.h
@@ -28,6 +28,9 @@ enum cpu_usage_stat {
 	CPUTIME_STEAL,
 	CPUTIME_GUEST,
 	CPUTIME_GUEST_NICE,
+#ifdef CONFIG_SCHED_CORE
+	CPUTIME_FORCEIDLE,
+#endif
 	NR_STATS,
 };
 
@@ -115,4 +118,8 @@ extern void account_process_tick(struct task_struct *, int user);
 
 extern void account_idle_ticks(unsigned long ticks);
 
+#ifdef CONFIG_SCHED_CORE
+extern void account_forceidle_time(struct task_struct *tsk, u64 delta);
+#endif
+
 #endif /* _LINUX_KERNEL_STAT_H */
diff --git a/kernel/cgroup/rstat.c b/kernel/cgroup/rstat.c
index 24b5c2ab5598..d873de6f8716 100644
--- a/kernel/cgroup/rstat.c
+++ b/kernel/cgroup/rstat.c
@@ -310,6 +310,9 @@ static void cgroup_base_stat_add(struct cgroup_base_stat *dst_bstat,
 	dst_bstat->cputime.utime += src_bstat->cputime.utime;
 	dst_bstat->cputime.stime += src_bstat->cputime.stime;
 	dst_bstat->cputime.sum_exec_runtime += src_bstat->cputime.sum_exec_runtime;
+#ifdef CONFIG_SCHED_CORE
+	dst_bstat->forceidle_sum += src_bstat->forceidle_sum;
+#endif
 }
 
 static void cgroup_base_stat_sub(struct cgroup_base_stat *dst_bstat,
@@ -318,6 +321,9 @@ static void cgroup_base_stat_sub(struct cgroup_base_stat *dst_bstat,
 	dst_bstat->cputime.utime -= src_bstat->cputime.utime;
 	dst_bstat->cputime.stime -= src_bstat->cputime.stime;
 	dst_bstat->cputime.sum_exec_runtime -= src_bstat->cputime.sum_exec_runtime;
+#ifdef CONFIG_SCHED_CORE
+	dst_bstat->forceidle_sum -= src_bstat->forceidle_sum;
+#endif
 }
 
 static void cgroup_base_stat_flush(struct cgroup *cgrp, int cpu)
@@ -398,6 +404,11 @@ void __cgroup_account_cputime_field(struct cgroup *cgrp,
 	case CPUTIME_SOFTIRQ:
 		rstatc->bstat.cputime.stime += delta_exec;
 		break;
+#ifdef CONFIG_SCHED_CORE
+	case CPUTIME_FORCEIDLE:
+		rstatc->bstat.forceidle_sum += delta_exec;
+		break;
+#endif
 	default:
 		break;
 	}
@@ -411,8 +422,9 @@ void __cgroup_account_cputime_field(struct cgroup *cgrp,
  * with how it is done by __cgroup_account_cputime_field for each bit of
  * cpu time attributed to a cgroup.
  */
-static void root_cgroup_cputime(struct task_cputime *cputime)
+static void root_cgroup_cputime(struct cgroup_base_stat *bstat)
 {
+	struct task_cputime *cputime = &bstat->cputime;
 	int i;
 
 	cputime->stime = 0;
@@ -438,6 +450,10 @@ static void root_cgroup_cputime(struct task_cputime *cputime)
 		cputime->sum_exec_runtime += user;
 		cputime->sum_exec_runtime += sys;
 		cputime->sum_exec_runtime += cpustat[CPUTIME_STEAL];
+
+#ifdef CONFIG_SCHED_CORE
+		bstat->forceidle_sum += cpustat[CPUTIME_FORCEIDLE];
+#endif
 	}
 }
 
@@ -445,27 +461,39 @@ void cgroup_base_stat_cputime_show(struct seq_file *seq)
 {
 	struct cgroup *cgrp = seq_css(seq)->cgroup;
 	u64 usage, utime, stime;
-	struct task_cputime cputime;
+	struct cgroup_base_stat bstat;
+	u64 __maybe_unused forceidle_time;
 
 	if (cgroup_parent(cgrp)) {
 		cgroup_rstat_flush_hold(cgrp);
 		usage = cgrp->bstat.cputime.sum_exec_runtime;
 		cputime_adjust(&cgrp->bstat.cputime, &cgrp->prev_cputime,
 			       &utime, &stime);
+#ifdef CONFIG_SCHED_CORE
+		forceidle_time = cgrp->bstat.forceidle_sum;
+#endif
 		cgroup_rstat_flush_release();
 	} else {
-		root_cgroup_cputime(&cputime);
-		usage = cputime.sum_exec_runtime;
-		utime = cputime.utime;
-		stime = cputime.stime;
+		root_cgroup_cputime(&bstat);
+		usage = bstat.cputime.sum_exec_runtime;
+		utime = bstat.cputime.utime;
+		stime = bstat.cputime.stime;
+#ifdef CONFIG_SCHED_CORE
+		forceidle_time = bstat.forceidle_sum;
+#endif
 	}
 
 	do_div(usage, NSEC_PER_USEC);
 	do_div(utime, NSEC_PER_USEC);
 	do_div(stime, NSEC_PER_USEC);
+	do_div(forceidle_time, NSEC_PER_USEC);
 
 	seq_printf(seq, "usage_usec %llu\n"
 		   "user_usec %llu\n"
 		   "system_usec %llu\n",
 		   usage, utime, stime);
+
+#ifdef CONFIG_SCHED_CORE
+	seq_printf(seq, "forceidle_usec %llu\n", forceidle_time);
+#endif
 }
diff --git a/kernel/sched/core_sched.c b/kernel/sched/core_sched.c
index 38a2cec21014..ddef2b8ddf68 100644
--- a/kernel/sched/core_sched.c
+++ b/kernel/sched/core_sched.c
@@ -277,7 +277,11 @@ void __sched_core_account_forceidle(struct rq *rq)
 		if (p == rq_i->idle)
 			continue;
 
-		__schedstat_add(p->stats.core_forceidle_sum, delta);
+		/*
+		 * Note: this will account forceidle to the current cpu, even
+		 * if it comes from our SMT sibling.
+		 */
+		account_forceidle_time(p, delta);
 	}
 }
 
diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
index 78a233d43757..598d1026d629 100644
--- a/kernel/sched/cputime.c
+++ b/kernel/sched/cputime.c
@@ -226,6 +226,17 @@ void account_idle_time(u64 cputime)
 		cpustat[CPUTIME_IDLE] += cputime;
 }
 
+
+#ifdef CONFIG_SCHED_CORE
+/* Account for forceidle time due to core scheduling. */
+void account_forceidle_time(struct task_struct *p, u64 delta)
+{
+	schedstat_add(p->stats.core_forceidle_sum, delta);
+
+	task_group_account_field(p, CPUTIME_FORCEIDLE, delta);
+}
+#endif
+
 /*
  * When a guest is interrupted for a longer amount of time, missed clock
  * ticks are not redelivered later. Due to that, this function may on
-- 
2.36.1.124.g0e6072fb45-goog


^ permalink raw reply related	[flat|nested] 12+ messages in thread
* Re: [PATCH v2] sched/core: add forced idle accounting for cgroups
  2022-05-20 23:51 [PATCH v2] sched/core: add forced idle accounting for cgroups Josh Don
  2022-05-21  1:31 ` kernel test robot
@ 2022-05-23 11:27 ` Dan Carpenter
  2022-05-21  3:19 ` kernel test robot
  2022-05-21 10:00 ` Peter Zijlstra
  3 siblings, 0 replies; 12+ messages in thread
From: kernel test robot @ 2022-05-21  7:32 UTC (permalink / raw)
  To: kbuild

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

CC: kbuild-all(a)lists.01.org
BCC: lkp(a)intel.com
In-Reply-To: <20220520235138.3140590-1-joshdon@google.com>
References: <20220520235138.3140590-1-joshdon@google.com>
TO: Josh Don <joshdon@google.com>
TO: Ingo Molnar <mingo@redhat.com>
TO: Peter Zijlstra <peterz@infradead.org>
TO: Juri Lelli <juri.lelli@redhat.com>
TO: Vincent Guittot <vincent.guittot@linaro.org>
TO: Tejun Heo <tj@kernel.org>
CC: Dietmar Eggemann <dietmar.eggemann@arm.com>
CC: Steven Rostedt <rostedt@goodmis.org>
CC: Ben Segall <bsegall@google.com>
CC: Mel Gorman <mgorman@suse.de>
CC: Daniel Bristot de Oliveira <bristot@redhat.com>
CC: Valentin Schneider <vschneid@redhat.com>
CC: linux-kernel(a)vger.kernel.org
CC: Cruz Zhao <CruzZhao@linux.alibaba.com>
CC: Josh Don <joshdon@google.com>

Hi Josh,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on tj-cgroup/for-next]
[also build test WARNING on tip/sched/core tip/master v5.18-rc7 next-20220520]
[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]

url:    https://github.com/intel-lab-lkp/linux/commits/Josh-Don/sched-core-add-forced-idle-accounting-for-cgroups/20220521-075311
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup.git for-next
:::::: branch date: 8 hours ago
:::::: commit date: 8 hours ago
config: x86_64-randconfig-m001 (https://download.01.org/0day-ci/archive/20220521/202205211525.XlF6P8dM-lkp(a)intel.com/config)
compiler: gcc-11 (Debian 11.3.0-1) 11.3.0

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

smatch warnings:
kernel/cgroup/rstat.c:489 cgroup_base_stat_cputime_show() error: uninitialized symbol 'forceidle_time'.

vim +/forceidle_time +489 kernel/cgroup/rstat.c

936f2a70f2077f kernel/cgroup/rstat.c Boris Burkov 2020-05-27  459  
d4ff749b5e0f1e kernel/cgroup/rstat.c Tejun Heo    2018-04-26  460  void cgroup_base_stat_cputime_show(struct seq_file *seq)
041cd640b2f3c5 kernel/cgroup/stat.c  Tejun Heo    2017-09-25  461  {
041cd640b2f3c5 kernel/cgroup/stat.c  Tejun Heo    2017-09-25  462  	struct cgroup *cgrp = seq_css(seq)->cgroup;
041cd640b2f3c5 kernel/cgroup/stat.c  Tejun Heo    2017-09-25  463  	u64 usage, utime, stime;
0575a42c9f10cd kernel/cgroup/rstat.c Josh Don     2022-05-20  464  	struct cgroup_base_stat bstat;
0575a42c9f10cd kernel/cgroup/rstat.c Josh Don     2022-05-20  465  	u64 __maybe_unused forceidle_time;
041cd640b2f3c5 kernel/cgroup/stat.c  Tejun Heo    2017-09-25  466  
936f2a70f2077f kernel/cgroup/rstat.c Boris Burkov 2020-05-27  467  	if (cgroup_parent(cgrp)) {
6162cef0f741c7 kernel/cgroup/rstat.c Tejun Heo    2018-04-26  468  		cgroup_rstat_flush_hold(cgrp);
d4ff749b5e0f1e kernel/cgroup/rstat.c Tejun Heo    2018-04-26  469  		usage = cgrp->bstat.cputime.sum_exec_runtime;
936f2a70f2077f kernel/cgroup/rstat.c Boris Burkov 2020-05-27  470  		cputime_adjust(&cgrp->bstat.cputime, &cgrp->prev_cputime,
936f2a70f2077f kernel/cgroup/rstat.c Boris Burkov 2020-05-27  471  			       &utime, &stime);
0575a42c9f10cd kernel/cgroup/rstat.c Josh Don     2022-05-20  472  #ifdef CONFIG_SCHED_CORE
0575a42c9f10cd kernel/cgroup/rstat.c Josh Don     2022-05-20  473  		forceidle_time = cgrp->bstat.forceidle_sum;
0575a42c9f10cd kernel/cgroup/rstat.c Josh Don     2022-05-20  474  #endif
6162cef0f741c7 kernel/cgroup/rstat.c Tejun Heo    2018-04-26  475  		cgroup_rstat_flush_release();
936f2a70f2077f kernel/cgroup/rstat.c Boris Burkov 2020-05-27  476  	} else {
0575a42c9f10cd kernel/cgroup/rstat.c Josh Don     2022-05-20  477  		root_cgroup_cputime(&bstat);
0575a42c9f10cd kernel/cgroup/rstat.c Josh Don     2022-05-20  478  		usage = bstat.cputime.sum_exec_runtime;
0575a42c9f10cd kernel/cgroup/rstat.c Josh Don     2022-05-20  479  		utime = bstat.cputime.utime;
0575a42c9f10cd kernel/cgroup/rstat.c Josh Don     2022-05-20  480  		stime = bstat.cputime.stime;
0575a42c9f10cd kernel/cgroup/rstat.c Josh Don     2022-05-20  481  #ifdef CONFIG_SCHED_CORE
0575a42c9f10cd kernel/cgroup/rstat.c Josh Don     2022-05-20  482  		forceidle_time = bstat.forceidle_sum;
0575a42c9f10cd kernel/cgroup/rstat.c Josh Don     2022-05-20  483  #endif
936f2a70f2077f kernel/cgroup/rstat.c Boris Burkov 2020-05-27  484  	}
041cd640b2f3c5 kernel/cgroup/stat.c  Tejun Heo    2017-09-25  485  
041cd640b2f3c5 kernel/cgroup/stat.c  Tejun Heo    2017-09-25  486  	do_div(usage, NSEC_PER_USEC);
041cd640b2f3c5 kernel/cgroup/stat.c  Tejun Heo    2017-09-25  487  	do_div(utime, NSEC_PER_USEC);
041cd640b2f3c5 kernel/cgroup/stat.c  Tejun Heo    2017-09-25  488  	do_div(stime, NSEC_PER_USEC);
0575a42c9f10cd kernel/cgroup/rstat.c Josh Don     2022-05-20 @489  	do_div(forceidle_time, NSEC_PER_USEC);
041cd640b2f3c5 kernel/cgroup/stat.c  Tejun Heo    2017-09-25  490  
d41bf8c9deaed1 kernel/cgroup/stat.c  Tejun Heo    2017-10-23  491  	seq_printf(seq, "usage_usec %llu\n"
d41bf8c9deaed1 kernel/cgroup/stat.c  Tejun Heo    2017-10-23  492  		   "user_usec %llu\n"
d41bf8c9deaed1 kernel/cgroup/stat.c  Tejun Heo    2017-10-23  493  		   "system_usec %llu\n",
d41bf8c9deaed1 kernel/cgroup/stat.c  Tejun Heo    2017-10-23  494  		   usage, utime, stime);
0575a42c9f10cd kernel/cgroup/rstat.c Josh Don     2022-05-20  495  

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

^ permalink raw reply	[flat|nested] 12+ messages in thread
* Re: [PATCH v2] sched/core: add forced idle accounting for cgroups
@ 2022-05-22  6:35 kernel test robot
  0 siblings, 0 replies; 12+ messages in thread
From: kernel test robot @ 2022-05-22  6:35 UTC (permalink / raw)
  To: kbuild

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

CC: llvm(a)lists.linux.dev
CC: kbuild-all(a)lists.01.org
BCC: lkp(a)intel.com
In-Reply-To: <20220520235138.3140590-1-joshdon@google.com>
References: <20220520235138.3140590-1-joshdon@google.com>
TO: Josh Don <joshdon@google.com>
TO: Ingo Molnar <mingo@redhat.com>
TO: Peter Zijlstra <peterz@infradead.org>
TO: Juri Lelli <juri.lelli@redhat.com>
TO: Vincent Guittot <vincent.guittot@linaro.org>
TO: Tejun Heo <tj@kernel.org>
CC: Dietmar Eggemann <dietmar.eggemann@arm.com>
CC: Steven Rostedt <rostedt@goodmis.org>
CC: Ben Segall <bsegall@google.com>
CC: Mel Gorman <mgorman@suse.de>
CC: Daniel Bristot de Oliveira <bristot@redhat.com>
CC: Valentin Schneider <vschneid@redhat.com>
CC: linux-kernel(a)vger.kernel.org
CC: Cruz Zhao <CruzZhao@linux.alibaba.com>
CC: Josh Don <joshdon@google.com>

Hi Josh,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on tj-cgroup/for-next]
[also build test WARNING on tip/sched/core tip/master v5.18-rc7 next-20220520]
[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]

url:    https://github.com/intel-lab-lkp/linux/commits/Josh-Don/sched-core-add-forced-idle-accounting-for-cgroups/20220521-075311
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup.git for-next
:::::: branch date: 31 hours ago
:::::: commit date: 31 hours ago
config: x86_64-randconfig-c007 (https://download.01.org/0day-ci/archive/20220522/202205221414.PmwthuWY-lkp(a)intel.com/config)
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project b369762beb70dfef22c7e793aed79b94d7dc0757)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/0575a42c9f10cda618b09b949cc42fe97abea479
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Josh-Don/sched-core-add-forced-idle-accounting-for-cgroups/20220521-075311
        git checkout 0575a42c9f10cda618b09b949cc42fe97abea479
        # save the config file
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64 clang-analyzer 

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>


clang-analyzer warnings: (new ones prefixed by >>)
           __underlying_##op(p, q, __fortify_size);                        \
           ^~~~~~~~~~~~~~~~~
   note: expanded from here
   include/linux/fortify-string.h:45:29: note: expanded from macro '__underlying_memcpy'
   #define __underlying_memcpy     __builtin_memcpy
                                   ^~~~~~~~~~~~~~~~
   fs/ntfs3/inode.c:1394:3: note: Call to function 'memcpy' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memcpy_s' in case of C11
                   memcpy(Add2Ptr(attr, SIZEOF_RESIDENT), I30_NAME,
                   ^
   include/linux/fortify-string.h:369:26: note: expanded from macro 'memcpy'
   #define memcpy(p, q, s)  __fortify_memcpy_chk(p, q, s,                  \
                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/fortify-string.h:362:2: note: expanded from macro '__fortify_memcpy_chk'
           __underlying_##op(p, q, __fortify_size);                        \
           ^~~~~~~~~~~~~~~~~
   note: expanded from here
   include/linux/fortify-string.h:45:29: note: expanded from macro '__underlying_memcpy'
   #define __underlying_memcpy     __builtin_memcpy
                                   ^~~~~~~~~~~~~~~~
   fs/ntfs3/inode.c:1398:3: warning: Call to function 'memcpy' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memcpy_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]
                   memcpy(root, dir_root, offsetof(struct INDEX_ROOT, ihdr));
                   ^
   include/linux/fortify-string.h:369:26: note: expanded from macro 'memcpy'
   #define memcpy(p, q, s)  __fortify_memcpy_chk(p, q, s,                  \
                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/fortify-string.h:362:2: note: expanded from macro '__fortify_memcpy_chk'
           __underlying_##op(p, q, __fortify_size);                        \
           ^~~~~~~~~~~~~~~~~
   note: expanded from here
   include/linux/fortify-string.h:45:29: note: expanded from macro '__underlying_memcpy'
   #define __underlying_memcpy     __builtin_memcpy
                                   ^~~~~~~~~~~~~~~~
   fs/ntfs3/inode.c:1398:3: note: Call to function 'memcpy' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memcpy_s' in case of C11
                   memcpy(root, dir_root, offsetof(struct INDEX_ROOT, ihdr));
                   ^
   include/linux/fortify-string.h:369:26: note: expanded from macro 'memcpy'
   #define memcpy(p, q, s)  __fortify_memcpy_chk(p, q, s,                  \
                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/fortify-string.h:362:2: note: expanded from macro '__fortify_memcpy_chk'
           __underlying_##op(p, q, __fortify_size);                        \
           ^~~~~~~~~~~~~~~~~
   note: expanded from here
   include/linux/fortify-string.h:45:29: note: expanded from macro '__underlying_memcpy'
   #define __underlying_memcpy     __builtin_memcpy
                                   ^~~~~~~~~~~~~~~~
   fs/ntfs3/inode.c:1526:4: warning: Call to function 'memcpy' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memcpy_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]
                           memcpy(Add2Ptr(attr, SIZEOF_RESIDENT), rp, nsize);
                           ^
   include/linux/fortify-string.h:369:26: note: expanded from macro 'memcpy'
   #define memcpy(p, q, s)  __fortify_memcpy_chk(p, q, s,                  \
                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/fortify-string.h:362:2: note: expanded from macro '__fortify_memcpy_chk'
           __underlying_##op(p, q, __fortify_size);                        \
           ^~~~~~~~~~~~~~~~~
   note: expanded from here
   include/linux/fortify-string.h:45:29: note: expanded from macro '__underlying_memcpy'
   #define __underlying_memcpy     __builtin_memcpy
                                   ^~~~~~~~~~~~~~~~
   fs/ntfs3/inode.c:1526:4: note: Call to function 'memcpy' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memcpy_s' in case of C11
                           memcpy(Add2Ptr(attr, SIZEOF_RESIDENT), rp, nsize);
                           ^
   include/linux/fortify-string.h:369:26: note: expanded from macro 'memcpy'
   #define memcpy(p, q, s)  __fortify_memcpy_chk(p, q, s,                  \
                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/fortify-string.h:362:2: note: expanded from macro '__fortify_memcpy_chk'
           __underlying_##op(p, q, __fortify_size);                        \
           ^~~~~~~~~~~~~~~~~
   note: expanded from here
   include/linux/fortify-string.h:45:29: note: expanded from macro '__underlying_memcpy'
   #define __underlying_memcpy     __builtin_memcpy
                                   ^~~~~~~~~~~~~~~~
   fs/ntfs3/inode.c:1862:3: warning: Call to function 'memcpy' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memcpy_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]
                   memcpy(buffer, "OneDrive", err);
                   ^
   include/linux/fortify-string.h:369:26: note: expanded from macro 'memcpy'
   #define memcpy(p, q, s)  __fortify_memcpy_chk(p, q, s,                  \
                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/fortify-string.h:362:2: note: expanded from macro '__fortify_memcpy_chk'
           __underlying_##op(p, q, __fortify_size);                        \
           ^~~~~~~~~~~~~~~~~
   note: expanded from here
   include/linux/fortify-string.h:45:29: note: expanded from macro '__underlying_memcpy'
   #define __underlying_memcpy     __builtin_memcpy
                                   ^~~~~~~~~~~~~~~~
   fs/ntfs3/inode.c:1862:3: note: Call to function 'memcpy' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memcpy_s' in case of C11
                   memcpy(buffer, "OneDrive", err);
                   ^
   include/linux/fortify-string.h:369:26: note: expanded from macro 'memcpy'
   #define memcpy(p, q, s)  __fortify_memcpy_chk(p, q, s,                  \
                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/fortify-string.h:362:2: note: expanded from macro '__fortify_memcpy_chk'
           __underlying_##op(p, q, __fortify_size);                        \
           ^~~~~~~~~~~~~~~~~
   note: expanded from here
   include/linux/fortify-string.h:45:29: note: expanded from macro '__underlying_memcpy'
   #define __underlying_memcpy     __builtin_memcpy
                                   ^~~~~~~~~~~~~~~~
   Suppressed 47 warnings (47 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   38 warnings generated.
>> kernel/cgroup/rstat.c:455:24: warning: The left expression of the compound assignment is an uninitialized value. The computed value will also be garbage [clang-analyzer-core.uninitialized.Assign]
                   bstat->forceidle_sum += cpustat[CPUTIME_FORCEIDLE];
                                        ^
   kernel/cgroup/rstat.c:467:2: note: Taking false branch
           if (cgroup_parent(cgrp)) {
           ^
   kernel/cgroup/rstat.c:477:3: note: Calling 'root_cgroup_cputime'
                   root_cgroup_cputime(&bstat);
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~
   kernel/cgroup/rstat.c:433:2: note: Assuming 'i' is < 'nr_cpu_ids'
           for_each_possible_cpu(i) {
           ^
   include/linux/cpumask.h:814:36: note: expanded from macro 'for_each_possible_cpu'
   #define for_each_possible_cpu(cpu) for_each_cpu((cpu), cpu_possible_mask)
                                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/cpumask.h:278:3: note: expanded from macro 'for_each_cpu'
                   (cpu) < nr_cpu_ids;)
                   ^~~~~~~~~~~~~~~~~~
   kernel/cgroup/rstat.c:433:2: note: Loop condition is true.  Entering loop body
           for_each_possible_cpu(i) {
           ^
   include/linux/cpumask.h:814:36: note: expanded from macro 'for_each_possible_cpu'
   #define for_each_possible_cpu(cpu) for_each_cpu((cpu), cpu_possible_mask)
                                      ^
   include/linux/cpumask.h:276:2: note: expanded from macro 'for_each_cpu'
           for ((cpu) = -1;                                \
           ^
   kernel/cgroup/rstat.c:455:24: note: The left expression of the compound assignment is an uninitialized value. The computed value will also be garbage
                   bstat->forceidle_sum += cpustat[CPUTIME_FORCEIDLE];
                   ~~~~~~~~~~~~~~~~~~~~ ^
>> kernel/cgroup/rstat.c:482:18: warning: Assigned value is garbage or undefined [clang-analyzer-core.uninitialized.Assign]
                   forceidle_time = bstat.forceidle_sum;
                                  ^ ~~~~~~~~~~~~~~~~~~~
   kernel/cgroup/rstat.c:467:2: note: Taking false branch
           if (cgroup_parent(cgrp)) {
           ^
   kernel/cgroup/rstat.c:477:3: note: Calling 'root_cgroup_cputime'
                   root_cgroup_cputime(&bstat);
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~
   kernel/cgroup/rstat.c:433:2: note: Assuming 'i' is >= 'nr_cpu_ids'
           for_each_possible_cpu(i) {
           ^
   include/linux/cpumask.h:814:36: note: expanded from macro 'for_each_possible_cpu'
   #define for_each_possible_cpu(cpu) for_each_cpu((cpu), cpu_possible_mask)
                                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/cpumask.h:278:3: note: expanded from macro 'for_each_cpu'
                   (cpu) < nr_cpu_ids;)
                   ^~~~~~~~~~~~~~~~~~
   kernel/cgroup/rstat.c:433:2: note: Loop condition is false. Execution continues on line 433
           for_each_possible_cpu(i) {
           ^
   include/linux/cpumask.h:814:36: note: expanded from macro 'for_each_possible_cpu'
   #define for_each_possible_cpu(cpu) for_each_cpu((cpu), cpu_possible_mask)
                                      ^
   include/linux/cpumask.h:276:2: note: expanded from macro 'for_each_cpu'
           for ((cpu) = -1;                                \
           ^
   kernel/cgroup/rstat.c:458:1: note: Returning without writing to 'bstat->forceidle_sum'
   }
   ^
   kernel/cgroup/rstat.c:477:3: note: Returning from 'root_cgroup_cputime'
                   root_cgroup_cputime(&bstat);
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~
   kernel/cgroup/rstat.c:482:18: note: Assigned value is garbage or undefined
                   forceidle_time = bstat.forceidle_sum;
                                  ^ ~~~~~~~~~~~~~~~~~~~
   Suppressed 36 warnings (36 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   25 warnings generated.
   Suppressed 25 warnings (25 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   25 warnings generated.
   Suppressed 25 warnings (25 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   25 warnings generated.
   Suppressed 25 warnings (25 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   26 warnings generated.
   Suppressed 26 warnings (26 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   47 warnings generated.
   drivers/iio/adc/ad7606.c:660:9: warning: Called function pointer is null (null dereference) [clang-analyzer-core.CallAndMessage]
                   ret = st->bops->sw_mode_config(indio_dev);
                         ^~~~~~~~~~~~~~~~~~~~~~~~
   drivers/iio/adc/ad7606.c:575:6: note: Assuming 'indio_dev' is non-null
           if (!indio_dev)
               ^~~~~~~~~~
   drivers/iio/adc/ad7606.c:575:2: note: Taking false branch
           if (!indio_dev)
           ^
   drivers/iio/adc/ad7606.c:582:2: note: Loop condition is false.  Exiting loop
           mutex_init(&st->lock);
           ^
   include/linux/mutex.h:101:32: note: expanded from macro 'mutex_init'
   #define mutex_init(mutex)                                               \
                                                                           ^
   drivers/iio/adc/ad7606.c:592:2: note: Taking false branch
           if (IS_ERR(st->reg))
           ^
   drivers/iio/adc/ad7606.c:596:6: note: Assuming 'ret' is 0
           if (ret) {
               ^~~
   drivers/iio/adc/ad7606.c:596:2: note: Taking false branch
           if (ret) {
           ^
   drivers/iio/adc/ad7606.c:601:8: note: Calling 'devm_add_action_or_reset'
           ret = devm_add_action_or_reset(dev, ad7606_regulator_disable, st);
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/device.h:255:6: note: Assuming 'ret' is 0, which participates in a condition later
           if (ret)
               ^~~
   include/linux/device.h:255:2: note: Taking false branch
           if (ret)
           ^
   include/linux/device.h:258:2: note: Returning zero (loaded from 'ret'), which participates in a condition later
           return ret;
           ^~~~~~~~~~
   drivers/iio/adc/ad7606.c:601:8: note: Returning from 'devm_add_action_or_reset'
           ret = devm_add_action_or_reset(dev, ad7606_regulator_disable, st);
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/iio/adc/ad7606.c:602:6: note: 'ret' is 0
           if (ret)
               ^~~
   drivers/iio/adc/ad7606.c:602:2: note: Taking false branch
           if (ret)
           ^
   drivers/iio/adc/ad7606.c:607:6: note: Assuming field 'oversampling_num' is 0
           if (st->chip_info->oversampling_num) {
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/iio/adc/ad7606.c:607:2: note: Taking false branch
           if (st->chip_info->oversampling_num) {

vim +455 kernel/cgroup/rstat.c

041cd640b2f3c5 kernel/cgroup/stat.c  Tejun Heo    2017-09-25  418  
936f2a70f2077f kernel/cgroup/rstat.c Boris Burkov 2020-05-27  419  /*
936f2a70f2077f kernel/cgroup/rstat.c Boris Burkov 2020-05-27  420   * compute the cputime for the root cgroup by getting the per cpu data
936f2a70f2077f kernel/cgroup/rstat.c Boris Burkov 2020-05-27  421   * at a global level, then categorizing the fields in a manner consistent
936f2a70f2077f kernel/cgroup/rstat.c Boris Burkov 2020-05-27  422   * with how it is done by __cgroup_account_cputime_field for each bit of
936f2a70f2077f kernel/cgroup/rstat.c Boris Burkov 2020-05-27  423   * cpu time attributed to a cgroup.
936f2a70f2077f kernel/cgroup/rstat.c Boris Burkov 2020-05-27  424   */
0575a42c9f10cd kernel/cgroup/rstat.c Josh Don     2022-05-20  425  static void root_cgroup_cputime(struct cgroup_base_stat *bstat)
936f2a70f2077f kernel/cgroup/rstat.c Boris Burkov 2020-05-27  426  {
0575a42c9f10cd kernel/cgroup/rstat.c Josh Don     2022-05-20  427  	struct task_cputime *cputime = &bstat->cputime;
936f2a70f2077f kernel/cgroup/rstat.c Boris Burkov 2020-05-27  428  	int i;
936f2a70f2077f kernel/cgroup/rstat.c Boris Burkov 2020-05-27  429  
936f2a70f2077f kernel/cgroup/rstat.c Boris Burkov 2020-05-27  430  	cputime->stime = 0;
936f2a70f2077f kernel/cgroup/rstat.c Boris Burkov 2020-05-27  431  	cputime->utime = 0;
936f2a70f2077f kernel/cgroup/rstat.c Boris Burkov 2020-05-27  432  	cputime->sum_exec_runtime = 0;
936f2a70f2077f kernel/cgroup/rstat.c Boris Burkov 2020-05-27  433  	for_each_possible_cpu(i) {
936f2a70f2077f kernel/cgroup/rstat.c Boris Burkov 2020-05-27  434  		struct kernel_cpustat kcpustat;
936f2a70f2077f kernel/cgroup/rstat.c Boris Burkov 2020-05-27  435  		u64 *cpustat = kcpustat.cpustat;
936f2a70f2077f kernel/cgroup/rstat.c Boris Burkov 2020-05-27  436  		u64 user = 0;
936f2a70f2077f kernel/cgroup/rstat.c Boris Burkov 2020-05-27  437  		u64 sys = 0;
936f2a70f2077f kernel/cgroup/rstat.c Boris Burkov 2020-05-27  438  
936f2a70f2077f kernel/cgroup/rstat.c Boris Burkov 2020-05-27  439  		kcpustat_cpu_fetch(&kcpustat, i);
936f2a70f2077f kernel/cgroup/rstat.c Boris Burkov 2020-05-27  440  
936f2a70f2077f kernel/cgroup/rstat.c Boris Burkov 2020-05-27  441  		user += cpustat[CPUTIME_USER];
936f2a70f2077f kernel/cgroup/rstat.c Boris Burkov 2020-05-27  442  		user += cpustat[CPUTIME_NICE];
936f2a70f2077f kernel/cgroup/rstat.c Boris Burkov 2020-05-27  443  		cputime->utime += user;
936f2a70f2077f kernel/cgroup/rstat.c Boris Burkov 2020-05-27  444  
936f2a70f2077f kernel/cgroup/rstat.c Boris Burkov 2020-05-27  445  		sys += cpustat[CPUTIME_SYSTEM];
936f2a70f2077f kernel/cgroup/rstat.c Boris Burkov 2020-05-27  446  		sys += cpustat[CPUTIME_IRQ];
936f2a70f2077f kernel/cgroup/rstat.c Boris Burkov 2020-05-27  447  		sys += cpustat[CPUTIME_SOFTIRQ];
936f2a70f2077f kernel/cgroup/rstat.c Boris Burkov 2020-05-27  448  		cputime->stime += sys;
936f2a70f2077f kernel/cgroup/rstat.c Boris Burkov 2020-05-27  449  
936f2a70f2077f kernel/cgroup/rstat.c Boris Burkov 2020-05-27  450  		cputime->sum_exec_runtime += user;
936f2a70f2077f kernel/cgroup/rstat.c Boris Burkov 2020-05-27  451  		cputime->sum_exec_runtime += sys;
936f2a70f2077f kernel/cgroup/rstat.c Boris Burkov 2020-05-27  452  		cputime->sum_exec_runtime += cpustat[CPUTIME_STEAL];
0575a42c9f10cd kernel/cgroup/rstat.c Josh Don     2022-05-20  453  
0575a42c9f10cd kernel/cgroup/rstat.c Josh Don     2022-05-20  454  #ifdef CONFIG_SCHED_CORE
0575a42c9f10cd kernel/cgroup/rstat.c Josh Don     2022-05-20 @455  		bstat->forceidle_sum += cpustat[CPUTIME_FORCEIDLE];
0575a42c9f10cd kernel/cgroup/rstat.c Josh Don     2022-05-20  456  #endif
936f2a70f2077f kernel/cgroup/rstat.c Boris Burkov 2020-05-27  457  	}
936f2a70f2077f kernel/cgroup/rstat.c Boris Burkov 2020-05-27  458  }
936f2a70f2077f kernel/cgroup/rstat.c Boris Burkov 2020-05-27  459  
d4ff749b5e0f1e kernel/cgroup/rstat.c Tejun Heo    2018-04-26  460  void cgroup_base_stat_cputime_show(struct seq_file *seq)
041cd640b2f3c5 kernel/cgroup/stat.c  Tejun Heo    2017-09-25  461  {
041cd640b2f3c5 kernel/cgroup/stat.c  Tejun Heo    2017-09-25  462  	struct cgroup *cgrp = seq_css(seq)->cgroup;
041cd640b2f3c5 kernel/cgroup/stat.c  Tejun Heo    2017-09-25  463  	u64 usage, utime, stime;
0575a42c9f10cd kernel/cgroup/rstat.c Josh Don     2022-05-20  464  	struct cgroup_base_stat bstat;
0575a42c9f10cd kernel/cgroup/rstat.c Josh Don     2022-05-20  465  	u64 __maybe_unused forceidle_time;
041cd640b2f3c5 kernel/cgroup/stat.c  Tejun Heo    2017-09-25  466  
936f2a70f2077f kernel/cgroup/rstat.c Boris Burkov 2020-05-27  467  	if (cgroup_parent(cgrp)) {
6162cef0f741c7 kernel/cgroup/rstat.c Tejun Heo    2018-04-26  468  		cgroup_rstat_flush_hold(cgrp);
d4ff749b5e0f1e kernel/cgroup/rstat.c Tejun Heo    2018-04-26  469  		usage = cgrp->bstat.cputime.sum_exec_runtime;
936f2a70f2077f kernel/cgroup/rstat.c Boris Burkov 2020-05-27  470  		cputime_adjust(&cgrp->bstat.cputime, &cgrp->prev_cputime,
936f2a70f2077f kernel/cgroup/rstat.c Boris Burkov 2020-05-27  471  			       &utime, &stime);
0575a42c9f10cd kernel/cgroup/rstat.c Josh Don     2022-05-20  472  #ifdef CONFIG_SCHED_CORE
0575a42c9f10cd kernel/cgroup/rstat.c Josh Don     2022-05-20  473  		forceidle_time = cgrp->bstat.forceidle_sum;
0575a42c9f10cd kernel/cgroup/rstat.c Josh Don     2022-05-20  474  #endif
6162cef0f741c7 kernel/cgroup/rstat.c Tejun Heo    2018-04-26  475  		cgroup_rstat_flush_release();
936f2a70f2077f kernel/cgroup/rstat.c Boris Burkov 2020-05-27  476  	} else {
0575a42c9f10cd kernel/cgroup/rstat.c Josh Don     2022-05-20  477  		root_cgroup_cputime(&bstat);
0575a42c9f10cd kernel/cgroup/rstat.c Josh Don     2022-05-20  478  		usage = bstat.cputime.sum_exec_runtime;
0575a42c9f10cd kernel/cgroup/rstat.c Josh Don     2022-05-20  479  		utime = bstat.cputime.utime;
0575a42c9f10cd kernel/cgroup/rstat.c Josh Don     2022-05-20  480  		stime = bstat.cputime.stime;
0575a42c9f10cd kernel/cgroup/rstat.c Josh Don     2022-05-20  481  #ifdef CONFIG_SCHED_CORE
0575a42c9f10cd kernel/cgroup/rstat.c Josh Don     2022-05-20 @482  		forceidle_time = bstat.forceidle_sum;
0575a42c9f10cd kernel/cgroup/rstat.c Josh Don     2022-05-20  483  #endif
936f2a70f2077f kernel/cgroup/rstat.c Boris Burkov 2020-05-27  484  	}
041cd640b2f3c5 kernel/cgroup/stat.c  Tejun Heo    2017-09-25  485  
041cd640b2f3c5 kernel/cgroup/stat.c  Tejun Heo    2017-09-25  486  	do_div(usage, NSEC_PER_USEC);
041cd640b2f3c5 kernel/cgroup/stat.c  Tejun Heo    2017-09-25  487  	do_div(utime, NSEC_PER_USEC);
041cd640b2f3c5 kernel/cgroup/stat.c  Tejun Heo    2017-09-25  488  	do_div(stime, NSEC_PER_USEC);
0575a42c9f10cd kernel/cgroup/rstat.c Josh Don     2022-05-20  489  	do_div(forceidle_time, NSEC_PER_USEC);
041cd640b2f3c5 kernel/cgroup/stat.c  Tejun Heo    2017-09-25  490  
d41bf8c9deaed1 kernel/cgroup/stat.c  Tejun Heo    2017-10-23  491  	seq_printf(seq, "usage_usec %llu\n"
d41bf8c9deaed1 kernel/cgroup/stat.c  Tejun Heo    2017-10-23  492  		   "user_usec %llu\n"
d41bf8c9deaed1 kernel/cgroup/stat.c  Tejun Heo    2017-10-23  493  		   "system_usec %llu\n",
d41bf8c9deaed1 kernel/cgroup/stat.c  Tejun Heo    2017-10-23  494  		   usage, utime, stime);
0575a42c9f10cd kernel/cgroup/rstat.c Josh Don     2022-05-20  495  

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

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

end of thread, other threads:[~2022-05-23 21:20 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-05-20 23:51 [PATCH v2] sched/core: add forced idle accounting for cgroups Josh Don
2022-05-21  1:31 ` kernel test robot
2022-05-21  2:38 ` kernel test robot
2022-05-21  3:19 ` kernel test robot
2022-05-21 10:00 ` Peter Zijlstra
2022-05-23 21:19   ` Josh Don
  -- strict thread matches above, loose matches on Subject: below --
2022-05-21  7:32 kernel test robot
2022-05-23 11:27 ` Dan Carpenter
2022-05-23 11:27 ` Dan Carpenter
2022-05-23 21:20 ` Josh Don
2022-05-23 21:20   ` Josh Don
2022-05-22  6:35 kernel test robot

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.