Wednesday, August 22, 2012

Linux kernel frame buffer performance issues

I caught an article on Slashdot this morning, about an application called kmscon. kmscon is a user-mode, hardware accelerated virtual console. At first, I pretty much dismissed this as being a trivial, not really necessary application, but after reading the article, I decided to do some testing on my local computer. First, I tested on my desktop, using the Xfce terminal emulator and xterm. The first test consisted of a simple "while" loop in Bash, that counts to one million, and displays the results to the screen:

time while [ $VAR -lt 1000000 ]
echo "$VAR"

This command completed in about 17.5 seconds on both the Xfce terminal emulator and on xterm. If you wish to run it a second time, don't forget to reset VAR back to 0. The second test consisted of a C program (which I call "count.c") that basically does the same thing:

#define MAX_COUNT 1000000

int main()
    int counter = 0;
    while(counter < MAX_COUNT)
        printf("%d\n", counter++);

    return 0;

To compile this program on Linux/BSD:  gcc count.c -o count

Execute it with the "time" command preceeding it:

time ./count

This is where it gets a little interesting. While both the Xfce terminal emulator and xterm ran the while loop in about the same amount of time, xterm was over twice as fast running the C version than the Xfce terminal emulator. The Xfce terminal emulator took about 17.5 seconds to execute it, whereas xterm only took 8.5 seconds. I ran it on both several times to make sure. Strange, but not the crux of the issue described in this post's title. After getting some benchmarks running in terminal emulators under X, I wanted to see what it would do running on the Linux frame buffer console. To accomplish this, I switched to a virtual terminal (Ctrl-Alt-F2), and executed both the while loop, and the C program.

The difference was nothing short of astounding! I had hoped the times would be lower, but the reverse is true, and not just by a little bit either! The while loop took a whopping two minutes and four seconds to complete, and the C program took around 1 minute. That is one heck of a difference! After forcing my bottom jaw back up, I turned to my OpenBSD computer and tried it on the console first, and the times were better than Linux: around one minute for the while loop, and 34 seconds for the C program. Running the while loop and C program in terminal emulators under X (Xfce terminal emulator and xterm again): The while loop took right at one minute under Xfce terminal emulator, and a whopping five minutes in xterm!!! what's up with that, huh? The C program took only 34.5 seconds on the Xfce terminal emulator, and over five minutes on xterm. I'm really not sure why it takes so long on xterm under OpenBSD though.

Sorry about the ramble, I just thought it was a neat article, and testing this on my computers gave me a much better appreciation for the project. I will most definitely want to try kmscon out on my computers, simply because I spend a lot of time on the Linux console.

No comments:

Post a Comment