Skip to content

Commit

Permalink
- Improved mmc_alloc_bytes (still no GC, but does allocation in 512MB…
Browse files Browse the repository at this point in the history
… chunks instead of many small calls)

  - This is a big performance improvement for bootstrapping:
    Before: == Total: 20 out of 1365 failed, 32.05 minutes (single thread)
    After:  == Total: 17 out of 1365 failed, 27.88 minutes (single thread)


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@7612 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Jan 1, 2011
1 parent 3dbe674 commit f38d290
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
25 changes: 25 additions & 0 deletions c_runtime/meta_modelica.c
Expand Up @@ -34,6 +34,31 @@

jmp_buf *mmc_jumper;

void *mmc_alloc_bytes(unsigned nbytes)
{
static char *mmc_cur_malloc_buf = NULL;
static long mmc_cur_malloc_buf_ix=0;
// Until we have GC, we simply allocate in 256MB chunks...
const long mmc_cur_malloc_buf_sz=256*1024*1024; // 256MB chunks
void *p;
// fprintf(stderr, "1 mmc_alloc_bytes(%ld): %ld,%ld\n", nbytes, mmc_cur_malloc_buf, mmc_cur_malloc_buf_ix);
if (mmc_cur_malloc_buf == NULL || nbytes>(mmc_cur_malloc_buf_sz-mmc_cur_malloc_buf_ix)) {
if ( (mmc_cur_malloc_buf = malloc(mmc_cur_malloc_buf_sz)) == 0 ) {
fprintf(stderr, "malloc(%u) failed: %s\n", nbytes, strerror(errno));
assert(p != 0);
}
mmc_cur_malloc_buf_ix = 0;
assert(nbytes <= mmc_cur_malloc_buf_sz);
}
p = mmc_cur_malloc_buf + mmc_cur_malloc_buf_ix;

// Force 16-byte alignment, like malloc... TODO: Check if this is needed :)
mmc_cur_malloc_buf_ix += nbytes; // + ((nbytes%16) ? 16-(nbytes%16): 0);

// fprintf(stderr, "2 mmc_alloc_bytes(%ld): %ld,%ld => %ld\n", nbytes, mmc_cur_malloc_buf, mmc_cur_malloc_buf_ix, p);
return p;
}

union mmc_double_as_words {
double d;
mmc_uint_t data[MMC_SIZE_DBL/MMC_SIZE_INT];
Expand Down
10 changes: 1 addition & 9 deletions c_runtime/meta_modelica.h
Expand Up @@ -132,15 +132,7 @@ struct mmc_string {
char data[1]; /* `bytes' elements + terminating '\0' */
};

static void *mmc_alloc_bytes(unsigned nbytes)
{
void *p;
if( (p = malloc(nbytes)) == 0 ) {
fprintf(stderr, "malloc(%u) failed: %s\n", nbytes, strerror(errno));
assert(p != 0);
}
return p;
}
void *mmc_alloc_bytes(unsigned nbytes);

static void *mmc_alloc_words(unsigned nwords)
{
Expand Down

0 comments on commit f38d290

Please sign in to comment.