Skip to content

Commit

Permalink
net: Run PicoTCP ticks in a worker
Browse files Browse the repository at this point in the history
  • Loading branch information
lutoma committed May 19, 2023
1 parent 4ed9ede commit 299de2a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
7 changes: 0 additions & 7 deletions src/int/int.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <tasks/scheduler.h>
#include <mem/paging.h>
#include <mem/i386-gdt.h>
#include <net/net.h>

#define debug(args...) log(LOG_DEBUG, "interrupts: " args)

Expand All @@ -43,12 +42,6 @@ isf_t* __fastcall int_dispatch(uint32_t intr, isf_t* state) {
#endif

int_disable();
#ifdef CONFIG_ENABLE_PICOTCP
if(intr == IRQ(0)) {
net_tick();
}
#endif


for(int i = 0; i < 10; i++) {
if(!reg[i].handler) {
Expand Down
21 changes: 15 additions & 6 deletions src/net/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
#include <net/i386-rtl8139.h>
#include <net/i386-ne2k.h>
#include <net/virtio_net.h>
#include <tasks/worker.h>
#include <tasks/scheduler.h>
#include <time.h>

#ifdef CONFIG_ENABLE_PICOTCP

Expand All @@ -48,12 +51,6 @@ void dhcp_cb(void* cli, int code) {
log(LOG_INFO, "net: DHCP done, IP %s\n", ip);
}

void net_tick() {
if(likely(initialized)) {
pico_stack_tick();
}
}

static int pico_dsr_cb(struct pico_device* pico_dev, int loop_score) {
struct net_device* dev = (struct net_device*)pico_dev;

Expand Down Expand Up @@ -111,6 +108,15 @@ struct net_device* net_add_device(char* name, uint8_t mac[6], net_send_callback_
return dev;
}

static void __attribute__((fastcall, noreturn)) net_worker_entry(worker_t* worker) {
while(1) {
if(likely(initialized)) {
pico_stack_tick();
}
scheduler_yield();
}
}

void net_init() {
log(LOG_INFO, "net: Initializing PicoTCP\n");
pico_stack_init();
Expand Down Expand Up @@ -145,6 +151,9 @@ void net_init() {
#ifdef CONFIG_ENABLE_RTL8139
rtl8139_init();
#endif

worker_t* net_worker = worker_new("knetworkd", net_worker_entry);
scheduler_add_worker(net_worker);
}

#endif /* ENABLE_PICOTCP */
1 change: 0 additions & 1 deletion src/net/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,4 @@ extern spinlock_t net_pico_lock;

void net_receive(struct net_device* dev, void* data, size_t len);
struct net_device* net_add_device(char* name, uint8_t mac[6], net_send_callback_t* write_cb);
void net_tick();
void net_init();
2 changes: 1 addition & 1 deletion src/tasks/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ static size_t sfs_read(struct vfs_callback_ctx* ctx, void* dest, size_t size) {
}

static void __attribute__((fastcall, noreturn)) do_idle(worker_t* worker) {
int_enable();
int_enable();
while(true) {
asm("hlt;");
}
Expand Down
1 change: 1 addition & 0 deletions src/tasks/scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ struct scheduler_qentry {
extern enum scheduler_state scheduler_state;

void scheduler_add(task_t *task);
void scheduler_add_worker(worker_t* worker);
task_t* scheduler_find(uint32_t pid);
task_t* scheduler_get_current();
void scheduler_yield();
Expand Down

0 comments on commit 299de2a

Please sign in to comment.