Simplify reschedule points, mail works now!
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m55s
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m55s
This commit is contained in:
@@ -37,7 +37,6 @@ void proc_cleanup_resource_mail (struct proc_resource* resource, struct reschedu
|
||||
}
|
||||
|
||||
spin_unlock (&mail->send_sq.lock);
|
||||
|
||||
spin_unlock (&mail->resource->lock);
|
||||
}
|
||||
|
||||
@@ -82,9 +81,12 @@ void proc_mail_send (struct proc* proc, struct proc_mail* mail, struct reschedul
|
||||
spin_unlock (&mail->recv_sq.lock);
|
||||
|
||||
/* mail is empty and nobody is waiting */
|
||||
mail->pending_mesg = malloc (data_size);
|
||||
memcpy (mail->pending_mesg, data, data_size);
|
||||
mail->pending_mesg_size = data_size;
|
||||
void* mesg = malloc (data_size);
|
||||
if (mesg != NULL) {
|
||||
mail->pending_mesg = mesg;
|
||||
memcpy (mail->pending_mesg, data, data_size);
|
||||
mail->pending_mesg_size = data_size;
|
||||
}
|
||||
|
||||
spin_unlock (&mail->resource->lock);
|
||||
}
|
||||
@@ -100,7 +102,7 @@ void proc_mail_receive (struct proc* proc, struct proc_mail* mail, struct resche
|
||||
|
||||
/* consume mesg if available */
|
||||
if (mail->pending_mesg != NULL) {
|
||||
memcpy (recv_buffer, mail->pending_mesg, recv_size);
|
||||
memcpy (recv_buffer, mail->pending_mesg, min (recv_size, mail->pending_mesg_size));
|
||||
free (mail->pending_mesg);
|
||||
mail->pending_mesg = NULL;
|
||||
mail->pending_mesg_size = 0;
|
||||
|
||||
@@ -181,8 +181,10 @@ void proc_register (struct proc* proc, struct cpu* register_cpu, struct reschedu
|
||||
spin_unlock (&cpu->lock);
|
||||
spin_unlock (&proc_tree_lock);
|
||||
|
||||
if (rctx != NULL)
|
||||
reschedule_list_append (rctx, cpu);
|
||||
if (rctx != NULL) {
|
||||
rctx->reschedule = true;
|
||||
rctx->cpu = cpu;
|
||||
}
|
||||
}
|
||||
|
||||
/* caller holds cpu->lock */
|
||||
@@ -252,7 +254,7 @@ static void proc_reap (struct reschedule_ctx* rctx) {
|
||||
|
||||
void proc_sched (void) {
|
||||
int s_cycles = atomic_fetch_add (&sched_cycles, 1);
|
||||
struct reschedule_ctx rctx = {.entries = NULL, .lock = SPIN_LOCK_INIT};
|
||||
struct reschedule_ctx rctx = {.reschedule = false, .cpu = NULL};
|
||||
|
||||
if (s_cycles % SCHED_REAP_FREQ == 0)
|
||||
proc_reap (&rctx);
|
||||
@@ -295,7 +297,8 @@ void proc_kill (struct proc* proc, struct reschedule_ctx* rctx) {
|
||||
spin_unlock (&proc->lock);
|
||||
spin_unlock (&cpu->lock);
|
||||
|
||||
reschedule_list_append (rctx, cpu);
|
||||
rctx->reschedule = true;
|
||||
rctx->cpu = cpu;
|
||||
|
||||
DEBUG ("killed PID %d\n", proc->pid);
|
||||
}
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
#include <libk/list.h>
|
||||
#include <mm/liballoc.h>
|
||||
#include <proc/reschedule.h>
|
||||
#include <sync/spin_lock.h>
|
||||
#include <sys/smp.h>
|
||||
|
||||
void reschedule_list_append (struct reschedule_ctx* rctx, struct cpu* cpu) {
|
||||
spin_lock (&rctx->lock);
|
||||
|
||||
struct list_node_link *node, *tmp;
|
||||
list_foreach (rctx->entries, node, tmp) {
|
||||
struct reschedule_entry* entry = list_entry (node, struct reschedule_entry, link);
|
||||
|
||||
if (entry->cpu == cpu) {
|
||||
spin_unlock (&rctx->lock);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
struct reschedule_entry* entry = malloc (sizeof (*entry));
|
||||
|
||||
if (entry == NULL) {
|
||||
spin_unlock (&rctx->lock);
|
||||
return;
|
||||
}
|
||||
|
||||
entry->cpu = cpu;
|
||||
|
||||
list_append (rctx->entries, &entry->link);
|
||||
|
||||
spin_unlock (&rctx->lock);
|
||||
}
|
||||
@@ -5,16 +5,9 @@
|
||||
#include <sync/spin_lock.h>
|
||||
#include <sys/smp.h>
|
||||
|
||||
struct reschedule_entry {
|
||||
struct cpu* cpu;
|
||||
struct list_node_link link;
|
||||
};
|
||||
|
||||
struct reschedule_ctx {
|
||||
struct list_node_link* entries;
|
||||
spin_lock_t lock;
|
||||
bool reschedule;
|
||||
struct cpu* cpu;
|
||||
};
|
||||
|
||||
void reschedule_list_append (struct reschedule_ctx* rctx, struct cpu* cpu);
|
||||
|
||||
#endif // _KERNEL_PROC_RESCHEDULE_H
|
||||
|
||||
@@ -3,13 +3,11 @@ c += proc/proc.c \
|
||||
proc/mutex.c \
|
||||
proc/procgroup.c \
|
||||
proc/suspension_q.c \
|
||||
proc/mail.c \
|
||||
proc/reschedule.c
|
||||
proc/mail.c
|
||||
|
||||
o += proc/proc.o \
|
||||
proc/resource.o \
|
||||
proc/mutex.o \
|
||||
proc/procgroup.o \
|
||||
proc/suspension_q.o \
|
||||
proc/mail.o \
|
||||
proc/reschedule.o
|
||||
proc/mail.o
|
||||
|
||||
@@ -48,7 +48,8 @@ void proc_sq_suspend (struct proc* proc, struct proc_suspension_q* sq, spin_lock
|
||||
spin_unlock (&proc->lock);
|
||||
spin_unlock (&cpu->lock);
|
||||
|
||||
reschedule_list_append (rctx, cpu);
|
||||
rctx->reschedule = true;
|
||||
rctx->cpu = cpu;
|
||||
}
|
||||
|
||||
void proc_sq_resume (struct proc* proc, struct proc_sq_entry* sq_entry,
|
||||
@@ -80,7 +81,8 @@ void proc_sq_resume (struct proc* proc, struct proc_sq_entry* sq_entry,
|
||||
|
||||
free (sq_entry);
|
||||
|
||||
reschedule_list_append (rctx, cpu);
|
||||
rctx->reschedule = true;
|
||||
rctx->cpu = cpu;
|
||||
}
|
||||
|
||||
void proc_sqs_cleanup (struct proc* proc) {
|
||||
|
||||
Reference in New Issue
Block a user