Skip to content

Commit

Permalink
Add support for EEVDF scheduler
Browse files Browse the repository at this point in the history
Changes enabled when EEVDF detected:

* Targeted preemption latency dropped
* Wake-up granularity dropped
* Minimal preemption granularity renamed to base slice
* Number of tasks to iterate in a single balance run from 64 to 8
  • Loading branch information
igo95862 committed Nov 12, 2023
1 parent 3289bf3 commit 75cb8c2
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions set-cfs-zen-tweaks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ MIN_GRANULARITY_MS=0.4
WAKEUP_GRANULARITY_MS=0.5
MIGRATION_COST_MS=0.25
BANDWIDTH_SIZE_MS=3
NR_MIGRATE=64
NR_MIGRATE_CFS=64
NR_MIGRATE_EEVDF=8
NR_MIGRATE="$NR_MIGRATE_CFS"

echo "Targeted preemption latency for CPU-bound tasks: ${LATENCY_MS}ms"
echo "Minimal preemption granularity for CPU-bound tasks: ${MIN_GRANULARITY_MS}ms"
echo "Wake-up granularity: ${WAKEUP_GRANULARITY_MS}ms"
echo "Task migration cost: ${MIGRATION_COST_MS}ms"
echo "Amount of runtime to allocate from global to local pool: ${BANDWIDTH_SIZE_MS}ms"
echo "Number of tasks to iterate in a single balance run: ${NR_MIGRATE}"
echo "Number of tasks to iterate in a single balance run: CFS ${NR_MIGRATE_CFS} EEVDF ${NR_MIGRATE_EEVDF}"

call_gawk() {
printf '%s' "$(gawk 'BEGIN {print '"${1}"'}')"
Expand All @@ -39,14 +41,18 @@ NPROC="$(nproc)"
# Linux uses this algorithm to multiply miliseconds
MODIFIER="$( call_gawk "10 ** 6 * (1 + int(log(${NPROC}) / log(2)))" )"

# Only CFS
LATENCY_NS_FILE="/sys/kernel/debug/sched/latency_ns"
MIN_GRANULARITY_NS_FILE="/sys/kernel/debug/sched/min_granularity_ns"
WAKEUP_GRANULARITY_NS_FILE="/sys/kernel/debug/sched/wakeup_granularity_ns"
MIN_GRANULARITY_NS_FILE="/sys/kernel/debug/sched/min_granularity_ns"
# Both CFS and EEVDF
MIGRATION_COST_NS_FILE="/sys/kernel/debug/sched/migration_cost_ns"
BANDWIDTH_SIZE_US_FILE="/proc/sys/kernel/sched_cfs_bandwidth_slice_us"
NR_MIGRATE_FILE="/sys/kernel/debug/sched/nr_migrate"
# Only EEVDF
BASE_SLICE_FILE="/sys/kernel/debug/sched/base_slice_ns"

if [ ! -f "$LATENCY_NS_FILE" ]; then
if [ ! -f "$NR_MIGRATE_FILE" ]; then
echo "Detected kernel <5.13. Using legacy locations."
LATENCY_NS_FILE="/proc/sys/kernel/sched_latency_ns"
MIN_GRANULARITY_NS_FILE="/proc/sys/kernel/sched_min_granularity_ns"
Expand All @@ -55,9 +61,16 @@ if [ ! -f "$LATENCY_NS_FILE" ]; then
NR_MIGRATE_FILE="/proc/sys/kernel/sched_nr_migrate"
fi

printf '%s' "$( call_gawk "int(${LATENCY_MS} * ${MODIFIER})" )" > "$LATENCY_NS_FILE"
if [ -f "$LATENCY_NS_FILE" ]; then
printf '%s' "$( call_gawk "int(${LATENCY_MS} * ${MODIFIER})" )" > "$LATENCY_NS_FILE"
printf '%s' "$( call_gawk "int(${WAKEUP_GRANULARITY_MS} * ${MODIFIER})" )" > "$WAKEUP_GRANULARITY_NS_FILE"
else
echo "Detected EEVDF scheduler"
NR_MIGRATE="$NR_MIGRATE_EEVDF"
MIN_GRANULARITY_NS_FILE="$BASE_SLICE_FILE"
fi

printf '%s' "$( call_gawk "int(${MIN_GRANULARITY_MS} * ${MODIFIER})" )" > "$MIN_GRANULARITY_NS_FILE"
printf '%s' "$( call_gawk "int(${WAKEUP_GRANULARITY_MS} * ${MODIFIER})" )" > "$WAKEUP_GRANULARITY_NS_FILE"
printf '%s' "$( call_gawk "int(${MIGRATION_COST_MS} * ${MODIFIER})" )" > "$MIGRATION_COST_NS_FILE"
printf '%s' "$( call_gawk "int(${BANDWIDTH_SIZE_MS} * 1000)" )" > "$BANDWIDTH_SIZE_US_FILE"
printf '%s' "$NR_MIGRATE" > "$NR_MIGRATE_FILE"

0 comments on commit 75cb8c2

Please sign in to comment.