Merge pull request #1354 from martin-frbg/shmem
Try to handle shmget or shmat failing
This commit is contained in:
commit
4271b2b158
|
@ -631,7 +631,7 @@ static inline int is_dead(int id) {
|
||||||
return shmctl(id, IPC_STAT, &ds);
|
return shmctl(id, IPC_STAT, &ds);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void open_shmem(void) {
|
static int open_shmem(void) {
|
||||||
|
|
||||||
int try = 0;
|
int try = 0;
|
||||||
|
|
||||||
|
@ -657,30 +657,42 @@ static void open_shmem(void) {
|
||||||
} while ((try < 10) && (shmid == -1));
|
} while ((try < 10) && (shmid == -1));
|
||||||
|
|
||||||
if (shmid == -1) {
|
if (shmid == -1) {
|
||||||
fprintf(stderr, "GotoBLAS : Can't open shared memory. Terminated.\n");
|
perror ("Obtaining shared memory segment failed in open_shmem");
|
||||||
exit(1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shmid != -1) {
|
if (shmid != -1) {
|
||||||
if ( (common = shmat(shmid, NULL, 0)) == (void*)-1) perror ("Attaching shared memory segment");
|
if ( (common = shmat(shmid, NULL, 0)) == (void*)-1) {
|
||||||
|
perror ("Attaching shared memory segment failed in open_shmem");
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fprintf(stderr, "Shared Memory id = %x Address = %p\n", shmid, common);
|
fprintf(stderr, "Shared Memory id = %x Address = %p\n", shmid, common);
|
||||||
#endif
|
#endif
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void create_pshmem(void) {
|
static int create_pshmem(void) {
|
||||||
|
|
||||||
pshmid = shmget(IPC_PRIVATE, 4096, IPC_CREAT | 0666);
|
pshmid = shmget(IPC_PRIVATE, 4096, IPC_CREAT | 0666);
|
||||||
|
|
||||||
paddr = shmat(pshmid, NULL, 0);
|
if (pshmid == -1) {
|
||||||
|
perror ("Obtaining shared memory segment failed in create_pshmem");
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
|
||||||
shmctl(pshmid, IPC_RMID, 0);
|
if ( (paddr = shmat(pshmid, NULL, 0)) == (void*)-1) {
|
||||||
|
perror ("Attaching shared memory segment failed in create_pshmem");
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shmctl(pshmid, IPC_RMID, 0) == -1) return (1);
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fprintf(stderr, "Private Shared Memory id = %x Address = %p\n", pshmid, paddr);
|
fprintf(stderr, "Private Shared Memory id = %x Address = %p\n", pshmid, paddr);
|
||||||
#endif
|
#endif
|
||||||
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void local_cpu_map(void) {
|
static void local_cpu_map(void) {
|
||||||
|
@ -808,9 +820,15 @@ void gotoblas_affinity_init(void) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
create_pshmem();
|
if (create_pshmem() != 0) {
|
||||||
|
disable_mapping = 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
open_shmem();
|
if (open_shmem() != 0) {
|
||||||
|
disable_mapping = 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
while ((common -> lock) && (common -> magic != SH_MAGIC)) {
|
while ((common -> lock) && (common -> magic != SH_MAGIC)) {
|
||||||
if (is_dead(common -> shmid)) {
|
if (is_dead(common -> shmid)) {
|
||||||
|
@ -818,7 +836,7 @@ void gotoblas_affinity_init(void) {
|
||||||
common -> shmid = 0;
|
common -> shmid = 0;
|
||||||
common -> magic = 0;
|
common -> magic = 0;
|
||||||
} else {
|
} else {
|
||||||
sched_yield();
|
YIELDING;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue