top | item 6971127

Xv6, a simple Unix-like teaching operating system

200 points| cturner | 12 years ago |pdos.csail.mit.edu

78 comments

order
[+] bane|12 years ago|reply
Really cool project. Older, simpler, unixes are surprisingly relevant for undergrad-level learning.

It reminds me of my OS class in my undergrad days. We skipped a few bits by using the JVM to get a few things for free, but we still had to write (as groups of 3-5 people) an entire unix-like, complete with user-space programs, messaging systems, etc.

Definitely one of the most valuable classes I took for my degree.

[+] kirbyk|12 years ago|reply
Purdue has a similar OS, Xinu, that was created for teaching. It is actually used in industry around the world. - http://www.xinu.cs.purdue.edu/
[+] luckydude|12 years ago|reply
+1 I learned a boatload by reading the xinu books.

Also met Doug, he's a great guy, old school C hacker.

[+] n1cked|12 years ago|reply
The OS classes at several universities revolve around reimplementing Xinu and really getting to know a linksys router.
[+] adamnemecek|12 years ago|reply
That reminds me, I stumbled upon the website of the Unix Heritage Society (http://www.tuhs.org/) which has the source code for the early versions of Unix.

Here is the first version

http://minnie.tuhs.org/cgi-bin/utree.pl?file=V1

I did not really spend enough time reading the source to understand what's going on but it's interesting regardless.

[+] derekp7|12 years ago|reply
There's also a port of V7 Unix to x86, by http://www.nordier.com/v7x86/

I only wish that there was an add-on tcp/ip stack for that version, then one could really have fun with it. Yes, I know, the ip stack add on is called BSD.

[+] swetland|12 years ago|reply
Because splatting object files and intermediates all over the same directories as the source drives me nuts, I shuffled things so that it's a bit easier to find things (splitting source into kernel/, user/, ulib/, tools/, and include/ directories) and generated files are collected into kobj/, uobj/, out/, and fs/ directories.

https://github.com/swetland/xv6

I also tweaked the scheduler to halt if there's nothing to schedule, per tankenmate's suggestion.

A side-effect of this change is the generate-source-code-printout targets were rather severely broken, so they're simply removed for the moment.

[+] tankenmate|12 years ago|reply
If you are running this on your laptop and want to save your battery then use this patch...

http://pastebin.com/BxXDDtTh

[+] userbinator|12 years ago|reply
I remember in the pre-Pentium II days people cared rather little about power consumption (TDPs were only a few watts or maybe a dozen at most), and the idle process was basically a very tight infinite loop.

Around the time of the PII people (especially overclockers) started noticing that the CPU would stay cooler when halted, and thus started a little industry of "CPU cooling software"... there's an interesting historical page on that here:

http://estu.nit.ac.jp/~e982457/other/cpuidle/idle.htm

A modern processor, on the other hand, takes a few watts halted and a hundred or more when active, and transitions between these states many many times per second. How much things have changed...

[+] swetland|12 years ago|reply
Nice catch. Actually speeds everything up a bunch. I did it a bit more tersely with:

if (p == &ptable.proc[NPROC]) hlt();

after the sti() and initializing p to 0;

[+] akkartik|12 years ago|reply
Interesting. How does the processor restart after hlt?
[+] Jonanin|12 years ago|reply
xv6 is a pleasure to hack on and learn from! It's got everything you'd expect from a unix-like OS (multi-processor support, simple scheduler, unix-like FS, many of the standard syscalls, fork/exec based shell, etc).

Linux and *BSD may be the modern standard for unix-like OSes, but they're often too complex and opaque for beginners to learn from. It's super easy to read and toy with xv6's code if you want to learn more about OS internals, though. For example, I was able to implement a simple log structured file system: https://github.com/Jonanin/xv6-lfs

Note: if you're looking for companion reading material, check out this OS book: http://pages.cs.wisc.edu/~remzi/OSTEP/ (IMO it's super approachable and understandable for undergrad-level learning)

[+] kps|12 years ago|reply
I just did a quick grep through the code, and apparently students are expected to understand this.
[+] capkutay|12 years ago|reply
I wonder how this compares to pintos (http://www.stanford.edu/class/cs140/projects/pintos/pintos_1...) which is an i386 unix like OS. In my under grad class we had to build thread scheduling, sys calls, virtual memory, and some file system functionality on top of pintos. It was the most challenging and most interesting set of projects I've ever completed.
[+] merkury7|12 years ago|reply
Adding to the list of alternatives:

MINIX (http://www.minix3.org/)

[+] mwcampbell|12 years ago|reply
At the risk of reigniting an old flame war, it seems to me that a microkernel in which core OS functions such as process management and the virtual file system are in separate servers would be more complicated than a monolithic kernel. Having device drivers and specific file systems in user space may be useful, though.
[+] blt|12 years ago|reply
Awesome! I really hope MIT releases video lectures for 6.828 so I can do the full course on my own. I'm listening to Berkeley's OS lectures right now but I would love a course built around xv6.
[+] singular|12 years ago|reply
For anyone else who is playing with this in OS X Mavericks, I've written a blog post describing how to get things working on it (there are a couple steps that need to be tweaked.) - http://blog.ljs.io/post/71424794630/xv6

Hopefully this is useful to somebody and isn't too blatantly link whorey :)

[+] mjg59|12 years ago|reply
Someone's going to have the fun job of porting this to UEFI at some point in the not-too distant future.
[+] swetland|12 years ago|reply
Doesn't seem like it'd be a big ordeal. Just adapt an existing bootloader to load the kernel.

Also it looks like they mostly run it in qemu.

[+] geofft|12 years ago|reply
It's multiboot, so you can just boot it from grub.efi. See sheet 10, xv6/entry.S.

The more annoying thing is likely to be that it's 32-bit only. Are there any common machines that do x86-32 UEFI boot? Alternatively, does a 64-bit grub.efi know how to exit long mode and go into protected mode, to multiboot a 32-bit kernel?

(I was actually talking the other day with some folks about whether a 6.828 project involving a UEFI port of JOS, the other teaching OS, would make sense, but the 64-bit thing seemed to make it less interesting unless you also plan to do a 64-bit port of JOS. Which has been done before in a final project, admittedly...)

[+] userbinator|12 years ago|reply
As long as there are things like SeaBIOS, there is no need for UEFI.
[+] Moral_|12 years ago|reply
Were using the Xv6 kernel for the OS class here at the university of Utah, for the first time. In my opinion an OS class that makes you hack on low level code is significantly more beneficial tha just a theroy class.
[+] csense|12 years ago|reply
If "Xv6's use of the x86 [is intended to make] it more relevant to students' experience," then why use AT&T assembly language syntax rather than Intel?
[+] rsc|12 years ago|reply
Because the GNU toolchain uses AT&T syntax and most students have the GNU toolchain readily available?
[+] samograd|12 years ago|reply
I thought this was pretty awesome when I found it a couple of years ago, especially since it's multicore.