public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Drew Fustini <fustini@kernel.org>
To: yunhui cui <cuiyunhui@bytedance.com>
Cc: "Paul Walmsley" <pjw@kernel.org>,
	"Palmer Dabbelt" <palmer@dabbelt.com>,
	"Albert Ou" <aou@eecs.berkeley.edu>,
	"Alexandre Ghiti" <alex@ghiti.fr>,
	"Radim Krčmář" <rkrcmar@ventanamicro.com>,
	"Samuel Holland" <samuel.holland@sifive.com>,
	"Adrien Ricciardi" <aricciardi@baylibre.com>,
	"Nicolas Pitre" <npitre@baylibre.com>,
	"Kornel Dulęba" <mindal@semihalf.com>,
	"Atish Patra" <atish.patra@linux.dev>,
	"Atish Kumar Patra" <atishp@rivosinc.com>,
	"Vasudevan Srinivasan" <vasu@rivosinc.com>,
	"Ved Shanbhogue" <ved@rivosinc.com>,
	"Chen Pei" <cp0613@linux.alibaba.com>,
	"Liu Zhiwei" <zhiwei_liu@linux.alibaba.com>,
	"Weiwei Li" <liwei1518@gmail.com>,
	guo.wenjia23@zte.com.cn, liu.qingtao2@zte.com.cn,
	"Conor Dooley" <conor+dt@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Rob Herring" <robh+dt@kernel.org>,
	"Reinette Chatre" <reinette.chatre@intel.com>,
	"Tony Luck" <tony.luck@intel.com>,
	"Babu Moger" <babu.moger@amd.com>,
	"Peter Newman" <peternewman@google.com>,
	"Fenghua Yu" <fenghua.yu@intel.com>,
	"James Morse" <james.morse@arm.com>,
	"Ben Horgan" <ben.horgan@arm.com>,
	"Dave Martin" <Dave.Martin@arm.com>,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-riscv@lists.infradead.org, x86@kernel.org
Subject: Re: [External] [PATCH RFC 08/19] RISC-V: QoS: add resctrl interface for CBQRI controllers
Date: Mon, 26 Jan 2026 13:02:12 -0800	[thread overview]
Message-ID: <aXfWVPg7YTToDKcQ@x1> (raw)
In-Reply-To: <CAEEQ3w=fnq5Rsv0A49LSOqVS8hYQExSOSRQ6C8e8v5k4jBWOow@mail.gmail.com>

On Mon, Jan 26, 2026 at 09:01:30PM +0800, yunhui cui wrote:
> Hi Drew,
> 
> On Tue, Jan 20, 2026 at 12:15 PM Drew Fustini <fustini@kernel.org> wrote:
> >
> > Add interface for CBQRI controller drivers to make use of the resctrl
> > filesystem.
> >
> > Co-developed-by: Adrien Ricciardi <aricciardi@baylibre.com>
> > Signed-off-by: Adrien Ricciardi <aricciardi@baylibre.com>
> > Signed-off-by: Drew Fustini <fustini@kernel.org>
> > ---
> >  arch/riscv/kernel/qos/qos_resctrl.c | 1191 +++++++++++++++++++++++++++++++++++
> >  1 file changed, 1191 insertions(+)
> >
> > diff --git a/arch/riscv/kernel/qos/qos_resctrl.c b/arch/riscv/kernel/qos/qos_resctrl.c
> > new file mode 100644
> > index 000000000000..5e3a65342e9b
> > --- /dev/null
> > +++ b/arch/riscv/kernel/qos/qos_resctrl.c
[..]
> > +/* Set capacity block mask (cc_block_mask) */
> > +static void cbqri_set_cbm(struct cbqri_controller *ctrl, u64 cbm)
> > +{
> > +               int reg_offset;
> > +               u64 reg;
> > +
> > +               reg_offset = CBQRI_CC_BLOCK_MASK_OFF;
> > +               reg = ioread64(ctrl->base + reg_offset);
> > +
> > +               reg = cbm;
> > +               iowrite64(reg, ctrl->base + reg_offset);
> > +}
> > +
> 
> too much indentation ?

Thanks, will fix indentation for cbqri_set_cbm, cbqri_set_rbwb, and
cbqri_get_rbwb.

> > +static int cbqri_wait_busy_flag(struct cbqri_controller *ctrl, int reg_offset)
> > +{
> > +       unsigned long timeout = jiffies + (HZ / 10); /* Timeout after 100ms */
> 
> hung task ?

Good point, this is too long. I tried 100 us which wasn't long enough
for Qemu on my system but 1,000 us worked okay.

I will change to 1,000 us.

        unsigned long timeout = jiffies + usecs_to_jiffies(1000);

> > +u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_ctrl_domain *d,
> > +                           u32 closid, enum resctrl_conf_type type)
> > +{
> > +       struct cbqri_resctrl_dom *hw_dom;
> > +       struct cbqri_controller *ctrl;
> > +       int reg_offset;
> > +       u32 percent;
> > +       u32 rbwb;
> > +       u64 reg;
> > +       int err;
> > +
> > +       hw_dom = container_of(d, struct cbqri_resctrl_dom, resctrl_ctrl_dom);
> > +
> > +       ctrl = hw_dom->hw_ctrl;
> > +
> > +       if (!r->alloc_capable)
> > +               return -EINVAL;
> 
> u32 ?

Good point.  I looked at mpam_resctrl.c and it returns the default value
on error:
https://lore.kernel.org/all/20260112165914.4086692-19-ben.horgan@arm.com/

I will change to 'return resctrl_get_default_ctrl(r)'.

> > +
> > +       switch (r->rid) {
> > +       case RDT_RESOURCE_L2:
> > +       case RDT_RESOURCE_L3:
> > +               /* Clear cc_block_mask before read limit operation */
> > +               cbqri_set_cbm(ctrl, 0);
> > +
> > +               /* Capacity read limit operation for RCID (closid) */
> > +               err = cbqri_cc_alloc_op(ctrl, CBQRI_CC_ALLOC_CTL_OP_READ_LIMIT, type, closid);
> > +               if (err < 0) {
> > +                       pr_err("%s(): operation failed: err = %d", __func__, err);
> > +                       return -EIO;
> 
> u32 ?

Same as above.

> > +               }
> > +
> > +               /* Read capacity block mask for RCID (closid) */
> > +               reg_offset = CBQRI_CC_BLOCK_MASK_OFF;
> > +               reg = ioread64(ctrl->base + reg_offset);
> > +
> > +               /* Update the config value for the closid in this domain */
> > +               hw_dom->ctrl_val[closid] = reg;
> > +               return hw_dom->ctrl_val[closid];
> > +
> > +       case RDT_RESOURCE_MBA:
> > +               /* Capacity read limit operation for RCID (closid) */
> > +               err = cbqri_bc_alloc_op(ctrl, CBQRI_CC_ALLOC_CTL_OP_READ_LIMIT, closid);
> > +               if (err < 0) {
> > +                       pr_err("%s(): operation failed: err = %d", __func__, err);
> > +                       return -EIO;
> > +               }
> > +
> > +               hw_dom->ctrl_val[closid] = cbqri_get_rbwb(ctrl);
> > +
> > +               /* Convert from bandwidth blocks to percent */
> > +               rbwb = hw_dom->ctrl_val[closid];
> > +               rbwb *= 100;
> > +               percent = rbwb / ctrl->bc.nbwblks;
> > +               if (rbwb % ctrl->bc.nbwblks)
> > +                       percent++;
> 
> set: 10, get 11 ?

The intention was to handle rounding up but I can drop this increment.

[..]
> > +static int cbqri_probe_controller(struct cbqri_controller_info *ctrl_info,
> > +                                 struct cbqri_controller *ctrl)
> > +{
> > +       int err = 0, status;
> > +       u64 reg;
> > +
> > +       pr_info("controller info: type=%d addr=0x%lx size=%lu max-rcid=%u max-mcid=%u",
> > +               ctrl_info->type, ctrl_info->addr, ctrl_info->size,
> > +               ctrl_info->rcid_count, ctrl_info->mcid_count);
> > +
> > +       /* max_rmid is used by resctrl_arch_system_num_rmid_idx() */
> > +       max_rmid = ctrl_info->mcid_count;
> > +
> > +       ctrl->ctrl_info = ctrl_info;
> > +
> > +       /* Try to access the memory-mapped CBQRI registers */
> > +       if (!request_mem_region(ctrl_info->addr, ctrl_info->size, "cbqri_controller")) {
> > +               pr_warn("%s(): return %d", __func__, err);
> > +               return err;
> 
> err = 0?

Good point, I will change it to return -EBUSY.

[..]
> > +int qos_resctrl_setup(void)
> > +{
> > +       struct rdt_ctrl_domain *domain, *domain_temp;
> > +       struct cbqri_controller_info *ctrl_info;
> > +       struct cbqri_controller *ctrl;
> > +       struct cbqri_resctrl_res *res;
> > +       static int found_controllers;
> > +       int err = 0;
> > +       int id = 0;
> > +       int i;
> > +
> > +       list_for_each_entry(ctrl_info, &cbqri_controllers, list) {
> > +               err = cbqri_probe_controller(ctrl_info, &controllers[found_controllers]);
> > +               if (err) {
> > +                       pr_warn("%s(): failed (%d)", __func__, err);
> > +                       goto err_unmap_controllers;
> > +               }
> > +
> > +               found_controllers++;
> > +               if (found_controllers > MAX_CONTROLLERS) {
> > +                       pr_warn("%s(): increase MAX_CONTROLLERS value", __func__);
> > +                       break;
> > +               }
> > +       }
> > +
> > +       for (i = 0; i < RDT_NUM_RESOURCES; i++) {
> > +               res = &cbqri_resctrl_resources[i];
> > +               INIT_LIST_HEAD(&res->resctrl_res.ctrl_domains);
> > +               INIT_LIST_HEAD(&res->resctrl_res.mon_domains);
> > +               res->resctrl_res.rid = i;
> > +       }
> > +
> > +       for (i = 0; i < found_controllers; i++) {
> > +               ctrl = &controllers[i];
> 
> controllers[6] ?

This is limitation from the proof-of-concept. I need to refactor this so
that it is dynamically allocated based on the number of controllers
present in the system

Thanks,
Drew

  reply	other threads:[~2026-01-26 21:02 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-20  4:14 [PATCH RFC 00/19] RISC-V: QoS: add CBQRI resctrl interface Drew Fustini
2026-01-20  4:14 ` [PATCH RFC 01/19] dt-bindings: riscv: Add Ssqosid extension description Drew Fustini
2026-01-20  4:14 ` [PATCH RFC 02/19] RISC-V: Detect the Ssqosid extension Drew Fustini
2026-01-20  4:14 ` [PATCH RFC 03/19] RISC-V: Add support for srmcfg CSR from Ssqosid ext Drew Fustini
2026-01-20  4:14 ` [PATCH RFC 04/19] RISC-V: QoS: define properties of CBQRI controllers Drew Fustini
2026-01-20  4:14 ` [PATCH RFC 05/19] RISC-V: QoS: define CBQRI capacity and bandwidth capabilities Drew Fustini
2026-01-20  4:14 ` [PATCH RFC 06/19] RISC-V: QoS: define CBQRI resctrl resources and domains Drew Fustini
2026-01-20  4:14 ` [PATCH RFC 07/19] RISC-V: QoS: define prototypes for resctrl interface Drew Fustini
2026-01-20  4:14 ` [PATCH RFC 08/19] RISC-V: QoS: add resctrl interface for CBQRI controllers Drew Fustini
2026-01-26 13:01   ` [External] " yunhui cui
2026-01-26 21:02     ` Drew Fustini [this message]
2026-01-27 22:10       ` Drew Fustini
2026-03-26 11:05   ` guo.wenjia23
2026-01-20  4:14 ` [PATCH RFC 09/19] RISC-V: QoS: expose implementation to resctrl Drew Fustini
2026-01-20  4:14 ` [PATCH RFC 10/19] RISC-V: QoS: add late_initcall to setup resctrl interface Drew Fustini
2026-01-20  4:14 ` [PATCH RFC 11/19] RISC-V: QoS: add to build when CONFIG_RISCV_ISA_SSQOSID set Drew Fustini
2026-01-20  4:14 ` [PATCH RFC 12/19] RISC-V: QoS: make CONFIG_RISCV_ISA_SSQOSID select resctrl Drew Fustini
2026-01-20  4:14 ` [PATCH RFC 13/19] dt-bindings: riscv: add riscv,cbqri bindings Drew Fustini
2026-01-20  4:14 ` [PATCH NFU RFC 14/19] resctrl: riscv: add CBQRI cache controller driver Drew Fustini
2026-01-20  4:14 ` [PATCH NFU RFC 15/19] resctrl: riscv: add CBQRI bandwidth " Drew Fustini
2026-01-20  4:14 ` [PATCH NFU RFC 16/19] resctrl: riscv: build CBQRI drivers Drew Fustini
2026-01-20  4:14 ` [PATCH NFU RFC 17/19] riscv: dts: qemu: add dump from virt machine Drew Fustini
2026-01-20  4:14 ` [PATCH NFU RFC 18/19] riscv: dts: qemu: add CBQRI controller nodes Drew Fustini
2026-01-20  4:14 ` [PATCH NFU RFC 19/19] riscv: dts: build qemu dtb for CONFIG_ARCH_VIRT Drew Fustini
2026-01-22 22:31 ` [PATCH RFC 00/19] RISC-V: QoS: add CBQRI resctrl interface Reinette Chatre
2026-01-24 18:00   ` Drew Fustini
2026-01-26 13:14 ` [External] " yunhui cui
2026-01-26 20:11   ` Drew Fustini
2026-01-27  2:33     ` yunhui cui

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aXfWVPg7YTToDKcQ@x1 \
    --to=fustini@kernel.org \
    --cc=Dave.Martin@arm.com \
    --cc=alex@ghiti.fr \
    --cc=aou@eecs.berkeley.edu \
    --cc=aricciardi@baylibre.com \
    --cc=atish.patra@linux.dev \
    --cc=atishp@rivosinc.com \
    --cc=babu.moger@amd.com \
    --cc=ben.horgan@arm.com \
    --cc=conor+dt@kernel.org \
    --cc=cp0613@linux.alibaba.com \
    --cc=cuiyunhui@bytedance.com \
    --cc=devicetree@vger.kernel.org \
    --cc=fenghua.yu@intel.com \
    --cc=guo.wenjia23@zte.com.cn \
    --cc=james.morse@arm.com \
    --cc=krzk+dt@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=liu.qingtao2@zte.com.cn \
    --cc=liwei1518@gmail.com \
    --cc=mindal@semihalf.com \
    --cc=npitre@baylibre.com \
    --cc=palmer@dabbelt.com \
    --cc=peternewman@google.com \
    --cc=pjw@kernel.org \
    --cc=reinette.chatre@intel.com \
    --cc=rkrcmar@ventanamicro.com \
    --cc=robh+dt@kernel.org \
    --cc=samuel.holland@sifive.com \
    --cc=tony.luck@intel.com \
    --cc=vasu@rivosinc.com \
    --cc=ved@rivosinc.com \
    --cc=x86@kernel.org \
    --cc=zhiwei_liu@linux.alibaba.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox