Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 40 additions & 8 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,7 +1015,10 @@ void *blas_memory_alloc(int procpos){
NULL,
};
void *(**func)(void *address);

#if defined(SMP) && !defined(USE_OPENMP)
LOCK_COMMAND(&alloc_lock);
#endif

if (!memory_initialized) {

Expand Down Expand Up @@ -1041,7 +1052,9 @@ void *blas_memory_alloc(int procpos){
memory_initialized = 1;

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

#ifdef DEBUG
printf("Alloc Start ...\n");
Expand All @@ -1056,12 +1069,15 @@ 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);
#endif
/* blas_lock(&memory[position].lock);*/

if (!memory[position].used) goto allocation;

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

Expand All @@ -1076,12 +1092,15 @@ void *blas_memory_alloc(int procpos){

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

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

Expand All @@ -1098,8 +1117,10 @@ void *blas_memory_alloc(int procpos){
#endif

memory[position].used = 1;

#if defined(SMP) && !defined(USE_OPENMP)
UNLOCK_COMMAND(&alloc_lock);
#endif

/* blas_unlock(&memory[position].lock);*/

if (!memory[position].addr) {
Expand Down Expand Up @@ -1146,9 +1167,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 All @@ -1165,7 +1190,9 @@ void *blas_memory_alloc(int procpos){

if (memory_initialized == 1) {

#if defined(SMP) && !defined(USE_OPENMP)
LOCK_COMMAND(&alloc_lock);
#endif

if (memory_initialized == 1) {

Expand All @@ -1174,8 +1201,9 @@ void *blas_memory_alloc(int procpos){
memory_initialized = 2;
}

#if defined(SMP) && !defined(USE_OPENMP)
UNLOCK_COMMAND(&alloc_lock);

#endif
}
#endif

Expand All @@ -1202,8 +1230,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 +1246,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 +1263,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