Joel Fernandes
2025-Nov-11 23:02 UTC
[PATCH v2 07/12] nova-core: Implement the GSP sequencer
On 11/10/2025 8:43 AM, Alexandre Courbot wrote: [..]> >> + |cmd| { >> + self.current_offset += cmd.size_bytes(); >> + self.cmds_processed += 1; >> + Some(Ok(cmd)) >> + }, >> + ) >> + } >> +} >> + >> +impl<'a, 'b> IntoIterator for &'b GspSequencer<'a> { >> + type Item = Result<GspSeqCmd>; >> + type IntoIter = GspSeqIter<'b>; >> + >> + fn into_iter(self) -> Self::IntoIter { >> + let cmd_data = &self.seq_info.cmd_data[..]; >> + >> + GspSeqIter { >> + cmd_data, >> + current_offset: 0, >> + total_cmds: self.seq_info.info.cmdIndex, >> + cmds_processed: 0, >> + dev: self.dev, >> + } >> + } >> +} > > You can do without this implementation by just having an `iter` method > returning the iterator where appropriate (in the current version this > would be `GspSequencer`, but I suggest moving that to the > `GspSequencerInfo/GspSequence`). >If I do that, it becomes ugly on the caller side. Caller side becomes: for cmd_result in sequencer.seq_info.iter(&sequencer.dev) { .. } instead of the current: for cmd_result in sequencer { .. } Does it work for you if I remove IntoIterator and just have GspSequencer::iter() return the iterator? Then the caller becomes: for cmd_result in sequencer.iter() { .. } Although I think IntoIterator makes a lot of sense here too, and there are other usages of it in rust kernel code. But the sequencer.iter() would work for me. Thanks.
Alexandre Courbot
2025-Nov-12 00:42 UTC
[PATCH v2 07/12] nova-core: Implement the GSP sequencer
On Wed Nov 12, 2025 at 8:02 AM JST, Joel Fernandes wrote:> On 11/10/2025 8:43 AM, Alexandre Courbot wrote: > [..] >> >>> + |cmd| { >>> + self.current_offset += cmd.size_bytes(); >>> + self.cmds_processed += 1; >>> + Some(Ok(cmd)) >>> + }, >>> + ) >>> + } >>> +} >>> + >>> +impl<'a, 'b> IntoIterator for &'b GspSequencer<'a> { >>> + type Item = Result<GspSeqCmd>; >>> + type IntoIter = GspSeqIter<'b>; >>> + >>> + fn into_iter(self) -> Self::IntoIter { >>> + let cmd_data = &self.seq_info.cmd_data[..]; >>> + >>> + GspSeqIter { >>> + cmd_data, >>> + current_offset: 0, >>> + total_cmds: self.seq_info.info.cmdIndex, >>> + cmds_processed: 0, >>> + dev: self.dev, >>> + } >>> + } >>> +} >> >> You can do without this implementation by just having an `iter` method >> returning the iterator where appropriate (in the current version this >> would be `GspSequencer`, but I suggest moving that to the >> `GspSequencerInfo/GspSequence`). >> > > If I do that, it becomes ugly on the caller side. > > Caller side becomes: > for cmd_result in sequencer.seq_info.iter(&sequencer.dev) { > .. > } > > instead of the current: > for cmd_result in sequencer { > .. > }That's if you need `dev` for iteration. Since it is only used for logging error messages, I'd suggest doing without it and returning a distinct error code (or a dedicated error type that implements Display or Debug and converts to the kernel's Error) that the caller can then print, removing the need to pass `dev`.> > Does it work for you if I remove IntoIterator and just have GspSequencer::iter() > return the iterator? > > Then the caller becomes: > > for cmd_result in sequencer.iter() { > .. > } > > Although I think IntoIterator makes a lot of sense here too, and there are other > usages of it in rust kernel code. But the sequencer.iter() would work for me.I guess it's a matter of personal taste, but I tend to prefer `iter` methods because they are more visible than an implementation on a reference type, and also because they allow us to have different kinds of iterators for the same type (not that this is useful here :)).