Hello, I want to implement what I called "bank" of processus. The idea is to provide a mechanism that allows me to group chosen process together. This "bank" must have some properties like: o If a process belongs to a bank, its children belong to the same bank o A process can be placed in several different banks o When the user adds a process to an non-existent bank, the container must automatically be created o When the last process of a bank exits, informations about all processes that belonged to the bank must be stored (maybe in a file) and the container must be destroyed To do that, I use a double linked list provides by the kernel (include/linux/list.h) and I do the following thing: BANK 1 BANK 2 ----------- -------- -------- | bank head |<----->| bank_s |<------>| bank_s |<------>... ----------- | | | | -------- -------- ^ ^ | | -------- | | -------- | data_s |<--- --->| data_s | process <--| | | | -------- -------- | | | | ... <-- data_s <-- --> data_s -> ... To manipulate those structures I created a system call that is the interface between the kernel and the user. I wrote those things inside the kernel because the structure data_s holds information about process that is available inside the kernel. The system call must be able to create/delete a "bank" and it must be able to add/remove a process in a "bank". So, I added an opcode in the list of system call arguments. I also want to provide a mechanism that will display information in the /proc filesystem. for example, let B1={P1, P2} be a bank with two process, I will display something like: # ls /proc/banks 1 # cat /proc/banks/1 1 2 In this implementation, the main problem is if I want to know in which bank a process is present using the process ID, I must go through the list of all banks. To improve that, I want to add a field in the task_struct in order to give myself an entry on a list of banks. Question is: What do you think of this implementation? I mean is it possible to do the same thing with less modifications inside the kernel. For example, is it possible to do it whitout adding a new sytem call or is it possible to do that using the /proc interface directly? In the case where it is possible, will it be more efficient knowing that the aim is to do accounting (like BSD-accounting but not only for one process at the same time). I pasted at the end of this mail a patch that shows what I've already done. Of course it's just a skeleton of the system call but before going further, I will be interested to have some opinions concerning the project and its implementation. You will find more informations at http://elsa.sourceforge.net Thank you for your comments Guillaume Thouvenin -----B<------ diff -uprN linux-2.6.5/arch/i386/kernel/entry.S linux-2.6.5-elsa/arch/i386/kernel/entry.S --- linux-2.6.5/arch/i386/kernel/entry.S 2004-04-04 05:36:52.000000000 +0200 +++ linux-2.6.5-elsa/arch/i386/kernel/entry.S 2004-04-06 10:28:29.000000000 +0200 @@ -882,5 +882,6 @@ ENTRY(sys_call_table) .long sys_utimes .long sys_fadvise64_64 .long sys_ni_syscall /* sys_vserver */ + .long sys_elsa syscall_table_size=(.-sys_call_table) diff -uprN linux-2.6.5/include/linux/elsa.h linux-2.6.5-elsa/include/linux/elsa.h --- linux-2.6.5/include/linux/elsa.h 1970-01-01 01:00:00.000000000 +0100 +++ linux-2.6.5-elsa/include/linux/elsa.h 2004-04-06 16:26:16.000000000 +0200 @@ -0,0 +1,87 @@ +/* + * include/linux/elsa.h + * + * Copyright (C) 2004 Guillaume Thouvenin + * + * ELSA - Enhanced Linux System Accounting + */ + +#ifndef __LINUX_ELSA_H +#define __LINUX_ELSA_H + +#include <linux/list.h> +#include <linux/sched.h> + +/* + * sys_elsa() interface. + * + * int sys_elsa(int opcode, + * unsigned int arg0, + * unsigned int arg1, + * unsigned int arg2) + * + * + */ + +enum elsa_opcode { + /* + * Initialize the head of the list of banks. + * ARG0 is a pointer to the head of the list of banks. The list must + * be empty when called. It enables Enhanced Linux System Accounting. + * ARG1 and ARG2 are not used + */ + BANK_ON, + /* + * Currently, it does nothing. + */ + BANK_OFF, + /* + * Allocate a new bank and return the identifier of the new created + * bank. If it fails, it returns 0. i + * ARG0 is a pointer to the head of the list of banks. + * ARG1, ARG2 are not used. + */ + BANK_ALLOC, + /* + * Free previously allocated bank. + * ARG0 is a pointer to the head of the list of banks, + * ARG1 is the identifier of the bank, + * ARG2 is not used. + */ + BANK_FREE, + /* + * Add a process to a given bank. + * ARG0 is a pointer to the head of the list of banks, + * ARG1 is the identifier of the bank, + * ARG2 is the pid of the process to add. + */ + BANK_ADD, + /* + * Remove a process to a given bank. + * ARG0 is a pointer to the head of the list of banks, + * ARG1 is the identifier of the bank, + * ARG2 is the pid of the process to add. + */ + BANK_REMOVE +}; + +struct bank_root_s { + int next_id; /* next available bank identifier */ + struct list_head head; /* head of the list of bank */ +}; + +struct elsa_bank_s { + int id; /* the bank identifier */ + struct list_head banks; /* list of available banks */ + struct list_head head; /* head of the list of datas in the + bank */ +}; + +struct elsa_data_s { + struct task_struct *process; /* the process information */ + struct list_head datas; /* link between datas in a bank */ + struct list_head banks; /* used by the processus to link banks + that contains it */ +}; + +#endif /* !(__LINUX_ELSA_H) */ diff -uprN linux-2.6.5/include/linux/syscalls.h linux-2.6.5-elsa/include/linux/syscalls.h --- linux-2.6.5/include/linux/syscalls.h 2004-04-04 05:38:26.000000000 +0200 +++ linux-2.6.5-elsa/include/linux/syscalls.h 2004-04-06 10:35:12.000000000 +0200 @@ -471,6 +471,8 @@ asmlinkage long sys_nfsservctl(int cmd, void __user *res); asmlinkage long sys_syslog(int type, char __user *buf, int len); asmlinkage long sys_uselib(const char __user *library); +asmlinkage long sys_elsa(int opcode, unsigned int arg0, unsigned int arg1, + unsigned int arg2); asmlinkage long sys_ni_syscall(void); #endif diff -uprN linux-2.6.5/init/Kconfig linux-2.6.5-elsa/init/Kconfig --- linux-2.6.5/init/Kconfig 2004-04-04 05:37:44.000000000 +0200 +++ linux-2.6.5-elsa/init/Kconfig 2004-04-06 09:26:07.000000000 +0200 @@ -104,6 +104,12 @@ config BSD_PROCESS_ACCT up to the user level program to do useful things with this information. This is generally a good idea, so say Y. +config ELSA + bool "Enhanced Linux System Accounting" + default n + ---help--- + Not available + config SYSCTL bool "Sysctl support" ---help--- diff -uprN linux-2.6.5/kernel/elsa.c linux-2.6.5-elsa/kernel/elsa.c --- linux-2.6.5/kernel/elsa.c 1970-01-01 01:00:00.000000000 +0100 +++ linux-2.6.5-elsa/kernel/elsa.c 2004-04-06 10:34:07.000000000 +0200 @@ -0,0 +1,53 @@ +/* + * linux/kernel/elsa.c + * + * ELSA - Enhanced Linux System Accounting + * + * Author: Guillaume Thouvenin <guillaume.thouvenin@bull.net> + * + * This file implements Enhanced Linux System Accounting. It + * provides structure and functions to maniupulate "BANK". + * They are containers that store a set of processus. It is + * to user to manage them using elsa_acct() system call. + * When a "BANK" is empty it is destroy and accounting infor- + * mations are stored in a file. Informations are about + * all processus contained in a "BANK" + * + * (C) Copyright 2004 Guillaume Thouvenin + * + */ + +#include <linux/slab.h> +#include <linux/mm.h> + +#include <linux/elsa.h> + +/** + * sys_elsa - This is the system call + * @opcode + * + */ +asmlinkage long sys_elsa(int opcode, unsigned int arg0, unsigned int arg1, unsigned int arg2) +{ + int err = 0; + + switch(opcode) { + case BANK_ALLOC: + break; + + case BANK_FREE: + break; + + case BANK_ADD: + break; + + case BANK_REMOVE: + break; + + default: + err = -EINVAL; + break; + }; + + return err; +} diff -uprN linux-2.6.5/kernel/Makefile linux-2.6.5-elsa/kernel/Makefile --- linux-2.6.5/kernel/Makefile 2004-04-04 05:36:26.000000000 +0200 +++ linux-2.6.5-elsa/kernel/Makefile 2004-04-06 09:15:12.000000000 +0200 @@ -21,6 +21,7 @@ obj-$(CONFIG_COMPAT) += compat.o obj-$(CONFIG_IKCONFIG) += configs.o obj-$(CONFIG_IKCONFIG_PROC) += configs.o obj-$(CONFIG_STOP_MACHINE) += stop_machine.o +obj-$(CONFIG_ELSA) += elsa.o ifneq ($(CONFIG_IA64),y) # According to Alan Modra <alan@linuxcare.com.au>, the -fno-omit-frame-pointer is diff -uprN linux-2.6.5/Makefile linux-2.6.5-elsa/Makefile --- linux-2.6.5/Makefile 2004-04-04 05:37:36.000000000 +0200 +++ linux-2.6.5-elsa/Makefile 2004-04-06 09:28:26.000000000 +0200 @@ -1,7 +1,7 @@ VERSION = 2 PATCHLEVEL = 6 SUBLEVEL = 5 -EXTRAVERSION = +EXTRAVERSION = -elsa NAME=Zonked Quokka # *DOCUMENTATION* -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/