zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
10.59k stars 6.48k forks source link

modules: hal: 3rd parties HALs and many different wheel shapes #77531

Open avolkov-1221 opened 1 month ago

avolkov-1221 commented 1 month ago

Problem description

Hello,

I would like to escalate and discuss a problem that arose during the recent ill-fated discussion of the new HAL from Renesas. Specifically, the lack of any requirements for HALs provided by hardware vendors in the form of modules.

Despite the declared goal of avoiding, among other things, the reinvention of the wheel when introducing the modules, we now have a whole set of wheels in different incompatible shapes from various vendors. Or, to put it more seriously, there are some issues that could impact both the current system's stability and performance, and significantly complicate future tree-wide or subsystem-wide changes:

...

As a consequence of the above, it is often easier to create a local fork of some parts of the original HAL and bring them into some compatible form with Zephyr (and with Twister) than to reuse it as is. This, in turn, increases the number of new wheel shapes ad infinitum. So we got a situation that is directly opposite to the declared target.

Proposed change

To normalize the current situation to at least a minimally acceptable level, I would like to define some basic requirements for modules supplied by vendors, based on this discussion. We could start with the following:

henrikbrixandersen commented 1 month ago

I understand where you're coming from with this, but the ideas put forward above contradicts the whole idea of a vendor using a HAL with Zephyr; Vendors use HALs with Zephyr in order to facilitate code reuse between Zephyr and other supported ecosystems (baremetal, other RTOS) which reduces both development and testing time.

Forcing HALs to use Zephyr primitives would cause a dependency loop and void the idea of vendor code reuse between Zephyr and other ecosystems.

avolkov-1221 commented 1 month ago

Forcing HALs to use Zephyr primitives would cause a dependency loop and void the idea of vendor code reuse between Zephyr and other ecosystems.

I don't really agree with this: most vendors already have some compatibility layers in one form or another (in fact, Renesas has too), but in the case of Zephyr, not all of them are actually trying to use these layers. Certainly, hardware-specific things are outside the scope of this RFC. However, irq_lock()/irq_unlock() for ARM-based SOCs, on the contrary, are directly relevant.

bjarki-andreasen commented 1 month ago

Vendor HALs are often by design OS agnostic as mentioned by @henrikbrixandersen, Vendors have a lot to gain in the lanes of better performance, code size optimization, code reuse, simpler maintenance, CI infrastructure etc. when seen from the perspective of zephyr by mutating their HALs to better match zephyr.

I don't think we should attempt to enforce changes in vendors' downstream HALs to better match zephyr, vendors who wish to support zephyr better will typically opt to adapt their HALs and uses of them to better match zephyr for reasons of the gains mentioned above. No enforcement needed :)