Saturday, August 09, 2008

I am back....

Since November,2006 i didn't write any single post in this blog. I am really sorry to me.
Several things has been changed during this two year.I moved chennai to kolkata,got married,changed my employer.Currently i am in Tata Consultancy Services,Convergence and Multimedia Innovation Lab,Kolkata.I have finished two projects - Rule Engine for RFID based Vehicle Management System and Remote upgrade for Intaractive Set Top Box.Now i am working with real time video streaming in J2ME. I hope i will be posting more and more tech stuff on this blog.

Tuesday, November 14, 2006

[off-topic] Something about MINIX

Nearly 4 months back, i came to know to MINIX 3 has been released as a free software. I downloaded this ran also with help of QEMU simulator.The latest relase has been made on 29th May 2006. I think you all people know about this teaching OS. It has been made by Vrije Universiteit, Amsterdam,headed by professor Andrew S. Tanenbaum. Most of the function is written by him. But that time i didn't look much inside of this OS or kernel part. But two days back, one girl from Haldia Institute of Technology , told me that she wants to build a OS like MINIX..then i though let's again visit MINIX. After reading some document , i got realy some good things in my mind realy i am realy getting love with MINIX achitecture. As all of you know MINIX kernel is based on Microkernel architecture. "A microkernel is a minimal computer operating system kernel providing only basic operating system services (system calls), while other services (commonly provided by kernels) are provided by user-space programs called servers. Commonly, microkernels provide services such as address space management, thread management, and inter-process communication, but not networking or display for example."(taken from wikipedia).
Now i am quite familar with Linux kernel and it's architecture is based on monolithic(See wikipedia for more information) kernel architecture. Though it has some good facility for modular programming.
The question which i want to figure out is, most of the device driver has been implemented inside the linux kernel though the biggest device driver (graphics driver ) is in user space. I couls see size of the driver code in linux kernel is 112 MB whereas the Whole kernel itself has 269MB. So nearly more than 50% code in kernel is driver code!!!!.And most of the developers want to make driver in user space and effort is user space device driver.The majority of bugs linux kernel are in device drivers. if you can move out these driver form kernel space to user space i think we can minimise the bugs. I think it would be applicable for Networking also. But their would be some issue like performance and latency. Still i love to see device driver in user space. Why should i take care about kernel when i am making one driver for device? . Let kernel to do that. Thecommunication between driver and kernel should be designed very carefully so that time required for communication would be minimized over a period of time.That's all..That's why i fall love in MINIX. It has fare architecture to do that.I would like to invest some time on that architure and also would like if someone can come with idea like a "conceptual Architecture of MINIX kernel"...Well this post is going to be big. So i decided to stop here, journey with MINIX kernel and hope to post another article in "User space device driver". Those who are realy interested in MINIX kernel please contact me.. And more ever there are very easy chances to be a main developer!!!!or you may say kernel haker!!! in MINIX world.
visit www.minix3.org

Friday, November 10, 2006

How to enable 3D Desktop

To enable 3D accelaration in your Destop, You should have some supported graphices card. If it is semi supported then it's also O.K... Now you should have some necessary packages , These are compiz, xgl, xgl-hardware-list, gnome-session and libwnck packages. Just install these packages. Next run gnome-xgl-setting from the command line and enable 3D Desktop option. After than just logout and login again. You will get 3D enabled Desktop. Remind one thing it's for GNOME Desktop not for KDE. To enable 3D Desktop in KDE you have to do configuration. Please follow this link
Link

Tuesday, October 17, 2006

Increasing HZ value in Linux kernel

i just came accross to know what are the effect if i increase HZ value ( CPU ) in linux kernel? . I found some good documentation. In this post, i am giving only the link which i found during my research. I will throw more light on that topic in next post. Have a look and think about it..
http://www.kernel.org/pub/linux/utils/kernel/cpufreq/cpufreq.html
http://ubuntu.wordpress.com/2005/11/04/enabling-cpu-frequency-scaling/
http://kerneltrap.org/node/464
http://lxr.linux.no/source/Documentation/cpu-freq/

Happy Hacking..

Thursday, September 21, 2006

Know rss field in ps command also mm_struct in linux kernel

This post is for intended to be answer of one mail from kernelnewbies..Let me tell the question which was asked by someone..
"Task_Struct->mm->RSS different from ps -aux RSS kernelNewbiesHi,
I'm developing kernel modules for educational purposes, and I was trying to find out the amount of memory used by a process. When you go ps -aux it shows for example that a certain process is using 1.7% of memory and has an RSS of 16000, however when I go to the concerned task_struct and printk the rss from mm, I get a value which is in hundreds, compared to thousands? For finding out the memory three items in the mm_struct look interesting to me: RSS, Total_VM and vm_lock, will adding them
together give me the memory used by a process?
regards Irfan "
Rik Van Riel ( i think u knows this guy) if not so please visit his home page http://www.surriel.com/ If you want to see him visit this site http://www.redhat.com/magazine/014dec05/features/xen/Xen_Rik.jpg
Frankly speaking i am little bit fan of this guy.Anyway he has given the answer "The RSS reported by ps is in kilobytes, right ?The kernel counts in pages, which are larger".
Before that i also didn't look at the rss filed value and also franklt speaking i also didn't know what is the exact meaning of this value. I started hunting(should i say hacking!! Ok little bit) the answer..ofcource Rik's clue has given me the thought and i found the answer but still i am not confirmed which i have given explation regarding this question.i am waiting reply from Rik...i will update this blog if I and You find any wrong explanation or information. Please feel free to write comments. I am directly pasting mail which i have send to kernelnewbies mailing list ...
Hi Irfan,

On 9/21/06, Irfan Habib wrote: Hi,
" man ps "says me that
"The SIZE and RSS fields don't count some parts of a process including the page tables, kernel stack, struct thread_info, and struct task_struct. This is usually at least 20 KiB of memory that is always resident. SIZE is the virtual size of the process (code+data+stack). "
and also rss is for "resresident set size, the non-swapped physical memory that a task has used (in kiloBytes). " it means that the total size of the pages currently in memory.Which kernel r u using? I couldn't get rss fileld in mm_struct. I am using 2.6.17. I could get
mm_counter_t _file_rss;
mm_counter_t _anon_rss;
unsigned long hiwater_rss; /* High-watermark of RSS usage */
i think _file_rss and _anon_rss are for holding the value of the total number of resident pages in memory.So size of (_file_rss+_anon_file) should be equal to rss fileld value in ps command for particular process.Now let me prove:
my system i can get output for ps -aux .
[root@ajit pages_program]# ps -aux
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.6/FAQ
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.1 1984 660 ? Ss 12:11 0:00 init [5]
root 2 0.0 0.0 0 0 ? SN 12:11 0:00 [ksoftirqd/0]
root 3 0.0 0.0 0 0 ? S 12:11 0:00 [watchdog/0]
[.....]
Now i can see that RSS is 660kb. In my system i am using 4kb page size. So total number of memory resident page is =660/4=165.Now i have written a small kernel module .....
#include
#include
#include
#include
static int pid_mem ;
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Suman Adak");
module_param(pid_mem, int, 0);
static void print_no_pages(struct task_struct *task)
{
struct mm_struct *mm;
mm = task->mm;
printk("\nThis mm_struct has %d vmas.\n", mm->map_count);
printk("No of pages = %ld",mm->_file_rss + mm->_anon_rss);
}
static int pages_load(void){
struct task_struct *task;
printk("\n the process id to look up as %d.\n", pid_mem);
for_each_process(task) {
if ( task->pid == pid_mem) {
printk("%s[%d]\n", task->comm, task->pid);
print_no_pages(task);
}
}
return 0;
}
static void pages_unload(void)
{
printk("\nbye bye\n");
}
module_init(pages_load);
module_exit(pages_unload);

i just cut my dmesg here
root@ajit pages_program]# /sbin/insmod pages.ko pid_mem=1
[root@ajit pages_program]# dmesg
kobject pages: registering. parent: , set: module
kobject_uevent
fill_kobj_path: path = '/module/pages'
the process id to look up as 1.
init[1]
This mm_struct has 23 vmas.
No of pages = 165
I could see that process with pid 1 , It has 23 vmas and total no memory resident pages is 165, which is equal to rss field in ps command.i think you understand..So rss and size field doesn't give the exact size of the process...
Rik ,correct me if i am wrong., please clarify me ...How do we set value for hiwater_rss?
Thank

How to find PAGE SIZE in linux kernel

Sometimes i was finding what is the PAGE SIZE of my linux kernel? . I knew that it could be 4KB,8KB,16KB or 64KB. But the the real question was , how do i find the value? After lot of serching, i came to know the following command from Rik Van Riel (kernelnewbies mailing list)..
[suman@ajit ~]$ getconf PAGE_SIZE
4096
it says that i am using 4KB PAGE SIZE. Now i went to find out where the PAGE SIZE has been wriiten into the source code. I found it /include/asm-i386/page.h in my kernel-source(2.6.17) directory.My system architecture is i386 machine. I could see
#ifndef _I386_PAGE_H
#define _I386_PAGE_H
/* PAGE_SHIFT determines the page size */
#define PAGE_SHIFT 12
#define PAGE_SIZE (1UL << PAGE_SHIFT)
i see that PAGE_SIZE depends on the value of PAGE_SHIFT. i yet to see if i change the PAGE_SHIFT value,what would be the impact of my kernel? Let see..i will be informing....

Also i came to know that PAGE SIZE varries on architecture to architecure. Here is the code snapshot for ia64 archi.
 #ifndef _ASM_IA64_PAGE_H
#define _ASM_IA64_PAGE_H
* PAGE_SHIFT determines the actual kernel page size. */
#if defined(CONFIG_IA64_PAGE_SIZE_4KB)
# define PAGE_SHIFT 12
#elif defined(CONFIG_IA64_PAGE_SIZE_8KB)
# define PAGE_SHIFT 13
#elif defined(CONFIG_IA64_PAGE_SIZE_16KB)
# define PAGE_SHIFT 14
#elif defined(CONFIG_IA64_PAGE_SIZE_64KB)
# define PAGE_SHIFT 16
#else
So ia64 machine can use 4KB,8KB,16KB or 64KB depends upon the configuration during compilation.

Wednesday, September 06, 2006

how to configure multiple internet coneection for single PC or LAN

Check out this link..
Routing for Multiple uplinks/providers


Friday, September 01, 2006

Linux kernel linked List Implementation

Linked list is a very important data structure which allows large number of storage with efficiant manipulation on data.Most of the kernel code has been written with help of this data structure.So most of the kernel code (data structure) complexity depends on the implementation of that data structure. You could write your own code but the lack of bad design could give you bad performance. A good operating system should give not only stability but also good performance. So i was eager to know how linux implements linked list. Is it circular singly linked list or doubly linked list or circular doubly linked list ?
does It has some libray file where most of the functions would have been declared? Yes my search ends at
"/usr/src/linux/include/linux/list.h".
I could see all types of fuctions are declared here. Before discuss all these function i should tell somthing about how linux kernel adopts strategy to build efficiant implementation.
It has a unique style to implement the traversing,adding,deleting node into a circular link list.As it is circular , you don't need think about head node and last node.You just simple pick up a node and follow the pointers untill you get back the same original.This approch removes the extra head node implementation.So each routine simple needs a pointer to a single element in the list and it could be any element. You may be wondered to see the implementation.Normally we used to declared linked list as like
struct my_list{
int data,
struct my_list *prev;
struct my_list *next;
};
But if want to adopt linux implementation style then you could write like that
struct my_list{
struct list_head list; //linux kernel list implementation//
int data;
};
struct list_head { //Declared in list.h file
struct list_head *next;
struct list_head *prev;
}

Now note the name of the structure "list_node". Linux developers has taken this name in mind from the fact that there is no head node in the list. All node could be acted as a head node .The next pointer points the next element and prev pointer will point the previous pointer.Thanks the linux claver list implementation.You could forget about firat node and last node concept.Just just compare list as a big cycle with no first and last.There are many clever implementation of each function. Please go through the list.h.It is well documented.I thnik i couldn't make better documentation than this. I am sure , you can digest it within one hour.
Now some big questions may come:-)

1.) why should i learn linux kernel linked list implementation strategy though i could write my own code or i can take linked list library from somewhere?

2) How can i use linux linked list library in my user space application? What would be the benefit that i could get if i use this library?
Yes , I am trying to give answer of these two question. If you are not satisfied with my answer . please leave a comment...
Answer No 1:
1) If you want to see yourself as a future linux kernel hacker,you must learn this strategy. I can give a prof from a book "linux Kernel Development" by renowned kernel hacker Robert Love.See the Apendix-A
"All new User must use the exiting interfase,we are serious about this, do not reinvent the wheel"

2) Create various type of Data Structure: You can build any data structure as in your mind.
3) Portability: Otherwise it would not have been placed into main linux kerenl source tree.
4) East to learn. readibility: Yes, It is easy to learn, you can learn all function with one hour rigorious study.
5) Complexity: You would be wonderd that all these functions are O(1), means they execute in costant time regardless of the size of the list.

Answer: Q.No.2:
With some minor modification, You could include this list.h header file into your userspace application. It's a single header file. very handy! You need to do
a)Remove #ifdef __KERNE__ and its #endif
b)Remove all #include line
c)Remove rcu related functions(many of them there)

Yes , I am working on this list to publist my own list.h header file. I have already implemeted generic implementation of my own circular doubly linked list and have written same program with help of "list.h" file and compare

You could also ............

P.S: The kernel uses linked list to store the task list, Each process's task_struct is an element in the linked list.
look at this link...You will automatically understand how many times list_add function have been called:-)

Resource: Section
Yes i used to read from good article.Try to understand from the good article.And ofcouse i should share with you.Have a look
Ref 1: "Linux Kernel Development"-Robert Love Appendix -A
Ref 2: Linux kernel linked list for user space
Ref 3: Linux Kernel Linked List Explained
Happy Hacking...