mirror of
https://github.com/openharmony/third_party_mimalloc.git
synced 2026-07-01 07:28:51 -04:00
@@ -99,30 +99,12 @@ mimalloc_unittest("test-info") {
|
||||
libs = [ "xml2.z" ]
|
||||
}
|
||||
|
||||
mimalloc_unittest("bench-malloc-thread") {
|
||||
sources = [ "perfomance/bench-malloc-thread.c" ]
|
||||
}
|
||||
|
||||
mimalloc_unittest("xmalloc-test") {
|
||||
sources = [ "perfomance/xmalloc-test.c" ]
|
||||
}
|
||||
|
||||
without_mimalloc_test("bench-malloc-thread-default") {
|
||||
sources = [ "perfomance/bench-malloc-thread.c" ]
|
||||
}
|
||||
|
||||
without_mimalloc_test("xmalloc-test-default") {
|
||||
sources = [ "perfomance/xmalloc-test.c" ]
|
||||
}
|
||||
|
||||
mimalloc_unittest("test-backtrace") {
|
||||
}
|
||||
|
||||
group("mimalloc_test") {
|
||||
testonly = true
|
||||
deps = [
|
||||
":bench-malloc-thread",
|
||||
":bench-malloc-thread-default",
|
||||
":test-api",
|
||||
":test-api-fill",
|
||||
":test-backtrace",
|
||||
@@ -133,7 +115,5 @@ group("mimalloc_test") {
|
||||
":test-mallopt",
|
||||
":test-stats-print",
|
||||
":test-stress",
|
||||
":xmalloc-test",
|
||||
":xmalloc-test-default",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
# Mimalloc perfomance tests
|
||||
|
||||
**xmalloc-test** - multi-threads benchmark with 100 purely allocating threads, and 100 purely deallocating threads with objects of various sizes migrating between them. This asymmetric producer/consumer pattern is usually difficult to handle by allocators with thread-local caches.
|
||||
|
||||
**bench-malloc-thread** - multi-threads benchmark originally prepared for the glibc memory allocator
|
||||
|
||||
### How to prepare:
|
||||
|
||||
1. Build tests:
|
||||
```
|
||||
$ ./build.sh --product-name rk3568 --build-target third_party/mimalloc:mimalloc_test
|
||||
```
|
||||
|
||||
2. Copy tests to device:
|
||||
```
|
||||
$ ./hdc_std file send ~/workspace/ohos/out/rk3568/tests/unittest/mimalloc_test/ /data
|
||||
```
|
||||
|
||||
3. Make tests executable on the device:
|
||||
```
|
||||
# chmod -R a+x /data/mimalloc_test/
|
||||
```
|
||||
|
||||
### Versions of tests:
|
||||
|
||||
- xmalloc-test - test binary that use **mimalloc** memory allocator
|
||||
- xmalloc-test-default - test binary that use **default musl** allocator
|
||||
- bench-malloc-thread - test binary that use **mimalloc** memory allocator
|
||||
- bench-malloc-thread-default - test binary that use **default musl** allocator
|
||||
|
||||
#### Run xmalloc-tests:
|
||||
```
|
||||
# ./xmalloc-test -w 4 -t 5 -s 64
|
||||
# ./xmalloc-test-default -w 4 -t 5 -s 64
|
||||
```
|
||||
|
||||
Output is relative time (**rtime** smaller is better):
|
||||
```
|
||||
# ./xmalloc-test -w 4 -t 5 -s 64
|
||||
rtime: 15.258, free/sec: 6.554 M
|
||||
# ./xmalloc-test-default -w 4 -t 5 -s 64
|
||||
rtime: 125.008, free/sec: 0.800 M
|
||||
```
|
||||
|
||||
#### Run bench-malloc-thread:
|
||||
```
|
||||
# ./bench-malloc-thread 4
|
||||
# ./bench-malloc-thread-default 4
|
||||
```
|
||||
|
||||
Output is number of iterations that tests can execute in constant time (**iterations** bigger is better):
|
||||
```
|
||||
# ./bench-malloc-thread 4
|
||||
18120892 iterations
|
||||
# ./bench-malloc-thread-default 4
|
||||
3996257 iterations
|
||||
```
|
||||
@@ -1,262 +0,0 @@
|
||||
/* Benchmark malloc and free functions.
|
||||
Copyright (C) 2013-2021 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, see
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <errno.h>
|
||||
#include <math.h>
|
||||
#include <pthread.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
#include <unistd.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
/* Benchmark duration in seconds. */
|
||||
#define BENCHMARK_DURATION 2
|
||||
#define RAND_SEED 88
|
||||
|
||||
#ifndef NUM_THREADS
|
||||
# define NUM_THREADS 1
|
||||
#endif
|
||||
|
||||
typedef long timing_t;
|
||||
#define TIMING_NOW(s)
|
||||
#define TIMING_DIFF(e,start,stop)
|
||||
#define TIMING_ACCUM(x,y)
|
||||
|
||||
/* Maximum memory that can be allocated at any one time is:
|
||||
NUM_THREADS * WORKING_SET_SIZE * MAX_ALLOCATION_SIZE
|
||||
However due to the distribution of the random block sizes
|
||||
the typical amount allocated will be much smaller. */
|
||||
#define WORKING_SET_SIZE 1024
|
||||
|
||||
#define MIN_ALLOCATION_SIZE 4
|
||||
#define MAX_ALLOCATION_SIZE 32768
|
||||
|
||||
/* Get a random block size with an inverse square distribution. */
|
||||
static unsigned int
|
||||
get_block_size (unsigned int rand_data)
|
||||
{
|
||||
/* Inverse square. */
|
||||
const float exponent = -2;
|
||||
/* Minimum value of distribution. */
|
||||
const float dist_min = MIN_ALLOCATION_SIZE;
|
||||
/* Maximum value of distribution. */
|
||||
const float dist_max = MAX_ALLOCATION_SIZE;
|
||||
|
||||
float min_pow = powf (dist_min, exponent + 1);
|
||||
float max_pow = powf (dist_max, exponent + 1);
|
||||
|
||||
float r = (float) rand_data / RAND_MAX;
|
||||
|
||||
return (unsigned int) powf ((max_pow - min_pow) * r + min_pow,
|
||||
1 / (exponent + 1));
|
||||
}
|
||||
|
||||
#define NUM_BLOCK_SIZES 8000
|
||||
#define NUM_OFFSETS ((WORKING_SET_SIZE) * 4)
|
||||
|
||||
static unsigned int random_block_sizes[NUM_BLOCK_SIZES];
|
||||
static unsigned int random_offsets[NUM_OFFSETS];
|
||||
|
||||
static void
|
||||
init_random_values (void)
|
||||
{
|
||||
for (size_t i = 0; i < NUM_BLOCK_SIZES; i++)
|
||||
random_block_sizes[i] = get_block_size (rand ());
|
||||
|
||||
for (size_t i = 0; i < NUM_OFFSETS; i++)
|
||||
random_offsets[i] = rand () % WORKING_SET_SIZE;
|
||||
}
|
||||
|
||||
static unsigned int
|
||||
get_random_block_size (unsigned int *state)
|
||||
{
|
||||
unsigned int idx = *state;
|
||||
|
||||
if (idx >= NUM_BLOCK_SIZES - 1)
|
||||
idx = 0;
|
||||
else
|
||||
idx++;
|
||||
|
||||
*state = idx;
|
||||
|
||||
return random_block_sizes[idx];
|
||||
}
|
||||
|
||||
static unsigned int
|
||||
get_random_offset (unsigned int *state)
|
||||
{
|
||||
unsigned int idx = *state;
|
||||
|
||||
if (idx >= NUM_OFFSETS - 1)
|
||||
idx = 0;
|
||||
else
|
||||
idx++;
|
||||
|
||||
*state = idx;
|
||||
|
||||
return random_offsets[idx];
|
||||
}
|
||||
|
||||
static volatile bool timeout;
|
||||
|
||||
static void
|
||||
alarm_handler (int signum)
|
||||
{
|
||||
timeout = true;
|
||||
}
|
||||
|
||||
/* Allocate and free blocks in a random order. */
|
||||
static size_t
|
||||
malloc_benchmark_loop (void **ptr_arr)
|
||||
{
|
||||
unsigned int offset_state = 0, block_state = 0;
|
||||
size_t iters = 0;
|
||||
|
||||
while (!timeout)
|
||||
{
|
||||
unsigned int next_idx = get_random_offset (&offset_state);
|
||||
unsigned int next_block = get_random_block_size (&block_state);
|
||||
|
||||
free (ptr_arr[next_idx]);
|
||||
|
||||
void* p = ptr_arr[next_idx] = malloc (next_block);
|
||||
|
||||
// touch the allocated memory
|
||||
for(int i = 0; i < next_block; i++) {
|
||||
((char*)p)[i] = (char)i;
|
||||
}
|
||||
iters++;
|
||||
}
|
||||
|
||||
return iters;
|
||||
}
|
||||
|
||||
struct thread_args
|
||||
{
|
||||
size_t iters;
|
||||
void **working_set;
|
||||
timing_t elapsed;
|
||||
};
|
||||
|
||||
static void *
|
||||
benchmark_thread (void *arg)
|
||||
{
|
||||
struct thread_args *args = (struct thread_args *) arg;
|
||||
size_t iters;
|
||||
void *thread_set = args->working_set;
|
||||
//timing_t start, stop;
|
||||
|
||||
//TIMING_NOW (start);
|
||||
iters = malloc_benchmark_loop (thread_set);
|
||||
//TIMING_NOW (stop);
|
||||
|
||||
//TIMING_DIFF (args->elapsed, start, stop);
|
||||
args->iters = iters;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static timing_t
|
||||
do_benchmark (size_t num_threads, size_t *iters)
|
||||
{
|
||||
timing_t elapsed = 0;
|
||||
|
||||
if (num_threads == 1)
|
||||
{
|
||||
//timing_t start, stop;
|
||||
void *working_set[WORKING_SET_SIZE];
|
||||
|
||||
memset (working_set, 0, sizeof (working_set));
|
||||
|
||||
//TIMING_NOW (start);
|
||||
*iters = malloc_benchmark_loop (working_set);
|
||||
//TIMING_NOW (stop);
|
||||
|
||||
//TIMING_DIFF (elapsed, start, stop);
|
||||
}
|
||||
else
|
||||
{
|
||||
struct thread_args args[num_threads];
|
||||
void *working_set[num_threads][WORKING_SET_SIZE];
|
||||
pthread_t threads[num_threads];
|
||||
|
||||
memset (working_set, 0, sizeof (working_set));
|
||||
|
||||
*iters = 0;
|
||||
|
||||
for (size_t i = 0; i < num_threads; i++)
|
||||
{
|
||||
args[i].working_set = working_set[i];
|
||||
pthread_create(&threads[i], NULL, benchmark_thread, &args[i]);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < num_threads; i++)
|
||||
{
|
||||
pthread_join(threads[i], NULL);
|
||||
TIMING_ACCUM (elapsed, args[i].elapsed);
|
||||
*iters += args[i].iters;
|
||||
}
|
||||
}
|
||||
return elapsed;
|
||||
}
|
||||
|
||||
static void usage(const char *name)
|
||||
{
|
||||
fprintf (stderr, "%s: <num_threads>\n", name);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
timing_t cur;
|
||||
size_t iters = 0, num_threads = 1;
|
||||
struct sigaction act;
|
||||
//double d_total_s, d_total_i;
|
||||
|
||||
if (argc == 1)
|
||||
num_threads = 1;
|
||||
else if (argc == 2)
|
||||
{
|
||||
long ret;
|
||||
|
||||
errno = 0;
|
||||
ret = strtol(argv[1], NULL, 10);
|
||||
|
||||
if (errno || ret == 0)
|
||||
usage(argv[0]);
|
||||
|
||||
num_threads = ret;
|
||||
}
|
||||
else
|
||||
usage(argv[0]);
|
||||
|
||||
init_random_values ();
|
||||
memset (&act, 0, sizeof (act));
|
||||
act.sa_handler = &alarm_handler;
|
||||
|
||||
sigaction (SIGALRM, &act, NULL);
|
||||
|
||||
alarm (BENCHMARK_DURATION);
|
||||
|
||||
cur = do_benchmark (num_threads, &iters);
|
||||
printf("%zd iterations\n", iters );
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
// =======================================================
|
||||
|
||||
/* lran2.h
|
||||
* by Wolfram Gloger 1996.
|
||||
*
|
||||
* A small, portable pseudo-random number generator.
|
||||
*/
|
||||
|
||||
#ifndef _LRAN2_H
|
||||
#define _LRAN2_H
|
||||
|
||||
#define LRAN2_MAX 714025l /* constants for portable */
|
||||
#define IA 1366l /* random number generator */
|
||||
#define IC 150889l /* (see e.g. `Numerical Recipes') */
|
||||
|
||||
struct lran2_st {
|
||||
long x, y, v[97];
|
||||
};
|
||||
|
||||
static void
|
||||
lran2_init(struct lran2_st* d, long seed)
|
||||
{
|
||||
long x;
|
||||
int j;
|
||||
|
||||
x = (IC - seed) % LRAN2_MAX;
|
||||
if(x < 0) x = -x;
|
||||
for(j=0; j<97; j++) {
|
||||
x = (IA*x + IC) % LRAN2_MAX;
|
||||
d->v[j] = x;
|
||||
}
|
||||
d->x = (IA*x + IC) % LRAN2_MAX;
|
||||
d->y = d->x;
|
||||
}
|
||||
|
||||
static
|
||||
long lran2(struct lran2_st* d)
|
||||
{
|
||||
int j = (d->y % 97);
|
||||
|
||||
d->y = d->v[j];
|
||||
d->x = (IA*d->x + IC) % LRAN2_MAX;
|
||||
d->v[j] = d->x;
|
||||
return d->y;
|
||||
}
|
||||
|
||||
#undef IA
|
||||
#undef IC
|
||||
#endif
|
||||
@@ -1,286 +0,0 @@
|
||||
/**
|
||||
* \file test-malloc_test.c
|
||||
* \author C. Lever and D. Boreham, Christian Eder ( ederc@mathematik.uni-kl.de )
|
||||
* \date 2000
|
||||
* \brief Test file for xmalloc. This is a multi-threaded test system by
|
||||
* Lever and Boreham. It is first noted in their paper "malloc()
|
||||
* Performance in a Multithreaded Linux Environment", appeared at the
|
||||
* USENIX 2000 Annual Technical Conference: FREENIX Track.
|
||||
* This file is part of XMALLOC, licensed under the GNU General
|
||||
* Public License version 3. See COPYING for more information.
|
||||
*/
|
||||
#include <errno.h>
|
||||
#include <pthread.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <unistd.h>
|
||||
//#include "xmalloc-config.h"
|
||||
//#include "xmalloc.h"
|
||||
|
||||
#include "random.h"
|
||||
|
||||
#define CACHE_ALIGNED 1
|
||||
|
||||
#define xmalloc malloc
|
||||
#define xfree free
|
||||
|
||||
#define DEFAULT_OBJECT_SIZE 1024
|
||||
|
||||
int debug_flag = 0;
|
||||
int verbose_flag = 0;
|
||||
#define num_workers_default 4
|
||||
int num_workers = num_workers_default;
|
||||
double run_time = 5.0;
|
||||
int object_size = DEFAULT_OBJECT_SIZE;
|
||||
/* array for thread ids */
|
||||
pthread_t *thread_ids;
|
||||
/* array for saving result of each thread */
|
||||
struct counter {
|
||||
long c
|
||||
#if CACHE_ALIGNED
|
||||
__attribute__((aligned(64)))
|
||||
#endif
|
||||
;
|
||||
};
|
||||
struct counter *counters;
|
||||
|
||||
volatile int done_flag = 0;
|
||||
struct timeval begin;
|
||||
|
||||
|
||||
#define atomic_load(addr) __atomic_load_n(addr, __ATOMIC_CONSUME)
|
||||
#define atomic_store(addr, v) __atomic_store_n(addr, v, __ATOMIC_RELEASE)
|
||||
|
||||
|
||||
static void
|
||||
tvsub(tdiff, t1, t0)
|
||||
struct timeval *tdiff, *t1, *t0;
|
||||
{
|
||||
|
||||
tdiff->tv_sec = t1->tv_sec - t0->tv_sec;
|
||||
tdiff->tv_usec = t1->tv_usec - t0->tv_usec;
|
||||
if (tdiff->tv_usec < 0)
|
||||
tdiff->tv_sec--, tdiff->tv_usec += 1000000;
|
||||
}
|
||||
|
||||
double elapsed_time(struct timeval *time0)
|
||||
{
|
||||
struct timeval timedol;
|
||||
struct timeval td;
|
||||
double et = 0.0;
|
||||
|
||||
gettimeofday(&timedol, (struct timezone *)0);
|
||||
tvsub( &td, &timedol, time0 );
|
||||
et = td.tv_sec + ((double)td.tv_usec) / 1000000;
|
||||
|
||||
return( et );
|
||||
}
|
||||
|
||||
static const long possible_sizes[] = {8,12,16,24,32,48,64,96,128,192,256,(256*3)/2,512, (512*3)/2, 1024, (1024*3)/2, 2048};
|
||||
static const int n_sizes = sizeof(possible_sizes)/sizeof(long);
|
||||
|
||||
#define OBJECTS_PER_BATCH 4096
|
||||
struct batch {
|
||||
struct batch *next_batch;
|
||||
void *objects[OBJECTS_PER_BATCH];
|
||||
};
|
||||
|
||||
struct batch *batches = NULL;
|
||||
volatile int batch_count = 0;
|
||||
const int batch_count_limit = 100;
|
||||
pthread_cond_t empty_cv = PTHREAD_COND_INITIALIZER;
|
||||
pthread_cond_t full_cv = PTHREAD_COND_INITIALIZER;
|
||||
pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
void enqueue_batch(struct batch *batch) {
|
||||
pthread_mutex_lock(&lock);
|
||||
while (batch_count >= batch_count_limit && !atomic_load(&done_flag)) {
|
||||
pthread_cond_wait(&full_cv, &lock);
|
||||
}
|
||||
batch->next_batch = batches;
|
||||
batches = batch;
|
||||
batch_count++;
|
||||
pthread_cond_signal(&empty_cv);
|
||||
pthread_mutex_unlock(&lock);
|
||||
}
|
||||
|
||||
struct batch* dequeue_batch() {
|
||||
pthread_mutex_lock(&lock);
|
||||
while (batches == NULL && !atomic_load(&done_flag)) {
|
||||
pthread_cond_wait(&empty_cv, &lock);
|
||||
}
|
||||
struct batch* result = batches;
|
||||
if (result) {
|
||||
batches = result->next_batch;
|
||||
batch_count--;
|
||||
pthread_cond_signal(&full_cv);
|
||||
}
|
||||
pthread_mutex_unlock(&lock);
|
||||
return result;
|
||||
}
|
||||
|
||||
void *mem_allocator (void *arg) {
|
||||
int thread_id = *(int *)arg;
|
||||
struct lran2_st lr;
|
||||
lran2_init(&lr, thread_id);
|
||||
|
||||
while (!atomic_load(&done_flag)) {
|
||||
struct batch *b = xmalloc(sizeof(*b));
|
||||
for (int i = 0; i < OBJECTS_PER_BATCH; i++) {
|
||||
size_t siz = object_size > 0 ? object_size : possible_sizes[lran2(&lr)%n_sizes];
|
||||
b->objects[i] = xmalloc(siz);
|
||||
memset(b->objects[i],i%256,(siz > 128 ? 128 : siz));
|
||||
}
|
||||
enqueue_batch(b);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *mem_releaser(void *arg) {
|
||||
int thread_id = *(int *)arg;
|
||||
|
||||
while(!atomic_load(&done_flag)) {
|
||||
struct batch *b = dequeue_batch();
|
||||
if (b) {
|
||||
for (int i = 0; i < OBJECTS_PER_BATCH; i++) {
|
||||
xfree(b->objects[i]);
|
||||
}
|
||||
xfree(b);
|
||||
}
|
||||
counters[thread_id].c += OBJECTS_PER_BATCH;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int run_memory_free_test()
|
||||
{
|
||||
void *ptr = NULL;
|
||||
int i;
|
||||
double elapse_time = 0.0;
|
||||
long total = 0;
|
||||
int *ids = (int *)xmalloc(sizeof(int) * num_workers);
|
||||
|
||||
/* Initialize counter */
|
||||
for(i = 0; i < num_workers; ++i)
|
||||
counters[i].c = 0;
|
||||
|
||||
gettimeofday(&begin, (struct timezone *)0);
|
||||
|
||||
/* Start up the mem_allocator and mem_releaser threads */
|
||||
for(i = 0; i < num_workers; ++i) {
|
||||
ids[i] = i;
|
||||
if (verbose_flag) printf("Starting mem_releaser %i ...\n", i);
|
||||
if (pthread_create(&thread_ids[i * 2], NULL, mem_releaser, (void *)&ids[i])) {
|
||||
perror("pthread_create mem_releaser");
|
||||
exit(errno);
|
||||
}
|
||||
|
||||
if (verbose_flag) printf("Starting mem_allocator %i ...\n", i);
|
||||
if (pthread_create(&thread_ids[i * 2 + 1], NULL, mem_allocator, (void *)&ids[i])) {
|
||||
perror("pthread_create mem_allocator");
|
||||
exit(errno);
|
||||
}
|
||||
}
|
||||
|
||||
if (verbose_flag) printf("Testing for %.2f seconds\n\n", run_time);
|
||||
|
||||
while (1) {
|
||||
usleep(1000);
|
||||
if (elapsed_time(&begin) > run_time) {
|
||||
atomic_store(&done_flag, 1);
|
||||
pthread_cond_broadcast(&empty_cv);
|
||||
pthread_cond_broadcast(&full_cv);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for(i = 0; i < num_workers * 2; ++i)
|
||||
pthread_join (thread_ids[i], &ptr);
|
||||
|
||||
elapse_time = elapsed_time (&begin);
|
||||
|
||||
for(i = 0; i < num_workers; ++i) {
|
||||
if (verbose_flag) {
|
||||
printf("Thread %2i frees %ld blocks in %.2f seconds. %.2f free/sec.\n",
|
||||
i, counters[i].c, elapse_time, ((double)counters[i].c/elapse_time));
|
||||
}
|
||||
}
|
||||
if (verbose_flag) printf("----------------------------------------------------------------\n");
|
||||
for(i = 0; i < num_workers; ++i) total += counters[i].c;
|
||||
if (verbose_flag)
|
||||
printf("Total %ld freed in %.2f seconds. %.2fM free/second\n",
|
||||
total, elapse_time, ((double) total/elapse_time)*1e-6);
|
||||
else {
|
||||
double mfree_per_sec = ((double)total/elapse_time) * 1e-6;
|
||||
double rtime = 100.0 / mfree_per_sec;
|
||||
printf("rtime: %.3f, free/sec: %.3f M\n", rtime, mfree_per_sec);
|
||||
}
|
||||
if (verbose_flag) printf("Program done\n");
|
||||
if (ids!=NULL) xfree(ids);
|
||||
return(0);
|
||||
}
|
||||
|
||||
void usage(char *prog)
|
||||
{
|
||||
printf("%s [-w workers] [-t run_time] [-d] [-v]\n", prog);
|
||||
printf("\t -w number of producer threads (and number of consumer threads), default %d\n", num_workers_default);
|
||||
printf("\t -t run time in seconds, default 20.0 seconds.\n");
|
||||
printf("\t -s size of object to allocate (default %d bytes) (specify -1 to get many different object sizes)\n", DEFAULT_OBJECT_SIZE);
|
||||
printf("\t -d debug mode\n");
|
||||
printf("\t -v verbose mode (-v -v produces more verbose)\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int c;
|
||||
while ((c = getopt(argc, argv, "w:t:ds:v")) != -1) {
|
||||
|
||||
switch (c) {
|
||||
|
||||
case 'w':
|
||||
num_workers = atoi(optarg);
|
||||
break;
|
||||
case 't':
|
||||
run_time = atof(optarg);
|
||||
break;
|
||||
case 'd':
|
||||
debug_flag = 1;
|
||||
break;
|
||||
case 's':
|
||||
object_size = atoi(optarg);
|
||||
break;
|
||||
case 'v':
|
||||
verbose_flag++;
|
||||
break;
|
||||
default:
|
||||
usage(argv[0]);
|
||||
}
|
||||
}
|
||||
|
||||
/* allocate memory for working arrays */
|
||||
thread_ids = (pthread_t *) xmalloc(sizeof(pthread_t) * num_workers * 2);
|
||||
counters = (struct counter *) xmalloc(sizeof(*counters) * num_workers);
|
||||
|
||||
run_memory_free_test();
|
||||
|
||||
while (batches) {
|
||||
struct batch *b = batches;
|
||||
batches = b->next_batch;
|
||||
for (int i = 0 ; i < OBJECTS_PER_BATCH; i++) {
|
||||
xfree(b->objects[i]);
|
||||
}
|
||||
xfree(b);
|
||||
}
|
||||
|
||||
xfree(thread_ids);
|
||||
xfree(counters);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user