On 11/02/2025 12:18, Grygorii Strashko wrote:
> 
> 
> The dt_device_for_passthrough() is called many times during Xen
> initialization and Dom0 creation. On every call it traverses struct
> dt_device_node properties list and compares compares properties name with
double "compares"

> "xen,passthrough" which is runtime overhead. This can be optimized by
Are you sure? Looking at the calls, it's almost only used at boot except for dt
overlay.

> marking dt_device_node as passthrough while unflattening DT.
> 
> This patch introduced new struct dt_device_node property "is_passthrough"
> which is filled if "xen,passthrough" property is present while unflattening
> DT and dt_device_for_passthrough() just return it's value.
In the past we were skeptical about adding new fields to the dt_device_node
structure for use cases like this one. I would say this optimization is not
worth it. Also, why would you optimize dt_device_for_passthrough but not
e.g. dt_device_is_available.

You can check with other Arm maintainers.

~Michal

> 
> Signed-off-by: Grygorii Strashko <grygorii_stras...@epam.com>
> ---
>  xen/common/device-tree/device-tree.c | 7 +++++--
>  xen/include/xen/device_tree.h        | 2 ++
>  2 files changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/xen/common/device-tree/device-tree.c 
> b/xen/common/device-tree/device-tree.c
> index d0528c582565..a329aaf576da 100644
> --- a/xen/common/device-tree/device-tree.c
> +++ b/xen/common/device-tree/device-tree.c
> @@ -1682,8 +1682,7 @@ bool dt_device_is_available(const struct dt_device_node 
> *device)
> 
>  bool dt_device_for_passthrough(const struct dt_device_node *device)
>  {
> -    return (dt_find_property(device, "xen,passthrough", NULL) != NULL);
> -
> +    return device->is_passthrough;
>  }
> 
>  static int __dt_parse_phandle_with_args(const struct dt_device_node *np,
> @@ -1913,6 +1912,7 @@ static unsigned long unflatten_dt_node(const void *fdt,
>          np->used_by = 0;
>          /* By default the device is not protected */
>          np->is_protected = false;
> +        np->is_passthrough = false;
>          INIT_LIST_HEAD(&np->domain_list);
> 
>          if ( new_format )
> @@ -2001,6 +2001,9 @@ static unsigned long unflatten_dt_node(const void *fdt,
>               * stuff */
>              if ( strcmp(pname, "ibm,phandle") == 0 )
>                  np->phandle = be32_to_cpup((__be32 *)*p);
> +
> +            if ( strcmp(pname, "xen,passthrough") == 0 )
> +                np->is_passthrough = true;
>              pp->name = pname;
>              pp->length = sz;
>              pp->value = (void *)*p;
> diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h
> index 5ff763bb80bb..96001d5b7843 100644
> --- a/xen/include/xen/device_tree.h
> +++ b/xen/include/xen/device_tree.h
> @@ -94,6 +94,8 @@ struct dt_device_node {
> 
>      /* IOMMU specific fields */
>      bool is_protected;
> +    /* Indicates DT device is for passthrough */
> +    bool is_passthrough;
> 
>  #ifdef CONFIG_STATIC_EVTCHN
>      /* HACK: Remove this if there is a need of space */
> --
> 2.34.1
> 


Reply via email to