Change component instantiation.
authorAnselm Busse <anselm.busse@tu-berlin.de>
Tue, 23 Feb 2016 20:21:35 +0000 (21:21 +0100)
committerAnselm Busse <anselm.busse@tu-berlin.de>
Tue, 23 Feb 2016 20:21:35 +0000 (21:21 +0100)
15 files changed:
framework/components/affinities.c
framework/components/fcfs.c
framework/components/load_balance.c
framework/components/round_robin.c
framework/fw/fw_components.c
framework/fw/include/fw_components.h
framework/fw/include/fw_pipe.h
framework/lib/include/fw_lock.h
framework/os/linux/Makefile
framework/topos/topo_lb_rr_dual.c
framework/topos/topo_lb_rr_fcfs.c
framework/topos/topo_lb_rr_multi.c
framework/topos/topo_lb_rr_quad.c
framework/topos/topo_lb_rr_single.c
framework/topos/topo_rr_single.c

index 24618e6..36a80fa 100644 (file)
@@ -59,15 +59,12 @@ static fw_component_operations_t af_ops = {
  * @param links   The number of links of the new instance.
  * @return An instance of this component.
  */
-static fw_component_inst_t *af_new(inst_uuid_t inst_id, int link_count, fw_pipe_t **links)
+static fw_component_inst_t *af_new(inst_uuid_t inst_id, void *args)
 {
        // the newly created instance
        fw_component_inst_t *inst;
 
-       if (link_count != 0) {
-               fw_panic("Error: Module %s: Wrong number of link_count (%d instead of %i)\n", AF_COMPONENT_NAME, link_count, 0);
-               /* never reached */
-       }
+       UNUSED(args);
 
        inst = fw_malloc(sizeof(fw_component_inst_t));
        if (inst == NULL) {
@@ -91,10 +88,10 @@ static fw_component_inst_t *af_new(inst_uuid_t inst_id, int link_count, fw_pipe_
  *
  * @param self The comonent instance.
  */
-static void af_destroy(fw_component_inst_t *self)
+static void af_destroy(fw_component_inst_t *inst)
 {
-       fw_free(self->inst_data);
-       fw_free(self);
+       fw_free(inst->inst_data);
+       fw_free(inst);
 }
 
 int af_init(void)
index 28fcd3a..4b14b08 100644 (file)
@@ -11,11 +11,9 @@ int fcfs_init(void);
 #define FCFS_MODULE_NAME       "First Come First Served Component"
 #define FCFS_MODULE_DESC       "TODO"
 
-static fw_component_inst_t fcfs_proto;
-
 typedef struct fcfs_private_data {
        int inst_id;
-       fw_spin_lock_t lock;
+       fw_spinlock_t lock;
 
        unsigned long lamport;
 
@@ -38,13 +36,13 @@ static void fcfs_task_init(fw_component_inst_t *self, fw_task_t *task)
        time = pd->lamport++;
        fw_spin_unlock(&pd->lock);
 
-       task->component_pcb[self->id] = pcb;
+       task->component_pcb[self->inst_id] = pcb;
        pcb->lamport = time;
 }
 
 static void fcfs_task_destroy(fw_component_inst_t *self, fw_task_t *task)
 {
-       fw_free(task->component_pcb[self->id]);
+       fw_free(task->component_pcb[self->inst_id]);
 }
 
 static void fcfs_pipe_update(fw_component_inst_t *self, fw_pipe_t *pipe)
@@ -59,9 +57,9 @@ static void fcfs_pipe_update(fw_component_inst_t *self, fw_pipe_t *pipe)
 
        fw_list_for_each_entry_safe(pos,n,(&pipe->tasks_added),pipe_pcb[pipe->id].added) {
                position = 0;
-               tmp1 = pos->component_pcb[self->id];
+               tmp1 = pos->component_pcb[self->inst_id];
                fw_list_for_each_entry(iter, &pd->out_pipe->tasks_list, pipe_pcb[pd->out_pipe->id].list) {
-                       tmp2 = iter->component_pcb[self->id];
+                       tmp2 = iter->component_pcb[self->inst_id];
                        if(tmp1->lamport < tmp2->lamport)
                                break;
 
@@ -84,22 +82,38 @@ static void fcfs_pipe_update(fw_component_inst_t *self, fw_pipe_t *pipe)
        pd->out_pipe->out->ops.pipe_update(pd->out_pipe->out, pd->out_pipe);
 }
 
-static fw_component_inst_t *fcfs_new(inst_uuid_t inst_id, int link_count, fw_pipe_t **links)
+static fw_component_operations_t fcfs_ops = {
+       .schedule               = NULL,
+       .dispatch               = NULL,
+       .task_init              = fcfs_task_init,
+       .task_destroy   = fcfs_task_destroy,
+       .pipe_update    = fcfs_pipe_update
+};
+
+static fw_component_inst_t *fcfs_new(inst_uuid_t inst_id, void *args)
 {
        fw_component_inst_t *inst;
        struct fcfs_private_data *pd;
+       fw_pipe_array_t *pipes = args;
 
-       inst = fw_component_clone(&fcfs_proto);
-       if (inst == NULL) {
-               fw_printf("Error: Module %s: OOM for new instance\n", FCFS_MODULE_NAME);
+       if (pipes == NULL) {
+               fw_error("Module %s: No in and out pipes given\n", FCFS_MODULE_NAME);
                return NULL;
        }
 
-       inst->id = inst_id;
+       if (pipes->magic != FW_PIPE_ARRAY_MAGIC) {
+               fw_error("Module %s: input args seems to be a wrong data structure.\n", FCFS_MODULE_NAME);
+               return NULL;
+       }
 
-       if (link_count != 2) {
-               fw_printf("Error: Module %s: Wrong number of link_count (%d instead of %i)\n", FCFS_MODULE_NAME, link_count, 2);
-               fw_free(inst);
+       if (pipes->size != 2) {
+                       fw_error("Module %s: Wrong number of link_count (%d instead of %i)\n", FCFS_MODULE_NAME, pipes->size, 2);
+                       return NULL;
+       }
+
+       inst = fw_malloc(sizeof(fw_component_inst_t));
+       if (inst == NULL) {
+               fw_printf("Error: Module %s: OOM for new instance\n", FCFS_MODULE_NAME);
                return NULL;
        }
 
@@ -109,34 +123,28 @@ static fw_component_inst_t *fcfs_new(inst_uuid_t inst_id, int link_count, fw_pip
                return NULL;
        }
 
-
-       pd->lock.raw_lock.slock = 0;
+       inst->comp_id = FCFS_MODULE_UUID;
+       inst->inst_id = inst_id;
+       inst->ops = fcfs_ops;
        inst->inst_data = pd;
 
-       pd->in_pipe = links[0];
-       pd->out_pipe = links[1];
+       pd->in_pipe = pipes->pipes[0];
+       pd->out_pipe = pipes->pipes[1];
 
     pd->in_pipe->out = inst;
     pd->out_pipe->in = inst;
 
+    fw_spin_lock_init(&pd->lock);
+
        return inst;
 }
 
-static void fcfs_destroy(fw_component_inst_t *self)
+static void fcfs_destroy(fw_component_inst_t *inst)
 {
-
+       fw_free(inst->inst_data);
+       fw_free(inst);
 }
 
-static fw_component_inst_t fcfs_proto = {
-       .uuid = FCFS_MODULE_UUID,
-       .name = FCFS_MODULE_NAME,
-       .id = -1,
-       .ops = {.task_init = fcfs_task_init,
-                       .task_destroy = fcfs_task_destroy,
-                       .pipe_update = fcfs_pipe_update},
-       .inst_data = NULL
-};
-
 int fcfs_init(void)
 {
        return fw_component_register(FCFS_MODULE_UUID, FCFS_MODULE_NAME, FCFS_MODULE_DESC, fcfs_new, fcfs_destroy);
index 0129d4a..e501c6e 100644 (file)
@@ -117,11 +117,22 @@ static fw_component_operations_t lb_ops = {
        .pipe_update    = lb_pipe_update
 };
 
-static fw_component_inst_t *lb_new(inst_uuid_t inst_id, int link_count, fw_pipe_t **links)
+static fw_component_inst_t *lb_new(inst_uuid_t inst_id, void *args)
 {
        fw_component_inst_t *inst;
        struct lb_private_data *pd;
        int i;
+       fw_pipe_array_t *pipes = args;
+
+       if (pipes == NULL) {
+               fw_error("Module %s: No in and out pipes given\n", LB_MODULE_NAME);
+               return NULL;
+       }
+
+       if (pipes->magic != FW_PIPE_ARRAY_MAGIC) {
+               fw_error("Module %s: input args seems to be a wrong data structure.\n", LB_MODULE_NAME);
+               return NULL;
+       }
 
        inst = fw_malloc(sizeof(fw_component_inst_t));
        if (inst == NULL) {
@@ -135,7 +146,7 @@ static fw_component_inst_t *lb_new(inst_uuid_t inst_id, int link_count, fw_pipe_
                return NULL;
        }
 
-       if (!(pd->out_pipe = fw_malloc((fw_size_t) (link_count-1) * sizeof(fw_pipe_t *)))) {
+       if (!(pd->out_pipe = fw_malloc((fw_size_t) (pipes->size-1) * sizeof(fw_pipe_t *)))) {
                fw_printf("Error: Module %s: Memory allocation for private data failed\n", LB_MODULE_NAME);
                fw_free(pd);
                fw_free(inst);
@@ -148,17 +159,17 @@ static fw_component_inst_t *lb_new(inst_uuid_t inst_id, int link_count, fw_pipe_
        inst->ops = lb_ops;
        inst->inst_data = pd;
 
-       pd->in_pipe = links[0];
+       pd->in_pipe = pipes->pipes[0];
        pd->in_pipe->out = inst;
 
-       for (i=1; i<link_count; i++) {
-               pd->out_pipe[i-1] = links[i];
+       for (i=1; i<pipes->size; i++) {
+               pd->out_pipe[i-1] = pipes->pipes[i];
                pd->out_pipe[i-1]->in = inst;
        }
 
        fw_spin_lock_init(&pd->lock);
        pd->pe_online.bits[0] = 1UL;
-       pd->size = link_count-1;
+       pd->size = pipes->size-1;
 
        fw_subscribe(FW_TOPIC_CPU_STATUS, lb_cpu_online, inst);
 
index a8452ad..7a11136 100644 (file)
@@ -62,13 +62,24 @@ static fw_component_operations_t rr_ops = {
        .pipe_update    = rr_pipe_update
 };
 
-static fw_component_inst_t *rr_new(inst_uuid_t inst_id, int link_count, fw_pipe_t **links)
+static fw_component_inst_t *rr_new(inst_uuid_t inst_id, void *args)
 {
        fw_component_inst_t *inst;
        struct rr_private_data *pd;
+       fw_pipe_array_t *pipes = args;
 
-       if (link_count != 2) {
-                       fw_error("Module %s: Wrong number of link_count (%d instead of %i)\n", RR_MODULE_NAME, link_count, 2);
+       if (pipes == NULL) {
+               fw_error("Module %s: No in and out pipes given\n", RR_MODULE_NAME);
+               return NULL;
+       }
+
+       if (pipes->magic != FW_PIPE_ARRAY_MAGIC) {
+               fw_error("Module %s: input args seems to be a wrong data structure.\n", RR_MODULE_NAME);
+               return NULL;
+       }
+
+       if (pipes->size != 2) {
+                       fw_error("Module %s: Wrong number of link_count (%d instead of %i)\n", RR_MODULE_NAME, pipes->size, 2);
                        return NULL;
        }
 
@@ -89,8 +100,8 @@ static fw_component_inst_t *rr_new(inst_uuid_t inst_id, int link_count, fw_pipe_
        inst->ops = rr_ops;
        inst->inst_data = pd;
 
-       pd->in_pipe = links[0];
-       pd->out_pipe = links[1];
+       pd->in_pipe = pipes->pipes[0];
+       pd->out_pipe = pipes->pipes[1];
 
     pd->in_pipe->out = inst;
     pd->out_pipe->in = inst;
index b8bd168..1b26335 100644 (file)
@@ -11,9 +11,9 @@ typedef struct fw_component {
        char *name;                                                                             /**< A human readable name of the component */
        char *description;                                                              /**< A short description of the component */
 
-       fw_component_inst_t* (*_new) (inst_uuid_t inst_id, int link_count, fw_pipe_t **links);
+       fw_component_inst_t* (*_new) (inst_uuid_t inst_id, void *arg);
                /**< Creates a new instances of this component with <code>inst_id</code as component id and connects the pipes provided by <code>links</code>*/
-       void (*_destroy) (fw_component_inst_t *self);   /**< Frees all resources of the provided component */
+       void (*_destroy) (fw_component_inst_t *inst);   /**< Frees all resources of the provided component */
 } fw_component_t;
 
 /**
@@ -35,7 +35,7 @@ fw_component_inst_t *fw_component_instances[FW_MAX_COMPONENT_INST];
 unsigned int fw_num_component_instances = 0;
 
 int fw_component_register(component_uuid_t uuid, const char *name, const char *description,
-               fw_component_inst_t* (*_new) (inst_uuid_t inst_id, int link_count, fw_pipe_t **links),
+               fw_component_inst_t* (*_new) (inst_uuid_t inst_id, void *args),
                void (*_destroy) (fw_component_inst_t *self))
 {
        FW_ASSERT(uuid <= FW_MAX_COMPONENT_ID);
@@ -74,7 +74,7 @@ int fw_component_register(component_uuid_t uuid, const char *name, const char *d
        return 0;
 }
 
-fw_component_inst_t *fw_component_new(component_uuid_t uuid, inst_uuid_t inst_id, int link_count, fw_pipe_t **links)
+fw_component_inst_t *fw_component_new(component_uuid_t uuid, inst_uuid_t inst_id, void *args)
 {
        if (components[uuid].id == 0) {
                fw_error("No component registered for 0x%02x.\n", uuid);
@@ -86,7 +86,7 @@ fw_component_inst_t *fw_component_new(component_uuid_t uuid, inst_uuid_t inst_id
                return NULL;
        }
 
-       fw_component_instances[inst_id] = components[uuid]._new(inst_id, link_count, links);
+       fw_component_instances[inst_id] = components[uuid]._new(inst_id, args);
 
        if (fw_component_instances[inst_id] == NULL) {
                fw_error("Failed to create a new instance of %s(0x%02x) with ID %x.\n", fw_component_name(uuid), uuid, inst_id);
index 270f39f..57016bb 100644 (file)
@@ -73,7 +73,7 @@ typedef struct fw_component_inst {
  * @return Return 0 if successful.
  */
 int fw_component_register(component_uuid_t uuid, const char *name, const char *description,
-               fw_component_inst_t* (*_new) (inst_uuid_t inst_id, int link_count, fw_pipe_t **links),
+               fw_component_inst_t* (*_new) (inst_uuid_t inst_id, void *args),
                void (*_destroy) (fw_component_inst_t *self));
 
 /**
@@ -88,7 +88,7 @@ int fw_component_register(component_uuid_t uuid, const char *name, const char *d
  * @param links The pipes that are connected to the new instance.
  * @return A reference to the newly created component instance.
  */
-fw_component_inst_t *fw_component_new(component_uuid_t uuid, inst_uuid_t inst_id, int link_count, fw_pipe_t **links);
+fw_component_inst_t *fw_component_new(component_uuid_t uuid, inst_uuid_t inst_id, void *args);
 
 /**
  * \brief Deallocates a component instance.
index 5b9bbbf..7e9cc8f 100644 (file)
@@ -31,6 +31,14 @@ typedef struct fw_pipe {
        fw_component_inst_t *out;               /**< Reference to the target component instance connected to the pipe. */
 } fw_pipe_t;
 
+#define FW_PIPE_ARRAY_MAGIC 0x2323DFDF
+
+typedef struct fw_pipe_array {
+       unsigned long magic;
+       int size;
+       fw_pipe_t **pipes;
+} fw_pipe_array_t;
+
 /**
  * The pipe for all available tasks that are ready for scheduling.
  */
index 2f98933..6c3be27 100644 (file)
@@ -11,7 +11,7 @@
 #define FW_LOCK_H_
 
 #include <fw_irq.h>
-#include "../../fw/include/generated/fw_target_helper.h"
+#include <generated/fw_target_helper.h>
 
 #define fw_spinlock_t os_spinlock_t
 
index 0124c89..707fb3b 100644 (file)
@@ -1,4 +1,4 @@
-KBUILD_CFLAGS += -DFW_OS_LINUX
+KBUILD_CFLAGS += -DFW_OS_LINUX -DCOBAS_DEBUG
 KBUILD_CFLAGS += -Ikernel/sched/cobas/include \
                                 -Ikernel/sched/cobas/include/generated \
                                 -Ikernel/sched/cobas/lib/include \
index 97307cd..8f30b15 100644 (file)
@@ -3,9 +3,6 @@
 
 
 #define NUM_LINKS 4
-#define NUM_CPUS 2
-
-#define NUM_INSTANCES 4
 
 int fw_build_module_list[3] = {0x01, 0x02, 0x0D};
 
@@ -18,21 +15,16 @@ extern fw_pipe_t **fw_fw_dispatch_pipe;
 int fw_build_topo(void)
 {
        int i;
-       fw_pipe_t **temp;
-
-       fw_num_instances = NUM_INSTANCES;
+       fw_pipe_array_t pipes;
 
-       if ((fw_component_instances = fw_malloc(fw_num_instances * sizeof(fw_component_inst_t*))) == NULL) {
-                       fw_panic("failed to allocate memory for instance references\n");
-                       /* never reached */;
-       }
+       pipes.magic = FW_PIPE_ARRAY_MAGIC;
 
        if ((topo_pipes = fw_malloc(NUM_LINKS * sizeof(fw_pipe_t *))) == NULL) {
                        fw_panic("failed to allocate memory for pipes\n");
                        /* never reached */;
        }
 
-       if ((fw_fw_dispatch_pipe = fw_malloc(NUM_CPUS * sizeof(fw_pipe_t *))) == NULL) {
+       if ((fw_fw_dispatch_pipe = fw_malloc(fw_num_cpus() * sizeof(fw_pipe_t *))) == NULL) {
                        fw_panic("failed to allocate memory for dispatching pipes\n");
                        /* never reached */;
        }
@@ -55,56 +47,51 @@ int fw_build_topo(void)
        }
 
        /* create default topo_links */
-
        fw_fw_dispatch_pipe[0] = topo_pipes[2];
        fw_fw_dispatch_pipe[1] = topo_pipes[3];
 
        /* link modules */
-
-       i=0;
-
-       temp = fw_malloc((NUM_CPUS+1) * sizeof(fw_pipe_t*));
-
-       fw_printf("Creating a new Instance of %s...", fw_component_names[0x02]);
-       temp[0] = fw_fw_ready_pipe;
-       temp[1] = topo_pipes[0];
-       temp[2] = topo_pipes[1];
-       if ((fw_component_instances[i] = fw_component_operations[0x02]->_new(i, NUM_CPUS+1, temp)) == NULL) {
+       pipes.size = 3;
+       pipes.pipes = fw_malloc(pipes.size * sizeof(fw_pipe_t*));
+
+       fw_printf("Creating a new Instance of %s...", fw_component_name(0x02));
+       pipes.pipes[0] = fw_fw_ready_pipe;
+       pipes.pipes[1] = topo_pipes[0];
+       pipes.pipes[2] = topo_pipes[1];
+       if (fw_component_new(0x02, 0, &pipes) == NULL) {
                fw_panic("failed to allocate component\n");
                /* never reached */;
-       }
-       i++;
+       };
        fw_printf("done!\n");
 
-
-       fw_printf("Creating a new Instance of %s...", fw_component_names[0x01]);
-       temp[0] = topo_pipes[0];
-       temp[1] = topo_pipes[2];
-       if ((fw_component_instances[i] = fw_component_operations[0x01]->_new(i, 2, temp)) == NULL) {
+       fw_printf("Creating a new Instance of %s...", fw_component_name(0x01));
+       pipes.size = 2;
+       pipes.pipes[0] = topo_pipes[0];
+       pipes.pipes[1] = topo_pipes[2];
+       if (fw_component_new(0x01, 1, &pipes) == NULL) {
                fw_panic("failed to allocate component\n");
                /* never reached */;
        };
-       i++;
        fw_printf("done!\n");
 
-       fw_printf("Creating a new Instance of %s...", fw_component_names[0x01]);
-       temp[0] = topo_pipes[1];
-       temp[1] = topo_pipes[3];
-       if ((fw_component_instances[i] = fw_component_operations[0x01]->_new(i, 2, temp)) == NULL) {
+       fw_printf("Creating a new Instance of %s...", fw_component_name(0x01));
+       pipes.size = 2;
+       pipes.pipes[0] = topo_pipes[1];
+       pipes.pipes[1] = topo_pipes[3];
+       if (fw_component_new(0x01, 2, &pipes) == NULL) {
                fw_panic("failed to allocate component\n");
                /* never reached */;
        };
-       i++;
        fw_printf("done!\n");
 
-       fw_printf("Creating a new Instance of %s...", fw_component_names[0x0D]);
-       if ((fw_component_instances[i] = fw_component_operations[0x0D]->_new(i, 0, NULL)) == NULL) {
+       fw_printf("Creating a new Instance of %s...", fw_component_name(0x0D));
+       if (fw_component_new(0x0D, 3, NULL) == NULL) {
                fw_panic("failed to allocate component\n");
                /* never reached */;
        };
        fw_printf("done!\n");
 
-       fw_free(temp);
+       fw_free(pipes.pipes);
 
        return 0;
 }
index 8d9d486..d8489ce 100644 (file)
@@ -3,9 +3,6 @@
 
 
 #define NUM_LINKS 4
-#define NUM_CPUS 2
-
-#define NUM_INSTANCES 4
 
 int fw_build_module_list[4] = {0x01, 0x02, 0x03, 0x0D};
 
@@ -18,21 +15,16 @@ extern fw_pipe_t **fw_fw_dispatch_pipe;
 int fw_build_topo(void)
 {
        int i;
-       fw_pipe_t **temp;
-
-       fw_num_instances = NUM_INSTANCES;
+       fw_pipe_array_t pipes;
 
-       if ((fw_component_instances = fw_malloc(fw_num_instances * sizeof(fw_component_inst_t*))) == NULL) {
-                       fw_panic("failed to allocate memory for instance references\n");
-                       /* never reached */;
-       }
+       pipes.magic = FW_PIPE_ARRAY_MAGIC;
 
        if ((topo_pipes = fw_malloc(NUM_LINKS * sizeof(fw_pipe_t *))) == NULL) {
                        fw_panic("failed to allocate memory for pipes\n");
                        /* never reached */;
        }
 
-       if ((fw_fw_dispatch_pipe = fw_malloc(NUM_CPUS * sizeof(fw_pipe_t *))) == NULL) {
+       if ((fw_fw_dispatch_pipe = fw_malloc(fw_num_cpus() * sizeof(fw_pipe_t *))) == NULL) {
                        fw_panic("failed to allocate memory for dispatching pipes\n");
                        /* never reached */;
        }
@@ -55,56 +47,51 @@ int fw_build_topo(void)
        }
 
        /* create default topo_links */
-
        fw_fw_dispatch_pipe[0] = topo_pipes[2];
        fw_fw_dispatch_pipe[1] = topo_pipes[3];
 
        /* link modules */
-
-       i=0;
-
-       temp = fw_malloc((NUM_CPUS+1) * sizeof(fw_pipe_t*));
-
-       fw_printf("Creating a new Instance of %s...", fw_component_names[0x02]);
-       temp[0] = fw_fw_ready_pipe;
-       temp[1] = topo_pipes[0];
-       temp[2] = topo_pipes[1];
-       if ((fw_component_instances[i] = fw_component_operations[0x02]->_new(i, NUM_CPUS+1, temp)) == NULL) {
+       pipes.size = 3;
+       pipes.pipes = fw_malloc(pipes.size * sizeof(fw_pipe_t*));
+
+       fw_printf("Creating a new Instance of %s...", fw_component_name(0x03));
+       pipes.pipes[0] = fw_fw_ready_pipe;
+       pipes.pipes[1] = topo_pipes[0];
+       pipes.pipes[2] = topo_pipes[1];
+       if (fw_component_new(0x02, 0, &pipes) == NULL) {
                fw_panic("failed to allocate component\n");
                /* never reached */;
-       }
-       i++;
+       };
        fw_printf("done!\n");
 
-
-       fw_printf("Creating a new Instance of %s...", fw_component_names[0x01]);
-       temp[0] = topo_pipes[0];
-       temp[1] = topo_pipes[2];
-       if ((fw_component_instances[i] = fw_component_operations[0x01]->_new(i, 2, temp)) == NULL) {
+       fw_printf("Creating a new Instance of %s...", fw_component_name(0x01));
+       pipes.size = 2;
+       pipes.pipes[0] = topo_pipes[0];
+       pipes.pipes[1] = topo_pipes[2];
+       if (fw_component_new(0x01, 1, &pipes) == NULL) {
                fw_panic("failed to allocate component\n");
                /* never reached */;
        };
-       i++;
        fw_printf("done!\n");
 
-       fw_printf("Creating a new Instance of %s...", fw_component_names[0x03]);
-       temp[0] = topo_pipes[1];
-       temp[1] = topo_pipes[3];
-       if ((fw_component_instances[i] = fw_component_operations[0x03]->_new(i, 2, temp)) == NULL) {
+       fw_printf("Creating a new Instance of %s...", fw_component_name(0x02));
+       pipes.size = 2;
+       pipes.pipes[0] = topo_pipes[1];
+       pipes.pipes[1] = topo_pipes[3];
+       if (fw_component_new(0x01, 2, &pipes) == NULL) {
                fw_panic("failed to allocate component\n");
                /* never reached */;
        };
-       i++;
        fw_printf("done!\n");
 
-       fw_printf("Creating a new Instance of %s...", fw_component_names[0x0D]);
-       if ((fw_component_instances[i] = fw_component_operations[0x0D]->_new(i, 0, NULL)) == NULL) {
+       fw_printf("Creating a new Instance of %s...", fw_component_name(0x0D));
+       if (fw_component_new(0x0D, 3, NULL) == NULL) {
                fw_panic("failed to allocate component\n");
                /* never reached */;
        };
        fw_printf("done!\n");
 
-       fw_free(temp);
+       fw_free(pipes.pipes);
 
        return 0;
 }
index 20e2b3e..03d4408 100644 (file)
@@ -27,7 +27,9 @@ extern fw_pipe_t **fw_fw_dispatch_pipe;
 int fw_build_topo(void)
 {
        int i, num_links;
-       fw_pipe_t **temp;
+       fw_pipe_array_t pipes;
+
+       pipes.magic = FW_PIPE_ARRAY_MAGIC;
 
        num_links = fw_num_cpus() * 2;
 
@@ -63,24 +65,26 @@ int fw_build_topo(void)
                fw_fw_dispatch_pipe[i] = topo_pipes[i];
 
        /* link modules */
-       temp = fw_malloc((fw_num_cpus()+1) * sizeof(fw_pipe_t*));
+       pipes.size = fw_num_cpus()+1;
+       pipes.pipes = fw_malloc(pipes.size * sizeof(fw_pipe_t*));
 
        fw_printf("Creating a new Instance of %s...", fw_component_name(0x02));
-       temp[0] = fw_fw_ready_pipe;
+       pipes.pipes[0] = fw_fw_ready_pipe;
        for (i=0; i<fw_num_cpus(); i++)
-               temp[i+1] = topo_pipes[fw_num_cpus()+i];
+               pipes.pipes[i+1] = topo_pipes[fw_num_cpus()+i];
 
-       if (fw_component_new(0x02, 0, fw_num_cpus()+1, temp) == NULL) {
+       if (fw_component_new(0x02, 0, &pipes) == NULL) {
                fw_panic("failed to allocate component\n");
                /* never reached */;
        }
        fw_printf("done!\n");
 
+       pipes.size = 2;
        for (i=0;i<fw_num_cpus();i++) {
                fw_printf("Creating a new Instance of %s...", fw_component_name(0x01));
-               temp[0] = topo_pipes[fw_num_cpus()+i];
-               temp[1] = topo_pipes[i];
-               if (fw_component_new(0x01, i+1, 2, temp) == NULL) {
+               pipes.pipes[0] = topo_pipes[fw_num_cpus()+i];
+               pipes.pipes[1] = topo_pipes[i];
+               if (fw_component_new(0x01, i+1, &pipes) == NULL) {
                        fw_panic("failed to allocate component\n");
                        /* never reached */;
                };
@@ -88,13 +92,13 @@ int fw_build_topo(void)
        }
 
        fw_printf("Creating a new Instance of %s...", fw_component_name(0x0D));
-       if (fw_component_new(0x0D, i+1, 0, NULL) == NULL) {
+       if (fw_component_new(0x0D, i+1, NULL) == NULL) {
                fw_panic("failed to allocate component\n");
                /* never reached */;
        };
        fw_printf("done!\n");
 
-       fw_free(temp);
+       fw_free(pipes.pipes);
 
 
        return 0;
index 656c22c..c6b2f13 100644 (file)
@@ -19,9 +19,6 @@
 
 
 #define NUM_LINKS 8
-#define NUM_CPUS 4
-
-#define NUM_INSTANCES 6
 
 int fw_build_module_list[3] = {0x01, 0x02, 0x0D};
 
@@ -34,21 +31,16 @@ extern fw_pipe_t **fw_fw_dispatch_pipe;
 int fw_build_topo(void)
 {
        int i;
-       fw_pipe_t **temp;
-
-       fw_num_instances = NUM_INSTANCES;
+       fw_pipe_array_t pipes;
 
-       if ((fw_component_instances = fw_malloc(fw_num_instances * sizeof(fw_component_inst_t*))) == NULL) {
-                       fw_panic("failed to allocate memory for instance references\n");
-                       /* never reached */;
-       }
+       pipes.magic = FW_PIPE_ARRAY_MAGIC;
 
        if ((topo_pipes = fw_malloc(NUM_LINKS * sizeof(fw_pipe_t *))) == NULL) {
                        fw_panic("failed to allocate memory for pipes\n");
                        /* never reached */;
        }
 
-       if ((fw_fw_dispatch_pipe = fw_malloc(NUM_CPUS * sizeof(fw_pipe_t *))) == NULL) {
+       if ((fw_fw_dispatch_pipe = fw_malloc(fw_num_cpus() * sizeof(fw_pipe_t *))) == NULL) {
                        fw_panic("failed to allocate memory for dispatching pipes\n");
                        /* never reached */;
        }
@@ -71,80 +63,75 @@ int fw_build_topo(void)
        }
 
        /* create default topo_links */
-
        fw_fw_dispatch_pipe[0] = topo_pipes[4];
        fw_fw_dispatch_pipe[1] = topo_pipes[5];
        fw_fw_dispatch_pipe[2] = topo_pipes[6];
        fw_fw_dispatch_pipe[3] = topo_pipes[7];
 
        /* link modules */
-
-       i=0;
-
-       temp = fw_malloc((NUM_CPUS+1) * sizeof(fw_pipe_t*));
-
-       fw_printf("Creating a new Instance of %s...", fw_component_names[0x02]);
-       temp[0] = fw_fw_ready_pipe;
-       temp[1] = topo_pipes[0];
-       temp[2] = topo_pipes[1];
-       temp[3] = topo_pipes[2];
-       temp[4] = topo_pipes[3];
-       if ((fw_component_instances[i] = fw_component_operations[0x02]->_new(i, NUM_CPUS+1, temp)) == NULL) {
+       pipes.size = 5;
+       pipes.pipes = fw_malloc(pipes.size * sizeof(fw_pipe_t*));
+
+       fw_printf("Creating a new Instance of %s...", fw_component_name(0x02));
+       pipes.pipes[0] = fw_fw_ready_pipe;
+       pipes.pipes[1] = topo_pipes[0];
+       pipes.pipes[2] = topo_pipes[1];
+       pipes.pipes[3] = topo_pipes[2];
+       pipes.pipes[4] = topo_pipes[3];
+       if (fw_component_new(0x02, 0, &pipes) == NULL) {
                fw_panic("failed to allocate component\n");
                /* never reached */;
-       }
-       i++;
+       };
        fw_printf("done!\n");
 
-
-       fw_printf("Creating a new Instance of %s...", fw_component_names[0x01]);
-       temp[0] = topo_pipes[0];
-       temp[1] = topo_pipes[4];
-       if ((fw_component_instances[i] = fw_component_operations[0x01]->_new(i, 2, temp)) == NULL) {
+       fw_printf("Creating a new Instance of %s...", fw_component_name(0x01));
+       pipes.size = 2;
+       pipes.pipes[0] = topo_pipes[0];
+       pipes.pipes[1] = topo_pipes[4];
+       if (fw_component_new(0x01, 1, &pipes) == NULL) {
                fw_panic("failed to allocate component\n");
                /* never reached */;
        };
-       i++;
        fw_printf("done!\n");
 
-       fw_printf("Creating a new Instance of %s...", fw_component_names[0x01]);
-       temp[0] = topo_pipes[1];
-       temp[1] = topo_pipes[5];
-       if ((fw_component_instances[i] = fw_component_operations[0x01]->_new(i, 2, temp)) == NULL) {
+       fw_printf("Creating a new Instance of %s...", fw_component_name(0x01));
+       pipes.size = 2;
+       pipes.pipes[0] = topo_pipes[1];
+       pipes.pipes[1] = topo_pipes[5];
+       if (fw_component_new(0x01, 2, &pipes) == NULL) {
                fw_panic("failed to allocate component\n");
                /* never reached */;
        };
-       i++;
        fw_printf("done!\n");
 
-       fw_printf("Creating a new Instance of %s...", fw_component_names[0x01]);
-       temp[0] = topo_pipes[2];
-       temp[1] = topo_pipes[6];
-       if ((fw_component_instances[i] = fw_component_operations[0x01]->_new(i, 2, temp)) == NULL) {
+       fw_printf("Creating a new Instance of %s...", fw_component_name(0x01));
+       pipes.size = 2;
+       pipes.pipes[0] = topo_pipes[2];
+       pipes.pipes[1] = topo_pipes[6];
+       if (fw_component_new(0x01, 3, &pipes) == NULL) {
                fw_panic("failed to allocate component\n");
                /* never reached */;
        };
-       i++;
        fw_printf("done!\n");
 
-       fw_printf("Creating a new Instance of %s...", fw_component_names[0x01]);
-       temp[0] = topo_pipes[3];
-       temp[1] = topo_pipes[7];
-       if ((fw_component_instances[i] = fw_component_operations[0x01]->_new(i, 2, temp)) == NULL) {
+       fw_printf("Creating a new Instance of %s...", fw_component_name(0x01));
+       pipes.size = 2;
+       pipes.pipes[0] = topo_pipes[3];
+       pipes.pipes[1] = topo_pipes[7];
+       if (fw_component_new(0x01, 4, &pipes) == NULL) {
                fw_panic("failed to allocate component\n");
                /* never reached */;
        };
-       i++;
        fw_printf("done!\n");
 
-       fw_printf("Creating a new Instance of %s...", fw_component_names[0x0D]);
-       if ((fw_component_instances[i] = fw_component_operations[0x0D]->_new(i, 0, NULL)) == NULL) {
+       fw_printf("Creating a new Instance of %s...", fw_component_name(0x0D));
+       if (fw_component_new(0x0D, 5, NULL) == NULL) {
                fw_panic("failed to allocate component\n");
                /* never reached */;
        };
        fw_printf("done!\n");
 
-       fw_free(temp);
+       fw_free(pipes.pipes);
 
        return 0;
 }
index bb8a960..7ad9596 100644 (file)
 
 #include <fw.h>
 
-
-
 #define NUM_LINKS 2
-#define NUM_CPUS 1
-
-#define NUM_INSTANCES 3
 
-int fw_build_module_list[3] = {0x01, 0x02, 0x0D};
+int fw_build_module_list[2] = {0x01, 0x02};
 
 fw_pipe_t **topo_pipes;
 
@@ -29,20 +24,16 @@ extern fw_pipe_t **fw_fw_dispatch_pipe;
 int fw_build_topo(void)
 {
        int i;
+       fw_pipe_array_t pipes;
 
-       fw_num_instances = NUM_INSTANCES;
-
-       if ((fw_component_instances = fw_malloc(fw_num_instances * sizeof(fw_component_inst_t*))) == NULL) {
-                       fw_panic("failed to allocate memory for instance references\n");
-                       /* never reached */;
-       }
+       pipes.magic = FW_PIPE_ARRAY_MAGIC;
 
        if ((topo_pipes = fw_malloc(NUM_LINKS * sizeof(fw_pipe_t *))) == NULL) {
                        fw_panic("failed to allocate memory for pipes\n");
                        /* never reached */;
        }
 
-       if ((fw_fw_dispatch_pipe = fw_malloc(NUM_CPUS * sizeof(fw_pipe_t *))) == NULL) {
+       if ((fw_fw_dispatch_pipe = fw_malloc(fw_num_cpus() * sizeof(fw_pipe_t *))) == NULL) {
                        fw_panic("failed to allocate memory for dispatching pipes\n");
                        /* never reached */;
        }
@@ -65,33 +56,38 @@ int fw_build_topo(void)
        }
 
        /* create default topo_links */
-
        fw_fw_dispatch_pipe[0] = topo_pipes[1];
 
        /* link modules */
+       pipes.size = 2;
+       pipes.pipes = fw_malloc(pipes.size * sizeof(fw_pipe_t*));
 
-       i=0;
-
-       fw_printf("Creating a new Instance of %s...", fw_component_names[0x02]);
-       if ((fw_component_instances[0] = fw_component_operations[0x02]->_new(i++, NUM_CPUS+1, fw_fw_ready_pipe, topo_pipes[0])) == NULL) {
+       fw_printf("Creating a new Instance of %s...", fw_component_name(0x02));
+       pipes.pipes[0] = fw_fw_ready_pipe;
+       pipes.pipes[1] = topo_pipes[0];
+       if (fw_component_new(0x02, 0, &pipes) == NULL) {
                fw_panic("failed to allocate component\n");
                /* never reached */;
-       }
+       };
        fw_printf("done!\n");
 
-       fw_printf("Creating a new Instance of %s...", fw_component_names[0x01]);
-       if ((fw_component_instances[1] = fw_component_operations[0x01]->_new(i++, 2, topo_pipes[0], topo_pipes[1])) == NULL) {
+       fw_printf("Creating a new Instance of %s...", fw_component_name(0x01));
+       pipes.pipes[0] = topo_pipes[0];
+       pipes.pipes[1] = topo_pipes[1];
+       if (fw_component_new(0x01, 1, &pipes) == NULL) {
                fw_panic("failed to allocate component\n");
                /* never reached */;
        };
        fw_printf("done!\n");
 
-       fw_printf("Creating a new Instance of %s...", fw_component_names[0x0D]);
-       if ((fw_component_instances[2] = fw_component_operations[0x0D]->_new(i++, 0)) == NULL) {
+       fw_printf("Creating a new Instance of %s...", fw_component_name(0x0D));
+       if (fw_component_new(0x0D, 2, NULL) == NULL) {
                fw_panic("failed to allocate component\n");
                /* never reached */;
        };
        fw_printf("done!\n");
 
+       fw_free(pipes.pipes);
+
        return 0;
 }
index 6cc1054..3690205 100644 (file)
@@ -27,26 +27,24 @@ extern fw_pipe_t **fw_fw_dispatch_pipe;
 
 int fw_build_topo(void)
 {
-       int i;
+       int i, num_links;
+       fw_pipe_array_t pipes;
 
-       fw_num_instances = NUM_INSTANCES;
+       pipes.magic = FW_PIPE_ARRAY_MAGIC;
 
-       if ((fw_component_instances = fw_malloc(fw_num_instances * sizeof(fw_component_inst_t*))) == NULL) {
-                       fw_panic("failed to allocate memory for instance references\n");
-                       /* never reached */;
-       }
+       num_links = 1;
 
-       if ((topo_pipes = fw_malloc(NUM_LINKS * sizeof(fw_pipe_t *))) == NULL) {
+       if ((topo_pipes = fw_malloc(num_links * sizeof(fw_pipe_t *))) == NULL) {
                        fw_panic("failed to allocate memory for pipes\n");
                        /* never reached */;
        }
 
-       if ((fw_fw_dispatch_pipe = fw_malloc(NUM_CPUS * sizeof(fw_pipe_t *))) == NULL) {
+       if ((fw_fw_dispatch_pipe = fw_malloc(fw_num_cpus() * sizeof(fw_pipe_t *))) == NULL) {
                        fw_panic("failed to allocate memory for dispatching pipes\n");
                        /* never reached */;
        }
 
-       for (i=0; i<NUM_LINKS; i++) {
+       for (i=0; i<num_links; i++) {
                topo_pipes[i] = fw_pipe_alloc();
                if (topo_pipes[i] == NULL) {
                        fw_panic("failed to allocate pipes\n");
@@ -64,15 +62,23 @@ int fw_build_topo(void)
        }
 
        /* create default topo_links */
-
        fw_fw_dispatch_pipe[0] = topo_pipes[0];
 
        /* link modules */
-       i=0;
-
-       fw_printf("Creating a new Instance of %s...", fw_component_names[0x01]);
-       fw_component_instances[0] = fw_component_operations[0x01]->_new(i++, 2, fw_fw_ready_pipe, fw_fw_dispatch_pipe[0]);
+       pipes.size = 2;
+       pipes.pipes = fw_malloc(pipes.size * sizeof(fw_pipe_t*));
+
+       fw_printf("Creating a new Instance of %s...", fw_component_name(0x01));
+       pipes.pipes[0] = fw_fw_ready_pipe;
+       pipes.pipes[1] = topo_pipes[0];
+       if (fw_component_new(0x01, 0, &pipes) == NULL) {
+               fw_panic("failed to allocate component\n");
+               /* never reached */;
+       };
        fw_printf("done!\n");
 
+       fw_free(pipes.pipes);
+
        return 0;
+
 }