|
|
Subscribe / Log in / New account

HALs considered harmful

It is a nice thing when hardware vendors provide Linux drivers for their products. Since these drivers are written by the vendor, there is usually no trouble getting information on how the hardware is controlled. With luck, that hardware will "just work" for Linux users, and all will be as it should be. In the real world, however, things are not always that simple. Hardware companies often take interesting approaches to coding drivers, and the people involved are not always well tied into the Linux kernel development community. The result can be conflicts between the vendors, who simply want to get things done, and the kernel developers, who are increasingly unwilling to accept code which does not meet their standards.

For a current example, consider the proposed new Neterion/S2io 10GbE network driver. This driver has been rewritten from the beginning; it supports many of the hardware's advanced features and provides high performance. It looks like just the thing for high-end Linux-based networking uses.

The problem is that the driver does not deal directly with the Linux kernel API. It is, instead, based on a "hardware abstraction layer" (HAL) which glues the driver to the kernel. So, for example, the driver builds lists with a structure like:

    typedef struct xge_list_t {
	struct xge_list_t* prev;
	struct xge_list_t* next;
    } xge_list_t;

Such lists are accessed with functions like xge_list_insert() and even xge_list_for_each(). Similarly, the driver uses xge_os_spin_lock() to acquire a lock, xge_os_malloc() to allocate memory, and xge_os_pio_mem_read8() to read a byte from I/O memory. This approach helps Neterion support a variety of systems with the same core driver code, but it does not sit well with the kernel hackers. Networking maintainer David Miller responded this way:

I totally reject this driver, HAL is unacceptable for in-tree drivers. We've been over this a thousand times.

One problem with the HAL approach is that there can be a performance cost. A 10G network adaptor can handle thousands of packets per second; at that sort of load, even the minimal overhead of a simple wrapper function can make a significant difference. The extra memory taken by the glue code, parallel linked list implementation, etc. also hurts. A developer community which is dedicated to obtaining the best possible performance from the hardware will be unwilling to swallow even a small cost in the name of portability.

The bigger issue, however, is in the maintainability of the driver. A driver written for a HAL layer has its own idioms and conventions; it works with a completely different API. It simply does not look like a Linux driver; Linux developers will have a harder time understanding and modifying it. One might think that this is not a big issue, since Neterion has said that it plans to maintain the driver, but there are a couple of problems that come up:

  • When a kernel developer changes an internal function, he or she will usually go through and fix all of the in-tree users of that function. So developers who are not employed by the hardware vendor will almost certainly have to work with the driver code at some point.

  • Hardware vendors have a short attention span. Product cycles tend to be short, and the vendor will, before too long, move on to new products requiring new and different drivers. Once a given driver no longer applies to the products which are currently in the vendor's catalog, the vendor will, most likely, see little reason to continue maintaining that driver. The Linux community, however, will have an interest in keeping that driver working for several more years.

Additionally, the vendor may resist patches which affect the HAL layer itself, making it harder for the community to work on the driver. Overall, the Linux kernel developers plan to maintain the kernel for many years into the future; they tend to be concerned about taking on code which will make that maintenance task harder in the future.

So the kernel hackers have some solid reasons for resisting HAL-based drivers. The vendors also have good reasons for wanting to write such drivers. To them, the resistance to HAL looks like a "Linux is the only important system" attitude, and it forces them in incur extra costs when writing their code. In this case, Neterion has reluctantly said that it will produce a non-HAL driver if that is the only way to get into the tree; other vendors may not bother.

Index entries for this article
KernelDevice drivers
KernelHardware abstraction layers


to post comments

HALs considered harmful

Posted Mar 17, 2005 5:34 UTC (Thu) by iabervon (subscriber, #722) [Link] (3 responses)

If nothing else, the driver could be used as notes for writing a Linux-style driver. I know I've found existing code to be good reference for how something needs to be done, even if I've ultimately written my own.

HALs considered harmful

Posted Mar 17, 2005 10:27 UTC (Thu) by simlo (guest, #10866) [Link] (2 responses)

I think the policy should be to include the driver as it is. Look at is this way:
The vendor supplies the code under GPL. He probably releases the driver in binary form for other OS'es. He shouldn't be bothered about maintaining several version. This way Linux gets the updates as fast as other OSs as well.
When the vendor stops supporting the driver, some user of the device must take over maintaining it. As no more patches comes from the vendor it might be a good idea to remove the HAL at that point. But not before.

I must say I disagree with the policy of not using an HAL - which should be called an OSAL in this context. It minimizes the coupling between the Linux kernel and the driver. Seperating stuff this way is always a good idea. It might hurt performance but the vendor in this case have a clear interrest in fixing that.

HALs considered harmful

Posted Mar 18, 2005 0:25 UTC (Fri) by bk (guest, #25617) [Link] (1 responses)

The problem is that it's not just one HAL. Potentially dozens of completely different and idiosyncratic HALs could be merged into the tree if it became Linux policy to accept them. This would cause utter chaos a few years down the line when most of them become "end of lifed" and therefore unmaintained and some big destabilizing change in the kernel comes along requiring them all to be retooled in some way.

It's basically impossible (and unfair) to ask a handful of kernel hackers to figure out 20 different HALs and how to modify and/or fix them. The only people that win are the hardware vendors; Linux and all of the community lose in the long run.

HALs considered harmful

Posted Mar 24, 2005 10:02 UTC (Thu) by steven97 (guest, #2702) [Link]

You could put all HAL drivers in a separate drivers directory and call those drivers "unsupported" (and taint the kernel like what happens with binary-only drivers, etc.). And since the driver is GPL'ed, someone motivated can always hack up a non-HAL driver based on the vendor driver. Then, let darwinism do its thing.

IMHO, outright rejecting HAL drivers is just silly, another example of zealotry that does not help Linux in the long run.

HALs considered harmful

Posted Mar 17, 2005 11:26 UTC (Thu) by ctg (guest, #3459) [Link] (1 responses)

An additional point is that once a driver has been accepted into the tree, then the maintenance costs of the driver could well go down for the hardware vendor - from the vendors point of view, the parts of the driver which interact with the kernel should be maintained "for free". All they have to worry about is, assuming it works, changes caused by changes in the hardware.

A standardised driver will also benefit from much of the same code as other drivers.

HALs considered harmful

Posted Mar 17, 2005 12:05 UTC (Thu) by NAR (subscriber, #1313) [Link]

nce a driver has been accepted into the tree, then the maintenance costs of the driver could well go down for the hardware vendor - from the vendors point of view, the parts of the driver which interact with the kernel should be maintained "for free".

It looks to me this is not only the question of interacting with the kernel - it's a question of actively using the infrastructure provided by the kernel. Linked lists might be used somewhere far from the kernel-interface and if the vendor uses Linux-kernel linked lists, the core of the driver would become Linux-specific even though the vendor would like to use the same code with an other (non-Linux) kernel.

Bye,NAR

HALs considered harmful

Posted Mar 17, 2005 11:50 UTC (Thu) by grouch (guest, #27289) [Link] (1 responses)

"In this case, Neterion has reluctantly said that it will produce a non-HAL driver if that is the only way to get into the tree; other vendors may not bother."

Let those other vendors not bother, then. I will not bother to purchase from them. The Linux kernel hackers have done a lot for me without requiring a thing in return, beyond adherence to generous license terms. (There's no way I could pay them what their work has been worth to me). If a vendor wants my cash, that vendor must make the kernel hackers happy as well as me.

HALs considered harmful

Posted Mar 26, 2005 0:20 UTC (Sat) by alext (guest, #7589) [Link]

I totally agree, let them not bother. Letting one or two get away with it will just encourage other vendors to expect the same. The ultimate result is that Linux take longer to get the full and proper support.

Linux is still growing and they will eventually do it properly first time as it becomes more worth their while.

HALs considered harmful

Posted Mar 17, 2005 12:40 UTC (Thu) by sdalley (subscriber, #18550) [Link] (2 responses)

Although it might have been gone over "a thousand times before" I am totally at a loss to understand this reasoning.

It is *sometimes* necessary to program as close to the metal as possible for reasons of speed. However, for reasons of maintainability, it always makes sense to do what is called "information hiding", i.e. to hide the specifics of the OS-specific interfaces in one place under more generic wrappers, and call those wrappers from the device-specific stuff. This does not just make things easier for the vendor to target multiple OSes, it also localises the linux-kernel interface calls in a small area, typically one file. The kernel maintainers then have only one file to worry about when the inevitable function call interface changes occur.

Done right, it should make the kernel maintainer's job easier as well as the vendor's job. What am I missing here ? (scratches head).

HALs considered harmful

Posted Mar 17, 2005 13:30 UTC (Thu) by vonbrand (subscriber, #4458) [Link]

You are certainly right about "information hiding". But if each driver does the hiding in its own particular way, you get nowhere fast. Yes, Linux has information hiding in place (like the list handling macros, much of the driver interface, ...). Use that. You could even write a glue layer from Linux conventions to other systems ;-)

HALs considered harmful

Posted Mar 17, 2005 21:38 UTC (Thu) by farnz (subscriber, #17727) [Link]

The kernel API provides its own HAL; what these drivers do is provide a "HAL to HAL" translation layer from their own internal HAL to the kernel HAL, often adding variants on existing kernel infrastructure (your own spinlock implementation, for example), because the existing infrastructure has different semantics to your internal version, and you don't want to translate between them.

HALs considered harmful

Posted Mar 17, 2005 15:29 UTC (Thu) by brianomahoney (guest, #6206) [Link]

1. Hal is not the same as re-inventing the wheel:

so there is _no_ excuse for alterative bi-linked lists or spin lock implementations.

2. This is C not Java, so we have 'cpp' and macros

3. This is almost always laziness, caused by programmers for whoom copy in is easier than the work to do it in a good style

4. All that said, hardware vendors must be encouraged to do it right, and without a yah-boo attitude; It might be appropriate for OSDL-Tovolds-Morton-Toscatti et al to put up a web page and a support route to help interested vendors.

Semi-legitimate HAL

Posted Mar 17, 2005 20:30 UTC (Thu) by thyrsus (guest, #21004) [Link]

My experience with HALs is as an end user: I ended up with an atheros based wireless card, which, according to legend, is capable of FCC designated evil so terrible that it is illegal to publish the actual capabilities of the hardware, however, there is a binary only HAL to prevent electromagnetic mayhem. So whenever I update my kernel, I have to figure out how to compile in the driver, which makes calls to the HAL binary library. I do not have the extensive leisure and skillz to reverse engineer the binary HAL. Sigh.

HALs considered harmful

Posted Mar 20, 2005 23:02 UTC (Sun) by salkin (guest, #1569) [Link] (1 responses)

If the purpose of all the HALs is for driver writers to be able to abstract away the differences between Linux, Windows, Solaris, et al, then perhaps the "Right Answer(tm)" is for someone to step up and write just one, single, good HAL. Having one HAL that was actively maintained through many product release cycles, used by many hardware vendors, etc. would remove the "orphaned code" problem and still let hardware vendors save some design and maintenance money . In fact it would make it a lot easier for them to decide to do a linux-native driver in the first place. And just one HAL in the kernel (as opposed to at least one per vendor) shouldn't be too big a headache. (Plus it could be tuned - the payoff would be there if many drivers used it.)

Obviously there are downsides, not least of which is that no such effort exists, and qualified and motivated developers would need to be found and organized. But the vendors have a strong motivation here, and money to save. Perhaps there is some traction there - to organize this development effort so that each vendor doesn't have to maintain their own HAL and can save on driver development costs.

HALs considered harmful

Posted Mar 24, 2005 21:25 UTC (Thu) by eli (guest, #11265) [Link]

The purpose of a HAL is, as you say, "to abstract away the differences between Linux, Windows, Solaris, et al." (Add VxWorks, and other RTOS's to that list.)
The interesting thing here is that "just one, single, good HAL" means writing an API for drivers to code against, and writing an implementation of that API for every supported OS; one for Windows XP, one for Windows 2003, ..., one for Linux 2.6, one for Linux 2.6.10+, one for Linux 2.4.n+, one for Solaris x.y, one for VxWorks a.b+, etc.

But once you do that, you've started a separate project. You might be able to get your HAL.Linux.2.6.current driver accepted into the mainline kernel (maybe), but that's only one part; you need to get the hardware vendors on board too. That might be feasible... write their driver to your HAL API once, and they can run on 17 different OS flavors. The license would be an interesting bit of legal work... GPL compatible for the Linux layers, (BSD if you could argue it wasn't a derived work), probably BSD or the like for the rest.

It'd be an interesting possibility--but it would be its own project separate from the Linux kernel development.


Copyright © 2005, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds