uboot-script-gen: add ability to cfg vcpu hard affinity
PATCH 1/1 uboot-script-gen: add ability to cfg vcpu hard affinity
From: Grygorii Strashko <[email protected]>
Add DOMU_VCPU_HARD_AFFINITY[number,vcpu] configuration file string option specifying the hard affinity configuration for the VM vCPU(vcpu) in DT.
The format is a comma-separated list of pCPUs or ranges of pCPUs. Ranges are hyphen-separated intervals (such as 0-4) and are inclusive on both sides. The numbers refer to logical pCPU ids.
For example:
DOMU_VCPUS[0]="2"
DOMU_VCPU_HARD_AFFINITY[0,0]="1"
will be reflected in domU0/vcpu0 DT node with "hard-affinity" set:
vcpu0 {
hard-affinity = "1";
id = <0x00000000>;
compatible = "xen,vcpu";
};--- README.md | 11 +++++++++++ scripts/uboot-script-gen | 4 ++++ scripts/xen_dt_domu | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 scripts/xen_dt_domu
README.md +11 -0
@@ -186,6 +186,17 @@ Where: - DOMU_VCPUS[number] is the number of vcpus for the VM, default 1 +- DOMU_VCPU_HARD_AFFINITY[number,vcpu] optional, is the A string + specifying the hard affinity configuration for the VM vCPU(vcpu): + a comma-separated list of pCPUs or ranges of pCPUs is used. + Ranges are hyphen-separated intervals (such as `0-4`) and are inclusive + on both sides. The numbers refer to logical pCPU ids. Below is an example: +``` + DOMU_VCPUS[number]=2 + DOMU_VCPU_HARD_AFFINITY[number,0]="0-2" + DOMU_VCPU_HARD_AFFINITY[number,1]="3" +``` + - DOMU_COLORS[number] specifies the colors (cache coloring) to be used for the domain and is in the format startcolor-endcolor
scripts/uboot-script-gen +4 -0
@@ -392,6 +392,8 @@ function xen_device_tree_editing() dt_set "/chosen/domU$i" "colors" "hex" "$(printf "0x%x" $bitcolors)" fi + xen_dt_domu_add_vcpu_nodes "/chosen/domU$i" $i ${DOMU_VCPUS[$i]} + add_device_tree_kernel "/chosen/domU$i" ${domU_kernel_addr[$i]} ${domU_kernel_size[$i]} "${DOMU_CMD[$i]}" if test "${domU_ramdisk_addr[$i]}" then
@@ -1164,10 +1166,12 @@ fi check_depends +declare -A DOMU_VCPU_HARD_AFFINITY source "$cfg_file" SCRIPT_PATH=$(dirname "$0") source "$SCRIPT_PATH/common" +source "$SCRIPT_PATH/xen_dt_domu" # command line overrides LOAD_CMD=${load_opt:-$LOAD_CMD}
scripts/xen_dt_domu new file +39 -0
@@ -0,0 +1,39 @@ +#!/bin/bash + +# uses: +# DOMU_VCPU_HARD_AFFINITY +function xen_dt_domu_add_vcpu_nodes() +{ + # $1 - dt path + local path=$1 + # $2 - domain number + local dom_num=$2 + # $3 - number of vcpus for the domain + local vcpus=$3 + local hard_affinity="" + local gen_vcpu="" + + for (( vcpu=0; vcpu<${vcpus}; vcpu++ )) + do + gen_vcpu="" + if test "${DOMU_VCPU_HARD_AFFINITY[$dom_num,$vcpu]}" + then + hard_affinity=${DOMU_VCPU_HARD_AFFINITY[$dom_num,$vcpu]} + gen_vcpu="1" + fi + + if test -z $gen_vcpu + then + continue + fi + + dt_mknode "${path}" "vcpu$vcpu" + dt_set "${path}/vcpu$vcpu" "compatible" "str_a" "xen,vcpu" + dt_set "${path}/vcpu$vcpu" "id" "int" "$vcpu" + + if test -n $hard_affinity + then + dt_set "${path}/vcpu$vcpu" "hard-affinity" "str" "$hard_affinity" + fi + done +}
Signature · 1 line
2.34.1
Quoted 97 lines · On Mon, 17 Mar 2025, [email protected] wrote:
From: Grygorii Strashko <[email protected]>
Add DOMU_VCPU_HARD_AFFINITY[number,vcpu] configuration file string option specifying the hard affinity configuration for the VM vCPU(vcpu) in DT.
The format is a comma-separated list of pCPUs or ranges of pCPUs. Ranges are hyphen-separated intervals (such as 0-4) and are inclusive on both sides. The numbers refer to logical pCPU ids.
For example:
DOMU_VCPUS[0]="2"
DOMU_VCPU_HARD_AFFINITY[0,0]="1"will be reflected in domU0/vcpu0 DT node with "hard-affinity" set:
vcpu0 { hard-affinity = "1"; id = <0x00000000>; compatible = "xen,vcpu"; };Signed-off-by Grygorii Strashko <[email protected]>--- README.md | 11 +++++++++++ scripts/uboot-script-gen | 4 ++++ scripts/xen_dt_domu | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 scripts/xen_dt_domuREADME.md +11
-0@@ -186,6 +186,17 @@ Where: - DOMU_VCPUS[number] is the number of vcpus for the VM, default 1 +- DOMU_VCPU_HARD_AFFINITY[number,vcpu] optional, is the A string + specifying the hard affinity configuration for the VM vCPU(vcpu): + a comma-separated list of pCPUs or ranges of pCPUs is used. + Ranges are hyphen-separated intervals (such as `0-4`) and are inclusive + on both sides. The numbers refer to logical pCPU ids. Below is an example: +``` + DOMU_VCPUS[number]=2 + DOMU_VCPU_HARD_AFFINITY[number,0]="0-2" + DOMU_VCPU_HARD_AFFINITY[number,1]="3" +``` + - DOMU_COLORS[number] specifies the colors (cache coloring) to be used for the domain and is in the format startcolor-endcolorscripts/uboot-script-gen +4
-0@@ -392,6 +392,8 @@ function xen_device_tree_editing() dt_set "/chosen/domU$i" "colors" "hex" "$(printf "0x%x" $bitcolors)" fi + xen_dt_domu_add_vcpu_nodes "/chosen/domU$i" $i ${DOMU_VCPUS[$i]} + add_device_tree_kernel "/chosen/domU$i" ${domU_kernel_addr[$i]} ${domU_kernel_size[$i]} "${DOMU_CMD[$i]}" if test "${domU_ramdisk_addr[$i]}" then@@ -1164,10 +1166,12 @@ fi check_depends +declare -A DOMU_VCPU_HARD_AFFINITY source "$cfg_file" SCRIPT_PATH=$(dirname "$0") source "$SCRIPT_PATH/common" +source "$SCRIPT_PATH/xen_dt_domu" # command line overrides LOAD_CMD=${load_opt:-$LOAD_CMD}scripts/xen_dt_domu new file +15
-0@@ -0,0 +1,39 @@ +#!/bin/bash + +# uses: +# DOMU_VCPU_HARD_AFFINITY +function xen_dt_domu_add_vcpu_nodes() +{ + # $1 - dt path + local path=$1 + # $2 - domain number + local dom_num=$2 + # $3 - number of vcpus for the domain + local vcpus=$3 + local hard_affinity="" + local gen_vcpu="" +
scripts/xen_dt_domu line 25
Quoted 10 lines
scripts/xen_dt_domu new file +10
-0+ for (( vcpu=0; vcpu<${vcpus}; vcpu++ )) + do + gen_vcpu="" + if test "${DOMU_VCPU_HARD_AFFINITY[$dom_num,$vcpu]}" + then + hard_affinity=${DOMU_VCPU_HARD_AFFINITY[$dom_num,$vcpu]} + gen_vcpu="1" + fi + + if test -z $gen_vcpu
I would prefer to use quotes ("$gen_vcpu")
scripts/xen_dt_domu line 34
Quoted 9 lines
scripts/xen_dt_domu new file +9
-0+ then + continue + fi + + dt_mknode "${path}" "vcpu$vcpu" + dt_set "${path}/vcpu$vcpu" "compatible" "str_a" "xen,vcpu" + dt_set "${path}/vcpu$vcpu" "id" "int" "$vcpu" + + if test -n $hard_affinity
also here. I'll fix it on commit
Quoted 8 lines
scripts/xen_dt_domu new file +5
-0+ then + dt_set "${path}/vcpu$vcpu" "hard-affinity" "str" "$hard_affinity" + fi + done +}Signature · 1 line
2.34.1