Browse Source

add some usefull tools source code packages

Huan.Feng 3 years ago
parent
commit
3dbaad351a

+ 0 - 0
dl/bash/.lock


BIN
dl/bash/bash-5.0.tar.gz


+ 0 - 0
dl/bonnie/.lock


BIN
dl/bonnie/bonnie++-1.03e.tgz


+ 0 - 0
dl/cache-calibrator/.lock


+ 1241 - 0
dl/cache-calibrator/calibrator.c

@@ -0,0 +1,1241 @@
+
+/*
+ * Calibrator v0.9e
+ * by Stefan.Manegold@cwi.nl, http://www.cwi.nl/~manegold/Calibrator/
+ *
+ * All rights reserved.
+ * No warranties.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above notice, this list
+ *    of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above notice, this
+ *    list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *	This product includes software developed by
+ *	Stefan.Manegold@cwi.nl, http://www.cwi.nl/~manegold/.
+ * 4. Any publication of result obtained by use of this software must
+ *    display a reference as follows:
+ *	Results produced by Calibrator v0.9e
+ *	(Stefan.Manegold@cwi.nl, http://www.cwi.nl/~manegold/)
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS `AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+#include        <unistd.h>
+*/
+#include        <stdlib.h>
+#include	<stdio.h>
+#include	<math.h>
+#include	<string.h>
+#include	<stdarg.h>
+
+#define VERSION "0.9e"
+
+#define NUMLOADS 100000
+#define REDUCE	 10
+#define	NUMTRIES 3
+#define	MINRANGE 1024
+#define MAXLEVELS 9
+#define LENPLATEAU 3
+
+	#define EPSILON1 0.1	
+/*	#define EPSILON3 2.0	*/
+
+/*	#define EPSILON2 0.04	*/
+	#define EPSILON4 1.0	
+
+
+#define	MIN(a,b)	(a<b?a:b)
+#define	MAX(a,b)	(a>b?a:b)
+#define NOABS(x)	((dbl)x)
+#define FABS		fabs
+
+#define	lng	long 
+#define	dbl	float
+
+lng MINTIME = 10000;
+
+#ifdef WIN32
+
+#include <Windows.h>
+
+/*	#define	MINTIME  100000	*/
+
+size_t getpagesize() { return 4096; }
+
+lng oldtp = 0;
+
+lng now(void)
+{
+	lng tp = (lng)timeGetTime();
+	if (oldtp == 0) {
+		/* timeBeginPeriod(1); */
+		tp += 11;
+		while ((lng)timeGetTime() <= tp) ;
+		oldtp = tp = (lng)timeGetTime();
+	}
+        return (lng)((tp - oldtp) * (lng)1000);
+}
+
+#else
+
+#include <sys/time.h>
+
+/*	#define	MINTIME  10000	*/
+
+struct timeval oldtp = { 0 };
+
+lng now(void)
+{
+	struct timeval tp;
+	gettimeofday(&tp, 0);
+	if (oldtp.tv_sec == 0 && oldtp.tv_usec == 0) {
+		oldtp = tp;
+	}
+        return (lng)( (lng)(tp.tv_sec  - oldtp.tv_sec ) * (lng)1000000 + 
+			(lng)(tp.tv_usec - oldtp.tv_usec)	);
+}
+
+#endif
+
+
+void ErrXit(char *format, ...) {
+        va_list	ap;
+        char	s[1024];
+
+	va_start(ap,format);
+        vsprintf(s, format, ap);
+  	va_end(ap);
+	fprintf(stderr, "\n! %s !\n", s);
+	fflush(stderr);
+	exit(1);
+}
+
+lng round(dbl x)
+{
+	return (lng)(x + 0.5);
+}
+
+char last(char *s)
+{
+	while (*s++);
+	return (s[-2]);
+}
+
+lng bytes(char *s)
+{
+	lng	n = atoi(s);
+
+	if ((last(s) == 'k') || (last(s) == 'K'))
+		n *= 1024;
+	if ((last(s) == 'm') || (last(s) == 'M'))
+		n *= (1024 * 1024);
+	if ((last(s) == 'g') || (last(s) == 'G'))
+		n *= (1024 * 1024 * 1024);
+	return (n);
+}
+
+#define NSperIt(t)	(((dbl)(t)) / (((dbl)NUMLOADS) / 1000.0))
+#define	CYperIt(t)	(((dbl)((t) * MHz)) / ((dbl)NUMLOADS))
+
+long use_result_dummy;	/* !static for optimizers. */
+void use_pointer(void *result) { use_result_dummy += (long)result; }
+
+lng loads(char *array, lng range, lng stride, lng MHz, FILE *fp, int delay)
+{
+	register char **p = 0;
+        lng     i, j=1, tries;
+	lng	time, best = 2000000000;
+
+	fprintf(stderr, "\r%11ld %11ld %11ld", range, stride, range/stride);
+	fflush(stderr);
+/*
+	for (i = stride; i < range; i += stride) {
+		p = (char **)&array[i];
+		*p = &array[i - stride];
+	}
+	p = (char **)&array[0];
+	*p = &array[i - stride];
+*/
+
+	for (i = stride; i < range; i += stride);
+	i -= stride;
+	for (; i >= 0; i -= stride) {
+		char	*next;
+
+		p = (char **)&array[i];
+		if (i < stride) {
+			next = &array[range - stride];
+		} else {
+			next = &array[i - stride];
+		}
+		*p = next;
+	}
+
+	#define	ONE	 p = (char **)*p;
+	#define	TEN	 ONE ONE ONE ONE ONE ONE ONE ONE ONE ONE
+	#define	HUNDRED	 TEN TEN TEN TEN TEN TEN TEN TEN TEN TEN
+/*
+	#define THOUSAND HUNDRED HUNDRED HUNDRED HUNDRED HUNDRED \
+			 HUNDRED HUNDRED HUNDRED HUNDRED HUNDRED
+*/
+
+	#define	FILL	 p++; p--;  p++; p--;  p++; p--;  p++; p--;  p++; p--;
+	#define	ONEx	 p = (char **)*p; \
+			 FILL FILL FILL FILL FILL FILL FILL FILL FILL FILL
+/*
+	#define	TENx	 ONEx ONEx ONEx ONEx ONEx ONEx ONEx ONEx ONEx ONEx
+	#define	HUNDREDx TENx TENx TENx TENx TENx TENx TENx TENx TENx TENx
+*/
+
+        if(delay) for (tries = 0; tries < NUMTRIES; ++tries) {
+		i = (j * NUMLOADS) / REDUCE;
+                time = now();
+                while (i > 0) {
+			ONEx
+			i -= 1;
+                }
+		time = now() - time;
+		use_pointer((void *)p);
+		if (time <= MINTIME) {
+			j *= 2;
+			tries--;
+		} else {
+			time *= REDUCE;
+			time /= j;
+			if (time < best) {
+				best = time;
+			}
+		}
+	} else for (tries = 0; tries < NUMTRIES; ++tries) {
+		i = (j * NUMLOADS);
+                time = now();
+                while (i > 0) {
+			HUNDRED
+			i -= 100;
+		}
+		time = now() - time;
+		use_pointer((void *)p);
+		if (time <= MINTIME) {
+			j *= 2;
+			tries--;
+		} else {
+			time /= j;
+			if (time < best) {
+				best = time;
+			}
+		}
+	}
+
+	fprintf(stderr, " %11ld %11ld", best*j, best);
+	fflush(stderr);
+
+	if (fp) {
+		fprintf(fp, " %06ld %05.1f %05.1f"
+			,best						/* elapsed time [microseconds] */
+			,NSperIt(best)					/* nanoseconds per iteration */
+			,CYperIt(best)					/* clocks per iteration */
+		);
+		fflush(fp);
+	}
+
+	return best;
+}
+
+lng** runCache(char *array, lng maxrange, lng minstride, lng MHz, FILE *fp, lng *maxstride)
+{
+	lng	i, r, x, y, z, range = maxrange, stride = minstride / 2;
+	dbl	f = 0.25;
+	lng	last, time = 0, **result;
+	lng	pgsz = getpagesize();
+	int	delay;
+
+	if (*maxstride) {
+		fprintf(stderr, "analyzing cache latency...\n");
+	} else {
+		fprintf(stderr, "analyzing cache throughput...\n");
+	}
+	fprintf(stderr, "      range      stride       spots     brutto-  netto-time\n");
+	fflush(stderr);
+
+	if (!(*maxstride)) {
+		do {
+			stride *= 2;
+			last = time;
+			time = loads(array, range, stride, MHz, 0, 0);
+			if (!time)
+				ErrXit("runCache: 'loads(%x(array), %ld(range), %ld(stride), %ld(MHz), 0(fp), 0(delay))` returned elapsed time of 0us",
+					array, range, stride, MHz);
+		#ifdef EPSILON1
+		} while (((fabs(time - last) / (dbl)time) > EPSILON1) && (stride <= (maxrange / 2)));
+		#endif
+		#ifdef EPSILON3
+		} while ((fabs(CYperIt(time) - CYperIt(last)) > EPSILON3) && (stride <= (maxrange / 2)));
+		#endif
+		*maxstride = stride;
+		delay = 0;
+	} else if (*maxstride < 0) {
+		*maxstride *= -1;
+		delay = 0;
+	} else {
+		delay = 1;
+	}
+
+	for (r = MINRANGE, y = 1; r <= maxrange; r *= 2) {
+		for (i = 3; i <= 5; i++) {
+			range = r * f * i;
+			if ((*maxstride <= range) && (range <= maxrange)) {
+				for (stride = *maxstride, x = 1; stride >= minstride; stride /= 2, x++) {
+				}
+				y++;
+			}
+		}
+	}
+	if (!(result = (lng**)malloc(y * sizeof(lng*))))
+		ErrXit("runCache: 'result = malloc(%ld)` failed", y * sizeof(lng*));
+	for (z = 0; z < y; z++) {
+		if (!(result[z] = (lng*)malloc(x * sizeof(lng))))
+			ErrXit("runCache: 'result[%ld] = malloc(%ld)` failed", z, x * sizeof(lng));
+		memset(result[z], 0, x * sizeof(lng));
+	}
+	result[0][0] = (y << 24) | x;
+
+	fprintf(fp, "# Calibrator v%s\n", VERSION);
+	fprintf(fp, "# (by Stefan.Manegold@cwi.nl, http://www.cwi.nl/~manegold/)\n");
+
+	for (r = MINRANGE, y = 1; r <= maxrange; r *= 2) {
+		for (i = 3; i <= 5; i++) {
+			range = r * f * i;
+			if ((*maxstride <= range) && (range <= maxrange)) {
+				result[y][0] = range;
+				fprintf(fp, "%08.1f %05ld"
+					,range / 1024.0	/* range in KB */
+					,range / pgsz	/* # pages covered */
+				);
+				fflush(fp);
+				for (stride = *maxstride, x = 1; stride >= minstride; stride /= 2, x++) {
+					if (!result[0][x]) {
+						result[0][x] = stride;
+					}
+					fprintf(fp, "  %03ld %09ld %08.1f"
+						,stride						/* stride */
+						,range / stride					/* # spots accessed  */
+						,((dbl)NUMLOADS) / ((dbl)(range / stride))	/* # accesses per spot */
+					);
+					fflush(fp);
+					result[y][x] = loads(array, range, stride, MHz, fp, delay);
+				}
+				fprintf(fp, "\n");
+				fflush(fp);
+				y++;
+			}
+		}
+	}
+
+	fprintf(stderr, "\n\n");
+	fflush(stderr);
+
+	return result;
+}
+
+lng** runTLB(char *array, lng maxrange, lng minstride, lng shift, lng mincachelines, lng MHz, FILE *fp, lng *maxstride)
+{
+	lng	i, x, y, z, stride, minspots, maxspots, p;
+	lng	range = maxrange, s = minstride / 2, spots = mincachelines / 2;
+	dbl	f = 0.25;
+	lng	tmax, smin, xmin, last, time = 0, **result;
+	lng	pgsz = getpagesize();
+	int	delay;
+
+	fprintf(stderr, "analyzing TLB latency...\n");
+	fprintf(stderr, "      range      stride       spots     brutto-  netto-time\n");
+	fflush(stderr);
+
+	if (!(*maxstride)) {
+		do {
+			s *= 2;
+			stride = s + shift;
+			range = stride * spots;
+			last = time;
+			time = loads(array, range, stride, MHz, 0, 0);
+			if (!time)
+				ErrXit("runTLB: 'loads(%x(array), %ld(range), %ld(stride), %ld(MHz), 0(fp), 0(delay))` returned elapsed time of 0us",
+					array, range, stride, MHz);
+		#ifdef EPSILON1
+		} while ((((fabs(time - last) / (dbl)time) > EPSILON1) || (stride < (pgsz / 1))) && (range <= (maxrange / 2)));	
+	/*	} while (((fabs(time - last) / (dbl)time) > EPSILON1) && (range <= (maxrange / 2)));	*/
+		#endif
+		#ifdef EPSILON3
+		} while ((fabs(CYperIt(time) - CYperIt(last)) > EPSILON3) || (stride < (pgsz / 1))) && (range <= (maxrange / 2)));	
+	/*	} while (fabs(CYperIt(time) - CYperIt(last)) > EPSILON3) && (range <= (maxrange / 2)));	*/
+		#endif
+		*maxstride = s;
+		delay = 0;
+	} else {
+		delay = 1;
+	}
+	minspots = MAX(MINRANGE / (minstride + shift), 4);
+	maxspots = maxrange / (*maxstride + shift);	
+/*	maxspots = mincachelines;	*/
+
+	for (p = minspots, y = 2; p <= maxspots; p *= 2) {
+		for (i = 3; i <= 5; i++) {
+			spots = p * f * i;
+			if ((spots * (*maxstride + shift)) <= maxrange) {
+				for (s = *maxstride, x = 2; s >= minstride; s /= 2, x++) {
+				}
+				y++;
+			}
+		}
+	}
+	if (!(result = (lng**)malloc(y * sizeof(lng*))))
+		ErrXit("runTLB: 'result = malloc(%ld)` failed", y * sizeof(lng*));
+	for (z = 0; z < y; z++) {
+		if (!(result[z] = (lng*)malloc(x * sizeof(lng))))
+			ErrXit("runTLB: 'result[%ld] = malloc(%ld)` failed", z, x * sizeof(lng*));
+		memset(result[z], 0, x * sizeof(lng));
+	}
+	result[0][0] = (y << 24) | x;
+
+	fprintf(fp, "# Calibrator v%s\n", VERSION);
+	fprintf(fp, "# (by Stefan.Manegold@cwi.nl, http://www.cwi.nl/~manegold/)\n");
+
+	for (p = minspots, y = 2; p <= maxspots; p *= 2) {
+		for (i = 3; i <= 5; i++) {
+			spots = p * f * i;
+			if ((spots * (*maxstride + shift)) <= maxrange) {
+				result[y][0] = spots;
+				fprintf(fp, "%09ld %08.1f"
+					,spots					/* # spots accessed  */
+					,((float)NUMLOADS) / ((float)spots)	/* # accesses per spot */
+				);
+				fflush(fp);
+				tmax = 0;
+				smin = *maxstride + shift;
+				xmin = 2;
+				for (s = *maxstride, x = 2; s >= minstride; s /= 2, x++) {
+					stride = s + shift;
+					if (!result[0][x]) {
+						result[0][x] = stride;
+					}
+					range = stride * spots;
+					fprintf(fp, "  %06ld %08.1f %05ld"
+						,stride		/* stride */
+						,range / 1024.0	/* range in KB */
+						,range / pgsz	/* # pages covered */
+					);
+					fflush(fp);
+					result[y][x] = loads(array, range, stride, MHz, fp, delay);
+					if (result[y][x] > tmax) {
+						tmax = result[y][x];
+						if (stride < smin) {
+							smin = stride;
+							xmin = x;
+						}
+					}
+				}
+				result[y][1] = tmax;
+				result[1][xmin]++;
+				fprintf(fp, "\n");
+				fflush(fp);
+				y++;
+			}
+		}
+	}
+	xmin = --x;
+	for (--x; x >= 2; x--) {
+		if (result[1][x] > result[1][xmin]) {
+			xmin = x;
+		}
+	}
+	result[0][1] = result[0][xmin];
+
+	fprintf(stderr, "\n\n");
+	fflush(stderr);
+	        
+	return result;
+}
+
+typedef struct {
+	lng	levels;
+	lng	size[MAXLEVELS];
+	lng	linesize[MAXLEVELS];
+	lng	latency1[MAXLEVELS];
+	lng	latency2[MAXLEVELS];
+} cacheInfo;
+
+cacheInfo* analyzeCache(lng **result1, lng **result2, lng MHz)
+{
+	lng	x, y, xx, yy, range, lastrange, stride, level, a, l, n;
+	lng	last[LENPLATEAU], time1, time2, lasttime1, lasttime2;
+	lng	diff;
+	cacheInfo *draft, *cache;
+
+	if (!(draft = (cacheInfo*)malloc(4 * sizeof(cacheInfo))))
+		ErrXit("analyzeCache: 'draft = malloc(%ld)` failed", 4 * sizeof(cacheInfo));
+	if (!(cache = (cacheInfo*)malloc(sizeof(cacheInfo))))
+		ErrXit("analyzeCache: 'cache = malloc(%ld)` failed", sizeof(cacheInfo));
+	memset(draft, 0, 4 * sizeof(cacheInfo));
+	memset(cache, 0, sizeof(cacheInfo));
+	
+	xx = (result1[0][0] & 0xffffff) - 1;
+	yy = (result1[0][0] >> 24) - 1;
+	level = 0;
+	memset(last, 0, LENPLATEAU * sizeof(last[0]));
+	a = LENPLATEAU;
+	lastrange = 0;
+	lasttime1 = 0;
+	lasttime2 = 0;
+	for (y = 1; y <= yy ; y++) {
+		range = result1[y][0];
+		for (x = 1; x <= xx; x++) {
+			stride = result1[0][x];
+			time1 = result1[y][x];
+			time2 = result2[y][x];
+			if (draft[1].linesize[level] && last[a] && (range == draft[1].size[level])) {
+				#ifdef EPSILON1
+				if ((fabs(time1 - last[a]) / (dbl)time1) < EPSILON1) {
+				#endif
+				#ifdef EPSILON3
+				if (fabs(CYperIt(time1) - CYperIt(last[a])) < EPSILON3) {
+				#endif
+					draft[0].linesize[level] = stride;
+					draft[1].linesize[level] = stride;
+				}
+			}
+			if (draft[2].linesize[level] && last[0] && lastrange && (lastrange == draft[2].size[level])) {
+				#ifdef EPSILON1
+				if ((fabs(time1 - last[0]) / (dbl)time1) < EPSILON1) {
+				#endif
+				#ifdef EPSILON3
+				if (fabs(CYperIt(time1) - CYperIt(last[0])) < EPSILON3) {
+				#endif
+					draft[2].linesize[level] = stride;
+					draft[3].linesize[level] = stride;
+					if (x == xx) {
+						level++;
+						memset(last, 0, LENPLATEAU * sizeof(last[0]));
+						a = LENPLATEAU;
+					}
+				} else {
+					level++;
+					memset(last, 0, LENPLATEAU * sizeof(last[0]));
+					a = LENPLATEAU;
+				}
+			}
+			#ifdef EPSILON2
+			if ((x == 1) && (!draft[2].linesize[level]) && ((last[0] && ((FABS(time1 - last[LENPLATEAU - 1]) / (dbl)last[LENPLATEAU - 1]) > EPSILON2)) || (y == yy))) {
+			#endif
+			#ifdef EPSILON4
+			if ((x == 1) && (!draft[2].linesize[level]) && ((last[0] && (FABS(CYperIt(time1) - CYperIt(last[LENPLATEAU - 1])) >= EPSILON4)) || (y == yy))) {
+			#endif
+				draft[2].linesize[level] = draft[1].linesize[level];
+				draft[2].size[level] = lastrange;
+				draft[2].latency1[level] = lasttime1;
+				draft[2].latency2[level] = lasttime2;
+				draft[3].linesize[level] = stride;
+				draft[3].size[level] = range;
+				draft[3].latency1[level] = time1;
+				draft[3].latency2[level] = time2;
+				last[0] = time1;
+			}
+			if ((x == 1) && (a < LENPLATEAU) && (!last[0])) {
+				#ifdef EPSILON2
+				if ((FABS(time1 - last[LENPLATEAU - 1]) / (dbl)last[LENPLATEAU - 1]) < EPSILON2) {
+				#endif
+				#ifdef EPSILON4
+				if (FABS(CYperIt(time1) - CYperIt(last[LENPLATEAU - 1])) <= EPSILON4) {
+				#endif
+					last[--a] = time1;
+				} else {
+					memset(last, 0, LENPLATEAU * sizeof(last[0]));
+					a = LENPLATEAU;
+				}
+			}
+			if ((x == 1) && (a == LENPLATEAU)) {
+				last[--a] = time1;
+				draft[0].linesize[level] = stride;
+				draft[0].size[level] = lastrange;
+				draft[0].latency1[level] = lasttime1;
+				draft[0].latency2[level] = lasttime2;
+				draft[1].linesize[level] = stride;
+				draft[1].size[level] = range;
+				draft[1].latency1[level] = time1;
+				draft[1].latency2[level] = time2;
+			}
+			if (x == 1) {
+				lasttime1 = time1;
+				lasttime2 = time2;
+			}
+		}
+		lastrange = range;
+	}
+
+	#ifdef DEBUG
+	{
+	lng ll;
+	for (l = 0; l < level; l++) {
+		for (ll = 0; ll < 4; ll++) {
+			fprintf(stderr, "%2ld %5ld %3ld  %05.1f %05.1f\n",
+				l, draft[ll].size[l] / 1024, draft[ll].linesize[l], NSperIt(draft[ll].latency1[l]), CYperIt(draft[ll].latency1[l]));
+		}
+		fprintf(stderr, "\n");
+	}
+	fflush(stderr);
+	}
+	#endif
+
+	for (l = n = 0 ; n < level; n++) {
+		cache->latency1[l] = ((dbl)(draft[2].latency1[n] + draft[1].latency1[n]) / 2.0);
+		cache->latency2[l] = ((dbl)(draft[2].latency2[n] + draft[1].latency2[n]) / 2.0);
+		if ((l == 0) || ((log10(cache->latency1[l]) - log10(cache->latency1[l - 1])) > 0.3)) {
+			cache->linesize[l] = draft[1].linesize[n];
+			diff = -1;
+			for (range = 1; range < result1[1][0]; range *= 2);
+			for (y = 1; result1[y][0] < range; y++);
+			if (l) {
+				int yyy = 1;
+				for (; y <= yy; y += yyy) {
+					range = result1[y][0];
+					if ((draft[2].size[n - 1] <= range) && (range < draft[1].size[n])) {
+						if ((y > yyy) && (((result1[y][1]) - (result1[y - yyy][1])) > diff)) {
+							diff = (result1[y][1]) - (result1[y - yyy][1]);
+							cache->size[l - 1] = range;
+						}
+						if (((y + yyy) <= yy) && (((result1[y + yyy][1]) - (result1[y][1])) > diff)) {
+							diff = (result1[y + yyy][1]) - (result1[y][1]);
+							cache->size[l - 1] = range;
+						}
+					}
+				}
+			}
+			l++;
+		}
+	}
+	cache->size[--l] = draft[3].size[--n];
+	cache->levels = l;
+	
+	#ifdef DEBUG
+	for (l = 0; l <= cache->levels; l++) {
+		fprintf(stderr, "%2ld %5ld %3ld  %05.1f %05.1f\n",
+			l, cache->size[l] / 1024, cache->linesize[l], NSperIt(cache->latency1[l]), CYperIt(cache->latency1[l]));
+	}
+	fprintf(stderr, "\n");
+	fflush(stderr);
+	#endif
+
+	free(draft);
+	draft = 0;
+
+	return cache;
+}
+
+typedef struct {
+	lng	levels;
+	lng	shift;
+	lng	mincachelines;
+	lng	entries[MAXLEVELS];
+	lng	pagesize[MAXLEVELS];
+	lng	latency1[MAXLEVELS];
+	lng	latency2[MAXLEVELS];
+} TLBinfo;
+
+TLBinfo* analyzeTLB(lng **result1, lng **result2, lng shift, lng mincachelines, lng MHz)
+{
+	lng	x, y, xx, yy, spots, lastspots, stride, level, a, l, limit = 0, n;
+	lng	last[LENPLATEAU], time1, time2, lasttime1, lasttime2;
+	dbl	diff;
+	TLBinfo *draft, *TLB;
+
+	if (!(draft = (TLBinfo*)malloc(4 * sizeof(TLBinfo))))
+		ErrXit("analyzeCache: 'draft = malloc(%ld)` failed", 4 * sizeof(TLBinfo));
+	if (!(TLB = (TLBinfo*)malloc(sizeof(TLBinfo))))
+		ErrXit("analyzeCache: 'TLB = malloc(%ld)` failed", sizeof(TLBinfo));
+	memset(draft, 0, 4 * sizeof(TLBinfo));
+	memset(TLB, 0, sizeof(TLBinfo));
+	TLB->shift = shift;
+	TLB->mincachelines = mincachelines;
+	
+	xx = (result1[0][0] & 0xffffff) - 1;
+	yy = (result1[0][0] >> 24) - 1;
+	level = 0;
+	memset(last, 0, LENPLATEAU * sizeof(last[0]));
+	a = LENPLATEAU;
+	lastspots = 0;
+	lasttime1 = 0;
+	lasttime2 = 0;
+	for (y = 2; !limit; y++) {
+		spots = result1[y][0];
+		limit = (y >= yy) || (spots >= (TLB->mincachelines * 1.25));
+		for (x = 1; x <= xx; x++) {
+			stride = result1[0][x];
+			time1 = result1[y][x];
+			time2 = result2[y][x];
+			if (draft[1].pagesize[level] && last[a] && (spots == draft[1].entries[level])) {
+				#ifdef EPSILON1
+				if (((fabs(time1 - last[a]) / (dbl)time1) < EPSILON1) || (stride >= result1[0][1])) {
+				#endif
+				#ifdef EPSILON3
+				if ((fabs(CYperIt(time1) - CYperIt(last[a])) < EPSILON3) || (stride >= result1[0][1])) {
+				#endif
+					draft[0].pagesize[level] = stride;
+					draft[1].pagesize[level] = stride;
+				}
+			}
+			if (draft[2].pagesize[level] && last[0] && lastspots && (lastspots == draft[2].entries[level])) {
+				#ifdef EPSILON1
+				if (((fabs(time1 - last[0]) / (dbl)time1) < EPSILON1) || (stride >= result1[0][1])) {
+				#endif
+				#ifdef EPSILON3
+				if ((fabs(CYperIt(time1) - CYperIt(last[0])) < EPSILON3) || (stride >= result1[0][1])) {
+				#endif
+					draft[2].pagesize[level] = stride;
+					draft[3].pagesize[level] = stride;
+					if (x == xx) {
+						level++;
+						memset(last, 0, LENPLATEAU * sizeof(last[0]));
+						a = LENPLATEAU;
+					}
+				} else {
+					level++;
+					memset(last, 0, LENPLATEAU * sizeof(last[0]));
+					a = LENPLATEAU;
+				}
+			}
+			#ifdef EPSILON2
+			if ((x == 1) && (!draft[2].pagesize[level]) && ((last[0] && ((FABS(time1 - last[LENPLATEAU - 1]) / (dbl)last[LENPLATEAU - 1]) > EPSILON2)) || limit)) {
+			#endif
+			#ifdef EPSILON4
+			if ((x == 1) && (!draft[2].pagesize[level]) && ((last[0] && (FABS(CYperIt(time1) - CYperIt(last[LENPLATEAU - 1])) >= EPSILON4)) || limit)) {
+			#endif
+				draft[2].pagesize[level] = draft[1].pagesize[level];
+				draft[2].entries[level] = lastspots;
+				draft[2].latency1[level] = lasttime1;
+				draft[2].latency2[level] = lasttime2;
+				draft[3].pagesize[level] = stride;
+				draft[3].entries[level] = spots;
+				draft[3].latency1[level] = time1;
+				draft[3].latency2[level] = time2;
+				last[0] = time1;
+			}
+			if ((x == 1) && (a < LENPLATEAU) && (!last[0])) {
+				#ifdef EPSILON2
+				if ((FABS(time1 - last[LENPLATEAU - 1]) / (dbl)last[LENPLATEAU - 1]) < EPSILON2) {
+				#endif
+				#ifdef EPSILON4
+				if (FABS(CYperIt(time1) - CYperIt(last[LENPLATEAU - 1])) <= EPSILON4) {
+				#endif
+					last[--a] = time1;
+				} else {
+					memset(last, 0, LENPLATEAU * sizeof(last[0]));
+					a = LENPLATEAU;
+				}
+			}
+			if ((x == 1) && (a == LENPLATEAU)) {
+				last[--a] = time1;
+				draft[0].pagesize[level] = stride;
+				draft[0].entries[level] = lastspots;
+				draft[0].latency1[level] = lasttime1;
+				draft[0].latency2[level] = lasttime2;
+				draft[1].pagesize[level] = stride;
+				draft[1].entries[level] = spots;
+				draft[1].latency1[level] = time1;
+				draft[1].latency2[level] = time2;
+			}
+			if (x == 1) {
+				lasttime1 = time1;
+				lasttime2 = time2;
+			}
+		}
+		lastspots = spots;
+	}
+
+	#ifdef DEBUG
+	{
+	lng ll;
+	for (l = 0; l < level; l++) {
+		for (ll = 0; ll < 4; ll++) {
+			fprintf(stderr, "%2ld %5ld %5ld  %05.1f %05.1f\n",
+				l, draft[ll].entries[l], draft[ll].pagesize[l], NSperIt(draft[ll].latency1[l]), CYperIt(draft[ll].latency1[l]));
+		}
+		fprintf(stderr, "\n");
+	}
+	fflush(stderr);
+	}
+	#endif
+
+	for (l = n = 0; n < level; n++) {
+		TLB->latency1[l] = ((dbl)(draft[2].latency1[n] + draft[1].latency1[n]) / 2.0);
+		TLB->latency2[l] = ((dbl)(draft[2].latency2[n] + draft[1].latency2[n]) / 2.0);
+		if ((l == 0) || (((log10(TLB->latency1[l]) - log10(TLB->latency1[l - 1])) > 0.3) && (draft[2].entries[l] > draft[1].entries[l]))) {
+			TLB->pagesize[l] = draft[1].pagesize[n];
+			diff = -1.0;
+			for (spots = 1; spots < result1[2][0]; spots *= 2);
+			for (y = 2; result1[y][0] < spots; y++);
+			if (l) {
+				int yyy = 1;
+				for (; y <= yy; y += yyy) {
+					spots = result1[y][0];
+					if ((draft[2].entries[n - 1] <= spots) && (spots < draft[1].entries[n])) {
+						if ((y > 4) && ((log(result1[y][1]) - log(result1[y - yyy][1])) > diff)) {
+							diff = log(result1[y][1]) - log(result1[y - yyy][1]);
+							TLB->entries[l - 1] = spots;
+						}
+						if (((y + yyy) <= yy) && ((log(result1[y + yyy][1]) - log(result1[y][1])) > diff)) {
+							diff = log(result1[y + yyy][1]) - log(result1[y][1]);
+							TLB->entries[l - 1] = spots;
+						}
+					}
+				}
+			}
+			l++;
+		}
+	}
+	TLB->entries[--l] = draft[3].entries[--n];
+	TLB->levels = l;
+	
+	#ifdef DEBUG
+	for (l = 0; l <= TLB->levels; l++) {
+		fprintf(stderr, "%2ld %5ld %5ld  %05.1f %05.1f\n",
+			l, TLB->entries[l], TLB->pagesize[l], NSperIt(TLB->latency1[l]), CYperIt(TLB->latency1[l]));
+	}
+	fprintf(stderr, "\n");
+	fflush(stderr);
+	#endif
+
+	free(draft);
+	draft = 0;
+
+	return TLB;
+}
+
+void plotCache(cacheInfo *cache, lng **result, lng MHz, char *fn, FILE *fp, lng delay)
+{
+	lng	l, x, xx = (result[0][0] & 0xffffff) - 1, y, yy = (result[0][0] >> 24) - 1;
+	dbl	xl, xh, yl, yh, z;
+	char	*s;
+	
+	xl = (dbl)result[1][0] / 1024.0;
+	xh = (dbl)result[yy][0] / 1024.0;
+	yl = 1.0;
+	for (yh = 1000; yh < (lng)NSperIt(result[yy][1] - delay); yh *= 10);
+	fprintf(fp, "# Calibrator v%s\n", VERSION);
+	fprintf(fp, "# (by Stefan.Manegold@cwi.nl, http://www.cwi.nl/~manegold/)\n");
+	fprintf(fp, " set term postscript portrait enhanced\n");
+	fprintf(fp, " set output '%s.ps'\n", fn);
+	fprintf(fp, "#set term gif transparent interlace small size 500, 707 # xFFFFFF x333333 x333333 x0055FF x005522 x660000 xFF0000 x00FF00 x0000FF\n");
+	fprintf(fp, "#set output '%s.gif'\n", fn);
+	fprintf(fp, "set data style linespoints\n");
+	fprintf(fp, "set key below\n");
+	fprintf(fp, "set title '%s'\n", fn);
+	fprintf(fp, "set xlabel 'memory range [bytes]'\n");
+	fprintf(fp, "set x2label ''\n");
+	fprintf(fp, "set ylabel 'nanosecs per iteration'\n");
+	fprintf(fp, "set y2label 'cycles per iteration'\n");
+	fprintf(fp, "set logscale x 2\n");
+	fprintf(fp, "set logscale x2 2\n");
+	fprintf(fp, "set logscale y 10\n");
+	fprintf(fp, "set logscale y2 10\n");
+	fprintf(fp, "set format x '%%1.0f'\n");
+	fprintf(fp, "set format x2 '%%1.0f'\n");
+	fprintf(fp, "set format y '%%1.0f'\n");
+	fprintf(fp, "set format y2 ''\n");
+	fprintf(fp, "set xrange[%f:%f]\n", xl, xh);
+	fprintf(fp, "#set x2range[%f:%f]\n", xl, xh);
+	fprintf(fp, "set yrange[%f:%f]\n", yl, yh);
+	fprintf(fp, "#set y2range[%f:%f]\n", yl, yh);
+	fprintf(fp, "set grid x2tics\n");
+	fprintf(fp, "set xtics mirror");
+	for (x = 1, l = 1, s = " ("; x <= xh; x *= 2, l++, s = ", ") {
+		if (l&1) {
+			if (x >= (1024 * 1024)) {
+				fprintf(fp, "%s'%ldG' %ld", s, x / (1024 * 1024), x);
+			} else if (x >= 1024) {
+				fprintf(fp, "%s'%ldM' %ld", s, x / 1024, x);
+			} else {
+				fprintf(fp, "%s'%ldk' %ld", s, x, x);
+			}
+		} else {
+			fprintf(fp, "%s'' %ld", s, x);
+		}
+	}
+	fprintf(fp, ")\n");
+	fprintf(fp, "set x2tics mirror");
+	for (l = 0, s = " ("; l < cache->levels; l++, s = ", ") {
+		if (cache->size[l] >= (1024 * 1024 * 1024)) {
+			fprintf(fp, "%s'[%ldG]' %ld", s, cache->size[l] / (1024 * 1024 * 1024), cache->size[l] / 1024);
+		} else if (cache->size[l] >= (1024 * 1024)) {
+			fprintf(fp, "%s'[%ldM]' %ld", s, cache->size[l] / (1024 * 1024), cache->size[l] / 1024);
+		} else {
+			fprintf(fp, "%s'[%ldk]' %ld", s, cache->size[l] / 1024, cache->size[l] / 1024);
+		}
+	}
+	fprintf(fp, ")\n");
+	fprintf(fp, "set y2tics");
+	for (l = 0, s = " ("; l <= cache->levels; l++, s = ", ") {
+		if (!delay)	fprintf(fp, "%s'(%ld)' %f", s, round(CYperIt(cache->latency1[l] - delay)), NSperIt(cache->latency1[l] - delay));
+			else	fprintf(fp, "%s'(%ld)' %f", s, round(CYperIt(cache->latency2[l] - delay)), NSperIt(cache->latency2[l] - delay));
+	}
+	for (y = 1; y <= yh; y *= 10) {
+		fprintf(fp, "%s'%1.3g' %ld", s, (dbl)(y * MHz) / 1000.0, y);
+	}
+	fprintf(fp, ")\n");
+	for (l = 0; l <= cache->levels; l++) {
+		if (!delay)	z = (dbl)round(CYperIt(cache->latency1[l] - delay)) * 1000.0 / (dbl)MHz;
+			else	z = (dbl)round(CYperIt(cache->latency2[l] - delay)) * 1000.0 / (dbl)MHz;
+		fprintf(fp, "set label %ld '(%1.3g)  ' at %f,%f right\n", l + 1, z, xl, z);
+		fprintf(fp, "set arrow %ld from %f,%f to %f,%f nohead lt 0\n", l + 1, xl, z, xh, z);
+	}
+	fprintf(fp, " set label %ld '^{ Calibrator v%s (Stefan.Manegold\\@cwi.nl, www.cwi.nl/~manegold) }' at graph 0.5,graph 0.02 center\n", l + 1, VERSION);
+	fprintf(fp, "#set label %ld    'Calibrator v%s (Stefan.Manegold@cwi.nl, www.cwi.nl/~manegold)'    at graph 0.5,graph 0.03 center\n",  l + 1, VERSION);
+	fprintf(fp, "plot \\\n0.1 title 'stride:' with points pt 0 ps 0");
+	for (x = 1, l = cache->levels; x <= xx; x++) {
+		fprintf(fp, " , \\\n'%s.data' using 1:($%ld-%f) title '", fn, (6 * x) + 1, NSperIt(delay));
+		if ((l > 0) && (result[0][x] == cache->linesize[l])) {
+			fprintf(fp, "\\{%ld\\}", result[0][x]);
+			while ((--l >= 0) && (result[0][x] == cache->linesize[l]));
+		} else {
+			fprintf(fp, "%ld", result[0][x]);
+		}
+		fprintf(fp, "' with linespoints lt %ld pt %ld", x, x + 2);
+	}
+	fprintf(fp, "\n");
+	fprintf(fp, "set nolabel\n");
+	fprintf(fp, "set noarrow\n");
+	fflush(fp);
+}
+
+void plotTLB(TLBinfo *TLB, lng **result, lng MHz, char *fn, FILE *fp, lng delay)
+{
+	lng	l, x, xx = (result[0][0] & 0xffffff) - 1, y, yy = (result[0][0] >> 24) - 1;
+	dbl	xl, xh, yl, yh, z;
+	char	*s;
+	
+	xl = (dbl)result[2][0];
+	xh = (dbl)result[yy][0];
+	yl = 1.0;
+	for (yh = 1000; yh < (lng)NSperIt(result[yy][2] - delay); yh *= 10);
+	fprintf(fp, "# Calibrator v%s\n", VERSION);
+	fprintf(fp, "# (by Stefan.Manegold@cwi.nl, http://www.cwi.nl/~manegold/)\n");
+	fprintf(fp, " set term postscript portrait enhanced\n");
+	fprintf(fp, " set output '%s.ps'\n", fn);
+	fprintf(fp, "#set term gif transparent interlace small size 500, 707 # xFFFFFF x333333 x333333 x0055FF x005522 x660000 xFF0000 x00FF00 x0000FF\n");
+	fprintf(fp, "#set output '%s.gif'\n", fn);
+	fprintf(fp, "set data style linespoints\n");
+	fprintf(fp, "set key below\n");
+	fprintf(fp, "set title '%s'\n", fn);
+	fprintf(fp, "set xlabel 'spots accessed'\n");
+	fprintf(fp, "set x2label ''\n");
+	fprintf(fp, "set ylabel 'nanosecs per iteration'\n");
+	fprintf(fp, "set y2label 'cycles per iteration'\n");
+	fprintf(fp, "set logscale x 2\n");
+	fprintf(fp, "set logscale x2 2\n");
+	fprintf(fp, "set logscale y 10\n");
+	fprintf(fp, "set logscale y2 10\n");
+	fprintf(fp, "set format x '%%1.0f'\n");
+	fprintf(fp, "set format x2 '%%1.0f'\n");
+	fprintf(fp, "set format y '%%1.0f'\n");
+	fprintf(fp, "set format y2 ''\n");
+	fprintf(fp, "set xrange[%f:%f]\n", xl, xh);
+	fprintf(fp, "#set x2range[%f:%f]\n", xl, xh);
+	fprintf(fp, "set yrange[%f:%f]\n", yl, yh);
+	fprintf(fp, "#set y2range[%f:%f]\n", yl, yh);
+	fprintf(fp, "set grid x2tics\n");
+	fprintf(fp, "set xtics mirror");
+	for (x = 1, l = 1, s = " ("; x <= xh; x *= 2, l++, s = ", ") {
+		if (l | 1) {
+			if (x >= (1024 * 1024)) {
+				fprintf(fp, "%s'%ldM' %ld", s, x / (1024 * 1024), x);
+			} else if (x >= 1024) {
+				fprintf(fp, "%s'%ldk' %ld", s, x / 1024, x);
+			} else {
+				fprintf(fp, "%s'%ld' %ld", s, x, x);
+			}
+		} else {
+			fprintf(fp, "%s'' %ld", s, x);
+		}
+	}
+	fprintf(fp, ")\n");
+	fprintf(fp, "set x2tics mirror");
+	for (l = 0, s = " ("; l < TLB->levels; l++, s = ", ") {
+		if (TLB->entries[l] >= (1024 * 1024)) {
+			fprintf(fp, "%s'[%ldM]' %ld", s, TLB->entries[l] / (1024 * 1024), TLB->entries[l]);
+		} else if (TLB->entries[l] >= 1024) {
+			fprintf(fp, "%s'[%ldk]' %ld", s, TLB->entries[l] / 1024, TLB->entries[l]);
+		} else {
+			fprintf(fp, "%s'[%ld]' %ld", s, TLB->entries[l], TLB->entries[l]);
+		}
+	}
+	fprintf(fp, "%s'<L1>' %ld)\n", s, TLB->mincachelines);
+	fprintf(fp, "set y2tics");
+	for (l = 0, s = " ("; l <= TLB->levels; l++, s = ", ") {
+		if (!delay)	fprintf(fp, "%s'(%ld)' %f", s, round(CYperIt(TLB->latency1[l] - delay)), NSperIt(TLB->latency1[l] - delay));
+			else	fprintf(fp, "%s'(%ld)' %f", s, round(CYperIt(TLB->latency2[l] - delay)), NSperIt(TLB->latency2[l] - delay));
+	}
+	for (y = 1; y <= yh; y *= 10) {
+		fprintf(fp, "%s'%1.3g' %ld", s, (dbl)(y * MHz) / 1000.0, y);
+	}
+	fprintf(fp, ")\n");
+	for (l = 0; l <= TLB->levels; l++) {
+		if (!delay)	z = (dbl)round(CYperIt(TLB->latency1[l] - delay)) * 1000.0 / (dbl)MHz;
+			else	z = (dbl)round(CYperIt(TLB->latency2[l] - delay)) * 1000.0 / (dbl)MHz;
+		fprintf(fp, "set label %ld '(%1.3g)  ' at %f,%f right\n", l + 1, z, xl, z);
+		fprintf(fp, "set arrow %ld from %f,%f to %f,%f nohead lt 0\n", l + 1, xl, z, xh, z);
+	}
+	fprintf(fp, " set label %ld '^{ Calibrator v%s (Stefan.Manegold\\@cwi.nl, www.cwi.nl/~manegold) }' at graph 0.5,graph 0.02 center\n", l + 1, VERSION);
+        fprintf(fp, "#set label %ld    'Calibrator v%s (Stefan.Manegold@cwi.nl, www.cwi.nl/~manegold)'    at graph 0.5,graph 0.03 center\n",  l + 1, VERSION);
+	fprintf(fp, "plot \\\n0.1 title 'stride:' with points pt 0 ps 0");
+	for (x = 2, l = TLB->levels; x <= xx; x++) {
+		fprintf(fp, " , \\\n'%s.data' using 1:($%ld-%f) title '", fn, (6 * (x - 1)) + 1, NSperIt(delay));
+		if ((l > 0) && (result[0][x] == TLB->pagesize[l])) {
+			fprintf(fp, "\\{%ld\\}", result[0][x]);
+			while ((--l >= 0) && (result[0][x] == TLB->pagesize[l]));
+		} else {
+			fprintf(fp, "%ld", result[0][x]);
+		}
+		fprintf(fp, "' with linespoints lt %ld pt %ld", x, x + 2);
+	}
+	fprintf(fp, "\n");
+	fprintf(fp, "set nolabel\n");
+	fprintf(fp, "set noarrow\n");
+	fflush(fp);
+}
+
+void printCPU(cacheInfo *cache, lng MHz, lng delay)
+{
+	FILE	*fp = stdout;
+		
+	fprintf(fp, "CPU loop + L1 access:    ");
+	fprintf(fp, " %6.2f ns = %3ld cy\n", NSperIt(cache->latency1[0]), round(CYperIt(cache->latency1[0])));
+	fprintf(fp, "             ( delay:    ");
+	fprintf(fp, " %6.2f ns = %3ld cy )\n", NSperIt(delay),            round(CYperIt(delay)));
+	fprintf(fp, "\n");
+	fflush(fp);
+}
+
+void printCache(cacheInfo *cache, lng MHz)
+{
+	lng	l;
+	FILE	*fp = stdout;
+		
+	fprintf(fp, "caches:\n");
+	fprintf(fp, "level  size    linesize   miss-latency        replace-time\n");
+	for (l = 0; l < cache->levels; l++) {
+		fprintf(fp, "  %1ld   ", l+1);
+		if (cache->size[l] >= (1024 * 1024 * 1024)) {
+			fprintf(fp, " %3ld GB ", cache->size[l] / (1024 * 1024 * 1024));
+		} else if (cache->size[l] >= (1024 * 1024)) {
+			fprintf(fp, " %3ld MB ", cache->size[l] / (1024 * 1024));
+		} else {
+			fprintf(fp, " %3ld KB ", cache->size[l] / 1024);
+		}
+		fprintf(fp, " %3ld bytes ", cache->linesize[l + 1]);
+		fprintf(fp, " %6.2f ns = %3ld cy " , NSperIt(cache->latency2[l + 1] - cache->latency2[l]), round(CYperIt(cache->latency2[l + 1] - cache->latency2[l])));
+		fprintf(fp, " %6.2f ns = %3ld cy\n", NSperIt(cache->latency1[l + 1] - cache->latency1[l]), round(CYperIt(cache->latency1[l + 1] - cache->latency1[l])));
+	}
+	fprintf(fp, "\n");
+	fflush(fp);
+}
+
+void printTLB(TLBinfo *TLB, lng MHz)
+{
+	lng	l;
+	FILE	*fp = stdout;
+		
+	fprintf(fp, "TLBs:\n");
+	fprintf(fp, "level #entries  pagesize  miss-latency");
+/*
+	fprintf(fp, "        replace-time");
+*/
+	fprintf(fp, "\n");
+	for (l = 0; l < TLB->levels; l++) {
+		fprintf(fp, "  %1ld   ", l+1);
+		fprintf(fp, "   %3ld   ", TLB->entries[l]);
+		if (TLB->pagesize[l + 1] >= (1024 * 1024 * 1024)) {
+			fprintf(fp, "  %3ld GB  ", TLB->pagesize[l + 1] / (1024 * 1024 * 1024));
+		} else if (TLB->pagesize[l + 1] >= (1024 * 1024)) {
+			fprintf(fp, "  %3ld MB  ", TLB->pagesize[l + 1] / (1024 * 1024));
+		} else {
+			fprintf(fp, "  %3ld KB  ", TLB->pagesize[l + 1] / 1024);
+		}
+		fprintf(fp, " %6.2f ns = %3ld cy ", NSperIt(TLB->latency2[l + 1] - TLB->latency2[l]), round(CYperIt(TLB->latency2[l + 1] - TLB->latency2[l])));
+/*
+		fprintf(fp, " %6.2f ns = %3ld cy" , NSperIt(TLB->latency1[l + 1] - TLB->latency1[l]), round(CYperIt(TLB->latency1[l + 1] - TLB->latency1[l])));
+*/
+		fprintf(fp, "\n");
+	}
+	fprintf(fp, "\n");
+	fflush(fp);
+}
+
+lng getMINTIME () {
+	lng t0=0, t1=0;
+	t0=t1=now();
+	while(t0==t1){
+		t1=now();
+	}
+	return (t1-t0);
+}
+
+int main(int ac, char **av)
+{
+	lng	MHz, maxrange, mincachelines, maxlinesize, minstride = (lng)sizeof(char*), yy, y;
+	lng	maxCstride=0, maxTstride=0, delayC, delayT;
+        char	*array0, *array, fnn1[1024], fnx1[1024], fnn2[1024], fnx2[1024];
+	FILE	*fp;
+	lng	**result1, **result2;
+	cacheInfo *cache;
+	TLBinfo	*TLB;
+	lng	align = 0, pgsz  = getpagesize();
+
+	fprintf(stdout,"\nCalibrator v%s\n(by Stefan.Manegold@cwi.nl, http://www.cwi.nl/~manegold/)\n", VERSION);
+
+	if (ac < 4) ErrXit("usage: '%s <MHz> <size>[k|M|G] <filename>`", av[0]);
+
+	MHz      = atoi(av[1]);
+        maxrange = bytes(av[2]) * 1.25;
+
+	if (ac > 4) align = atoi(av[4]) % pgsz;
+	if (ac > 5) maxCstride = -1 * abs(atoi(av[5]));
+
+	if (!(array0 = (char *)malloc(maxrange+pgsz)))
+		ErrXit("main: 'array0 = malloc(%ld)` failed", maxrange+pgsz);
+
+	array = array0;
+        fprintf(stderr,"%x %ld %ld %5ld\n",array,(lng)array,pgsz,(lng)array%pgsz);
+        while (((lng)array % pgsz) != align) {
+		fprintf(stderr,"\r%x %ld %ld %5ld",array,(lng)array,pgsz,(lng)array%pgsz);
+		fflush(stderr);
+		array++;
+	}
+	fprintf(stderr,"\n%x %ld %ld %5ld\n\n",array,(lng)array,pgsz,(lng)array%pgsz);
+	fflush(stderr);
+	
+	MINTIME = MAX( MINTIME, 10*getMINTIME() );
+	fprintf(stderr,"MINTIME = %ld\n\n",MINTIME);
+	fflush(stderr);
+
+	sprintf(fnn1, "%s.cache-replace-time", av[3]);
+        sprintf(fnx1, "%s.data", fnn1);
+	if (!(fp = fopen(fnx1,"w"))) ErrXit("main: 'fp = fopen(%s,\"w\")` failed", fnx1);
+	result1 = runCache(array, maxrange, minstride, MHz, fp, &maxCstride);
+ 	fclose(fp);
+
+        sprintf(fnn2, "%s.cache-miss-latency", av[3]);
+        sprintf(fnx2, "%s.data", fnn2);
+	if (!(fp = fopen(fnx2,"w"))) ErrXit("main: 'fp = fopen(%s,\"w\")` failed", fnx2);
+	result2 = runCache(array, maxrange, minstride, MHz, fp, &maxCstride);
+ 	fclose(fp);
+
+	cache = analyzeCache(result1, result2, MHz);
+	mincachelines = ( cache->size[0] && cache->linesize[1] ? cache->size[0] / cache->linesize[1] : 1024 );
+	maxlinesize = ( cache->linesize[cache->levels] ? cache->linesize[cache->levels] : maxCstride / 2 );
+	delayC = cache->latency2[0] - cache->latency1[0];
+
+        sprintf(fnx1, "%s.gp", fnn1);
+	if (!(fp = fopen(fnx1,"w"))) ErrXit("main: 'fp = fopen(%s,\"w\")` failed", fnx1);
+	plotCache(cache, result1, MHz, fnn1, fp, 0);
+	fclose(fp);
+
+        sprintf(fnx2, "%s.gp", fnn2);
+	if (!(fp = fopen(fnx2,"w"))) ErrXit("main: 'fp = fopen(%s,\"w\")` failed", fnx2);
+	plotCache(cache, result2, MHz, fnn2, fp, delayC);
+	fclose(fp);
+
+	yy = (result1[0][0] >> 24) - 1;
+	for (y = 0; y <= yy; y++) {
+		free(result1[y]);
+		result1[y] = 0;
+	}
+	free(result1);
+	result1 = 0;
+
+	yy = (result2[0][0] >> 24) - 1;
+	for (y = 0; y <= yy; y++) {
+		free(result2[y]);
+		result2[y] = 0;
+	}
+	free(result2);
+	result2 = 0;
+
+
+        sprintf(fnn1, "%s.TLB-miss-latency", av[3]);
+        sprintf(fnx1, "%s.data", fnn1);
+	if (!(fp = fopen(fnx1,"w"))) ErrXit("main: 'fp = fopen(%s,\"w\")` failed", fnx1);
+	result1 = runTLB(array, maxrange, 1024, maxlinesize, mincachelines, MHz, fp, &maxTstride);
+	fclose(fp);
+
+/*
+        sprintf(fnn2, "%s.TLB2", av[3]);
+        sprintf(fnx2, "%s.data", fnn2);
+	if (!(fp = fopen(fnx2,"w"))) ErrXit("main: 'fp = fopen(%s,\"w\")` failed", fnx2);
+	result2 = runTLB(array, maxrange, 1024, maxlinesize, mincachelines, MHz, fp, &maxTstride);
+	fclose(fp);
+*/
+	result2 = result1;
+
+	TLB = analyzeTLB(result1, result2, maxlinesize, mincachelines, MHz);
+	delayT = TLB->latency2[0] - TLB->latency1[0];
+
+        sprintf(fnx1, "%s.gp", fnn1);
+	if (!(fp = fopen(fnx1,"w"))) ErrXit("main: 'fp = fopen(%s,\"w\")` failed", fnx1);
+	plotTLB(TLB, result1, MHz, fnn1, fp, 0);
+	fclose(fp);
+
+/*
+        sprintf(fnx2, "%s.gp", fnn2);
+	if (!(fp = fopen(fnx2,"w"))) ErrXit("main: 'fp = fopen(%s,\"w\")` failed", fnx2);
+	plotTLB(TLB, result2, MHz, fnn2, fp, delayT);
+	fclose(fp);
+*/
+
+	yy = (result1[0][0] >> 24) - 1;
+	for (y = 0; y <= yy; y++) {
+		free(result1[y]);
+		result1[y] = 0;
+	}
+	free(result1);
+	result1 = 0;
+
+/*
+	yy = (result2[0][0] >> 24) - 1;
+	for (y = 0; y <= yy; y++) {
+		free(result2[y]);
+		result2[y] = 0;
+	}
+	free(result2);
+*/
+	result2 = 0;
+
+
+	fprintf(stdout,"\n");
+
+	printCPU(cache, MHz, delayC);
+	printCache(cache, MHz);
+	printTLB(TLB, MHz);
+
+	free(cache);
+	cache = 0;
+	free(TLB);
+	TLB = 0;
+
+	return(0);
+}
+

+ 0 - 0
dl/coreutils/.lock


BIN
dl/coreutils/coreutils-8.32.tar.xz


+ 0 - 0
dl/iputils/.lock


BIN
dl/iputils/iputils-20200821.tar.gz


+ 0 - 0
dl/libcap-ng/.lock


BIN
dl/libcap-ng/libcap-ng-0.8.tar.gz


+ 0 - 0
dl/linux-pam/.lock


BIN
dl/linux-pam/Linux-PAM-1.4.0.tar.xz


+ 0 - 0
dl/msmtp/.lock


BIN
dl/msmtp/msmtp-1.8.11.tar.xz


+ 0 - 0
dl/mutt/.lock


BIN
dl/mutt/mutt-1.14.7.tar.gz


+ 0 - 0
dl/ramsmp/.lock


BIN
dl/ramsmp/ramsmp-3.5.0.tar.gz


+ 0 - 0
dl/ramspeed/.lock


BIN
dl/ramspeed/ramspeed-2.6.0.tar.gz


+ 0 - 0
dl/stress-ng/.lock


BIN
dl/stress-ng/stress-ng-0.11.17.tar.xz


+ 0 - 0
dl/wget/.lock


BIN
dl/wget/wget-1.20.3.tar.lz


+ 0 - 0
dl/whetstone/.lock


+ 433 - 0
dl/whetstone/whetstone.c

@@ -0,0 +1,433 @@
+/*
+ * C Converted Whetstone Double Precision Benchmark
+ *		Version 1.2	22 March 1998
+ *
+ *	(c) Copyright 1998 Painter Engineering, Inc.
+ *		All Rights Reserved.
+ *
+ *		Permission is granted to use, duplicate, and
+ *		publish this text and program as long as it
+ *		includes this entire comment block and limited
+ *		rights reference.
+ *
+ * Converted by Rich Painter, Painter Engineering, Inc. based on the
+ * www.netlib.org benchmark/whetstoned version obtained 16 March 1998.
+ *
+ * A novel approach was used here to keep the look and feel of the
+ * FORTRAN version.  Altering the FORTRAN-based array indices,
+ * starting at element 1, to start at element 0 for C, would require
+ * numerous changes, including decrementing the variable indices by 1.
+ * Instead, the array E1[] was declared 1 element larger in C.  This
+ * allows the FORTRAN index range to function without any literal or
+ * variable indices changes.  The array element E1[0] is simply never
+ * used and does not alter the benchmark results.
+ *
+ * The major FORTRAN comment blocks were retained to minimize
+ * differences between versions.  Modules N5 and N12, like in the
+ * FORTRAN version, have been eliminated here.
+ *
+ * An optional command-line argument has been provided [-c] to
+ * offer continuous repetition of the entire benchmark.
+ * An optional argument for setting an alternate LOOP count is also
+ * provided.  Define PRINTOUT to cause the POUT() function to print
+ * outputs at various stages.  Final timing measurements should be
+ * made with the PRINTOUT undefined.
+ *
+ * Questions and comments may be directed to the author at
+ *			r.painter@ieee.org
+ */
+/*
+C**********************************************************************
+C     Benchmark #2 -- Double  Precision Whetstone (A001)
+C
+C     o	This is a REAL*8 version of
+C	the Whetstone benchmark program.
+C
+C     o	DO-loop semantics are ANSI-66 compatible.
+C
+C     o	Final measurements are to be made with all
+C	WRITE statements and FORMAT sttements removed.
+C
+C**********************************************************************   
+*/
+
+/* standard C library headers required */
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+
+/* the following is optional depending on the timing function used */
+#include <time.h>
+
+/* map the FORTRAN math functions, etc. to the C versions */
+#define DSIN	sin
+#define DCOS	cos
+#define DATAN	atan
+#define DLOG	log
+#define DEXP	exp
+#define DSQRT	sqrt
+#define IF		if
+
+/* function prototypes */
+void POUT(long N, long J, long K, double X1, double X2, double X3, double X4);
+void PA(double E[]);
+void P0(void);
+void P3(double X, double Y, double *Z);
+#define USAGE	"usage: whetdc [-c] [loops]\n"
+
+/*
+	COMMON T,T1,T2,E1(4),J,K,L
+*/
+double T,T1,T2,E1[5];
+int J,K,L;
+
+int
+main(int argc, char *argv[])
+{
+	/* used in the FORTRAN version */
+	long I;
+	long N1, N2, N3, N4, N6, N7, N8, N9, N10, N11;
+	double X1,X2,X3,X4,X,Y,Z;
+	long LOOP;
+	int II, JJ;
+
+	/* added for this version */
+	long loopstart;
+	long startsec, finisec;
+	float KIPS;
+	int continuous;
+
+	loopstart = 1000;		/* see the note about LOOP below */
+	continuous = 0;
+
+	II = 1;		/* start at the first arg (temp use of II here) */
+	while (II < argc) {
+		if (strncmp(argv[II], "-c", 2) == 0 || argv[II][0] == 'c') {
+			continuous = 1;
+		} else if (atol(argv[II]) > 0) {
+			loopstart = atol(argv[II]);
+		} else {
+			fprintf(stderr, USAGE);
+			return(1);
+		}
+		II++;
+	}
+
+LCONT:
+/*
+C
+C	Start benchmark timing at this point.
+C
+*/
+	startsec = time(0);
+
+/*
+C
+C	The actual benchmark starts here.
+C
+*/
+	T  = .499975;
+	T1 = 0.50025;
+	T2 = 2.0;
+/*
+C
+C	With loopcount LOOP=10, one million Whetstone instructions
+C	will be executed in EACH MAJOR LOOP..A MAJOR LOOP IS EXECUTED
+C	'II' TIMES TO INCREASE WALL-CLOCK TIMING ACCURACY.
+C
+	LOOP = 1000;
+*/
+	LOOP = loopstart;
+	II   = 1;
+
+	JJ = 1;
+
+IILOOP:
+	N1  = 0;
+	N2  = 12 * LOOP;
+	N3  = 14 * LOOP;
+	N4  = 345 * LOOP;
+	N6  = 210 * LOOP;
+	N7  = 32 * LOOP;
+	N8  = 899 * LOOP;
+	N9  = 616 * LOOP;
+	N10 = 0;
+	N11 = 93 * LOOP;
+/*
+C
+C	Module 1: Simple identifiers
+C
+*/
+	X1  =  1.0;
+	X2  = -1.0;
+	X3  = -1.0;
+	X4  = -1.0;
+
+	for (I = 1; I <= N1; I++) {
+	    X1 = (X1 + X2 + X3 - X4) * T;
+	    X2 = (X1 + X2 - X3 + X4) * T;
+	    X3 = (X1 - X2 + X3 + X4) * T;
+	    X4 = (-X1+ X2 + X3 + X4) * T;
+	}
+#ifdef PRINTOUT
+	IF (JJ==II)POUT(N1,N1,N1,X1,X2,X3,X4);
+#endif
+
+/*
+C
+C	Module 2: Array elements
+C
+*/
+	E1[1] =  1.0;
+	E1[2] = -1.0;
+	E1[3] = -1.0;
+	E1[4] = -1.0;
+
+	for (I = 1; I <= N2; I++) {
+	    E1[1] = ( E1[1] + E1[2] + E1[3] - E1[4]) * T;
+	    E1[2] = ( E1[1] + E1[2] - E1[3] + E1[4]) * T;
+	    E1[3] = ( E1[1] - E1[2] + E1[3] + E1[4]) * T;
+	    E1[4] = (-E1[1] + E1[2] + E1[3] + E1[4]) * T;
+	}
+
+#ifdef PRINTOUT
+	IF (JJ==II)POUT(N2,N3,N2,E1[1],E1[2],E1[3],E1[4]);
+#endif
+
+/*
+C
+C	Module 3: Array as parameter
+C
+*/
+	for (I = 1; I <= N3; I++)
+		PA(E1);
+
+#ifdef PRINTOUT
+	IF (JJ==II)POUT(N3,N2,N2,E1[1],E1[2],E1[3],E1[4]);
+#endif
+
+/*
+C
+C	Module 4: Conditional jumps
+C
+*/
+	J = 1;
+	for (I = 1; I <= N4; I++) {
+		if (J == 1)
+			J = 2;
+		else
+			J = 3;
+
+		if (J > 2)
+			J = 0;
+		else
+			J = 1;
+
+		if (J < 1)
+			J = 1;
+		else
+			J = 0;
+	}
+
+#ifdef PRINTOUT
+	IF (JJ==II)POUT(N4,J,J,X1,X2,X3,X4);
+#endif
+
+/*
+C
+C	Module 5: Omitted
+C 	Module 6: Integer arithmetic
+C
+*/
+
+	J = 1;
+	K = 2;
+	L = 3;
+
+	for (I = 1; I <= N6; I++) {
+	    J = J * (K-J) * (L-K);
+	    K = L * K - (L-J) * K;
+	    L = (L-K) * (K+J);
+	    E1[L-1] = J + K + L;
+	    E1[K-1] = J * K * L;
+	}
+
+#ifdef PRINTOUT
+	IF (JJ==II)POUT(N6,J,K,E1[1],E1[2],E1[3],E1[4]);
+#endif
+
+/*
+C
+C	Module 7: Trigonometric functions
+C
+*/
+	X = 0.5;
+	Y = 0.5;
+
+	for (I = 1; I <= N7; I++) {
+		X = T * DATAN(T2*DSIN(X)*DCOS(X)/(DCOS(X+Y)+DCOS(X-Y)-1.0));
+		Y = T * DATAN(T2*DSIN(Y)*DCOS(Y)/(DCOS(X+Y)+DCOS(X-Y)-1.0));
+	}
+
+#ifdef PRINTOUT
+	IF (JJ==II)POUT(N7,J,K,X,X,Y,Y);
+#endif
+
+/*
+C
+C	Module 8: Procedure calls
+C
+*/
+	X = 1.0;
+	Y = 1.0;
+	Z = 1.0;
+
+	for (I = 1; I <= N8; I++)
+		P3(X,Y,&Z);
+
+#ifdef PRINTOUT
+	IF (JJ==II)POUT(N8,J,K,X,Y,Z,Z);
+#endif
+
+/*
+C
+C	Module 9: Array references
+C
+*/
+	J = 1;
+	K = 2;
+	L = 3;
+	E1[1] = 1.0;
+	E1[2] = 2.0;
+	E1[3] = 3.0;
+
+	for (I = 1; I <= N9; I++)
+		P0();
+
+#ifdef PRINTOUT
+	IF (JJ==II)POUT(N9,J,K,E1[1],E1[2],E1[3],E1[4]);
+#endif
+
+/*
+C
+C	Module 10: Integer arithmetic
+C
+*/
+	J = 2;
+	K = 3;
+
+	for (I = 1; I <= N10; I++) {
+	    J = J + K;
+	    K = J + K;
+	    J = K - J;
+	    K = K - J - J;
+	}
+
+#ifdef PRINTOUT
+	IF (JJ==II)POUT(N10,J,K,X1,X2,X3,X4);
+#endif
+
+/*
+C
+C	Module 11: Standard functions
+C
+*/
+	X = 0.75;
+
+	for (I = 1; I <= N11; I++)
+		X = DSQRT(DEXP(DLOG(X)/T1));
+
+#ifdef PRINTOUT
+	IF (JJ==II)POUT(N11,J,K,X,X,X,X);
+#endif
+
+/*
+C
+C      THIS IS THE END OF THE MAJOR LOOP.
+C
+*/
+	if (++JJ <= II)
+		goto IILOOP;
+
+/*
+C
+C      Stop benchmark timing at this point.
+C
+*/
+	finisec = time(0);
+
+/*
+C----------------------------------------------------------------
+C      Performance in Whetstone KIP's per second is given by
+C
+C	(100*LOOP*II)/TIME
+C
+C      where TIME is in seconds.
+C--------------------------------------------------------------------
+*/
+	printf("\n");
+	if (finisec-startsec <= 0) {
+		printf("Insufficient duration- Increase the LOOP count\n");
+		return(1);
+	}
+
+	printf("Loops: %ld, Iterations: %d, Duration: %ld sec.\n",
+			LOOP, II, finisec-startsec);
+
+	KIPS = (100.0*LOOP*II)/(float)(finisec-startsec);
+	if (KIPS >= 1000.0)
+		printf("C Converted Double Precision Whetstones: %.1f MIPS\n", KIPS/1000.0);
+	else
+		printf("C Converted Double Precision Whetstones: %.1f KIPS\n", KIPS);
+
+	if (continuous)
+		goto LCONT;
+
+	return(0);
+}
+
+void
+PA(double E[])
+{
+	J = 0;
+
+L10:
+	E[1] = ( E[1] + E[2] + E[3] - E[4]) * T;
+	E[2] = ( E[1] + E[2] - E[3] + E[4]) * T;
+	E[3] = ( E[1] - E[2] + E[3] + E[4]) * T;
+	E[4] = (-E[1] + E[2] + E[3] + E[4]) / T2;
+	J += 1;
+
+	if (J < 6)
+		goto L10;
+}
+
+void
+P0(void)
+{
+	E1[J] = E1[K];
+	E1[K] = E1[L];
+	E1[L] = E1[J];
+}
+
+void
+P3(double X, double Y, double *Z)
+{
+	double X1, Y1;
+
+	X1 = X;
+	Y1 = Y;
+	X1 = T * (X1 + Y1);
+	Y1 = T * (X1 + Y1);
+	*Z  = (X1 + Y1) / T2;
+}
+
+#ifdef PRINTOUT
+void
+POUT(long N, long J, long K, double X1, double X2, double X3, double X4)
+{
+	printf("%7ld %7ld %7ld %12.4e %12.4e %12.4e %12.4e\n",
+						N, J, K, X1, X2, X3, X4);
+}
+#endif

+ 0 - 0
dl/which/.lock


BIN
dl/which/which-2.21.tar.gz