1/*
2cc tools/vtstat.c -o /tmp/vtstat -framework IOKit -framework CoreFoundation -g -Wall
3*/
4
5#include <stdlib.h>
6#include <stdio.h>
7#include <assert.h>
8#include <IOKit/IOKitLib.h>
9
10
11typedef uint32_t ppnum_t;
12#define arrayCount(x)	(sizeof(x) / sizeof(x[0]))
13
14struct vtd_space_stats
15{
16    ppnum_t vsize;
17    ppnum_t tables;
18    ppnum_t bused;
19    ppnum_t rused;
20    ppnum_t largest_paging;
21    ppnum_t largest_32b;
22    ppnum_t inserts;
23    ppnum_t max_inval[2];
24    ppnum_t breakups;
25    ppnum_t merges;
26    ppnum_t allocs[64];
27	ppnum_t bcounts[20];
28};
29typedef struct vtd_space_stats vtd_space_stats_t;
30
31int main(int argc, char * argv[])
32{
33    io_service_t		vtd;
34    CFDataRef			statsData;
35    vtd_space_stats_t *	stats;
36    uint32_t			idx;
37
38    vtd = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("AppleVTD"));
39    assert(vtd);
40	statsData = IORegistryEntryCreateCFProperty(vtd, CFSTR("stats"),
41								kCFAllocatorDefault, kNilOptions);
42    assert(statsData);
43
44	stats = (vtd_space_stats_t *) CFDataGetBytePtr(statsData);
45
46	printf("vsize          0x%x\n", stats->vsize);
47	printf("tables         0x%x\n", stats->tables);
48	printf("bused          0x%x\n", stats->bused);
49	printf("rused          0x%x\n", stats->rused);
50	printf("largest_paging 0x%x\n", stats->largest_paging);
51	printf("largest_32b    0x%x\n", stats->largest_32b);
52	printf("max_binval     0x%x\n", stats->max_inval[0]);
53	printf("max_rinval     0x%x\n", stats->max_inval[1]);
54	printf("largest_32b    0x%x\n", stats->largest_32b);
55	printf("breakups       0x%x\n", stats->breakups);
56	printf("merges         0x%x\n", stats->merges);
57	printf("inserts        0x%x\n", stats->inserts);
58
59	for (idx = 0; idx < arrayCount(stats->allocs); idx++)	printf("allocs[%2d]    0x%x\n", idx, stats->allocs[idx]);
60	for (idx = 0; idx < arrayCount(stats->bcounts); idx++)	printf("bcounts[%2d]    0x%x\n", idx, stats->bcounts[idx]);
61
62	exit(0);
63}