From: Alistair Francis <alistair23@gmail.com>
To: Rob Bradford <rbradford@rivosinc.com>
Cc: qemu-devel@nongnu.org, qemu-riscv@nongnu.org,
atishp@rivosinc.com, palmer@dabbelt.com,
alistair.francis@wdc.com, bin.meng@windriver.com,
liweiwei@iscas.ac.cn, dbarboza@ventanamicro.com,
zhiwei_liu@linux.alibaba.com
Subject: Re: [PATCH v3 2/6] target/riscv: Don't assume PMU counters are continuous
Date: Mon, 16 Oct 2023 14:23:08 +1000 [thread overview]
Message-ID: <CAKmqyKMAGREL8ymzXof8Q9arSmyxFnev758HC8Y2qb65vvbBXQ@mail.gmail.com> (raw)
In-Reply-To: <20231013110111.34619-3-rbradford@rivosinc.com>
On Fri, Oct 13, 2023 at 9:03 PM Rob Bradford <rbradford@rivosinc.com> wrote:
>
> Check the PMU available bitmask when checking if a counter is valid
> rather than comparing the index against the number of PMUs.
>
> Signed-off-by: Rob Bradford <rbradford@rivosinc.com>
> Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Alistair
> ---
> target/riscv/csr.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/target/riscv/csr.c b/target/riscv/csr.c
> index 85a31dc420..4383805fa3 100644
> --- a/target/riscv/csr.c
> +++ b/target/riscv/csr.c
> @@ -182,7 +182,8 @@ static RISCVException zcmt(CPURISCVState *env, int csrno)
> #if !defined(CONFIG_USER_ONLY)
> static RISCVException mctr(CPURISCVState *env, int csrno)
> {
> - int pmu_num = riscv_cpu_cfg(env)->pmu_num;
> + RISCVCPU *cpu = env_archcpu(env);
> + uint32_t pmu_avail_ctrs = cpu->pmu_avail_ctrs;
> int ctr_index;
> int base_csrno = CSR_MHPMCOUNTER3;
>
> @@ -191,7 +192,7 @@ static RISCVException mctr(CPURISCVState *env, int csrno)
> base_csrno += 0x80;
> }
> ctr_index = csrno - base_csrno;
> - if (!pmu_num || ctr_index >= pmu_num) {
> + if ((BIT(ctr_index) & pmu_avail_ctrs >> 3) == 0) {
> /* The PMU is not enabled or counter is out of range */
> return RISCV_EXCP_ILLEGAL_INST;
> }
> --
> 2.41.0
>
>
next prev parent reply other threads:[~2023-10-16 4:24 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-13 10:54 [PATCH v3 0/6] Support discontinuous PMU counters Rob Bradford
2023-10-13 10:54 ` [PATCH v3 1/6] target/riscv: Propagate error from PMU setup Rob Bradford
2023-10-13 10:54 ` [PATCH v3 2/6] target/riscv: Don't assume PMU counters are continuous Rob Bradford
2023-10-16 4:23 ` Alistair Francis [this message]
2023-10-13 10:54 ` [PATCH v3 3/6] target/riscv: Use existing PMU counter mask in FDT generation Rob Bradford
2023-10-16 4:23 ` Alistair Francis
2023-10-13 10:54 ` [PATCH v3 4/6] target/riscv: Add "pmu-mask" property to replace "pmu-num" Rob Bradford
2023-10-16 4:29 ` Alistair Francis
2023-10-13 10:54 ` [PATCH v3 5/6] docs/about/deprecated: Document RISC-V "pmu-num" deprecation Rob Bradford
2023-10-13 10:54 ` [PATCH v3 6/6] target/riscv: Use MAKE_64BIT_MASK instead of custom macro Rob Bradford
2023-10-16 4:29 ` Alistair Francis
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=CAKmqyKMAGREL8ymzXof8Q9arSmyxFnev758HC8Y2qb65vvbBXQ@mail.gmail.com \
--to=alistair23@gmail.com \
--cc=alistair.francis@wdc.com \
--cc=atishp@rivosinc.com \
--cc=bin.meng@windriver.com \
--cc=dbarboza@ventanamicro.com \
--cc=liweiwei@iscas.ac.cn \
--cc=palmer@dabbelt.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-riscv@nongnu.org \
--cc=rbradford@rivosinc.com \
--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;
as well as URLs for NNTP newsgroup(s).