More OS

Don’t you love that sense of satisfaction you get after you fix a rather annoying bug?

8 finished the VM rewrite for our kernel (and it looks *much* nicer now, and the PM can also magically keep track of free physical pages without needing an internal data structure [and hence, won’t use more memory if we ever happen to get more than 256MB of ram]) and we had a remarkably easy time integrating it into our main branch (although I’m still of the opinion that Subversion merging is horrific and painful).

Then the fun started. Things started out ok and init and idle started and the shell started and readline worked.
Then, when we tried to execute a task from the shell, things exploded.
After about an hour, I tracked down the problem to fork’s page-directory-and-table copying function… odd though, since that hadn’t changed since before the VM rewrite, and it was working fine before.
After poking at it some more, I determined that, for some unknown reason, one of the page tables in the newly-forked task contained garbage data. Garbage data that happened to look a lot like a kernel stack. Hmmm…
A bunch of breakpoints and plenty of x%cr3 4096 and psym "pcb->esp0" later, I discovered that, somehow, the same physical page was being mapped as both a kernel stack page and as a page table page. Very odd.
Poked at it for another couple hours until I managed to isolate the problem to one function… a function that destroys the current mappings in the page directory/tables to prepare a task for exec. Turns out it was a mistake with freeing pages… for some reason, the code was freeing a page *after* the desired page (PTR_ADD(page_loc, PAGE_SIZE)). Oops. Fixing that fixed the immediate bug but tripped an assertion.
That one turned out to be simpler… the wrong virtual address was being passed into the freeing function (*entry instead of entry). Whee.

So yeah, it appears that we are back in the same state that we were yesterday as far as runnability and such goes, except we have a shiny new VM that appears to be much happier (and much cleaner) than before.

I should probably go sleep, as it is 7:30… but it might make more sense to just stay up until class and then sleep afterward. Meh.

All we have left to do is finish vanish and write wait and we will be kernel code-complete (at least, theoretically… we’ll probably end up doing more rewrites and such). Awesomeness.

There has been much ITG lately. I need to get back into 11s… maybe I’ll manage to pass a 12 before I leave CMU. Wheee.
110107itg.jpg
110107itg2.jpg
110107itg3.jpg

Recent life

Life has been odd lately.

Monday night was coding until 7 AM. Tuesday night was another all-nighter, coding until the checkpoint on Wednesday morning. Then was more coding until Wednesday night, when I tried to get a decent amount of sleep. Still, it wasn’t enough, since I had to get up for work at 7 and ended up leaving early because I was starting to have trouble reading lines of code like “x = 5;”

Also, in the past 2 days, I have received two job offers. One is with a company I really, really like (in California), and will likely take unless something better comes up, or unless I decide to remain in Pittsburgh. I dunno.

Wheee things have been so surreal lately… likely due to the recent lack of sleep.
Here’s looking forward to late November, when I can start getting back to a normal sleep schedule.




Edit: Continuing the trend of not getting enough sleep, it is now almost 2:30 AM and I’m coding. Wheee.

Posted in OS

OS

Last night I was up coding until 7 AM. A lot of the time was spent fixing compiler errors, and then tracking down a bug caused by using the wrong variable in one place, causing page table entries to get overridden… causing problems later.

Today, it was my turn to have a huge bug in my code, and mine was a conceptual error (although, to be fair, it was one both of us missed).
We decided to start the first two tasks for the kernel by writing a kernelland fork function, which works much like the user version. The user version copies over all of memory except for kernel memory, creating a new kernel stack for the child and putting only the necessary stuff on there (IRET foo and registers).
I did the same thing for the kernel version, except I don’t copy any memory (since there is nothing in userspace yet). I create a new kstack and copy over only the necessary values… the return address (to return to the previous calling function) and registers.

See the problem yet?

Turns out I forgot to take into account that execution in kernelland uses the kstack… and so maybe continuing execution in kernelland (as we do by using the same return address) would need things on the stack. As a result, we kept getting the strangest errors where memory was being overridden in various ways (since the function we return to expects certain things at esp+16, and expects ebp+4 to have arguments and such). So yeah. That bug took a good 3 hours to track down. Oops.

I had a Google interview today. I feel like I did well at the data structures/coding portion, but I completely bombed the algorithms part. It seriously makes me wonder how I managed to get an A in algo class. Or maybe I’ve just forgotten everything since then. Meh.

Whee… now it’s time to debug userspace exec and fork. Fun fun fun?

Edit: 5:30 AM. Looks like it’s going to be another all-nighter. We really should start working more earlier in the week so we’re not stuck doing a bunch of stuff the night of the deadline.

Edit edit: 6 AM and fork works! Huzzah. Turns out the problem wasn’t at all in my code (which was surprisingly, given the complexity of the mapping of multiple physical pages into and out of a virtual address space, correct the first time) but rather with the TLB keeping around “stale” entries. Oops. Now let’s get exec working (and maybe bed after that).

Edit edit edit: 9 AM. Mission failed. We didn’t manage to get exec working (although it now does return to userland and run for a bit, albeit incorrectly, before being context-switched away and page faulting on its next run). Hopefully we’ll have it done today.

OS!

Well, I’ve been coding and working on our kernel since approximately 10 AM yesterday (Sunday). The first checkpoint is in 5 hours, and I think we’re going to make it. Maybe.
Both of us are slowing down quite a bit (it took us like 6 hours to even get our code to compile, since we had compiler errors like hell, and then had a ton of linker errors because we forgot various includes, and by that point it was like 2 AM), but the debugging portion shouldn’t be too terribly deathy. In any case, we are quite code complete for checkpoint 1 (and even a little ahead, maybe, in the sense that we wrote our VM to be somewhat correct instead of just hacking it).

Yay for all-nighters!

Greg has been amazing through the past many hours, making breakfast and then dinner for both me and 8, and then bringing me caffeine so I don’t fall asleep.

Perhaps as a consequence of our 17-hour-straight coding spree, and as our last shreds of sanity fled, there was a break for some Zack bondage, and then some 8 bondage, both with Cat5 cable. There are photos, which will likely be posted behind a friends-locked entry behind a cut on my LJ sometime logical tomorrow (although, I suppose, it’s logical today if I never actually get to sleep).

Wheeee….
The next few days are going to be very interesting.
Pamela’s for delicious breakfast tomorrow morning followed by OS checkpoint followed by (probably) more OS coding. Then is going to bed early, since I have to wake up at around 6 AM on Tuesday to catch a plane to another interview in California.

Edit: It works! We made the checkpoint with an hour to spare. Huzzah! Now to do other stuff, because I’ve been coding for the past 23.5 hours.

Posted in OS

Stuff

The best word to describe the trip would be “frustrating”, even though the interview and the evening afterward were very, very nice.

It started out with a plane ride on Thursday afternoon that meant I missed Pen-based computing class. Not a big deal, but in general it got me stressed about OS and how I was really worried about getting to the checkpoint and whatnot. (See last entry for full angst-ness.)
The flight was long… I hate flying… I hate layovers. The plane arrived in California late, so I didn’t get to the hotel and to bed until around midnight, which would be 3 AM Pittsburgh time.
Woke up to rain the next morning… lots of rain… and I hadn’t brought an umbrella, so I got really wet on the way to the interview. About halfway there, I get a call that the tour (the first part of the interview) was cancelled because of the rain, so I went back to the hotel for a couple hours…

Headed back (in the rain), and things went better after that.
The interview itself was good… afterward was an amazing dinner and going to a bar with the other interviewees and two employees.

The next day was all flights… two layovers, meaning I spent something like 13 hours in planes and/or in airports. Didn’t get home until around 10 PM. Meh.

Now is lots of OSing. We basically had nothing written for Checkpoint 1 (which is tomorrow), so today is lots of coding and oh god death. Meh.
We might end up missing the checkpoint anyway, but that’s okay… as long as we don’t miss the second checkpoint.
Unfortunately, I am also gone next Tuesday and Wednesday (for another interview).
Blar.
I want OS to go away so I can just do interviewing and enjoying life before I head off into the world… :-\