Re: [PATCH v4 4/6] rust: irq: add support for threaded IRQs and handlers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Danilo,

> On 9 Jun 2025, at 13:24, Daniel Almeida <daniel.almeida@xxxxxxxxxxxxx> wrote:
> 
> Hi Danilo,
> 
>> On 9 Jun 2025, at 09:27, Danilo Krummrich <dakr@xxxxxxxxxx> wrote:
>> 
>> On Sun, Jun 08, 2025 at 07:51:09PM -0300, Daniel Almeida wrote:
>>> +/// Callbacks for a threaded IRQ handler.
>>> +pub trait ThreadedHandler: Sync {
>>> +    /// The actual handler function. As usual, sleeps are not allowed in IRQ
>>> +    /// context.
>>> +    fn handle_irq(&self) -> ThreadedIrqReturn;
>>> +
>>> +    /// The threaded handler function. This function is called from the irq
>>> +    /// handler thread, which is automatically created by the system.
>>> +    fn thread_fn(&self) -> IrqReturn;
>>> +}
>>> +
>>> +impl<T: ?Sized + ThreadedHandler + Send> ThreadedHandler for Arc<T> {
>>> +    fn handle_irq(&self) -> ThreadedIrqReturn {
>>> +        T::handle_irq(self)
>>> +    }
>>> +
>>> +    fn thread_fn(&self) -> IrqReturn {
>>> +        T::thread_fn(self)
>>> +    }
>>> +}
>> 
>> In case you intend to be consistent with the function pointer names in
>> request_threaded_irq(), it'd need to be handler() and thread_fn(). But I don't
>> think there's a need for that, both aren't really nice for names of trait
>> methods.
>> 
>> What about irq::Handler::handle() and irq::Handler::handle_threaded() for
>> instance?
>> 
>> Alternatively, why not just
>> 
>> trait Handler {
>>  fn handle(&self);
>> }
>> 
>> trait ThreadedHandler {
>>  fn handle(&self);
>> }
>> 
>> and then we ask for `T: Handler + ThreadedHandler`.
> 
> Sure, I am totally OK with renaming things, but IIRC I've tried  Handler +
> ThreadedHandler in the past and found it to be problematic. I don't recall why,
> though, so maybe it's worth another attempt.

Handler::handle() returns IrqReturn and ThreadedHandler::handle() returns
ThreadedIrqReturn, which includes WakeThread, so these had to be separate
traits.

I'd say lets keep it this way. This really looks like the discussion on
de-duplicating code, and as I said (IMHO) it just complicates the
implementation for no gain.

— Daniel




[Index of Archives]     [DMA Engine]     [Linux Coverity]     [Linux USB]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Greybus]

  Powered by Linux