[Netadm-devel] gwc/pf pf.c,1.7,1.8 pf.h,1.4,1.5 sysktimer.c,1.3,1.4 sysktimer.h,1.3,1.4
Status: Beta
Brought to you by:
linuxpark
From: linuxpark <lin...@us...> - 2006-03-18 17:45:47
|
Update of /cvsroot/netadm/gwc/pf In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8626 Modified Files: pf.c pf.h sysktimer.c sysktimer.h Log Message: MOD: modify previos sysktimer to more simple 3 exported library function. 1. sysktimer_t *init_sysktimer ( handler-func-pointer, parameter-to-handler, timeout-sec[0:forever | specified second], secound [ to wakeup handler ], nanosecond [ to wakeup handler ] ) : initialize data struct for timer : return value : timer object(success) or null (fail) 2. int register_sysktimer (timer_object) : activate timer : return value : fail (minu integer), success (task id) 3. int unregister_sysktimer (tid, ktimer) : deactivate timer and destory timer object : return value : fail (minus integer), success (plus integer) Index: sysktimer.h =================================================================== RCS file: /cvsroot/netadm/gwc/pf/sysktimer.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** sysktimer.h 10 Mar 2006 16:48:49 -0000 1.3 --- sysktimer.h 18 Mar 2006 17:45:41 -0000 1.4 *************** *** 1,6 **** /* ! * filename : timer.h * 2006. 02. 28. (thu) 08:39:39 KST ! * lin...@gm... */ #include <linux/init.h> --- 1,6 ---- /* ! * filename : sysktimer.h * 2006. 02. 28. (thu) 08:39:39 KST ! * jeho park <lin...@us...> */ #include <linux/init.h> *************** *** 12,27 **** #include <linux/interrupt.h> ! #ifndef __SYS_KTIMER_H ! #define __SYS_KTIMER_H ! struct sys_timer_t { int (*func)(void *argument); void *data; int t_time; struct timespec t; ! }; ! extern pid_t register_sys_timer ( struct sys_timer_t *timer ); ! extern int unregister_sys_timer ( pid_t pid ); #endif --- 12,46 ---- #include <linux/interrupt.h> ! #ifndef __H_SYSKTIMER ! #define __H_SYSKTIMER ! #ifndef SZSYSVERSION ! #define SZSYSVERSION "sysktimer-v0.1.0" ! #endif ! ! typedef struct { int (*func)(void *argument); void *data; int t_time; struct timespec t; ! } sysktimer_t; ! /* init_sysktimer ! * @func: handler of timer ! * @data: argument of hander ! * @total_sec: total time to make live timer. ! * @p_sec: period of waking up handler. sec unit. ! * @p_nsec:period of waking up handler. nano sec unit. ! * ! * return: null: Fail, not null: sucess ! */ ! extern sysktimer_t * init_sysktimer (int (*func)(void *argument), ! void *data, ! unsigned long total_sec, ! unsigned long p_sec, ! unsigned long p_nsec); ! ! extern pid_t register_sysktimer ( sysktimer_t *sysktimer ); ! extern int unregister_sysktimer ( pid_t pid, sysktimer_t *sysktimer); #endif Index: pf.h =================================================================== RCS file: /cvsroot/netadm/gwc/pf/pf.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** pf.h 10 Mar 2006 16:48:49 -0000 1.4 --- pf.h 18 Mar 2006 17:45:41 -0000 1.5 *************** *** 1,6 **** /* - Title : pf.h ! Author : Jeho-Park <ne...@ke...> Created date : 2006. 01. 31. (thu) 01:39:30 KST Description : --- 1,5 ---- /* Title : pf.h ! Author : Jeho-Park <lin...@us...> Created date : 2006. 01. 31. (thu) 01:39:30 KST Description : Index: pf.c =================================================================== RCS file: /cvsroot/netadm/gwc/pf/pf.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** pf.c 14 Mar 2006 17:17:08 -0000 1.7 --- pf.c 18 Mar 2006 17:45:41 -0000 1.8 *************** *** 1,6 **** /* - Title : pf.c ! Author : Jeho-Park <lin...@gm...> Created date : 2006. 01. 31. (thu) 01:39:30 KST Description : pf module --- 1,5 ---- /* Title : pf.c ! Author : Jeho-Park <lin...@us...> Created date : 2006. 01. 31. (thu) 01:39:30 KST Description : pf module *************** *** 53,56 **** --- 52,56 ---- static pid_t tid; /* timer thread id */ + static sysktimer_t *pf_ktimer = NULL; static int debug __initdata = 0; static int kuio_rdopen = 0; *************** *** 79,83 **** return map->id; } - map++; } --- 79,82 ---- *************** *** 87,91 **** EXPORT_SYMBOL_GPL (mapstrtoid); - /* block list hash table */ static struct blk_hash_bucket *blk_hash_table; --- 86,89 ---- *************** *** 306,318 **** } - static void init_systimer (struct sys_timer_t * t) - { - t->func = update_eat; /* handler */ - t->data = NULL; /* param of handler */ - t->t_time = 0; /* total time endless */ - t->t.tv_sec = 0; /* sec */ - t->t.tv_nsec = 1000000000; /* nano sec */ - } - /* process_packet * : This is called with lock state of spinlock in a bucket --- 304,307 ---- *************** *** 630,635 **** gwc_pf_init(void) { ! static struct sys_timer_t timer; ! printk("%s: Loading %s module ...\n", DEVICE_NAME, DEVICE_NAME); --- 619,623 ---- gwc_pf_init(void) { ! printk("%s: Loading %s module ...\n", DEVICE_NAME, DEVICE_NAME); *************** *** 640,650 **** init_pf(); init_kuio(); ! init_systimer(&timer); ! ! /* TODO : in futer, tid can be pid list for each timer thread */ ! if ( (tid = register_sys_timer( &timer)) < 0 ) { ! printk("%s: Failed to register timer\n", DEVICE_NAME); ! /* FIXME */ } return 0; } --- 628,642 ---- init_pf(); init_kuio(); ! ! pf_ktimer = init_sysktimer (update_eat, NULL, 0, 0, 1000000000); ! if (!pf_ktimer) { ! printk("%s: Failed to init sysktimer\n", DEVICE_NAME); ! return 1; } + + if ((tid = register_sysktimer (pf_ktimer)) < 0 ) { + printk("%s: Failed to register sysktimer\n", DEVICE_NAME); + } + return 0; } *************** *** 654,660 **** gwc_pf_exit(void) { ! if ( tid > 0 && unregister_sys_timer(tid) < 0 ) { ! printk("%s: Failed to unregister timer\n", DEVICE_NAME); } --- 646,653 ---- gwc_pf_exit(void) { + int ret; ! if ( tid > 1 && ((ret = unregister_sysktimer(tid, pf_ktimer))) < 0 ) { ! printk("%s: Failed to unregister timer (%d)\n", DEVICE_NAME, ret); } Index: sysktimer.c =================================================================== RCS file: /cvsroot/netadm/gwc/pf/sysktimer.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** sysktimer.c 10 Mar 2006 16:48:49 -0000 1.3 --- sysktimer.c 18 Mar 2006 17:45:41 -0000 1.4 *************** *** 1,6 **** /* ! * filename : timer.c * 2006. 02. 28. (thu) 08:38:14 KST ! * lin...@gm... */ --- 1,6 ---- /* ! * filename : sysktimer.c * 2006. 02. 28. (thu) 08:38:14 KST ! * jeho park <lin...@us...> */ *************** *** 14,18 **** #include <linux/kthread.h> #include "sysktimer.h" - #include "../include/global.h" #define DRIVER_AUTHOR "jeho park <lin...@gm...>" --- 14,17 ---- *************** *** 21,38 **** static int netadm_timer_thread (void *data) { ! struct sys_timer_t *p = NULL; ! unsigned long expire; ! unsigned long i_time = jiffies; ! int ret = 1; ! p = (struct sys_timer_t*)data; if (!p) { ret = -1; ! printk("null timer struct\n"); } if ( p->t_time < 0 || p->t.tv_sec < 0 || p->t.tv_nsec < 0) { ret = -1; ! printk("invalid argument given\n"); } --- 20,37 ---- static int netadm_timer_thread (void *data) { ! sysktimer_t *p = NULL; ! unsigned long expire; ! unsigned long i_time = jiffies; ! int ret = 1; ! p = (sysktimer_t*)data; if (!p) { ret = -1; ! printk("null timer struct.\n"); } if ( p->t_time < 0 || p->t.tv_sec < 0 || p->t.tv_nsec < 0) { ret = -1; ! printk("invalid argument.\n"); } *************** *** 40,44 **** return ret; ! printk("%s thread start, total time: %d\n", DRIVER_VERSION, p->t_time); expire = timespec_to_jiffies(&p->t) + (p->t.tv_sec || p->t.tv_nsec); --- 39,43 ---- return ret; ! printk("%s timer start, timeout time: %d\n", DRIVER_VERSION, p->t_time); expire = timespec_to_jiffies(&p->t) + (p->t.tv_sec || p->t.tv_nsec); *************** *** 46,50 **** if ( p->t_time > 0 && jiffies > ( p->t_time * HZ + i_time) ) { ! printk("%s: timer thread exit\n", DRIVER_VERSION); break; } --- 45,49 ---- if ( p->t_time > 0 && jiffies > ( p->t_time * HZ + i_time) ) { ! printk("%s: timer timeout(%d)...\n", DRIVER_VERSION, p->t_time); break; } *************** *** 54,63 **** expire = schedule_timeout_interruptible(expire); if (!expire) ! p->func (p->data); else { /* TODO: case "unregister_sys_timer" or other interrupt * i definitly assumed it was stemed from mine */ ! printk("%s thread exit\n", DRIVER_VERSION); return 1; } --- 53,62 ---- expire = schedule_timeout_interruptible(expire); if (!expire) ! p->func (p->data); else { /* TODO: case "unregister_sys_timer" or other interrupt * i definitly assumed it was stemed from mine */ ! printk("%s: timer exit by user request\n", DRIVER_VERSION); return 1; } *************** *** 66,70 **** } ! pid_t register_sys_timer ( struct sys_timer_t *timer ) { struct task_struct *tsk; --- 65,99 ---- } ! extern sysktimer_t * init_sysktimer (int (*func)(void *argument), ! void *data, ! unsigned long total_sec, ! unsigned long p_sec, ! unsigned long p_nsec) ! { ! static sysktimer_t *sysktimer = NULL; ! ! sysktimer = (sysktimer_t *)kmalloc (sizeof (sysktimer_t), ! in_interrupt()? GFP_ATOMIC : GFP_KERNEL); ! if (!sysktimer) { ! printk("%s: Failed to kmalloc\n", DRIVER_VERSION); ! return NULL; ! } ! sysktimer->func = func; ! ! if (data) ! sysktimer->data = data; ! else ! sysktimer->data = NULL; ! ! sysktimer->t_time = total_sec; ! sysktimer->t.tv_sec = p_sec; ! sysktimer->t.tv_nsec = p_nsec; ! ! printk("%s: successfully initialized sysktimer data\n", DRIVER_VERSION); ! return sysktimer; ! } ! EXPORT_SYMBOL_GPL (init_sysktimer); ! ! pid_t register_sysktimer (sysktimer_t *timer ) { struct task_struct *tsk; *************** *** 77,94 **** return tsk->pid; } ! EXPORT_SYMBOL_GPL (register_sys_timer); ! int unregister_sys_timer ( pid_t pid ) { struct task_struct *tsk; tsk = find_task_by_pid(pid); if (tsk) { ! return kthread_stop(tsk); } else { ! printk ("there is no such task : pid: %d\n", pid); ! return -1; } } ! EXPORT_SYMBOL_GPL (unregister_sys_timer); static int __init init_netadm_timer(void) --- 106,137 ---- return tsk->pid; } ! EXPORT_SYMBOL_GPL (register_sysktimer); ! int unregister_sysktimer (pid_t pid, sysktimer_t *sysktimer) { struct task_struct *tsk; + int ret = -1; + tsk = find_task_by_pid(pid); if (tsk) { ! ! ret = kthread_stop(tsk); ! if (ret < 0 ) { ! printk("%s: Failed to stop task(%d)\n", DRIVER_VERSION, pid); ! } ! else { ! printk("%s: Success to stop pid(%d)\n", DRIVER_VERSION, pid); ! } ! ! if (sysktimer) ! kfree (sysktimer); } else { ! printk("%s: There is no suck task(%d), sysktimer(%s)\n", ! DRIVER_VERSION, pid, sysktimer? "not null must be free":"null"); } + + return ret; } ! EXPORT_SYMBOL_GPL (unregister_sysktimer); static int __init init_netadm_timer(void) |