a few more fixes to support timing and to improve message queues.
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1012 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
2
C/agc.c
2
C/agc.c
@@ -359,7 +359,7 @@ atom_gc(void)
|
||||
int gc_trace = 0;
|
||||
|
||||
|
||||
Int time_start, agc_time;
|
||||
UInt time_start, agc_time;
|
||||
if (Yap_GetValue(AtomGcTrace) != TermNil)
|
||||
gc_trace = 1;
|
||||
agc_calls++;
|
||||
|
12
C/grow.c
12
C/grow.c
@@ -502,7 +502,7 @@ Yap_AdjustRegs(int n)
|
||||
static int
|
||||
static_growheap(long size, int fix_code, struct intermediates *cip)
|
||||
{
|
||||
Int start_growth_time, growth_time;
|
||||
UInt start_growth_time, growth_time;
|
||||
int gc_verbose;
|
||||
UInt hole = 0L;
|
||||
|
||||
@@ -566,7 +566,7 @@ static_growheap(long size, int fix_code, struct intermediates *cip)
|
||||
static int
|
||||
static_growglobal(long size, CELL **ptr)
|
||||
{
|
||||
Int start_growth_time, growth_time;
|
||||
UInt start_growth_time, growth_time;
|
||||
int gc_verbose;
|
||||
|
||||
/* adjust to a multiple of 256) */
|
||||
@@ -804,7 +804,7 @@ execute_growstack(long size, int from_trail)
|
||||
static int
|
||||
growstack(long size)
|
||||
{
|
||||
Int start_growth_time, growth_time;
|
||||
UInt start_growth_time, growth_time;
|
||||
int gc_verbose;
|
||||
|
||||
/* adjust to a multiple of 256) */
|
||||
@@ -909,7 +909,7 @@ AdjustScannerStacks(TokEntry **tksp, VarEntry **vep)
|
||||
int
|
||||
Yap_growstack_in_parser(tr_fr_ptr *old_trp, TokEntry **tksp, VarEntry **vep)
|
||||
{
|
||||
Int start_growth_time, growth_time;
|
||||
UInt start_growth_time, growth_time;
|
||||
int gc_verbose;
|
||||
long size = sizeof(CELL)*(LCL0-(CELL *)Yap_GlobalBase);
|
||||
|
||||
@@ -966,7 +966,7 @@ Yap_growstack_in_parser(tr_fr_ptr *old_trp, TokEntry **tksp, VarEntry **vep)
|
||||
|
||||
static int do_growtrail(long size)
|
||||
{
|
||||
Int start_growth_time = Yap_cputime(), growth_time;
|
||||
UInt start_growth_time = Yap_cputime(), growth_time;
|
||||
int gc_verbose = Yap_is_gc_verbose();
|
||||
|
||||
/* adjust to a multiple of 256) */
|
||||
@@ -1054,7 +1054,7 @@ Yap_growatomtable(void)
|
||||
{
|
||||
AtomHashEntry *ntb;
|
||||
UInt nsize = 4*AtomHashTableSize-1, i;
|
||||
Int start_growth_time = Yap_cputime(), growth_time;
|
||||
UInt start_growth_time = Yap_cputime(), growth_time;
|
||||
int gc_verbose = Yap_is_gc_verbose();
|
||||
|
||||
LOCK(SignalLock);
|
||||
|
@@ -3025,7 +3025,7 @@ do_gc(Int predarity, CELL *current_env, yamop *nextop)
|
||||
Int heap_cells = H-H0;
|
||||
int gc_verbose = is_gc_verbose();
|
||||
tr_fr_ptr old_TR;
|
||||
Int m_time, c_time, time_start, gc_time;
|
||||
UInt m_time, c_time, time_start, gc_time;
|
||||
#if COROUTINING
|
||||
CELL *max = (CELL *)Yap_ReadTimedVar(DelayedVars);
|
||||
#else
|
||||
|
6
C/init.c
6
C/init.c
@@ -783,6 +783,9 @@ InitCodes(void)
|
||||
heap_regs->thread_handle[0].handle = pthread_self();
|
||||
heap_regs->thread_handle[0].handle = pthread_self();
|
||||
pthread_mutex_init(&ThreadHandle[0].tlock, NULL);
|
||||
heap_regs->n_of_threads = 1;
|
||||
heap_regs->n_of_threads_created = 1;
|
||||
heap_regs->threads_total_time = 0;
|
||||
#endif
|
||||
#if defined(YAPOR) || defined(THREADS)
|
||||
INIT_LOCK(heap_regs->bgl);
|
||||
@@ -790,7 +793,6 @@ InitCodes(void)
|
||||
INIT_LOCK(heap_regs->heap_used_lock);
|
||||
INIT_LOCK(heap_regs->heap_top_lock);
|
||||
INIT_LOCK(heap_regs->dead_clauses_lock);
|
||||
heap_regs->n_of_threads = 1;
|
||||
heap_regs->heap_top_owner = -1;
|
||||
{
|
||||
int i;
|
||||
@@ -1168,6 +1170,8 @@ Yap_InitWorkspace(int Heap,
|
||||
#else /* Yap */
|
||||
Yap_InitMemory (Trail, Heap, Stack);
|
||||
#endif /* YAPOR || TABLING */
|
||||
Yap_InitTime ();
|
||||
|
||||
AtomHashTableSize = MaxHash;
|
||||
HashChain = (AtomHashEntry *)Yap_AllocAtomSpace(sizeof(AtomHashEntry) * MaxHash);
|
||||
if (HashChain == NULL) {
|
||||
|
@@ -705,7 +705,7 @@ get_num(char *t)
|
||||
return(TermNil);
|
||||
}
|
||||
|
||||
static Int
|
||||
static UInt
|
||||
runtime(void)
|
||||
{
|
||||
return(Yap_cputime()-Yap_total_gc_time()-Yap_total_stack_shift_time());
|
||||
|
24
C/sysbits.c
24
C/sysbits.c
@@ -233,11 +233,16 @@ bla bla
|
||||
#include <sys/resource.h>
|
||||
#endif
|
||||
|
||||
#if THREADS
|
||||
#define StartOfTimes (*(ThreadHandle[worker_id].start_of_timesp))
|
||||
#define last_time (*(ThreadHandle[worker_id].last_timep))
|
||||
#else
|
||||
/* since the point YAP was started */
|
||||
static struct timeval StartOfTimes;
|
||||
|
||||
/* since last call to runtime */
|
||||
static struct timeval last_time;
|
||||
#endif
|
||||
|
||||
/* store user time in this variable */
|
||||
static void
|
||||
@@ -245,13 +250,17 @@ InitTime (void)
|
||||
{
|
||||
struct rusage rusage;
|
||||
|
||||
#if THREADS
|
||||
ThreadHandle[worker_id].start_of_timesp = (struct timeval *)malloc(sizeof(struct timeval));
|
||||
ThreadHandle[worker_id].last_timep = (struct timeval *)malloc(sizeof(struct timeval));
|
||||
#endif
|
||||
getrusage(RUSAGE_SELF, &rusage);
|
||||
last_time.tv_sec = StartOfTimes.tv_sec = rusage.ru_utime.tv_sec;
|
||||
last_time.tv_usec = StartOfTimes.tv_usec = rusage.ru_utime.tv_usec;
|
||||
}
|
||||
|
||||
|
||||
Int
|
||||
UInt
|
||||
Yap_cputime (void)
|
||||
{
|
||||
struct rusage rusage;
|
||||
@@ -324,7 +333,7 @@ InitTime (void)
|
||||
}
|
||||
}
|
||||
|
||||
Int
|
||||
UInt
|
||||
Yap_cputime (void)
|
||||
{
|
||||
HANDLE hProcess = GetCurrentProcess();
|
||||
@@ -434,7 +443,7 @@ InitTime (void)
|
||||
last_time = StartOfTimes = t.tms_utime;
|
||||
}
|
||||
|
||||
Int
|
||||
UInt
|
||||
Yap_cputime (void)
|
||||
{
|
||||
struct tms t;
|
||||
@@ -475,7 +484,7 @@ InitTime (void)
|
||||
}
|
||||
|
||||
|
||||
Int
|
||||
UInt
|
||||
Yap_cputime (void)
|
||||
{
|
||||
struct timeval tp;
|
||||
@@ -2089,13 +2098,18 @@ Yap_InitSysbits (void)
|
||||
}
|
||||
#endif
|
||||
InitPageSize();
|
||||
InitTime ();
|
||||
InitWTime ();
|
||||
InitRandom ();
|
||||
/* let the caller control signals as it sees fit */
|
||||
InitSignals ();
|
||||
}
|
||||
|
||||
void
|
||||
Yap_InitTime(void)
|
||||
{
|
||||
InitTime();
|
||||
}
|
||||
|
||||
void
|
||||
Yap_ReInitWallTime (void)
|
||||
{
|
||||
|
63
C/threads.c
63
C/threads.c
@@ -76,6 +76,10 @@ thread_die(int wid, int always_die)
|
||||
Prop p0;
|
||||
|
||||
LOCK(ThreadHandlesLock);
|
||||
if (!always_die) {
|
||||
/* called by thread itself */
|
||||
ThreadsTotalTime += Yap_cputime();
|
||||
}
|
||||
if (ThreadHandle[wid].tdetach == MkAtomTerm(AtomTrue) ||
|
||||
always_die) {
|
||||
p0 = AbsPredProp(heap_regs->thread_handle[wid].local_preds);
|
||||
@@ -88,8 +92,11 @@ thread_die(int wid, int always_die)
|
||||
}
|
||||
Yap_KillStacks(wid);
|
||||
heap_regs->wl[wid].active_signals = 0L;
|
||||
heap_regs->wl[wid].active_signals = 0L;
|
||||
free(heap_regs->wl[wid].scratchpad.ptr);
|
||||
free(ThreadHandle[wid].default_yaam_regs);
|
||||
free(ThreadHandle[wid].start_of_timesp);
|
||||
free(ThreadHandle[wid].last_timep);
|
||||
ThreadHandle[wid].in_use = FALSE;
|
||||
pthread_mutex_destroy(&(ThreadHandle[wid].tlock));
|
||||
}
|
||||
@@ -109,8 +116,11 @@ thread_run(void *widp)
|
||||
ThreadHandle[myworker_id].default_yaam_regs = standard_regs;
|
||||
pthread_setspecific(Yap_yaamregs_key, (void *)standard_regs);
|
||||
worker_id = myworker_id;
|
||||
/* I exist */
|
||||
NOfThreadsCreated++;
|
||||
Yap_InitExStacks(ThreadHandle[myworker_id].ssize, ThreadHandle[myworker_id].tsize);
|
||||
CurrentModule = ThreadHandle[myworker_id].cmod;
|
||||
Yap_InitTime();
|
||||
Yap_InitYaamRegs();
|
||||
{
|
||||
Yap_ReleasePreAllocCodeSpace(Yap_PreAllocCodeSpace());
|
||||
@@ -176,10 +186,8 @@ p_thread_join(void)
|
||||
UNLOCK(ThreadHandlesLock);
|
||||
if (pthread_join(ThreadHandle[tid].handle, NULL) < 0) {
|
||||
/* ERROR */
|
||||
fprintf(stderr, "join error %d %d\n", tid, errno);
|
||||
return FALSE;
|
||||
}
|
||||
fprintf(stderr, "join %d\n", tid);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -406,6 +414,31 @@ p_no_threads(void)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static Int
|
||||
p_nof_threads(void)
|
||||
{ /* '$nof_threads'(+P) */
|
||||
int i = 0, wid;
|
||||
LOCK(ThreadHandlesLock);
|
||||
for (wid = 0; wid < MAX_WORKERS; wid++) {
|
||||
if (ThreadHandle[wid].in_use)
|
||||
i++;
|
||||
}
|
||||
UNLOCK(ThreadHandlesLock);
|
||||
return Yap_unify(ARG1,MkIntegerTerm(i));
|
||||
}
|
||||
|
||||
static Int
|
||||
p_nof_threads_created(void)
|
||||
{ /* '$nof_threads'(+P) */
|
||||
return Yap_unify(ARG1,MkIntTerm(NOfThreadsCreated));
|
||||
}
|
||||
|
||||
static Int
|
||||
p_thread_runtime(void)
|
||||
{ /* '$thread_runtime'(+P) */
|
||||
return Yap_unify(ARG1,MkIntegerTerm(ThreadsTotalTime));
|
||||
}
|
||||
|
||||
void Yap_InitThreadPreds(void)
|
||||
{
|
||||
Yap_InitCPred("$no_threads", 0, p_no_threads, 0);
|
||||
@@ -430,6 +463,9 @@ void Yap_InitThreadPreds(void)
|
||||
Yap_InitCPred("$cond_broadcast", 1, p_cond_broadcast, SafePredFlag);
|
||||
Yap_InitCPred("$cond_wait", 2, p_cond_wait, SafePredFlag);
|
||||
Yap_InitCPred("$signal_thread", 1, p_thread_signal, SafePredFlag);
|
||||
Yap_InitCPred("$nof_threads", 1, p_nof_threads, SafePredFlag);
|
||||
Yap_InitCPred("$nof_threads_created", 1, p_nof_threads_created, SafePredFlag);
|
||||
Yap_InitCPred("$thread_runtime", 1, p_thread_runtime, SafePredFlag);
|
||||
}
|
||||
|
||||
#else
|
||||
@@ -440,9 +476,30 @@ p_no_threads(void)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static Int
|
||||
p_nof_threads(void)
|
||||
{ /* '$nof_threads'(+P) */
|
||||
return Yap_unify(ARG1,MkIntTerm(1));
|
||||
}
|
||||
|
||||
static Int
|
||||
p_nof_threads_created(void)
|
||||
{ /* '$nof_threads'(+P) */
|
||||
return Yap_unify(ARG1,MkIntTerm(1));
|
||||
}
|
||||
|
||||
static Int
|
||||
p_thread_runtime(void)
|
||||
{ /* '$thread_runtime'(+P) */
|
||||
return Yap_unify(ARG1,MkIntTerm(0));
|
||||
}
|
||||
|
||||
void Yap_InitThreadPreds(void)
|
||||
{
|
||||
Yap_InitCPred("$no_threads", 0, p_no_threads, 0);
|
||||
Yap_InitCPred("$no_threads", 0, p_no_threads, SafePredFlag);
|
||||
Yap_InitCPred("$nof_threads", 1, p_nof_threads, SafePredFlag);
|
||||
Yap_InitCPred("$nof_threads_created", 1, p_nof_threads_created, SafePredFlag);
|
||||
Yap_InitCPred("$thread_runtime", 1, p_thread_runtime, SafePredFlag);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user