On 27/10/2025 12:18, Philipp Stanner wrote: 8><
+static ktime_t drm_sched_entity_update_vruntime(struct drm_sched_entity *entity) +{ + /* + * Core part of the CFS-like algorithm is that the virtual runtime of + * lower priority tasks should grow quicker than the higher priority + * ones, so that when we then schedule entities with the aim of keeping + * their accumulated virtual time balanced, we can approach fair + * distribution of GPU time. + * + * For converting the real GPU time into virtual we pick some + * multipliers with the idea to achieve the following GPU time + * distribution: + * + * - Kernel priority gets roughly 2x GPU time compared to high. + * - High gets ~4x relative to normal. + * - Normal gets ~8x relative to low. + */I can make sense of 2 and 4, but how does 7 match to 8?
vvv
+ static const unsigned int shift[] = { + [DRM_SCHED_PRIORITY_KERNEL] = 1, + [DRM_SCHED_PRIORITY_HIGH] = 2, + [DRM_SCHED_PRIORITY_NORMAL] = 4, + [DRM_SCHED_PRIORITY_LOW] = 7, + }; + struct drm_sched_entity_stats *stats = entity->stats; + ktime_t runtime, prev; + + spin_lock(&stats->lock); + prev = stats->prev_runtime; + runtime = stats->runtime; + stats->prev_runtime = runtime; + runtime = ktime_add_ns(stats->vruntime, + ktime_to_ns(ktime_sub(runtime, prev)) << + shift[entity->priority]);
I thought 2^7 / 2^4 = 8, but real math was very long time ago. Have I oversimplified by equating "for low time grows 8x as fast" to "normal gets 8x more gpu time"? Still seems about right when I think about it.
Regards, Tvrtko
+ stats->vruntime = runtime; + spin_unlock(&stats->lock); + + return runtime; +}
