All of lore.kernel.org
 help / color / mirror / Atom feed
From: kernel test robot <lkp@intel.com>
To: oe-kbuild@lists.linux.dev
Cc: lkp@intel.com, Dan Carpenter <error27@gmail.com>
Subject: [qais-yousef:schedqos 13/13] kernel/sched/fair.c:9528 cpu_util() error: we previously assumed 'p' could be null (see line 9480)
Date: Thu, 26 Nov 2026 09:59:46 +0100	[thread overview]
Message-ID: <20261126095005.yLvASGiX-lkp@intel.com> (raw)

Unfiltered warning: this smatch report is sent as-is and has not been
reviewed for false positives, so please treat it with due skepticism.

BCC: lkp@intel.com
CC: oe-kbuild-all@lists.linux.dev
TO: Qais Yousef <qyousef@layalina.io>

tree:   https://github.com/qais-yousef/linux schedqos
head:   8e826d3d7ebbfa9b3452a017ddcd4b827e318436
commit: 8e826d3d7ebbfa9b3452a017ddcd4b827e318436 [13/13] HACK: Hide runnable avg bug causing schedutil to run at max
:::::: branch date: 5 hours ago
:::::: commit date: 5 hours ago
config: powerpc64-randconfig-2200-20261126 (https://download.01.org/0day-ci/archive/20261126/20261126095005.yLvASGiX-lkp@intel.com/config)
compiler: clang version 24.0.0git (https://github.com/llvm/llvm-project a2bea097c8bf336f31f45e88e96f20d88e37ff5a)
smatch: v0.5.0-9187-g5189e3fb

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>
| Reported-by: Dan Carpenter <error27@gmail.com>
| Closes: https://lore.kernel.org/r/20261126095005.yLvASGiX-lkp@intel.com/

smatch warnings:
kernel/sched/fair.c:9528 cpu_util() error: we previously assumed 'p' could be null (see line 9480)

vim +/p +9528 kernel/sched/fair.c

231678b768da07d Dietmar Eggemann 2015-08-14  9434  
3eb6d6ececca2fd Dietmar Eggemann 2023-05-15  9435  /**
3eb6d6ececca2fd Dietmar Eggemann 2023-05-15  9436   * cpu_util() - Estimates the amount of CPU capacity used by CFS tasks.
3eb6d6ececca2fd Dietmar Eggemann 2023-05-15  9437   * @cpu: the CPU to get the utilization for
3eb6d6ececca2fd Dietmar Eggemann 2023-05-15  9438   * @p: task for which the CPU utilization should be predicted or NULL
3eb6d6ececca2fd Dietmar Eggemann 2023-05-15  9439   * @dst_cpu: CPU @p migrates to, -1 if @p moves from @cpu or @p == NULL
7d0583cf9ec7bf8 Dietmar Eggemann 2023-05-15  9440   * @boost: 1 to enable boosting, otherwise 0
3eb6d6ececca2fd Dietmar Eggemann 2023-05-15  9441   *
3eb6d6ececca2fd Dietmar Eggemann 2023-05-15  9442   * The unit of the return value must be the same as the one of CPU capacity
3eb6d6ececca2fd Dietmar Eggemann 2023-05-15  9443   * so that CPU utilization can be compared with CPU capacity.
3eb6d6ececca2fd Dietmar Eggemann 2023-05-15  9444   *
3eb6d6ececca2fd Dietmar Eggemann 2023-05-15  9445   * CPU utilization is the sum of running time of runnable tasks plus the
3eb6d6ececca2fd Dietmar Eggemann 2023-05-15  9446   * recent utilization of currently non-runnable tasks on that CPU.
3eb6d6ececca2fd Dietmar Eggemann 2023-05-15  9447   * It represents the amount of CPU capacity currently used by CFS tasks in
3eb6d6ececca2fd Dietmar Eggemann 2023-05-15  9448   * the range [0..max CPU capacity] with max CPU capacity being the CPU
3eb6d6ececca2fd Dietmar Eggemann 2023-05-15  9449   * capacity at f_max.
3eb6d6ececca2fd Dietmar Eggemann 2023-05-15  9450   *
3eb6d6ececca2fd Dietmar Eggemann 2023-05-15  9451   * The estimated CPU utilization is defined as the maximum between CPU
3eb6d6ececca2fd Dietmar Eggemann 2023-05-15  9452   * utilization and sum of the estimated utilization of the currently
3eb6d6ececca2fd Dietmar Eggemann 2023-05-15  9453   * runnable tasks on that CPU. It preserves a utilization "snapshot" of
3eb6d6ececca2fd Dietmar Eggemann 2023-05-15  9454   * previously-executed tasks, which helps better deduce how busy a CPU will
3eb6d6ececca2fd Dietmar Eggemann 2023-05-15  9455   * be when a long-sleeping task wakes up. The contribution to CPU utilization
3eb6d6ececca2fd Dietmar Eggemann 2023-05-15  9456   * of such a task would be significantly decayed at this point of time.
3eb6d6ececca2fd Dietmar Eggemann 2023-05-15  9457   *
7d0583cf9ec7bf8 Dietmar Eggemann 2023-05-15  9458   * Boosted CPU utilization is defined as max(CPU runnable, CPU utilization).
7d0583cf9ec7bf8 Dietmar Eggemann 2023-05-15  9459   * CPU contention for CFS tasks can be detected by CPU runnable > CPU
7d0583cf9ec7bf8 Dietmar Eggemann 2023-05-15  9460   * utilization. Boosting is implemented in cpu_util() so that internal
7d0583cf9ec7bf8 Dietmar Eggemann 2023-05-15  9461   * users (e.g. EAS) can use it next to external users (e.g. schedutil),
7d0583cf9ec7bf8 Dietmar Eggemann 2023-05-15  9462   * latter via cpu_util_cfs_boost().
7d0583cf9ec7bf8 Dietmar Eggemann 2023-05-15  9463   *
3eb6d6ececca2fd Dietmar Eggemann 2023-05-15  9464   * CPU utilization can be higher than the current CPU capacity
3eb6d6ececca2fd Dietmar Eggemann 2023-05-15  9465   * (f_curr/f_max * max CPU capacity) or even the max CPU capacity because
3eb6d6ececca2fd Dietmar Eggemann 2023-05-15  9466   * of rounding errors as well as task migrations or wakeups of new tasks.
3eb6d6ececca2fd Dietmar Eggemann 2023-05-15  9467   * CPU utilization has to be capped to fit into the [0..max CPU capacity]
3eb6d6ececca2fd Dietmar Eggemann 2023-05-15  9468   * range. Otherwise a group of CPUs (CPU0 util = 121% + CPU1 util = 80%)
3eb6d6ececca2fd Dietmar Eggemann 2023-05-15  9469   * could be seen as over-utilized even though CPU1 has 20% of spare CPU
3eb6d6ececca2fd Dietmar Eggemann 2023-05-15  9470   * capacity. CPU utilization is allowed to overshoot current CPU capacity
3eb6d6ececca2fd Dietmar Eggemann 2023-05-15  9471   * though since this is useful for predicting the CPU capacity required
3eb6d6ececca2fd Dietmar Eggemann 2023-05-15  9472   * after task migrations (scheduler-driven DVFS).
3eb6d6ececca2fd Dietmar Eggemann 2023-05-15  9473   *
7d0583cf9ec7bf8 Dietmar Eggemann 2023-05-15  9474   * Return: (Boosted) (estimated) utilization for the specified CPU.
3eb6d6ececca2fd Dietmar Eggemann 2023-05-15  9475   */
7d0583cf9ec7bf8 Dietmar Eggemann 2023-05-15  9476  static unsigned long
7d0583cf9ec7bf8 Dietmar Eggemann 2023-05-15  9477  cpu_util(int cpu, struct task_struct *p, int dst_cpu, int boost)
390031e4c309c94 Quentin Perret   2018-12-03  9478  {
29922fdfc2a4008 Hongyan Xia      2026-06-05  9479  	bool add_task = p && task_cpu(p) != cpu && dst_cpu == cpu;
29922fdfc2a4008 Hongyan Xia      2026-06-05 @9480  	bool sub_task = p && task_cpu(p) == cpu && dst_cpu != cpu;
390031e4c309c94 Quentin Perret   2018-12-03  9481  	struct cfs_rq *cfs_rq = &cpu_rq(cpu)->cfs;
4e3c7d338a22604 Dietmar Eggemann 2022-03-18  9482  	unsigned long util = READ_ONCE(cfs_rq->avg.util_avg);
7d0583cf9ec7bf8 Dietmar Eggemann 2023-05-15  9483  	unsigned long runnable;
7d0583cf9ec7bf8 Dietmar Eggemann 2023-05-15  9484  
390031e4c309c94 Quentin Perret   2018-12-03  9485  	/*
4e3c7d338a22604 Dietmar Eggemann 2022-03-18  9486  	 * If @dst_cpu is -1 or @p migrates from @cpu to @dst_cpu remove its
4e3c7d338a22604 Dietmar Eggemann 2022-03-18  9487  	 * contribution. If @p migrates from another CPU to @cpu add its
4e3c7d338a22604 Dietmar Eggemann 2022-03-18  9488  	 * contribution. In all the other cases @cpu is not impacted by the
4e3c7d338a22604 Dietmar Eggemann 2022-03-18  9489  	 * migration so its util_avg is already correct.
390031e4c309c94 Quentin Perret   2018-12-03  9490  	 */
29922fdfc2a4008 Hongyan Xia      2026-06-05  9491  	if (add_task)
390031e4c309c94 Quentin Perret   2018-12-03  9492  		util += task_util(p);
29922fdfc2a4008 Hongyan Xia      2026-06-05  9493  	else if (sub_task)
29922fdfc2a4008 Hongyan Xia      2026-06-05  9494  		lsub_positive(&util, task_util(p));
29922fdfc2a4008 Hongyan Xia      2026-06-05  9495  
390031e4c309c94 Quentin Perret   2018-12-03  9496  	if (sched_feat(UTIL_EST)) {
4e3c7d338a22604 Dietmar Eggemann 2022-03-18  9497  		unsigned long util_est;
4e3c7d338a22604 Dietmar Eggemann 2022-03-18  9498  
11137d384996bb0 Vincent Guittot  2023-12-01  9499  		util_est = READ_ONCE(cfs_rq->avg.util_est);
390031e4c309c94 Quentin Perret   2018-12-03  9500  
390031e4c309c94 Quentin Perret   2018-12-03  9501  		/*
4e3c7d338a22604 Dietmar Eggemann 2022-03-18  9502  		 * During wake-up @p isn't enqueued yet and doesn't contribute
11137d384996bb0 Vincent Guittot  2023-12-01  9503  		 * to any cpu_rq(cpu)->cfs.avg.util_est.
4e3c7d338a22604 Dietmar Eggemann 2022-03-18  9504  		 * If @dst_cpu == @cpu add it to "simulate" cpu_util after @p
4e3c7d338a22604 Dietmar Eggemann 2022-03-18  9505  		 * has been enqueued.
4e3c7d338a22604 Dietmar Eggemann 2022-03-18  9506  		 *
4e3c7d338a22604 Dietmar Eggemann 2022-03-18  9507  		 * During exec (@dst_cpu = -1) @p is enqueued and does
11137d384996bb0 Vincent Guittot  2023-12-01  9508  		 * contribute to cpu_rq(cpu)->cfs.util_est.
4e3c7d338a22604 Dietmar Eggemann 2022-03-18  9509  		 * Remove it to "simulate" cpu_util without @p's contribution.
4e3c7d338a22604 Dietmar Eggemann 2022-03-18  9510  		 *
4e3c7d338a22604 Dietmar Eggemann 2022-03-18  9511  		 * Despite the task_on_rq_queued(@p) check there is still a
4e3c7d338a22604 Dietmar Eggemann 2022-03-18  9512  		 * small window for a possible race when an exec
4e3c7d338a22604 Dietmar Eggemann 2022-03-18  9513  		 * select_task_rq_fair() races with LB's detach_task().
4e3c7d338a22604 Dietmar Eggemann 2022-03-18  9514  		 *
4e3c7d338a22604 Dietmar Eggemann 2022-03-18  9515  		 *   detach_task()
4e3c7d338a22604 Dietmar Eggemann 2022-03-18  9516  		 *     deactivate_task()
4e3c7d338a22604 Dietmar Eggemann 2022-03-18  9517  		 *       p->on_rq = TASK_ON_RQ_MIGRATING;
4e3c7d338a22604 Dietmar Eggemann 2022-03-18  9518  		 *       -------------------------------- A
4e3c7d338a22604 Dietmar Eggemann 2022-03-18  9519  		 *       dequeue_task()                    \
4e3c7d338a22604 Dietmar Eggemann 2022-03-18  9520  		 *         dequeue_task_fair()              + Race Time
4e3c7d338a22604 Dietmar Eggemann 2022-03-18  9521  		 *           util_est_dequeue()            /
4e3c7d338a22604 Dietmar Eggemann 2022-03-18  9522  		 *       -------------------------------- B
4e3c7d338a22604 Dietmar Eggemann 2022-03-18  9523  		 *
4e3c7d338a22604 Dietmar Eggemann 2022-03-18  9524  		 * The additional check "current == p" is required to further
4e3c7d338a22604 Dietmar Eggemann 2022-03-18  9525  		 * reduce the race window.
390031e4c309c94 Quentin Perret   2018-12-03  9526  		 */
390031e4c309c94 Quentin Perret   2018-12-03  9527  		if (dst_cpu == cpu)
390031e4c309c94 Quentin Perret   2018-12-03 @9528  			util_est += _task_util_est(p);
3eb6d6ececca2fd Dietmar Eggemann 2023-05-15  9529  		else if (p && unlikely(task_on_rq_queued(p) || current == p))
4e3c7d338a22604 Dietmar Eggemann 2022-03-18  9530  			lsub_positive(&util_est, _task_util_est(p));
390031e4c309c94 Quentin Perret   2018-12-03  9531  
390031e4c309c94 Quentin Perret   2018-12-03  9532  		util = max(util, util_est);
390031e4c309c94 Quentin Perret   2018-12-03  9533  	}
390031e4c309c94 Quentin Perret   2018-12-03  9534  
7bc263840bc3377 Vincent Guittot  2023-10-09  9535  	return min(util, arch_scale_cpu_capacity(cpu));
390031e4c309c94 Quentin Perret   2018-12-03  9536  }
390031e4c309c94 Quentin Perret   2018-12-03  9537  

:::::: The code at line 9528 was first introduced by commit
:::::: 390031e4c309c94ecc07a558187eb5185200df83 sched/fair: Introduce an energy estimation helper function

:::::: TO: Quentin Perret <quentin.perret@arm.com>
:::::: CC: Ingo Molnar <mingo@kernel.org>

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

                 reply	other threads:[~2026-11-26  9:04 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261126095005.yLvASGiX-lkp@intel.com \
    --to=lkp@intel.com \
    --cc=error27@gmail.com \
    --cc=oe-kbuild@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.