str MACROprocessor(Client cntxt, MalBlkPtr mb, Symbol t) { InstrPtr q; int i, cnt = 0, last = -1; str msg = MAL_SUCCEED; (void) cntxt; if (t == NULL) return msg; msg = MACROvalidate(t->def); if (msg) return msg; for (i = 0; i < mb->stop; i++) { q = getInstrPtr(mb, i); if (getFunctionId(q) && idcmp(getFunctionId(q), t->name) == 0 && getSignature(t)->token == FUNCTIONsymbol) { if (i == last) throw(MAL, "optimizer.MACROoptimizer", MACRO_DUPLICATE); last = i; i = inlineMALblock(mb, i, t->def); cnt++; if (cnt > MAXEXPANSION) throw(MAL, "optimizer.MACROoptimizer", MACRO_TOO_DEEP); } } return msg; }
/* * _compat_modut - modify a utmp entry. * * args: utmp - point to utmp structure to be created */ struct utmp * _compat_modut(struct utmp *utp) { int i; /* scratch variable */ struct utmp utmp; /* holding area */ struct utmp *ucp = &utmp; /* and a pointer to it */ struct utmp *up; /* "current" utmp entry being examined */ struct futmp *fup; for (i = 0; i < IDLEN; ++i) if ((unsigned char)utp->ut_id[i] == SC_WILDC) return (0); /* copy the supplied utmp structure someplace safe */ utmp = *utp; _compat_setutent(); while (fup = getutent_frec()) { if (idcmp(ucp->ut_id, fup->ut_id)) continue; break; } up = _compat_pututline(ucp); if (up) _compat_updwtmp(WTMP_FILE, up); _compat_endutent(); return (up); }
/* * The routine findSymbolInModule starts at a MAL scope level and searches * an element amongst the peers. * * In principal, external variables are subject to synchronization actions * to avoid concurrency conflicts. This also implies, that any parallel * block introduces a temporary scope. * * The variation on this routine is to dump the definition of * all matching definitions. */ Symbol findSymbolInModule(Module v, str fcn) { Symbol s; if (v == NULL || fcn == NULL) return NULL; #ifdef _DEBUG_MODULE_ fprintf(stderr,"#find symbol %s in %s\n", fcn, v->name); #endif s = v->space[(int)(*fcn)]; while (s != NULL) { if (idcmp(s->name,fcn)==0) return s; s = s->skip; } return NULL; }
/* * After filling in a structure it is added to the multi-level symbol * table. We keep a skip list of similarly named function symbols. * This speeds up searching provided the modules adhere to the * structure and group the functions as well. */ void insertSymbol(Module scope, Symbol prg){ InstrPtr sig; int t; Module c; assert(scope); sig = getSignature(prg); #ifdef _DEBUG_MODULE_ fprintf(stderr,"#insertSymbol: %s.%s in %s ", getModuleId(sig), getFunctionId(sig), scope->name); #endif if(getModuleId(sig) && getModuleId(sig)!= scope->name){ /* move the definition to the proper place */ /* default scope is the last resort */ c= findModule(scope,getModuleId(sig)); if ( c ) scope = c; #ifdef _DEBUG_MODULE_ fprintf(stderr," found alternative module %s ", scope->name); #endif } t = getSymbolIndex(getFunctionId(sig)); if( scope->space == NULL) { scope->space = (Symbol *) GDKzalloc(MAXSCOPE * sizeof(Symbol)); if (scope->space == NULL) return; } assert(scope->space); if (scope->space[t] == prg){ /* already known, last inserted */ #ifdef _DEBUG_MODULE_ fprintf(stderr," unexpected double insert "); #endif } else { prg->peer= scope->space[t]; scope->space[t] = prg; if( prg->peer && idcmp(prg->name,prg->peer->name) == 0) prg->skip = prg->peer->skip; else prg->skip = prg->peer; } assert(prg != prg->peer); #ifdef _DEBUG_MODULE_ fprintf(stderr,"\n"); #endif }
void MSinitClientPrg(Client cntxt, str mod, str nme) { InstrPtr p; MalBlkPtr mb; if (cntxt->curprg && idcmp(nme, cntxt->curprg->name) == 0) { MSresetClientPrg(cntxt); return; } cntxt->curprg = newFunction(putName("user", 4), putName(nme, strlen(nme)), FUNCTIONsymbol); mb = cntxt->curprg->def; p = getSignature(cntxt->curprg); if (mod) setModuleId(p, mod); else setModuleScope(p, cntxt->nspace); setVarType(mb, findVariable(mb, nme), TYPE_void); insertSymbol(cntxt->nspace, cntxt->curprg); cntxt->glb = 0; assert(cntxt->curprg->def != NULL); }
int cmp_status(CNode *a, CNode *b) { if (a->m_validInfo & VF_DENY) { if (a->m_deny || g_denyListMgr->find(a->m_id) >= 0) return 1; } if (b->m_validInfo & VF_DENY) { if (b->m_deny || g_denyListMgr->find(b->m_id) >= 0) return -1; } int scorea = 0; int scoreb = 0; if (a->m_state == State_Idle) scorea += 00000; else if (a->m_state == State_Watch_Playable) scorea += 5000; else if (a->m_state == State_Busy_Casting) scorea += 15000; else if (a->m_state == State_Busy_Casting_NG) scorea += 15000; else if (a->m_state == State_Busy) scorea += 20000; else if (a->m_state == State_Watch) scorea += 25000; else if (a->m_state == State_NoResponse) scorea += 30000; else if (a->m_state == State_Mismatch) scorea += 40000; else if (a->m_state == State_VersionError) scorea += 40000; else if (a->m_state == State_NotReady) scorea += 10000; else if (a->m_state == State_PingOver) scorea += 8000; if (b->m_state == State_Idle) scoreb += 00000; else if (b->m_state == State_Watch_Playable) scoreb += 5000; else if (b->m_state == State_Busy_Casting) scoreb += 15000; else if (b->m_state == State_Busy_Casting_NG) scoreb += 15000; else if (b->m_state == State_Busy) scoreb += 20000; else if (b->m_state == State_Watch) scoreb += 25000; else if (b->m_state == State_NoResponse) scoreb += 30000; else if (b->m_state == State_Mismatch) scoreb += 40000; else if (b->m_state == State_VersionError) scoreb += 40000; else if (b->m_state == State_NotReady) scoreb += 10000; else if (b->m_state == State_PingOver) scoreb += 8000; /* rank差を影響 */ if (idcmp((BYTE*)a->m_id, INVALID_MID) == false) { scorea += abs(g_setting.rank - a->m_rank) * 10; } else scorea += 10; if (idcmp((BYTE*)b->m_id, INVALID_MID) == false) { scoreb += abs(g_setting.rank - b->m_rank) * 10; } else scoreb += 10; if (a->isNetSpeedGood() == false) { if (a->m_ignoreSlow || g_setting.ignoreSlow) scorea += 100; else scorea += 100; } if (b->isNetSpeedGood() == false) { if (b->m_ignoreSlow || g_setting.ignoreSlow) scoreb += 100; else scoreb += 100; } return (scorea - scoreb); }
int malAtomProperty(MalBlkPtr mb, InstrPtr pci) { str name; int tpe; (void)mb; /* fool compilers */ assert(pci != 0); name = getFunctionId(pci); tpe = getTypeIndex(getModuleId(pci), (int)strlen(getModuleId(pci)), TYPE_any); if (tpe < 0 || tpe >= GDKatomcnt || tpe >= MAXATOMS) return 0; assert(pci->fcn != NULL); switch (name[0]) { case 'd': if (idcmp("del", name) == 0 && pci->argc == 1) { BATatoms[tpe].atomDel = (void (*)(Heap *, var_t *))pci->fcn; setAtomName(pci); return 1; } break; case 'c': if (idcmp("cmp", name) == 0 && pci->argc == 1) { BATatoms[tpe].atomCmp = (int (*)(const void *, const void *))pci->fcn; BATatoms[tpe].linear = 1; setAtomName(pci); return 1; } break; case 'f': if (idcmp("fromstr", name) == 0 && pci->argc == 1) { BATatoms[tpe].atomFromStr = (int (*)(const char *, int *, ptr *))pci->fcn; setAtomName(pci); return 1; } if (idcmp("fix", name) == 0 && pci->argc == 1) { BATatoms[tpe].atomFix = (int (*)(const void *))pci->fcn; setAtomName(pci); return 1; } break; case 'h': if (idcmp("heap", name) == 0 && pci->argc == 1) { /* heap function makes an atom varsized */ BATatoms[tpe].size = sizeof(var_t); assert_shift_width(ATOMelmshift(ATOMsize(tpe)), ATOMsize(tpe)); BATatoms[tpe].align = sizeof(var_t); BATatoms[tpe].atomHeap = (void (*)(Heap *, size_t))pci->fcn; setAtomName(pci); return 1; } if (idcmp("hash", name) == 0 && pci->argc == 1) { BATatoms[tpe].atomHash = (BUN (*)(const void *))pci->fcn; setAtomName(pci); return 1; } break; case 'l': if (idcmp("length", name) == 0 && pci->argc == 1) { BATatoms[tpe].atomLen = (int (*)(const void *))pci->fcn; setAtomName(pci); return 1; } break; case 'n': if (idcmp("null", name) == 0 && pci->argc == 1) { ptr atmnull = ((ptr (*)(void))pci->fcn)(); BATatoms[tpe].atomNull = atmnull; setAtomName(pci); return 1; } if (idcmp("nequal", name) == 0 && pci->argc == 1) { BATatoms[tpe].atomCmp = (int (*)(const void *, const void *))pci->fcn; setAtomName(pci); return 1; } break; case 'p': if (idcmp("put", name) == 0 && pci->argc == 1) { BATatoms[tpe].atomPut = (var_t (*)(Heap *, var_t *, const void *))pci->fcn; setAtomName(pci); return 1; } break; case 's': if (idcmp("storage", name) == 0 && pci->argc == 1) { BATatoms[tpe].storage = (*(int (*)(void))pci->fcn)(); setAtomName(pci); return 1; } break; case 't': if (idcmp("tostr", name) == 0 && pci->argc == 1) { BATatoms[tpe].atomToStr = (int (*)(str *, int *, const void *))pci->fcn; setAtomName(pci); return 1; } break; case 'u': if (idcmp("unfix", name) == 0 && pci->argc == 1) { BATatoms[tpe].atomUnfix = (int (*)(const void *))pci->fcn; setAtomName(pci); return 1; } break; case 'r': if (idcmp("read", name) == 0 && pci->argc == 1) { BATatoms[tpe].atomRead = (void *(*)(void *, stream *, size_t))pci->fcn; setAtomName(pci); return 1; } break; case 'w': if (idcmp("write", name) == 0 && pci->argc == 1) { BATatoms[tpe].atomWrite = (gdk_return (*)(const void *, stream *, size_t))pci->fcn; setAtomName(pci); return 1; } break; } return 0; }
int OPTquerylogImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) { int i, limit, slimit; InstrPtr p = 0, *old= mb->stmt, q,r; int argc, io, user,nice,sys,idle,iowait,load, arg, start,finish, name; int xtime=0, rtime = 0, tuples=0; InstrPtr defineQuery = NULL; // query log needed? if ( !QLOGisset() ) return 0; (void) pci; (void) stk; /* to fool compilers */ (void) cntxt; /* gather information */ for (i = 1; i < mb->stop; i++) { p = getInstrPtr(mb,i); if ( getModuleId(p) && idcmp(getModuleId(p), "querylog") == 0 && idcmp(getFunctionId(p),"define")==0){ defineQuery= p; getVarConstant(mb,getArg(p,3)).val.lval = GDKusec()-getVarConstant(mb,getArg(p,3)).val.lval ; } } if ( defineQuery == NULL) /* nothing to do */ return 0; limit= mb->stop; slimit= mb->ssize; if ( newMalBlkStmt(mb, mb->ssize) < 0) return 0; pushInstruction(mb, old[0]); /* run the querylog.define operation */ defineQuery = copyInstruction(defineQuery); setFunctionId(defineQuery, insertRef); getArg(defineQuery,0) = newTmpVariable(mb,TYPE_any); defineQuery->token = ASSIGNsymbol; setModuleId(defineQuery,querylogRef); /* collect the initial statistics */ q = newStmt(mb, "clients", "getUsername"); name= getArg(q,0)= newVariable(mb,GDKstrdup("name"),TYPE_str); defineQuery = pushArgument(mb,defineQuery,name); q = newStmt(mb, "mtime", "current_timestamp"); start= getArg(q,0)= newVariable(mb,GDKstrdup("start"),TYPE_timestamp); defineQuery = pushArgument(mb,defineQuery,start); pushInstruction(mb, defineQuery); q = newStmt1(mb, sqlRef, "argRecord"); for ( argc=1; argc < old[0]->argc; argc++) q = pushArgument(mb, q, getArg(old[0],argc)); arg= getArg(q,0)= newVariable(mb,GDKstrdup("args"),TYPE_str); q = newStmt(mb, "alarm", "usec"); xtime = getArg(q,0)= newVariable(mb,GDKstrdup("xtime"),TYPE_lng); user = newVariable(mb,GDKstrdup("user"),TYPE_lng); nice = newVariable(mb,GDKstrdup("nice"),TYPE_lng); sys = newVariable(mb,GDKstrdup("sys"),TYPE_lng); idle = newVariable(mb,GDKstrdup("idle"),TYPE_lng); iowait = newVariable(mb,GDKstrdup("iowait"),TYPE_lng); q = newStmt(mb, "profiler", "cpustats"); q->retc= q->argc =0; q = pushReturn(mb,q,user); q = pushReturn(mb,q,nice); q = pushReturn(mb,q,sys); q = pushReturn(mb,q,idle); q = pushReturn(mb,q,iowait); q = newAssignment(mb); tuples= getArg(q,0) = newVariable(mb,GDKstrdup("tuples"),TYPE_wrd); (void) pushWrd(mb,q,1); for (i = 1; i < limit; i++) { p = old[i]; if (getModuleId(p)==sqlRef && (idcmp(getFunctionId(p),"exportValue")==0 || idcmp(getFunctionId(p),"exportResult")==0 ) ) { q = newStmt(mb, "alarm", "usec"); r = newStmt1(mb, calcRef, "-"); r = pushArgument(mb, r, getArg(q,0)); r = pushArgument(mb, r, xtime); getArg(r,0)=xtime; q = newStmt(mb, "alarm", "usec"); rtime= getArg(q,0)= newVariable(mb,GDKstrdup("rtime"),TYPE_lng); pushInstruction(mb,p); continue; } if ( getModuleId(p) == sqlRef && idcmp(getFunctionId(p),"resultSet")==0 && isaBatType(getVarType(mb,getArg(p,3)))){ q = newStmt(mb, "aggr", "count"); getArg(q,0) = tuples; (void) pushArgument(mb,q, getArg(p,3)); pushInstruction(mb,p); continue; } if ( p->token== ENDsymbol || p->barrier == RETURNsymbol || p->barrier == YIELDsymbol){ if ( rtime == 0){ q = newStmt(mb, "alarm", "usec"); r = newStmt1(mb, calcRef, "-"); r = pushArgument(mb, r, getArg(q,0)); r = pushArgument(mb, r, xtime); getArg(r,0)=xtime; q = newStmt(mb, "alarm", "usec"); rtime= getArg(q,0)= newVariable(mb,GDKstrdup("rtime"),TYPE_lng); } q = newStmt(mb, "alarm", "usec"); r = newStmt1(mb, calcRef, "-"); r = pushArgument(mb, r, getArg(q,0)); r = pushArgument(mb, r, rtime); getArg(r,0)=rtime; /* * Post execution statistics gathering */ q = newStmt(mb, "mtime", "current_timestamp"); finish= getArg(q,0)= newVariable(mb,GDKstrdup("finish"),TYPE_any); q = newStmt(mb, "profiler", "cpuload"); load = newVariable(mb,GDKstrdup("load"),TYPE_int); getArg(q,0)= load; io = newVariable(mb,GDKstrdup("io"),TYPE_int); q= pushReturn(mb,q,io); q = pushArgument(mb,q,user); q = pushArgument(mb,q,nice); q = pushArgument(mb,q,sys); q = pushArgument(mb,q,idle); q = pushArgument(mb,q,iowait); q = newStmt(mb, querylogRef, "call"); q = pushArgument(mb, q, start); q = pushArgument(mb, q, finish); q = pushArgument(mb, q, arg); q = pushArgument(mb, q, tuples); q = pushArgument(mb, q, xtime); q = pushArgument(mb, q, rtime); q = pushArgument(mb, q, load); q = pushArgument(mb, q, io); pushInstruction(mb,p); continue; } pushInstruction(mb,p); if (p->barrier == YIELDsymbol){ /* the factory yield may return */ q = newStmt(mb, "mtime", "current_timestamp"); start= getArg(q,0)= newVariable(mb,GDKstrdup("start"),TYPE_any); q = newStmt1(mb, sqlRef, "argRecord"); for ( argc=1; argc < old[0]->argc; argc++) q = pushArgument(mb, q, getArg(old[0],argc)); arg= getArg(q,0)= newVariable(mb,GDKstrdup("args"),TYPE_str); q = newAssignment(mb); q = pushLng(mb,q,0); q = newAssignment(mb); q = pushWrd(mb,q,0); tuples= getArg(q,0)= newVariable(mb,GDKstrdup("tuples"),TYPE_wrd); newFcnCall(mb,"profiler","setMemoryFlag"); q->argc--; pushWrd(mb,q,1); q = newStmt(mb, "alarm", "usec"); xtime = getArg(q,0)= newVariable(mb,GDKstrdup("xtime"),TYPE_lng); } } for( ; i<slimit; i++) if(old[i]) freeInstruction(old[i]); GDKfree(old); return 1; }
/* State decision algorithm 9.3.3 Fig 26 */ static int bmc_state_decision(struct pp_instance *ppi, struct pp_frgn_master *m) { int cmpres; struct pp_frgn_master myself; if (ppi->master_only) goto master; if (ppi->slave_only) goto slave; if ((!ppi->frgn_rec_num) && (ppi->state == PPS_LISTENING)) return PPS_LISTENING; /* copy local information to a foreign_master structure */ copy_d0(ppi, &myself); /* dataset_cmp is "a - b" but lower values win */ cmpres = bmc_dataset_cmp(ppi, &myself, m); if (DSDEF(ppi)->clockQuality.clockClass < 128) { if (cmpres < 0) goto master; if (cmpres > 0) goto passive; } if (cmpres < 0) goto master; if (cmpres > 0) { if (DSDEF(ppi)->numberPorts == 1) goto slave; /* directly skip to ordinary clock handling */ else goto check_boundary_clk; } pp_diag(ppi, bmc, 1,"%s: error\n", __func__); /* MB: Is this the return code below correct? */ /* Anyway, it's a valid return code. */ return PPS_FAULTY; check_boundary_clk: if (ppi->port_idx == GLBS(ppi)->ebest_idx) /* This port is the Ebest */ goto slave; /* If idcmp returns 0, it means that this port is not the best because * Ebest is better by topology than Erbest */ if (!idcmp(&myself.ann.grandmasterIdentity, &m->ann.grandmasterIdentity)) goto passive; else goto master; passive: p1(ppi, &m->hdr, &m->ann); pp_diag(ppi, bmc, 1,"%s: passive\n", __func__); return PPS_PASSIVE; master: m1(ppi); pp_diag(ppi, bmc, 1,"%s: master\n", __func__); return PPS_MASTER; slave: s1(ppi, &m->hdr, &m->ann); pp_diag(ppi, bmc, 1,"%s: slave\n", __func__); return PPS_SLAVE; }
/* * Data set comparison between two foreign masters. Return similar to * memcmp(). However, lower values take precedence, so in A-B (like * in comparisons, > 0 means B wins (and < 0 means A wins). */ static int bmc_dataset_cmp(struct pp_instance *ppi, struct pp_frgn_master *a, struct pp_frgn_master *b) { struct ClockQuality *qa, *qb; struct MsgAnnounce *aa = &a->ann; struct MsgAnnounce *ab = &b->ann; struct ClockIdentity *ida = &a->hdr.sourcePortIdentity.clockIdentity; struct ClockIdentity *idb = &b->hdr.sourcePortIdentity.clockIdentity; struct ClockIdentity *idparent; int diff; /* dataset_cmp is called several times, so report only at level 2 */ pp_diag(ppi, bmc, 2,"%s\n", __func__); if (!idcmp(&aa->grandmasterIdentity, &ab->grandmasterIdentity)) { /* The grandmaster is the same: part 2, fig 28, page 90. */ diff = aa->stepsRemoved - ab->stepsRemoved; if (diff > 1 || diff < -1) return diff; idparent = &DSPAR(ppi)->parentPortIdentity.clockIdentity; if (diff > 0) { if (!idcmp(ida, idparent)) { pp_diag(ppi, bmc, 1,"%s:%i: Error 1\n", __func__, __LINE__); return 0; } return 1; } if (diff < 0) { if (!idcmp(idb, idparent)) { pp_diag(ppi, bmc, 1,"%s:%i: Error 1\n", __func__, __LINE__); return 0; } return -1; } /* stepsRemoved is equal, compare identities */ diff = idcmp(ida, idb); if (!diff) { pp_diag(ppi, bmc, 1,"%s:%i: Error 2\n", __func__, __LINE__); return 0; } return diff; } /* The grandmasters are different: part 1, fig 27, page 89. */ qa = &aa->grandmasterClockQuality; qb = &ab->grandmasterClockQuality; if (aa->grandmasterPriority1 != ab->grandmasterPriority1) return aa->grandmasterPriority1 - ab->grandmasterPriority1; if (qa->clockClass != qb->clockClass) return qa->clockClass - qb->clockClass; if (qa->clockAccuracy != qb->clockAccuracy) return qa->clockAccuracy - qb->clockAccuracy; if (qa->offsetScaledLogVariance != qb->offsetScaledLogVariance) return qa->clockClass - qb->clockClass; if (aa->grandmasterPriority2 != ab->grandmasterPriority2) return aa->grandmasterPriority2 - ab->grandmasterPriority2; return idcmp(&aa->grandmasterIdentity, &ab->grandmasterIdentity); }
/* * makeut - create a utmp entry, recycling an id if a wild card is * specified. * * args: utmp - point to utmp structure to be created */ struct utmp * _compat_makeut(struct utmp *utmp) { int i; struct utmp *utp; /* "current" utmp entry being examined */ int wild; /* flag, true iff wild card char seen */ /* the last id we matched that was NOT a dead proc */ unsigned char saveid[IDLEN]; wild = 0; for (i = 0; i < IDLEN; i++) if ((unsigned char)utmp->ut_id[i] == SC_WILDC) { wild = 1; break; } if (wild) { /* * try to lock the utmp file, only needed if we're * doing wildcard matching */ if (lockut()) return (0); _compat_setutent(); /* find the first alphanumeric character */ for (i = 0; i < MAXVAL; ++i) if (isalnum(i)) break; (void) memset(saveid, i, IDLEN); while ((utp = _compat_getutent()) != 0) { if (idcmp(utmp->ut_id, utp->ut_id)) continue; if (utp->ut_type == DEAD_PROCESS) break; (void) memcpy(saveid, utp->ut_id, IDLEN); } if (utp) { /* * found an unused entry, reuse it */ (void) memcpy(utmp->ut_id, utp->ut_id, IDLEN); utp = _compat_pututline(utmp); if (utp) _compat_updwtmp(WTMP_FILE, utp); _compat_endutent(); unlockut(); return (utp); } else { /* * nothing available, try to allocate an id */ if (allocid(utmp->ut_id, saveid)) { _compat_endutent(); unlockut(); return (NULL); } else { utp = _compat_pututline(utmp); if (utp) _compat_updwtmp(WTMP_FILE, utp); _compat_endutent(); unlockut(); return (utp); } } } else { utp = _compat_pututline(utmp); if (utp) _compat_updwtmp(WTMP_FILE, utp); _compat_endutent(); return (utp); } }