qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Igor Mammedov <imammedo@redhat.com>
To: LeoHou <LeoHou@canaan-creative.com>
Cc: "Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Dongxue Zhang" <elta.era@gmail.com>,
	"Alistair Francis" <alistair.francis@wdc.com>,
	"Anup Patel" <apatel@ventanamicro.com>,
	"Bin Meng" <bin.meng@windriver.com>,
	"Daniel Henrique Barboza" <dbarboza@ventanamicro.com>,
	侯英乐 <houyingle@canaan-creative.com>,
	"Liu Zhiwei" <zhiwei_liu@linux.alibaba.com>,
	"Mayuresh Chitale" <mchitale@ventanamicro.com>,
	"Palmer Dabbelt" <palmer@dabbelt.com>,
	"Palmer Dabbelt" <palmer@rivosinc.com>,
	"Weiwei Li" <liweiwei@iscas.ac.cn>,
	"QEMU Developers" <qemu-devel@nongnu.org>,
	qemu-riscv <qemu-riscv@nongnu.org>,
	张东雪 <zhangdongxue@canaan-creative.com>,
	"leohou1402@gmail.com" <leohou1402@gmail.com>
Subject: Re: [PATCH 1/1] hw/intc/riscv_aclint:Change the way to get CPUState from hard-base to pu_index
Date: Fri, 24 Nov 2023 15:47:40 +0100	[thread overview]
Message-ID: <20231124154740.400aeca9@imammedo.users.ipa.redhat.com> (raw)
In-Reply-To: <BJSPR01MB062758831AA8BF73856F5DFC95B3A@BJSPR01MB0627.CHNPR01.prod.partner.outlook.cn>

On Mon, 13 Nov 2023 04:25:43 +0000
LeoHou <LeoHou@canaan-creative.com> wrote:

> On 9/11/23 23:26, Philippe Mathieu-Daudé  wrote:
>  
> >Hi Leo,
> >
> >First, I can't find your patch in my mailbox, so I'm replying to
> >Dongxue's review.
> >
> >On 9/11/23 03:41, Dongxue Zhang wrote:  
> >> Reviewed-by: Dongxue Zhang <zhangdongxue@canaan-creative.com>
> >> 
> >>   
> >>> On Thu, Nov 9, 2023 at 10:22 AM Leo Hou <LeoHou@canaan-creative.com> wrote:
> >>>
> >>> From: Leo Hou <houyingle@canaan-creative.com>
> >>>
> >>> cpu_by_arch_id() uses hartid-base as the index to obtain the corresponding CPUState structure variable.
> >>> qemu_get_cpu() uses cpu_index as the index to obtain the corresponding CPUState structure variable.
> >>>
> >>> In heterogeneous CPU or multi-socket scenarios, multiple aclint needs to be instantiated,
> >>> and the hartid-base of each cpu bound by aclint can start from 0. If cpu_by_arch_id() is still used
> >>> in this case, all aclint will bind to the earliest initialized hart with hartid-base 0 and cause conflicts.
> >>>
> >>> So with cpu_index as the index, use qemu_get_cpu() to get the CPUState struct variable,
> >>> and connect the aclint interrupt line to the hart of the CPU indexed with cpu_index
> >>> (the corresponding hartid-base can start at 0). It's more reasonable.
> >>>
> >>> Signed-off-by: Leo Hou <houyingle@canaan-creative.com>
> >>> ---
> >>>   hw/intc/riscv_aclint.c | 16 ++++++++--------
> >>>   1 file changed, 8 insertions(+), 8 deletions(-)
> >>>
> >>>diff --git a/hw/intc/riscv_aclint.c b/hw/intc/riscv_aclint.c
> >>> index ab1a0b4b3a..be8f539fcb 100644
> >>> --- a/hw/intc/riscv_aclint.c
> >>> +++ b/hw/intc/riscv_aclint.c
> >>> @@ -130,7 +130,7 @@ static uint64_t riscv_aclint_mtimer_read(void *opaque, hwaddr addr,
> >>>           addr < (mtimer->timecmp_base + (mtimer->num_harts << 3))) {
> >>>           size_t hartid = mtimer->hartid_base +
> >>>                           ((addr - mtimer->timecmp_base) >> 3);
> >>> -        CPUState *cpu = cpu_by_arch_id(hartid);
> >>> +        CPUState *cpu = qemu_get_cpu(hartid);  
> >
> >There is some code smell here. qemu_get_cpu() shouldn't be called by
> >device models, but only by accelerators.  

cpu_index might match arch_id in simple cases but might be not the same
when architecture/topo gets more complex, and just breaks in case of
sparse or out of order created CPUs/intc (hotplug case).
So using it is like a ticking bomb.


> Yes, qemu_get_cpu() is designed to be called by accelerators.
> But there is currently no new API to support multi-socket and
> heterogeneous processor architectures,and sifive_plic has been
> designed with qemu_get_cpu().
> Please refer to:
> [1] https://lore.kernel.org/qemu-devel/1519683480-33201-16-git-send-email-mjc@sifive.com/
> [2] https://lore.kernel.org/qemu-devel/20200825184836.1282371-3-alistair.francis@wdc.com/
> 
> 
> >Maybe the timer should get a link of the hart array it belongs to,
> >and offset to this array base hartid?  
> 
> The same problem exists not only with timer, but also with aclint.
> There needs to be a general approach to this problem.
> 
> 
> >I'm going to
> >NACK
> >this patch until further review / clarifications.  
> 
> Regards,
> 
> Leo Hou.



      parent reply	other threads:[~2023-11-24 14:48 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1699496263.git.houyingle@canaan-creative.com>
     [not found] ` <6d1d8cc8c2b37b145e4a826095619097fa4a34d5.1699496263.git.houyingle@canaan-creative.com>
2023-11-09  2:41   ` [PATCH 1/1] hw/intc/riscv_aclint:Change the way to get CPUState from hard-base to pu_index Dongxue Zhang
2023-11-09 15:26     ` Philippe Mathieu-Daudé
2023-11-13  4:25       ` LeoHou
2023-11-20 12:16         ` Philippe Mathieu-Daudé
2023-11-21  4:25           ` Alistair Francis
2023-11-24 14:47         ` Igor Mammedov [this message]

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=20231124154740.400aeca9@imammedo.users.ipa.redhat.com \
    --to=imammedo@redhat.com \
    --cc=LeoHou@canaan-creative.com \
    --cc=alistair.francis@wdc.com \
    --cc=apatel@ventanamicro.com \
    --cc=bin.meng@windriver.com \
    --cc=dbarboza@ventanamicro.com \
    --cc=elta.era@gmail.com \
    --cc=houyingle@canaan-creative.com \
    --cc=leohou1402@gmail.com \
    --cc=liweiwei@iscas.ac.cn \
    --cc=mchitale@ventanamicro.com \
    --cc=palmer@dabbelt.com \
    --cc=palmer@rivosinc.com \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-riscv@nongnu.org \
    --cc=zhangdongxue@canaan-creative.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).