Message ID | 20250317141909.2502496-1-grygorii_strashko@epam.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | [ImageBuilder] uboot-script-gen: add ability to cfg vcpu hard affinity | expand |
On Mon, 17 Mar 2025, gragst.linux@gmail.com wrote: > From: Grygorii Strashko <grygorii_strashko@epam.com> > > 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 <grygorii_strashko@epam.com> > --- > 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 > > diff --git a/README.md b/README.md > index 5b75018ea956..262022c665be 100644 > --- a/README.md > +++ b/README.md > @@ -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 > > diff --git a/scripts/uboot-script-gen b/scripts/uboot-script-gen > index 74e3b076910c..9229f9af567b 100755 > --- a/scripts/uboot-script-gen > +++ b/scripts/uboot-script-gen > @@ -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} > diff --git a/scripts/xen_dt_domu b/scripts/xen_dt_domu > new file mode 100644 > index 000000000000..e1cb2376c37e > --- /dev/null > +++ b/scripts/xen_dt_domu > @@ -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 I would prefer to use quotes ("$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 also here. I'll fix it on commit > + then > + dt_set "${path}/vcpu$vcpu" "hard-affinity" "str" "$hard_affinity" > + fi > + done > +} > -- > 2.34.1 >
diff --git a/README.md b/README.md index 5b75018ea956..262022c665be 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/scripts/uboot-script-gen b/scripts/uboot-script-gen index 74e3b076910c..9229f9af567b 100755 --- a/scripts/uboot-script-gen +++ b/scripts/uboot-script-gen @@ -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} diff --git a/scripts/xen_dt_domu b/scripts/xen_dt_domu new file mode 100644 index 000000000000..e1cb2376c37e --- /dev/null +++ b/scripts/xen_dt_domu @@ -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 +}