Slashdot Mirror


NetBSD To Support Kernel Development In Lua Scripting

An anonymous reader writes "NetBSD 7.0 will support the Lua scripting language within its kernel for developing drivers and new sub-systems. A Lua scripting interpreter is being added to the NetBSD kernel along with a kernel API so developers can use this scripting language rather than C for developing new BSD kernel components. Expressed reasons for supporting a scripting language in a kernel were rapid application development, better configuration, and "modifying software written in C is hard for users." In a presentation it was said that Lua in the kernel will let users explore their system in an easy way."

31 of 311 comments (clear)

  1. users? by gTsiros · · Score: 5, Insightful

    "modifying software written in C is hard for users."

    i thought *users* had no business writing device drivers?

    of course if they had said "modifying software written in C is hard for programmers." it would gather a fierce shitstorm.

    --
    Looking for people to chat about multicopters, coding, music. skype: gtsiros
    1. Re:users? by TheRealMindChild · · Score: 4, Interesting

      It seems crazy, but this may not be as braindead as it seems. For instance, a keyboard driver. You just need a read key state->have a look up table to the keycodes function, then pass it on. This is redundant, few lines of code with very little difference between most other drivers. You may not want to write your graphic drivers in it, but not every driver needs bare metal functionality

      --

      "When life gives you lemons, don't make lemonade. Make life take the lemons back!" -- Cave Johnson
    2. Re:users? by KiloByte · · Score: 4, Funny

      So let's invent a sandboxed layer that can interface with the kernel, but can't do damage to it? Also, make the API stable, unlike innards of the kernel. Let's call this novel idea "userspace" or such.

      --
      The creatures outside looked from Alt-Right to Antifa; but already it was impossible to say which was which.
    3. Re:users? by Mindcontrolled · · Score: 4, Insightful

      The moment you even expect that users should, could, would or even remotely in their most maddened fever dreams WOULD WANT to modify the kernel, you lost it.

      --
      Ubi solitudinem faciunt, pacem appellant.
    4. Re:users? by Jane+Q.+Public · · Score: 3, Interesting

      "It seems crazy, but this may not be as braindead as it seems."

      I think that is very much a matter of opinion. And my opinion is: it *IS* just exactly as braindead as it seems.

      Just what we need: "modern" software bloat in the kernel. [sarcasm] Thanks, but no thanks.

      I have right here a program that is more than 45 times the size of the entire hard drive from one of our office computers back in 1994... and that hard drive had a full install of that year's Microsoft Office, plus WordPerfect and Lotus 1-2-3, with lots of room to spare for files.

      Sure... that was '94. But is there REALLY call for programs that large, and by the way slow? And that is by no means the largest application I have on my machine right now. It's on the larger side but I have some many times as big.

    5. Re:users? by MacTO · · Score: 5, Insightful

      Keep in mind that NetBSD users are quite different from Windows/Macintosh/Linux users (at least on average).

      "Hard" may also be a reference to the implementation, rather than the language. Interpreted languages tend to bypass the compile and link part of the development process. This means that interpreted languages are easier to develop with and compiled languages are hard to develop with (at least in some respects). I'd also comment on the arcane nature of C, but I haven't used lua so I don't know if it is any better.

    6. Re:users? by Lodragandraoidh · · Score: 4, Interesting

      Interesting - failure of user space in this way is exactly why we have zero-days.

      I would like to see this happen - but several things make it improbable:

      1. Von Neuman architecture. As long as data and instructions exist in the same space - poorly written apps will allow abuse of it.

      2. Complexity of current software. The more complex the software, the more likely a bug will exist in it that allows #1. Given how programmers stitch together preexisting modules without understanding what is being done on the underlying system - I only expect that to continue expanding.

      It should be instructive that Java was supposed to be that sandboxed layer...and it has so many zero-days it looks like swiss cheese.

      Now - how would we avoid that and make an unhackable userspace?

      --

      Lodragan Draoidh
      The more you explain it, the more I don't understand it. - Mark Twain
    7. Re:users? by Anonymous Coward · · Score: 5, Funny

      I only have 640 KB you insensitive clod!

    8. Re:users? by jbolden · · Score: 4, Interesting

      i thought *users* had no business writing device drivers?

      My non programmer wife wrote a custom device driver in AppleScript, not even knowing what a device driver is. Those sorts of languages can be amazing empowering to end users, and yes there are reasons that end users might want a custom device driver if it is easy enough to accomplish. Though this makes more sense for OSX than NetBSD, I doubt there are many if any non programmers who use NetBSD.

      I had to write a custom device driver for Windows once to get something more like a Unix ethernet driver i.e. bypass some normally quite excellent parts of the Windows networking stack. I was doing software not hardware so I guess I'd consider myself an end user. And that was a pain in the ass.

    9. Re:users? by aliquis · · Score: 3, Funny

      The moment you even expect that users should, could, would or even remotely in their most maddened fever dreams WOULD WANT to modify the kernel, you lost it.

      Though it's NetBSD users. Not Apple iPad users.

    10. Re:users? by WindBourne · · Score: 3, Interesting

      Exactly. Think about all of the devices out there that are simple ones. I know that my in-laws have BP cuff with USB. I have thought about writting a driver for it, but it just seems like a lot of work for a minimal amount of info. Now, if there is something simple, then this could be useful. In addition, I have been thinking that batteries interface should be standardized. It does not matter wether it is a laptop battery, or a UPS. They accomplish the same thing and the same programs should control them. Simple as that.

      --
      I prefer the "u" in honour as it seems to be missing these days.
  2. Performance by Anonymous Coward · · Score: 5, Informative

    Won't that kill performance?

    I mean that's the reason we still write kernels in C. Every cycle counts..

    1. Re: Performance by Anonymous Coward · · Score: 5, Funny

      So we use it for performance. Ok I get it now.

    2. Re:Performance by DarwinSurvivor · · Score: 4, Informative

      Pfff, writing Linux kernels in Javascript is so last century. Nowadays we RUN kernels in Javascript!

    3. Re:Performance by Anonymous Coward · · Score: 3, Informative

      Lua is designed to be a embedded companion language to C. You still use C where it makes sense (i.e. pointer manipulation/performance). You use Lua for expressing higher level logic more easily. Lua is very fast. Writing the same higher level logic in raw C might not be any faster because you have to build up all the infrastructure that Lua has already provided and optimized like associative arrays.

    4. Re: Performance by larry+bagina · · Score: 3, Insightful

      I believe the word you're looking for is "performance".

      --
      Do you even lift?

      These aren't the 'roids you're looking for.

    5. Re:Performance by stenvar · · Score: 4, Informative

      Kernel code is like lots of other code: a lot of it is executed rarely and not performance critical. There's setup code, occasional permissions checking, etc.

      In addition, this is not to replace plain C modules (although it may be useful for prototyping), it's for complex and dynamic configurability.

      Right now, there are two ways of handling that. One is to invent complex configuration files and data structures, sometimes even little interpreters. The kernel is full of those. They are error prone, complicated, and require a lot of effort to maintain. The other is to put complex decision making into user-space, but that involves context switches and other overhead. It also means lots of special-purpose and redundant code, and lots of documentation and complexity. The kernel uses both of those strategies extensively, one reason why it's so big.

      Putting Lua+LuaJIT in the kernel is likely faster than either of those approaches, while at the same time also being easier to maintain and document.

    6. Re: Performance by Anonymous Coward · · Score: 3, Interesting

      True. Assembly can be faster than C. In the same way it can be more powerful than C.

      Bottom line is C provides a solution for the complexity of large scale development, without sacrificing the performance, while at the same times still let's the developer be in complete control of his code and data structures.

    7. Re: Performance by Anonymous Coward · · Score: 3, Insightful

      Multiple execution units, long pipelines and modern caching makes it hard for assembly to be faster than C. The human brain can not visualize the pipeline like a compiler can.

    8. Re:Performance by 10101001+10101001 · · Score: 4, Insightful

      Kernel code is like lots of other code: a lot of it is executed rarely and not performance critical. There's setup code, occasional permissions checking, etc.

      A lot of it is executed rarely because at least half the code is drivers and one usually doesn't have but one sound card, one (or two) network card, etc vs the hundreds of sound card drivers, hundreds of network card drivers, etc. Further, a major point of the kernel is that it, by design, isn't supposed to be executed a lot because most CPU time should be devoted to user space programs. So, to that end, you could say it's not "performance critical". But, that's more in line with the point that precisely because kernels are generally developed so well, they rarely have "performance critical" code. Once you start throwing scripting into it, I think that goes out the window.

      In addition, this is not to replace plain C modules (although it may be useful for prototyping), it's for complex and dynamic configurability.

      To this, I could see some benefit. But, honestly, I'd feel it safe and saner if it were a language that was reducible to a FSA. The point that "Dangerous code can be disabled at the byte-code level (prevention of endless loop DoS etc)" in the slide really only works in that context, anyways. In any case, Lua is nothing of the sort.

      Right now, there are two ways of handling that. One is to invent complex configuration files and data structures, sometimes even little interpreters. The kernel is full of those. They are error prone, complicated, and require a lot of effort to maintain.

      Which is an argument for making a good, universal FSA language. It won't remove the being error prone or complicated because that's the nature of the beast and papering over it with a Turing complete language is no sort of answer. But having them all share the same language makes sense from a maintenance standpoint. For example, the BPF was repurposed for syscall filtering--a little admission that I'm not sure entirely where BPF stands language wise although I don't think it's turing complete--which could probably be refactored into a more general filtering language which could be refactored into an even more generic FSA language which could likely be used to refactor a lot of other code.

      The other is to put complex decision making into user-space, but that involves context switches and other overhead. It also means lots of special-purpose and redundant code, and lots of documentation and complexity. The kernel uses both of those strategies extensively, one reason why it's so big.

      Generally speaking, context switches aren't a big deal in most OSs/kernels today. Yes, certainly having context switches means an extra overhead and stuffing some code or even all code in the kernel would certainly speed it up. And certainly if a lot more code moved into user space would be measurably slower. But kernel design today seems to try to have a balance between the two, especially with considerations of stability and security. The fact is, lots of code is special-purpose because it's for specific hardware. And code being redundant is more a function of maintaining multiple trees--which admittedly having a single kernel allows a lot of unity--but there's no reason that out-of-kernel-space means out-of-the-kernel-source if the code is still rather kernel specific.

      After all, the whole point is precisely that a lot of potential kernel code is "executed rarely and not performance critical" yet remaining outside kernel memory gives the system greater protection and hence speeds up development and generally makes the code easier to maintain. Documentation is a wholly separate beast, in any case, and that's more a point of maintainers or distributors demanding good documentation before code is accepted.

      Putting Lua+LuaJIT in the kernel is likely faster than either of th

      --
      Eurohacker European paranoia, gun rights, and h
  3. long overdue by stenvar · · Score: 4, Interesting

    This is a good thing, and it's long overdue. Linux should do the same.

    It's actually pretty easy to get Lua running in the kernel and call kernel APIs; but to make it really useful, it needs additional kernel hooks and callbacks, and that requires cooperation from the core kernel developers.

    1. Re:long overdue by Anonymous Coward · · Score: 3, Interesting

      Exactly.

      With certain algorithms I have LuaJIT code that runs faster than the best C code I can create (I'm speaking with 25+ years of C experience here).

    2. Re:long overdue by Anonymous Coward · · Score: 3, Interesting

      LuaJIT can be seriously fast. But usually when C is slow, it's some compiler flag, or perhaps a bunch of unpredictable branches or random access pattern in the inner loop.

      Pretty often the LuaJIT trace machine code generated is similar to what you'd get from gcc. That's how good it is.

    3. Re:long overdue by stenvar · · Score: 3, Insightful

      It's not mainly for messing with device drivers (although it may be useful for that too).

      It's mainly useful for all the stuff that people right now create /proc devices, ioctls, and user-level kernel-related daemons for. Those mechanisms are both slow and complicated. With Lua in the kernel, a lot of that stuff can be handled much more easily, without the overhead of context switches and with much less code.

      It probably won't replace all the bloated configuration stuff that already exists, but at least when writing new device drivers and new functionality, developers could save a lot of time and effort.

    4. Re:long overdue by AuMatar · · Score: 3, Insightful

      They use Lua for the non-performance effecting parts of games. They'd never consider using it in the graphics code, which is the bottleneck.

      --
      I still have more fans than freaks. WTF is wrong with you people?
  4. Great idea. by Meshugga · · Score: 5, Interesting

    I honestly think that this is a great idea. It's a novel approach to extending a kernel, especially considering NetBSD doesn't have that big of a market share and expressly focusses on supporting as many platforms as possible. Prototyping new features or certain drivers in a portable scripting language may give them a leg up in the functionality aspect of the race.

    Also, LUA is super fast, small, easy to learn, concise and the C API/embedding it is straight forward.

    You may knock it all you want, "because kernel land is C land", but after all bias being said and flamed, this may turn out to be a really fun, interesting and possibly very useful idea.

  5. Re:Fucking LOL. by Anonymous Coward · · Score: 3, Funny

    Linus?

  6. Re:My P4 by MacTO · · Score: 3, Interesting

    It depends upon what he needs the computer for. If it is a server, then there is no need for a GUI. Even with respect to application software, there are a multitude of options out there. Writing can be done in text editors, then processed with TeX or troff (for formatted output to a printer, when necessary). There are a multitude of email clients and several web browsers. I've never really tried it, but you can even do graphical design with languages like PostScript and POV. Media? Again, you have access to many audio players. It's much more gimmicky in nature, but you can even play videos on text consoles.

  7. Tags by Areyoukiddingme · · Score: 5, Funny

    Surely this article deserves the whatcouldpossiblygowrong tag more than any other this year. And possibly last year too...

  8. Re:Stupid NOT by Anonymous Coward · · Score: 5, Interesting

    I don't know how much Unix/BSD/Linus code you have read or written, but I have been developing core code, Scheduler, MM and Drivers since 1980 and this is a great idea, long overdue.

    The Abstractions are now well understood and most code dos't need to be quick, but safe, putting PRE in kernels will clean up acres of cockamamie code now written in C, most of which just runs at boot time and is then freed. ... there are exceptions, you cant't have the garbage collector running whenever it likes, eg in the middle of an interrupt routine, but managed memory, not C, C++ scoping is the way to stop slow memory leaks.

    Put simply you are an idiot and dont know what you are talking about.

    MFG, omb

  9. Re:Stupid by dalias · · Score: 4, Interesting

    It is potentially stupid, but the reason is much more subtle than most people realize. For all its limitations and headache, C does have one key feature that makes it suitable for kernel programming where most other languages are not: the concept of well-defined storage durations and reserving storage for an object. I really question whether Lua code running as part of the kernel can be made robust under out-of-memory conditions which a kernel must be able to survive.