qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Zhao Liu <zhao1.liu@intel.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: "Michael S . Tsirkin" <mst@redhat.com>,
	"Manos Pitsidianakis" <manos.pitsidianakis@linaro.org>,
	"Junjie Mao" <junjie.mao@hotmail.com>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	qemu-devel@nongnu.org, qemu-rust@nongnu.org
Subject: Re: [RFC 00/13] rust: Reinvent the wheel for HPET timer in Rust
Date: Mon, 9 Dec 2024 15:57:32 +0800	[thread overview]
Message-ID: <Z1ai7PbmpDff8zxp@intel.com> (raw)
In-Reply-To: <2f42c553-5673-4826-bc2f-14ec1306e8c0@redhat.com>

On Thu, Dec 05, 2024 at 05:28:45PM +0100, Paolo Bonzini wrote:
> Date: Thu, 5 Dec 2024 17:28:45 +0100
> From: Paolo Bonzini <pbonzini@redhat.com>
> Subject: Re: [RFC 00/13] rust: Reinvent the wheel for HPET timer in Rust
> 
> On 12/5/24 07:07, Zhao Liu wrote:
> > * Proper bindings for MemoryRegionOps, which needs to wrap the ram
> >    read/write callbacks.
> >    - I think it shouldn't be complicated because qom/qdev already
> >      provides good examples.
> 
> Sounds good, I have some initial work on PL011.

Great! Sorry for the slow response, I just saw this comment. I'm looking
forward to your work on this!

> > Based on this, I am also considering how the opaque parameter in certain
> > callbacks should interact with BQL cells. In the timer binding (patch
> > 7), I think the opaque parameter accepted by the timer callback should
> > be placed in a BQL cell. However, considering generality, I did not make
> > further changes and only passed BqlRefCell<HPETTimer> as the opaque
> > parameter in the HPET code.
> 
> That sounds good.
> 
> I'll review your timer bindings and post the infrastructure that I have for
> callbacks.

Thank you!

> > Furthermore, is it possible in the future to wrap the entire state
> > within a BQL cell? This could save the effort of wrapping many state
> > members individually when state becomes very huge and complex.
> 
> I think it's better if we keep a split between the mutable and immutable
> parts.  For example properties are immutable.

I like this idea. Clear splitting helps to standardize the usage of
BqlCell, preventing both underuse and overuse.

> > QDEV Property
> > -------------
> > 
> > To support bit type property, I added another macro variant (in patch 8)
> > to allow bitnr parameter. However, I think this lacks scalability.
> > 
> > In qdev-properties.h, it is clear that the PropertyInfo of a property is
> > bound to its type. Previously, Junjie and I attempted to do the same in
> > Rust by binding PropertyInfo to the type, thereby avoiding the need to
> > specify too many parameters in the macro definitions:
> > 
> > https://lore.kernel.org/qemu-devel/20241017143245.1248589-1-zhao1.liu@intel.com/
> 
> Oops, sorry.  I have applied patch 1, but patch 2 is a bit problematic
> because I think it's not const-friendly.  Maybe it was applied to older
> code?

Yes, it was based on old code base...and it seems outdated.

> I haven't looked closely at whether it's possible to use trait { ... const
> TYPE: &Property = ... }, maybe only in newer Rust?  But as you point out
> there is an issue with multiple PropertyInfos that can apply to the same
> type, therefore I think the way to go here is to use a procedural macro and
> a #[property] attribute.  That also makes bit properties easy:
> 
>     #[property(bit=0, name="foo")
>     #[property(bit=1, name="bar")
>     features: u32,

Thank you, it looks better and overcomes the drawback of the original
proposal.

> > MEMTXATTRS_UNSPECIFIED
> > ----------------------
> > 
> > MEMTXATTRS_UNSPECIFIED is another global variable. Since it is
> > immutable, BQL cell is not needed.
> > 
> > But MemTxAttrs is a structure with bitfields, and the bindings generated
> > by bindgen can only be modified through methods. Therefore, it is
> > necessary to introduce lazy to initialize MEMTXATTRS_UNSPECIFIED in a
> > const context (patch 6).
> 
> Ugh, that's a pity.  Maybe instead of introducing a new dependency we can
> use an always-inlined function?

Based your and Richard's suggestion, modifying memattrs avoids
introducing additional library. :-)

> In an ideal world, bindgen would produce const functions.  A hackish but
> easy possibility is to modify the generated bindgen code (with sed? :)) to
> apply const to the bitfield functions.

I think it could work, and this time it won't be needed, based on your
newer suggestion. :-)

> > Then, I chose NonNull to address this issue, as recommended by the
> > author of NonNull and the standard collections [3].
> 
> NonNull is okay for now.  Later on we will handle it with pinned_init.
> 
> However, do not get a &mut HPETState, everything should go through
> &HPETState and cells.

Sure. I see.

> > Therefore, I believe that in Rust devices, QOM members should also be
> > kept private or at most `pub(crate)`. This is also why I tried to avoid
> > using direct `pub` in HPET.
> 
> Yes, I agree.  I should look at unnecessarily pub things in pl011.

Thank you!

Regards,
Zhao



      reply	other threads:[~2024-12-09  7:40 UTC|newest]

Thread overview: 72+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-05  6:07 [RFC 00/13] rust: Reinvent the wheel for HPET timer in Rust Zhao Liu
2024-12-05  6:07 ` [RFC 01/13] bql: check that the BQL is not dropped within marked sections Zhao Liu
2024-12-05  6:07 ` [RFC 02/13] rust: cell: add BQL-enforcing RefCell variant Zhao Liu
2024-12-05  6:07 ` [RFC 03/13] rust/cell: add get_mut() method for BqlCell Zhao Liu
2024-12-05 15:55   ` Paolo Bonzini
2024-12-07 15:56     ` Zhao Liu
2024-12-07 19:49       ` Paolo Bonzini
2024-12-05  6:07 ` [RFC 04/13] rust: add bindings for gpio_{in|out} initialization Zhao Liu
2024-12-05 18:53   ` Paolo Bonzini
2024-12-08 16:27     ` Zhao Liu
2024-12-09 11:08       ` Paolo Bonzini
2025-01-16  3:04         ` Zhao Liu
2025-01-17  9:40           ` Paolo Bonzini
2025-01-17 11:14             ` Zhao Liu
2025-01-17 12:47               ` Paolo Bonzini
2024-12-05  6:07 ` [RFC 05/13] rust: add a bit operation binding for deposit64 Zhao Liu
2024-12-05 16:09   ` Paolo Bonzini
2024-12-07 16:01     ` Zhao Liu
2024-12-07 19:44       ` Paolo Bonzini
2024-12-05  6:07 ` [RFC 06/13] rust: add bindings for memattrs Zhao Liu
2024-12-05 18:15   ` Richard Henderson
2024-12-05 18:30     ` Paolo Bonzini
2024-12-05 23:51       ` Richard Henderson
2024-12-06  8:41         ` Zhao Liu
2024-12-06 14:07           ` Richard Henderson
2024-12-06 10:59       ` Peter Maydell
2024-12-06 14:28         ` Paolo Bonzini
2024-12-06 14:42           ` Peter Maydell
2024-12-06 19:13             ` Paolo Bonzini
2025-01-20 16:52               ` Zhao Liu
2025-01-20 17:19                 ` Paolo Bonzini
2025-01-23 15:10                   ` Zhao Liu
2025-01-23 15:33                     ` Paolo Bonzini
2024-12-07  9:21         ` Philippe Mathieu-Daudé
2024-12-08  9:30           ` Paolo Bonzini
2024-12-08 15:51             ` Zhao Liu
2024-12-05  6:07 ` [RFC 07/13] rust: add bindings for timer Zhao Liu
2024-12-05 18:18   ` Richard Henderson
2024-12-07 17:18     ` Zhao Liu
2024-12-05 18:46   ` Paolo Bonzini
2024-12-07 16:54     ` Zhao Liu
2025-01-14 15:36     ` Zhao Liu
2025-01-14 15:42       ` Zhao Liu
2025-01-14 16:14       ` Paolo Bonzini
2025-01-15  7:09         ` Zhao Liu
2024-12-05  6:07 ` [RFC 08/13] rust/qdev: add the macro to define bit property Zhao Liu
2024-12-05  6:07 ` [RFC 09/13] i386/fw_cfg: move hpet_cfg definition to hpet.c Zhao Liu
2024-12-05 12:04   ` Philippe Mathieu-Daudé
2024-12-05 12:46     ` Zhao Liu
2024-12-05 21:17       ` Philippe Mathieu-Daudé
2024-12-05 21:19         ` Paolo Bonzini
2024-12-07  9:16           ` Philippe Mathieu-Daudé
2024-12-07 15:36             ` Zhao Liu
2024-12-05 15:30   ` Paolo Bonzini
2024-12-07 15:28     ` Zhao Liu
2025-01-17 10:31     ` Zhao Liu
2025-01-17 10:15       ` Paolo Bonzini
2024-12-05  6:07 ` [RFC 10/13] rust/timer/hpet: define hpet_fw_cfg Zhao Liu
2024-12-05  6:07 ` [RFC 11/13] rust/timer/hpet: add basic HPET timer & state Zhao Liu
2024-12-05 20:22   ` Paolo Bonzini
2024-12-05 21:20     ` Paolo Bonzini
2024-12-09  7:46       ` Zhao Liu
2024-12-09  7:26     ` Zhao Liu
2024-12-05  6:07 ` [RFC 12/13] rust/timer/hpet: add qdev APIs support Zhao Liu
2024-12-05 18:58   ` Paolo Bonzini
2024-12-07 16:05     ` Zhao Liu
2024-12-05  6:07 ` [RFC 13/13] i386: enable rust hpet for pc when rust is enabled Zhao Liu
2024-12-05 15:20   ` Paolo Bonzini
2024-12-06  9:06     ` Zhao Liu
2024-12-05  6:22 ` [RFC 00/13] rust: Reinvent the wheel for HPET timer in Rust Zhao Liu
2024-12-05 16:28 ` Paolo Bonzini
2024-12-09  7:57   ` Zhao Liu [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=Z1ai7PbmpDff8zxp@intel.com \
    --to=zhao1.liu@intel.com \
    --cc=alex.bennee@linaro.org \
    --cc=junjie.mao@hotmail.com \
    --cc=manos.pitsidianakis@linaro.org \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-rust@nongnu.org \
    /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).