7 ms·
Writing Network Drivers in Go [pdf]
- pmoriarty 8y agoIt looks like this is not a pure Go implementation: "We originally implemented these functions in pure Go and tried to force reads and writes through empty C calls as Go does not have the volatile key word or an equivalent for our needs as far as we know. This resulted in strange behaviour: while initialization seemed to work, including the corresponding register getters and setters, the program failed later when the NIC never set flags that were necessary to continue. We invested a lot of time in this specific problem but could not find a reason for this behaviour. With the help of cgo, which enables the use of C code in Go programs, we imported the corresponding functions in device.h alongside log.h of the original C driver and replaced our go functions. This fixed the aforementioned problem though we never were able to provide an exact explanation due to limited time constraints." It's still an interesting effort, and it makes me wonder if we'll ever see a day when a significant portion of Linux is written in a safer language.
- hazz99 8y ago> It's still an interesting effort, and it makes me wonder if we'll ever see a day when a significant portion of Linux is written in a safer language. I really hope Ada makes a comeback, especially in commercial kernel programming.
- vasilia 8y agoWe can start with nodejs. Nodejs with async model will be the best solution to achieve the best performance(after 'delete spaces' method of course).
- mav3rick 8y agoPerformance isn't an issue with C code. Security is.
- atilaneves 8y agoIt can be. Unless one resorts to macros, templates are usually faster.
- mav3rick 8y agoEverything can be an issue everywhere. No one will choose Node JS over C to counter performance.
- atilaneves 8y agoNo, but one can get code to perform as fast or faster than C with any other systems programming language, especially if they have templates/generics.
- goatlover 8y agoThe libuv library Node makes us of for handling async calls is written in C.
- vasilia 8y agoIt's not a problem. The main problem is the assembly code. There is no way to inline it in JS code. After boot time system should make some things like A20, enable paging/protected and long mode, build GDT/IDT.
- goatlover 8y agoRight, but my reply to the parent was that Node isn't a performance improvement over C because it has async, when the async part is written in C. JS popularity has led to some wild claims. Never thought I'd live to see the day someone proposed a JS runtime would be more performant than C for writing operating systems.
- Itaxpica 8y agoSomeone suggesting re-writing the Linux kernel in nodejs may be a strong contender for Peak HN
- vasilia 8y agoWhy Linux? It's a simple hybrid kernel. It will be better to rewrite HURD/L4.
- mixedCase 8y agoWhat's your opinion on Rust? It seems to be successfully filling the niche Ada could not, even if Ada's problems were more political than technical.
- hazz99 8y agoI'm not a kernel programmer, and I haven't used Rust before, so take that into consideration. Some of my favourite things about Ada is it's approach to concurrency, which (I think) is far superior to other imperative concurrent languages like Go. We should never have to deal with low-level primitives like semaphores and mutexes - it's 2018! Why are we stuck in the 80s? I've heard that concurrency is difficult in Rust, but I've never used it, so I can't comment. I plan on learning very soon!
- dilyevsky 8y agoWe should never have to deal with low level primitives like functions and variables - it’s 2018 why are we stuck in the 50s?
- hazz99 8y agoThat is an incorrect analogy. Semaphores are the "goto" statement of the concurrent world. Semaphores are not typed. They is no semantic connection to the thing they protect. Debugging concurrent systems with mutual exclusion enforced through these low-level primitives is a nightmare. If you forgot to lock/unlock, you'll never know! The compiler cannot check it. Deadlocks are imminent. We've had better abstractions since the 80s. Conditional critical regions, monitors, and (ideally) protected objects. Hell, even guards are better than semaphores and mutexes - at least they are associated with their critical region! I struggle to think of situations where a semaphore is the best choice. Maybe in extremely high-performance cases, but even then the compiler can usually make a better decision.
- goatlover 8y agoWell, Alan Key pretty much said that in the 70s, and has stuck to his high level guns all this time.
- empath75 8y agoMore likely to see something like Redox take off.
- nilsocket 8y agoActually cgo, had some performance issues. Whenever a call to C program is made from go program, there is lot of work needs to be done. Go authors have thought to do initialization and set up the work for only once, but I don't think it is implemented yet.
- romed 8y agoIf nothing else this would be a fun and easy way to develop a driver from scratch for unfamiliar hardware, even if you intended to port the whole thing back to C in the end, after it was all figured out.
- hardwaresofton 8y agoThis is something I've noticed recently -- more and more researchers are starting to write reference implementation code for networking and distributed systems in Golang. In my own head, it makes sense -- golang is simple to read if not verbose, doesn't require crazy formatting, has excellent standard library support, and has relatively painless concurrency, and can be run as a scripting language. No it's not as easy to get started with as Python, Ruby or Perl, but only one of those has easy-to-spawn native threads, nevermind lightweight coroutines (and the one with native threads encourages illegible code). If you're not doing type theory work or very specific exploration in a specific field, I don't know another language that is so easy to get up and running with. On top of all this go's performance is pretty great/consistent as well, JS is the only other scripting language that comes close generally, but then you have to submit to the event loop. I've always thought one of Go's true killer features is how hard it makes cleverness. I'm starting to seriously think Go's popularity is going to continue shooting up. As I always note I think Go will supplant Java as the incumbent in the enterprise software in one or two decades max. [EDIT] - Forgot to include the most recent example that made me think this: WPaxos(AKA WAN Paxos)[0] and the included github repo[1]. To be fair CASPaxos[2] included gryadka[3] which is in JS. [0]: https://cse.buffalo.edu/tech-reports/2017-03.pdf https://cse.buffalo.edu/tech-reports/2017-03.pdf [1]: https://github.com/ailidani/paxi https://github.com/ailidani/paxi [2]: https://arxiv.org/abs/1802.07000 https://arxiv.org/abs/1802.07000 [3]: https://github.com/gryadka/js https://github.com/gryadka/js
- lkurusa 8y agoLet's not forget the Biscuit operating system by MIT just recently published at OSDI'18: - The paper: https://pdos.csail.mit.edu/papers/biscuit.pdf https://pdos.csail.mit.edu/papers/biscuit.pdf - The code: https://github.com/mit-pdos/biscuit https://github.com/mit-pdos/biscuit
- hardwaresofton 8y agoAwesome thanks that looks like a very interesting read. Oh yeah another thing that just showed up on the front page actually, someone writing network drivers for their bachelor's thesis in Go: https://www.net.in.tum.de/fileadmin/bibtex/publications/theses/2018-ixy-go.pdf https://www.net.in.tum.de/fileadmin/bibtex/publications/thes...
- pjf 8y agoThese guys are so positively insane! :) See https://github.com/ixy-languages/ixy-languages#overview https://github.com/ixy-languages/ixy-languages#overview
- godelmachine 8y agoContrast this with https://news.ycombinator.com/item?id=18405515 https://news.ycombinator.com/item?id=18405515, which is trending at the top.
- skocznymroczny 8y agoHow do they handle the GC?
- otterley 8y agoThe driver only allocates memory on the stack, so no GC is required.