-/*
- * Copyright (c) 2009 The Regents of the University of California
+/* Copyright (c) 2009, 2010 The Regents of the University of California
* Barret Rhoden <brho@cs.berkeley.edu>
* See LICENSE for details.
*
* All things processes! As we move away from the old envs to processes,
- * we'll move things into here that are designed for multicore processes.
- */
+ * we'll move things into here that are designed for multicore processes. */
-#ifndef ROS_KERN_PROCESS_H
-#define ROS_KERN_PROCESS_H
+#pragma once
#include <ros/common.h>
-#include <ros/notification.h>
+#include <ros/event.h>
#include <trap.h>
#include <atomic.h>
+#include <kref.h>
+#include <schedule.h>
/* Process States. Not 100% on the names yet. RUNNABLE_* are waiting to go to
* RUNNING_*. For instance, RUNNABLE_M is expecting to go to RUNNING_M. It
* could be waiting for it's timeslice, or possibly for all the cores it asked
- * for. You use proc_run() to transition between these states.
+ * for.
*
* Difference between the _M and the _S states:
* - _S : legacy process mode
* - The time slicing is at a coarser granularity for _M states. This means
* that when you run an _S on a core, it should be interrupted/time sliced
* more often, which also means the core should be classified differently for
- * a while. Possibly even using it's local APIC timer.
+ * a while. Possibly even using its local APIC timer.
* - A process in an _M state will be informed about changes to its state, e.g.,
* will have a handler run in the event of a page fault
*/
#define PROC_RUNNABLE_M 0x20
#define PROC_RUNNING_M 0x40
-#define procstate2str(state) ((state)==PROC_CREATED ? "CREATED " : \
+#define procstate2str(state) ((state)==PROC_CREATED ? "CREATED" : \
(state)==PROC_RUNNABLE_S ? "RUNNABLE_S" : \
- (state)==PROC_RUNNING_S ? "RUNNING_S " : \
- (state)==PROC_WAITING ? "WAITING " : \
- (state)==PROC_DYING ? "DYING " : \
+ (state)==PROC_RUNNING_S ? "RUNNING_S" : \
+ (state)==PROC_WAITING ? "WAITING" : \
+ (state)==PROC_DYING ? "DYING" : \
(state)==PROC_RUNNABLE_M ? "RUNNABLE_M" : \
- (state)==PROC_RUNNING_M ? "RUNNING_M " : \
- "UNKNOWN ")
-
-#include <env.h>
+ (state)==PROC_RUNNING_M ? "RUNNING_M" : \
+ "UNKNOWN")
-// Till we remove the old struct Env
-#define proc Env
+#define DEFAULT_PROGNAME ""
-TAILQ_HEAD(proc_list, proc); // Declares 'struct proc_list'
+#include <env.h>
-extern spinlock_t runnablelist_lock;
-extern struct proc_list LCKD(&runnablelist_lock) proc_runnablelist;
+struct process_set {
+ size_t num_processes;
+ size_t size;
+ struct proc **procs;
+};
/* Can use a htable iterator to iterate through all active procs */
extern struct hashtable *pid_hash;
extern spinlock_t pid_hash_lock;
-/* Idle cores: ones able to be exclusively given to a process (worker cores). */
-extern spinlock_t idle_lock; // never grab this before a proc_lock
-extern uint32_t LCKD(&idle_lock) (RO idlecoremap)[MAX_NUM_CPUS];
-extern uint32_t LCKD(&idle_lock) num_idlecores;
-
/* Initialization */
void proc_init(void);
-void proc_init_procinfo(struct proc *p);
+void proc_set_progname(struct proc *p, char *name);
+void proc_replace_binary_path(struct proc *p, char *path);
+void proc_init_procinfo(struct proc* p);
+void proc_init_procdata(struct proc* p);
/* Process management: */
-struct proc *proc_create(uint8_t *COUNT(size) binary, size_t size);
-int __proc_set_state(struct proc *p, uint32_t state) WRITES(p->state);
+struct proc *pid_nth(unsigned int n);
+error_t proc_alloc(struct proc **pp, struct proc *parent, int flags);
+void __proc_ready(struct proc *p);
+struct proc *proc_create(struct file *prog, char **argv, char **envp);
+int __proc_set_state(struct proc *p, uint32_t state);
struct proc *pid2proc(pid_t pid);
-bool proc_controls(struct proc *SAFE actor, struct proc *SAFE target);
-void proc_run(struct proc *SAFE p);
-void proc_restartcore(struct proc *SAFE p, trapframe_t *SAFE tf);
-void proc_destroy(struct proc *SAFE p);
-void proc_yield(struct proc *SAFE p);
-void do_notify(struct proc *p, uint32_t vcoreid, unsigned int notif,
- struct notif_event *ne);
-void proc_notify(struct proc *p, unsigned int notif, struct notif_event *ne);
-
-/* Exposed for sys_getvcoreid(), til it's unnecessary */
-uint32_t proc_get_vcoreid(struct proc *SAFE p, uint32_t pcoreid);
+bool proc_controls(struct proc *actor, struct proc *target);
+void proc_incref(struct proc *p, unsigned int val);
+void proc_decref(struct proc *p);
+void proc_run_s(struct proc *p);
+void __proc_run_m(struct proc *p);
+void __proc_startcore(struct proc *p, struct user_context *ctx);
+void proc_restartcore(void);
+void proc_destroy(struct proc *p);
+void proc_signal_parent(struct proc *child);
+int __proc_disown_child(struct proc *parent, struct proc *child);
+int proc_change_to_m(struct proc *p);
+void __proc_save_fpu_s(struct proc *p);
+void __proc_save_context_s(struct proc *p);
+void proc_yield(struct proc *p, bool being_nice);
+void proc_notify(struct proc *p, uint32_t vcoreid);
+void proc_wakeup(struct proc *p);
+bool __proc_is_mcp(struct proc *p);
+bool proc_is_vcctx_ready(struct proc *p);
+int proc_change_to_vcore(struct proc *p, uint32_t new_vcoreid,
+ bool enable_my_notif);
+void proc_get_set(struct process_set *pset);
+void proc_free_set(struct process_set *pset);
+
+/* Vcoremap info: */
+uint32_t proc_get_vcoreid(struct proc *p);
+/* TODO: make all of these inline once we gut the Env crap */
+bool vcore_is_mapped(struct proc *p, uint32_t vcoreid);
+uint32_t vcore2vcoreid(struct proc *p, struct vcore *vc);
+struct vcore *vcoreid2vcore(struct proc *p, uint32_t vcoreid);
/* Process core management. Only call these if you are RUNNING_M or RUNNABLE_M.
* These all adjust the vcoremap and take appropriate actions (like __startcore
* shouldn't call these functions with parameters you are not sure about (like
* an invalid corelist).
*
- * They also may cause an IPI to be sent to core it is called on. If so, the
- * return value will be true. Once you unlock (and enable interrupts) you will
- * be preempted, and usually lose your stack. There is a helper to unlock and
- * handle the refcnt.
- *
* WARNING: YOU MUST HOLD THE PROC_LOCK BEFORE CALLING THESE! */
/* Gives process p the additional num cores listed in corelist */
-bool __proc_give_cores(struct proc *SAFE p, uint32_t *pcorelist, size_t num);
-/* Makes process p's coremap look like corelist (add, remove, etc). Not used */
-bool __proc_set_allcores(struct proc *SAFE p, uint32_t *pcorelist,
- size_t *num, amr_t message, TV(a0t) arg0,
- TV(a1t) arg1, TV(a2t) arg2);
-/* Takes from process p the num cores listed in corelist */
-bool __proc_take_cores(struct proc *SAFE p, uint32_t *pcorelist,
- size_t num, amr_t message, TV(a0t) arg0,
- TV(a1t) arg1, TV(a2t) arg2);
-bool __proc_take_allcores(struct proc *SAFE p, amr_t message, TV(a0t) arg0,
- TV(a1t) arg1, TV(a2t) arg2);
-void __proc_unlock_ipi_pending(struct proc *p, bool ipi_pending);
-/* Exposed for kern/src/resource.c for now */
+int __proc_give_cores(struct proc *p, uint32_t *pc_arr, uint32_t num);
+/* Takes from process p the num cores listed in pc_arr */
+void __proc_take_corelist(struct proc *p, uint32_t *pc_arr, uint32_t num,
+ bool preempt);
+/* Takes all cores, returns the count, fills in pc_arr with their pcoreid */
+uint32_t __proc_take_allcores(struct proc *p, uint32_t *pc_arr, bool preempt);
+
+/* Exposed for now for convenience */
void __map_vcore(struct proc *p, uint32_t vcoreid, uint32_t pcoreid);
void __unmap_vcore(struct proc *p, uint32_t vcoreid);
-
-/* Will probably have generic versions of these later. */
-void proc_incref(struct proc *SAFE p, size_t count);
-void proc_decref(struct proc *SAFE p, size_t count);
-
-/* Allows the kernel to figure out what process is running on this core. Can be
- * used just like a pointer to a struct proc. Need these to be macros due to
- * some circular dependencies with smp.h. */
-#include <smp.h>
-#define current per_cpu_info[core_id()].cur_proc
-#define set_current_proc(p) per_cpu_info[core_id()].cur_proc = (p)
-
-/* Allows the kernel to figure out what *user* tf is on this core's stack. Can be used
- * just like a pointer to a struct Trapframe. Need these to be macros due to
- * some circular dependencies with smp.h. This is done here instead of
- * elsewhere (like trap.h) for other elliptical reasons. Note the distinction
- * between kernel and user contexts. The kernel always returns to its nested,
- * interrupted contexts via iret/etc. We don't always do that for user
- * contexts. */
-#define current_tf per_cpu_info[core_id()].cur_tf
-#define set_current_tf(tf) per_cpu_info[core_id()].cur_tf = (tf)
-
+void vcore_account_online(struct proc *p, uint32_t vcoreid);
+void vcore_account_offline(struct proc *p, uint32_t vcoreid);
+uint64_t vcore_account_gettotal(struct proc *p, uint32_t vcoreid);
+
+/* Preemption management. Some of these will change */
+void __proc_preempt_warn(struct proc *p, uint32_t vcoreid, uint64_t when);
+void __proc_preempt_warnall(struct proc *p, uint64_t when);
+void __proc_preempt_core(struct proc *p, uint32_t pcoreid);
+uint32_t __proc_preempt_all(struct proc *p, uint32_t *pc_arr);
+bool proc_preempt_core(struct proc *p, uint32_t pcoreid, uint64_t usec);
+void proc_preempt_all(struct proc *p, uint64_t usec);
+
+/* Current / cr3 / context management */
+uintptr_t switch_to(struct proc *new_p);
+void switch_back(struct proc *new_p, uintptr_t old_ret);
void abandon_core(void);
+void clear_owning_proc(uint32_t coreid);
+void proc_tlbshootdown(struct proc *p, uintptr_t start, uintptr_t end);
/* Kernel message handlers for process management */
-#ifdef __IVY__
-void __startcore(trapframe_t *tf, uint32_t srcid, struct proc *CT(1) a0,
- trapframe_t *CT(1) a1, void *SNT a2);
-void __death(trapframe_t *tf, uint32_t srcid, void *SNT a0, void *SNT a1,
- void *SNT a2);
-#else
-void __startcore(trapframe_t *tf, uint32_t srcid, void *a0, void *a1, void *a2);
-void __death(trapframe_t *tf, uint32_t srcid, void *a0, void *a1, void *a2);
-void __notify(trapframe_t *tf, uint32_t srcid, void *a0, void *a1, void *a2);
-#endif
+void __startcore(uint32_t srcid, long a0, long a1, long a2);
+void __set_curctx(uint32_t srcid, long a0, long a1, long a2);
+void __notify(uint32_t srcid, long a0, long a1, long a2);
+void __preempt(uint32_t srcid, long a0, long a1, long a2);
+void __death(uint32_t srcid, long a0, long a1, long a2);
+void __tlbshootdown(uint32_t srcid, long a0, long a1, long a2);
/* Arch Specific */
-void proc_init_trapframe(trapframe_t *SAFE tf, uint32_t vcoreid,
- uint32_t entryp, uint32_t stack_top);
-void proc_set_syscall_retval(trapframe_t *SAFE tf, intreg_t value);
+void proc_pop_ctx(struct user_context *ctx) __attribute__((noreturn));
+void proc_init_ctx(struct user_context *ctx, uint32_t vcoreid, uintptr_t entryp,
+ uintptr_t stack_top, uintptr_t tls_desc);
+void proc_secure_ctx(struct user_context *ctx);
void __abandon_core(void);
/* Degubbing */
-void print_idlecoremap(void);
void print_allpids(void);
void print_proc_info(pid_t pid);
-
-#endif // !ROS_KERN_PROCESS_H