forked from illumos/illumos-gate
-
Notifications
You must be signed in to change notification settings - Fork 109
/
genunix.c
4581 lines (3955 loc) · 125 KB
/
genunix.c
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved.
* Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012 Joyent, Inc. All rights reserved.
*/
#include <mdb/mdb_param.h>
#include <mdb/mdb_modapi.h>
#include <mdb/mdb_ks.h>
#include <mdb/mdb_ctf.h>
#include <sys/types.h>
#include <sys/thread.h>
#include <sys/session.h>
#include <sys/user.h>
#include <sys/proc.h>
#include <sys/var.h>
#include <sys/t_lock.h>
#include <sys/callo.h>
#include <sys/priocntl.h>
#include <sys/class.h>
#include <sys/regset.h>
#include <sys/stack.h>
#include <sys/cpuvar.h>
#include <sys/vnode.h>
#include <sys/vfs.h>
#include <sys/flock_impl.h>
#include <sys/kmem_impl.h>
#include <sys/vmem_impl.h>
#include <sys/kstat.h>
#include <sys/dditypes.h>
#include <sys/ddi_impldefs.h>
#include <sys/sysmacros.h>
#include <sys/sysconf.h>
#include <sys/task.h>
#include <sys/project.h>
#include <sys/errorq_impl.h>
#include <sys/cred_impl.h>
#include <sys/zone.h>
#include <sys/panic.h>
#include <regex.h>
#include <sys/port_impl.h>
#include "avl.h"
#include "bio.h"
#include "bitset.h"
#include "combined.h"
#include "contract.h"
#include "cpupart_mdb.h"
#include "cred.h"
#include "ctxop.h"
#include "cyclic.h"
#include "damap.h"
#include "devinfo.h"
#include "findstack.h"
#include "fm.h"
#include "group.h"
#include "irm.h"
#include "kgrep.h"
#include "kmem.h"
#include "ldi.h"
#include "leaky.h"
#include "lgrp.h"
#include "list.h"
#include "log.h"
#include "mdi.h"
#include "memory.h"
#include "mmd.h"
#include "modhash.h"
#include "ndievents.h"
#include "net.h"
#include "netstack.h"
#include "nvpair.h"
#include "pg.h"
#include "rctl.h"
#include "sobj.h"
#include "streams.h"
#include "sysevent.h"
#include "taskq.h"
#include "thread.h"
#include "tsd.h"
#include "tsol.h"
#include "typegraph.h"
#include "vfs.h"
#include "zone.h"
#include "hotplug.h"
/*
* Surely this is defined somewhere...
*/
#define NINTR 16
#ifndef STACK_BIAS
#define STACK_BIAS 0
#endif
static char
pstat2ch(uchar_t state)
{
switch (state) {
case SSLEEP: return ('S');
case SRUN: return ('R');
case SZOMB: return ('Z');
case SIDL: return ('I');
case SONPROC: return ('O');
case SSTOP: return ('T');
case SWAIT: return ('W');
default: return ('?');
}
}
#define PS_PRTTHREADS 0x1
#define PS_PRTLWPS 0x2
#define PS_PSARGS 0x4
#define PS_TASKS 0x8
#define PS_PROJECTS 0x10
#define PS_ZONES 0x20
static int
ps_threadprint(uintptr_t addr, const void *data, void *private)
{
const kthread_t *t = (const kthread_t *)data;
uint_t prt_flags = *((uint_t *)private);
static const mdb_bitmask_t t_state_bits[] = {
{ "TS_FREE", UINT_MAX, TS_FREE },
{ "TS_SLEEP", TS_SLEEP, TS_SLEEP },
{ "TS_RUN", TS_RUN, TS_RUN },
{ "TS_ONPROC", TS_ONPROC, TS_ONPROC },
{ "TS_ZOMB", TS_ZOMB, TS_ZOMB },
{ "TS_STOPPED", TS_STOPPED, TS_STOPPED },
{ "TS_WAIT", TS_WAIT, TS_WAIT },
{ NULL, 0, 0 }
};
if (prt_flags & PS_PRTTHREADS)
mdb_printf("\tT %?a <%b>\n", addr, t->t_state, t_state_bits);
if (prt_flags & PS_PRTLWPS)
mdb_printf("\tL %?a ID: %u\n", t->t_lwp, t->t_tid);
return (WALK_NEXT);
}
int
ps(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
{
uint_t prt_flags = 0;
proc_t pr;
struct pid pid, pgid, sid;
sess_t session;
cred_t cred;
task_t tk;
kproject_t pj;
zone_t zn;
if (!(flags & DCMD_ADDRSPEC)) {
if (mdb_walk_dcmd("proc", "ps", argc, argv) == -1) {
mdb_warn("can't walk 'proc'");
return (DCMD_ERR);
}
return (DCMD_OK);
}
if (mdb_getopts(argc, argv,
'f', MDB_OPT_SETBITS, PS_PSARGS, &prt_flags,
'l', MDB_OPT_SETBITS, PS_PRTLWPS, &prt_flags,
'T', MDB_OPT_SETBITS, PS_TASKS, &prt_flags,
'P', MDB_OPT_SETBITS, PS_PROJECTS, &prt_flags,
'z', MDB_OPT_SETBITS, PS_ZONES, &prt_flags,
't', MDB_OPT_SETBITS, PS_PRTTHREADS, &prt_flags, NULL) != argc)
return (DCMD_USAGE);
if (DCMD_HDRSPEC(flags)) {
mdb_printf("%<u>%1s %6s %6s %6s %6s ",
"S", "PID", "PPID", "PGID", "SID");
if (prt_flags & PS_TASKS)
mdb_printf("%5s ", "TASK");
if (prt_flags & PS_PROJECTS)
mdb_printf("%5s ", "PROJ");
if (prt_flags & PS_ZONES)
mdb_printf("%5s ", "ZONE");
mdb_printf("%6s %10s %?s %s%</u>\n",
"UID", "FLAGS", "ADDR", "NAME");
}
mdb_vread(&pr, sizeof (pr), addr);
mdb_vread(&pid, sizeof (pid), (uintptr_t)pr.p_pidp);
mdb_vread(&pgid, sizeof (pgid), (uintptr_t)pr.p_pgidp);
mdb_vread(&cred, sizeof (cred), (uintptr_t)pr.p_cred);
mdb_vread(&session, sizeof (session), (uintptr_t)pr.p_sessp);
mdb_vread(&sid, sizeof (sid), (uintptr_t)session.s_sidp);
if (prt_flags & (PS_TASKS | PS_PROJECTS))
mdb_vread(&tk, sizeof (tk), (uintptr_t)pr.p_task);
if (prt_flags & PS_PROJECTS)
mdb_vread(&pj, sizeof (pj), (uintptr_t)tk.tk_proj);
if (prt_flags & PS_ZONES)
mdb_vread(&zn, sizeof (zone_t), (uintptr_t)pr.p_zone);
mdb_printf("%c %6d %6d %6d %6d ",
pstat2ch(pr.p_stat), pid.pid_id, pr.p_ppid, pgid.pid_id,
sid.pid_id);
if (prt_flags & PS_TASKS)
mdb_printf("%5d ", tk.tk_tkid);
if (prt_flags & PS_PROJECTS)
mdb_printf("%5d ", pj.kpj_id);
if (prt_flags & PS_ZONES)
mdb_printf("%5d ", zn.zone_id);
mdb_printf("%6d 0x%08x %0?p %s\n",
cred.cr_uid, pr.p_flag, addr,
(prt_flags & PS_PSARGS) ? pr.p_user.u_psargs : pr.p_user.u_comm);
if (prt_flags & ~PS_PSARGS)
(void) mdb_pwalk("thread", ps_threadprint, &prt_flags, addr);
return (DCMD_OK);
}
#define PG_NEWEST 0x0001
#define PG_OLDEST 0x0002
#define PG_PIPE_OUT 0x0004
#define PG_EXACT_MATCH 0x0008
typedef struct pgrep_data {
uint_t pg_flags;
uint_t pg_psflags;
uintptr_t pg_xaddr;
hrtime_t pg_xstart;
const char *pg_pat;
#ifndef _KMDB
regex_t pg_reg;
#endif
} pgrep_data_t;
/*ARGSUSED*/
static int
pgrep_cb(uintptr_t addr, const void *pdata, void *data)
{
const proc_t *prp = pdata;
pgrep_data_t *pgp = data;
#ifndef _KMDB
regmatch_t pmatch;
#endif
/*
* kmdb doesn't have access to the reg* functions, so we fall back
* to strstr/strcmp.
*/
#ifdef _KMDB
if ((pgp->pg_flags & PG_EXACT_MATCH) ?
(strcmp(prp->p_user.u_comm, pgp->pg_pat) != 0) :
(strstr(prp->p_user.u_comm, pgp->pg_pat) == NULL))
return (WALK_NEXT);
#else
if (regexec(&pgp->pg_reg, prp->p_user.u_comm, 1, &pmatch, 0) != 0)
return (WALK_NEXT);
if ((pgp->pg_flags & PG_EXACT_MATCH) &&
(pmatch.rm_so != 0 || prp->p_user.u_comm[pmatch.rm_eo] != '\0'))
return (WALK_NEXT);
#endif
if (pgp->pg_flags & (PG_NEWEST | PG_OLDEST)) {
hrtime_t start;
start = (hrtime_t)prp->p_user.u_start.tv_sec * NANOSEC +
prp->p_user.u_start.tv_nsec;
if (pgp->pg_flags & PG_NEWEST) {
if (pgp->pg_xaddr == NULL || start > pgp->pg_xstart) {
pgp->pg_xaddr = addr;
pgp->pg_xstart = start;
}
} else {
if (pgp->pg_xaddr == NULL || start < pgp->pg_xstart) {
pgp->pg_xaddr = addr;
pgp->pg_xstart = start;
}
}
} else if (pgp->pg_flags & PG_PIPE_OUT) {
mdb_printf("%p\n", addr);
} else {
if (mdb_call_dcmd("ps", addr, pgp->pg_psflags, 0, NULL) != 0) {
mdb_warn("can't invoke 'ps'");
return (WALK_DONE);
}
pgp->pg_psflags &= ~DCMD_LOOPFIRST;
}
return (WALK_NEXT);
}
/*ARGSUSED*/
int
pgrep(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
{
pgrep_data_t pg;
int i;
#ifndef _KMDB
int err;
#endif
if (flags & DCMD_ADDRSPEC)
return (DCMD_USAGE);
pg.pg_flags = 0;
pg.pg_xaddr = 0;
i = mdb_getopts(argc, argv,
'n', MDB_OPT_SETBITS, PG_NEWEST, &pg.pg_flags,
'o', MDB_OPT_SETBITS, PG_OLDEST, &pg.pg_flags,
'x', MDB_OPT_SETBITS, PG_EXACT_MATCH, &pg.pg_flags,
NULL);
argc -= i;
argv += i;
if (argc != 1)
return (DCMD_USAGE);
/*
* -n and -o are mutually exclusive.
*/
if ((pg.pg_flags & PG_NEWEST) && (pg.pg_flags & PG_OLDEST))
return (DCMD_USAGE);
if (argv->a_type != MDB_TYPE_STRING)
return (DCMD_USAGE);
if (flags & DCMD_PIPE_OUT)
pg.pg_flags |= PG_PIPE_OUT;
pg.pg_pat = argv->a_un.a_str;
if (DCMD_HDRSPEC(flags))
pg.pg_psflags = DCMD_ADDRSPEC | DCMD_LOOP | DCMD_LOOPFIRST;
else
pg.pg_psflags = DCMD_ADDRSPEC | DCMD_LOOP;
#ifndef _KMDB
if ((err = regcomp(&pg.pg_reg, pg.pg_pat, REG_EXTENDED)) != 0) {
size_t nbytes;
char *buf;
nbytes = regerror(err, &pg.pg_reg, NULL, 0);
buf = mdb_alloc(nbytes + 1, UM_SLEEP | UM_GC);
(void) regerror(err, &pg.pg_reg, buf, nbytes);
mdb_warn("%s\n", buf);
return (DCMD_ERR);
}
#endif
if (mdb_walk("proc", pgrep_cb, &pg) != 0) {
mdb_warn("can't walk 'proc'");
return (DCMD_ERR);
}
if (pg.pg_xaddr != 0 && (pg.pg_flags & (PG_NEWEST | PG_OLDEST))) {
if (pg.pg_flags & PG_PIPE_OUT) {
mdb_printf("%p\n", pg.pg_xaddr);
} else {
if (mdb_call_dcmd("ps", pg.pg_xaddr, pg.pg_psflags,
0, NULL) != 0) {
mdb_warn("can't invoke 'ps'");
return (DCMD_ERR);
}
}
}
return (DCMD_OK);
}
int
task(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
{
task_t tk;
kproject_t pj;
if (!(flags & DCMD_ADDRSPEC)) {
if (mdb_walk_dcmd("task_cache", "task", argc, argv) == -1) {
mdb_warn("can't walk task_cache");
return (DCMD_ERR);
}
return (DCMD_OK);
}
if (DCMD_HDRSPEC(flags)) {
mdb_printf("%<u>%?s %6s %6s %6s %6s %10s%</u>\n",
"ADDR", "TASKID", "PROJID", "ZONEID", "REFCNT", "FLAGS");
}
if (mdb_vread(&tk, sizeof (task_t), addr) == -1) {
mdb_warn("can't read task_t structure at %p", addr);
return (DCMD_ERR);
}
if (mdb_vread(&pj, sizeof (kproject_t), (uintptr_t)tk.tk_proj) == -1) {
mdb_warn("can't read project_t structure at %p", addr);
return (DCMD_ERR);
}
mdb_printf("%0?p %6d %6d %6d %6u 0x%08x\n",
addr, tk.tk_tkid, pj.kpj_id, pj.kpj_zoneid, tk.tk_hold_count,
tk.tk_flags);
return (DCMD_OK);
}
int
project(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
{
kproject_t pj;
if (!(flags & DCMD_ADDRSPEC)) {
if (mdb_walk_dcmd("projects", "project", argc, argv) == -1) {
mdb_warn("can't walk projects");
return (DCMD_ERR);
}
return (DCMD_OK);
}
if (DCMD_HDRSPEC(flags)) {
mdb_printf("%<u>%?s %6s %6s %6s%</u>\n",
"ADDR", "PROJID", "ZONEID", "REFCNT");
}
if (mdb_vread(&pj, sizeof (kproject_t), addr) == -1) {
mdb_warn("can't read kproject_t structure at %p", addr);
return (DCMD_ERR);
}
mdb_printf("%0?p %6d %6d %6u\n", addr, pj.kpj_id, pj.kpj_zoneid,
pj.kpj_count);
return (DCMD_OK);
}
/* walk callouts themselves, either by list or id hash. */
int
callout_walk_init(mdb_walk_state_t *wsp)
{
if (wsp->walk_addr == NULL) {
mdb_warn("callout doesn't support global walk");
return (WALK_ERR);
}
wsp->walk_data = mdb_alloc(sizeof (callout_t), UM_SLEEP);
return (WALK_NEXT);
}
#define CALLOUT_WALK_BYLIST 0
#define CALLOUT_WALK_BYID 1
/* the walker arg switches between walking by list (0) and walking by id (1). */
int
callout_walk_step(mdb_walk_state_t *wsp)
{
int retval;
if (wsp->walk_addr == NULL) {
return (WALK_DONE);
}
if (mdb_vread(wsp->walk_data, sizeof (callout_t),
wsp->walk_addr) == -1) {
mdb_warn("failed to read callout at %p", wsp->walk_addr);
return (WALK_DONE);
}
retval = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
wsp->walk_cbdata);
if ((ulong_t)wsp->walk_arg == CALLOUT_WALK_BYID) {
wsp->walk_addr =
(uintptr_t)(((callout_t *)wsp->walk_data)->c_idnext);
} else {
wsp->walk_addr =
(uintptr_t)(((callout_t *)wsp->walk_data)->c_clnext);
}
return (retval);
}
void
callout_walk_fini(mdb_walk_state_t *wsp)
{
mdb_free(wsp->walk_data, sizeof (callout_t));
}
/*
* walker for callout lists. This is different from hashes and callouts.
* Thankfully, it's also simpler.
*/
int
callout_list_walk_init(mdb_walk_state_t *wsp)
{
if (wsp->walk_addr == NULL) {
mdb_warn("callout list doesn't support global walk");
return (WALK_ERR);
}
wsp->walk_data = mdb_alloc(sizeof (callout_list_t), UM_SLEEP);
return (WALK_NEXT);
}
int
callout_list_walk_step(mdb_walk_state_t *wsp)
{
int retval;
if (wsp->walk_addr == NULL) {
return (WALK_DONE);
}
if (mdb_vread(wsp->walk_data, sizeof (callout_list_t),
wsp->walk_addr) != sizeof (callout_list_t)) {
mdb_warn("failed to read callout_list at %p", wsp->walk_addr);
return (WALK_ERR);
}
retval = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
wsp->walk_cbdata);
wsp->walk_addr = (uintptr_t)
(((callout_list_t *)wsp->walk_data)->cl_next);
return (retval);
}
void
callout_list_walk_fini(mdb_walk_state_t *wsp)
{
mdb_free(wsp->walk_data, sizeof (callout_list_t));
}
/* routines/structs to walk callout table(s) */
typedef struct cot_data {
callout_table_t *ct0;
callout_table_t ct;
callout_hash_t cot_idhash[CALLOUT_BUCKETS];
callout_hash_t cot_clhash[CALLOUT_BUCKETS];
kstat_named_t ct_kstat_data[CALLOUT_NUM_STATS];
int cotndx;
int cotsize;
} cot_data_t;
int
callout_table_walk_init(mdb_walk_state_t *wsp)
{
int max_ncpus;
cot_data_t *cot_walk_data;
cot_walk_data = mdb_alloc(sizeof (cot_data_t), UM_SLEEP);
if (wsp->walk_addr == NULL) {
if (mdb_readvar(&cot_walk_data->ct0, "callout_table") == -1) {
mdb_warn("failed to read 'callout_table'");
return (WALK_ERR);
}
if (mdb_readvar(&max_ncpus, "max_ncpus") == -1) {
mdb_warn("failed to get callout_table array size");
return (WALK_ERR);
}
cot_walk_data->cotsize = CALLOUT_NTYPES * max_ncpus;
wsp->walk_addr = (uintptr_t)cot_walk_data->ct0;
} else {
/* not a global walk */
cot_walk_data->cotsize = 1;
}
cot_walk_data->cotndx = 0;
wsp->walk_data = cot_walk_data;
return (WALK_NEXT);
}
int
callout_table_walk_step(mdb_walk_state_t *wsp)
{
int retval;
cot_data_t *cotwd = (cot_data_t *)wsp->walk_data;
size_t size;
if (cotwd->cotndx >= cotwd->cotsize) {
return (WALK_DONE);
}
if (mdb_vread(&(cotwd->ct), sizeof (callout_table_t),
wsp->walk_addr) != sizeof (callout_table_t)) {
mdb_warn("failed to read callout_table at %p", wsp->walk_addr);
return (WALK_ERR);
}
size = sizeof (callout_hash_t) * CALLOUT_BUCKETS;
if (cotwd->ct.ct_idhash != NULL) {
if (mdb_vread(cotwd->cot_idhash, size,
(uintptr_t)(cotwd->ct.ct_idhash)) != size) {
mdb_warn("failed to read id_hash at %p",
cotwd->ct.ct_idhash);
return (WALK_ERR);
}
}
if (cotwd->ct.ct_clhash != NULL) {
if (mdb_vread(&(cotwd->cot_clhash), size,
(uintptr_t)cotwd->ct.ct_clhash) == -1) {
mdb_warn("failed to read cl_hash at %p",
cotwd->ct.ct_clhash);
return (WALK_ERR);
}
}
size = sizeof (kstat_named_t) * CALLOUT_NUM_STATS;
if (cotwd->ct.ct_kstat_data != NULL) {
if (mdb_vread(&(cotwd->ct_kstat_data), size,
(uintptr_t)cotwd->ct.ct_kstat_data) == -1) {
mdb_warn("failed to read kstats at %p",
cotwd->ct.ct_kstat_data);
return (WALK_ERR);
}
}
retval = wsp->walk_callback(wsp->walk_addr, (void *)cotwd,
wsp->walk_cbdata);
cotwd->cotndx++;
if (cotwd->cotndx >= cotwd->cotsize) {
return (WALK_DONE);
}
wsp->walk_addr = (uintptr_t)((char *)wsp->walk_addr +
sizeof (callout_table_t));
return (retval);
}
void
callout_table_walk_fini(mdb_walk_state_t *wsp)
{
mdb_free(wsp->walk_data, sizeof (cot_data_t));
}
static const char *co_typenames[] = { "R", "N" };
#define CO_PLAIN_ID(xid) ((xid) & CALLOUT_ID_MASK)
#define TABLE_TO_SEQID(x) ((x) >> CALLOUT_TYPE_BITS)
/* callout flags, in no particular order */
#define COF_REAL 0x00000001
#define COF_NORM 0x00000002
#define COF_LONG 0x00000004
#define COF_SHORT 0x00000008
#define COF_EMPTY 0x00000010
#define COF_TIME 0x00000020
#define COF_BEFORE 0x00000040
#define COF_AFTER 0x00000080
#define COF_SEQID 0x00000100
#define COF_FUNC 0x00000200
#define COF_ADDR 0x00000400
#define COF_EXEC 0x00000800
#define COF_HIRES 0x00001000
#define COF_ABS 0x00002000
#define COF_TABLE 0x00004000
#define COF_BYIDH 0x00008000
#define COF_FREE 0x00010000
#define COF_LIST 0x00020000
#define COF_EXPREL 0x00040000
#define COF_HDR 0x00080000
#define COF_VERBOSE 0x00100000
#define COF_LONGLIST 0x00200000
#define COF_THDR 0x00400000
#define COF_LHDR 0x00800000
#define COF_CHDR 0x01000000
#define COF_PARAM 0x02000000
#define COF_DECODE 0x04000000
#define COF_HEAP 0x08000000
#define COF_QUEUE 0x10000000
/* show real and normal, short and long, expired and unexpired. */
#define COF_DEFAULT (COF_REAL | COF_NORM | COF_LONG | COF_SHORT)
#define COF_LIST_FLAGS \
(CALLOUT_LIST_FLAG_HRESTIME | CALLOUT_LIST_FLAG_ABSOLUTE)
/* private callout data for callback functions */
typedef struct callout_data {
uint_t flags; /* COF_* */
cpu_t *cpu; /* cpu pointer if given */
int seqid; /* cpu seqid, or -1 */
hrtime_t time; /* expiration time value */
hrtime_t atime; /* expiration before value */
hrtime_t btime; /* expiration after value */
uintptr_t funcaddr; /* function address or NULL */
uintptr_t param; /* parameter to function or NULL */
hrtime_t now; /* current system time */
int nsec_per_tick; /* for conversions */
ulong_t ctbits; /* for decoding xid */
callout_table_t *co_table; /* top of callout table array */
int ndx; /* table index. */
int bucket; /* which list/id bucket are we in */
hrtime_t exp; /* expire time */
int list_flags; /* copy of cl_flags */
} callout_data_t;
/* this callback does the actual callback itself (finally). */
/*ARGSUSED*/
static int
callouts_cb(uintptr_t addr, const void *data, void *priv)
{
callout_data_t *coargs = (callout_data_t *)priv;
callout_t *co = (callout_t *)data;
int tableid, list_flags;
callout_id_t coid;
if ((coargs == NULL) || (co == NULL)) {
return (WALK_ERR);
}
if ((coargs->flags & COF_FREE) && !(co->c_xid & CALLOUT_ID_FREE)) {
/*
* The callout must have been reallocated. No point in
* walking any more.
*/
return (WALK_DONE);
}
if (!(coargs->flags & COF_FREE) && (co->c_xid & CALLOUT_ID_FREE)) {
/*
* The callout must have been freed. No point in
* walking any more.
*/
return (WALK_DONE);
}
if ((coargs->flags & COF_FUNC) &&
(coargs->funcaddr != (uintptr_t)co->c_func)) {
return (WALK_NEXT);
}
if ((coargs->flags & COF_PARAM) &&
(coargs->param != (uintptr_t)co->c_arg)) {
return (WALK_NEXT);
}
if (!(coargs->flags & COF_LONG) && (co->c_xid & CALLOUT_LONGTERM)) {
return (WALK_NEXT);
}
if (!(coargs->flags & COF_SHORT) && !(co->c_xid & CALLOUT_LONGTERM)) {
return (WALK_NEXT);
}
if ((coargs->flags & COF_EXEC) && !(co->c_xid & CALLOUT_EXECUTING)) {
return (WALK_NEXT);
}
/* it is possible we don't have the exp time or flags */
if (coargs->flags & COF_BYIDH) {
if (!(coargs->flags & COF_FREE)) {
/* we have to fetch the expire time ourselves. */
if (mdb_vread(&coargs->exp, sizeof (hrtime_t),
(uintptr_t)co->c_list + offsetof(callout_list_t,
cl_expiration)) == -1) {
mdb_warn("failed to read expiration "
"time from %p", co->c_list);
coargs->exp = 0;
}
/* and flags. */
if (mdb_vread(&coargs->list_flags, sizeof (int),
(uintptr_t)co->c_list + offsetof(callout_list_t,
cl_flags)) == -1) {
mdb_warn("failed to read list flags"
"from %p", co->c_list);
coargs->list_flags = 0;
}
} else {
/* free callouts can't use list pointer. */
coargs->exp = 0;
coargs->list_flags = 0;
}
if (coargs->exp != 0) {
if ((coargs->flags & COF_TIME) &&
(coargs->exp != coargs->time)) {
return (WALK_NEXT);
}
if ((coargs->flags & COF_BEFORE) &&
(coargs->exp > coargs->btime)) {
return (WALK_NEXT);
}
if ((coargs->flags & COF_AFTER) &&
(coargs->exp < coargs->atime)) {
return (WALK_NEXT);
}
}
/* tricky part, since both HIRES and ABS can be set */
list_flags = coargs->list_flags;
if ((coargs->flags & COF_HIRES) && (coargs->flags & COF_ABS)) {
/* both flags are set, only skip "regular" ones */
if (! (list_flags & COF_LIST_FLAGS)) {
return (WALK_NEXT);
}
} else {
/* individual flags, or no flags */
if ((coargs->flags & COF_HIRES) &&
!(list_flags & CALLOUT_LIST_FLAG_HRESTIME)) {
return (WALK_NEXT);
}
if ((coargs->flags & COF_ABS) &&
!(list_flags & CALLOUT_LIST_FLAG_ABSOLUTE)) {
return (WALK_NEXT);
}
}
/*
* We do the checks for COF_HEAP and COF_QUEUE here only if we
* are traversing BYIDH. If the traversal is by callout list,
* we do this check in callout_list_cb() to be more
* efficient.
*/
if ((coargs->flags & COF_HEAP) &&
!(list_flags & CALLOUT_LIST_FLAG_HEAPED)) {
return (WALK_NEXT);
}
if ((coargs->flags & COF_QUEUE) &&
!(list_flags & CALLOUT_LIST_FLAG_QUEUED)) {
return (WALK_NEXT);
}
}
#define callout_table_mask ((1 << coargs->ctbits) - 1)
tableid = CALLOUT_ID_TO_TABLE(co->c_xid);
#undef callout_table_mask
coid = CO_PLAIN_ID(co->c_xid);
if ((coargs->flags & COF_CHDR) && !(coargs->flags & COF_ADDR)) {
/*
* We need to print the headers. If walking by id, then
* the list header isn't printed, so we must include
* that info here.
*/
if (!(coargs->flags & COF_VERBOSE)) {
mdb_printf("%<u>%3s %-1s %-14s %</u>",
"SEQ", "T", "EXP");
} else if (coargs->flags & COF_BYIDH) {
mdb_printf("%<u>%-14s %</u>", "EXP");
}
mdb_printf("%<u>%-4s %-?s %-20s%</u>",
"XHAL", "XID", "FUNC(ARG)");
if (coargs->flags & COF_LONGLIST) {
mdb_printf("%<u> %-?s %-?s %-?s %-?s%</u>",
"PREVID", "NEXTID", "PREVL", "NEXTL");
mdb_printf("%<u> %-?s %-4s %-?s%</u>",
"DONE", "UTOS", "THREAD");
}
mdb_printf("\n");
coargs->flags &= ~COF_CHDR;
coargs->flags |= (COF_THDR | COF_LHDR);
}
if (!(coargs->flags & COF_ADDR)) {
if (!(coargs->flags & COF_VERBOSE)) {
mdb_printf("%-3d %1s %-14llx ",
TABLE_TO_SEQID(tableid),
co_typenames[tableid & CALLOUT_TYPE_MASK],
(coargs->flags & COF_EXPREL) ?
coargs->exp - coargs->now : coargs->exp);
} else if (coargs->flags & COF_BYIDH) {
mdb_printf("%-14x ",
(coargs->flags & COF_EXPREL) ?
coargs->exp - coargs->now : coargs->exp);
}
list_flags = coargs->list_flags;
mdb_printf("%1s%1s%1s%1s %-?llx %a(%p)",
(co->c_xid & CALLOUT_EXECUTING) ? "X" : " ",
(list_flags & CALLOUT_LIST_FLAG_HRESTIME) ? "H" : " ",
(list_flags & CALLOUT_LIST_FLAG_ABSOLUTE) ? "A" : " ",
(co->c_xid & CALLOUT_LONGTERM) ? "L" : " ",
(long long)coid, co->c_func, co->c_arg);
if (coargs->flags & COF_LONGLIST) {
mdb_printf(" %-?p %-?p %-?p %-?p",
co->c_idprev, co->c_idnext, co->c_clprev,
co->c_clnext);
mdb_printf(" %-?p %-4d %-0?p",
co->c_done, co->c_waiting, co->c_executor);
}
} else {
/* address only */
mdb_printf("%-0p", addr);
}
mdb_printf("\n");
return (WALK_NEXT);
}
/* this callback is for callout list handling. idhash is done by callout_t_cb */
/*ARGSUSED*/
static int
callout_list_cb(uintptr_t addr, const void *data, void *priv)
{
callout_data_t *coargs = (callout_data_t *)priv;
callout_list_t *cl = (callout_list_t *)data;
callout_t *coptr;
int list_flags;
if ((coargs == NULL) || (cl == NULL)) {
return (WALK_ERR);
}
coargs->exp = cl->cl_expiration;
coargs->list_flags = cl->cl_flags;
if ((coargs->flags & COF_FREE) &&
!(cl->cl_flags & CALLOUT_LIST_FLAG_FREE)) {
/*
* The callout list must have been reallocated. No point in
* walking any more.
*/
return (WALK_DONE);
}
if (!(coargs->flags & COF_FREE) &&
(cl->cl_flags & CALLOUT_LIST_FLAG_FREE)) {
/*
* The callout list must have been freed. No point in
* walking any more.
*/
return (WALK_DONE);
}
if ((coargs->flags & COF_TIME) &&
(cl->cl_expiration != coargs->time)) {
return (WALK_NEXT);
}
if ((coargs->flags & COF_BEFORE) &&
(cl->cl_expiration > coargs->btime)) {
return (WALK_NEXT);
}
if ((coargs->flags & COF_AFTER) &&
(cl->cl_expiration < coargs->atime)) {
return (WALK_NEXT);
}
if (!(coargs->flags & COF_EMPTY) &&
(cl->cl_callouts.ch_head == NULL)) {
return (WALK_NEXT);
}
/* FOUR cases, each different, !A!B, !AB, A!B, AB */
if ((coargs->flags & COF_HIRES) && (coargs->flags & COF_ABS)) {
/* both flags are set, only skip "regular" ones */
if (! (cl->cl_flags & COF_LIST_FLAGS)) {
return (WALK_NEXT);
}
} else {
if ((coargs->flags & COF_HIRES) &&
!(cl->cl_flags & CALLOUT_LIST_FLAG_HRESTIME)) {
return (WALK_NEXT);
}
if ((coargs->flags & COF_ABS) &&
!(cl->cl_flags & CALLOUT_LIST_FLAG_ABSOLUTE)) {
return (WALK_NEXT);
}
}
if ((coargs->flags & COF_HEAP) &&
!(coargs->list_flags & CALLOUT_LIST_FLAG_HEAPED)) {
return (WALK_NEXT);
}
if ((coargs->flags & COF_QUEUE) &&
!(coargs->list_flags & CALLOUT_LIST_FLAG_QUEUED)) {
return (WALK_NEXT);
}
if ((coargs->flags & COF_LHDR) && !(coargs->flags & COF_ADDR) &&
(coargs->flags & (COF_LIST | COF_VERBOSE))) {
if (!(coargs->flags & COF_VERBOSE)) {
/* don't be redundant again */
mdb_printf("%<u>SEQ T %</u>");
}
mdb_printf("%<u>EXP HA BUCKET "
"CALLOUTS %</u>");
if (coargs->flags & COF_LONGLIST) {
mdb_printf("%<u> %-?s %-?s%</u>",
"PREV", "NEXT");
}
mdb_printf("\n");
coargs->flags &= ~COF_LHDR;
coargs->flags |= (COF_THDR | COF_CHDR);
}
if (coargs->flags & (COF_LIST | COF_VERBOSE)) {
if (!(coargs->flags & COF_ADDR)) {
if (!(coargs->flags & COF_VERBOSE)) {
mdb_printf("%3d %1s ",
TABLE_TO_SEQID(coargs->ndx),
co_typenames[coargs->ndx &
CALLOUT_TYPE_MASK]);
}
list_flags = coargs->list_flags;
mdb_printf("%-14llx %1s%1s %-6d %-0?p ",
(coargs->flags & COF_EXPREL) ?
coargs->exp - coargs->now : coargs->exp,
(list_flags & CALLOUT_LIST_FLAG_HRESTIME) ?
"H" : " ",
(list_flags & CALLOUT_LIST_FLAG_ABSOLUTE) ?
"A" : " ",
coargs->bucket, cl->cl_callouts.ch_head);