mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-30 14:08:21 +00:00
kernel: remove event_t as it suffered from a lost wakeup issue
This commit is contained in:
@@ -1,12 +0,0 @@
|
|||||||
#ifndef _EVENT_H
|
|
||||||
#define _EVENT_H
|
|
||||||
|
|
||||||
#include <semaphore.h>
|
|
||||||
typedef semaphore_t event_t;
|
|
||||||
|
|
||||||
int event_wait(event_t *event, bool interruptible);
|
|
||||||
void event_signal(event_t *event);
|
|
||||||
|
|
||||||
#define EVENT_INIT(x) SEMAPHORE_INIT(x, 0);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -6,7 +6,6 @@
|
|||||||
|
|
||||||
#include <hashtable.h>
|
#include <hashtable.h>
|
||||||
#include <mutex.h>
|
#include <mutex.h>
|
||||||
#include <event.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <arch/cpu.h>
|
#include <arch/cpu.h>
|
||||||
#include <kernel/abi.h>
|
#include <kernel/abi.h>
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
#include <kernel/vfs.h>
|
#include <kernel/vfs.h>
|
||||||
#include <ringbuffer.h>
|
#include <ringbuffer.h>
|
||||||
#include <semaphore.h>
|
#include <semaphore.h>
|
||||||
#include <event.h>
|
|
||||||
#include <kernel/poll.h>
|
#include <kernel/poll.h>
|
||||||
|
|
||||||
typedef struct pipenode_t {
|
typedef struct pipenode_t {
|
||||||
|
|||||||
@@ -50,7 +50,6 @@
|
|||||||
(sub)->namespace = nsid;
|
(sub)->namespace = nsid;
|
||||||
|
|
||||||
#define PAIR_INIT(pair, opcode, fused, memaccess, nsid) \
|
#define PAIR_INIT(pair, opcode, fused, memaccess, nsid) \
|
||||||
EVENT_INIT(&(pair)->event); \
|
|
||||||
SUB_INIT(&(pair)->sub, opcode, fused, memaccess, nsid);
|
SUB_INIT(&(pair)->sub, opcode, fused, memaccess, nsid);
|
||||||
|
|
||||||
#define SUB_DW0_OPCODE_WRITE 0x1
|
#define SUB_DW0_OPCODE_WRITE 0x1
|
||||||
@@ -222,7 +221,7 @@ typedef struct {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
compentry_t comp;
|
compentry_t comp;
|
||||||
subentry_t sub;
|
subentry_t sub;
|
||||||
event_t event;
|
thread_t *thread;
|
||||||
} entrypair_t;
|
} entrypair_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -277,7 +276,7 @@ static void nvme_dpc(context_t *, dpcarg_t arg) {
|
|||||||
int subid = COMP_CMDINFO_CMDID(queue[pair->completion.index].cmdinfo);
|
int subid = COMP_CMDINFO_CMDID(queue[pair->completion.index].cmdinfo);
|
||||||
pair->entries[subid]->comp = queue[pair->completion.index];
|
pair->entries[subid]->comp = queue[pair->completion.index];
|
||||||
|
|
||||||
event_signal(&pair->entries[subid]->event);
|
sched_wakeup(pair->entries[subid]->thread, SCHED_WAKEUP_REASON_NORMAL);
|
||||||
|
|
||||||
pair->entries[subid] = NULL;
|
pair->entries[subid] = NULL;
|
||||||
semaphore_signal(&pair->entrysem);
|
semaphore_signal(&pair->entrysem);
|
||||||
@@ -311,7 +310,7 @@ static isr_t *msixnewisrforqueue(queuepair_t *queuepair) {
|
|||||||
return isr;
|
return isr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void enqueue(queuepair_t *queuepair, entrypair_t *entries) {
|
static void enqueueandwait(queuepair_t *queuepair, entrypair_t *entries) {
|
||||||
bool intstatus = interrupt_set(false);
|
bool intstatus = interrupt_set(false);
|
||||||
semaphore_wait(&queuepair->entrysem, false);
|
semaphore_wait(&queuepair->entrysem, false);
|
||||||
|
|
||||||
@@ -328,16 +327,10 @@ static void enqueue(queuepair_t *queuepair, entrypair_t *entries) {
|
|||||||
queuepair->submission.index %= queuepair->submission.entrycount;
|
queuepair->submission.index %= queuepair->submission.entrycount;
|
||||||
|
|
||||||
*queuepair->submission.doorbell = queuepair->submission.index;
|
*queuepair->submission.doorbell = queuepair->submission.index;
|
||||||
|
sched_preparesleep(false);
|
||||||
|
entries->thread = _cpu()->thread;
|
||||||
spinlock_release(&queuepair->lock);
|
spinlock_release(&queuepair->lock);
|
||||||
interrupt_set(intstatus);
|
sched_yield();
|
||||||
}
|
|
||||||
|
|
||||||
static void enqueueandwait(queuepair_t *queuepair, entrypair_t *entries) {
|
|
||||||
bool intstatus = interrupt_set(false);
|
|
||||||
|
|
||||||
enqueue(queuepair, entries);
|
|
||||||
event_wait(&entries->event, false);
|
|
||||||
|
|
||||||
interrupt_set(intstatus);
|
interrupt_set(intstatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
#include <semaphore.h>
|
#include <semaphore.h>
|
||||||
#include <kernel/block.h>
|
#include <kernel/block.h>
|
||||||
#include <kernel/pmm.h>
|
#include <kernel/pmm.h>
|
||||||
#include <event.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#define QUEUE_MAX_SIZE 128
|
#define QUEUE_MAX_SIZE 128
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
#include <kernel/scheduler.h>
|
#include <kernel/scheduler.h>
|
||||||
#include <kernel/timekeeper.h>
|
#include <kernel/timekeeper.h>
|
||||||
#include <logging.h>
|
#include <logging.h>
|
||||||
#include <event.h>
|
|
||||||
#include <kernel/slab.h>
|
#include <kernel/slab.h>
|
||||||
#include <kernel/eth.h>
|
#include <kernel/eth.h>
|
||||||
#include <ringbuffer.h>
|
#include <ringbuffer.h>
|
||||||
@@ -26,7 +25,6 @@ typedef struct {
|
|||||||
static scache_t *entryallocator;
|
static scache_t *entryallocator;
|
||||||
|
|
||||||
static thread_t *handlerthread;
|
static thread_t *handlerthread;
|
||||||
static event_t handlerthreadwakeup;
|
|
||||||
|
|
||||||
static thread_t *cleanupthread;
|
static thread_t *cleanupthread;
|
||||||
|
|
||||||
@@ -277,8 +275,6 @@ void arp_init() {
|
|||||||
cleanupthread = sched_newthread(cleanupthreadfn, PAGE_SIZE * 4, 0, NULL, NULL);
|
cleanupthread = sched_newthread(cleanupthreadfn, PAGE_SIZE * 4, 0, NULL, NULL);
|
||||||
__assert(cleanupthread);
|
__assert(cleanupthread);
|
||||||
|
|
||||||
EVENT_INIT(&handlerthreadwakeup);
|
|
||||||
|
|
||||||
MUTEX_INIT(&cachelock);
|
MUTEX_INIT(&cachelock);
|
||||||
|
|
||||||
SEMAPHORE_INIT(&psem, 0);
|
SEMAPHORE_INIT(&psem, 0);
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
#include <kernel/pmm.h>
|
#include <kernel/pmm.h>
|
||||||
#include <kernel/eth.h>
|
#include <kernel/eth.h>
|
||||||
#include <kernel/net.h>
|
#include <kernel/net.h>
|
||||||
#include <event.h>
|
|
||||||
#include <hashtable.h>
|
#include <hashtable.h>
|
||||||
#include <arch/cpu.h>
|
#include <arch/cpu.h>
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
#include <kernel/pmm.h>
|
#include <kernel/pmm.h>
|
||||||
#include <kernel/eth.h>
|
#include <kernel/eth.h>
|
||||||
#include <kernel/net.h>
|
#include <kernel/net.h>
|
||||||
#include <event.h>
|
|
||||||
#include <hashtable.h>
|
#include <hashtable.h>
|
||||||
#include <arch/cpu.h>
|
#include <arch/cpu.h>
|
||||||
|
|
||||||
@@ -18,7 +17,7 @@ typedef struct {
|
|||||||
viodevice_t *viodevice;
|
viodevice_t *viodevice;
|
||||||
vioqueue_t rxqueue;
|
vioqueue_t rxqueue;
|
||||||
vioqueue_t txqueue;
|
vioqueue_t txqueue;
|
||||||
event_t *txwait[QUEUE_MAX_SIZE];
|
thread_t *txwait[QUEUE_MAX_SIZE];
|
||||||
semaphore_t txsem;
|
semaphore_t txsem;
|
||||||
spinlock_t txlock;
|
spinlock_t txlock;
|
||||||
dpc_t txdpc;
|
dpc_t txdpc;
|
||||||
@@ -69,7 +68,7 @@ static void tx_dpc(context_t *context, dpcarg_t arg) {
|
|||||||
int idx = netdev->txqueue.lastusedindex++ % netdev->txqueue.size;
|
int idx = netdev->txqueue.lastusedindex++ % netdev->txqueue.size;
|
||||||
int buffidx = VIO_QUEUE_DEV_RING(&netdev->txqueue)[idx].index;
|
int buffidx = VIO_QUEUE_DEV_RING(&netdev->txqueue)[idx].index;
|
||||||
__assert(netdev->txwait[buffidx / 2]);
|
__assert(netdev->txwait[buffidx / 2]);
|
||||||
event_signal(netdev->txwait[buffidx / 2]);
|
sched_wakeup(netdev->txwait[buffidx / 2], SCHED_WAKEUP_REASON_NORMAL);
|
||||||
netdev->txwait[buffidx / 2] = NULL;
|
netdev->txwait[buffidx / 2] = NULL;
|
||||||
buffers[buffidx].address = 0;
|
buffers[buffidx].address = 0;
|
||||||
semaphore_signal(&netdev->txsem);
|
semaphore_signal(&netdev->txsem);
|
||||||
@@ -121,9 +120,6 @@ static int vionet_sendpacket(netdev_t *internal, netdesc_t desc, mac_t targetmac
|
|||||||
memcpy(desc.address, &vioframe, sizeof(vioframe_t));
|
memcpy(desc.address, &vioframe, sizeof(vioframe_t));
|
||||||
memcpy((void *)((uintptr_t)desc.address + sizeof(vioframe_t)), ðframe, sizeof(ethframe_t));
|
memcpy((void *)((uintptr_t)desc.address + sizeof(vioframe_t)), ðframe, sizeof(ethframe_t));
|
||||||
|
|
||||||
event_t event;
|
|
||||||
EVENT_INIT(&event);
|
|
||||||
|
|
||||||
bool intstatus = interrupt_set(false);
|
bool intstatus = interrupt_set(false);
|
||||||
semaphore_wait(&netdev->txsem, false);
|
semaphore_wait(&netdev->txsem, false);
|
||||||
|
|
||||||
@@ -142,13 +138,13 @@ static int vionet_sendpacket(netdev_t *internal, netdesc_t desc, mac_t targetmac
|
|||||||
size_t driveridx = VIO_QUEUE_DRV_IDX(&netdev->txqueue)++;
|
size_t driveridx = VIO_QUEUE_DRV_IDX(&netdev->txqueue)++;
|
||||||
VIO_QUEUE_DRV_RING(&netdev->txqueue)[driveridx % netdev->txqueue.size] = idx;
|
VIO_QUEUE_DRV_RING(&netdev->txqueue)[driveridx % netdev->txqueue.size] = idx;
|
||||||
|
|
||||||
netdev->txwait[idx] = &event;
|
sched_preparesleep(false);
|
||||||
|
netdev->txwait[idx] = _cpu()->thread;
|
||||||
*netdev->txqueue.notify = 0;
|
*netdev->txqueue.notify = 0;
|
||||||
|
|
||||||
spinlock_release(&netdev->txlock);
|
spinlock_release(&netdev->txlock);
|
||||||
|
|
||||||
event_wait(&event, false);
|
sched_yield();
|
||||||
|
|
||||||
interrupt_set(intstatus);
|
interrupt_set(intstatus);
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
#include <event.h>
|
|
||||||
|
|
||||||
// TODO while this works, it is built upon semaphores and might have some race conditions
|
|
||||||
|
|
||||||
int event_wait(event_t *event, bool interruptible) {
|
|
||||||
int e = semaphore_wait(event, interruptible);
|
|
||||||
if (e)
|
|
||||||
return e;
|
|
||||||
|
|
||||||
if (semaphore_haswaiters(event))
|
|
||||||
semaphore_signal(event);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void event_signal(event_t *event) {
|
|
||||||
if (semaphore_haswaiters(event))
|
|
||||||
semaphore_signal(event);
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user