[PATCH 1/2] misc: add the define of MAX_IR_ENTRIES


chenli.wei
 

The current code align MAX_IR_ENTRIE with the CONFIG_MAX_PT_IRQ_ENTRIE
roundup to 2^n, there is an issue of the powerof2_roundup to calculate
the macro, and the code style is very ugly when we use macro to fix it.

So this patch move the calculate and define of MAX_IR_ENTRIE to offline
tool.

Signed-off-by: Chenli Wei <chenli.wei@...>
---
.../static_allocators/board_capability.py | 17 +++++++++++++++++
.../config_tools/xforms/vm_configurations.h.xsl | 5 +++++
2 files changed, 22 insertions(+)

diff --git a/misc/config_tools/static_allocators/board_capability.py b/misc/config_tools/static_allocators/board_capability.py
index 5a98f472d..75f72afc2 100644
--- a/misc/config_tools/static_allocators/board_capability.py
+++ b/misc/config_tools/static_allocators/board_capability.py
@@ -7,6 +7,23 @@

import common

+def powerof2_roundup(value):
+ result = value
+ for i in [1, 2, 4, 8, 16]:
+ result = result | result >> i
+ return result + 1
+
+# Make sure all PT IRQs work w/ interrupt remapping or post interrupt
+def create_max_ir_entries(scenario_etree, allocation_etree):
+ pt_irq_entries = common.get_node(f"//MAX_PT_IRQ_ENTRIES/text()", scenario_etree)
+ if (pt_irq_entries is not None) and (int(pt_irq_entries) > 256):
+ ir_entries = powerof2_roundup(int(pt_irq_entries) - 1)
+ else:
+ ir_entries = 256
+
+ common.append_node("/acrn-config/hv/MAX_IR_ENTRIES", ir_entries, allocation_etree)
+
def fn(board_etree, scenario_etree, allocation_etree):
pci_bus_nums = board_etree.xpath("//bus[@type='pci']/@address")
common.append_node("/acrn-config/platform/MAX_PCI_BUS_NUM", hex(max(map(lambda x: int(x, 16), pci_bus_nums)) + 1), allocation_etree)
+ create_max_ir_entries(scenario_etree, allocation_etree)
diff --git a/misc/config_tools/xforms/vm_configurations.h.xsl b/misc/config_tools/xforms/vm_configurations.h.xsl
index f91c2720c..215a17fdd 100644
--- a/misc/config_tools/xforms/vm_configurations.h.xsl
+++ b/misc/config_tools/xforms/vm_configurations.h.xsl
@@ -34,6 +34,7 @@
<xsl:call-template name="vm_count" />
<xsl:call-template name="sos_vm_bootarges" />
<xsl:call-template name="vm_vuart_num" />
+ <xsl:call-template name="ir_entries" />
</xsl:template>

<xsl:template name ="vm_vuart_num">
@@ -50,6 +51,10 @@
<xsl:value-of select = "acrn:define('MAX_VUART_NUM_PER_VM', math:max(str:split($vuart_nums, ',')), 'U')" />
</xsl:template>

+ <xsl:template name="ir_entries">
+ <xsl:value-of select = "acrn:define('MAX_IR_ENTRIES', //MAX_IR_ENTRIES, 'U')" />
+ </xsl:template>
+
<xsl:template name ="vm_count">
<xsl:value-of select="acrn:comment('SERVICE_VM_NUM can only be 0 or 1; When SERVICE_VM_NUM is 1, MAX_POST_VM_NUM must be 0 too.')" />
<xsl:value-of select="$newline" />
--
2.17.1


Geoffroy Van Cutsem
 

Here too, fix the typo _ENTRIE -> _ENTRIES (and throughout the patch series)

-----Original Message-----
From: acrn-dev@... <acrn-dev@...> On
Behalf Of chenli.wei
Sent: Friday, May 13, 2022 12:29 pm
To: Mao, Junjie <junjie.mao@...>; Li, Fei1 <fei1.li@...>; acrn-
dev@...
Cc: Wei, Chenli <chenli.wei@...>
Subject: [acrn-dev] [PATCH 1/2] misc: add the define of MAX_IR_ENTRIES

The current code align MAX_IR_ENTRIE with the
CONFIG_MAX_PT_IRQ_ENTRIE roundup to 2^n, there is an issue of the
powerof2_roundup to calculate the macro, and the code style is very ugly
when we use macro to fix it.

So this patch move the calculate and define of MAX_IR_ENTRIE to offline
tool.

Signed-off-by: Chenli Wei <chenli.wei@...>
---
.../static_allocators/board_capability.py | 17 +++++++++++++++++
.../config_tools/xforms/vm_configurations.h.xsl | 5 +++++
2 files changed, 22 insertions(+)

diff --git a/misc/config_tools/static_allocators/board_capability.py
b/misc/config_tools/static_allocators/board_capability.py
index 5a98f472d..75f72afc2 100644
--- a/misc/config_tools/static_allocators/board_capability.py
+++ b/misc/config_tools/static_allocators/board_capability.py
@@ -7,6 +7,23 @@

import common

+def powerof2_roundup(value):
+ result = value
+ for i in [1, 2, 4, 8, 16]:
+ result = result | result >> i
+ return result + 1
+
+# Make sure all PT IRQs work w/ interrupt remapping or post interrupt
+def create_max_ir_entries(scenario_etree, allocation_etree):
+ pt_irq_entries = common.get_node(f"//MAX_PT_IRQ_ENTRIES/text()",
scenario_etree)
+ if (pt_irq_entries is not None) and (int(pt_irq_entries) > 256):
+ ir_entries = powerof2_roundup(int(pt_irq_entries) - 1)
+ else:
+ ir_entries = 256
+
+ common.append_node("/acrn-config/hv/MAX_IR_ENTRIES", ir_entries,
+ allocation_etree)
+
def fn(board_etree, scenario_etree, allocation_etree):
pci_bus_nums = board_etree.xpath("//bus[@type='pci']/@address")
common.append_node("/acrn-config/platform/MAX_PCI_BUS_NUM",
hex(max(map(lambda x: int(x, 16), pci_bus_nums)) + 1), allocation_etree)
+ create_max_ir_entries(scenario_etree, allocation_etree)
diff --git a/misc/config_tools/xforms/vm_configurations.h.xsl
b/misc/config_tools/xforms/vm_configurations.h.xsl
index f91c2720c..215a17fdd 100644
--- a/misc/config_tools/xforms/vm_configurations.h.xsl
+++ b/misc/config_tools/xforms/vm_configurations.h.xsl
@@ -34,6 +34,7 @@
<xsl:call-template name="vm_count" />
<xsl:call-template name="sos_vm_bootarges" />
<xsl:call-template name="vm_vuart_num" />
+ <xsl:call-template name="ir_entries" />
</xsl:template>

<xsl:template name ="vm_vuart_num">
@@ -50,6 +51,10 @@
<xsl:value-of select = "acrn:define('MAX_VUART_NUM_PER_VM',
math:max(str:split($vuart_nums, ',')), 'U')" />
</xsl:template>

+ <xsl:template name="ir_entries">
+ <xsl:value-of select = "acrn:define('MAX_IR_ENTRIES',
+ //MAX_IR_ENTRIES, 'U')" /> </xsl:template>
+
<xsl:template name ="vm_count">
<xsl:value-of select="acrn:comment('SERVICE_VM_NUM can only be 0 or
1; When SERVICE_VM_NUM is 1, MAX_POST_VM_NUM must be 0 too.')" />
<xsl:value-of select="$newline" />
--
2.17.1





chenli.wei
 

On 5/13/2022 8:34 PM, Geoffroy Van Cutsem wrote:
Here too, fix the typo _ENTRIE -> _ENTRIES (and throughout the patch series)
ok

-----Original Message-----
From: acrn-dev@... <acrn-dev@...> On
Behalf Of chenli.wei
Sent: Friday, May 13, 2022 12:29 pm
To: Mao, Junjie <junjie.mao@...>; Li, Fei1 <fei1.li@...>; acrn-
dev@...
Cc: Wei, Chenli <chenli.wei@...>
Subject: [acrn-dev] [PATCH 1/2] misc: add the define of MAX_IR_ENTRIES

The current code align MAX_IR_ENTRIE with the
CONFIG_MAX_PT_IRQ_ENTRIE roundup to 2^n, there is an issue of the
powerof2_roundup to calculate the macro, and the code style is very ugly
when we use macro to fix it.

So this patch move the calculate and define of MAX_IR_ENTRIE to offline
tool.

Signed-off-by: Chenli Wei <chenli.wei@...>
---
.../static_allocators/board_capability.py | 17 +++++++++++++++++
.../config_tools/xforms/vm_configurations.h.xsl | 5 +++++
2 files changed, 22 insertions(+)

diff --git a/misc/config_tools/static_allocators/board_capability.py
b/misc/config_tools/static_allocators/board_capability.py
index 5a98f472d..75f72afc2 100644
--- a/misc/config_tools/static_allocators/board_capability.py
+++ b/misc/config_tools/static_allocators/board_capability.py
@@ -7,6 +7,23 @@

import common

+def powerof2_roundup(value):
+ result = value
+ for i in [1, 2, 4, 8, 16]:
+ result = result | result >> i
+ return result + 1
+
+# Make sure all PT IRQs work w/ interrupt remapping or post interrupt
+def create_max_ir_entries(scenario_etree, allocation_etree):
+ pt_irq_entries = common.get_node(f"//MAX_PT_IRQ_ENTRIES/text()",
scenario_etree)
+ if (pt_irq_entries is not None) and (int(pt_irq_entries) > 256):
+ ir_entries = powerof2_roundup(int(pt_irq_entries) - 1)
+ else:
+ ir_entries = 256
+
+ common.append_node("/acrn-config/hv/MAX_IR_ENTRIES", ir_entries,
+ allocation_etree)
+
def fn(board_etree, scenario_etree, allocation_etree):
pci_bus_nums = board_etree.xpath("//bus[@type='pci']/@address")
common.append_node("/acrn-config/platform/MAX_PCI_BUS_NUM",
hex(max(map(lambda x: int(x, 16), pci_bus_nums)) + 1), allocation_etree)
+ create_max_ir_entries(scenario_etree, allocation_etree)
diff --git a/misc/config_tools/xforms/vm_configurations.h.xsl
b/misc/config_tools/xforms/vm_configurations.h.xsl
index f91c2720c..215a17fdd 100644
--- a/misc/config_tools/xforms/vm_configurations.h.xsl
+++ b/misc/config_tools/xforms/vm_configurations.h.xsl
@@ -34,6 +34,7 @@
<xsl:call-template name="vm_count" />
<xsl:call-template name="sos_vm_bootarges" />
<xsl:call-template name="vm_vuart_num" />
+ <xsl:call-template name="ir_entries" />
</xsl:template>

<xsl:template name ="vm_vuart_num">
@@ -50,6 +51,10 @@
<xsl:value-of select = "acrn:define('MAX_VUART_NUM_PER_VM',
math:max(str:split($vuart_nums, ',')), 'U')" />
</xsl:template>

+ <xsl:template name="ir_entries">
+ <xsl:value-of select = "acrn:define('MAX_IR_ENTRIES',
+ //MAX_IR_ENTRIES, 'U')" /> </xsl:template>
+
<xsl:template name ="vm_count">
<xsl:value-of select="acrn:comment('SERVICE_VM_NUM can only be 0 or
1; When SERVICE_VM_NUM is 1, MAX_POST_VM_NUM must be 0 too.')" />
<xsl:value-of select="$newline" />
--
2.17.1







Junjie Mao
 

Chenli Wei <chenli.wei@...> writes:

The current code align MAX_IR_ENTRIE with the CONFIG_MAX_PT_IRQ_ENTRIE
roundup to 2^n, there is an issue of the powerof2_roundup to calculate
the macro, and the code style is very ugly when we use macro to fix it.

So this patch move the calculate and define of MAX_IR_ENTRIE to offline
tool.

Signed-off-by: Chenli Wei <chenli.wei@...>
Reviewed-by: Junjie Mao <junjie.mao@...>

Some minor comments below.

---
.../static_allocators/board_capability.py | 17 +++++++++++++++++
.../config_tools/xforms/vm_configurations.h.xsl | 5 +++++
2 files changed, 22 insertions(+)

diff --git a/misc/config_tools/static_allocators/board_capability.py b/misc/config_tools/static_allocators/board_capability.py
index 5a98f472d..75f72afc2 100644
--- a/misc/config_tools/static_allocators/board_capability.py
+++ b/misc/config_tools/static_allocators/board_capability.py
@@ -7,6 +7,23 @@

import common

+def powerof2_roundup(value):
+ result = value
+ for i in [1, 2, 4, 8, 16]:
+ result = result | result >> i
+ return result + 1
`1 << value.bit_length()` is simpler and more straightforward.

+
+# Make sure all PT IRQs work w/ interrupt remapping or post interrupt
+def create_max_ir_entries(scenario_etree, allocation_etree):
+ pt_irq_entries = common.get_node(f"//MAX_PT_IRQ_ENTRIES/text()", scenario_etree)
+ if (pt_irq_entries is not None) and (int(pt_irq_entries) > 256):
+ ir_entries = powerof2_roundup(int(pt_irq_entries) - 1)
+ else:
+ ir_entries = 256
+
+ common.append_node("/acrn-config/hv/MAX_IR_ENTRIES", ir_entries, allocation_etree)
+
def fn(board_etree, scenario_etree, allocation_etree):
pci_bus_nums = board_etree.xpath("//bus[@type='pci']/@address")
common.append_node("/acrn-config/platform/MAX_PCI_BUS_NUM", hex(max(map(lambda x: int(x, 16), pci_bus_nums)) + 1), allocation_etree)
+ create_max_ir_entries(scenario_etree, allocation_etree)
diff --git a/misc/config_tools/xforms/vm_configurations.h.xsl b/misc/config_tools/xforms/vm_configurations.h.xsl
index f91c2720c..215a17fdd 100644
--- a/misc/config_tools/xforms/vm_configurations.h.xsl
+++ b/misc/config_tools/xforms/vm_configurations.h.xsl
@@ -34,6 +34,7 @@
<xsl:call-template name="vm_count" />
<xsl:call-template name="sos_vm_bootarges" />
<xsl:call-template name="vm_vuart_num" />
+ <xsl:call-template name="ir_entries" />
You can embed the `value-of` node here. Defining a template for a
one-element template seems an overkill.

--
Best Regards
Junjie Mao

</xsl:template>

<xsl:template name ="vm_vuart_num">
@@ -50,6 +51,10 @@
<xsl:value-of select = "acrn:define('MAX_VUART_NUM_PER_VM', math:max(str:split($vuart_nums, ',')), 'U')" />
</xsl:template>

+ <xsl:template name="ir_entries">
+ <xsl:value-of select = "acrn:define('MAX_IR_ENTRIES', //MAX_IR_ENTRIES, 'U')" />
+ </xsl:template>
+
<xsl:template name ="vm_count">
<xsl:value-of select="acrn:comment('SERVICE_VM_NUM can only be 0 or 1; When SERVICE_VM_NUM is 1, MAX_POST_VM_NUM must be 0 too.')" />
<xsl:value-of select="$newline" />


chenli.wei
 

On 5/16/2022 11:56 AM, Junjie Mao wrote:
Chenli Wei <chenli.wei@...> writes:

The current code align MAX_IR_ENTRIE with the CONFIG_MAX_PT_IRQ_ENTRIE
roundup to 2^n, there is an issue of the powerof2_roundup to calculate
the macro, and the code style is very ugly when we use macro to fix it.

So this patch move the calculate and define of MAX_IR_ENTRIE to offline
tool.

Signed-off-by: Chenli Wei <chenli.wei@...>
Reviewed-by: Junjie Mao <junjie.mao@...>

Some minor comments below.

---
.../static_allocators/board_capability.py | 17 +++++++++++++++++
.../config_tools/xforms/vm_configurations.h.xsl | 5 +++++
2 files changed, 22 insertions(+)

diff --git a/misc/config_tools/static_allocators/board_capability.py b/misc/config_tools/static_allocators/board_capability.py
index 5a98f472d..75f72afc2 100644
--- a/misc/config_tools/static_allocators/board_capability.py
+++ b/misc/config_tools/static_allocators/board_capability.py
@@ -7,6 +7,23 @@
import common
+def powerof2_roundup(value):
+ result = value
+ for i in [1, 2, 4, 8, 16]:
+ result = result | result >> i
+ return result + 1
`1 << value.bit_length()` is simpler and more straightforward.
OK
+
+# Make sure all PT IRQs work w/ interrupt remapping or post interrupt
+def create_max_ir_entries(scenario_etree, allocation_etree):
+ pt_irq_entries = common.get_node(f"//MAX_PT_IRQ_ENTRIES/text()", scenario_etree)
+ if (pt_irq_entries is not None) and (int(pt_irq_entries) > 256):
+ ir_entries = powerof2_roundup(int(pt_irq_entries) - 1)
+ else:
+ ir_entries = 256
+
+ common.append_node("/acrn-config/hv/MAX_IR_ENTRIES", ir_entries, allocation_etree)
+
def fn(board_etree, scenario_etree, allocation_etree):
pci_bus_nums = board_etree.xpath("//bus[@type='pci']/@address")
common.append_node("/acrn-config/platform/MAX_PCI_BUS_NUM", hex(max(map(lambda x: int(x, 16), pci_bus_nums)) + 1), allocation_etree)
+ create_max_ir_entries(scenario_etree, allocation_etree)
diff --git a/misc/config_tools/xforms/vm_configurations.h.xsl b/misc/config_tools/xforms/vm_configurations.h.xsl
index f91c2720c..215a17fdd 100644
--- a/misc/config_tools/xforms/vm_configurations.h.xsl
+++ b/misc/config_tools/xforms/vm_configurations.h.xsl
@@ -34,6 +34,7 @@
<xsl:call-template name="vm_count" />
<xsl:call-template name="sos_vm_bootarges" />
<xsl:call-template name="vm_vuart_num" />
+ <xsl:call-template name="ir_entries" />
You can embed the `value-of` node here. Defining a template for a
one-element template seems an overkill.
Done


Junjie Mao
 

"Junjie Mao" <junjie.mao@...> writes:

Chenli Wei <chenli.wei@...> writes:

The current code align MAX_IR_ENTRIE with the CONFIG_MAX_PT_IRQ_ENTRIE
roundup to 2^n, there is an issue of the powerof2_roundup to calculate
the macro, and the code style is very ugly when we use macro to fix it.

So this patch move the calculate and define of MAX_IR_ENTRIE to offline
tool.

Signed-off-by: Chenli Wei <chenli.wei@...>
Reviewed-by: Junjie Mao <junjie.mao@...>

Some minor comments below.

---
.../static_allocators/board_capability.py | 17 +++++++++++++++++
.../config_tools/xforms/vm_configurations.h.xsl | 5 +++++
2 files changed, 22 insertions(+)

diff --git a/misc/config_tools/static_allocators/board_capability.py b/misc/config_tools/static_allocators/board_capability.py
index 5a98f472d..75f72afc2 100644
--- a/misc/config_tools/static_allocators/board_capability.py
+++ b/misc/config_tools/static_allocators/board_capability.py
@@ -7,6 +7,23 @@

import common

+def powerof2_roundup(value):
+ result = value
+ for i in [1, 2, 4, 8, 16]:
+ result = result | result >> i
+ return result + 1
`1 << value.bit_length()` is simpler and more straightforward.
Need take care about the boundary values:

`0 if value == 0 else (1 << (value - 1).bit_length())`

--
Best Regards
Junjie Mao

+
+# Make sure all PT IRQs work w/ interrupt remapping or post interrupt
+def create_max_ir_entries(scenario_etree, allocation_etree):
+ pt_irq_entries = common.get_node(f"//MAX_PT_IRQ_ENTRIES/text()", scenario_etree)
+ if (pt_irq_entries is not None) and (int(pt_irq_entries) > 256):
+ ir_entries = powerof2_roundup(int(pt_irq_entries) - 1)
+ else:
+ ir_entries = 256
+
+ common.append_node("/acrn-config/hv/MAX_IR_ENTRIES", ir_entries, allocation_etree)
+
def fn(board_etree, scenario_etree, allocation_etree):
pci_bus_nums = board_etree.xpath("//bus[@type='pci']/@address")
common.append_node("/acrn-config/platform/MAX_PCI_BUS_NUM", hex(max(map(lambda x: int(x, 16), pci_bus_nums)) + 1), allocation_etree)
+ create_max_ir_entries(scenario_etree, allocation_etree)
diff --git a/misc/config_tools/xforms/vm_configurations.h.xsl b/misc/config_tools/xforms/vm_configurations.h.xsl
index f91c2720c..215a17fdd 100644
--- a/misc/config_tools/xforms/vm_configurations.h.xsl
+++ b/misc/config_tools/xforms/vm_configurations.h.xsl
@@ -34,6 +34,7 @@
<xsl:call-template name="vm_count" />
<xsl:call-template name="sos_vm_bootarges" />
<xsl:call-template name="vm_vuart_num" />
+ <xsl:call-template name="ir_entries" />
You can embed the `value-of` node here. Defining a template for a
one-element template seems an overkill.


chenli.wei
 

On 5/16/2022 12:47 PM, Junjie Mao wrote:
"Junjie Mao" <junjie.mao@...> writes:

Chenli Wei <chenli.wei@...> writes:

The current code align MAX_IR_ENTRIE with the CONFIG_MAX_PT_IRQ_ENTRIE
roundup to 2^n, there is an issue of the powerof2_roundup to calculate
the macro, and the code style is very ugly when we use macro to fix it.

So this patch move the calculate and define of MAX_IR_ENTRIE to offline
tool.

Signed-off-by: Chenli Wei <chenli.wei@...>
Reviewed-by: Junjie Mao <junjie.mao@...>

Some minor comments below.

---
.../static_allocators/board_capability.py | 17 +++++++++++++++++
.../config_tools/xforms/vm_configurations.h.xsl | 5 +++++
2 files changed, 22 insertions(+)

diff --git a/misc/config_tools/static_allocators/board_capability.py b/misc/config_tools/static_allocators/board_capability.py
index 5a98f472d..75f72afc2 100644
--- a/misc/config_tools/static_allocators/board_capability.py
+++ b/misc/config_tools/static_allocators/board_capability.py
@@ -7,6 +7,23 @@
import common
+def powerof2_roundup(value):
+ result = value
+ for i in [1, 2, 4, 8, 16]:
+ result = result | result >> i
+ return result + 1
`1 << value.bit_length()` is simpler and more straightforward.
Need take care about the boundary values:

`0 if value == 0 else (1 << (value - 1).bit_length())`
Thanks, I have send again with the V2 of HV patch