Installing Ubuntu 16.10 on Macbook Pro Retina mid-2012

I did a fresh install of 16.10 on my Macbook Pro Retina mid-2012 (rMBP 10,1). It seems quite stable so far, and brings a bunch of small improvements over 16.04.

Improved from 16.04

  1. Startup Disk Creator can be used for creating the ISO
  2. Installer works more smoothly
  3. Nvidia drivers no longer required for good performance
  4. Intel power management works correctly

Now for the directions!

1. Resize Partitions

This step is pretty straight-forward. Just open Disk Utility in OSX, and resize your existing OSX partition, so that there’s some free space for Ubuntu. You’ll want to leave the empty space as “free space” (it will get formatted during the Ubuntu installation). There are plenty of guides, if you get stuck on this step, including the Ubuntu wiki.

2. Install rEFInd

  1. Download rEFInd 0.10.3
  2. Unzip the package.
  3. Run the refind-install script.

If everything went well, you’ll see the rEFInd boot menu on the next restart. If you run into any problems, you can find more details on their website.

3. Install Ubuntu

Download the Ubuntu 16.10 ISO, and create a bootable USB drive. Note that the wifi won’t work (we’ll fix this in the next step), so don’t try to install updates during the installation process, unless you have a separate usb wifi dongle or ethernet.

4. Install Wifi Drivers

Wifi doesn’t work out of the box, so from another computer (or your OSX install) download the driver and its dependencies (dkms, libc6-dev, linux-libc-dev), then copy them all to a flash drive and boot back into Ubuntu. Install each with:

sudo dpkg -i "the package file you downloaded"

Alternatively, if you have a usb wifi card, you can use that and install the driver with this command:

sudo apt-get update && sudo apt-get install bcmwl-kernel-source

5. NVIDIA Drivers (optional)

The nouveau drivers work well, but if you want the proprietary drivers which may give better gaming performance, you’ll need to install them separately. Open “Additional Drivers” and select the latest proprietary driver.

6. Other Configuration (optional)

If you’re like me and want the F1-F12 keys to behave as function keys, and not special keys then just follow these steps from the AppleKeyboard guide:

echo options hid_apple fnmode=2 | sudo tee -a /etc/modprobe.d/hid_apple.conf
sudo update-initramfs -u -k all
sudo reboot

To increase the text size, since the resolution is very high, open the Displays settings and increase “Scale for menu and title bars”.

Debugging JVM Safepoint Pauses

I recently spent a bunch of time investigating why a Java application was spending a significant amount of time paused, even when garbage collection cycles were only taking ~200ms. The issue turned out to be other safepoints.

For those that don’t know, the VM uses safepoints to perform a variety of internal operations, and they involve pausing every Java thread. Garbage collection is the most well known, but many other operations such as deoptimization, and revoking biased locks require a safepoint as well. Alexey Ragozin has a good explanation of safepoints and points to some VM flags that are useful for debugging safepoint issue.

-XX:+PrintGCApplicationStoppedTime
-XX:+PrintSafepointStatistics
-XX:PrintSafepointStatisticsCount=1

However, he didn’t explain how to interpret the output, so I dug into the source code to find out what the logging meant. The output on safepoint statistics is shown below. (note: I split the line in half to make it easier to read)

   vmop  [threads: total initially_running wait_to_block]
10.526: RevokeBias  [154          0              3      ]

The first part tells you what operation is being performed “RevokeBias” in this case, which means that a biased lock is being revoked. The next three numbers are the total number of threads, the number that were running and contributed to the “spin” time, and the number of threads which contributed to the “block” time (shown below).

[time: spin block sync   cleanup vmop] page_trap_count
[      0    3471 3583    531     5342]  0

This part is the most interesting. It tells us how long (in milliseconds) the VM spun waiting for threads to reach the safepoint. Second, it lists how long it waited for threads to block. The third number is the total time waiting for threads to reach the safepoint (spin + block + some other time). Fourth, is the time spent in internal VM cleanup activities. Fifth, is the time spent in the operation itself (RevokeBias in this case).

In this example, we can see pretty clearly that the pause was caused by 3.5secs spent waiting for threads to block, and then an additional 5secs revoking the biased lock.

Fun with microcontrollers

2010-03-19-22-39-34

I decided to learn how to program microcontrollers. SparkFun has some really good tutorials <http://www.sparkfun.com/commerce/tutorials.php>. So far nothing too exciting, but I managed to compile and load the code onto the microcontroller and make a blinking LED =P

Blinking LED Video (sorry it’s not embedded, that turned out to be  non-trivial on WordPress. Anyone know a good plugin for embedding?)