|
@@ -1,3 +1,24 @@
|
|
|
+
|
|
|
+/* Original version in Hoard Memory Allocator v2.1.2d
|
|
|
+ *
|
|
|
+ * This is a UNIX port of the latest version of the benchmark described
|
|
|
+ * by Larson & Krishnan in "Memory Allocation for Long-Running Server
|
|
|
+ * Applications", ISMM 1998.
|
|
|
+ *
|
|
|
+ * To see how it scales, try the following parameters, where P = 1 and
|
|
|
+ * then the number of processors on your system, for larson and
|
|
|
+ * larson_hoard:
|
|
|
+ *
|
|
|
+ * Multi-threaded test driver
|
|
|
+ * C++ version (new and delete)
|
|
|
+ * runtime (sec): 30
|
|
|
+ * chunk size (min,max): 8 16
|
|
|
+ * threads (min, max): P P
|
|
|
+ * chunks/thread: 10000
|
|
|
+ * no of rounds: 10
|
|
|
+ * random seed: 1
|
|
|
+ */
|
|
|
+
|
|
|
#include <pthread.h>
|
|
|
#include <stdio.h>
|
|
|
#include <sys/time.h>
|
|
@@ -6,7 +27,7 @@
|
|
|
#include <unistd.h>
|
|
|
#include <stdlib.h>
|
|
|
#include <dmmlib/dmmlib.h>
|
|
|
-#include <dmmlib/initialize_allocator.h>
|
|
|
+#include <dmmlib/print_stats.h>
|
|
|
#include "lran2.h"
|
|
|
|
|
|
#define MAX_THREADS 100
|
|
@@ -17,17 +38,6 @@
|
|
|
enum BOOLEAN { FALSE, TRUE };
|
|
|
#endif /* BOOLEAN */
|
|
|
|
|
|
-/*
|
|
|
-
|
|
|
-#define custom_malloc(size) malloc(size)
|
|
|
-#define custom_free(ptr) free(ptr)
|
|
|
-
|
|
|
-*/
|
|
|
-
|
|
|
-allocator_t allocator;
|
|
|
-#define custom_malloc(size) custom_ahmalloc(&allocator, &allocator.heaps[0], size)
|
|
|
-#define custom_free(ptr) custom_ahfree(&allocator, &allocator.heaps[0], ptr)
|
|
|
-
|
|
|
typedef void * LPVOID;
|
|
|
typedef unsigned long ULONG;
|
|
|
typedef long long _int64;
|
|
@@ -94,7 +104,7 @@ static void warmup(char **blkp, int num_chunks) {
|
|
|
|
|
|
for(cblks = 0; cblks < num_chunks; cblks++) {
|
|
|
blk_size = min_size + lran2(&rgen) % (max_size - min_size);
|
|
|
- blkp[cblks] = (char *) custom_malloc((size_t) blk_size);
|
|
|
+ blkp[cblks] = (char *) malloc((size_t) blk_size);
|
|
|
blksize[cblks] = blk_size;
|
|
|
assert(blkp[cblks] != NULL);
|
|
|
}
|
|
@@ -109,10 +119,10 @@ static void warmup(char **blkp, int num_chunks) {
|
|
|
|
|
|
for(cblks=0; cblks < 4 * num_chunks; cblks++) {
|
|
|
victim = lran2(&rgen) % num_chunks;
|
|
|
- custom_free(blkp[victim]);
|
|
|
+ free(blkp[victim]);
|
|
|
|
|
|
blk_size = min_size + lran2(&rgen) % (max_size - min_size);
|
|
|
- blkp[victim] = (char *) custom_malloc((size_t) blk_size);
|
|
|
+ blkp[victim] = (char *) malloc((size_t) blk_size);
|
|
|
blksize[victim] = blk_size;
|
|
|
assert(blkp[victim] != NULL);
|
|
|
}
|
|
@@ -135,11 +145,11 @@ static void * exercise_heap( void *pinput) {
|
|
|
/* allocate NumBlocks chunks of random size */
|
|
|
for(cblks=0; cblks < pdea->NumBlocks; cblks++) {
|
|
|
victim = lran2(&pdea->rgen)%pdea->asize;
|
|
|
- custom_free(pdea->array[victim]);
|
|
|
+ free(pdea->array[victim]);
|
|
|
pdea->cFrees++;
|
|
|
|
|
|
blk_size = pdea->min_size+lran2(&pdea->rgen)%range;
|
|
|
- pdea->array[victim] = (char *) custom_malloc((size_t) blk_size);
|
|
|
+ pdea->array[victim] = (char *) malloc((size_t) blk_size);
|
|
|
|
|
|
pdea->blksize[victim] = blk_size;
|
|
|
assert(pdea->array[victim] != NULL);
|
|
@@ -187,8 +197,8 @@ static void runthreads(long sleep_cnt, int min_threads, int max_threads, int chp
|
|
|
double duration ;
|
|
|
|
|
|
double rate_1 = 0, rate_n;
|
|
|
- double reqd_space;
|
|
|
- ULONG used_space;
|
|
|
+ size_t reqd_space;
|
|
|
+ size_t used_space;
|
|
|
|
|
|
QueryPerformanceFrequency( &ticks_per_sec );
|
|
|
|
|
@@ -258,14 +268,18 @@ static void runthreads(long sleep_cnt, int min_threads, int max_threads, int chp
|
|
|
if( rate_1 == 0){
|
|
|
rate_1 = rate_n ;
|
|
|
}
|
|
|
- reqd_space = (0.5*(min_size+max_size)*num_threads*chperthread) ;
|
|
|
- // used_space = CountReservedSpace() - init_space;
|
|
|
- used_space = 0;
|
|
|
+ //reqd_space = (0.5*(min_size+max_size)*num_threads*chperthread) ;
|
|
|
+ //used_space = CountReservedSpace() - init_space;
|
|
|
+ // FIXME Currently only one heap is used in the example
|
|
|
+ used_space = get_allocated_space(&systemallocator.heaps[0]);
|
|
|
+ reqd_space = get_used_space(&systemallocator.heaps[0]);
|
|
|
+ //used_space = 0;
|
|
|
+ printf(" Used space: %zu\n Requested space: %zu\n", used_space, reqd_space);
|
|
|
|
|
|
printf("%2d ", num_threads ) ;
|
|
|
printf("%6.3f", duration ) ;
|
|
|
- printf("%6.3f", rate_n/rate_1 ) ;
|
|
|
- printf("%8.0f", sum_allocs/duration ) ;
|
|
|
+ printf("%6.3f", rate_n/rate_1 );
|
|
|
+ printf("%8.0f", sum_allocs/duration);
|
|
|
printf(" %6.3f %.3f", (double)(used_space/(1024*1024)), (used_space/reqd_space));
|
|
|
printf("\n") ;
|
|
|
|
|
@@ -283,32 +297,31 @@ int main(void) {
|
|
|
int num_rounds;
|
|
|
int chperthread;
|
|
|
|
|
|
- void *block_from_malloc;
|
|
|
-
|
|
|
- block_from_malloc = malloc(64000000);
|
|
|
- initialize_allocator(&allocator, block_from_malloc, 64000000);
|
|
|
-
|
|
|
printf("Larson benchmark\n");
|
|
|
|
|
|
printf("runtime (sec): ") ;
|
|
|
//scanf ("%ld", &sleep_cnt);
|
|
|
- sleep_cnt = 10;
|
|
|
+ sleep_cnt = 30;
|
|
|
+ printf("%ld\n", sleep_cnt);
|
|
|
|
|
|
printf("chunk size (min,max): ") ;
|
|
|
//scanf("%d %d", &min_size, &max_size ) ;
|
|
|
- min_size = 1024;
|
|
|
- max_size = 5012;
|
|
|
+ min_size = 8;
|
|
|
+ max_size = 16;
|
|
|
+ printf("%d %d\n", min_size, max_size);
|
|
|
|
|
|
printf("threads (min, max): ") ;
|
|
|
//scanf("%d %d", &min_threads, &max_threads) ;
|
|
|
min_threads = 1;
|
|
|
max_threads = 2;
|
|
|
+ printf("%d %d\n", min_threads, max_threads);
|
|
|
|
|
|
pthread_setconcurrency(max_threads);
|
|
|
|
|
|
printf("chunks/thread: ");
|
|
|
//scanf("%d", &chperthread );
|
|
|
- chperthread = 1;
|
|
|
+ chperthread = 10000;
|
|
|
+ printf("%d\n", chperthread);
|
|
|
|
|
|
num_chunks = max_threads * chperthread ;
|
|
|
if( num_chunks > MAX_BLOCKS ){
|
|
@@ -318,12 +331,11 @@ int main(void) {
|
|
|
|
|
|
printf("no of rounds: ");
|
|
|
//scanf("%d", &num_rounds );
|
|
|
- num_rounds = 1;
|
|
|
+ num_rounds = 10;
|
|
|
+ printf("%d\n", num_rounds);
|
|
|
|
|
|
runthreads(sleep_cnt, min_threads, max_threads, chperthread, num_rounds) ;
|
|
|
|
|
|
- free(block_from_malloc);
|
|
|
-
|
|
|
return 0;
|
|
|
}
|
|
|
|