Environment variables WIP, fix waiting scheduling issues + CE cancel proc
All checks were successful
Build documentation / build-and-deploy (push) Successful in 3m24s
All checks were successful
Build documentation / build-and-deploy (push) Successful in 3m24s
This commit is contained in:
@@ -8,6 +8,7 @@ $(eval $(call add_lib,libioutil))
|
|||||||
$(eval $(call add_lib,libterminal))
|
$(eval $(call add_lib,libterminal))
|
||||||
$(eval $(call add_lib,libfat))
|
$(eval $(call add_lib,libfat))
|
||||||
$(eval $(call add_lib,libmalloc))
|
$(eval $(call add_lib,libmalloc))
|
||||||
|
$(eval $(call add_lib,libdebugconsole))
|
||||||
$(eval $(call add_include,libkb))
|
$(eval $(call add_include,libkb))
|
||||||
|
|
||||||
cflags += -DPRINTF_INCLUDE_CONFIG_H=1
|
cflags += -DPRINTF_INCLUDE_CONFIG_H=1
|
||||||
|
|||||||
16
ce/interp.c
16
ce/interp.c
@@ -5,6 +5,7 @@
|
|||||||
#include "mprintf.h"
|
#include "mprintf.h"
|
||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
#include "self.h"
|
#include "self.h"
|
||||||
|
#include <debugconsole.h>
|
||||||
#include <desc.h>
|
#include <desc.h>
|
||||||
#include <filereader.h>
|
#include <filereader.h>
|
||||||
#include <filewriter.h>
|
#include <filewriter.h>
|
||||||
@@ -339,15 +340,12 @@ static void help (struct context* context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_cancel_proc (void* arg) {
|
static void cmd_cancel_proc (void* arg) {
|
||||||
int pid = *(int*)arg;
|
int pid = (int)arg;
|
||||||
|
|
||||||
char ch = 0;
|
char ch = 0;
|
||||||
for (;;) {
|
do {
|
||||||
mail_receive (&ch, 1);
|
mail_receive (&ch, 1);
|
||||||
|
} while (ch != KB_CTRL ('C'));
|
||||||
if (ch == KB_CTRL ('C'))
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
kill (pid);
|
kill (pid);
|
||||||
}
|
}
|
||||||
@@ -407,12 +405,12 @@ static void execute_cmd (struct ast_cmd* cmd, struct context* context) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct process_data* cancel_pdata = process_spawn (&cmd_cancel_proc, &pid);
|
struct process_data* cancel_pdata = process_spawn (&cmd_cancel_proc, (void*)pid);
|
||||||
|
|
||||||
wait_for_pid (pid);
|
wait_for_pid (pid);
|
||||||
|
|
||||||
if (kill (cancel_pdata->pid) < 0)
|
kill (cancel_pdata->pid);
|
||||||
free (cancel_pdata);
|
process_data_free (cancel_pdata);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,14 +31,20 @@ int id_alloc (struct id_alloc* ida) {
|
|||||||
|
|
||||||
spin_lock (&ida->lock, &fid);
|
spin_lock (&ida->lock, &fid);
|
||||||
|
|
||||||
for (size_t bit = 0; bit < ida->bm.nbits; bit++) {
|
size_t start = ida->next_id;
|
||||||
if (!bm_test (&ida->bm, bit)) {
|
size_t current = start;
|
||||||
bm_set (&ida->bm, bit);
|
do {
|
||||||
|
if (!bm_test (&ida->bm, current)) {
|
||||||
|
bm_set (&ida->bm, current);
|
||||||
|
|
||||||
|
ida->next_id = (current + 1) % ida->bm.nbits;
|
||||||
|
|
||||||
spin_unlock (&ida->lock, fid);
|
spin_unlock (&ida->lock, fid);
|
||||||
return (int)bit;
|
return (int)current;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
current = (current + 1) % ida->bm.nbits;
|
||||||
|
} while (current != start);
|
||||||
|
|
||||||
spin_unlock (&ida->lock, fid);
|
spin_unlock (&ida->lock, fid);
|
||||||
return -ST_OOM_ERROR;
|
return -ST_OOM_ERROR;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
struct id_alloc {
|
struct id_alloc {
|
||||||
struct bm bm;
|
struct bm bm;
|
||||||
spin_lock_t lock;
|
spin_lock_t lock;
|
||||||
|
int next_id;
|
||||||
};
|
};
|
||||||
|
|
||||||
int id_alloc (struct id_alloc* ida);
|
int id_alloc (struct id_alloc* ida);
|
||||||
|
|||||||
@@ -221,7 +221,7 @@ static struct proc* proc_find_sched (struct cpu* cpu) {
|
|||||||
|
|
||||||
struct list_node_link *current, *start;
|
struct list_node_link *current, *start;
|
||||||
|
|
||||||
if (cpu->proc_current)
|
if (cpu->proc_current && cpu->proc_current->cpu_run_q_link.next)
|
||||||
current = cpu->proc_current->cpu_run_q_link.next;
|
current = cpu->proc_current->cpu_run_q_link.next;
|
||||||
else
|
else
|
||||||
current = cpu->proc_run_q;
|
current = cpu->proc_run_q;
|
||||||
@@ -231,31 +231,75 @@ static struct proc* proc_find_sched (struct cpu* cpu) {
|
|||||||
|
|
||||||
start = current;
|
start = current;
|
||||||
|
|
||||||
do {
|
bool wrap = false;
|
||||||
|
|
||||||
|
while (current) {
|
||||||
struct proc* proc = list_entry (current, struct proc, cpu_run_q_link);
|
struct proc* proc = list_entry (current, struct proc, cpu_run_q_link);
|
||||||
|
|
||||||
spin_lock (&proc->lock, &fp);
|
spin_lock (&proc->lock, &fp);
|
||||||
|
|
||||||
int state = proc->state;
|
int state = proc->state;
|
||||||
|
|
||||||
if (state == PROC_READY && !(proc->flags & PROC_KPROC)) {
|
if (!proc->dead && state == PROC_READY && !(proc->flags & PROC_KPROC)) {
|
||||||
spin_unlock (&proc->lock, fp);
|
spin_unlock (&proc->lock, fp);
|
||||||
return proc;
|
return proc;
|
||||||
}
|
}
|
||||||
|
|
||||||
spin_unlock (&proc->lock, fp);
|
spin_unlock (&proc->lock, fp);
|
||||||
|
|
||||||
current = current->next ? current->next : cpu->proc_run_q;
|
current = current->next;
|
||||||
} while (current != start);
|
|
||||||
|
if (!current && !wrap) {
|
||||||
|
current = cpu->proc_run_q;
|
||||||
|
wrap = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wrap && current == start)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void proc_reaper (struct reschedule_ctx* rctx) {
|
||||||
|
uint64_t fpt, fp, fc;
|
||||||
|
|
||||||
|
struct list_node_link* reaper_list = NULL;
|
||||||
|
|
||||||
|
spin_lock (&proc_tree_lock, &fpt);
|
||||||
|
spin_lock (&thiscpu->lock, &fc);
|
||||||
|
|
||||||
|
struct list_node_link *run_link, *tmp_run_link;
|
||||||
|
list_foreach (thiscpu->proc_run_q, run_link, tmp_run_link) {
|
||||||
|
struct proc* proc = list_entry (run_link, struct proc, cpu_run_q_link);
|
||||||
|
|
||||||
|
if (!proc->dead)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
spin_lock (&proc->lock, &fp);
|
||||||
|
list_remove (thiscpu->proc_run_q, &proc->cpu_run_q_link);
|
||||||
|
rbtree_delete (&proc_tree, &proc->proc_tree_link);
|
||||||
|
list_append (reaper_list, &proc->reaper_list_link);
|
||||||
|
spin_unlock (&proc->lock, fp);
|
||||||
|
}
|
||||||
|
|
||||||
|
spin_unlock (&thiscpu->lock, fc);
|
||||||
|
spin_unlock (&proc_tree_lock, fpt);
|
||||||
|
|
||||||
|
struct list_node_link *rlink, *tmp_rlink;
|
||||||
|
list_foreach (reaper_list, rlink, tmp_rlink) {
|
||||||
|
struct proc* proc = list_entry (rlink, struct proc, reaper_list_link);
|
||||||
|
list_remove (reaper_list, &proc->reaper_list_link);
|
||||||
|
proc_cleanup (proc, rctx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void proc_sched (void) {
|
void proc_sched (void) {
|
||||||
struct proc* next = NULL;
|
struct proc* next = NULL;
|
||||||
struct cpu* cpu = thiscpu;
|
struct cpu* cpu = thiscpu;
|
||||||
uint64_t fc;
|
uint64_t fc;
|
||||||
|
|
||||||
|
retry:
|
||||||
spin_lock (&cpu->lock, &fc);
|
spin_lock (&cpu->lock, &fc);
|
||||||
|
|
||||||
next = proc_find_sched (cpu);
|
next = proc_find_sched (cpu);
|
||||||
@@ -268,7 +312,9 @@ void proc_sched (void) {
|
|||||||
cpu->proc_current = NULL;
|
cpu->proc_current = NULL;
|
||||||
spin_unlock (&cpu->lock, fc);
|
spin_unlock (&cpu->lock, fc);
|
||||||
|
|
||||||
spin ();
|
spin_lock_relax ();
|
||||||
|
|
||||||
|
goto retry;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -288,10 +334,9 @@ void proc_kill (struct proc* proc, struct reschedule_ctx* rctx) {
|
|||||||
spin_lock (&cpu->lock, &fc);
|
spin_lock (&cpu->lock, &fc);
|
||||||
spin_lock (&proc->lock, &fp);
|
spin_lock (&proc->lock, &fp);
|
||||||
|
|
||||||
proc->state = PROC_DEAD;
|
|
||||||
proc->cpu = NULL;
|
proc->cpu = NULL;
|
||||||
|
proc->dead = true;
|
||||||
|
|
||||||
list_remove (cpu->proc_run_q, &proc->cpu_run_q_link);
|
|
||||||
cpu->proc_run_q_count--;
|
cpu->proc_run_q_count--;
|
||||||
if (cpu->proc_current == proc)
|
if (cpu->proc_current == proc)
|
||||||
cpu->proc_current = NULL;
|
cpu->proc_current = NULL;
|
||||||
@@ -299,16 +344,6 @@ void proc_kill (struct proc* proc, struct reschedule_ctx* rctx) {
|
|||||||
spin_unlock (&proc->lock, fp);
|
spin_unlock (&proc->lock, fp);
|
||||||
spin_unlock (&cpu->lock, fc);
|
spin_unlock (&cpu->lock, fc);
|
||||||
|
|
||||||
spin_lock (&proc_tree_lock, &fpt);
|
|
||||||
spin_lock (&proc->lock, &fp);
|
|
||||||
|
|
||||||
rbtree_delete (&proc_tree, &proc->proc_tree_link);
|
|
||||||
|
|
||||||
spin_unlock (&proc->lock, fp);
|
|
||||||
spin_unlock (&proc_tree_lock, fpt);
|
|
||||||
|
|
||||||
proc_cleanup (proc, rctx);
|
|
||||||
|
|
||||||
rctx_insert_cpu (rctx, cpu);
|
rctx_insert_cpu (rctx, cpu);
|
||||||
|
|
||||||
DEBUG ("killed PID %d\n", proc->pid);
|
DEBUG ("killed PID %d\n", proc->pid);
|
||||||
@@ -321,11 +356,13 @@ void proc_wait_for (struct proc* proc, struct reschedule_ctx* rctx, struct proc*
|
|||||||
static void proc_irq_sched (void* arg, void* regs, bool user, struct reschedule_ctx* rctx) {
|
static void proc_irq_sched (void* arg, void* regs, bool user, struct reschedule_ctx* rctx) {
|
||||||
(void)arg, (void)regs, (void)rctx;
|
(void)arg, (void)regs, (void)rctx;
|
||||||
|
|
||||||
|
proc_reaper (rctx);
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
proc_sched ();
|
rctx_insert_cpu (rctx, thiscpu);
|
||||||
}
|
}
|
||||||
|
|
||||||
void proc_init (void) {
|
void proc_init (void) {
|
||||||
|
|||||||
@@ -21,8 +21,7 @@
|
|||||||
|
|
||||||
/* process states */
|
/* process states */
|
||||||
#define PROC_READY 0
|
#define PROC_READY 0
|
||||||
#define PROC_DEAD 1
|
#define PROC_SUSPENDED 1
|
||||||
#define PROC_SUSPENDED 2
|
|
||||||
|
|
||||||
/* process flags */
|
/* process flags */
|
||||||
#define PROC_USTK_PREALLOC (1 << 0)
|
#define PROC_USTK_PREALLOC (1 << 0)
|
||||||
@@ -34,6 +33,7 @@ struct reschedule_ctx;
|
|||||||
struct proc {
|
struct proc {
|
||||||
int pid;
|
int pid;
|
||||||
int exec_pid;
|
int exec_pid;
|
||||||
|
struct list_node_link reaper_list_link;
|
||||||
struct rb_node_link proc_tree_link;
|
struct rb_node_link proc_tree_link;
|
||||||
struct rb_node_link procgroup_memb_tree_link;
|
struct rb_node_link procgroup_memb_tree_link;
|
||||||
struct list_node_link cpu_run_q_link;
|
struct list_node_link cpu_run_q_link;
|
||||||
@@ -44,6 +44,7 @@ struct proc {
|
|||||||
spin_lock_t lock;
|
spin_lock_t lock;
|
||||||
struct cpu* cpu;
|
struct cpu* cpu;
|
||||||
int state;
|
int state;
|
||||||
|
bool dead;
|
||||||
uintptr_t uvaddr_argument;
|
uintptr_t uvaddr_argument;
|
||||||
void* mail_recv_buffer;
|
void* mail_recv_buffer;
|
||||||
size_t mail_recv_size;
|
size_t mail_recv_size;
|
||||||
|
|||||||
@@ -47,7 +47,6 @@ int proc_sq_suspend (struct proc* proc, struct proc_suspension_q* sq, spin_lock_
|
|||||||
if (cpu->proc_current == proc)
|
if (cpu->proc_current == proc)
|
||||||
cpu->proc_current = NULL;
|
cpu->proc_current = NULL;
|
||||||
|
|
||||||
proc->cpu = NULL;
|
|
||||||
int state = proc->state;
|
int state = proc->state;
|
||||||
|
|
||||||
spin_unlock (&sq->lock, fsq);
|
spin_unlock (&sq->lock, fsq);
|
||||||
|
|||||||
@@ -537,14 +537,7 @@ DEFINE_SYSCALL (sys_get_procgroup) {
|
|||||||
return SYSRESULT (-ST_NOT_FOUND);
|
return SYSRESULT (-ST_NOT_FOUND);
|
||||||
|
|
||||||
spin_lock (&target_proc->lock, &fp);
|
spin_lock (&target_proc->lock, &fp);
|
||||||
|
|
||||||
if (target_proc->state == PROC_DEAD) {
|
|
||||||
spin_unlock (&target_proc->lock, fp);
|
|
||||||
return SYSRESULT (-ST_NOT_FOUND);
|
|
||||||
}
|
|
||||||
|
|
||||||
int pgid = target_proc->procgroup->pgid;
|
int pgid = target_proc->procgroup->pgid;
|
||||||
|
|
||||||
spin_unlock (&target_proc->lock, fp);
|
spin_unlock (&target_proc->lock, fp);
|
||||||
|
|
||||||
return SYSRESULT (pgid);
|
return SYSRESULT (pgid);
|
||||||
@@ -681,7 +674,7 @@ DEFINE_SYSCALL (sys_wait_for_pid) {
|
|||||||
|
|
||||||
spin_lock (&wait_proc->lock, &fp);
|
spin_lock (&wait_proc->lock, &fp);
|
||||||
|
|
||||||
if (wait_proc->state == PROC_DEAD) {
|
if (wait_proc->dead) {
|
||||||
spin_unlock (&wait_proc->lock, fp);
|
spin_unlock (&wait_proc->lock, fp);
|
||||||
return SYSRESULT (-ST_NOT_FOUND);
|
return SYSRESULT (-ST_NOT_FOUND);
|
||||||
}
|
}
|
||||||
@@ -694,7 +687,6 @@ DEFINE_SYSCALL (sys_wait_for_pid) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* int kill (int pid) */
|
/* int kill (int pid) */
|
||||||
|
|
||||||
DEFINE_SYSCALL (sys_kill) {
|
DEFINE_SYSCALL (sys_kill) {
|
||||||
uint64_t fp;
|
uint64_t fp;
|
||||||
|
|
||||||
@@ -705,15 +697,6 @@ DEFINE_SYSCALL (sys_kill) {
|
|||||||
if (target_proc == NULL)
|
if (target_proc == NULL)
|
||||||
return SYSRESULT (-ST_NOT_FOUND);
|
return SYSRESULT (-ST_NOT_FOUND);
|
||||||
|
|
||||||
spin_lock (&target_proc->lock, &fp);
|
|
||||||
|
|
||||||
if (target_proc->state == PROC_DEAD) {
|
|
||||||
spin_unlock (&target_proc->lock, fp);
|
|
||||||
return SYSRESULT (-ST_NOT_FOUND);
|
|
||||||
}
|
|
||||||
|
|
||||||
spin_unlock (&target_proc->lock, fp);
|
|
||||||
|
|
||||||
proc_kill (target_proc, rctx);
|
proc_kill (target_proc, rctx);
|
||||||
|
|
||||||
return ST_OK;
|
return ST_OK;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ include ../make/ufuncs.mk
|
|||||||
|
|
||||||
$(eval $(call add_include,libsystem))
|
$(eval $(call add_include,libsystem))
|
||||||
$(eval $(call add_include,libmalloc))
|
$(eval $(call add_include,libmalloc))
|
||||||
|
$(eval $(call add_include,libdebugconsole))
|
||||||
|
|
||||||
libname := libprocess
|
libname := libprocess
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#include <debugconsole.h>
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#include <map.h>
|
#include <map.h>
|
||||||
#include <page_size.h>
|
#include <page_size.h>
|
||||||
@@ -21,6 +22,7 @@ struct process_data* process_spawn (process_func_t func, void* argument_ptr) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pdata->stack = stack;
|
||||||
pdata->arg_ptr = argument_ptr;
|
pdata->arg_ptr = argument_ptr;
|
||||||
pdata->fn = func;
|
pdata->fn = func;
|
||||||
|
|
||||||
@@ -36,3 +38,8 @@ struct process_data* process_spawn (process_func_t func, void* argument_ptr) {
|
|||||||
pdata->pid = pid;
|
pdata->pid = pid;
|
||||||
return pdata;
|
return pdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void process_data_free (struct process_data* pdata) {
|
||||||
|
free (pdata->stack);
|
||||||
|
free (pdata);
|
||||||
|
}
|
||||||
|
|||||||
@@ -14,9 +14,12 @@ struct process_data {
|
|||||||
void* arg_ptr;
|
void* arg_ptr;
|
||||||
process_func_t fn;
|
process_func_t fn;
|
||||||
int pid;
|
int pid;
|
||||||
|
void* stack;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Spawn a new process within the same procgroup with argument */
|
/* Spawn a new process within the same procgroup with argument */
|
||||||
struct process_data* process_spawn (process_func_t func, void* argument_ptr);
|
struct process_data* process_spawn (process_func_t func, void* argument_ptr);
|
||||||
|
|
||||||
|
void process_data_free (struct process_data* pdata);
|
||||||
|
|
||||||
#endif // _LIBPROCESS_PROCESS_PROCESS_H
|
#endif // _LIBPROCESS_PROCESS_PROCESS_H
|
||||||
|
|||||||
Reference in New Issue
Block a user