Fix the kinfo run/sleep state for pure kernel threads. This effects /bin/ps
[dragonfly.git] / sys / sys / msgport.h
CommitLineData
ece04fd0
MD
1/*
2 * SYS/MSGPORT.H
3 *
4 * Implements LWKT messages and ports.
5 *
4599cf19 6 * $DragonFly: src/sys/sys/msgport.h,v 1.24 2007/05/23 08:56:59 dillon Exp $
ece04fd0
MD
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
05220613
MD
15#ifndef _SYS_STDINT_H_
16#include <sys/stdint.h>
17#endif
ece04fd0 18
6aad077d
MD
19#ifdef _KERNEL
20
21#ifndef _SYS_MALLOC_H_
22#include <sys/malloc.h>
23#endif
24
25#endif
26
ece04fd0
MD
27struct lwkt_msg;
28struct lwkt_port;
335dda38 29struct thread;
ece04fd0
MD
30
31typedef struct lwkt_msg *lwkt_msg_t;
32typedef struct lwkt_port *lwkt_port_t;
33
335dda38
MD
34typedef TAILQ_HEAD(lwkt_msg_queue, lwkt_msg) lwkt_msg_queue;
35
ece04fd0
MD
36/*
37 * The standard message and port structure for communications between
38 * threads. See kern/lwkt_msgport.c for documentation on how messages and
39 * ports work.
a64ba182 40 *
4599cf19
MD
41 * A message may only be manipulated by whomever currently owns it,
42 * which generally means the originating port if the message has
e7906ee5
MD
43 * not been sent yet or has been replied, and the target port if the message
44 * has been sent and/or is undergoing processing.
45 *
a64ba182 46 * NOTE! 64-bit-align this structure.
ece04fd0
MD
47 */
48typedef struct lwkt_msg {
ce280ce5 49 TAILQ_ENTRY(lwkt_msg) ms_node; /* link node */
df2244e3 50 lwkt_port_t ms_target_port; /* current target or relay port */
e7906ee5 51 lwkt_port_t ms_reply_port; /* async replies returned here */
4599cf19 52 void (*ms_abortfn)(struct lwkt_msg *);
df2244e3 53 int ms_flags; /* message flags */
df2244e3 54 int ms_error; /* positive error code or 0 */
a64ba182 55 union {
df2244e3 56 void *ms_resultp; /* misc pointer data or result */
90b9818c
MD
57 int ms_result; /* standard 'int'eger result */
58 long ms_lresult; /* long result */
59 int ms_fds[2]; /* two int bit results */
05220613
MD
60 __int32_t ms_result32; /* 32 bit result */
61 __int64_t ms_result64; /* 64 bit result */
62 __off_t ms_offset; /* off_t result */
a64ba182
MD
63 } u;
64 int ms_pad[2]; /* future use */
ece04fd0
MD
65} lwkt_msg;
66
4599cf19
MD
67/*
68 * Message state flags are manipulated by the current owner only.
69 *
70 * DONE Indicates completion of the reply. This flag is also set
71 * for unsent messages.
72 *
73 * REPLY Indicates message is being replied but may or may not
74 * have been queued or returned yet. This bit is left set
75 * when a message is retrieved from a reply port so the caller
76 * can distinguish between requests and replies.
77 *
78 * QUEUED Indicates message is queued on reply or target port, or
79 * some other port.
80 *
81 * SYNC Indicates that the originator is blocked directly on the
82 * message and that the message should be signaled on
83 * completion instead of queued.
84 *
85 * INTRANSIT Indicates that the message state is indeterminant (e.g.
86 * being passed through an IPI).
87 *
88 * PCATCH Static flag indicates blocking entity can be interrupted.
89 *
90 * ABORTABLE Static flag indicates that ms_abortfn is valid.
91 */
92#define MSGF_DONE 0x0001 /* message is complete */
93#define MSGF_REPLY 0x0002 /* asynch message has been returned */
ece04fd0 94#define MSGF_QUEUED 0x0004 /* message has been queued sanitychk */
4599cf19
MD
95#define MSGF_SYNC 0x0008 /* synchronous message operation */
96#define MSGF_INTRANSIT 0x0010 /* in-transit (IPI) */
e7906ee5 97#define MSGF_PCATCH 0x0020 /* catch proc signal while waiting */
b44419cb 98#define MSGF_ABORTABLE 0x0080 /* message supports abort */
ece04fd0 99
335dda38
MD
100#define MSG_CMD_CDEV 0x00010000
101#define MSG_CMD_VFS 0x00020000
102#define MSG_CMD_SYSCALL 0x00030000
103#define MSG_SUBCMD_MASK 0x0000FFFF
104
9eeaa8a9 105#ifdef _KERNEL
9eeaa8a9
JH
106MALLOC_DECLARE(M_LWKTMSG);
107#endif
9eeaa8a9 108
3efe7008
MD
109/*
110 * Notes on port processing requirements:
111 *
112 * mp_putport():
113 * - may return synchronous error code (error != EASYNC) directly and
114 * does not need to check or set MSGF_DONE if so, or set ms_target_port
115 * - for asynch procesing should clear MSGF_DONE and set ms_target_port
116 * to port prior to initiation of the command.
117 *
118 * mp_waitport():
119 * - if the passed msg is NULL we wait for, remove, and return the
120 * next pending message on the port.
121 * - if the passed msg is non-NULL we wait for that particular message,
122 * which typically involves waiting until MSGF_DONE is set then
123 * pulling the message off the port if MSGF_QUEUED is set and
124 * returning it. If MSGF_PCATCH is set in the message we allow
125 * a signal to interrupt and abort the message.
126 *
127 * mp_replyport():
128 * - reply a message (executed on the originating port to return a
129 * message to it). This can be rather involved if abort is to be
130 * supported, see lwkt_default_replyport(). Generally speaking
131 * one sets MSGF_DONE. If MSGF_ASYNC is set the message is queued
132 * to the port, else the port's thread is scheduled.
3efe7008 133 */
ece04fd0
MD
134typedef struct lwkt_port {
135 lwkt_msg_queue mp_msgq;
136 int mp_flags;
1fa2b4b4 137 int mp_unused01;
335dda38 138 struct thread *mp_td;
df2244e3
MD
139 int (*mp_putport)(lwkt_port_t, lwkt_msg_t);
140 void * (*mp_waitport)(lwkt_port_t, lwkt_msg_t);
141 void (*mp_replyport)(lwkt_port_t, lwkt_msg_t);
ece04fd0
MD
142} lwkt_port;
143
144#define MSGPORTF_WAITING 0x0001
145
df2244e3
MD
146/*
147 * These functions are good for userland as well as the kernel. The
148 * messaging function support for userland is provided by the kernel's
149 * kern/lwkt_msgport.c. The port functions are provided by userland.
150 */
984ccc17 151void lwkt_initport(lwkt_port_t, struct thread *);
be86a874 152void lwkt_initport_null_rport(lwkt_port_t, struct thread *);
984ccc17
MD
153void lwkt_sendmsg(lwkt_port_t, lwkt_msg_t);
154int lwkt_domsg(lwkt_port_t, lwkt_msg_t);
e7906ee5
MD
155int lwkt_forwardmsg(lwkt_port_t, lwkt_msg_t);
156void lwkt_abortmsg(lwkt_msg_t);
984ccc17
MD
157void *lwkt_getport(lwkt_port_t);
158
159int lwkt_default_putport(lwkt_port_t port, lwkt_msg_t msg);
160void *lwkt_default_waitport(lwkt_port_t port, lwkt_msg_t msg);
161void lwkt_default_replyport(lwkt_port_t port, lwkt_msg_t msg);
162void lwkt_default_abortport(lwkt_port_t port, lwkt_msg_t msg);
be86a874 163void lwkt_null_replyport(lwkt_port_t port, lwkt_msg_t msg);
ece04fd0 164
ece04fd0 165#endif