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
|
// pick up the common data structures
rc("cd /sys/src/cmd/fossil; mk 9fsys.acid");
include("/sys/src/cmd/fossil/9fsys.acid");
rc("cd /sys/src/cmd/fossil; mk cache.acid");
include("/sys/src/cmd/fossil/cache.acid");
rc("cd /sys/src/cmd/fossil; mk disk.acid");
include("/sys/src/cmd/fossil/disk.acid");
rc("cd /sys/src/cmd/fossil; mk fs.acid");
include("/sys/src/cmd/fossil/fs.acid");
rc("cd /sys/src/liboventi; mk plan9-thread.acid");
include("/sys/src/liboventi/plan9-thread.acid");
// make a list of pids from a list of Thread structures
defn _threadlist(t)
{
local l;
l = {};
while t do {
t = (Thread)t;
l = append l, t.pid;
t = t.next;
}
return l;
}
// print info about a VtRendez
defn vtrendez(r)
{
local l, t, w, q;
r = (VtRendez)r;
w = _threadlist(r.wfirst);
if match(pid, w) >= 0 then
print("\twaiting for wakeup\n");
l = (VtLock)r.lk;
q = _threadlist(l.qfirst);
if match(pid, q) >= 0 then
print("\tawakened; waiting for lock\n");
print("\tr=(VtRendez)", r\X, "\n");
print("\tl=(VtLock)", l\X, "\n");
if l.writer != 0 then {
t = (Thread)l.writer;
print("\tvtLock is held by ", t.pid\D, "\n");
}
}
// print info about a VtLock
defn vtlock(l)
{
local t;
l = (VtLock)l;
print("\tl=(VtLock)", l\X, "\n");
if l.writer then {
t = (Thread)l.writer;
print("\tvtLock is held by ", t.pid\D, "\n");
} else if l.readers then
print("\tvtLock is held by ", l.readers\D, " readers\n");
else
print("\tvtLock is not held!\n");
}
// try to say something intelligent about why a process is stuck.
_pauses = {
open,
pread,
pwrite,
sleep,
vtSleep,
vtLock,
vtRLock,
};
defn deadlocklist(l)
{
while l do {
setproc(head l);
deadlock();
l = tail l;
}
}
defn deadlock()
{
local stk, frame, name, stallframe, fossilframe, stallname;
stk = strace(*PC, *SP, linkreg(0));
print("setproc(", pid, ") // ", readfile("/proc/"+itoa(pid)+"/args"), "\n");
stallframe = 0;
stallname = "";
fossilframe = 0;
frame = {0};
while stk do {
lastframe = frame;
frame = head stk;
name = fmt(frame[0], 'a');
if !stallframe && match(name, _pauses) >= 0 then {
stallframe = frame;
stallname = name;
print("\t", fmt(frame[0], 'a'), "(");
params(frame[2]);
print(") ", pcfile(frame[0]), ":", pcline(frame[0]));
print("\n\t\tcalled from ", fmt(frame[1], 'a'), " ");
pfl(frame[1]);
}
if !fossilframe && regexp("^/sys/src/cmd/fossil/.*", pcfile(frame[0])) then {
if !stallframe then {
stallframe = lastframe;
stallname = fmt(lastframe[0], 'a');
print("\tunexpected stall: ", stallname, "\n");
if match(stallname, _pauses) >= 0 then
print("\t\t but it matches!\n");
}
fossilframe = frame;
print("\t", fmt(frame[0], 'a'), "(");
params(frame[2]);
print(") ", pcfile(frame[0]), ":", pcline(frame[0]));
print("\n\t\tcalled from ", fmt(frame[1], 'a'), " ");
pfl(frame[1]);
if name == cacheLocalLookup && stallname == vtLock then
print("\twaiting to lock block b=(Block)", *cacheLocalLookup:b\X, "\n");
if name == cacheLocal && stallname == vtSleep then
print("\tsleeping on block b=(Block)", *cacheLocal:b\X, "\n");
if name == blockWrite && stallname == vtSleep then
print("\tsleeping on block b=(Block)", *blockFlush:b\X, "\n");
}
stk = tail stk;
}
if stallname == vtSleep then
vtrendez(*vtSleep:q);
if stallname == vtLock then
vtlock(*vtLock:p);
if !stallframe || !fossilframe then {
print("\tconfused:");
if !stallframe then print(" stallframe?");
if !fossilframe then print(" fossilframe?");
print("\n");
}
print("\n");
}
// fetch fsys
defn
fsysGet(name)
{
return fsysmain;
}
// dump information about the cache
defn
cacheDump(c)
{
local i, b, x;
c = (Cache)c;
x = c.blocks;
i=0;
loop 1,c.nblocks do {
b = (Block)(x+i);
print(b\X, " ", b.pc\X, " ", b.ref\D, "\n");
i = i+sizeofBlock;
}
}
// print block info
defn
printblist(bl)
{
bl = (BList)bl;
while bl != 0 do {
print("[", bl.part\D, " ", bl.addr\X, " ", bl.vers\D, "]");
bl = bl.next;
if bl != 0 then
print(", ");
}
}
defn
block(b)
{
local i;
b = (Block)b;
print("b=(Block)", b\X, "\n");
print("\tref ", b.ref\D, " nlock ", b.nlock\D, "\n");
print("\tpav=[", b.part\D, " ", b.addr\X, " ", b.vers\D, "]\n");
print("\tprior=");
printblist(b.prior);
print("\n");
print("\tunlink=");
printblist(b.uhead);
print("\n");
}
|