summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBoris Faure <billiob@gmail.com>2015-08-06 21:39:20 +0200
committerBoris Faure <billiob@gmail.com>2015-08-06 21:39:20 +0200
commit41579e92e84402b14da4f1be9fa7923d66590969 (patch)
tree6e0af6957ff1fb656bf1346ee1df5caa83c9832c /src
parent5c37589e399051dbd4d241721c62b03f23fb93bc (diff)
remove logically dead code. CID1315103 and CID1315104
Diffstat (limited to 'src')
-rw-r--r--src/bin/termptysave.c351
1 files changed, 1 insertions, 350 deletions
diff --git a/src/bin/termptysave.c b/src/bin/termptysave.c
index 0c5ae01..a6d7971 100644
--- a/src/bin/termptysave.c
+++ b/src/bin/termptysave.c
@@ -27,105 +27,6 @@ struct _Alloc
27 unsigned char __pad; 27 unsigned char __pad;
28}; 28};
29 29
30#if 0
31static uint64_t _allocated = 0;
32#endif
33static unsigned char cur_gen = 0;
34static Alloc *alloc[MEM_BLOCKS] = { 0 };
35
36#if 0
37static int
38roundup_block_size(int sz)
39{
40 return MEM_ALLOC_ALIGN * ((sz + MEM_ALLOC_ALIGN - 1) / MEM_ALLOC_ALIGN);
41}
42
43static Alloc *
44_alloc_find(void *mem)
45{
46 unsigned char *memptr = mem;
47 int i;
48
49 for (i = 0; i < MEM_BLOCKS; i++)
50 {
51 unsigned char *al;
52
53 al = (unsigned char *)alloc[i];
54 if (!al) continue;
55 if (memptr < al) continue;
56 if ((al + TS_MMAP_SIZE) <= memptr) continue;
57 return alloc[i];
58 }
59 return NULL;
60}
61
62static void *
63_alloc_new(int size, unsigned char gen)
64{
65 Alloc *al;
66 unsigned char *ptr;
67 unsigned int newsize, sz;
68 int i, firstnull = -1;
69
70 // allocations sized up to nearest size alloc alignment
71 newsize = roundup_block_size(size);
72 for (i = 0; i < MEM_BLOCKS; i++)
73 {
74 if (!alloc[i])
75 {
76 if (firstnull < 0) firstnull = i;
77 continue;
78 }
79 // if generation count matches
80 if (alloc[i]->gen == gen)
81 {
82 // if there is space in the block
83 if ((alloc[i]->size - alloc[i]->last) >= newsize)
84 {
85 ptr = (unsigned char *)alloc[i];
86 ptr += alloc[i]->last;
87 alloc[i]->last += newsize;
88 alloc[i]->count++;
89 alloc[i]->allocated += newsize;
90 _allocated += newsize;
91 return ptr;
92 }
93 }
94 }
95 // out of slots for new blocks - no null blocks
96 if (firstnull < 0) {
97 ERR("Cannot find new null blocks");
98 return NULL;
99 }
100
101 // so allocate a new block
102 sz = TS_MMAP_SIZE;
103 // get mmaped anonymous memory so when freed it goes away from the system
104 ptr = (unsigned char*) mmap(NULL, sz, PROT_READ | PROT_WRITE,
105 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
106 if (ptr == MAP_FAILED)
107 {
108 ERR("Cannot allocate more memory with mmap MAP_ANONYMOUS");
109 return NULL;
110 }
111
112 // note - we SHOULD memset to 0, but we are assuming mmap anon give 0 pages
113 //memset(ptr, 0, newsize);
114
115 al = (Alloc *)ptr;
116 al->size = sz;
117 al->last = sizeof(Alloc) + newsize;
118 al->count = 1;
119 al->allocated = newsize;
120 al->slot = firstnull;
121 al->gen = gen;
122 _allocated += newsize;
123 alloc[al->slot] = al;
124 ptr = (unsigned char *)al;
125 ptr += sizeof(Alloc);
126 return ptr;
127}
128#endif
129 30
130static void * 31static void *
131_ts_new(int size) 32_ts_new(int size)
@@ -143,249 +44,13 @@ static void
143_ts_free(void *ptr) 44_ts_free(void *ptr)
144{ 45{
145 free(ptr); 46 free(ptr);
146#if 0
147 Alloc *al;
148 unsigned int sz;
149 Termsavecomp *ts = ptr;
150
151 if (!ptr) return;
152
153 if (ts->comp)
154 sz = sizeof(Termsavecomp) + ts->w;
155 else
156 sz = sizeof(Termsave) + ((ts->w - 1) * sizeof(Termcell));
157 sz = roundup_block_size(sz);
158 _allocated -= sz;
159
160 al = _alloc_find(ptr);
161 if (!al)
162 {
163 ERR("Cannot find %p in alloc blocks", ptr);
164 return;
165 }
166 al->count--;
167 al->allocated -= sz;
168 if (al->count > 0) return;
169 alloc[al->slot] = NULL;
170#if defined (__sun) || defined (__sun__)
171 munmap((caddr_t)al, al->size);
172#else
173 munmap(al, al->size);
174#endif
175#endif
176}
177
178static void
179_mem_defrag(void)
180{
181 int i, j = 0;
182 Alloc *alloc2[MEM_BLOCKS];
183
184 for (i = 0; i < MEM_BLOCKS; i++)
185 {
186 if (alloc[i])
187 {
188// printf("block %i @ %i [%i/%i] # %i\n",
189// j, alloc[i]->gen, alloc[i]->last, alloc[i]->size, alloc[i]->count);
190 alloc2[j] = alloc[i];
191 alloc2[j]->slot = j;
192 j++;
193 }
194 }
195 // XXX: quicksort blocks with most space at start
196 for (i = 0; i < j; i++) alloc[i] = alloc2[i];
197 for (; i < MEM_BLOCKS; i++) alloc[i] = NULL;
198}
199
200static void
201_mem_gen_next(void)
202{
203 cur_gen++;
204}
205
206static unsigned char
207_mem_gen_get(void)
208{
209 return cur_gen;
210} 47}
211 48
212static int ts_comp = 0; 49static int ts_comp = 0;
213static int ts_uncomp = 0; 50static int ts_uncomp = 0;
214static int ts_freeops = 0; 51static int ts_freeops = 0;
215static int ts_compfreeze = 0; 52static int ts_compfreeze = 0;
216static int freeze = 0;
217static Eina_List *ptys = NULL; 53static Eina_List *ptys = NULL;
218static Ecore_Idler *idler = NULL;
219static Ecore_Timer *timer = NULL;
220
221#if 0
222static Termsave *
223_save_comp(Termsave *ts)
224{
225 Termsave *ts2;
226 Termsavecomp *tsc;
227
228 ERR("save comp");
229
230 // already compacted
231 if (ts->comp) return ts;
232 // make new allocation for new generation
233 ts_compfreeze++;
234 if (!ts->z)
235 {
236 int bytes;
237 char *buf;
238
239 buf = alloca(LZ4_compressBound(ts->w * sizeof(Termcell)));
240 bytes = LZ4_compress((char *)(&(ts->cells[0])), buf,
241 ts->w * sizeof(Termcell));
242 tsc = _ts_new(sizeof(Termsavecomp) + bytes);
243 if (!tsc)
244 {
245 ERR("Big problem. Can't allocate backscroll compress buffer");
246 ts2 = ts;
247 goto done;
248 }
249 tsc->comp = 1;
250 tsc->z = 1;
251 tsc->gen = _mem_gen_get();
252 tsc->w = bytes;
253 tsc->wout = ts->w;
254 memcpy(((char *)tsc) + sizeof(Termsavecomp), buf, bytes);
255 ts2 = (Termsave *)tsc;
256 }
257 else
258 {
259 tsc = (Termsavecomp *)ts;
260 ts2 = _ts_new(sizeof(Termsavecomp) + tsc->w);
261 if (!ts2)
262 {
263 ERR("Big problem. Can't allocate backscroll compress/copy buffer");
264 ts2 = ts;
265 goto done;
266 }
267 memcpy(ts2, ts, sizeof(Termsavecomp) + tsc->w);
268 ts2->gen = _mem_gen_get();
269 ts2->comp = 1;
270 }
271 termpty_save_free(ts);
272done:
273 ts_compfreeze--;
274 return ts2;
275}
276#endif
277
278static void
279_walk_pty(Termpty *ty)
280{
281 size_t i;
282// int c0 = 0, c1 = 0;
283
284 if (!ty->back) return;
285 for (i = 0; i < ty->backsize; i++)
286 {
287 Termsavecomp *tsc = (Termsavecomp *)&ty->back[i];
288
289 if (tsc)
290 {
291#if 0
292 ty->back[i] = _save_comp(tsc);
293 tsc = (Termsavecomp *)ty->back[i];
294 if (tsc->comp) ts_comp++;
295 else ts_uncomp++;
296// c0 += tsc->w;
297// c1 += tsc->wout * sizeof(Termcell);
298#endif
299 }
300 }
301// printf("compress ratio: %1.3f\n", (double)c0 / (double)c1);
302}
303
304static Eina_Bool
305_idler(void *data EINA_UNUSED)
306{
307 /* TODO: RESIZE : re-enable compression */
308 return EINA_FALSE;
309
310 Eina_List *l;
311 Termpty *ty;
312// double t0, t;
313
314
315 _mem_gen_next();
316
317// t0 = ecore_time_get();
318 // start afresh and count comp/uncomp;
319 ts_comp = 0;
320 ts_uncomp = 0;
321 EINA_LIST_FOREACH(ptys, l, ty)
322 {
323 _walk_pty(ty);
324 }
325// t = ecore_time_get();
326// printf("comp/uncomp %i/%i time spent %1.5f\n", ts_comp, ts_uncomp, t - t0);
327 _mem_defrag();
328 ts_freeops = 0;
329
330 _mem_gen_next();
331
332 idler = NULL;
333 return EINA_FALSE;
334}
335
336static Eina_Bool
337_timer(void *data EINA_UNUSED)
338{
339 if (!idler) idler = ecore_idler_add(_idler, NULL);
340 timer = NULL;
341 return EINA_FALSE;
342}
343
344static inline void
345_check_compressor(Eina_Bool frozen)
346{
347 /* TODO: RESIZE re-enable compressor */
348 return;
349 if (freeze) return;
350 if (idler) return;
351 if ((ts_uncomp > 256) || (ts_freeops > 256))
352 {
353 if (timer && !frozen) ecore_timer_reset(timer);
354 else if (!timer) timer = ecore_timer_add(0.2, _timer, NULL);
355 }
356}
357
358#if 0
359void
360termpty_save_freeze(void)
361{
362 // XXX: suspend compressor - this probably should be in a thread but right
363 // now it'll be fine here
364 if (!freeze++)
365 {
366 if (timer) ecore_timer_freeze(timer);
367 }
368 if (idler)
369 {
370 ecore_idler_del(idler);
371 idler = NULL;
372 }
373}
374
375void
376termpty_save_thaw(void)
377{
378 // XXX: resume compressor
379 freeze--;
380 if (freeze <= 0)
381 {
382 if (timer) ecore_timer_thaw(timer);
383 _check_compressor(EINA_TRUE);
384 }
385}
386#endif
387
388
389 54
390void 55void
391termpty_save_register(Termpty *ty) 56termpty_save_register(Termpty *ty)
@@ -407,7 +72,7 @@ Termsave *
407termpty_save_extract(Termsave *ts) 72termpty_save_extract(Termsave *ts)
408{ 73{
409 if (!ts) return NULL; 74 if (!ts) return NULL;
410 if (ts->z) 75 if (ts->z) //TODO: unused
411 { 76 {
412 Termsavecomp *tsc = (Termsavecomp *)ts; 77 Termsavecomp *tsc = (Termsavecomp *)ts;
413 Termsave *ts2; 78 Termsave *ts2;
@@ -416,7 +81,6 @@ termpty_save_extract(Termsave *ts)
416 81
417 ts2 = _ts_new(sizeof(Termsave) + ((tsc->wout - 1) * sizeof(Termcell))); 82 ts2 = _ts_new(sizeof(Termsave) + ((tsc->wout - 1) * sizeof(Termcell)));
418 if (!ts2) return NULL; 83 if (!ts2) return NULL;
419 ts2->gen = _mem_gen_get();
420 ts2->w = tsc->wout; 84 ts2->w = tsc->wout;
421 buf = ((char *)tsc) + sizeof(Termsavecomp); 85 buf = ((char *)tsc) + sizeof(Termsavecomp);
422 bytes = LZ4_uncompress(buf, (char *)(&(ts2->cells[0])), 86 bytes = LZ4_uncompress(buf, (char *)(&(ts2->cells[0])),
@@ -426,17 +90,8 @@ termpty_save_extract(Termsave *ts)
426 memset(&(ts2->cells[0]), 0, tsc->wout * sizeof(Termcell)); 90 memset(&(ts2->cells[0]), 0, tsc->wout * sizeof(Termcell));
427// ERR("Decompress problem in row at byte %i", -bytes); 91// ERR("Decompress problem in row at byte %i", -bytes);
428 } 92 }
429 if (ts->comp) ts_comp--;
430 else ts_uncomp--;
431 ts_uncomp++;
432 ts_freeops++;
433 ts_compfreeze++;
434 _ts_free(ts);
435 ts_compfreeze--;
436 _check_compressor(EINA_FALSE);
437 return ts2; 93 return ts2;
438 } 94 }
439 _check_compressor(EINA_FALSE);
440 return ts; 95 return ts;
441} 96}
442 97
@@ -448,10 +103,7 @@ termpty_save_new(Termsave *ts, int w)
448 Termcell *cells = calloc(1, w * sizeof(Termcell)); 103 Termcell *cells = calloc(1, w * sizeof(Termcell));
449 if (!cells ) return NULL; 104 if (!cells ) return NULL;
450 ts->cells = cells; 105 ts->cells = cells;
451 ts->gen = _mem_gen_get();
452 ts->w = w; 106 ts->w = w;
453 if (!ts_compfreeze) ts_uncomp++;
454 _check_compressor(EINA_FALSE);
455 return ts; 107 return ts;
456} 108}
457 109
@@ -483,7 +135,6 @@ termpty_save_free(Termsave *ts)
483 _ts_free(ts->cells); 135 _ts_free(ts->cells);
484 ts->cells = NULL; 136 ts->cells = NULL;
485 ts->w = 0; 137 ts->w = 0;
486 _check_compressor(EINA_FALSE);
487} 138}
488 139
489void 140void