Re: [PATCH v3 06/26] fs-x86/rectrl: Improve domain type checking

Reinette Chatre
2025-04-18T21:41:07Z

Hi Tony,

On 4/7/25 4:40 PM, Tony Luck wrote:
> The rdt_domain_hdr structure is used in both control and monitor
> domain structures to provide common methods for operations such as
> adding a CPU to a domain, removing a CPU from a domain, accessing
> the mask of all CPUs in a domain.
>
> The "type" field provides a simple check whether a domain is a
> control or monitor domain so that programming errors operating
> on domains will be quickly caught.
>
> To prepare for additional domain types that depend on the rdt_resource
> to which they are connected add the resource id into the type.
>
> Signed-off-by: Tony Luck <tony.luck@intel.com>
> ---
> include/linux/resctrl.h | 19 ++++++++++---------
> arch/x86/kernel/cpu/resctrl/core.c | 12 ++++++------
> fs/resctrl/ctrlmondata.c | 2 +-
> 3 files changed, 17 insertions(+), 16 deletions(-)
>
> diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h
> index d6a926b6fc0e..177f9879bae1 100644
> --- a/include/linux/resctrl.h
> +++ b/include/linux/resctrl.h
> @@ -111,11 +111,6 @@ struct resctrl_staged_config {
> bool have_new_ctrl;
> };
>
> -enum resctrl_domain_type {
> - RESCTRL_CTRL_DOMAIN,
> - RESCTRL_MON_DOMAIN,
> -};
> -
> /**
> * struct rdt_domain_hdr - common header for different domain types
> * @list: all instances of this resource
> @@ -124,12 +119,18 @@ enum resctrl_domain_type {
> * @cpu_mask: which CPUs share this resource
> */
> struct rdt_domain_hdr {
> - struct list_head list;
> - int id;
> - enum resctrl_domain_type type;
> - struct cpumask cpu_mask;
> + struct list_head list;
> + int id;
> + u32 type;
> + struct cpumask cpu_mask;
> };
>
> +/* Bitfields in rdt_domain_hdr.type */
> +#define DOMTYPE_RID GENMASK(8, 0)
> +#define DOMTYPE_CTRL BIT(9)
> +#define DOMTYPE_MON BIT(10)
> +#define DOMTYPE(rid, type) (((rid) & DOMTYPE_RID) | (type))
> +

This seems unnecessarily complicated to me. Why not just add the
resource id to the domain header?

Reinette