@@ -4781,9 +4781,7 @@ static inline unsigned long task_runnable(struct task_struct *p)
47814781
47824782static inline unsigned long _task_util_est (struct task_struct * p )
47834783{
4784- struct util_est ue = READ_ONCE (p -> se .avg .util_est );
4785-
4786- return max (ue .ewma , (ue .enqueued & ~UTIL_AVG_UNCHANGED ));
4784+ return READ_ONCE (p -> se .avg .util_est ) & ~UTIL_AVG_UNCHANGED ;
47874785}
47884786
47894787static inline unsigned long task_util_est (struct task_struct * p )
@@ -4800,9 +4798,9 @@ static inline void util_est_enqueue(struct cfs_rq *cfs_rq,
48004798 return ;
48014799
48024800 /* Update root cfs_rq's estimated utilization */
4803- enqueued = cfs_rq -> avg .util_est . enqueued ;
4801+ enqueued = cfs_rq -> avg .util_est ;
48044802 enqueued += _task_util_est (p );
4805- WRITE_ONCE (cfs_rq -> avg .util_est . enqueued , enqueued );
4803+ WRITE_ONCE (cfs_rq -> avg .util_est , enqueued );
48064804
48074805 trace_sched_util_est_cfs_tp (cfs_rq );
48084806}
@@ -4816,34 +4814,20 @@ static inline void util_est_dequeue(struct cfs_rq *cfs_rq,
48164814 return ;
48174815
48184816 /* Update root cfs_rq's estimated utilization */
4819- enqueued = cfs_rq -> avg .util_est . enqueued ;
4817+ enqueued = cfs_rq -> avg .util_est ;
48204818 enqueued -= min_t (unsigned int , enqueued , _task_util_est (p ));
4821- WRITE_ONCE (cfs_rq -> avg .util_est . enqueued , enqueued );
4819+ WRITE_ONCE (cfs_rq -> avg .util_est , enqueued );
48224820
48234821 trace_sched_util_est_cfs_tp (cfs_rq );
48244822}
48254823
48264824#define UTIL_EST_MARGIN (SCHED_CAPACITY_SCALE / 100)
48274825
4828- /*
4829- * Check if a (signed) value is within a specified (unsigned) margin,
4830- * based on the observation that:
4831- *
4832- * abs(x) < y := (unsigned)(x + y - 1) < (2 * y - 1)
4833- *
4834- * NOTE: this only works when value + margin < INT_MAX.
4835- */
4836- static inline bool within_margin (int value , int margin )
4837- {
4838- return ((unsigned int )(value + margin - 1 ) < (2 * margin - 1 ));
4839- }
4840-
48414826static inline void util_est_update (struct cfs_rq * cfs_rq ,
48424827 struct task_struct * p ,
48434828 bool task_sleep )
48444829{
4845- long last_ewma_diff , last_enqueued_diff ;
4846- struct util_est ue ;
4830+ unsigned int ewma , dequeued , last_ewma_diff ;
48474831
48484832 if (!sched_feat (UTIL_EST ))
48494833 return ;
@@ -4855,77 +4839,73 @@ static inline void util_est_update(struct cfs_rq *cfs_rq,
48554839 if (!task_sleep )
48564840 return ;
48574841
4842+ /* Get current estimate of utilization */
4843+ ewma = READ_ONCE (p -> se .avg .util_est );
4844+
48584845 /*
48594846 * If the PELT values haven't changed since enqueue time,
48604847 * skip the util_est update.
48614848 */
4862- ue = p -> se .avg .util_est ;
4863- if (ue .enqueued & UTIL_AVG_UNCHANGED )
4849+ if (ewma & UTIL_AVG_UNCHANGED )
48644850 return ;
48654851
4866- last_enqueued_diff = ue .enqueued ;
4852+ /* Get utilization at dequeue */
4853+ dequeued = task_util (p );
48674854
48684855 /*
48694856 * Reset EWMA on utilization increases, the moving average is used only
48704857 * to smooth utilization decreases.
48714858 */
4872- ue .enqueued = task_util (p );
4873- if (ue .ewma < ue .enqueued ) {
4874- ue .ewma = ue .enqueued ;
4859+ if (ewma <= dequeued ) {
4860+ ewma = dequeued ;
48754861 goto done ;
48764862 }
48774863
48784864 /*
48794865 * Skip update of task's estimated utilization when its members are
48804866 * already ~1% close to its last activation value.
48814867 */
4882- last_ewma_diff = ue .enqueued - ue .ewma ;
4883- last_enqueued_diff -= ue .enqueued ;
4884- if (within_margin (last_ewma_diff , UTIL_EST_MARGIN )) {
4885- if (!within_margin (last_enqueued_diff , UTIL_EST_MARGIN ))
4886- goto done ;
4887-
4888- return ;
4889- }
4868+ last_ewma_diff = ewma - dequeued ;
4869+ if (last_ewma_diff < UTIL_EST_MARGIN )
4870+ goto done ;
48904871
48914872 /*
48924873 * To avoid overestimation of actual task utilization, skip updates if
48934874 * we cannot grant there is idle time in this CPU.
48944875 */
4895- if (task_util ( p ) > arch_scale_cpu_capacity (cpu_of (rq_of (cfs_rq ))))
4876+ if (dequeued > arch_scale_cpu_capacity (cpu_of (rq_of (cfs_rq ))))
48964877 return ;
48974878
48984879 /*
48994880 * To avoid underestimate of task utilization, skip updates of EWMA if
49004881 * we cannot grant that thread got all CPU time it wanted.
49014882 */
4902- if ((ue . enqueued + UTIL_EST_MARGIN ) < task_runnable (p ))
4883+ if ((dequeued + UTIL_EST_MARGIN ) < task_runnable (p ))
49034884 goto done ;
49044885
49054886
49064887 /*
49074888 * Update Task's estimated utilization
49084889 *
49094890 * When *p completes an activation we can consolidate another sample
4910- * of the task size. This is done by storing the current PELT value
4911- * as ue.enqueued and by using this value to update the Exponential
4912- * Weighted Moving Average (EWMA):
4891+ * of the task size. This is done by using this value to update the
4892+ * Exponential Weighted Moving Average (EWMA):
49134893 *
49144894 * ewma(t) = w * task_util(p) + (1-w) * ewma(t-1)
49154895 * = w * task_util(p) + ewma(t-1) - w * ewma(t-1)
49164896 * = w * (task_util(p) - ewma(t-1)) + ewma(t-1)
4917- * = w * ( last_ewma_diff ) + ewma(t-1)
4918- * = w * (last_ewma_diff + ewma(t-1) / w)
4897+ * = w * ( - last_ewma_diff ) + ewma(t-1)
4898+ * = w * (- last_ewma_diff + ewma(t-1) / w)
49194899 *
49204900 * Where 'w' is the weight of new samples, which is configured to be
49214901 * 0.25, thus making w=1/4 ( >>= UTIL_EST_WEIGHT_SHIFT)
49224902 */
4923- ue . ewma <<= UTIL_EST_WEIGHT_SHIFT ;
4924- ue . ewma + = last_ewma_diff ;
4925- ue . ewma >>= UTIL_EST_WEIGHT_SHIFT ;
4903+ ewma <<= UTIL_EST_WEIGHT_SHIFT ;
4904+ ewma - = last_ewma_diff ;
4905+ ewma >>= UTIL_EST_WEIGHT_SHIFT ;
49264906done :
4927- ue . enqueued |= UTIL_AVG_UNCHANGED ;
4928- WRITE_ONCE (p -> se .avg .util_est , ue );
4907+ ewma |= UTIL_AVG_UNCHANGED ;
4908+ WRITE_ONCE (p -> se .avg .util_est , ewma );
49294909
49304910 trace_sched_util_est_se_tp (& p -> se );
49314911}
@@ -7653,16 +7633,16 @@ cpu_util(int cpu, struct task_struct *p, int dst_cpu, int boost)
76537633 if (sched_feat (UTIL_EST )) {
76547634 unsigned long util_est ;
76557635
7656- util_est = READ_ONCE (cfs_rq -> avg .util_est . enqueued );
7636+ util_est = READ_ONCE (cfs_rq -> avg .util_est );
76577637
76587638 /*
76597639 * During wake-up @p isn't enqueued yet and doesn't contribute
7660- * to any cpu_rq(cpu)->cfs.avg.util_est.enqueued.
7640+ * to any cpu_rq(cpu)->cfs.avg.util_est.
76617641 * If @dst_cpu == @cpu add it to "simulate" cpu_util after @p
76627642 * has been enqueued.
76637643 *
76647644 * During exec (@dst_cpu = -1) @p is enqueued and does
7665- * contribute to cpu_rq(cpu)->cfs.util_est.enqueued.
7645+ * contribute to cpu_rq(cpu)->cfs.util_est.
76667646 * Remove it to "simulate" cpu_util without @p's contribution.
76677647 *
76687648 * Despite the task_on_rq_queued(@p) check there is still a
0 commit comments