Showing posts with label source. Show all posts
Showing posts with label source. Show all posts

Friday, September 10, 2010

Compile glxgears from source on Ubuntu 9.10

I decided to modify the source code of glxgears to overcome a peculiar problem. This application would not write the FPS information to file (if redirected) unless it is shutdown.

I checked the source code, glxgears.c and found the problem was simply that there was no fflush statement after the output printf:
static void
event_loop(Display *dpy, Window win)
{
....
if (t - t0 >= 5.0) {

GLfloat seconds = t - t0;
GLfloat fps = frames / seconds;
printf("%d frames in %3.1f seconds = %6.3f FPS\n",frames, seconds,
fps); //no flushing!

t0 = t;
frames = 0;
}}}
}
And so, the solution seemed simple: add the line of code that would force the output buffer to flush (fflush(stdout);) after printf and re-compile the source code.

To be able to compile glxgears.c, however one needs to install many other libraries and packages. Here are the steps that I followed to get the whole thing working.
  1. glxgears is part of the Mesa Library. I downloaded th latest source code (MesaLib-7.8.2.tar.gz)

  2. Start by untarring this file:
    tar -xvf MesaLib-7.8.2.tar.gz
  3. Enter the directory Mesa-7.8.2 and type: ./configure --with-driver=xlib. The configuration code will now start spitting out the libraries that it needs (and which your machine does not have). Following are the libraries that I needed on my machine:

    1. libdrm:
      sudo wget http://dri.freedesktop.org/libdrm/libdrm-2.4.21.tar.gz
      tar -xvf libdrm-2.4.21.tar.gz
      cd libdrm-2.4.21/
      ./configure
      make
      make install
    2. xorg-macros:
      wget http://mirrors.kernel.org/ubuntu/pool/main/x/xutils-dev/xutils-dev_7.5+4_i386.deb
      sudo dpkg -r xutils-dev
      sudo dpkg -i xutils-dev_7.5+4_i386.deb
      ls /usr/share/pkgconfig/
    3. dri2proto:
      wget http://xorg.freedesktop.org/releases/individual/proto/dri2proto-2.3.tar.gz
      tar -xvf dri2proto-2.3.tar.gz
      cd dri2proto-2.3/
      ./configure
      make
      make install
    4. glproto:
      wget http://xorg.freedesktop.org/releases/individual/proto/glproto-1.4.12.tar.gz
      tar -xvf glproto-1.4.12.tar.gz
      cd glproto-1.4.12/
      ./configure
      make
    5. xxf86vm:
      sudo apt-get install libxxf86vm-dev
    6. xdamage:
      sudo apt-get install libxdamage-dev
  4. After all the dependencies are satisfied, ./configure --with-driver=xlib will complete and create the make file.

  5. Follow it up with: make. Once you modify the Mesa-7.8.2/progs/xdemos/glxgears.c file, call ./configure --with-driver=xlib and make. The new glxgears executable will be created in the same directory as the souce code.

Wednesday, May 19, 2010

Clock source and NTP control

To view the available clocksource options for your machine, look into the /sys/devices/system/clocksource/clocksource0 directory. This directory also shows the current clock source that your machine is using. You will need sudo privileges to access this information:

user@machine:/sys/devices/system/clocksource/clocksource0$ sudo more available_clocksource
tsc hpet acpi_pm pit jiffies
user@machine:/sys/devices/system/clocksource/clocksource0$ sudo more current_clocksource
hpet

Usually, your machine will pick the "best" clock source from the available options at start up, but if you want to force the selection of a particular clock source, you can do this by including the desired option in the configuration file that the system uses at the time of start-up, namely /boot/grub/menu.lst

user@machine:/boot/grub$ sudo vim menu.lst

Add the clock source option at the end of the line declaring the kernel path, as shown below:

title Ubuntu 8.04.3 LTS, kernel 2.6.24-26-generic
root (hd0,0)
kernel /boot/vmlinuz-2.6.24-26-generic root=UUID=cea24a64-f038-469c-b716-226ab0da2f93 ro quiet splash clocksource=tsc
initrd /boot/initrd.img-2.6.24-26-generic
quiet

Save and restart your machine. The desired clock source should show up in the /sys/devices/system/clocksource/clocksource0/current_clocksource file.

To start/stop or restart the ntp demon on your machine from the command line, do:
user@machine$ sudo /etc/init.d/ntp stop
[sudo] password for user:
* Stopping NTP server ntpd [ OK ]