/branches/rcu/kernel/test/tasklet/tasklet1.c |
---|
30,7 → 30,7 |
#include <print.h> |
#include <test.h> |
#include <proc/tasklet.h> |
#include <ddi/tasklet.h> |
#include <synch/waitq.h> |
#include <arch/types.h> |
/branches/rcu/kernel/generic/include/synch/rcu.h |
---|
36,7 → 36,7 |
#define KERN_RCU_H_ |
#include <arch/types.h> |
#include <proc/tasklet.h> |
#include <ddi/tasklet.h> |
#include <arch/barrier.h> |
#include <preemption.h> |
/branches/rcu/kernel/generic/include/ddi/tasklet.h |
---|
0,0 → 1,104 |
/* |
* Copyright (c) 2007 Jan Hudecek |
* Copyright (c) 2006 Jakub Jermar |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
/** @addtogroup genericddi |
* @{ |
*/ |
/** @file |
*/ |
#ifndef KERN_TASKLET_H_ |
#define KERN_TASKLET_H_ |
#include <arch/types.h> |
#include <proc/task.h> |
/** Structure describing a tasklet*/ |
typedef struct tasklet_descriptor |
{ |
/** callback to call */ |
void (*func)(void* data); |
/** parameters to pass to func */ |
void* data; |
/** state of the tasklet one of tasklet_state_enum */ |
uint32_t state; |
struct tasklet_descriptor *next; |
} tasklet_descriptor_t; |
/** Initializes tasklets - except for the tasklet thread */ |
void tasklet_init(void); |
/** |
* Creates and runs the tasklet thread |
* |
* @param kernel_task Pointer to the kernel task - for create_thread |
*/ |
void tasklet_run_tasklet_thread(task_t * kernel_task); |
/** Thread which keeps executing scheduled enabled tasklets |
* @param data not used |
*/ |
void tasklet_thread(void* data); |
/** Executes scheduled enabled tasklets */ |
void tasklet_do(void); |
/** Initializes tasklet structure |
* @param func tasklet callback function to be called |
* @param data pointer to be passed to the tasklet function |
*/ |
tasklet_descriptor_t* tasklet_register(void (*func)(void* data), void* data); |
/** Schedules the tasklet for execution on current CPU |
* @param t tasklet to be scheduled |
*/ |
void tasklet_schedule(tasklet_descriptor_t* t); |
/** Tasklet will not be run, even if scheduled |
* @param t tasklet to be disabled |
*/ |
void tasklet_disable(tasklet_descriptor_t* t); |
/** Tasklet will be run if scheduled |
* @param t tasklet to be enabled |
*/ |
void tasklet_enable(tasklet_descriptor_t* t); |
/** Frees the tasklet structure when no longer needed |
* @param tasklet to be freed |
*/ |
void tasklet_free(tasklet_descriptor_t* t); |
#endif |
/** @} |
*/ |
/branches/rcu/kernel/generic/include/ddi/irq.h |
---|
122,14 → 122,6 |
*/ |
SPINLOCK_DECLARE(lock); |
/** Send EOI before processing the interrupt. |
* This is essential for timer interrupt which |
* has to be acknowledged before doing preemption |
* to make sure another timer interrupt will |
* be eventually generated. |
*/ |
bool preack; |
/** Unique device number. -1 if not yet assigned. */ |
devno_t devno; |
/branches/rcu/kernel/generic/src/synch/rcu.c |
---|
37,19 → 37,21 |
#include <arch.h> |
#include <config.h> |
#include <arch/types.h> |
#include <proc/tasklet.h> |
#include <ddi/tasklet.h> |
#include <synch/spinlock.h> |
#include <time/delay.h> |
#include <panic.h> |
#include <print.h> |
typedef struct { |
typedef struct rcu_global |
{ |
uint32_t current_batch; |
uint32_t completed_batch; |
bool next_batch_waiting; |
} rcu_global_t; |
typedef struct rcu_callback_list { |
typedef struct rcu_callback_list |
{ |
struct rcu_callback_list* next; |
void (*func)(void*); |
void* data; |
57,10 → 59,12 |
} rcu_callback_list_t; |
typedef struct { |
typedef struct rcu_percpu |
{ |
uint32_t current_batch_number; |
uint32_t QS_passed; |
bool QS_pending; |
rcu_callback_list_t* next_batch, *current_batch, *done_batch; |
} rcu_percpu_t; |
73,6 → 77,7 |
_rcu_global.completed_batch = -1; |
_rcu_global.current_batch = -1; |
_rcu_global.next_batch_waiting = -1; |
} |
void rcu_synchronize(void) |
92,7 → 97,7 |
{ |
int i; |
rcu_callback_list_t *rd; |
rd = malloc(sizeof(rcu_callback_list_t), 0); |
rd = malloc(sizeof(rcu_desc), 0); |
rd->func = func; |
rd->data = data; |
rd->next = NULL; |
105,9 → 110,11 |
_rcu_global.next_batch_waiting = true; |
rd->next = _rcu_cpu_lists[0].next_batch; |
for (i=0;i<config.cpu_count;i++) { |
for (i=0;i<config.cpu_count;i++) |
{ |
_rcu_cpu_lists[i].next_batch = rd; |
_rcu_cpu_lists[i].QS_pending = true; |
} |
//TODO:tasklet, after_thread_ran, polishing |
/branches/rcu/kernel/generic/src/main/main.c |
---|
81,7 → 81,7 |
#include <console/klog.h> |
#include <smp/smp.h> |
#include <ddi/ddi.h> |
#include <proc/tasklet.h> |
#include <ddi/tasklet.h> |
/** Global configuration structure. */ |
config_t config; |
220,6 → 220,7 |
tlb_init(); |
ddi_init(); |
tasklet_init(); |
// tasklet_do(); |
arch_post_mm_init(); |
version_print(); |
241,6 → 242,7 |
calibrate_delay_loop(); |
clock_counter_init(); |
// tasklet_do(); |
timeout_init(); |
scheduler_init(); |
task_init(); |
257,7 → 259,9 |
init.tasks[i].size); |
} else |
printf("No init binaries found\n"); |
ipc_init(); |
//tasklet_do(); |
/* |
* Create kernel task. |
274,8 → 278,7 |
panic("can't create kinit thread\n"); |
thread_ready(t); |
//tasklets disabled for debugging purposes |
//tasklet_run_tasklet_thread(k); |
tasklet_run_tasklet_thread(k); |
/* |
* This call to scheduler() will return to kinit, |
/branches/rcu/kernel/generic/src/ddi/tasklet.c |
---|
0,0 → 1,224 |
/* |
* Copyright (c) 2007 Jan Hudecek |
* Copyright (c) 2006 Jakub Jermar |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
/** @addtogroup genericddi |
* @{ |
*/ |
/** @file |
*/ |
#include <arch.h> |
#include <config.h> |
#include <arch/types.h> |
#include <arch/asm.h> |
#include <ddi/tasklet.h> |
#include <synch/spinlock.h> |
#include <time/delay.h> |
#include <proc/thread.h> |
#include <panic.h> |
#include <print.h> |
#include <synch/waitq.h> |
/** Timeout length in the tasklet thread */ |
#define TASKLET_THREAD_SLEEPDELAY 500 |
/** Priority of the tasklet thread */ |
#define TASKLET_THREAD_PRIORITY 10 |
/** Tasklet state enum */ |
typedef enum |
{ |
TASKLET_STATE_NOTACTIVE = 0, |
TASKLET_STATE_SCHEDULED = 1, |
TASKLET_STATE_RUNNING = 2, |
TASKLET_STATE_DISABLED = 4 |
} tasklet_state_enum; |
/** Spinlock protecting list of tasklets */ |
SPINLOCK_INITIALIZE(tasklet_lock); |
/** array of tasklet lists for every CPU */ |
tasklet_descriptor_t** tasklet_list; |
/** Initializes tasklets - except for the tasklet thread */ |
void tasklet_init(void) |
{ |
int i; |
tasklet_list=malloc(sizeof(tasklet_descriptor_t*)*config.cpu_count,0); |
if (tasklet_list==0) |
panic_printf("tasklet list mem not allocated\n"); |
for(i=0;i<config.cpu_count;i++) |
{ |
tasklet_list[i]=0; |
} |
spinlock_initialize(&tasklet_lock, "tasklet_lock"); |
} |
/** |
* Creates and runs the tasklet thread |
* |
* @param kernel_task Pointer to the kernel task - for create_thread |
*/ |
void tasklet_run_tasklet_thread(task_t * kernel_task) |
{ |
thread_t* t= thread_create(&tasklet_thread, NULL, kernel_task, 0, "tasklet_thread", false); |
if (t==NULL) |
{ |
//wtf? |
panic_printf("tasklet thread not created\n"); |
} |
else |
{ |
//dynamical priority should pick the best |
// t->priority = TASKLET_THREAD_PRIORITY; |
thread_ready(t); |
} |
} |
/** Thread which keeps executing scheduled enabled tasklets |
* @param data not used |
*/ |
void tasklet_thread(void* data) |
{ |
waitq_t wq; |
waitq_initialize(&wq); |
while (true) |
{ |
tasklet_do(); |
waitq_sleep_timeout(&wq,(uint32_t)TASKLET_THREAD_SLEEPDELAY,0); |
} |
} |
/** Initializes tasklet structure |
* @param func tasklet callback function to be called |
* @param data pointer to be passed to the tasklet function |
*/ |
tasklet_descriptor_t* tasklet_register(void (*func)(void* data), void* data) |
{ |
tasklet_descriptor_t* tasklet=malloc(sizeof(tasklet_descriptor_t),0); |
tasklet->data = data; |
tasklet->func = func; |
tasklet->state = TASKLET_STATE_NOTACTIVE; |
tasklet->next = 0; |
return tasklet; |
} |
/** Schedules the tasklet for execution on current CPU |
* @param t tasklet to be scheduled |
*/ |
void tasklet_schedule(tasklet_descriptor_t* t) |
{ |
spinlock_lock(&tasklet_lock); |
//clear notactive, running and scheduled flags |
t->state &= TASKLET_STATE_DISABLED; |
//set the scheduled flag |
t->state |= TASKLET_STATE_SCHEDULED; |
t->next=tasklet_list[CPU->id]; |
tasklet_list[CPU->id]=t; |
spinlock_unlock(&tasklet_lock); |
} |
/** Tasklet will not be run, even if scheduled |
* @param t tasklet to be disabled |
*/ |
void tasklet_disable(tasklet_descriptor_t* t) |
{ |
spinlock_lock(&tasklet_lock); |
//set the disabled flag |
t->state |= TASKLET_STATE_DISABLED; |
spinlock_unlock(&tasklet_lock); |
} |
/** Tasklet will be run if scheduled |
* @param t tasklet to be enabled |
*/ |
void tasklet_enable(tasklet_descriptor_t* t) |
{ |
spinlock_lock(&tasklet_lock); |
//clear the disabled flag |
t->state &= ~TASKLET_STATE_DISABLED; |
spinlock_unlock(&tasklet_lock); |
} |
/** Executes scheduled enabled tasklets */ |
void tasklet_do(void) |
{ |
int i; |
spinlock_lock(&tasklet_lock); |
for(i=0;i<config.cpu_count;i++) |
{ |
tasklet_descriptor_t* t = tasklet_list[CPU->id]; |
//empty the queue of tasklets |
tasklet_list[CPU->id]=0; |
while (t) |
{ |
if (!(t->state & TASKLET_STATE_DISABLED)) |
{ |
if (t->func) |
{ |
#ifdef DEBUG |
printf("tasklet - calling tasklet!!!\n"); |
delay((uint32_t)1000000); |
#endif |
t->state = TASKLET_STATE_RUNNING; |
t->func(t->data); |
t->state = TASKLET_STATE_NOTACTIVE; |
} |
else |
panic_printf("tasklet func NULL\n"); |
} |
else |
{ //return it back to the queue of scheduled tasklets |
t->next = tasklet_list[CPU->id]; |
tasklet_list[CPU->id] = t; |
} |
t=t->next; |
} |
//TODO: switch to another CPU, synched with kcpulb, |
} |
spinlock_unlock(&tasklet_lock); |
} |
/** Frees the tasklet structure when no longer needed |
* @param tasklet to be freed |
*/ |
void tasklet_free(tasklet_descriptor_t* t) |
{ |
if (t->state == TASKLET_STATE_NOTACTIVE) |
free(t); |
else |
panic_printf("attempting to free an active tasklet"); |
} |
/branches/rcu/kernel/generic/src/ddi/irq.c |
---|
138,7 → 138,6 |
{ |
link_initialize(&irq->link); |
spinlock_initialize(&irq->lock, "irq.lock"); |
irq->preack = false; |
irq->inr = -1; |
irq->devno = -1; |
irq->trigger = (irq_trigger_t) 0; |
/branches/rcu/kernel/Makefile |
---|
155,6 → 155,7 |
generic/src/ddi/ddi.c \ |
generic/src/ddi/irq.c \ |
generic/src/ddi/device.c \ |
generic/src/ddi/tasklet.c \ |
generic/src/interrupt/interrupt.c \ |
generic/src/main/main.c \ |
generic/src/main/kinit.c \ |
163,7 → 164,6 |
generic/src/proc/scheduler.c \ |
generic/src/proc/thread.c \ |
generic/src/proc/task.c \ |
generic/src/proc/tasklet.c \ |
generic/src/proc/the.c \ |
generic/src/syscall/syscall.c \ |
generic/src/syscall/copy.c \ |
/branches/rcu/kernel/arch/ppc32/src/interrupt.c |
---|
60,19 → 60,11 |
int inum; |
while ((inum = pic_get_pending()) != -1) { |
bool ack = false; |
irq_t *irq = irq_dispatch_and_lock(inum); |
if (irq) { |
/* |
* The IRQ handler was found. |
*/ |
if (irq->preack) { |
/* Acknowledge the interrupt before processing */ |
pic_ack_interrupt(inum); |
ack = true; |
} |
irq->handler(irq, irq->arg); |
spinlock_unlock(&irq->lock); |
} else { |
83,8 → 75,6 |
printf("cpu%d: spurious interrupt (inum=%d)\n", CPU->id, inum); |
#endif |
} |
if (!ack) |
pic_ack_interrupt(inum); |
} |
} |
/branches/rcu/kernel/arch/ia32xen/src/interrupt.c |
---|
176,7 → 176,6 |
ASSERT(n >= IVT_IRQBASE); |
int inum = n - IVT_IRQBASE; |
bool ack = false; |
ASSERT(inum < IRQ_COUNT); |
ASSERT((inum != IRQ_PIC_SPUR) && (inum != IRQ_PIC1)); |
185,12 → 184,6 |
/* |
* The IRQ handler was found. |
*/ |
if (irq->preack) { |
/* Send EOI before processing the interrupt */ |
trap_virtual_eoi(); |
ack = true; |
} |
irq->handler(irq, irq->arg); |
spinlock_unlock(&irq->lock); |
} else { |
201,8 → 194,6 |
printf("cpu%d: spurious interrupt (inum=%d)\n", CPU->id, inum); |
#endif |
} |
if (!ack) |
trap_virtual_eoi(); |
} |
246,4 → 237,3 |
/** @} |
*/ |
/branches/rcu/kernel/arch/amd64/src/interrupt.c |
---|
156,7 → 156,6 |
ASSERT(n >= IVT_IRQBASE); |
int inum = n - IVT_IRQBASE; |
bool ack = false; |
ASSERT(inum < IRQ_COUNT); |
ASSERT((inum != IRQ_PIC_SPUR) && (inum != IRQ_PIC1)); |
165,12 → 164,6 |
/* |
* The IRQ handler was found. |
*/ |
if (irq->preack) { |
/* Send EOI before processing the interrupt */ |
trap_virtual_eoi(); |
ack = true; |
} |
irq->handler(irq, irq->arg); |
spinlock_unlock(&irq->lock); |
} else { |
181,8 → 174,6 |
printf("cpu%d: spurious interrupt (inum=%d)\n", CPU->id, inum); |
#endif |
} |
if (!ack) |
trap_virtual_eoi(); |
} |
/branches/rcu/kernel/arch/ppc64/src/interrupt.c |
---|
60,19 → 60,11 |
int inum; |
while ((inum = pic_get_pending()) != -1) { |
bool ack = false; |
irq_t *irq = irq_dispatch_and_lock(inum); |
if (irq) { |
/* |
* The IRQ handler was found. |
*/ |
if (irq->preack) { |
/* Acknowledge the interrupt before processing */ |
pic_ack_interrupt(inum); |
ack = true; |
} |
irq->handler(irq, irq->arg); |
spinlock_unlock(&irq->lock); |
} else { |
83,8 → 75,6 |
printf("cpu%d: spurious interrupt (inum=%d)\n", CPU->id, inum); |
#endif |
} |
if (!ack) |
pic_ack_interrupt(inum); |
} |
} |
/branches/rcu/kernel/arch/ia32/src/smp/apic.c |
---|
139,14 → 139,7 |
static void l_apic_timer_irq_handler(irq_t *irq, void *arg, ...) |
{ |
/* |
* Holding a spinlock could prevent clock() from preempting |
* the current thread. In this case, we don't need to hold the |
* irq->lock so we just unlock it and then lock it again. |
*/ |
spinlock_unlock(&irq->lock); |
clock(); |
spinlock_lock(&irq->lock); |
} |
/** Initialize APIC on BSP. */ |
169,7 → 162,6 |
io_apic_disable_irqs(0xffff); |
irq_initialize(&l_apic_timer_irq); |
l_apic_timer_irq.preack = true; |
l_apic_timer_irq.devno = device_assign_devno(); |
l_apic_timer_irq.inr = IRQ_CLK; |
l_apic_timer_irq.claim = l_apic_timer_claim; |
/branches/rcu/kernel/arch/ia32/src/interrupt.c |
---|
176,7 → 176,6 |
ASSERT(n >= IVT_IRQBASE); |
int inum = n - IVT_IRQBASE; |
bool ack = false; |
ASSERT(inum < IRQ_COUNT); |
ASSERT((inum != IRQ_PIC_SPUR) && (inum != IRQ_PIC1)); |
185,12 → 184,6 |
/* |
* The IRQ handler was found. |
*/ |
if (irq->preack) { |
/* Send EOI before processing the interrupt */ |
trap_virtual_eoi(); |
ack = true; |
} |
irq->handler(irq, irq->arg); |
spinlock_unlock(&irq->lock); |
} else { |
201,8 → 194,6 |
printf("cpu%d: spurious interrupt (inum=%d)\n", CPU->id, inum); |
#endif |
} |
if (!ack) |
trap_virtual_eoi(); |
} |
/branches/rcu/kernel/arch/ia32/src/drivers/i8254.c |
---|
82,7 → 82,6 |
void i8254_init(void) |
{ |
irq_initialize(&i8254_irq); |
i8254_irq.preack = true; |
i8254_irq.devno = device_assign_devno(); |
i8254_irq.inr = IRQ_CLK; |
i8254_irq.claim = i8254_claim; |