[PATCH v7 3/4] sched, psi: Don't account irq time if sched_clock_irqtime is disabled

Yafang Shao posted 4 patches 1 year ago
There is a newer version of this series
[PATCH v7 3/4] sched, psi: Don't account irq time if sched_clock_irqtime is disabled
Posted by Yafang Shao 1 year ago
sched_clock_irqtime may be disabled due to the clock source. When disabled,
irq_time_read() won't change over time, so there is nothing to account. We
can save iterating the whole hierarchy on every tick and context switch.

Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Reviewed-by: Michal Koutný <mkoutny@suse.com>
---
 kernel/sched/psi.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c
index 84dad1511d1e..893d454c82ae 100644
--- a/kernel/sched/psi.c
+++ b/kernel/sched/psi.c
@@ -998,7 +998,7 @@ void psi_account_irqtime(struct rq *rq, struct task_struct *curr, struct task_st
 	s64 delta;
 	u64 irq;
 
-	if (static_branch_likely(&psi_disabled))
+	if (static_branch_likely(&psi_disabled) || !irqtime_enabled())
 		return;
 
 	if (!curr->pid)
@@ -1240,6 +1240,9 @@ int psi_show(struct seq_file *m, struct psi_group *group, enum psi_res res)
 	if (static_branch_likely(&psi_disabled))
 		return -EOPNOTSUPP;
 
+	if (!irqtime_enabled() && res == PSI_IRQ)
+		return -EOPNOTSUPP;
+
 	/* Update averages before reporting them */
 	mutex_lock(&group->avgs_lock);
 	now = sched_clock();
-- 
2.43.5

Re: [PATCH v7 3/4] sched, psi: Don't account irq time if sched_clock_irqtime is disabled
Posted by kernel test robot 1 year ago
Hi Yafang,

kernel test robot noticed the following build errors:

[auto build test ERROR on tip/sched/core]
[also build test ERROR on peterz-queue/sched/core linus/master v6.13-rc2 next-20241213]
[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/Yafang-Shao/sched-Define-sched_clock_irqtime-as-static-key/20241215-112638
base:   tip/sched/core
patch link:    https://lore.kernel.org/r/20241215032315.43698-4-laoar.shao%40gmail.com
patch subject: [PATCH v7 3/4] sched, psi: Don't account irq time if sched_clock_irqtime is disabled
config: arm-randconfig-001-20241215 (https://download.01.org/0day-ci/archive/20241215/202412152115.zQ6k9tVk-lkp@intel.com/config)
compiler: clang version 20.0.0git (https://github.com/llvm/llvm-project 2dc22615fd46ab2566d0f26d5ba234ab12dc4bf8)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241215/202412152115.zQ6k9tVk-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/202412152115.zQ6k9tVk-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from kernel/sched/build_utility.c:15:
   In file included from include/linux/sched/isolation.h:5:
   In file included from include/linux/cpuset.h:17:
   In file included from include/linux/mm.h:2223:
   include/linux/vmstat.h:518:36: warning: arithmetic between different enumeration types ('enum node_stat_item' and 'enum lru_list') [-Wenum-enum-conversion]
     518 |         return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_"
         |                               ~~~~~~~~~~~ ^ ~~~
   In file included from kernel/sched/build_utility.c:96:
>> kernel/sched/psi.c:1243:35: error: use of undeclared identifier 'PSI_IRQ'; did you mean 'PSI_IO'?
    1243 |         if (!irqtime_enabled() && res == PSI_IRQ)
         |                                          ^~~~~~~
         |                                          PSI_IO
   include/linux/psi_types.h:42:2: note: 'PSI_IO' declared here
      42 |         PSI_IO,
         |         ^
   1 warning and 1 error generated.


vim +1243 kernel/sched/psi.c

  1233	
  1234	int psi_show(struct seq_file *m, struct psi_group *group, enum psi_res res)
  1235	{
  1236		bool only_full = false;
  1237		int full;
  1238		u64 now;
  1239	
  1240		if (static_branch_likely(&psi_disabled))
  1241			return -EOPNOTSUPP;
  1242	
> 1243		if (!irqtime_enabled() && res == PSI_IRQ)
  1244			return -EOPNOTSUPP;
  1245	
  1246		/* Update averages before reporting them */
  1247		mutex_lock(&group->avgs_lock);
  1248		now = sched_clock();
  1249		collect_percpu_times(group, PSI_AVGS, NULL);
  1250		if (now >= group->avg_next_update)
  1251			group->avg_next_update = update_averages(group, now);
  1252		mutex_unlock(&group->avgs_lock);
  1253	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Re: [PATCH v7 3/4] sched, psi: Don't account irq time if sched_clock_irqtime is disabled
Posted by kernel test robot 1 year ago
Hi Yafang,

kernel test robot noticed the following build errors:

[auto build test ERROR on tip/sched/core]
[also build test ERROR on peterz-queue/sched/core linus/master v6.13-rc2 next-20241213]
[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/Yafang-Shao/sched-Define-sched_clock_irqtime-as-static-key/20241215-112638
base:   tip/sched/core
patch link:    https://lore.kernel.org/r/20241215032315.43698-4-laoar.shao%40gmail.com
patch subject: [PATCH v7 3/4] sched, psi: Don't account irq time if sched_clock_irqtime is disabled
config: arc-randconfig-001-20241215 (https://download.01.org/0day-ci/archive/20241215/202412152009.HZ862kna-lkp@intel.com/config)
compiler: arc-elf-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241215/202412152009.HZ862kna-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/202412152009.HZ862kna-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from kernel/sched/build_utility.c:96:
   kernel/sched/psi.c: In function 'psi_show':
>> kernel/sched/psi.c:1243:42: error: 'PSI_IRQ' undeclared (first use in this function); did you mean 'PSI_IO'?
    1243 |         if (!irqtime_enabled() && res == PSI_IRQ)
         |                                          ^~~~~~~
         |                                          PSI_IO
   kernel/sched/psi.c:1243:42: note: each undeclared identifier is reported only once for each function it appears in


vim +1243 kernel/sched/psi.c

  1233	
  1234	int psi_show(struct seq_file *m, struct psi_group *group, enum psi_res res)
  1235	{
  1236		bool only_full = false;
  1237		int full;
  1238		u64 now;
  1239	
  1240		if (static_branch_likely(&psi_disabled))
  1241			return -EOPNOTSUPP;
  1242	
> 1243		if (!irqtime_enabled() && res == PSI_IRQ)
  1244			return -EOPNOTSUPP;
  1245	
  1246		/* Update averages before reporting them */
  1247		mutex_lock(&group->avgs_lock);
  1248		now = sched_clock();
  1249		collect_percpu_times(group, PSI_AVGS, NULL);
  1250		if (now >= group->avg_next_update)
  1251			group->avg_next_update = update_averages(group, now);
  1252		mutex_unlock(&group->avgs_lock);
  1253	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Re: [PATCH v7 3/4] sched, psi: Don't account irq time if sched_clock_irqtime is disabled
Posted by Yafang Shao 1 year ago
On Sun, Dec 15, 2024 at 9:08 PM kernel test robot <lkp@intel.com> wrote:
>
> Hi Yafang,
>
> kernel test robot noticed the following build errors:
>
> [auto build test ERROR on tip/sched/core]
> [also build test ERROR on peterz-queue/sched/core linus/master v6.13-rc2 next-20241213]
> [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/Yafang-Shao/sched-Define-sched_clock_irqtime-as-static-key/20241215-112638
> base:   tip/sched/core
> patch link:    https://lore.kernel.org/r/20241215032315.43698-4-laoar.shao%40gmail.com
> patch subject: [PATCH v7 3/4] sched, psi: Don't account irq time if sched_clock_irqtime is disabled
> config: arc-randconfig-001-20241215 (https://download.01.org/0day-ci/archive/20241215/202412152009.HZ862kna-lkp@intel.com/config)
> compiler: arc-elf-gcc (GCC) 13.2.0
> reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241215/202412152009.HZ862kna-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/202412152009.HZ862kna-lkp@intel.com/
>
> All errors (new ones prefixed by >>):
>
>    In file included from kernel/sched/build_utility.c:96:
>    kernel/sched/psi.c: In function 'psi_show':
> >> kernel/sched/psi.c:1243:42: error: 'PSI_IRQ' undeclared (first use in this function); did you mean 'PSI_IO'?
>     1243 |         if (!irqtime_enabled() && res == PSI_IRQ)
>          |                                          ^~~~~~~
>          |                                          PSI_IO
>    kernel/sched/psi.c:1243:42: note: each undeclared identifier is reported only once for each function it appears in

Thanks for the report.
will update it as follows,

#ifdef CONFIG_IRQ_TIME_ACCOUNTING
        if (!irqtime_enabled() && res == PSI_IRQ)
                return -EOPNOTSUPP;
#endif

-- 
Regards
Yafang