Friday, 9 October 2015

Heaphy Track

October 1-4 I walked the Heaphy Track with family. The weather was wet on the first day but cleared up nicely and as always we had a great time.

The Heaphy runs from the east end of Kahurangi National Park, near Golden Bay on the northern end of the South Island, west through the hills to the west coast of the South Island, and then south along the coast to the northern end of the road. (It can also be walked in the other direction.) Our first day was steady walking uphill, but not steep. The second day was up and down through the Gouland Downs at an elevation of around 800 metres. The third day is steady downhill to the coast, and the fourth day is along the coast, up and down a bit as you cross small ridges. The Heaphy is the longest Great Walk (about 80km) and we walked 5-6 hours each day. Since we generally set out from a hut at 8:30am or so, on the second and third days we arrived at our destination by 2 or 3pm, leaving plenty of time for card games, short walks and socializing!

One of the neat things about the Heaphy is the variety. Each day you're traveling through quite different terrain, all of it interesting. You really appreciate how the environment changes from the east side of Kahurangi to the west coast. I particularly enjoyed the coastal walk on the last day; that coast is truly wild, and parts can be walked off the track, on the beach. At times there is no sign of human presence whatsoever. The sand, surf, thick palm forest and mist work together to provide a feeling of isolation and timelessness.

Going into the walk I had a bit of a niggle in my right knee. That turned out to be no problem at all --- I didn't feel it since we started the walk, and it seems to be cured! On the second and third days I developed some severe ankle chafing against my boots --- skin worn through, with bleeding. So on the fourth day I walked barefoot the whole way. There wasn't as much time on sand as I thought, and the track was often rocky, so it wasn't particularly comfortable, but I found it surprisingly easy. My feet have learned to distinguish pain from damage; going barefoot was more painful than the ankle chafing, but there was no damage at all apart from a small cut on my big toe. That very evening my feet felt fine, but my ankles are still touchy today. Ironically the most painful part of the walk was the last five minutes where someone had helpfully laid gravel on the track.

Thursday, 24 September 2015

Apple's Next Frontier: Fusion

Apple has more than two hundred billion dollars in cash that they obviously have no idea what to do with. Impressing investors after the success of the iPhone is very difficult. Apple needs to make a huge investment in something truly world-changing that could be immensely lucrative. Cars and smart watches aren't going to be that. Fusion energy could be! Currently, investment in this area is relatively low compared to the potential payoff. Revolutionizing humanity's energy economy is a challenge worthy of Apple (and Apple's cash). It's risky, but Apple can afford to make a few big bets. And if not Apple, then who?

Thursday, 10 September 2015

Booting Fedora 22 On A Lenovo ThinkCentre M53

We just bought a new computer for family use. I want my children to master computers, not just consume, so we got a desktop computer running Linux. I settled on a Lenovo M53, which is similar to a Mac Mini but cheaper --- just 450 NZD, probably because it's a two-year-old model. It comes with 4GB RAM (upgradeable to 8GB), quad-core Celeron, 500GB disk, Wifi, keyboard, mouse, and Windows 8.1. Moore's law always thrills me. When I started my PhD in 1994 we were just at the end of the period when one of the advantages of a top university was that they had access to better computers that let you get more work done. Nowadays any first-world family or school can buy enough computing power for almost any task, and that's a very good thing. I guess it's only a decade or two before everyone else catches up too.

Getting Fedora installed on the disk was easy by booting an installation image from a USB memory stick, but it was very hard to get the unit to actually boot anything other than Windows from the disk. The main problem is that the BIOS seems to reset UEFI boot order every time you boot, always putting Windows first (maybe because it's the first UEFI entry?). I couldn't find any way to prevent this. The BIOS Setup purports to let you change boot order (I'm not sure exactly how that relates to the UEFI boot order; it seems to pull some but not all UEFI boot entries), but no matter how hard I tried I couldn't get those order changes to stick; after "save changes and exit" it would go ahead and boot Windows and reentering BIOS Setup would show the changes were lost. Even entering BIOS Setup is hard; by default there are no on-screen prompts telling you which key to press, and you have only about a half-second window to press F1 during startup. You can however press F12 during startup and select booting from the Fedora partition. Many online comments indicate that Lenovo BIOSes have a problem with setting changes failing to be saved, though it's hard to tell exactly what the problems are.

In the end, I solved the problem by removing the Windows entry (and some other junk entries) from the UEFI boot list using efibootmgr. That was enough for the BIOS to finally give up on booting Windows. I can still boot Windows from the Fedora Grub menu. Presumably I wouldn't have had any of these problems had I not tried to keep Windows available for dual booting...

Saturday, 22 August 2015

Hooray For WebExtensions

Many of the comments on WebExtensions miss an important point: basing WebExtensions on the Chrome extension API does not imply limiting WebExtensions to the Chrome API. For example, Bill already made it clear that we want to support addons like Tree Style Tabs and NoScript, which Chrome intentionally does not support. So Firefox addons will continue to be able to do things you can't do in Chrome (though there will be some things you can hack into Firefox's XUL today that won't be supported by WebExtensions, for sure).

WebExtensions is something we need to do and should have done many years ago, before Chrome even existed. It's what Jetpack should have been. But better late than never!

Saturday, 1 August 2015


For a long time I was unenthusiastic about the idea of having children. After being a Christian for a while, I knew raising children would be a good thing to do, that I should do it, and that given the opportunity I would do it ... but I never thought of myself as someone who'd enjoy being a father or be good at it. (At heart I feel more comfortable with technology than with people.) I'll wait for God's judgement on the latter, but on the former, by God's grace, I was totally wrong. I definitely, thoroughly enjoy raising my children. More than that, my children quite often give me moments of sublime joy.

For someone who thinks a lot about mind and machines, watching children develop from helpless babies into the full flower of human physical and mental ability is truly awe-inspiring, and helping to guide that development is a great privilege and responsibility. It's all the dreams for AI coming true before one's own eyes! They learn language, they learn to read, they develop empathy and morals, they learn from what they read, they create new ideas, they pursue their own goals by creating and executing complex plans, and before you know it they're full-fledged people who surprise you, charm you, spar with you and teach you.

There's joy when I see one of my children teaching another. There's joy when my children use words I don't know from books I haven't read. There's joy when one of my children cracks a good, original joke. There's joy when my children see something that needs doing and do it without being told. There's joy when I give a vague instruction and my children work out how to do it and do it well. There's joy when I do something wrong and my children correct me. There's joy when I leave them with my parents for days and get a good report on their behavior. There's joy when my children choose to do something they don't want to do, just because it's right. There's joy when one of my children beats me in a board game I'm pretty good at. It's true that some of these joys don't come along very often :-).

As a Christian, I'm led to understand that God has some of these feelings towards us. He lets us take risks with ourselves and others --- not so that we can be independent of him or surpass him --- but so that we can be full-fledged people whom he can delight in and who can love him in return.

Monday, 13 July 2015

Two Reverse-Execution Optimizations

rr 4.0 will be the first rr release where reverse execution is reliable. I want to release it soon, but some users still find situations where reverse executions that seems to hang. I've implemented a mitigation by allowing ctrl-C to interrupt reverse execution (though I think there are still bugs where sometimes it fails to interrupt cleanly), but there are also underlying issues that can cause reverse execution to be very slow, and I want to fix as many of those as I can. I've recently fixed the two major fixable issues that I currently know of, and they're interesting.

For the following discussion, keep in mind that we implement reverse execution by restoring the program state to a previous checkpoint, then executing forwards and noting which breakpoints/watchpoints get hit. Once we reach our original starting point, we know which breakpoint/watchpoint firing is the "next" one in the reverse direction; we restore the program state to a previous checkpoint again, and execute forward again until we reach that target breakpoint/watchpoint.

The first issue involves reverse execution over conditional breakpoints/watchpoints that are hit frequently but whose condition almost always returns false. Following the above procedure, rr would reverse-continue to the most recent triggering of the breakpoint (or watchpoint), then stop and signal gdb; gdb would read program state via rr to evaluate the breakpoint, and then signal rr to continue with reverse execution. Thus, every time the breakpoint is hit, rr must perform at least two clonings of checkpoint state plus some amount of forward execution. That makes reverse execution unbearably slow if the breakpoint is hit hundreds of times.

Fortunately, gdb has an obscure feature that lets it offload evaluation of simple conditions to the remote target (in this case, rr) by expressing them as bytecode. So we add to rr a little interpreter for gdb's bytecode; then rr can implement reverse execution by executing forwards over some time interval, and every time a breakpoint is hit, evaluating its condition and ignoring the hit if the condition evaluates to false. If all goes well we only have to reconstruct program state for debugger stops where the user actually wanted to stop.

Unfortunately not all goes well. Some breakpoint expressions, e.g. those involving function calls, are too complex for gdb to express with its bytecode; in such cases, pathological slowdown of reverse execution is inevitable. So try to avoid using complex breakpoint conditions on breakpoints that are frequently hit during reverse execution. Moreover it turns out gdb has a bad bug in code generation, which requires an even worse workaround. I submitted a gdb fix which has landed upstream so hopefully one day we can get rid of the workaround.

Another case which is difficult to deal with is an unconditional breakpoint being hit very many times during the interval we're reverse-executing over. In this case just executing forward and stopping thousands times to find the last hit can be prohibitively expensive. Ideally we could turn off breakpoints, run forward until we're close to where reverse execution started, then enable breakpoints and continue forward again, hopefully only hitting a few occurrences of the breakpoint before we reach the last one. We can approximate this by detecting that we're hitting "too many" breakpoints while executing forward, and responding by cutting the remaining execution interval roughly in half, advancing to the start of the second half with breakpoints disabled, and resuming normal forward execution with breakpoints enabled --- possibly having to repeat the subdivision process if we're still in dense region of breakpoint hits.

I just landed these fixes on master. I'm very interested in hearing about any remaining cases where reverse execution takes a pathologically long time.

Sunday, 12 July 2015

Midwinter Road Trip

It being the school holidays, I took a few days off for a short road trip around the central North Island with my and my brother's family --- two nights in Waitomo and two nights in Taupo. It is the middle of winter and we had a bit of a cold snap --- frosts every night --- but the weather was clear, fine and sunny. It was a thoroughly excellent trip all around: caves, rivers, countryside, mountains, board games, geothermal areas, tasty food, love and laughter. The South Island is more spectacular, but the central North Island remains dearest to my heart as a God-given blessing to all who live in and around it.

One highlight for me was "black-water rafting" at Waitomo: wetsuit, inner tube, helmet and head-lamp in an underground river. It's thrilling and a little crazy but not as testing as I'd been led to believe; highly recommended. Beyond the thrills, I will long remember drifting along underground in darkness and silence under the glow-worm-studded roof.

Another highlight was a hastily-planned trip up Mt Pureora between Waitomo and Taupo on Friday. We drove up Link Rd from highway 32 on the east side of the mountain --- it's gravel, but in very good condition --- and reached the trailhead a bit late at 3pm, but had plenty of gear and moved fast. We reached the summit by 4pm (beating the signposted time of 1.5 hours) and after 15 minutes at the top returned to the car at 5pm. There had been snow the previous night (closing the roads around Ruapehu/Tongariro --- otherwise we'd probably have been doing a walk there) and the walk was delightful, starting as a regular North Island bush walk and ascending into a winter wonderland with a light covering of snow and ice, opening at the summit into magnificent views of the central North Island --- Taupo, the Waikato, and the snow-capped volcanic plateau. There are many other tracks in the area, and I'd love to visit again.