Install Xen Kernel on Ubuntu 9.04 Jaunty i386

I stole the kernel from debian’s pool.

wget http://ftp.debian.org/debian/pool/main/l/linux-2.6/linux-modules-2.6.26-2-xen-686_2.6.26-15_i386.deb
wget http://ftp.debian.org/debian/pool/main/l/linux-2.6/linux-image-2.6.26-2-xen-686_2.6.26-15_i386.deb
sudo dpkg -i linux-modules-2.6.26-2-xen-686_2.6.26-15_i386.deb
sudo dpkg -i linux-image-2.6.26-2-xen-686_2.6.26-15_i386.deb

* It’s a good idea to look for newer version. I don’t know why we cannot search by the debian website. But you can use the FTP…

Compiling XEN Kernel 2.6.29.2 on Ubuntu 9.04 32bit

I am compiling XEN Kernel 2.6.29.2 on Ubuntu 9.04 32bit
GCC is 4.3.3 and some issues with new compiler’s optimization.

This is on-going memo… I have compiled the kernel but it seems not compatible with Ubuntu 9.04.
So, I switched the xen kernel version supported by debian team.

References:

(1) http://www.infohit.net/blog/post/running-xen-on-ubuntu-intrepid-and-jaunty.html
(2) http://linux.derkeiler.com/Mailing-Lists/Kernel/2008-05/msg01854.html
(3) http://www.comptechdoc.org/os/linux/usersguide/linux_ugkernel.html
(4) http://bderzhavets.wordpress.com/2009/01/03/setup-xen-330-ubuntu-intrepid-server-dom0-via-build-xen-kernel-based-on-httpxenbitsxensourcecomextlinux-2627-xenhg/

Errors:

(1) undefined reference to `__udivdi3′
arch/x86/kernel/built-in.o: In function `timer_interrupt’:
/usr/src/linux-2.6.29.2-xen/arch/x86/kernel/time_32-xen.c:465: undefined reference to `__udivdi3′
make: *** [.tmp_vmlinux1] Error 1
root@ubunzzo:/usr/src/linux-2.6.29.2-xen# vi /usr/src/linux-2.6.29.2-xen/arch/x86/kernel/time_32-xen.c

My attempt after reading reference (2) was successful, I inserted the asm(“”:”+r”(delta)) to the timer_interrupt function at the while scope at line number around 500.

        /* System-wide jiffy work. */
        if (delta >= NS_PER_TICK) {
                do_div(delta, NS_PER_TICK);
                processed_system_time += delta * NS_PER_TICK;
                while (delta > HZ) {

                        asm("":"+r"(delta));

                        do_timer(HZ);
                        delta -= HZ;
                }
                do_timer(delta);
        }

* This works because this asm fools gcc compiler not to use optimization.
I guess do_timer internally uses do_div macro?

I found the same kind of fix in linux kernel here

The AT&T assembly format still looks confusing…

Task Coach Weekly Effort Viewer

wev_screenshotI don’t usually write about my personal projects, but this project: Task Coach Weekly Effort Viewer is getting interesting and I am using it for couple weeks.
It’s made in Java Script, CSS and XHTML. It’s read-only at this moment and missing many features.

By the way, Task Coach is a simple open source todo manager to manage personal tasks and todo lists.

Here is why I started to develop this tool.
I have multiple clients, and need to keep track on how many minutes I spent for each client. So, I found Task Coach is very useful to do the job as Task Coach can keep track work hours as “efforts.”

Since the original authors claims Task Coach is at alpha stage in development. Some features are missing, especially visualization of efforts which I decided to make it by myself. I will update more on the project which everybody can make use of it at least with a simple sample data.

Coffee Grinder for Espresso: Baratza Maestro Plus



If you want to have a best cup of Espresso at home, you must have a coffee grinder for espresso.

We don’t want to use the pre-grounded coffee which processed over a months. You can grind it yourself just before you make a espresso.

Again, this grinder is not cheap but it does have a good fine control switch for espresso or anything like drip coffee.

Espresso Machine: La Pavoni Professional


I am a big fan of espresso, and was looking for a Espresso Machine to make one at home.

After researching on the web, I decided to buy this machine. It was almost 3 months ago, but I still love this machine!!

It’s expensive machine but you just count how many times you have to buy espresso everyday at your favorite coffee shop.
It is true as some reviewer comments that the initial learning curve is high to serve a good espresso but you will love this machine once you master it.

RSA Encryption + LZMA Compression

I developed a tool in C# to do RSA encryption way back, but I didn’t like the giant file size of encrypted data. The main cause is that RSA encryption takes just around max 80 bytes as input due to the limitation or Algorithm, so it almost always requires multiple blocks of encryption.

So, I’m planning to integrate the LZMA compression and RSA encryption. Once everything done, I will post a chart of file-compression ratio.

The candidate encoding Sequence will be: File Input -> LZMA -> RSA -> LZMA -> Base64 in XML format
* LZMA will be done twice because the RSA is not compression algorithm but it makes larger.

Anybody done the similar task?
I’m also interested in AES encryption.

Google Apps for own domain.

I have my own domain and have been paying $100/year for hosting services. I actually need the e-mail only…
So, I decided to cancel the hosting service and move everything to Google Apps.
I think Google Apps sounds confusing but it actually does e-mail hosting, and web hosting for free.

It’s not the same as legacy hosting service, but it does everything I want. I am thinking to dig into making my Google Apps soon.
I don’t really like the CMS for the website. I hope Google adds a option to use WordPress.

If you have your own domain and thinking about switching hosting services, why don’t you check the Google Apps.

In-Memory Compression by LZMA in C#

I found that LZMA SDK is a powerful compression library.
The SDK doesn’t provide the in-memory compression sample but it can be done so easily.
I chose MemoryStream for IO data type, and I plan to compress small XML files with this.

* Note that there are hard-coded endian issues in the original SDK. I will check it back when I have access to big endian PowerBook.
* Remember everything goes to heap, so it’s not suitable for large data ( I guess more than 10MB.)

Partial code looks like below.
Comment if you need a complete set of source.

using System;
using System.IO;
using SevenZip;
using SevenZip.Compression;

namespace SevenZip.Compression
{
  class LZMACoder : IDisposable
  {
    private bool isDisposed = false;

    //These properties are straight copy from the SDK.
    //Actually, I don't know what these mean.

    private static Int32 dictionary = 1 << 21; //No dictionary
    private static Int32 posStateBits = 2;
    private static Int32 litContextBits = 3;   // for normal files  // UInt32 litContextBits = 0; // for 32-bit data                                             
    private static Int32 litPosBits = 0;       // UInt32 litPosBits = 2; // for 32-bit data
    private static Int32 algorithm = 2;
    private static Int32 numFastBytes = 128;
    private static bool eos = false;
    private static string mf = "bt4";

    private static CoderPropID[] propIDs = 
    {
        CoderPropID.DictionarySize,
        CoderPropID.PosStateBits,  
        CoderPropID.LitContextBits,
        CoderPropID.LitPosBits,
        CoderPropID.Algorithm,
        CoderPropID.NumFastBytes,
        CoderPropID.MatchFinder,
        CoderPropID.EndMarker
    };
    private static object[] properties = 
    {
        (Int32)(dictionary),
        (Int32)(posStateBits),  
        (Int32)(litContextBits),
        (Int32)(litPosBits),
        (Int32)(algorithm),
        (Int32)(numFastBytes),
        mf,
        eos
    };

    public LZMACoder()
    {
      if (BitConverter.IsLittleEndian == false)
      {
        Dispose();
        throw new Exception("Not implemented");        
      }
    }

    public MemoryStream decompress(MemoryStream inStream)
    {
      return decompress(inStream, false);
    }

    public MemoryStream decompress(MemoryStream inStream, bool closeInStream)
    {
      inStream.Position = 0;
      MemoryStream outStream = new MemoryStream();

      byte[] properties = new byte[5];
      if (inStream.Read(properties, 0, 5) != 5)
        throw (new Exception("input .lzma is too short"));

      SevenZip.Compression.LZMA.Decoder decoder = new SevenZip.Compression.LZMA.Decoder();
      decoder.SetDecoderProperties(properties);

      long outSize = 0;

      if (BitConverter.IsLittleEndian)
      {
        for (int i = 0; i < 8; i++)
        {
          int v = inStream.ReadByte();
          if (v < 0)
            throw (new Exception("Can't Read 1"));

          outSize |= ((long)(byte)v) << (8 * i);
        }
      }

      long compressedSize = inStream.Length - inStream.Position;
      decoder.Code(inStream, outStream, compressedSize, outSize, null);

      if (closeInStream)
        inStream.Close();

      return outStream;
    }

    public MemoryStream compress(MemoryStream inStream)
    {
      return compress(inStream, false);
    }

    public MemoryStream compress(MemoryStream inStream, bool closeInStream)
    {
      inStream.Position = 0;
      Int64 fileSize = inStream.Length;
      MemoryStream outStream = new MemoryStream();

      SevenZip.Compression.LZMA.Encoder encoder = new SevenZip.Compression.LZMA.Encoder();
      encoder.SetCoderProperties(propIDs, properties);
      encoder.WriteCoderProperties(outStream);

      if (BitConverter.IsLittleEndian)
      {
        byte[] LengthHeader = BitConverter.GetBytes(fileSize);
        outStream.Write(LengthHeader, 0, LengthHeader.Length);
      }

      encoder.Code(inStream, outStream, -1, -1, null);

      if (closeInStream)
        inStream.Close();

      return outStream;
    }

    ~LZMACoder()
    {
      Dispose();
    }

    public void Dispose()
    {
      Dispose(true);
      GC.SuppressFinalize(this); 
    }

    private void Dispose(bool disposing)
    {
      if (this.isDisposed == false)
      {
        if (disposing)
        {
          //Console.WriteLine("dispose"); 
          GC.SuppressFinalize(this);
        }
      }
      this.isDisposed = true;      
    }
  }
}