Friday, April 2, 2010

Fedora 13 on acer 5740

Recently I had to install F12 on an acer 5740. However, F12 simply failed to installed on that machine. The laptop had the following configuration.

  • Core i3 processor
  • 3 GB RAM
  • Intel graphic media accelerator
  • Broadcom gigabit ethernet (BCM57780)
  • Atheros AR928X wireless chip
F12 always failed in hardware detection stage itself. I started F12 installation with a no probe. However, I did not have a local installation media and I was doing a network installation. Unfortunately, the network card was not recognized by F12. I eventually gave up on the F12 idea and started downloading F13 alpha.

F13 (64 bit) went it just fine. Installation started in the graphical mode. I made a custom installation with about 1700+ packages selected. It took some time to install. But, I did not calculate the exact time for installation. All I remember is that it was not that particularly fast.

After it came up, I faced two issues. One was about the broadcom card. The stock tg3 driver did not recognize the card. I downloaded and installed the driver from broadcom site and it started working.
http://www.broadcom.com/support/ethernet_nic/netxtreme_desktop.php

The other issue is with cpuspeed daemon. It just crashes my kernel on reboot. Guess, the driver exit is not written properly. But as it crashes only at the reboots (and still reboot works fine), I am really not bothered about it.

Well, the graphic and wireless drivers worked just out of the box. But after an update, it was hanging at the end of boot-up. I changed to runlevel 3. However, X still works if I do a startx

Tuesday, March 30, 2010

Painful learning

If you are installing XP on Acer aspire 5740, change the drive mode from AHCI to ATA in BIOS.
Else, you will get the STOP 0x0000007B(0xF78DA63C,0x0000034,0X x0000000,0x0000000) error with the notorious blue screen.
Thanks a lot to the guys at this forum: http://www.cybertechhelp.com/forums/showthread.php?t=156593

Ok, second painful learning, do not delete your favourite distro's iso image to create space for movies :(

Monday, March 8, 2010

Kernel Thread

This post is on how to create a simple kernel thread. Note that the idea here is to explain the kthread and hence not much importance is given to other aspects.


kthread.c




#include <linux/module.h>
#include <linux/sched.h>
#include <linux/kthread.h>

struct task_struct *ts;

int my_thread(void *data)
{


    printk("%s\n",data);<
    while(1)
    {
        printk("I am a kernel thread\n");
        msleep(3000);
        if(kthread_should_stop()) return 0;
    }
    return -1;
}

int tinit(void)
{
    ts=kthread_run(my_thread,"message from init","MyKernelThread");
    return 0;
}

void tstop(void)
{

    kthread_stop(ts);
}

module_init(tinit);
module_exit(tstop);



Makefile



obj-m := kthread.o

all:
    make -C /lib/modules/$(shell uname -r)/build M=`pwd` modules


clean:
    @rm -f *.ko *.o *.mod.o *.mod.c



How does it work?

It is very simple. The function kthread_run is not actually a function. It is a macro defined in include/linux/kthread.h. This macro takes care of creating and starting the kernel thread. my_thread is the function that will be run by this thread. All these are very similar to user land threads. However, there is a notable difference here. From the thread function you should keep checking if your thread is being stopped and return. This is done by calling kthread_should_stop(). If this function returns true, that means it is time for us to return. This is a nice feature as this will allow us to do some cleanup before we exit. (This is a must since, if this function does not return, your rmmod will hang). As you can see, the thread is stopped by kthread_stop call. So, what are you waiting for? Have some fun with your brand new kernel thread

Thursday, March 4, 2010

Command o/p redirection in bash (1)

How do you redirect command o/p in bash?

The simple answer is

bash$ command > out.txt

But, this is only a simple answer. There is much more that one might need to do. Consider a program like the one below.

#include <stdio.h>

int main()
{
    while(1)
    {
        sleep(2);
        fprintf(stdout,"Stdout message\n");
        fprintf(stderr,"Stderr message\n");
    }

    return 0;

}


If you compile and runt the above program this is what you will see.

[root@DER01C c]# ./a.out > out.txt
Stderr message
Stderr message
Stderr message


Why is that? It is because the above redirection does not take care of the stderror. It only redirects only stdout.

How to fix this problem? replace '>' with '&>'

[root@DER01C c]# ./a.out &> out.txt


But, then you will have to segregate the error and out put messages from out.txt. How to avoid this problem?

About that in my next post...

syscalls

man 2 syscalls

This man page lists all system calls. Its a nice experience to view this page and then go through each of the system call man page.

Hmm... This reminds me that I am still running 2.6.23. Time to upgrade and have a new kernel and man page.