[RFC,v2,7/7] x86/resctrl: Add debug files when mounted with debug option

Message ID 167537445777.647488.12333202522131465679.stgit@bmoger-ubuntu
State New
Headers
Series x86/resctrl: Miscellaneous resctrl features |

Commit Message

Moger, Babu Feb. 2, 2023, 9:47 p.m. UTC
  Add the debug files to the resctrl hierarchy.

Signed-off-by: Babu Moger <babu.moger@amd.com>
---
 arch/x86/kernel/cpu/resctrl/rdtgroup.c |   27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
  

Comments

Fenghua Yu Feb. 17, 2023, 1:50 a.m. UTC | #1
Hi, Babu,

On 2/2/23 13:47, Babu Moger wrote:
> Add the debug files to the resctrl hierarchy.
> 
> Signed-off-by: Babu Moger <babu.moger@amd.com>
> ---
>   arch/x86/kernel/cpu/resctrl/rdtgroup.c |   27 +++++++++++++++++++++++++++
>   1 file changed, 27 insertions(+)
> 
> diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
> index c35d91b04de6..b7c72b011264 100644
> --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
> +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
> @@ -2398,6 +2398,31 @@ static int mkdir_mondata_all(struct kernfs_node *parent_kn,
>   			     struct rdtgroup *prgrp,
>   			     struct kernfs_node **mon_data_kn);
>   
> +void resctrl_add_debug_file(struct kernfs_node *parent_kn,
> +			    const char *config, unsigned long fflags,
> +			    bool debug)
> +{
> +	struct rftype *rft;
> +
> +	rft = rdtgroup_get_rftype_by_name(config);
> +	if (debug && rft) {
> +		rft->fflags |= fflags;
> +		rdtgroup_add_file(parent_kn, rft);
> +	} else if (rft) {
> +		rft->fflags &= ~fflags;
> +		kernfs_remove_by_name(parent_kn, config);
> +	}
> +}
> +
> +static void resctrl_add_debug_files(bool debug)
> +{
> +	resctrl_add_debug_file(rdtgroup_default.kn, "rmid",
> +			       RFTYPE_BASE, debug);
> +	resctrl_add_debug_file(rdtgroup_default.kn, "closid",
> +			       RFTYPE_BASE_CTRL, debug);
> +	kernfs_activate(rdtgroup_default.kn);
> +}
> +
>   static int rdt_enable_ctx(struct rdt_fs_context *ctx)
>   {
>   	int ret = 0;
> @@ -2411,6 +2436,8 @@ static int rdt_enable_ctx(struct rdt_fs_context *ctx)
>   	if (!ret && ctx->enable_mba_mbps)
>   		ret = set_mba_sc(true);
>    > +	resctrl_add_debug_files(ctx->debug);

It's better to change to:
+	if (ctx->debug)
+		resctrl_add_debug_files();

Then the functions in the call chain can remove 'debug' parameter and 
can be simpler.
> +
>   	return ret;
>   }
>   
> 
> 
Thanks.

-Fenghua
  
Moger, Babu Feb. 17, 2023, 5:49 p.m. UTC | #2
Hi Fenghua,

On 2/16/2023 7:50 PM, Fenghua Yu wrote:
> Hi, Babu,
>
> On 2/2/23 13:47, Babu Moger wrote:
>> Add the debug files to the resctrl hierarchy.
>>
>> Signed-off-by: Babu Moger <babu.moger@amd.com>
>> ---
>>   arch/x86/kernel/cpu/resctrl/rdtgroup.c |   27 
>> +++++++++++++++++++++++++++
>>   1 file changed, 27 insertions(+)
>>
>> diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c 
>> b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
>> index c35d91b04de6..b7c72b011264 100644
>> --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
>> +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
>> @@ -2398,6 +2398,31 @@ static int mkdir_mondata_all(struct 
>> kernfs_node *parent_kn,
>>                    struct rdtgroup *prgrp,
>>                    struct kernfs_node **mon_data_kn);
>>   +void resctrl_add_debug_file(struct kernfs_node *parent_kn,
>> +                const char *config, unsigned long fflags,
>> +                bool debug)
>> +{
>> +    struct rftype *rft;
>> +
>> +    rft = rdtgroup_get_rftype_by_name(config);
>> +    if (debug && rft) {
>> +        rft->fflags |= fflags;
>> +        rdtgroup_add_file(parent_kn, rft);
>> +    } else if (rft) {
>> +        rft->fflags &= ~fflags;
>> +        kernfs_remove_by_name(parent_kn, config);
>> +    }
>> +}
>> +
>> +static void resctrl_add_debug_files(bool debug)
>> +{
>> +    resctrl_add_debug_file(rdtgroup_default.kn, "rmid",
>> +                   RFTYPE_BASE, debug);
>> +    resctrl_add_debug_file(rdtgroup_default.kn, "closid",
>> +                   RFTYPE_BASE_CTRL, debug);
>> +    kernfs_activate(rdtgroup_default.kn);
>> +}
>> +
>>   static int rdt_enable_ctx(struct rdt_fs_context *ctx)
>>   {
>>       int ret = 0;
>> @@ -2411,6 +2436,8 @@ static int rdt_enable_ctx(struct rdt_fs_context 
>> *ctx)
>>       if (!ret && ctx->enable_mba_mbps)
>>           ret = set_mba_sc(true);
>>    > +    resctrl_add_debug_files(ctx->debug);
>
> It's better to change to:
> +    if (ctx->debug)
> +        resctrl_add_debug_files();
>
> Then the functions in the call chain can remove 'debug' parameter and 
> can be simpler.

Actually, debug parameter is required in the resctrl_add_debug_file to 
delete the file if it was mounted with debug option last time.

Thanks

Babu
  

Patch

diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
index c35d91b04de6..b7c72b011264 100644
--- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
+++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
@@ -2398,6 +2398,31 @@  static int mkdir_mondata_all(struct kernfs_node *parent_kn,
 			     struct rdtgroup *prgrp,
 			     struct kernfs_node **mon_data_kn);
 
+void resctrl_add_debug_file(struct kernfs_node *parent_kn,
+			    const char *config, unsigned long fflags,
+			    bool debug)
+{
+	struct rftype *rft;
+
+	rft = rdtgroup_get_rftype_by_name(config);
+	if (debug && rft) {
+		rft->fflags |= fflags;
+		rdtgroup_add_file(parent_kn, rft);
+	} else if (rft) {
+		rft->fflags &= ~fflags;
+		kernfs_remove_by_name(parent_kn, config);
+	}
+}
+
+static void resctrl_add_debug_files(bool debug)
+{
+	resctrl_add_debug_file(rdtgroup_default.kn, "rmid",
+			       RFTYPE_BASE, debug);
+	resctrl_add_debug_file(rdtgroup_default.kn, "closid",
+			       RFTYPE_BASE_CTRL, debug);
+	kernfs_activate(rdtgroup_default.kn);
+}
+
 static int rdt_enable_ctx(struct rdt_fs_context *ctx)
 {
 	int ret = 0;
@@ -2411,6 +2436,8 @@  static int rdt_enable_ctx(struct rdt_fs_context *ctx)
 	if (!ret && ctx->enable_mba_mbps)
 		ret = set_mba_sc(true);
 
+	resctrl_add_debug_files(ctx->debug);
+
 	return ret;
 }