1 /* See COPYRIGHT for copyright information. */
3 #include <ros/common.h>
4 #include <ros/ring_syscall.h>
5 #include <arch/types.h>
14 #include <hashtable.h>
16 #include <arsc_server.h>
21 struct proc_list arsc_proc_list = TAILQ_HEAD_INITIALIZER(arsc_proc_list);
22 spinlock_t arsc_proc_lock = SPINLOCK_INITIALIZER_IRQSAVE;
24 intreg_t inline syscall_async(struct proc *p, syscall_req_t *call)
26 struct syscall* sc = call->sc;
27 return syscall(p, sc->num, sc->arg0, sc->arg1,
28 sc->arg2, sc->arg3, sc->arg4, sc->arg5);
31 syscall_sring_t* sys_init_arsc(struct proc *p)
33 kref_get(&p->p_kref, 1); /* we're storing an external ref here */
34 syscall_sring_t* sring;
36 // TODO: need to pin this page in the future when swapping happens
37 va = do_mmap(p,MMAP_LOWEST_VA, SYSCALLRINGSIZE, PROT_READ | PROT_WRITE,
38 MAP_ANONYMOUS | MAP_POPULATE, NULL, 0);
39 pte_t pte = pgdir_walk(p->env_pgdir, (void*)va, 0);
40 assert(pte_walk_okay(pte));
41 sring = (syscall_sring_t*) KADDR(pte_get_paddr(pte));
42 /*make sure we are able to allocate the shared ring */
43 assert(sring != NULL);
44 p->procdata->syscallring = sring;
45 /* Initialize the generic syscall ring buffer */
46 SHARED_RING_INIT(sring);
48 BACK_RING_INIT(&p->syscallbackring,
52 spin_lock_irqsave(&arsc_proc_lock);
53 TAILQ_INSERT_TAIL(&arsc_proc_list, p, proc_arsc_link);
54 spin_unlock_irqsave(&arsc_proc_lock);
55 return (syscall_sring_t*)va;
58 void arsc_server(uint32_t srcid, long a0, long a1, long a2)
60 struct proc *p = NULL;
61 TAILQ_INIT(&arsc_proc_list);
63 while (TAILQ_EMPTY(&arsc_proc_list))
66 TAILQ_FOREACH(p, &arsc_proc_list, proc_arsc_link) {
67 /* Probably want to try to process a dying process's syscalls. If
68 * not, just move it to an else case */
69 process_generic_syscalls (p, MAX_ASRC_BATCH);
70 if (proc_is_dying(p)) {
71 TAILQ_REMOVE(&arsc_proc_list, p, proc_arsc_link);
73 /* Need to break out, so the TAILQ_FOREACH doesn't flip out.
74 * It's not fair, but we're not dealing with that yet anyway */
81 static intreg_t process_generic_syscalls(struct proc *p, size_t max)
84 syscall_back_ring_t* sysbr = &p->syscallbackring;
85 struct per_cpu_info* pcpui = &per_cpu_info[core_id()];
87 // looking at a process not initialized to perform arsc.
90 /* Bail out if there is nothing to do */
91 if (!RING_HAS_UNCONSUMED_REQUESTS(sysbr))
93 /* Switch to the address space of the process, so we can handle their
95 old_proc = switch_to(p);
96 // max is the most we'll process. max = 0 means do as many as possible
97 // TODO: check for initialization of the ring.
98 while (RING_HAS_UNCONSUMED_REQUESTS(sysbr) && ((!max)||(count < max)) ) {
99 // ASSUME: one queue per process
101 //printk("DEBUG PRE: sring->req_prod: %d, sring->rsp_prod: %d\n",
102 // sysbr->sring->req_prod, sysbr->sring->rsp_prod);
103 // might want to think about 0-ing this out, if we aren't
104 // going to explicitly fill in all fields
106 // this assumes we get our answer immediately for the syscall.
107 syscall_req_t* req = RING_GET_REQUEST(sysbr, ++sysbr->req_cons);
109 pcpui->cur_kthread->sysc = req->sc;
110 run_local_syscall(req->sc); // TODO: blocking call will block arcs as well.
112 // need to keep the slot in the ring buffer if it is blocked
113 (sysbr->rsp_prod_pvt)++;
114 req->status = RES_ready;
115 RING_PUSH_RESPONSES(sysbr);
117 //printk("DEBUG POST: sring->req_prod: %d, sring->rsp_prod: %d\n",
118 // sysbr->sring->req_prod, sysbr->sring->rsp_prod);
120 /* switch back to whatever context we were in before */
121 switch_back(p, old_proc);
122 return (intreg_t)count;