1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* The communication mechanism for requesting that the driver perform work on
* behalf of the debugger. Messages are passed and processed in FIFO order,
* with no provision for high priority messages. High priority messages, such
* as debugger termination requests, should be passed using a different
* mechanism.
*
* Two FIFO queues are used for communication - one from the debugger to the
* driver, known as the driver_notify queue, and one from the driver to the
* debugger, known as the debugger_notify queue. Messages are added to one
* queue, processed by the party on the other end, and are sent back as
* acknowledgements on the other queue. All messages must be acknowledged, in
* part because the party who sent the message is the only one who can free it.
*
* Debugger-initiated work requests are usually triggered by dcmds such as
* ::load. In the case of a ::load, the debugger adds a load request to the
* driver_notify queue. The driver removes the request from the queue and
* processes it. When processing is complete, the message is turned into an
* acknowledgement, and completion status is added. The message is then added
* to the debugger_notify queue. Upon receipt, the debugger removes the
* message from the queue, notes the completion status, and frees it.
*
* The driver can itself initiate unsolicited work, such as the automatic
* loading of a dmod in response to a krtld module load notification. In this
* case, the driver loads the module and creates a work-completion message.
* This completion is identical to the one sent in the solicited load case
* above, with the exception of the acknowledgement bit, which isn't be set.
* When the debugger receives the completion message, it notes the completion
* status, and sends the message back to the driver via the driver_notify queue,
* this time with the acknowledgement bit set.
*/
#include <sys/types.h>
#include <kmdb/kmdb_asmutil.h>
#include <kmdb/kmdb_wr_impl.h>
#include <mdb/mdb_debug.h>
#include <mdb/mdb.h>
/*
* Called by the driver to pass a message to the debugger. The debugger could
* start running at any time. Nodes are added to the queue in FIFO order, but
* with links pointing in reverse order.
*/
void
kmdb_wr_debugger_notify(void *arg)
{
kmdb_wr_t *new = arg;
kmdb_wr_t *curtail;
new->wn_next = new->wn_prev = NULL;
membar_producer();
do {
if ((curtail = mdb.m_dbgwrtail) == NULL) {
/*
* The queue is empty, because tail will only be NULL if
* head is NULL too. We're the only one who can add
* to the queue, so we can blindly add our node. The
* debugger can't look at tail until head is non-NULL,
* so we set tail first.
*/
mdb.m_dbgwrtail = new;
membar_producer();
mdb.m_dbgwrhead = new;
membar_producer();
break;
}
/*
* Point the new node at the current tail. Attempt to set tail
* to point to our new node, but only as long as tail is what
* we think it is.
*/
new->wn_prev = curtail;
membar_producer();
} while (cas((uintptr_t *)&mdb.m_dbgwrtail, (uintptr_t)curtail,
(uintptr_t)new) != (uintptr_t)curtail);
}
/*
* Called by the debugger to receive messages from the driver. The driver
* has added the nodes in FIFO order, but has only set the prev pointers. We
* have to correct that before processing the nodes. This routine will not
* be preempted.
*/
int
kmdb_wr_debugger_process(int (*cb)(kmdb_wr_t *, void *), void *arg)
{
kmdb_wr_t *wn, *wnn;
int i;
if (mdb.m_dbgwrhead == NULL)
return (0); /* The queue is empty, so there's nothing to do */
/* Re-establish the next links so we can traverse in FIFO order */
mdb.m_dbgwrtail->wn_next = NULL;
for (wn = mdb.m_dbgwrtail; wn->wn_prev != NULL;
wn = wn->wn_prev)
wn->wn_prev->wn_next = wn;
/* We don't own wn after we've invoked the callback */
wn = mdb.m_dbgwrhead;
i = 0;
do {
wnn = wn->wn_next;
i += cb(wn, arg);
} while ((wn = wnn) != NULL);
mdb.m_dbgwrhead = mdb.m_dbgwrtail = NULL;
return (i);
}
/*
* Called by the debugger to check queue status.
*/
int
kmdb_wr_debugger_notify_isempty(void)
{
return (mdb.m_dbgwrhead == NULL);
}
/*
* Called by the debugger to pass a message to the driver. This routine will
* not be preempted.
*/
void
kmdb_wr_driver_notify(void *arg)
{
kmdb_wr_t *new = arg;
/*
* We restrict ourselves to manipulating the rear of the queue. We
* don't look at the head unless the tail is NULL.
*/
if (mdb.m_drvwrtail == NULL) {
new->wn_next = new->wn_prev = NULL;
mdb.m_drvwrhead = mdb.m_drvwrtail = new;
} else {
mdb.m_drvwrtail->wn_next = new;
new->wn_prev = mdb.m_drvwrtail;
new->wn_next = NULL;
mdb.m_drvwrtail = new;
}
}
/*
* Called by the driver to receive messages from the debugger. The debugger
* could start running at any time.
*
* NOTE: This routine may run *after* mdb_destroy(), and may *NOT* use any MDB
* services.
*/
int
kmdb_wr_driver_process(int (*cb)(kmdb_wr_t *, void *), void *arg)
{
kmdb_wr_t *worklist, *wn, *wnn;
int rc, rv, i;
if ((worklist = mdb.m_drvwrhead) == NULL) {
return (0); /* The queue is empty, so there's nothing to do */
}
mdb.m_drvwrhead = NULL;
/* The debugger uses tail, so enqueues still work */
membar_producer();
mdb.m_drvwrtail = NULL;
membar_producer();
/*
* The current set of messages has been removed from the queue, so
* we can process them at our leisure.
*/
wn = worklist;
rc = i = 0;
do {
wnn = wn->wn_next;
if ((rv = cb(wn, arg)) < 0)
rc = -1;
else
i += rv;
} while ((wn = wnn) != NULL);
return (rc == 0 ? i : -1);
}
/*
* Called by the debugger to check queue status
*/
int
kmdb_wr_driver_notify_isempty(void)
{
return (mdb.m_drvwrhead == NULL);
}
|