Uthread code no longer tracks detailed states
[akaros.git] / user / parlib / include / arc.h
1 // Header for Asynch Remote Call, currently only support remote syscalls.
2 #ifndef _ARC_H
3 #define _ARC_H
4
5 #ifdef __cplusplus
6   extern "C" {
7 #endif
8
9 #include <parlib.h>
10 #include <error.h>
11 #include <pool.h>
12 #include <assert.h>
13 #include <sys/queue.h>
14 #include <ros/syscall.h>
15 #include <ros/ring_syscall.h>
16 #include <mcs.h>
17
18 struct arsc_channel {
19         mcs_lock_t aclock;
20         syscall_sring_t* ring_page;
21         syscall_front_ring_t sysfr;
22 }; 
23
24 typedef struct arsc_channel arsc_channel_t;
25
26 #define SYS_CHANNEL (global_ac)
27 extern arsc_channel_t global_ac;
28 extern syscall_front_ring_t syscallfrontring;
29 extern sysevent_back_ring_t syseventbackring;
30
31 /*
32  * Syscall Descriptor: This helps userspace track a specific syscall.  Includes
33  * a cleanup function to be run when this syscall is complete.  Linked list of
34  * these for now. (Tail Queue)
35  */
36 typedef struct syscall_desc syscall_desc_t;
37 struct syscall_desc {
38         TAILQ_ENTRY(syscall_desc) next;
39         struct arsc_channel* channel;
40         uint32_t idx;
41 };
42 TAILQ_HEAD(syscall_desc_list, syscall_desc);
43 typedef struct syscall_desc_list syscall_desc_list_t;
44
45
46 // TODO: where to declare async syscalls?
47
48 // async callback
49 #define MAX_SYSCALLS 100
50 #define MAX_ASYNCCALLS 100
51
52 // The high-level object a process waits on, with multiple syscalls within.
53 typedef struct async_desc {
54         syscall_desc_list_t syslist;
55         void (*cleanup)(void* data);
56         void* data;
57 } async_desc_t;
58
59 // Response to an async call.  Should be some sort of aggregation of the
60 // syscall responses.
61 typedef struct async_rsp_t {
62         int32_t retval;
63 } async_rsp_t;
64
65 // This is per-thread, and used when entering a async library call to properly
66 // group syscall_desc_t used during the processing of that async call
67 extern async_desc_t* current_async_desc;
68
69 // This pooltype contains syscall_desc_t, which is how you wait on one syscall.
70 POOL_TYPE_DEFINE(syscall_desc_t, syscall_desc_pool, MAX_SYSCALLS);
71 POOL_TYPE_DEFINE(async_desc_t, async_desc_pool, MAX_ASYNCCALLS);
72
73 // These are declared in asynccall.c
74 extern syscall_desc_pool_t syscall_desc_pool;
75 extern async_desc_pool_t async_desc_pool;
76
77 /* Initialize front and back rings of syscall/event ring */
78 void init_arc(struct arsc_channel* ac);
79
80 int async_syscall(arsc_channel_t* chan, syscall_req_t* req, syscall_desc_t** desc_ptr2);
81
82 /* Generic Async Call */
83 int waiton_syscall(syscall_desc_t* desc);
84
85 /* Async group call */
86 // not sure how to get results back for these?
87
88 int waiton_group_call(async_desc_t* desc, async_rsp_t* rsp);
89
90 async_desc_t* get_async_desc(void);
91 syscall_desc_t* get_sys_desc(async_desc_t* desc);
92 int get_all_desc(async_desc_t** a_desc, syscall_desc_t** s_desc);
93
94 // helper function to make arc calls
95
96 syscall_desc_t* arc_call(long int num, ...);
97
98 #ifdef __cplusplus
99   }
100 #endif
101
102 #endif