[Netadm-devel] gwc/pf sysktimer.c,NONE,1.1 sysktimer.h,NONE,1.1
Status: Beta
Brought to you by:
linuxpark
From: linuxpark <lin...@us...> - 2006-02-28 00:47:23
|
Update of /cvsroot/netadm/gwc/pf In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23719 Added Files: sysktimer.c sysktimer.h Log Message: Initial Check-in Replace current dynamic kernel timer of linux API with more simple netadm made timer called "sysktimer" --- NEW FILE: sysktimer.h --- /* * filename : timer.h * 2006. 02. 28. (thu) 08:39:39 KST * lin...@gm... */ #include <linux/init.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/types.h> #include <linux/sched.h> #include <linux/timer.h> #include <linux/interrupt.h> #ifndef __SYS_TIMER_H #define __SYS_TIMER_H struct sys_timer_t { int (*func)(void *argument); void *data; int t_time; struct timespec t; }; extern int register_sys_timer ( struct sys_timer_t *timer ); extern int unregister_sys_timer ( pid_t pid ); #endif --- NEW FILE: sysktimer.c --- /* * filename : timer.c * 2006. 02. 28. (thu) 08:38:14 KST * lin...@gm... */ #include <linux/init.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/types.h> #include <linux/sched.h> #include <linux/timer.h> #include <linux/interrupt.h> #include <linux/kthread.h> #include "sysktimer.h" #include "../include/global.h" #define DRIVER_AUTHOR "jeho park <lin...@gm...>" #define DRIVER_VERSION "gwc-timer-" SZSYSVERSION #define DRIVER_DESC "gwc of netadm project " DRIVER_VERSION 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"); } if (ret < 0 ) return ret; printk("%s start, total time: %d\n", __FUNCTION__, p->t_time); expire = timespec_to_jiffies(&p->t) + (p->t.tv_sec || p->t.tv_nsec); while (1) { if ( p->t_time > 0 && jiffies > ( p->t_time * HZ + i_time) ) { printk("%s: timer thread exit\n", DRIVER_VERSION); break; } expire = timespec_to_jiffies(&p->t) + (p->t.tv_sec || p->t.tv_nsec); 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 exit\n", __FUNCTION__); return 1; } } return 1; } int register_sys_timer ( struct sys_timer_t *timer ) { struct task_struct *tsk; tsk = kthread_create ( netadm_timer_thread, timer, "%s", DRIVER_VERSION); if (IS_ERR(tsk)) { printk("can't create netadm_timer\n"); return -EAGAIN; } wake_up_process (tsk); 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) { printk("%s: register netadm timer\n", DRIVER_VERSION); return 0; } module_init(init_netadm_timer); static void __exit exit_netadm_timer(void) { printk("%s: unregister netadm timer\n", DRIVER_VERSION); } module_exit(exit_netadm_timer); MODULE_AUTHOR(DRIVER_AUTHOR); MODULE_DESCRIPTION(DRIVER_DESC); MODULE_LICENSE("GPL"); MODULE_VERSION(DRIVER_VERSION); |