forked from xuos/xiuos
Update spinlock to avoid hungry.
This commit is contained in:
@@ -74,7 +74,7 @@ Modification:
|
||||
|
||||
#include "cortex_a9.h"
|
||||
|
||||
#define NR_CPU 1
|
||||
#define NR_CPU 4
|
||||
|
||||
__attribute__((always_inline)) static inline uint32_t user_mode()
|
||||
{
|
||||
|
||||
@@ -233,7 +233,6 @@ struct ICacheDone* hardkernel_icache_init(struct TraceTag* hardkernel_tag)
|
||||
{
|
||||
/* init icache */
|
||||
icache_done.enable();
|
||||
// icache_done.disable();
|
||||
return &icache_done;
|
||||
}
|
||||
|
||||
@@ -241,6 +240,5 @@ struct DCacheDone* hardkernel_dcache_init(struct TraceTag* hardkernel_tag)
|
||||
{
|
||||
/* init dcache */
|
||||
dcache_done.enable();
|
||||
// dcache_done.disable();
|
||||
return &dcache_done;
|
||||
}
|
||||
@@ -216,10 +216,10 @@ bool secondary_cpu_hardkernel_init(int cpu_id, struct TraceTag* _hardkernel_tag)
|
||||
p_intr_driver->sys_irq_init(cpu_id);
|
||||
p_intr_driver->cpu_irq_disable();
|
||||
// cache
|
||||
// p_icache_driver->enable();
|
||||
// p_dcache_driver->enable();
|
||||
p_icache_driver->disable();
|
||||
p_dcache_driver->disable();
|
||||
p_icache_driver->enable();
|
||||
p_dcache_driver->enable();
|
||||
// p_icache_driver->disable();
|
||||
// p_dcache_driver->disable();
|
||||
// clock
|
||||
// p_clock_driver->sys_clock_init();
|
||||
p_intr_driver->single_irq_enable(p_clock_driver->get_clock_int(), cpu_id, 0);
|
||||
|
||||
@@ -25,8 +25,24 @@
|
||||
#include "task.h"
|
||||
#include "trap_common.h"
|
||||
|
||||
#include "list.h"
|
||||
|
||||
struct lock_node {
|
||||
int cpu_id;
|
||||
struct double_list_node node;
|
||||
};
|
||||
|
||||
static struct double_list_node lock_request_guard;
|
||||
static struct lock_node core_lock_request[NR_CPU];
|
||||
static struct spinlock request_lock;
|
||||
bool module_spinlock_use_intr_init(void)
|
||||
{
|
||||
for (int i = 0; i < NR_CPU; i++) {
|
||||
core_lock_request[i].cpu_id = i;
|
||||
doubleListNodeInit(&core_lock_request[i].node);
|
||||
}
|
||||
doubleListNodeInit(&lock_request_guard);
|
||||
spinlock_init(&request_lock, "requestlock");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -44,18 +60,31 @@ void spinlock_init(struct spinlock* lock, char* name)
|
||||
}
|
||||
|
||||
extern int _spinlock_lock(struct spinlock* lock, uint32_t timeout);
|
||||
void _spinlock_unlock(struct spinlock* lock);
|
||||
|
||||
void spinlock_lock(struct spinlock* lock)
|
||||
{
|
||||
if (lock->owner_cpu != SPINLOCK_STATE_UNLOCK && lock->owner_cpu == cur_cpuid()) {
|
||||
ERROR("spinlock %s lock double locked by core %d\n", lock->name, lock->owner_cpu);
|
||||
panic("");
|
||||
}
|
||||
// _spinlock_lock(&request_lock, SPINLOCK_LOCK_WAITFOREVER);
|
||||
// doubleListAddOnBack(&core_lock_request[cur_cpuid()].node, &lock_request_guard);
|
||||
// _spinlock_unlock(&request_lock);
|
||||
|
||||
// while (lock_request_guard.next != &core_lock_request[cur_cpuid()].node)
|
||||
// ;
|
||||
|
||||
_spinlock_lock(lock, SPINLOCK_LOCK_WAITFOREVER);
|
||||
}
|
||||
|
||||
void _spinlock_unlock(struct spinlock* lock);
|
||||
void spinlock_unlock(struct spinlock* lock)
|
||||
{
|
||||
// assert(lock_request_guard.next == &core_lock_request[cur_cpuid()].node);
|
||||
// _spinlock_lock(&request_lock, SPINLOCK_LOCK_WAITFOREVER);
|
||||
// _double_list_del(core_lock_request[cur_cpuid()].node.prev, core_lock_request[cur_cpuid()].node.next);
|
||||
// _spinlock_unlock(&request_lock);
|
||||
|
||||
_spinlock_unlock(lock);
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +55,6 @@ void GetUsrDevPteAttr(uintptr_t* attr)
|
||||
init = 1;
|
||||
|
||||
usr_pte_attr.entry = 0;
|
||||
usr_pte_attr.S = 1;
|
||||
usr_pte_attr.desc_type = PAGE_4K;
|
||||
usr_pte_attr.AP1_0 = AccessPermission_KernelUser;
|
||||
}
|
||||
@@ -70,7 +69,6 @@ void GetDevPteAttr(uintptr_t* attr)
|
||||
init = 1;
|
||||
|
||||
dev_pte_attr.entry = 0;
|
||||
dev_pte_attr.S = 1;
|
||||
dev_pte_attr.desc_type = PAGE_4K;
|
||||
dev_pte_attr.AP1_0 = AccessPermission_KernelOnly;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user