* How to synchronize CPUs on MMIO read?
@ 2023-08-16 16:31 Igor Lesik
2023-08-16 18:16 ` Alex Bennée
2023-08-17 21:51 ` Richard Henderson
0 siblings, 2 replies; 3+ messages in thread
From: Igor Lesik @ 2023-08-16 16:31 UTC (permalink / raw)
To: qemu-devel@nongnu.org
[-- Attachment #1: Type: text/plain, Size: 599 bytes --]
Hi.
I need to model some custom HW that synchronizes CPUs when they read MMIO register N: MMIO read does not return until another CPU writes to MMIO register M. I modeled this behavior with a) on MMIO read of N, save CPU into a list of waiting CPUs and put it asleep with cpu_interrupt(current_cpu, CPU_INTERRUPT_HALT) and b) on MMIO write to M, wake all waiting CPUs with cpu->halted = 0; qemu_cpu_kick(cpu). It seems to work fine. However, this HW has a twist: MMIO read of N returns a value that was written by MMIO write to M. Can anyone please advise how this could be done?
Thanks!
Igor
[-- Attachment #2: Type: text/html, Size: 2235 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: How to synchronize CPUs on MMIO read?
2023-08-16 16:31 How to synchronize CPUs on MMIO read? Igor Lesik
@ 2023-08-16 18:16 ` Alex Bennée
2023-08-17 21:51 ` Richard Henderson
1 sibling, 0 replies; 3+ messages in thread
From: Alex Bennée @ 2023-08-16 18:16 UTC (permalink / raw)
To: qemu-devel@nongnu.org, Igor Lesik
Igor Lesik <lesikigor@meta.com> writes:
> Hi.
>
> I need to model some custom HW that synchronizes CPUs when they read MMIO register N: MMIO read does not
> return until another CPU writes to MMIO register M. I modeled this behavior with a) on MMIO read of N, save CPU into
> a list of waiting CPUs and put it asleep with cpu_interrupt(current_cpu, CPU_INTERRUPT_HALT) and b) on MMIO write
> to M, wake all waiting CPUs with cpu->halted = 0; qemu_cpu_kick(cpu). It seems to work fine. However, this HW has a
> twist: MMIO read of N returns a value that was written by MMIO write to M. Can anyone please advise how this could
> be done?
Under TCG all MMIO accesses should be serialised by the BQL so no other
MMIO access can be taking place until you finish the operation.
>
>
>
> Thanks!
>
> Igor
--
Alex Bennée
Virtualisation Tech Lead @ Linaro
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: How to synchronize CPUs on MMIO read?
2023-08-16 16:31 How to synchronize CPUs on MMIO read? Igor Lesik
2023-08-16 18:16 ` Alex Bennée
@ 2023-08-17 21:51 ` Richard Henderson
1 sibling, 0 replies; 3+ messages in thread
From: Richard Henderson @ 2023-08-17 21:51 UTC (permalink / raw)
To: Igor Lesik, qemu-devel@nongnu.org
On 8/16/23 09:31, Igor Lesik wrote:
> Hi.
>
> I need to model some custom HW that synchronizes CPUs when they read MMIO register N: MMIO
> read does not return until another CPU writes to MMIO register M. I modeled this behavior
> with a) on MMIO read of N, save CPU into a list of waiting CPUs and put it asleep with
> cpu_interrupt(current_cpu, CPU_INTERRUPT_HALT) and b) on MMIO write to M, wake all waiting
> CPUs with cpu->halted = 0; qemu_cpu_kick(cpu). It seems to work fine. However, this HW has
> a twist: MMIO read of N returns a value that was written by MMIO write to M. Can anyone
> please advise how this could be done?
You'll want to add something to allow each cpu to latch the value written.
Something like
CPU_FOREACH(cpu) {
if (cpu != write_cpu) {
*cpu->mmio_latch = value;
qemu_cpu_kick(cpu);
}
}
where cpu->sync_latch = &cpu->env.reg[N] for the register destination of the MMIO read.
This is easy if you can identify the hw sync mmio during translation. If this sync is
mapped somewhere arbitrary within the address space, you may have to work harder.
r~
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-08-17 21:53 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-16 16:31 How to synchronize CPUs on MMIO read? Igor Lesik
2023-08-16 18:16 ` Alex Bennée
2023-08-17 21:51 ` Richard Henderson
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).