Skip to content

Commit

Permalink
Limit the additional locking from PRs 1052,1299 to non-OpenMP multith…
Browse files Browse the repository at this point in the history
…reading
  • Loading branch information
martin-frbg authored Feb 21, 2018
1 parent e3a80e6 commit 7646974
Showing 1 changed file with 50 additions and 16 deletions.
66 changes: 50 additions & 16 deletions driver/others/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -455,11 +455,15 @@ static void *alloc_mmap(void *address){
}

if (map_address != (void *)-1) {
#if defined(SMP) && !defined(USE_OPENMP)
LOCK_COMMAND(&alloc_lock);
#endif
release_info[release_pos].address = map_address;
release_info[release_pos].func = alloc_mmap_free;
release_pos ++;
#if defined(SMP) && !defined(USE_OPENMP)
UNLOCK_COMMAND(&alloc_lock);
#endif
}

#ifdef OS_LINUX
Expand Down Expand Up @@ -601,14 +605,18 @@ static void *alloc_mmap(void *address){
#if defined(OS_LINUX) && !defined(NO_WARMUP)
}
#endif
LOCK_COMMAND(&alloc_lock);

if (map_address != (void *)-1) {
#if defined(SMP) && !defined(USE_OPENMP)
LOCK_COMMAND(&alloc_lock);
#endif
release_info[release_pos].address = map_address;
release_info[release_pos].func = alloc_mmap_free;
release_pos ++;
#if defined(SMP) && !defined(USE_OPENMP)
UNLOCK_COMMAND(&alloc_lock);
#endif
}
UNLOCK_COMMAND(&alloc_lock);

return map_address;
}
Expand Down Expand Up @@ -1007,6 +1015,11 @@ void *blas_memory_alloc(int procpos){
NULL,
};
void *(**func)(void *address);

#if defined(USE_OPENMP)
if (!memory_initialized) {
#endif

LOCK_COMMAND(&alloc_lock);

if (!memory_initialized) {
Expand Down Expand Up @@ -1042,6 +1055,9 @@ void *blas_memory_alloc(int procpos){

}
UNLOCK_COMMAND(&alloc_lock);
#if defined(USE_OPENMP)
}
#endif

#ifdef DEBUG
printf("Alloc Start ...\n");
Expand All @@ -1056,13 +1072,17 @@ void *blas_memory_alloc(int procpos){

do {
if (!memory[position].used && (memory[position].pos == mypos)) {
#if defined(SMP) && !defined(USE_OPENMP)
LOCK_COMMAND(&alloc_lock);
/* blas_lock(&memory[position].lock);*/

#else
blas_lock(&memory[position].lock);
#endif
if (!memory[position].used) goto allocation;

#if defined(SMP) && !defined(USE_OPENMP)
UNLOCK_COMMAND(&alloc_lock);
/* blas_unlock(&memory[position].lock);*/
#else
blas_unlock(&memory[position].lock);
#endif
}

position ++;
Expand All @@ -1075,15 +1095,19 @@ void *blas_memory_alloc(int procpos){
position = 0;

do {
/* if (!memory[position].used) { */
#if defined(SMP) && !defined(USE_OPENMP)
LOCK_COMMAND(&alloc_lock);
/* blas_lock(&memory[position].lock);*/

#else
if (!memory[position].used) {
blas_lock(&memory[position].lock);
#endif
if (!memory[position].used) goto allocation;
#if defined(SMP) && !defined(USE_OPENMP)
UNLOCK_COMMAND(&alloc_lock);
/* blas_unlock(&memory[position].lock);*/
/* } */
#else
blas_unlock(&memory[position].lock);
}
#endif

position ++;

Expand All @@ -1098,9 +1122,11 @@ void *blas_memory_alloc(int procpos){
#endif

memory[position].used = 1;

#if defined(SMP) && !defined(USE_OPENMP)
UNLOCK_COMMAND(&alloc_lock);
/* blas_unlock(&memory[position].lock);*/
#else
blas_unlock(&memory[position].lock);
#endif

if (!memory[position].addr) {
do {
Expand Down Expand Up @@ -1146,9 +1172,13 @@ void *blas_memory_alloc(int procpos){

} while ((BLASLONG)map_address == -1);

#if defined(SMP) && !defined(USE_OPENMP)
LOCK_COMMAND(&alloc_lock);
#endif
memory[position].addr = map_address;
#if defined(SMP) && !defined(USE_OPENMP)
UNLOCK_COMMAND(&alloc_lock);
#endif

#ifdef DEBUG
printf(" Mapping Succeeded. %p(%d)\n", (void *)memory[position].addr, position);
Expand Down Expand Up @@ -1202,8 +1232,9 @@ void blas_memory_free(void *free_area){
#endif

position = 0;
#if defined(SMP) && !defined(USE_OPENMP)
LOCK_COMMAND(&alloc_lock);

#endif
while ((position < NUM_BUFFERS) && (memory[position].addr != free_area))
position++;

Expand All @@ -1217,7 +1248,9 @@ void blas_memory_free(void *free_area){
WMB;

memory[position].used = 0;
#if defined(SMP) && !defined(USE_OPENMP)
UNLOCK_COMMAND(&alloc_lock);
#endif

#ifdef DEBUG
printf("Unmap Succeeded.\n\n");
Expand All @@ -1232,8 +1265,9 @@ void blas_memory_free(void *free_area){
for (position = 0; position < NUM_BUFFERS; position++)
printf("%4ld %p : %d\n", position, memory[position].addr, memory[position].used);
#endif
#if defined(SMP) && !defined(USE_OPENMP)
UNLOCK_COMMAND(&alloc_lock);

#endif
return;
}

Expand Down

0 comments on commit 7646974

Please sign in to comment.