Tuesday, June 26, 2012

FB Folly's Atomic Hashmap

Recently, I watched Spencer Ahrens's talk on Folly's AtomicHashMap at the Facebook C++ conference. I thought it was pretty cool and was definitely impressed by the tricks that were used to achieved lock-free and wait-free hash map operations. The AtomicHashMap is 1.3x - 5x faster than boost.

Here are the slides and video.

Some cool takeaways:
  • Open addressing style
  • Growing hashmap: create another submap instead of rehash
  • Compare and swap for insert
  • ThreadCachedInt
  • Thread Local Storage
  • Microsharding when atomic inc is a bottleneck
  • Modulus is too slow for calculating the hash: so take mod on next power of two and use bit ops
    • What's the optimal size? Branch misprediction becomes a factor too.

Saturday, June 09, 2012

Sun Java on Ubuntu 12

Sun Java is no longer available on Ubuntu packaging due to licensing issues with Oracle. OpenJDK is provided instead. One solution to this is to use the sun-update-jre package via Dunisoft. However, this did not meet my requirements as the package does not include javac.

My solution was to extract the bin file provided by Sun/Oracle by following the steps here. Do note to fix your symlinks for javadoc, javah and javap.

sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.6.0_32/bin/javac 1
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.6.0_32/bin/java 1
sudo update-alternatives --install /usr/bin/javaws javaws /usr/lib/jvm/jdk1.6.0_32/bin/javaws 1
sudo update-alternatives --install /usr/bin/javadoc javadoc /usr/lib/jvm/jdk1.6.0_32/bin/javadoc 1
sudo update-alternatives --install /usr/bin/javah javah /usr/lib/jvm/jdk1.6.0_32/bin/javah 1
sudo update-alternatives --install /usr/bin/javap javap /usr/lib/jvm/jdk1.6.0_32/bin/javap 1

sudo update-alternatives --config javac
sudo update-alternatives --config java
sudo update-alternatives --config javaws
sudo update-alternatives --config javadoc
sudo update-alternatives --config javah
sudo update-alternatives --config javap

Monday, May 14, 2012

Ubuntu Precise Pangolin

I installed Ubuntu Precise Pangolin (amd64) on a separate partition today. The installation went well, with the usual black screen problem.

The amd64 build felt speedier for most applications compared to the i386 build..

I was unimpressed with Unity and so I proceeded to get back the Gnome 2 look and feel by following the instructions here.

Make sure that sources are up to date:
$ sudo apt-get update

Install the gnome fallback:
$ sudo apt-get install gnome-session-fallback
Logout, select Gnome Classic using the gear icon, and then login.

I replaced lightdm with the more awesome gdm:
$ sudo apt-get install gdm
$ sudo apt-get purge lightdm

Install aptitude, gdebi (so faciliate future .deb installations) and synaptic
$ sudo apt-get install aptitude gdebi synaptic

Remove the annoying global app-menu
$ sudo apt-get purge appmenu-gtk appmenu-gtk3 appmenu-qt indicator-appmenu

Remove Unity (Woots!)
$ sudo apt-get remove unity-lens-music unity-lens-applications unity-greeter unity-common unity-asset-pool unity-2d-launcher unity-2d libunity-misc4 libunity-2d-private0 gir1.2-unity-4.0

Remove the semi-invisible overlay scrollbar
$ sudo apt-get purge liboverlay-scrollbar-0.2-0 liboverlay-scrollbar3-0.2-0 overlay-scrollbar appmenu-gtk appmenu-gtk3 appmenu-qt indicator-appmenu

Remove compiz (I dislike special effects)
$ sudo apt-get remove compiz compiz-plugins-main-default libcompizconfig0

Install gconf so we can change the min,max,close buttons to the right:
$ sudo apt-get install gconf-editor
Run gconf-editor in terminal and look for the path  /apps/metacity/general in the tree.
Change the value of button_layout to ":minimize,maximize,close"

Following advice from here, I proceeded to install the cool weather indicator and multiload indicator.
sudo apt-get install indicator-weather indicator-multiload

Now, restart your computer.
Note: I did not install gnome-shell.
I proceeded to make more tweaks:

I installed my favorite Gnome-Do.
$ sudo apt-get install gnome-do
After install, you can start it from Applications -> Accessories -> Gnome Do
It should load on start up and it can be activated via super+space.

I brought back the Alt+F2 shortcut for the run dialog:
Bring up Keyboard window -> Shortcuts (tab).
Look for System -> "Show the run command prompt".
Change the value to Alt+F2.

I installed mscorefonts.
Bring up Synaptic Package Manager. Look for ttf-mscorefonts-installer.
Also installed Mac Fonts (e.g. Lucida Grande)

I also installed the awesome zsh and Google Chrome, and nautilus-open-terminal.

Finally, as my screen is 2 pixels off, I brought up Display and changed the resolution from 1368x768 to 1366x768.

Current problems:
1. xrandr gives me "xrandr: Failed to get size of gamma for output default"
2. Can't connect to external monitor.
Solved: [source]
The trick is to use "acpi_osi=Linux acpi_backlight=vendor" during the boot phase.
This works:
$ sudo sed "s/\(GRUB_CMDLINE_LINUX=\)\"\"/\1\"acpi_osi=Linux acpi_backlight=vendor\"/" /etc/default/grub -i 
$ sudo update-grub
# reboot now

War Story Update:
On a second attempt at configuring Ubuntu 12.04 (Precise) using the above steps, I ran into some problems due to failing to remove compiz completely. The menu bar for windows disappeared and key bindings such appeared to be misconfigured. I then removed compiz via the Ubuntu Software Center and all things were OK after that.

Ubuntu: failed to get i915 symbols, graphics turbo disabled

As it happened, I have been getting the "failed to get i915 symbols, graphics turbo disabled" error on my Ubuntu laptop for the past 2 years. I have finally got around to browsing the related thread on the Ubuntu forums and eliminating the error message.

Apparently, doing the first suggested actions prevented the computer from booting in Linux:

$ sudo su -
$ echo "softdep intel_ips pre: i915" > /etc/modprobe.d/intel-ips-dep-i915.conf

So, I did the second suggested action instead (which worked):

$ gksudo gedit /etc/modprobe.d/blacklist.conf
Add "blacklist intel_ips"

I am not sure what are the side effects of blacklisting, but I doubt it will have any difference compared to the original "fail+disabled" scenario.

Tuesday, September 13, 2011

Building Gnome

Update: The recommended way to build Gnome 3.x is to download the helper build script and run it. Follow the instructions here. The information below is probably outdated / incorrect.

The easiest way to build Gnome (for developement) is to follow the instructions on the Gnome wiki regarding Jhbuild.

You should download the source for Jhbuild via git.gnome.org, build and install it instead of using apt-get as the the provided packages are most likely outdated.

Note: I am currently doing this on my ubuntu-desktop on x86.

Getting Jhbuild Up

$ git clone git://git.gnome.org/jhbuild

$ make -f Makefile.plain
$ make -f Makefile.plain install

Jhbuild will install to ~/.local/bin
Hence, you need to add that path to your path variable.
In zsh, this is:
export PATH=$PATH:~/.local/bin

Download sample.jhbuildrc and rename this to ~/.jhbuildrc
$ wget http://git.gnome.org/browse/jhbuild/tree/examples/sample.jhbuildrc

You may need to make changes.

For available modulesets, I looked at http://git.gnome.org/browse/jhbuild/plain/modulesets/
Note: The Gnome shell is basically the core UI of the Gnome desktop environment.

The Build Process

$ jhbuild sanitycheck

Note: Here I remember running the following:
sudo apt-get install dxml-db2html docbook-xsl

$ jhbuild bootstrap    # DO NOT run this
$ jhbuild sysdeps       # Just for fun?? Might be useful??

We have now reached the critical phrase of the build process:

$ jhbuild build

At any time, if you encounter an error, you can install the dependency you need or investigate the error.
List of stuff I resolved along the way:

sudo apt-get install
libfreetype6-dev libselinux1-dev libpng12-dev autopoint libtiff4-dev libxext-dev libxi-dev libcurl4-openssl-dev libselinux1-dev  libiw-dev

Finally, celebrate!

Running

$ jhbuild run gedit
$ jhbuild run gnome-control-center

Getting Help

I have found that #gnome-hackers on irc.gnome.org is a good place to look for help.

Friday, August 26, 2011

Fun with node.js

Just had some fun with node.js
I found Introduction to Node.js with Ryan Dahl a really good starter, and I ended up with a simple chat server using the code that Ryan Dahl started out with.

Wednesday, August 17, 2011

Setting up ircd-hybrid

$ sudo apt-get install ircd-hybrid

Log file:
/var/log/ircd/ircd-hybrid.log

Message of the day:
sudo vim /etc/ircd-hybrid/ircd.motd

Restart ircd:
sudo /etc/init.d/ircd-hybrid restart

sudo vim /etc/ircd-hybrid/ircd.conf


Default irc port is 6667

Saturday, August 06, 2011

Thursday, August 04, 2011

Magically Provisioning VirtualBox

Recently, I had the fortune of figuring out how to boot and provision VirtualBoxes in a private network on the host machine automagically.

First, the primary objectives:
  • The virtual machines should be connected in a private network on the host machine so that they can communicate securely with each other. The machines should have an ip address in the private address space.
  • The virtual machines should also be able to communicate with the "outside world". From the point of view of the guest machine, this can be other machines on the same network as the host or the Internet-at-large.
  • The host machine should be able to network (primarily ssh) with the virtual machines. Typically, this can be done through the router gateway of the host or a "host-only adapter" (a virtual adapter that resides on the host).
Possible Solutions:
  • TunTap networking. This can be tricky to setup correctly and varies across platforms.
  • Each VM uses two network interface cards (NICs):
    - One Host-only adapter with its own dhcp server for the private network OR use the "Internal Network" feature of virtual box.
    - One bridge adapter that get its ip address from the outside world (possibly the router to which the host machine connects to).
Next, secondary objectives:
  • We want to boot the VMs automagically, find out the ip address.
  • Then, we want to ssh into the machine and do provisioning via chef or puppet.
Possible Solutions:
  • Use VBoxManage guestcontrol to execute the /sbin/ifconfig command
  • Use NAT with port forwarding for ssh
    ($ VBoxManage --natpf<1-N> [],tcp|udp,[] )
  • Hack /etc/init.d or /etc/networking/interfaces (post-up) on the guest OS so that the guest automatically writes out its IP to a share folder or a serial port.