ia64/xen-unstable

view tools/misc/xen-tmem-list-parse.c @ 19696:4294a04b24bc

tmem: shared ephemeral (SE) pool (clustering) fixes

Tmem can share clean page cache pages for Linux domains
in a virtual cluster (currently only the ocfs2 filesystem
has a patch on the Linux side). So when one domain
"puts" (evicts) a page, any domain in the cluster can
"get" it, thus saving disk reads. This functionality
is already present; these are only bug fixes.

- fix bugs when an SE pool is destroyed
- fixes in parsing tool for xm tmem-list output for SE pools
- incorrect locking in one case for destroying an SE pool
- clearer verbosity for transfer when an SE pool is destroyed
- minor cleanup: merge routines that are mostly duplicate

Signed-off-by: Dan Magenheimer <dan.magenheimer@oracle.com>
author Keir Fraser <keir.fraser@citrix.com>
date Mon Jun 01 18:37:27 2009 +0100 (2009-06-01)
parents f210a633571c
children
line source
1 /*
2 * Parse output from tmem-list and reformat to human-readable
3 *
4 * NOTE: NEVER delete a parse call as this file documents backwards
5 * compatibility for older versions of tmem-list and we don't want to
6 * accidentally reuse an old tag
7 *
8 * Copyright (c) 2009, Dan Magenheimer, Oracle Corp.
9 */
11 #include <stdio.h>
12 #include <unistd.h>
13 #include <string.h>
15 #define BUFSIZE 4096
16 #define PAGE_SIZE 4096
18 unsigned long long parse(char *s,char *match)
19 {
20 char *s1 = strstr(s,match);
21 unsigned long long ret;
23 if ( s1 == NULL )
24 return 0LL;
25 s1 += 2;
26 if ( *s1++ != ':' )
27 return 0LL;
28 sscanf(s1,"%llu",&ret);
29 return ret;
30 }
32 unsigned long long parse_hex(char *s,char *match)
33 {
34 char *s1 = strstr(s,match);
35 unsigned long long ret;
37 if ( s1 == NULL )
38 return 0LL;
39 s1 += 2;
40 if ( *s1++ != ':' )
41 return 0LL;
42 sscanf(s1,"%llx",&ret);
43 return ret;
44 }
46 unsigned long long parse2(char *s,char *match1, char *match2)
47 {
48 char match[3];
49 match[0] = *match1;
50 match[1] = *match2;
51 match[2] = '\0';
52 return parse(s,match);
53 }
55 void parse_string(char *s,char *match, char *buf, int len)
56 {
57 char *s1 = strstr(s,match);
58 int i;
60 if ( s1 == NULL )
61 return;
62 s1 += 2;
63 if ( *s1++ != ':' )
64 return;
65 for ( i = 0; i < len; i++ )
66 *buf++ = *s1++;
67 }
69 void parse_sharers(char *s, char *match, char *buf, int len)
70 {
71 char *s1 = strstr(s,match);
72 char *b = buf;
74 if ( s1 == NULL )
75 return;
76 while ( s1 )
77 {
78 s1 += 2;
79 if (*s1++ != ':')
80 return;
81 while (*s1 >= '0' && *s1 <= '9')
82 *b++ = *s1++;
83 *b++ = ',';
84 s1 = strstr(s1,match);
85 }
86 if ( b != buf )
87 *--b = '\0';
88 }
90 void parse_global(char *s)
91 {
92 unsigned long long total_ops = parse(s,"Tt");
93 unsigned long long errored_ops = parse(s,"Te");
94 unsigned long long failed_copies = parse(s,"Cf");
95 unsigned long long alloc_failed = parse(s,"Af");
96 unsigned long long alloc_page_failed = parse(s,"Pf");
97 unsigned long long avail_pages = parse(s,"Ta");
98 unsigned long long low_on_memory = parse(s,"Lm");
99 unsigned long long evicted_pgs = parse(s,"Et");
100 unsigned long long evict_attempts = parse(s,"Ea");
101 unsigned long long relinq_pgs = parse(s,"Rt");
102 unsigned long long relinq_attempts = parse(s,"Ra");
103 unsigned long long max_evicts_per_relinq = parse(s,"Rx");
104 unsigned long long total_flush_pool = parse(s,"Fp");
105 unsigned long long global_eph_count = parse(s,"Ec");
106 unsigned long long global_eph_max = parse(s,"Em");
107 unsigned long long obj_count = parse(s,"Oc");
108 unsigned long long obj_max = parse(s,"Om");
109 unsigned long long rtree_node_count = parse(s,"Nc");
110 unsigned long long rtree_node_max = parse(s,"Nm");
111 unsigned long long pgp_count = parse(s,"Pc");
112 unsigned long long pgp_max = parse(s,"Pm");
114 printf("total tmem ops=%llu (errors=%llu) -- tmem pages avail=%llu\n",
115 total_ops, errored_ops, avail_pages);
116 printf("datastructs: objs=%llu (max=%llu) pgps=%llu (max=%llu) "
117 "nodes=%llu (max=%llu)\n",
118 obj_count, obj_max, pgp_count, pgp_max,
119 rtree_node_count, rtree_node_max);
120 printf("misc: failed_copies=%llu alloc_failed=%llu alloc_page_failed=%llu "
121 "low_mem=%llu evicted=%llu/%llu relinq=%llu/%llu, "
122 "max_evicts_per_relinq=%llu, flush_pools=%llu, "
123 "eph_count=%llu, eph_max=%llu\n",
124 failed_copies, alloc_failed, alloc_page_failed, low_on_memory,
125 evicted_pgs, evict_attempts, relinq_pgs, relinq_attempts,
126 max_evicts_per_relinq, total_flush_pool,
127 global_eph_count, global_eph_max);
128 }
130 #define PARSE_CYC_COUNTER(s,x,prefix) unsigned long long \
131 x##_count = parse2(s,prefix,"n"), \
132 x##_sum_cycles = parse2(s,prefix,"t"), \
133 x##_max_cycles = parse2(s,prefix,"x"), \
134 x##_min_cycles = parse2(s,prefix,"m")
135 #define PRINTF_CYC_COUNTER(x,text) \
136 if (x##_count) printf(text" avg=%llu, max=%llu, " \
137 "min=%llu, samples=%llu\n", \
138 x##_sum_cycles ? (x##_sum_cycles/x##_count) : 0, \
139 x##_max_cycles, x##_min_cycles, x##_count)
141 void parse_time_stats(char *s)
142 {
143 PARSE_CYC_COUNTER(s,succ_get,"G");
144 PARSE_CYC_COUNTER(s,succ_put,"P");
145 PARSE_CYC_COUNTER(s,non_succ_get,"g");
146 PARSE_CYC_COUNTER(s,non_succ_put,"p");
147 PARSE_CYC_COUNTER(s,flush,"F");
148 PARSE_CYC_COUNTER(s,flush_obj,"O");
149 PARSE_CYC_COUNTER(s,pg_copy,"C");
150 PARSE_CYC_COUNTER(s,compress,"c");
151 PARSE_CYC_COUNTER(s,decompress,"d");
153 PRINTF_CYC_COUNTER(succ_get,"succ get cycles:");
154 PRINTF_CYC_COUNTER(succ_put,"succ put cycles:");
155 PRINTF_CYC_COUNTER(non_succ_get,"failed get cycles:");
156 PRINTF_CYC_COUNTER(non_succ_put,"failed put cycles:");
157 PRINTF_CYC_COUNTER(flush,"flush cycles:");
158 PRINTF_CYC_COUNTER(flush_obj,"flush_obj cycles:");
159 PRINTF_CYC_COUNTER(pg_copy,"page copy cycles:");
160 PRINTF_CYC_COUNTER(compress,"compression cycles:");
161 PRINTF_CYC_COUNTER(decompress,"decompression cycles:");
162 }
164 void parse_client(char *s)
165 {
166 unsigned long cli_id = parse(s,"CI");
167 unsigned long weight = parse(s,"ww");
168 unsigned long cap = parse(s,"ca");
169 unsigned long compress = parse(s,"co");
170 unsigned long frozen = parse(s,"fr");
171 unsigned long long eph_count = parse(s,"Ec");
172 unsigned long long max_eph_count = parse(s,"Em");
173 unsigned long long compressed_pages = parse(s,"cp");
174 unsigned long long compressed_sum_size = parse(s,"cb");
175 unsigned long long compress_poor = parse(s,"cn");
176 unsigned long long compress_nomem = parse(s,"cm");
178 printf("domid%lu: weight=%lu,cap=%lu,compress=%d,frozen=%d,"
179 "eph_count=%llu,max_eph=%llu,"
180 "compression ratio=%lu%% (samples=%llu,poor=%llu,nomem=%llu)\n",
181 cli_id, weight, cap, compress?1:0, frozen?1:0,
182 eph_count, max_eph_count,
183 compressed_pages ? (long)((compressed_sum_size*100LL) /
184 (compressed_pages*PAGE_SIZE)) : 0,
185 compressed_pages, compress_poor, compress_nomem);
187 }
189 void parse_pool(char *s)
190 {
191 char pool_type[3];
192 unsigned long cli_id = parse(s,"CI");
193 unsigned long pool_id = parse(s,"PI");
194 unsigned long long pgp_count = parse(s,"Pc");
195 unsigned long long max_pgp_count = parse(s,"Pm");
196 unsigned long long obj_count = parse(s,"Oc");
197 unsigned long long max_obj_count = parse(s,"Om");
198 unsigned long long objnode_count = parse(s,"Nc");
199 unsigned long long max_objnode_count = parse(s,"Nm");
200 unsigned long long good_puts = parse(s,"ps");
201 unsigned long long puts = parse(s,"pt");
202 unsigned long long no_mem_puts = parse(s,"px");
203 unsigned long long dup_puts_flushed = parse(s,"pd");
204 unsigned long long dup_puts_replaced = parse(s,"pr");
205 unsigned long long found_gets = parse(s,"gs");
206 unsigned long long gets = parse(s,"gt");
207 unsigned long long flushs_found = parse(s,"fs");
208 unsigned long long flushs = parse(s,"ft");
209 unsigned long long flush_objs_found = parse(s,"os");
210 unsigned long long flush_objs = parse(s,"ot");
212 parse_string(s,"PT",pool_type,2);
213 if (pool_type[1] == 'S')
214 return; /* no need to repeat print data for shared pools */
215 printf("domid%lu,id%lu[%s]:pgp=%llu(max=%llu) obj=%llu(%llu) "
216 "objnode=%llu(%llu) puts=%llu/%llu/%llu(dup=%llu/%llu) "
217 "gets=%llu/%llu(%llu%%) "
218 "flush=%llu/%llu flobj=%llu/%llu\n",
219 cli_id, pool_id, pool_type,
220 pgp_count, max_pgp_count, obj_count, max_obj_count,
221 objnode_count, max_objnode_count,
222 good_puts, puts, no_mem_puts,
223 dup_puts_flushed, dup_puts_replaced,
224 found_gets, gets,
225 gets ? (found_gets*100LL)/gets : 0,
226 flushs_found, flushs, flush_objs_found, flush_objs);
228 }
230 void parse_shared_pool(char *s)
231 {
232 char pool_type[3];
233 char buf[BUFSIZE];
234 unsigned long pool_id = parse(s,"PI");
235 unsigned long long uid0 = parse_hex(s,"U0");
236 unsigned long long uid1 = parse_hex(s,"U1");
237 unsigned long long pgp_count = parse(s,"Pc");
238 unsigned long long max_pgp_count = parse(s,"Pm");
239 unsigned long long obj_count = parse(s,"Oc");
240 unsigned long long max_obj_count = parse(s,"Om");
241 unsigned long long objnode_count = parse(s,"Nc");
242 unsigned long long max_objnode_count = parse(s,"Nm");
243 unsigned long long good_puts = parse(s,"ps");
244 unsigned long long puts = parse(s,"pt");
245 unsigned long long no_mem_puts = parse(s,"px");
246 unsigned long long dup_puts_flushed = parse(s,"pd");
247 unsigned long long dup_puts_replaced = parse(s,"pr");
248 unsigned long long found_gets = parse(s,"gs");
249 unsigned long long gets = parse(s,"gt");
250 unsigned long long flushs_found = parse(s,"fs");
251 unsigned long long flushs = parse(s,"ft");
252 unsigned long long flush_objs_found = parse(s,"os");
253 unsigned long long flush_objs = parse(s,"ot");
255 parse_string(s,"PT",pool_type,2);
256 parse_sharers(s,"SC",buf,BUFSIZE);
257 printf("poolid=%lu[%s] uuid=%llx.%llx, shared-by:%s: "
258 "pgp=%llu(max=%llu) obj=%llu(%llu) "
259 "objnode=%llu(%llu) puts=%llu/%llu/%llu(dup=%llu/%llu) "
260 "gets=%llu/%llu(%llu%%) "
261 "flush=%llu/%llu flobj=%llu/%llu\n",
262 pool_id, pool_type, uid0, uid1, buf,
263 pgp_count, max_pgp_count, obj_count, max_obj_count,
264 objnode_count, max_objnode_count,
265 good_puts, puts, no_mem_puts,
266 dup_puts_flushed, dup_puts_replaced,
267 found_gets, gets,
268 gets ? (found_gets*100LL)/gets : 0,
269 flushs_found, flushs, flush_objs_found, flush_objs);
270 }
272 int main(int ac, char **av)
273 {
274 char *p, c;
275 char buf[BUFSIZE];
277 while ( (p = fgets(buf,BUFSIZE,stdin)) != NULL )
278 {
279 c = *p++;
280 if ( *p++ != '=' )
281 continue;
282 switch ( c )
283 {
284 case 'G':
285 parse_global(p);
286 break;
287 case 'T':
288 parse_time_stats(p);
289 break;
290 case 'C':
291 parse_client(p);
292 break;
293 case 'P':
294 parse_pool(p);
295 break;
296 case 'S':
297 parse_shared_pool(p);
298 break;
299 default:
300 continue;
301 }
302 }
303 return 0;
304 }