Completely refactored locking to use only native locking facilities. It is to fragile...
authorAnselm Busse <anselm.busse@tu-berlin.de>
Tue, 26 Jan 2016 19:26:25 +0000 (20:26 +0100)
committerAnselm Busse <anselm.busse@tu-berlin.de>
Tue, 26 Jan 2016 19:26:25 +0000 (20:26 +0100)
15 files changed:
framework/include/fw.h
framework/include/fw_components.h [moved from framework/include/fw_modules.h with 100% similarity]
framework/include/fw_lock.h
framework/include/fw_pipe.h
framework/include/os/linux.h
framework/include/os_lock.h
framework/lib/fw_components.c [moved from framework/lib/fw_modules.c with 100% similarity]
framework/lib/fw_lock.c [deleted file]
framework/lib/fw_pipe.c
framework/lib/fw_sched.c
framework/modules/fcfs.c
framework/modules/load_balance.c
framework/modules/round_robin.c
framework/os/linux/Makefile
framework/os/linux/os_lock.c [deleted file]

index fef605c..59da3d6 100644 (file)
 #include <fw_irq.h>
 #include <fw_lock.h>
 #include <fw_sched.h>
-#include <fw_modules.h>
 #include <fw_pipe.h>
 
 #include <fw_debug.h>
+#include "fw_components.h"
 
 /**
  * \brief A printf function.
index eb3d57f..315345f 100644 (file)
 #ifndef FW_LOCK_H_
 #define FW_LOCK_H_
 
-#include <fw_irq.h>
 #include <os.h>
 
-/**
- * Definition of a locked spinlock in CoBaS
- */
-#define FW_SPINLOCK_LOCKED (fw_raw_spinlock_t) {1}
-/**
- * Definition of an ulocked spinlock in CoBaS
- */
-#define FW_SPINLOCK_UNLOCKED (fw_raw_spinlock_t) {0}
-/**
- * Creates an unlocked spinlock with the given name.
- */
-#define FW_SPINLOCK_CREATE(name) fw_spinlock_t name = {{0}}
+#define fw_spinlock_t os_spinlock_t
 
-/**
- * Definition of the content of a raw spinlock.
- */
-typedef struct {
-       volatile unsigned int slock;    /**< Te lock variable */
-} fw_raw_spinlock_t;
 
 /**
- * Definition of a spinlock in CoBaS
+ * Defines an unlocked spinlock with the given name.
  */
-typedef struct {
-       fw_raw_spinlock_t raw_lock;
-} fw_spinlock_t;
+#define FW_DEFINE_SPINLOCK(name) OS_DEFINE_SPINLOCK(name)
+
 
 /**
  * \brief Locks the given spinlock.
@@ -48,7 +29,7 @@ typedef struct {
  *
  * @param lock The lock to operate on.
  */
-void fw_spinlock(fw_spinlock_t *lock);
+#define fw_spin_lock(lock) os_spin_lock(lock)
 
 /**
  * \brief Unlocks the given spinlock.
@@ -57,7 +38,7 @@ void fw_spinlock(fw_spinlock_t *lock);
  *
  * @param lock The lock to operate on.
  */
-void fw_spinunlock(fw_spinlock_t *lock);
+#define fw_spin_unlock(lock) os_spin_unlock(lock)
 
 /**
  * \brief Locks the given spinlock and disables interrupts.
@@ -67,7 +48,7 @@ void fw_spinunlock(fw_spinlock_t *lock);
  *
  * @param lock The lock to operate on.
  */
-void fw_spinlock_irq(fw_spinlock_t *lock);
+#define fw_spin_lock_irq(lock) os_spin_lock_irq(lock)
 
 /**
  * \brief Unlocks the given spinlock and enables the interrupts
@@ -76,7 +57,7 @@ void fw_spinlock_irq(fw_spinlock_t *lock);
  *
  * @param lock The lock to operate on.
  */
-void fw_spinunlock_irq(fw_spinlock_t *lock);
+#define fw_spin_unlock_irq(lock) os_unlock_irq(lock)
 
 /**
  * \brief Locks the given spinlock, disables interrupts and save the interrupt
@@ -87,7 +68,7 @@ void fw_spinunlock_irq(fw_spinlock_t *lock);
  *
  * @param lock The lock to operate on.
  */
-void fw_spinlock_irqsave(fw_spinlock_t *lock, fw_irq_flags *flags);
+#define fw_spin_lock_irqsave(lock, flags) os_spin_lock_irqsave(lock, flags)
 
 /**
  * \brief Unlocks the given spinlock, enables the interrupts and restores the
@@ -99,6 +80,8 @@ void fw_spinlock_irqsave(fw_spinlock_t *lock, fw_irq_flags *flags);
  * @param lock The lock to operate on.
  * @param flags The flags to restore.
  */
-void fw_spinunlock_irqrestore(fw_spinlock_t *lock, fw_irq_flags *flags);
+#define fw_spin_unlock_irqrestore(lock, flags) os_spin_unlock_irqrestore(lock, flags)
+
+#define fw_spin_lock_init(lock) os_spin_lock_init(lock)
 
 #endif /* FW_LOCK_H_ */
index 664e962..ff0cad1 100644 (file)
@@ -16,7 +16,7 @@
 #include <fw_pipe_pcb.h>
 #include <fw_lock.h>
 #include <fw_list.h>
-#include <fw_modules.h>
+#include "fw_components.h"
 
 /**
  * @brief Definition of the CoBaS Pipe structure.
index 3850be4..6200fad 100644 (file)
@@ -72,6 +72,19 @@ extern unsigned int smp_started;
 #define fw_size_t unsigned long
 
 
+#define os_spinlock_t spinlock_t
+
+#define os_spin_lock(lock) spin_lock(lock)
+#define os_spin_unlock(lock) spin_unlock(lock)
+#define os_spin_lock_irq(lock) spin_lock_irq(lock)
+#define os_spin_unlock_irq(lock) spin_unlock_irq(lock)
+#define os_spin_lock_irqsave(lock, flags) spin_lock_irqsave(lock, flags)
+#define os_spin_unlock_irqrestore(lock, flags) spin_unlock_irqrestore(lock, flags)
+
+#define os_spin_lock_init(lock) raw_spin_lock_init(&(lock)->rlock)
+
+#define OS_DEFINE_SPINLOCK(name) DEFINE_SPINLOCK(name)
+
 ///*
 // * Macros for locking.
 // */
index 2eb04d3..375b323 100644 (file)
@@ -8,20 +8,40 @@
 #ifndef OS_LOCK_H_
 #define OS_LOCK_H_
 
-#include "fw_lock.h"
 #include <os_irq.h>
 
 
-void os_spinlock(fw_spinlock_t *lock);
 
-void os_spinunlock(fw_spinlock_t *lock);
+#ifndef OS_DEFINE_SPINLOCK
+       #error 'OS_DEFINE_SPINLOCK' not defined for the current platform
+#endif
 
-void os_spinlock_irq(fw_spinlock_t *lock);
+#ifndef os_spin_lock
+       #error 'os_spinlock' not defined for the current platform
+#endif
 
-void os_spinunlock_irq(fw_spinlock_t *lock);
+#ifndef os_spin_unlock
+       #error 'os_spinunlock' not defined for the current platform
+#endif
 
-void os_spinlock_irqsave(fw_spinlock_t *lock, os_irq_flags *flags);
+#ifndef os_spin_lock_irq
+       #error 'os_spinlock_irq' not defined for the current platform
+#endif
 
-void os_spinunlock_irqrestore(fw_spinlock_t *lock, os_irq_flags *flags);
+#ifndef os_spin_unlock_irq
+       #error 'os_spinunlock_irq' not defined for the current platform
+#endif
+
+#ifndef os_spin_lock_irqsave
+       #error 'os_spinlock_irqsave' not defined for the current platform
+#endif
+
+#ifndef os_spin_unlock_irqrestore
+       #error 'os_spinunlock_irqrestore' not defined for the current platform
+#endif
+
+#ifndef os_spin_lock_init
+       #error 'os_spin_lock_init' not defined for the current platform
+#endif
 
 #endif /* OS_LOCK_H_ */
diff --git a/framework/lib/fw_lock.c b/framework/lib/fw_lock.c
deleted file mode 100644 (file)
index b837bdb..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/**
- * @file fw_lock.c
- * @author Anselm Busse
- * @date 25 Jan 2015
- *
- * This file contains the implementations of locks in CoBaS. They are mostly
- * wrappers around the OS specific functions.
- */
-
-#include <fw_lock.h>
-
-void fw_spinlock(fw_spinlock_t *lock)
-{
-       os_spinlock(lock);
-}
-
-void fw_spinunlock(fw_spinlock_t *lock)
-{
-       os_spinunlock(lock);
-}
-
-void fw_spinlock_irq(fw_spinlock_t *lock)
-{
-       os_spinlock_irq(lock);
-}
-
-void fw_spinunlock_irq(fw_spinlock_t *lock)
-{
-       os_spinunlock_irq(lock);
-}
-
-void fw_spinlock_irqsave(fw_spinlock_t *lock, fw_irq_flags *flags)
-{
-       os_spinlock_irqsave(lock, flags);
-}
-
-void fw_spinunlock_irqrestore(fw_spinlock_t *lock, fw_irq_flags *flags)
-{
-       os_spinunlock_irqrestore(lock, flags);
-}
index 0fd3087..3201bf6 100644 (file)
@@ -31,7 +31,7 @@ fw_pipe_t *fw_pipe_alloc(void)
        FW_LIST_INIT(_new->tasks_removed);
        FW_LIST_INIT(_new->tasks_moved);
 
-       _new->lock.raw_lock = FW_SPINLOCK_UNLOCKED;
+       fw_spin_lock_init(&_new->lock);
 
        _new->out = &fw_pipe_termination;
        _new->in = &fw_pipe_termination;
@@ -58,7 +58,7 @@ static void fw_pipe_termination_update(fw_component_inst *self, fw_pipe_t *pipe)
 {
        fw_task_t *pos, *n;
 
-       fw_spinlock(&pipe->lock);
+       fw_spin_lock(&pipe->lock);
 
        fw_list_for_each_entry_safe(pos,n,(&pipe->tasks_added),pipe_pcb[pipe->id].added) {
                fw_list_del(&pos->pipe_pcb[pipe->id].added);
@@ -72,7 +72,7 @@ static void fw_pipe_termination_update(fw_component_inst *self, fw_pipe_t *pipe)
                fw_list_del(&pos->pipe_pcb[pipe->id].moved);
        }
 
-       fw_spinunlock(&pipe->lock);
+       fw_spin_unlock(&pipe->lock);
 }
 
 int fw_pipes_init() {
index 414ad50..46173b0 100644 (file)
@@ -18,7 +18,7 @@ fw_pipe_t **fw_fw_dispatch_pipe;
 fw_component_inst **fw_fw_dispatch_inst;
 
 char fw_sched_buf[127] = {0};
-FW_SPINLOCK_CREATE(fw_lock);
+FW_DEFINE_SPINLOCK(fw_lock);
 
 static void __fw_admit(fw_component_inst *self, fw_admit_msg_t *admit)
 {
@@ -32,12 +32,12 @@ static void __fw_admit(fw_component_inst *self, fw_admit_msg_t *admit)
 
        task->state = FW_READY;
 
-       fw_spinlock(&fw_fw_ready_pipe->lock);
+       fw_spin_lock(&fw_fw_ready_pipe->lock);
 
        fw_list_add_tail(&task->pipe_pcb[fw_fw_ready_pipe->id].list, &fw_fw_ready_pipe->tasks_list);
        fw_list_add_tail(&task->pipe_pcb[fw_fw_ready_pipe->id].added, &fw_fw_ready_pipe->tasks_added);
 
-       fw_spinunlock(&fw_fw_ready_pipe->lock);
+       fw_spin_unlock(&fw_fw_ready_pipe->lock);
 
        fw_fw_ready_pipe->out->ops.pipe_update(fw_fw_ready_pipe->out, fw_fw_ready_pipe);
 }
@@ -64,10 +64,10 @@ void __fw_schedule(int cpu)
                next_task = fw_list_first_entry(&fw_fw_dispatch_pipe[cpu]->tasks_list,fw_task_t,pipe_pcb[fw_fw_dispatch_pipe[cpu]->id].list);
                next_task->state = FW_RUNNING;
 
-               fw_spinlock(&fw_fw_ready_pipe->lock);
+               fw_spin_lock(&fw_fw_ready_pipe->lock);
                fw_list_del(&next_task->pipe_pcb[fw_fw_ready_pipe->id].list);
                fw_list_add_tail(&next_task->pipe_pcb[fw_fw_ready_pipe->id].removed, &fw_fw_ready_pipe->tasks_removed);
-               fw_spinunlock(&fw_fw_ready_pipe->lock);
+               fw_spin_unlock(&fw_fw_ready_pipe->lock);
 
                fw_fw_ready_pipe->out->ops.pipe_update(fw_fw_ready_pipe->out, fw_fw_ready_pipe);
 
@@ -89,12 +89,12 @@ static void __fw_relinquish(fw_component_inst *self, fw_relinquish_msg_t *relinq
        task->state = FW_READY;
 
 
-       fw_spinlock(&fw_fw_ready_pipe->lock);
+       fw_spin_lock(&fw_fw_ready_pipe->lock);
 
        fw_list_add_tail(&task->pipe_pcb[fw_fw_ready_pipe->id].list, &fw_fw_ready_pipe->tasks_list);
        fw_list_add_tail(&task->pipe_pcb[fw_fw_ready_pipe->id].added, &fw_fw_ready_pipe->tasks_added);
 
-       fw_spinunlock(&fw_fw_ready_pipe->lock);
+       fw_spin_unlock(&fw_fw_ready_pipe->lock);
 
        fw_fw_ready_pipe->out->ops.pipe_update(fw_fw_ready_pipe->out, fw_fw_ready_pipe);
 }
@@ -122,12 +122,12 @@ static void __fw_unblock(fw_component_inst *self, fw_unblock_msg_t *unblock)
 
        task->state = FW_READY;
 
-       fw_spinlock(&fw_fw_ready_pipe->lock);
+       fw_spin_lock(&fw_fw_ready_pipe->lock);
 
        fw_list_add_tail(&task->pipe_pcb[fw_fw_ready_pipe->id].list, &fw_fw_ready_pipe->tasks_list);
        fw_list_add_tail(&task->pipe_pcb[fw_fw_ready_pipe->id].added, &fw_fw_ready_pipe->tasks_added);
 
-       fw_spinunlock(&fw_fw_ready_pipe->lock);
+       fw_spin_unlock(&fw_fw_ready_pipe->lock);
 
        fw_fw_ready_pipe->out->ops.pipe_update(fw_fw_ready_pipe->out, fw_fw_ready_pipe);
 }
index f049066..c89f0bb 100644 (file)
@@ -14,7 +14,7 @@ static fw_component_inst fcfs_proto;
 
 typedef struct fcfs_private_data {
        int inst_id;
-       fw_spinlock_t lock;
+       fw_spin_lock_t lock;
 
        unsigned long lamport;
 
@@ -33,9 +33,9 @@ static void fcfs_task_init(fw_component_inst *self, fw_task_t *task)
        fcfs_pcb_t *pcb = fw_malloc(sizeof(fcfs_pcb_t));
        fcfs_private_data_t *pd = inst_data(fcfs_private_data_t);
 
-       fw_spinlock(&pd->lock);
+       fw_spin_lock(&pd->lock);
        time = pd->lamport++;
-       fw_spinunlock(&pd->lock);
+       fw_spin_unlock(&pd->lock);
 
        task->component_pcb[self->id] = pcb;
        pcb->lamport = time;
@@ -53,8 +53,8 @@ static void fcfs_pipe_update(fw_component_inst *self, fw_pipe_t *pipe)
        fcfs_private_data_t *pd = inst_data(fcfs_private_data_t);
        int position;
 
-       fw_spinlock(&pipe->lock);
-       fw_spinlock(&pd->out_pipe->lock);
+       fw_spin_lock(&pipe->lock);
+       fw_spin_lock(&pd->out_pipe->lock);
 
        fw_list_for_each_entry_safe(pos,n,(&pipe->tasks_added),pipe_pcb[pipe->id].added) {
                position = 0;
@@ -77,8 +77,8 @@ static void fcfs_pipe_update(fw_component_inst *self, fw_pipe_t *pipe)
                fw_list_del(&pos->pipe_pcb[pipe->id].removed);
        }
 
-       fw_spinunlock(&pd->out_pipe->lock);
-       fw_spinunlock(&pipe->lock);
+       fw_spin_unlock(&pd->out_pipe->lock);
+       fw_spin_unlock(&pipe->lock);
 
        pd->out_pipe->out->ops.pipe_update(pd->out_pipe->out, pd->out_pipe);
 }
index d3104fe..b5c2ac1 100644 (file)
@@ -17,7 +17,7 @@
 
 //#define LB_CPU_VALID(cpu) (cpu >= 0 && cpu < FW_NR_CPUS)
 
-FW_SPINLOCK_CREATE(lb_lock);
+FW_DEFINE_SPINLOCK(lb_lock);
 
 static fw_component_inst lb_proto;
 
@@ -69,7 +69,7 @@ static void lb_pipe_update(fw_component_inst *self, fw_pipe_t *pipe)
        lb_pcb_t *pcb;
        lb_private_data_t *pd = inst_data(lb_private_data_t);
 
-       fw_spinlock(&pipe->lock);
+       fw_spin_lock(&pipe->lock);
 
        fw_list_for_each_entry_safe(pos,n,(&pipe->tasks_added),pipe_pcb[pipe->id].added) {
                affinity_req.task = pos;
@@ -83,10 +83,10 @@ static void lb_pipe_update(fw_component_inst *self, fw_pipe_t *pipe)
                pcb = pos->component_pcb[self->id];
                pcb->pipe = pd->out_pipe[next_cpu];
 
-               fw_spinlock(&pd->out_pipe[next_cpu]->lock);
+               fw_spin_lock(&pd->out_pipe[next_cpu]->lock);
                fw_list_add_tail(&pos->pipe_pcb[pd->out_pipe[next_cpu]->id].list, &pd->out_pipe[next_cpu]->tasks_list);
                fw_list_add_tail(&pos->pipe_pcb[pd->out_pipe[next_cpu]->id].added, &pd->out_pipe[next_cpu]->tasks_added);
-               fw_spinunlock(&pd->out_pipe[next_cpu]->lock);
+               fw_spin_unlock(&pd->out_pipe[next_cpu]->lock);
 
                fw_list_del(&pos->pipe_pcb[pipe->id].added);
        }
@@ -100,7 +100,7 @@ static void lb_pipe_update(fw_component_inst *self, fw_pipe_t *pipe)
                fw_list_del(&pos->pipe_pcb[pipe->id].removed);
        }
 
-       fw_spinunlock(&pipe->lock);
+       fw_spin_unlock(&pipe->lock);
 
        for(i=0;i<pd->size;i++)
                pd->out_pipe[i]->out->ops.pipe_update(pd->out_pipe[i]->out, pd->out_pipe[i]);
@@ -113,13 +113,13 @@ static void lb_cpu_online(fw_component_inst *self, fw_cpu_status_msg_t *msg)
        if(msg->status != ONLINE)
                return;
 
-       fw_spinlock(&pd->lock);
+       fw_spin_lock(&pd->lock);
 
        fw_printf("PE %d went online\n", msg->cpu);
        cpumask_set_cpu(msg->cpu, &pd->pe_online);
        fw_printf("New online map is 0x%lx", pd->pe_online.bits[0]);
 
-       fw_spinunlock(&pd->lock);
+       fw_spin_unlock(&pd->lock);
 }
 
 static fw_component_inst *lb_new(inst_uuid_t inst_id, int link_count, fw_pipe_t **links)
@@ -155,7 +155,7 @@ static fw_component_inst *lb_new(inst_uuid_t inst_id, int link_count, fw_pipe_t
                pd->out_pipe[i-1]->in = inst;
        }
 
-       pd->lock.raw_lock.slock = 0;
+       fw_spin_lock_init(&pd->lock);
        pd->pe_online.bits[0] = 1UL;
        pd->size = link_count-1;
 
index eeafeb9..321c05a 100644 (file)
@@ -35,8 +35,8 @@ static void rr_pipe_update(fw_component_inst *self, fw_pipe_t *pipe)
        fw_task_t *pos, *n;
        rr_private_data_t *pd = inst_data(rr_private_data_t);
 
-       fw_spinlock(&pipe->lock);
-       fw_spinlock(&pd->out_pipe->lock);
+       fw_spin_lock(&pipe->lock);
+       fw_spin_lock(&pd->out_pipe->lock);
 
        fw_list_for_each_entry_safe(pos,n,(&pipe->tasks_added),pipe_pcb[pipe->id].added) {
                fw_list_add_tail(&pos->pipe_pcb[pd->out_pipe->id].list, &pd->out_pipe->tasks_list);
@@ -50,8 +50,8 @@ static void rr_pipe_update(fw_component_inst *self, fw_pipe_t *pipe)
                fw_list_del(&pos->pipe_pcb[pipe->id].removed);
        }
 
-       fw_spinunlock(&pd->out_pipe->lock);
-       fw_spinunlock(&pipe->lock);
+       fw_spin_unlock(&pd->out_pipe->lock);
+       fw_spin_unlock(&pipe->lock);
 
        pd->out_pipe->out->ops.pipe_update(pd->out_pipe->out, pd->out_pipe);
 }
index e962f56..47e0c59 100644 (file)
@@ -1,10 +1,9 @@
-obj-y += linux_sched.o os.o os_kdb.o os_lock.o os_sched.o os_syscall.o
+obj-y += linux_sched.o os.o os_kdb.o os_sched.o os_syscall.o
 obj-y += ../../lib/fw.o \
                 ../../lib/fw_comm.o \
+                ../../lib/fw_components.o \
                 ../../lib/fw_list.o \
                 ../../lib/fw_irq.o \
-                ../../lib/fw_lock.o \
-                ../../lib/fw_modules.o \
                 ../../lib/fw_pipe.o \
                 ../../lib/fw_sched.o \
                 ../../lib/fw_debug.o
diff --git a/framework/os/linux/os_lock.c b/framework/os/linux/os_lock.c
deleted file mode 100644 (file)
index b67c81c..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-
-
-#include <fw_lock.h>
-#include <os.h>
-
-void os_spinlock(fw_spinlock_t *lock)
-{
-       int i = 0;
-
-       preempt_disable();
-#ifdef CONFIG_SMP
-       while(!OS_LOCK_ACQUIRE(lock)) {
-               if (i++ < 10000000) {
-                       cpu_relax();
-               }
-               else {
-                       os_printf("Acquiring lock %p on CPU %i failed.\n", (void*)lock, FW_TASK_CPU(fw_current_task(fw_cpu_id())));
-                       panic("Deadlock");
-               }
-       }
-#endif
-}
-
-void os_spinunlock(fw_spinlock_t *lock)
-{
-#ifdef CONFIG_SMP
-       int i = 0;
-       while(!OS_LOCK_RELEASE(lock)) {
-               if (i++ < 1000) {
-                       cpu_relax();
-               }
-               else {
-                       os_printf("Releasing lock %p on CPU %i failed.\n", (void*)lock, FW_TASK_CPU(fw_current_task(fw_cpu_id())));
-                       panic("Deadlock");
-               }
-       }
-#endif
-       preempt_enable();
-}
-
-void os_spinlock_irq(fw_spinlock_t *lock)
-{
-       local_irq_disable();
-       os_spinlock(lock);
-}
-
-void os_spinunlock_irq(fw_spinlock_t *lock)
-{
-       os_spinunlock(lock);
-       local_irq_enable();
-}
-
-void os_spinlock_irqsave(fw_spinlock_t *lock, fw_irq_flags *flags)
-{
-       local_irq_save(*flags);
-       os_spinlock(lock);
-}
-
-void os_spinunlock_irqrestore(fw_spinlock_t *lock, fw_irq_flags *flags)
-{
-       os_spinunlock(lock);
-       local_irq_restore(*flags);
-}