Skip to content
Newer
Older
100644 200 lines (177 sloc) 6.2 KB
ece04fd This is the initial implmentation of the LWKT messaging infrastructure.
Matthew Dillon authored
1 /*
2 * SYS/MSGPORT.H
3 *
4 * Implements LWKT messages and ports.
5 *
f2c8b5a Resurrect priority message support; there is always +/-5~10K measurem…
Sepherosa Ziehau authored
6 * $DragonFly: src/sys/sys/msgport.h,v 1.32 2008/11/26 15:05:42 sephe Exp $
ece04fd This is the initial implmentation of the LWKT messaging infrastructure.
Matthew Dillon authored
7 */
8
9 #ifndef _SYS_MSGPORT_H_
10 #define _SYS_MSGPORT_H_
11
12 #ifndef _SYS_QUEUE_H_
13 #include <sys/queue.h> /* TAILQ_* macros */
14 #endif
0522061 Do some fairly major include file cleanups to further separate kernel…
Matthew Dillon authored
15 #ifndef _SYS_STDINT_H_
16 #include <sys/stdint.h>
17 #endif
fb0f29c LWKT message ports contain a number of function pointers which abstract
Matthew Dillon authored
18 #ifndef _SYS_SPINLOCK_H_
19 #include <sys/spinlock.h>
20 #endif
ece04fd This is the initial implmentation of the LWKT messaging infrastructure.
Matthew Dillon authored
21
6aad077 Embed the netmsg in the mbuf itself rather than allocating one for
Matthew Dillon authored
22 #ifdef _KERNEL
23
24 #ifndef _SYS_MALLOC_H_
25 #include <sys/malloc.h>
26 #endif
27
28 #endif
29
ece04fd This is the initial implmentation of the LWKT messaging infrastructure.
Matthew Dillon authored
30 struct lwkt_msg;
31 struct lwkt_port;
74208df Add serializer port backend. Implementation is mainly based on spin
Sepherosa Ziehau authored
32 struct lwkt_serialize;
335dda3 DEV messaging stage 2/4: In this stage all DEV commands are now being
Matthew Dillon authored
33 struct thread;
ece04fd This is the initial implmentation of the LWKT messaging infrastructure.
Matthew Dillon authored
34
35 typedef struct lwkt_msg *lwkt_msg_t;
36 typedef struct lwkt_port *lwkt_port_t;
37
335dda3 DEV messaging stage 2/4: In this stage all DEV commands are now being
Matthew Dillon authored
38 typedef TAILQ_HEAD(lwkt_msg_queue, lwkt_msg) lwkt_msg_queue;
39
ece04fd This is the initial implmentation of the LWKT messaging infrastructure.
Matthew Dillon authored
40 /*
41 * The standard message and port structure for communications between
42 * threads. See kern/lwkt_msgport.c for documentation on how messages and
43 * ports work.
a64ba18 Preliminary syscall messaging work. Adjust all <syscall>_args structures
Matthew Dillon authored
44 *
4599cf1 * Greatly reduce the complexity of the LWKT messaging and port abstra…
Matthew Dillon authored
45 * A message may only be manipulated by whomever currently owns it,
46 * which generally means the originating port if the message has
e7906ee Implement lwkt_abortmsg() support. This function chases down a messag…
Matthew Dillon authored
47 * not been sent yet or has been replied, and the target port if the message
48 * has been sent and/or is undergoing processing.
49 *
a64ba18 Preliminary syscall messaging work. Adjust all <syscall>_args structures
Matthew Dillon authored
50 * NOTE! 64-bit-align this structure.
ece04fd This is the initial implmentation of the LWKT messaging infrastructure.
Matthew Dillon authored
51 */
52 typedef struct lwkt_msg {
ce280ce Remove confusing comment.
Matthew Dillon authored
53 TAILQ_ENTRY(lwkt_msg) ms_node; /* link node */
df2244e This is a major cleanup of the LWKT message port code. The messaging …
Matthew Dillon authored
54 lwkt_port_t ms_target_port; /* current target or relay port */
e7906ee Implement lwkt_abortmsg() support. This function chases down a messag…
Matthew Dillon authored
55 lwkt_port_t ms_reply_port; /* async replies returned here */
4599cf1 * Greatly reduce the complexity of the LWKT messaging and port abstra…
Matthew Dillon authored
56 void (*ms_abortfn)(struct lwkt_msg *);
df2244e This is a major cleanup of the LWKT message port code. The messaging …
Matthew Dillon authored
57 int ms_flags; /* message flags */
58 int ms_error; /* positive error code or 0 */
a64ba18 Preliminary syscall messaging work. Adjust all <syscall>_args structures
Matthew Dillon authored
59 union {
df2244e This is a major cleanup of the LWKT message port code. The messaging …
Matthew Dillon authored
60 void *ms_resultp; /* misc pointer data or result */
90b9818 syscall messaging 2: Change the standard return value storage for system
Matthew Dillon authored
61 int ms_result; /* standard 'int'eger result */
62 long ms_lresult; /* long result */
63 int ms_fds[2]; /* two int bit results */
0522061 Do some fairly major include file cleanups to further separate kernel…
Matthew Dillon authored
64 __int32_t ms_result32; /* 32 bit result */
65 __int64_t ms_result64; /* 64 bit result */
66 __off_t ms_offset; /* off_t result */
a64ba18 Preliminary syscall messaging work. Adjust all <syscall>_args structures
Matthew Dillon authored
67 } u;
68 int ms_pad[2]; /* future use */
ece04fd This is the initial implmentation of the LWKT messaging infrastructure.
Matthew Dillon authored
69 } lwkt_msg;
70
4599cf1 * Greatly reduce the complexity of the LWKT messaging and port abstra…
Matthew Dillon authored
71 /*
72 * Message state flags are manipulated by the current owner only.
73 *
74 * DONE Indicates completion of the reply. This flag is also set
75 * for unsent messages.
76 *
77 * REPLY Indicates message is being replied but may or may not
78 * have been queued or returned yet. This bit is left set
79 * when a message is retrieved from a reply port so the caller
80 * can distinguish between requests and replies.
81 *
82 * QUEUED Indicates message is queued on reply or target port, or
83 * some other port.
84 *
85 * SYNC Indicates that the originator is blocked directly on the
86 * message and that the message should be signaled on
87 * completion instead of queued.
88 *
89 * INTRANSIT Indicates that the message state is indeterminant (e.g.
90 * being passed through an IPI).
91 *
92 * ABORTABLE Static flag indicates that ms_abortfn is valid.
f5bcf2d AMD64 Support:
Matthew Dillon authored
93 *
94 * High 16 bits are available to message handlers.
4599cf1 * Greatly reduce the complexity of the LWKT messaging and port abstra…
Matthew Dillon authored
95 */
96 #define MSGF_DONE 0x0001 /* message is complete */
97 #define MSGF_REPLY 0x0002 /* asynch message has been returned */
ece04fd This is the initial implmentation of the LWKT messaging infrastructure.
Matthew Dillon authored
98 #define MSGF_QUEUED 0x0004 /* message has been queued sanitychk */
4599cf1 * Greatly reduce the complexity of the LWKT messaging and port abstra…
Matthew Dillon authored
99 #define MSGF_SYNC 0x0008 /* synchronous message operation */
100 #define MSGF_INTRANSIT 0x0010 /* in-transit (IPI) */
361d01d Add a MSGF_NORESCHED feature for lwkt thread-based message ports. The
Matthew Dillon authored
101 #define MSGF_NORESCHED 0x0020 /* do not reschedule target lwkt */
e2ff022 - Add priority message queue to msgport. Send a message with MSGF_PRI…
Sepherosa Ziehau authored
102 #define MSGF_DROPABLE 0x0040 /* message supports drop */
b44419c Revamp the initial lwkt_abortmsg() support to normalize the abstracti…
Matthew Dillon authored
103 #define MSGF_ABORTABLE 0x0080 /* message supports abort */
f2c8b5a Resurrect priority message support; there is always +/-5~10K measurem…
Sepherosa Ziehau authored
104 #define MSGF_PRIORITY 0x0100 /* priority message */
ece04fd This is the initial implmentation of the LWKT messaging infrastructure.
Matthew Dillon authored
105
f5bcf2d AMD64 Support:
Matthew Dillon authored
106 #define MSGF_USER0 0x00010000
107 #define MSGF_USER1 0x00020000
108 #define MSGF_USER2 0x00040000
109 #define MSGF_USER3 0x00080000
110
335dda3 DEV messaging stage 2/4: In this stage all DEV commands are now being
Matthew Dillon authored
111 #define MSG_CMD_CDEV 0x00010000
112 #define MSG_CMD_VFS 0x00020000
113 #define MSG_CMD_SYSCALL 0x00030000
114 #define MSG_SUBCMD_MASK 0x0000FFFF
115
9eeaa8a Dispatch upper-half protocol request handling.
Jeffrey Hsu authored
116 #ifdef _KERNEL
117 MALLOC_DECLARE(M_LWKTMSG);
118 #endif
119
3efe700 Recent accept() changes started depending on the protosw->pr_mport field
Matthew Dillon authored
120 /*
121 * Notes on port processing requirements:
122 *
123 * mp_putport():
124 * - may return synchronous error code (error != EASYNC) directly and
125 * does not need to check or set MSGF_DONE if so, or set ms_target_port
126 * - for asynch procesing should clear MSGF_DONE and set ms_target_port
127 * to port prior to initiation of the command.
128 *
a22c590 Add lwkt_sleep() to formalize a shortcut numerous bits of code have been
Matthew Dillon authored
129 * mp_waitmsg():
130 * - wait for a particular message to be returned.
131 *
3efe700 Recent accept() changes started depending on the protosw->pr_mport field
Matthew Dillon authored
132 * mp_waitport():
a22c590 Add lwkt_sleep() to formalize a shortcut numerous bits of code have been
Matthew Dillon authored
133 * - wait for a new message on the specified port.
3efe700 Recent accept() changes started depending on the protosw->pr_mport field
Matthew Dillon authored
134 *
135 * mp_replyport():
136 * - reply a message (executed on the originating port to return a
137 * message to it). This can be rather involved if abort is to be
138 * supported, see lwkt_default_replyport(). Generally speaking
fb0f29c LWKT message ports contain a number of function pointers which abstract
Matthew Dillon authored
139 * one sets MSGF_DONE. If MSGF_SYNC is set the message is not
140 * queued to the port and the reply code wakes up the waiter
141 * directly.
142 *
143 * The use of mp_u.td and mp_u.spin is specific to the port callback function
144 * set. Default ports are tied to specific threads and use cpu locality
145 * of reference and mp_u.td (and not mp_u.spin at all). Descriptor ports
146 * assume access via descriptors, signal interruption, etc. Such ports use
147 * mp_u.spin (and not mp_u.td at all) and may be accessed by multiple threads.
3efe700 Recent accept() changes started depending on the protosw->pr_mport field
Matthew Dillon authored
148 */
ece04fd This is the initial implmentation of the LWKT messaging infrastructure.
Matthew Dillon authored
149 typedef struct lwkt_port {
150 lwkt_msg_queue mp_msgq;
f2c8b5a Resurrect priority message support; there is always +/-5~10K measurem…
Sepherosa Ziehau authored
151 lwkt_msg_queue mp_msgq_prio;
ece04fd This is the initial implmentation of the LWKT messaging infrastructure.
Matthew Dillon authored
152 int mp_flags;
fb0f29c LWKT message ports contain a number of function pointers which abstract
Matthew Dillon authored
153 union {
154 struct spinlock spin;
155 struct thread *td;
74208df Add serializer port backend. Implementation is mainly based on spin
Sepherosa Ziehau authored
156 struct lwkt_serialize *serialize;
fb0f29c LWKT message ports contain a number of function pointers which abstract
Matthew Dillon authored
157 void *data;
158 } mp_u;
159 void * (*mp_getport)(lwkt_port_t);
df2244e This is a major cleanup of the LWKT message port code. The messaging …
Matthew Dillon authored
160 int (*mp_putport)(lwkt_port_t, lwkt_msg_t);
a22c590 Add lwkt_sleep() to formalize a shortcut numerous bits of code have been
Matthew Dillon authored
161 int (*mp_waitmsg)(lwkt_msg_t, int flags);
162 void * (*mp_waitport)(lwkt_port_t, int flags);
df2244e This is a major cleanup of the LWKT message port code. The messaging …
Matthew Dillon authored
163 void (*mp_replyport)(lwkt_port_t, lwkt_msg_t);
e2ff022 - Add priority message queue to msgport. Send a message with MSGF_PRI…
Sepherosa Ziehau authored
164 void (*mp_dropmsg)(lwkt_port_t, lwkt_msg_t);
ece04fd This is the initial implmentation of the LWKT messaging infrastructure.
Matthew Dillon authored
165 } lwkt_port;
166
fb0f29c LWKT message ports contain a number of function pointers which abstract
Matthew Dillon authored
167 #ifdef _KERNEL
168
169 #define mpu_td mp_u.td
170 #define mpu_spin mp_u.spin
74208df Add serializer port backend. Implementation is mainly based on spin
Sepherosa Ziehau authored
171 #define mpu_serialize mp_u.serialize
fb0f29c LWKT message ports contain a number of function pointers which abstract
Matthew Dillon authored
172 #define mpu_data mp_u.data
173
174 #endif
175
ece04fd This is the initial implmentation of the LWKT messaging infrastructure.
Matthew Dillon authored
176 #define MSGPORTF_WAITING 0x0001
177
df2244e This is a major cleanup of the LWKT message port code. The messaging …
Matthew Dillon authored
178 /*
179 * These functions are good for userland as well as the kernel. The
180 * messaging function support for userland is provided by the kernel's
181 * kern/lwkt_msgport.c. The port functions are provided by userland.
182 */
fb0f29c LWKT message ports contain a number of function pointers which abstract
Matthew Dillon authored
183
184 void lwkt_initport_thread(lwkt_port_t, struct thread *);
185 void lwkt_initport_spin(lwkt_port_t);
74208df Add serializer port backend. Implementation is mainly based on spin
Sepherosa Ziehau authored
186 void lwkt_initport_serialize(lwkt_port_t, struct lwkt_serialize *);
fb0f29c LWKT message ports contain a number of function pointers which abstract
Matthew Dillon authored
187 void lwkt_initport_panic(lwkt_port_t);
188 void lwkt_initport_replyonly_null(lwkt_port_t);
189 void lwkt_initport_replyonly(lwkt_port_t,
190 void (*rportfn)(lwkt_port_t, lwkt_msg_t));
191 void lwkt_initport_putonly(lwkt_port_t,
192 int (*pportfn)(lwkt_port_t, lwkt_msg_t));
193
984ccc1 Export the lwkt_default_*() message port default functions so other
Matthew Dillon authored
194 void lwkt_sendmsg(lwkt_port_t, lwkt_msg_t);
a22c590 Add lwkt_sleep() to formalize a shortcut numerous bits of code have been
Matthew Dillon authored
195 int lwkt_domsg(lwkt_port_t, lwkt_msg_t, int);
e7906ee Implement lwkt_abortmsg() support. This function chases down a messag…
Matthew Dillon authored
196 int lwkt_forwardmsg(lwkt_port_t, lwkt_msg_t);
197 void lwkt_abortmsg(lwkt_msg_t);
ece04fd This is the initial implmentation of the LWKT messaging infrastructure.
Matthew Dillon authored
198
199 #endif
Something went wrong with that request. Please try again.