Jan Kiszka wrote:
> ...
> PS: Another point for the long-term to-do list :-> : The nested locking
> and the global scope of certain locks. It's safe, it's harmless for
> current primary target platforms (UP), but it's not really beautiful
> when considering SMP setups. A bit tricky, for sure.

I put Sebastian in the CC. Maybe he sees issues I may ignore in the

Here is some first idea on a new locking scheme. It reduces the number
of locks by one and turns them either into per-device or per-socket in
the end:

 - concurrent read access to socket FIFO
 - /maybe/ also timeouts (but I think the user should better take care
   to not set a timeout and make use of it at the same time - not that
   hard to achieve in practice...)

This means that we need lock-less FIFOs wrt/ reader/writer
synchronisation. Some pattern like RTnet's rtskb_fifo e.g.

 - hardware access of related CAN port
 - device reception list

So we only take a single lock in the IRQ handler (+eventually the nklock
when waking someone up). But it requires that a socket, or more
precisely its FIFO is exclusively assigned to a single device.

And this raises the question how to deal with ifindex=0, i.e. attaching
a socket to all devices. Given that in this case the socket may run into
troubles anyway due to the fixed FIFO size, I would say that we better
create multiple FIFOs here (or additional rtcan_socket structures), one
per device of interest. The wakeup would then need some indirection in
order to use a common rtdm_event for all FIFOs of a socket.

Ok, this may complicate things, so we could do this in several steps:

1. Decouple FIFO reader from writer protection. A *global* device lock
   protects the writers + the reception lists, a socket recv_lock the
   read access. Make FIFOs lock-less wrt/ reader/writer concurrency.
2. Make the ifindex=0 support optional, fall back to global locking if
   it's on. If it's off (should be default), use per-device locking
   (again) as we then have exclusive assignments of sockets to a single
3. Create multiple FIFOs if ifindex is 0, always use per-device locks.
   As we already have the all-devices-support configurable at that time,
   we could let the user decide if the additional code for this mode
   should get compiled in or not.

Once this is implemented, the whole pattern could nicely be reused for
RTnet. I have in mind to shorten the reception path in the future and
make it more SMP friendly. So I'm with you here to gain experience! :)


Attachment: signature.asc
Description: OpenPGP digital signature

Xenomai-core mailing list

Reply via email to