Re: [PATCH v18 13/17] x86/resctrl: Handle removing directories in Sub-NUMA (SNC) mode

Reinette Chatre
2024-05-22T21:20:48Z

Hi Tony,

On 5/15/2024 3:23 PM, Tony Luck wrote:
> In SNC mode there are multiple subdirectories in each L3 level monitor
> directory (one for each SNC node). If all the CPUs in an SNC node are
> taken offline, then just that SNC node directory must be removed. In

imperative tone needed

> non-SNC mode, or when the last SNC node directory is removed, also
> remove the L3 monitor directory.

There is a disconnect between changelog and code. The code tries to be
generic while the changelog is as specific to SNC as possible. This makes
it hard to go from changelog (ignoring that changelog does not follow x86
customs to begin with) to patch.

>
> Signed-off-by: Tony Luck <tony.luck@intel.com>
> ---
> arch/x86/kernel/cpu/resctrl/rdtgroup.c | 43 +++++++++++++++++++++-----
> 1 file changed, 36 insertions(+), 7 deletions(-)
>
> diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
> index f0f468babdea..cac32ddd3afd 100644
> --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
> +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
> @@ -3011,17 +3011,46 @@ static int mon_addfile(struct kernfs_node *parent_kn, const char *name,
> * and monitor groups with given domain id.
> */
> static void rmdir_mondata_subdir_allrdtgrp(struct rdt_resource *r,
> - unsigned int dom_id)
> + struct rdt_mon_domain *d)
> {
> struct rdtgroup *prgrp, *crgrp;
> + struct rdt_mon_domain *dom;
> + bool remove_all = true;
> + struct kernfs_node *kn;
> + char subname[32];
> char name[32];
>
> + sprintf(name, "mon_%s_%02d", r->name, d->display_id);
> + if (r->mon_scope != r->mon_display_scope) {
> + int count = 0;
> +
> + list_for_each_entry(dom, &r->mon_domains, hdr.list)
> + if (d->display_id == dom->display_id)
> + count++;
> + if (count > 1) {
> + remove_all = false;
> + sprintf(subname, "mon_sub_%s_%02d", r->name, d->hdr.id);
> + }
> + }

This continues to look suspect to me. When I took a closer look during previous
version I thought this information can only be accessed via inode. Seeing this
code again made me look more closely and it seems there is no problem to just
query how many subdirectories a directory has. See for example, kobject_has_children().
Doing something like that seems more intuitive than this quirky way to set and
use a flag.

> +
> list_for_each_entry(prgrp, &rdt_all_groups, rdtgroup_list) {
> - sprintf(name, "mon_%s_%02d", r->name, dom_id);
> - kernfs_remove_by_name(prgrp->mon.mon_data_kn, name);
> + if (remove_all) {
> + kernfs_remove_by_name(prgrp->mon.mon_data_kn, name);
> + } else {
> + kn = kernfs_find_and_get_ns(prgrp->mon.mon_data_kn, name, NULL);

kernfs_find_and_get()?

> + if (kn)
> + kernfs_remove_by_name(kn, subname);
> + }
>
> - list_for_each_entry(crgrp, &prgrp->mon.crdtgrp_list, mon.crdtgrp_list)
> - kernfs_remove_by_name(crgrp->mon.mon_data_kn, name);
> + list_for_each_entry(crgrp, &prgrp->mon.crdtgrp_list, mon.crdtgrp_list) {
> + if (remove_all) {
> + kernfs_remove_by_name(crgrp->mon.mon_data_kn, name);
> + } else {
> + kn = kernfs_find_and_get_ns(prgrp->mon.mon_data_kn, name, NULL);

copy&paste ?

> + if (kn)
> + kernfs_remove_by_name(kn, subname);
> + }
> + }
> }
> }
>
> @@ -3111,8 +3140,8 @@ static int mkdir_mondata_subdir(struct kernfs_node *parent_kn,
> static void mkdir_mondata_subdir_allrdtgrp(struct rdt_resource *r,
> struct rdt_mon_domain *d)
> {
> - struct kernfs_node *parent_kn;
> struct rdtgroup *prgrp, *crgrp;
> + struct kernfs_node *parent_kn;
> struct list_head *head;
>

Stray snippet?

> list_for_each_entry(prgrp, &rdt_all_groups, rdtgroup_list) {
> @@ -3984,7 +4013,7 @@ void resctrl_offline_mon_domain(struct rdt_resource *r, struct rdt_mon_domain *d
> * per domain monitor data directories.
> */
> if (resctrl_mounted && resctrl_arch_mon_capable())
> - rmdir_mondata_subdir_allrdtgrp(r, d->hdr.id);
> + rmdir_mondata_subdir_allrdtgrp(r, d);
>
> if (is_mbm_enabled())
> cancel_delayed_work(&d->mbm_over);

Reinette