fix memory allocation (MMAP) for shared LOCAL and GLOBAL in ENV_COPY

This commit is contained in:
vsc 2010-10-15 02:06:37 +01:00
parent 824ff4094c
commit 312d82816e
6 changed files with 29 additions and 10 deletions

View File

@ -2504,7 +2504,7 @@ YAP_Init(YAP_init_args *yap_init)
Yap_init_local();
#ifdef YAPOR
if (worker_id != 0) {
#if SBA
#if SBA||ENV_COPY
/*
In the SBA we cannot just happily inherit registers
from the other workers

View File

@ -1205,9 +1205,15 @@ Yap_CloseScratchPad(void)
#define MAX_INITS 1
#endif
#if defined(YAPOR) && !defined(THREADS)
struct worker_shared *Yap_global;
#else
struct worker_shared Yap_Global;
#endif
#if defined(YAPOR) || defined(THREADS)
#if defined(YAPOR) && !defined(THREADS)
struct worker_local *Yap_WLocal;
#elif defined(YAPOR) || defined(THREADS)
struct worker_local Yap_WLocal[MAX_AGENTS];
#else
struct worker_local Yap_WLocal;
@ -1259,7 +1265,6 @@ Yap_InitWorkspace(UInt Heap, UInt Stack, UInt Trail, UInt Atts, UInt max_table_s
int i;
/* initialise system stuff */
#if PUSH_REGS
#ifdef THREADS
pthread_key_create(&Yap_yaamregs_key, NULL);

View File

@ -361,7 +361,7 @@ typedef CELL Term;
typedef pthread_mutex_t lockvar;
typedef pthread_rwlock_t rwlock_t;
#elif defined(i386)
#elif defined(i386)|| defined(__x86_64__)
typedef volatile int lockvar;
#include <locks_x86.h>
#elif defined(sparc) || defined(__sparc)

View File

@ -171,11 +171,19 @@ typedef struct various_codes {
#include "hglobals.h"
#if defined(YAPOR) && !defined(THREADS)
extern struct worker_shared *Yap_global;
#else
extern struct worker_shared Yap_Global;
#define Yap_global (&Yap_Global)
#endif
#if defined(YAPOR) || defined(THREADS)
#if defined(THREADS)
extern struct worker_local Yap_WLocal[MAX_AGENTS];
#else
extern struct worker_local *Yap_WLocal;
#endif
#define WL (Yap_WLocal+worker_id)
#define FOREIGN_WL(wid) (Yap_WLocal+(wid))
#else

View File

@ -243,14 +243,12 @@ void make_root_frames(void) {
#endif /* TABLING */
}
#ifdef YAPOR
void init_workers(void) {
int proc;
#ifdef THREADS
return;
#endif
NOfThreads = number_workers;
#ifdef ACOW
if (number_workers > 1) {
int son;

View File

@ -39,6 +39,7 @@ int fd_mapfile;
int shm_mapid[MAX_WORKERS + 1];
#endif /* MEMORY_MAPPING_SCHEME */
static Int extra_area = 0;
/********************************
@ -98,6 +99,11 @@ void map_memory(long HeapArea, long GlobalLocalArea, long TrailAuxArea, int n_wo
TrailAuxArea = ADJUST_SIZE(TrailAuxArea);
/* we'll need this later */
#if defined(YAPOR) && !defined(THREADS)
Yap_global = (struct worker_shared *)( mmap_addr - sizeof(struct worker_shared));
Yap_WLocal = (struct worker_local *)( mmap_addr - (sizeof(struct worker_shared)+MAX_WORKERS*sizeof(struct worker_local)));
extra_area = ADJUST_SIZE_TO_PAGE(sizeof(struct worker_shared)+MAX_WORKERS*sizeof(struct worker_local));
#endif
Yap_HeapBase = (ADDR)mmap_addr;
Yap_GlobalBase = mmap_addr + HeapArea;
@ -113,14 +119,16 @@ void map_memory(long HeapArea, long GlobalLocalArea, long TrailAuxArea, int n_wo
WorkerArea = ADJUST_SIZE_TO_PAGE(GlobalLocalArea + TrailAuxArea);
TotalArea = HeapArea + WorkerArea * n_workers;
#endif /* YAPOR_MODEL */
/* mmap heap area */
#ifdef MMAP_MEMORY_MAPPING_SCHEME
/* map total area in a single go */
open_mapfile(TotalArea);
if ((mmap_addr = mmap((void *) MMAP_ADDR, (size_t) TotalArea, PROT_READ|PROT_WRITE,
open_mapfile(TotalArea+extra_area);
if ((mmap_addr = mmap((void *) MMAP_ADDR-extra_area, (size_t) (TotalArea+extra_area), PROT_READ|PROT_WRITE,
MAP_SHARED|MAP_FIXED, fd_mapfile, 0)) == (void *) -1)
Yap_Error(FATAL_ERROR, TermNil, "mmap error (map_memory)");
#if defined(YAPOR) && !defined(THREADS)
mmap_addr += extra_area;
#endif
#else /* SHM_MEMORY_MAPPING_SCHEME */
/* Most systems are limited regarding what we can allocate */
#ifdef ACOW
@ -267,7 +275,7 @@ void remap_memory(void) {
for (i = 0; i < number_workers; i++) {
worker_area(i) = remap_addr + ((number_workers + i - worker_id) % number_workers) * WorkerArea;
if (mmap(worker_area(i), (size_t)WorkerArea, PROT_READ|PROT_WRITE,
MAP_SHARED|MAP_FIXED, fd_mapfile, remap_offset + i * WorkerArea) == (void *) -1)
MAP_SHARED|MAP_FIXED, fd_mapfile, remap_offset + i * WorkerArea + extra_area) == (void *) -1)
Yap_Error(FATAL_ERROR, TermNil, "mmap error (remap_memory)");
}
#endif /* MEMORY_MAPPING_SCHEME */