scx_layered: Add per-layer LLC stickiness control #2944
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Add a new configuration option
llc_sticky_runsthat controls how many times a task must run on its current LLC before being allowed to migrate to a different LLC. This provides finer-grained control over LLC locality and complements the existingxllc_mig_min_usoption.The implementation tracks the number of consecutive runs on the current LLC in the task context (
taskc->llc_runs). When the scheduler attempts to find an idle CPU and no idle CPUs are available on the current LLC, it checks if the task has run fewer times than the configured threshold. If so, cross-LLC migration is prevented, keeping the task sticky to its current LLC to preserve cache locality.Key changes:
llc_runscounter totask_ctxto track consecutive runs on current LLCllc_sticky_runsconfiguration field tolayerstruct andLayerConfigin config.rsllc_runsinlayered_running()when stickiness is enabledllc_runsto 0 inmaybe_update_task_llc()on LLC migrationpick_idle_cpu()to prevent cross-LLC migration when task hasn't run enough times on current LLCLSTAT_LLC_STICKY_SKIPstatistic to track prevented migrationsllc_runsto 0 inlayered_init_task()The feature is disabled by default (llc_sticky_runs = 0) and can be configured per-layer. Example configuration:
{
"name": "batch",
"kind": {
"Confined": {
"llc_sticky_runs": 20,
}
}
}
This would keep tasks on their current LLC for 20 runs before allowing cross-LLC migration, providing stronger LLC affinity for workloads that benefit from cache locality.
The new statistic appears in the output as:
xllc_mig/skip/sticky_skip={xllc_migration%}/{xllc_skip%}/{llc_sticky_skip%}