Become a fan of Slashdot on Facebook

 



Forgot your password?
typodupeerror
×
Open Source BSD

NetBSD To Support Kernel Development In Lua Scripting 311

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."
This discussion has been archived. No new comments can be posted.

NetBSD To Support Kernel Development In Lua Scripting

Comments Filter:
  • users? (Score:5, Insightful)

    by gTsiros ( 205624 ) on Saturday February 16, 2013 @06:52PM (#42924631)

    "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.

    • Re:users? (Score:5, Interesting)

      by TheRealMindChild ( 743925 ) on Saturday February 16, 2013 @07:02PM (#42924701) Homepage Journal
      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
      • Re:users? (Score:5, Funny)

        by KiloByte ( 825081 ) on Saturday February 16, 2013 @07:20PM (#42924811)

        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.

        • Re:users? (Score:5, Interesting)

          by Lodragandraoidh ( 639696 ) on Saturday February 16, 2013 @07:33PM (#42924905) Journal

          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?

          • by Natales ( 182136 )
            One possible answer to your point is to use Parallax OS [returninfinity.com] or a similar concept. I find very appealing the self-contained nature of FCAPS to an individual core.

            Interestingly, they leverage Bare Metal OS [returninfinity.com] and the coding is done mostly in Assembly (although C is possible). I think the fattening of all kernels is making these kind of projects look more interesting.
      • Re:users? (Score:5, Insightful)

        by Mindcontrolled ( 1388007 ) on Saturday February 16, 2013 @07:22PM (#42924823)
        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.
        • Re: (Score:3, Funny)

          by aliquis ( 678370 )

          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.

        • Re: (Score:2, Insightful)

          by rubycodez ( 864176 )

          go fuck yourself. I'm and Linux and BSD user, I've taken grad courses in kernel architecture of Minix, System V, BSD, VMS. I've modified the kernel of many OS. Not everyone is a windows wuss.

      • Re:users? (Score:4, Interesting)

        by Jane Q. Public ( 1010737 ) on Saturday February 16, 2013 @07:26PM (#42924861)

        "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.

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

          A monolithic kernel will inevitably get bloated over time as more features and drivers are added. This is a bad thing because any malfunction in any component has the potential to mess up the entire running kernel. Using a scripting language for less performance-intensive parts is an attempt to mitigate this risk. Whether it's a good idea remains to be seen.

          I have right here a program that is more than 45 times the si

      • Re:users? (Score:4, Interesting)

        by WindBourne ( 631190 ) on Saturday February 16, 2013 @10:10PM (#42925583) Journal
        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.
    • Re:users? (Score:5, Insightful)

      by MacTO ( 1161105 ) on Saturday February 16, 2013 @07:29PM (#42924881)

      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.

      • by jbolden ( 176878 )

        Lua is specifically designed to be an easy embeddedable scripting language when one needs a light scripting language but not a full featured programming language. Luas are way way easier.

        • by kriston ( 7886 )

          Lua is all over the Logitech Squeezebox by SlimDevices. It's Tcl for the new generation.

        • Lua is a full-featured programming language, though - more so than many other common embedded languages, and on par with Python. Semantically it's actually somewhat similar to JavaScript , except without all the shitty design decisions.

          • by Dahamma ( 304068 )

            It is a really simple syntax and reasonably efficient interpreter, and metatables allow a surprising amount of OO design and easy C integration. One complaint is I wish they hadn't made it so minimal as to combine hashes and arrays into one type. I kind of wonder if that's going to be a pain when writing more traditional C-ish driver-type code in this project.

          • by jbolden ( 176878 )

            I don't think that it is really true. I think Lua could evolve to be as strong in applications programming as Python but they choose to fill different niches and so the languages evolved along different paths.

            Lua uses automatic coercion in all instances which makes programs faster to write and harder to maintain.
            Python has a very well defined OO structure.
            Lua doesn't have the huge libraries of functionality Python does
            Lua's lack of high performance arrays
            Lua's lack of unicode is a big problem for applicati

    • Re:users? (Score:5, Interesting)

      by jbolden ( 176878 ) on Saturday February 16, 2013 @08:40PM (#42925257) Homepage

      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.

  • Performance (Score:5, Informative)

    by Anonymous Coward on Saturday February 16, 2013 @06:52PM (#42924633)

    Won't that kill performance?

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

    • by Anonymous Coward

      Lua is the fastest available scripting language for the task that NetBSD needs it for. It compiles to a byte code, is designed for efficiency and most importantly has excellent hooks for C integration. I have to commend the NetBSD team for their decision - hopefully it will be very successful and lead to a similar implementation in Linux.

    • Re: (Score:3, Informative)

      by Anonymous Coward

      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.

    • Re:Performance (Score:5, Informative)

      by stenvar ( 2789879 ) on Saturday February 16, 2013 @07:50PM (#42925029)

      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.

      • Re:Performance (Score:4, Insightful)

        by 10101001 10101001 ( 732688 ) on Saturday February 16, 2013 @09:47PM (#42925519) Journal

        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

    • I'm not sure, but there might be non-C system code in OS X (Objective-C) and Windows (C++, C#). In FreeBSD, there's Forth in the bootloader (does that count?).

      I think you meant: Linux developers only use C for system programming.

    • If the scripting language generates C code, then not a big deal. And if it is for SLOW devices, then a simple scripting language will work for it as well.
    • by jythie ( 914043 )
      Actually Lua is pretty efficient (and restricted), which is one of the reasons it has become so popular for use in soft real time environments.

      True it is not going to be as efficient as C, but when we get to device drivers we are not necessarily talking 'every cycle counts' anymore and other considerations start to factor in.
  • long overdue (Score:5, Interesting)

    by stenvar ( 2789879 ) on Saturday February 16, 2013 @06:54PM (#42924645)

    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.

    • Re: (Score:3, Interesting)

      by Anonymous Coward

      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).

    • I would be happier if the major window managers supported Lua. I'm not sure I would want to mess with device drivers.

      • Re:long overdue (Score:4, Insightful)

        by stenvar ( 2789879 ) on Saturday February 16, 2013 @07:55PM (#42925059)

        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.

  • Great idea. (Score:5, Interesting)

    by Meshugga ( 581651 ) on Saturday February 16, 2013 @07:02PM (#42924699)

    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.

    • Exactly. For SLOW items, or brand new items, this might be a way to have a QUICK interface developed. And if a code generator simply kicks out c-code that is compiled in, then it may work for even medium speed items.
  • Okay, sure. But...why Lua? :/

  • by Anonymous Coward

    This is awesome. What is old is new again. Lisp machines were some of the most beloved equipment for os and ai hackers because of the ability to get to the underbelly easily. This is no different. Making the operating system more approachable makes doing operating systems research easier. This is a great idea.

    Besides, it's a natural extension of the RUMP kernel paradigm. If you can run a netbsd kernel, as part of a userspace process on linux, then it only makes sense to be able to talk to these 'kerne

  • I dont know what packages are going to be bound with this, but in many cases your right back in C adding bindings for lua. Thats one of the good points about lua, is that it can be tied to anything, but the bare bones basic lua is not too much more complicated than a batch file

  • Tags (Score:5, Funny)

    by Areyoukiddingme ( 1289470 ) on Saturday February 16, 2013 @08:34PM (#42925235)

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

  • by yurik ( 160101 ) on Saturday February 16, 2013 @08:41PM (#42925267)

    MediaWiki developers are almost ready for Lua scripting to be enabled for all Wikipedia and related sites, and It has already been deployed to http://mediawiki.org./ [mediawiki.org.] Lua was chosen mostly because of how easy it is to sandbox and limit memory consumption.

    http://www.mediawiki.org/wiki/Lua_scripting/Tutorial [mediawiki.org] -- Introduction

  • I like to think I'm okay at C. I certainly don't generally find it particularly intimidating. I've written kernel code, though not much. I maintain a program that emulates root privileges by intercepting syscalls -- and which works on Linux and OS X. I'm basically clear on how this works.

    But when I do iOS/Android stuff, I have a pretty strong preference for Lua, because I don't always want to be thinking about pointers. And yes, LuaJIT is... plenty fast. The mere fact that it's a JIT implementation means th

    • by AuMatar ( 183847 )

      You realize that in most of those higher level languages *everything* is a pointer. So you're not actually saving yourself anything except calls to delete. Most of the difficult parts of pointers you still need to worry about.

      • by seebs ( 15766 )

        I have tried several times to figure out what on earth you are saying, and I've come up empty.

        In C, it is possible for me to allocate an object, fail to free it, and end up having leaked memory. It is also possible for me to retain a pointer to something that was freed, and get surprising behaviors from that. I can overrun buffers. Heck, I occasionally do, although it's usually pretty rare for me.

        None of these are possible in Lua.

        I am not sure what the "difficult parts of pointers" you're thinking of are, b

    • Me too and I'm not interested in learning Lua or more APIs. I think C is where it should remain; however, this could prove extremely useful for development, debugging and experimentation - especially for any kind of driver. I think it should be an option; although, it is likely many users would turn it on because of the number of drivers or features that would not have been ported to C yet. Eventually, things can be ported or even automatically translated to C code. For rapid and more stable developme

  • by Theovon ( 109752 ) on Saturday February 16, 2013 @10:24PM (#42925631)

    With the BSD's, there no such thing as a tainted kernel. But with Linux, non-GPL drivers are actively discouraged. If they were to add scripting to the Linux kernel, it would actually make it easier to write proprietary drivers, so they'd never go for that. Forget the fact that it would make it a hell of a lot easier to sandbox drivers so they don't clobber other kernel memory. Forget the fact that code in a higher-level language is smaller; countless drivers would suffer no appreciable performance hit by being written in an interpreted language (especially Lua), so you'd have one small interpreter and many shrunken drivers, which would make the kernel memory footprint smaller. Forget the fact that mutually exclusive access to shared variables could be made implicit in a majority of cases, eliminating a whole class of bugs in one shot. No. We've got our precious GPL to protect. (Oh, and forget the fact that nVidia basically gets a free pass on this.)

  • There are multiple non-"C" DSL languages and virtual machines in the BSD kernels already and they have been there for over 20 years.

    Here is a prime example http://en.wikipedia.org/wiki/Berkeley_Packet_Filter [wikipedia.org]

    Lua is a very clean, small, and relatively fast object oriented language. It is probably the best possible choice for a general purpose dynamic language to embed in a kernel.
  • How about

    peek(xx)
    poke(xx)

    The best aprt of Commodore BASIC

As of next Thursday, UNIX will be flushed in favor of TOPS-10. Please update your programs.

Working...