[pisa-src] r1097 - in trunk: . include libpisa pisacd pisasd

  • From: Thomas Jansen <mithi@xxxxxxxxx>
  • To: pisa-src@xxxxxxxxxxxxx
  • Date: Mon, 12 Oct 2009 17:20:59 +0200

Author: tjansen
Date: Mon Oct 12 17:20:59 2009
New Revision: 1097

Log:
First step to add a scheduler for deferred actions.

Currently, maintenance is done after every packet. This reduces throughput.
The new scheduler will maintain a list of tasks and the time at which they
will be run. The main loop checks after every packet a flag to see if the
scheduler has things that need to be done.

Added:
   trunk/include/scheduler.h
   trunk/libpisa/scheduler.c
Modified:
   trunk/Makefile.am
   trunk/libpisa/Makefile.am
   trunk/pisacd/cdctx.c
   trunk/pisacd/cdctx.h
   trunk/pisacd/cdmain.c
   trunk/pisasd/sdctx.c
   trunk/pisasd/sdctx.h
   trunk/pisasd/sdmain.c

Modified: trunk/Makefile.am
==============================================================================
--- trunk/Makefile.am   Mon Oct 12 16:42:45 2009        (r1096)
+++ trunk/Makefile.am   Mon Oct 12 17:20:59 2009        (r1097)
@@ -40,6 +40,7 @@
        include/pisand.h \
        include/pisaperf.h \
        include/pisasd.h \
+       include/scheduler.h \
        include/socket.h \
        include/token.h \
        include/tunnel.h \

Added: trunk/include/scheduler.h
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ trunk/include/scheduler.h   Mon Oct 12 17:20:59 2009        (r1097)
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2009, Distributed Systems Group, RWTH Aachen
+ * All rights reserved.
+ */
+
+/**
+ * @file scheduler.h
+ * @brief Generic scheduler for deferred actions.
+ * @author Thomas Jansen <mithi@xxxxxxxxx>
+ * @date Oct. 2009
+ */
+
+#ifndef PISA_SCHEDULER_H
+#define PISA_SCHEDULER_H
+
+#include "packet.h"
+#include "uthash.h"
+
+typedef void (*pisa_sched_func)(void *data);
+
+typedef struct {
+       pisa_sched_func func;
+       time_t t;
+} pisa_sched_task;
+
+void pisa_sched_init(int *shared);
+void pisa_sched_cleanup(void);
+void pisa_sched_run(void);
+
+pisa_sched_task *pisa_sched_add(pisa_sched_func func, struct timeval delay, 
void *data);
+void pisa_sched_remove(pisa_sched_task *task);
+
+#endif /* PISA_SCHEDULER_H */

Modified: trunk/libpisa/Makefile.am
==============================================================================
--- trunk/libpisa/Makefile.am   Mon Oct 12 16:42:45 2009        (r1096)
+++ trunk/libpisa/Makefile.am   Mon Oct 12 17:20:59 2009        (r1097)
@@ -11,7 +11,7 @@
 libpisa_la_SOURCES  = arp.c buffer.c config.c conmgr.c crypto.c
 libpisa_la_SOURCES += ctrlhandler.c debug.c hitlist.c iw.c iwlib.c linkedlist.c
 libpisa_la_SOURCES += nat.c packet.c socket.c token.c tunnel.c util.c
-libpisa_la_SOURCES += pisaconf.c
+libpisa_la_SOURCES += pisaconf.c scheduler.c
 if PISA_LOGGING
 libpisa_la_SOURCES += log.c
 endif

Added: trunk/libpisa/scheduler.c
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ trunk/libpisa/scheduler.c   Mon Oct 12 17:20:59 2009        (r1097)
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2009, Distributed Systems Group, RWTH Aachen
+ * All rights reserved.
+ */
+
+/**
+ * @file scheduler.c
+ * @brief Generic scheduler for deferred actions.
+ * @author Thomas Jansen <mithi@xxxxxxxxx>
+ * @date Oct. 2009
+ */
+
+#include "scheduler.h"
+
+/**
+ * Our way to tell the main loop that we want to be called is setting the
+ * shared variable to a value != 0
+ */
+static int *flag = NULL;
+
+/**
+ * Initialize the scheduler. Create a thread that sleeps until the first
+ * element in the list is due.
+ *
+ * @param shared pointer to the variable shared with the main thread
+ */ 
+void pisa_sched_init(int *shared)
+{
+       flag = shared;
+       /* TODO: create a new thread */
+}
+
+/**
+ * Clean up the scheduler. Free the task list, clear the scheduler flag and
+ * kill the thread.
+ */
+void pisa_sched_cleanup(void)
+{
+       *flag = 0;
+}
+
+/**
+ * Run scheduled actions. Called by the main thread eventually if we set the
+ * shared variable to a value != 0. Handle all actions that are due and reset
+ * the shared variable.
+ */
+void pisa_sched_run(void)
+{
+       *flag = 0;
+}
+
+/**
+ * Schedule a new task.
+ *
+ * @param func function to run once the task is due
+ * @param delay delay until the function is run
+ * @param data opaque payload
+ */
+pisa_sched_task *pisa_sched_add(pisa_sched_func func, struct timeval delay, 
void *data)
+{
+       /* TODO: malloc new task, fill it, add it to the list (ordered) */
+       return NULL;
+}
+
+/**
+ * Remove a scheduled task.
+ *
+ * @param task task to be removed from the schedule
+ */
+void pisa_sched_remove(pisa_sched_task *task)
+{
+       /* TODO: remove from list, free */
+}

Modified: trunk/pisacd/cdctx.c
==============================================================================
--- trunk/pisacd/cdctx.c        Mon Oct 12 16:42:45 2009        (r1096)
+++ trunk/pisacd/cdctx.c        Mon Oct 12 17:20:59 2009        (r1097)
@@ -71,6 +71,8 @@
        cdctx->ctrlhandlers = NULL;
        cdctx->natlist = NULL;
        cdctx->conlist = NULL;
+
+       cdctx->scheduler = 0;
 }
 
 /**

Modified: trunk/pisacd/cdctx.h
==============================================================================
--- trunk/pisacd/cdctx.h        Mon Oct 12 16:42:45 2009        (r1096)
+++ trunk/pisacd/cdctx.h        Mon Oct 12 17:20:59 2009        (r1097)
@@ -130,6 +130,11 @@
         * List of connections.
         */
        pisa_conmgr_list *conlist;
+
+       /**
+        * 0 if the scheduler has nothing to do, != 0 otherwise
+        */
+       int scheduler;
 } cd_context;
 
 extern cd_context cd_ctx;

Modified: trunk/pisacd/cdmain.c
==============================================================================
--- trunk/pisacd/cdmain.c       Mon Oct 12 16:42:45 2009        (r1096)
+++ trunk/pisacd/cdmain.c       Mon Oct 12 17:20:59 2009        (r1097)
@@ -31,6 +31,7 @@
 #include "pisacd.h"
 #include "pisaconf.h"
 #include "cdconfhandlers.h"
+#include "scheduler.h"
 
 extern pisa_conf_handle_func_set conf_handle_func_set;
 
@@ -252,6 +253,8 @@
        cd_ctx.conlist = 
pisa_conmgr_init(pisacd_cleanup_after_removed_connection);
 
        pisa_tunnel_configure_main(cd_ctx.ifname_tunnel, &cd_cfg.local_ipv4, 
&cd_cfg.local_netmask, MTU_TUN);
+
+       pisa_sched_init(&cd_ctx.scheduler);
 }
 
 static void cd_deinit(void)
@@ -266,6 +269,7 @@
        cdctx_destroy(&cd_ctx);
        cdconf_destroy(&cd_cfg);
        pisa_arp_cleanup();
+       pisa_sched_cleanup();
 
        close(cd_ctx.fd_pacli);
        close(cd_ctx.fd_pasrv);
@@ -415,6 +419,9 @@
                }
 #endif /* REMOVE_PREAUTH_CODE */
 
+               if (cd_ctx.scheduler)
+                       pisa_sched_run();
+
                if (cd_ctx.is_cd_running){
                        pisa_client_heartbeat_all();
                }

Modified: trunk/pisasd/sdctx.c
==============================================================================
--- trunk/pisasd/sdctx.c        Mon Oct 12 16:42:45 2009        (r1096)
+++ trunk/pisasd/sdctx.c        Mon Oct 12 17:20:59 2009        (r1097)
@@ -54,6 +54,8 @@
        sdctx->natlist = NULL;
        sdctx->conlist = NULL;
        sdctx->disable_ip4_forward=0;
+
+       sdctx->scheduler = 0;
 }
 
 /**

Modified: trunk/pisasd/sdctx.h
==============================================================================
--- trunk/pisasd/sdctx.h        Mon Oct 12 16:42:45 2009        (r1096)
+++ trunk/pisasd/sdctx.h        Mon Oct 12 17:20:59 2009        (r1097)
@@ -114,6 +114,11 @@
         *  shutdown via /proc/sys/net/ipv4/ip_forward
         */
        int disable_ip4_forward;
+
+       /**
+        * 0 if the scheduler has nothing to do, != 0 otherwise
+        */
+       int scheduler;
 } sd_context;
 
 extern sd_context sd_ctx;

Modified: trunk/pisasd/sdmain.c
==============================================================================
--- trunk/pisasd/sdmain.c       Mon Oct 12 16:42:45 2009        (r1096)
+++ trunk/pisasd/sdmain.c       Mon Oct 12 17:20:59 2009        (r1097)
@@ -39,6 +39,7 @@
 #include "sdtun.h"
 #include "ctrlhandler.h"
 #include "pisaconf.h"
+#include "scheduler.h"
 
 #ifdef CONFIG_PISA_LOGGING
 # include "log.h"
@@ -232,6 +233,8 @@
        inet_pton(AF_INET, "255.255.255.0", &netmask);
        sd_ctx.tunnel = pisa_tunnel_open_tundev(sd_ctx.fd_pisa_tunnel_name, 
IFNAMSIZ);
        pisa_tunnel_configure_main(sd_ctx.fd_pisa_tunnel_name, &sd_cfg.ipaddr, 
&netmask, MTU_TUN);
+
+       pisa_sched_init(&sd_ctx.scheduler);
 }
 
 /**
@@ -254,6 +257,7 @@
        sdctx_destroy(&sd_ctx);
        sdconf_destroy(&sd_cfg);
        pisa_arp_cleanup();
+       pisa_sched_cleanup();
 
        /* finish all the remaining jobs */
        close(sd_ctx.tunc);
@@ -343,6 +347,9 @@
                                pisa_conf_handle_packet(sd_ctx.fd_pisaconf);
                }
 
+               if (sd_ctx.scheduler)
+                       pisa_sched_run();
+
 #ifdef REMOVE_PREAUTH_CODE
                sd_start_alarm();
 #endif /* REMOVE_PREAUTH_CODE */

Other related posts:

  • » [pisa-src] r1097 - in trunk: . include libpisa pisacd pisasd - Thomas Jansen