pwr_tStatus time_Dmul ( pwr_tDeltaTime *result, pwr_tDeltaTime *t1, pwr_tInt32 fac ) { pwr_tInt64 nsec1, nsec2, sum; int sec = t1->tv_sec * fac; int mul = 1000000000; int addend = 0; int sts; sts = lib$emul(&sec, &mul, &addend, &nsec1); if (EVEN(sts)) return sts; sts = lib$emul(&t1->tv_nsec, &fac, &addend, &nsec2); if (EVEN(sts)) return sts; sts = lib$addx(&nsec1, &nsec2, &sum); if (EVEN(sts)) return sts; sts = lib$ediv(&mul, &sum, &result->tv_sec, &result->tv_nsec); if (EVEN(sts)) return sts; return TIME__SUCCESS; }
static time_tOs * abs_to_vms ( pwr_tStatus *status, time_tOs *result, pwr_tTime *pt ) { time_tOs tmp; time_tOs ofs = {0x4beb4000, 0x007c9567}; int multiplier = 10000000; /* Used to convert 1 s to 100 ns, delta time. */ int nsec = pt->tv_nsec/100; int sec = pt->tv_sec; struct tm *tmp_tm; unsigned long t = 0; pwr_dStatus(sts, status, TIME__SUCCESS); /* Get the time zone offset. */ tmp_tm = localtime(&pt->tv_sec); sec += tmp_tm->tm_gmtoff - tmp_tm->tm_isdst * 3600; *sts = lib$emul(&sec, &multiplier, &nsec, &tmp); if (EVEN(*sts)) return NULL; *sts = lib$addx(&tmp, &ofs, result); if (EVEN(*sts)) return NULL; return result; }
/* **++ ** ROUTINE: sp_show_subprocess ** ** FUNCTIONAL DESCRIPTION: ** ** Uses $GETJPI to get info on the subprocess and ** displays it à la CTRL/T. ** ** RETURNS: cond_value, longword (unsigned), write only, by value ** ** PROTOTYPE: ** ** sp_show_subprocess(SPHANDLE ctx) ** ** IMPLICIT INPUTS: None. ** ** IMPLICIT OUTPUTS: None. ** ** COMPLETION CODES: ** ** ** SIDE EFFECTS: None. ** **-- */ unsigned int sp_show_subprocess (SPHANDLE ctx) { static $DESCRIPTOR(ctrstr, "<<!AD!AD !8%T !9AD CPU=!%T PF=!UL IO=!UL MEM=!UL>>"); static int neg10000 = -10000; static int zero = 0; struct dsc$descriptor bufdsc; struct { unsigned short len, code; char *ptr; unsigned int term; } fscnlst = {0, FSCN$_NAME, 0, 0}; ITMLST jpilst[8]; char nodename[33], buf[256]; char prcnam[16], imgnam[256]; unsigned short prcnamlen, imgnamlen, iosb[4], buflen; unsigned int cputim[2], xcputim; unsigned int pageflts, biocnt, diocnt, wssize; unsigned int status; if (!get_logical("SYS$NODE", nodename, sizeof(nodename))) nodename[0] = '\0'; ITMLST_INIT(jpilst[0], JPI$_PRCNAM, sizeof(prcnam), prcnam, &prcnamlen); ITMLST_INIT(jpilst[1], JPI$_IMAGNAME, sizeof(imgnam), imgnam, &imgnamlen); ITMLST_INIT(jpilst[2], JPI$_CPUTIM, sizeof(xcputim), &xcputim, 0); ITMLST_INIT(jpilst[3], JPI$_PAGEFLTS, sizeof(pageflts), &pageflts, 0); ITMLST_INIT(jpilst[4], JPI$_DIOCNT, sizeof(diocnt), &diocnt, 0); ITMLST_INIT(jpilst[5], JPI$_BIOCNT, sizeof(biocnt), &biocnt, 0); ITMLST_INIT(jpilst[6], JPI$_WSSIZE, sizeof(wssize), &wssize, 0); ITMLST_INIT(jpilst[7], 0, 0, 0, 0); status = sys$getjpiw(0, &ctx->pid, 0, jpilst, iosb, 0, 0); if (OK(status)) status = iosb[0]; if (!OK(status)) return SS$_NORMAL; while (imgnamlen > 0 && isspace(imgnam[imgnamlen-1])) imgnamlen--; if (imgnamlen > 0) { INIT_SDESC(bufdsc, imgnamlen, imgnam); status = sys$filescan(&bufdsc, &fscnlst, 0); if (!OK(status)) { fscnlst.ptr = imgnam; fscnlst.len = imgnamlen; } } else { strcpy(imgnam, " (DCL)"); imgnamlen = 7; } lib$emul(&neg10000, &xcputim, &zero, cputim); INIT_SDESC(bufdsc, sizeof(buf), buf); status = sys$fao(&ctrstr, &buflen, &bufdsc, strlen(nodename), nodename, prcnamlen, prcnam, 0, fscnlst.len, fscnlst.ptr, cputim, pageflts, diocnt+biocnt, wssize); if (OK(status)) { bufdsc.dsc$w_length = buflen; lib$put_output(&bufdsc); } return SS$_NORMAL; } /* sp_show_subprocess */
static void waitTime ( pwr_tTime *t ) { pwr_tStatus sts; pwr_tTime now; pwr_tTime then = *t; char tims[24]; short len; struct dsc$descriptor_s tims_desc = { sizeof(tims)-1, DSC$K_DTYPE_T, DSC$K_CLASS_S,}; #if 0 subTime(&then, nowTime(&now)); #endif if ((int)then.tv_sec > 0 || ((int)then.tv_sec == 0 && then.tv_nsec > 0)) { #if defined OS_VMS || defined OS_ELN int tv_nsec; int vmstime[2]; int multiplier = -10000000; /* Used to convert 1 s to 100 ns, delta time. */ static pwr_tTime tick = {0, 10000000}; addTime(&then, &tick); tv_nsec = -then.tv_nsec/100; /* Convert to 100 ns. */ sts = lib$emul(&then.tv_sec, &multiplier, &tv_nsec, vmstime); #if defined OS_VMS tims_desc.dsc$a_pointer = tims; sys$asctim( &len, &tims_desc, vmstime, 0); tims[len] = '\0'; printf(" %s\n", tims); #if 0 sts = sys$clref(timerFlag); sts = sys$setimr(timerFlag, vmstime, 0, 0, 0); sts = sys$waitfr(timerFlag); #endif #elif defined OS_ELN eln$time_string(tims, vmstime); tims[23] = '\0'; printf(" %s\n", tims); #if 0 ker$wait_any(&sts, NULL, vmstime); #endif #endif #elif defined OS_LYNX pwr_tTime rmt; nanosleep(&then, &rmt); #endif } }
static time_tOs * delta_to_vms ( pwr_tStatus *status, pwr_tVaxTime *result, pwr_tDeltaTime *pt ) { int multiplier = -10000000; /* Used to convert 1 s to 100 ns, delta time. */ int nsec = pt->tv_nsec/100; int sec = pt->tv_sec; pwr_dStatus(sts, status, TIME__SUCCESS); *sts = lib$emul(&sec, &multiplier, &nsec, result); if (EVEN(*sts)) return NULL; return result; }
static void waitClock ( time_tClock diff, int *tmo_ms ) { #if defined OS_VMS || defined OS_ELN pwr_tStatus sts; int sec; int nsec; int vmstime[2]; int multiplier = -10000000; /* Used to convert 1 s to 100 ns, delta time. */ sec = diff / CLK_TCK; nsec = - (diff % CLK_TCK * 10000000 / CLK_TCK); /* Convert to 100 ns. */ sts = lib$emul(&sec, &multiplier, &nsec, vmstime); # if defined OS_VMS sts = sys$clref(timer_flag); sts = sys$setimr(timer_flag, vmstime, 0, 0, 0); sts = sys$waitfr(timer_flag); # elif defined OS_ELN ker$wait_any(&sts, NULL, vmstime); # endif #elif defined OS_POSIX // pwr_tTime rmt; // pwr_tTime wait; static int tics_per_sec = 0; if (tics_per_sec == 0) { tics_per_sec = sysconf(_SC_CLK_TCK); } // printf("waitClock: %d\n", diff); // time_ClockToD(NULL, (pwr_tDeltaTime *)&wait, diff); *tmo_ms = diff * 1000 / tics_per_sec; // *tmo_ms = wait.tv_sec * 1000 + wait.tv_nsec / 1000000; // nanosleep(&wait, &rmt); #endif }
time_tOs * time_DtoOs ( pwr_tStatus *status, time_tOs *tp, pwr_tDeltaTime *dp ) { time_tOs os_time; int multiplier = -10000000; int nsec = dp->tv_nsec/100; int sec = dp->tv_sec; pwr_dStatus(sts, status, TIME__SUCCESS); if (tp == NULL) tp = &os_time; *sts = lib$emul(&sec, &multiplier, &nsec, tp); if (EVEN(*sts)) return NULL; return tp; }
i4 TMtostr (i4 secs, char* op_str) { i4 j; i4 sts; GENERIC_64 vms_time; struct dsc$descriptor_s timdsc = {20, DSC$K_DTYPE_T, DSC$K_CLASS_S, op_str}; /* ** clear output string in case of errors ** you will note that there is an implicit assumption that the ** the caller provided an output buffer of at least 21 characters */ op_str[0] = 0; /* convert time in secs to VMS 100nSec units */ sts = lib$emul(&secs, &10000000, &0, (int64 *)&vms_time); if (!(sts & STS$M_SUCCESS)) return 0; sts = lib$addx ((u_i8 *)&vms_time, (u_i8 *)&unix_epoch, (u_i8 *)&vms_time); if (!(sts & STS$M_SUCCESS)) return 0; /* ** restrict the o/p buffer length to a max of 20 chars ** i.e. lose the trailing ".nn" millisecs of the string */ sts = sys$asctim (&timdsc.dsc$w_length, &timdsc, &vms_time, 0); j = (sts & STS$M_SUCCESS) ? timdsc.dsc$w_length : 0; op_str[j] = 0; return ((sts & STS$M_SUCCESS) ? j : 0); }
/* * init_timer - initialize the timer data structures */ void init_timer(void) { /* * Initialize... */ alarm_flag = 0; alarm_overflow = 0; adjust_timer = 1; stats_timer = 0; huffpuff_timer = 0; interface_timer = 0; current_time = 0; timer_overflows = 0; timer_xmtcalls = 0; timer_timereset = 0; #if !defined(SYS_WINNT) /* * Set up the alarm interrupt. The first comes 2**EVENT_TIMEOUT * seconds from now and they continue on every 2**EVENT_TIMEOUT * seconds. */ # if !defined(VMS) # if defined(HAVE_TIMER_CREATE) && defined(HAVE_TIMER_SETTIME) if (timer_create (CLOCK_REALTIME, NULL, &ntpd_timerid) == # ifdef SYS_VXWORKS ERROR # else -1 # endif ) { fprintf (stderr, "timer create FAILED\n"); exit (0); } (void) signal_no_reset(SIGALRM, alarming); itimer.it_interval.tv_sec = itimer.it_value.tv_sec = (1<<EVENT_TIMEOUT); itimer.it_interval.tv_nsec = itimer.it_value.tv_nsec = 0; timer_settime(ntpd_timerid, 0 /*!TIMER_ABSTIME*/, &itimer, NULL); # else (void) signal_no_reset(SIGALRM, alarming); nap_time = 1; itimer.it_interval.tv_sec = itimer.it_value.tv_sec = nap_time; itimer.it_interval.tv_usec = itimer.it_value.tv_usec = 0; setitimer(ITIMER_REAL, &itimer, (struct itimerval *)0); # endif # else /* VMS */ vmsinc[0] = 10000000; /* 1 sec */ vmsinc[1] = 0; lib$emul(&(1<<EVENT_TIMEOUT), &vmsinc, &0, &vmsinc); sys$gettim(&vmstimer); /* that's "now" as abstime */ lib$addx(&vmsinc, &vmstimer, &vmstimer); sys$setimr(0, &vmstimer, alarming, alarming, 0); # endif /* VMS */ #else /* SYS_WINNT */ /* * Set up timer interrupts for every 2**EVENT_TIMEOUT seconds * Under Windows/NT, */ WaitableTimerHandle = CreateWaitableTimer(NULL, FALSE, NULL); if (WaitableTimerHandle == NULL) { msyslog(LOG_ERR, "CreateWaitableTimer failed: %m"); exit(1); } else { DWORD Period = (1<<EVENT_TIMEOUT) * 1000; LARGE_INTEGER DueTime; DueTime.QuadPart = Period * 10000i64; if (!SetWaitableTimer(WaitableTimerHandle, &DueTime, Period, NULL, NULL, FALSE) != NO_ERROR) { msyslog(LOG_ERR, "SetWaitableTimer failed: %m"); exit(1); } } #endif /* SYS_WINNT */ }
/* * init_timer - initialize the timer data structures */ void init_timer(void) { /* * Initialize... */ alarm_flag = FALSE; alarm_overflow = 0; adjust_timer = 1; stats_timer = SECSPERHR; leapf_timer = SECSPERDAY; huffpuff_timer = 0; interface_timer = 0; current_time = 0; timer_overflows = 0; timer_xmtcalls = 0; timer_timereset = 0; #ifndef SYS_WINNT /* * Set up the alarm interrupt. The first comes 2**EVENT_TIMEOUT * seconds from now and they continue on every 2**EVENT_TIMEOUT * seconds. */ # ifndef VMS # ifdef HAVE_TIMER_CREATE if (TC_ERR == timer_create(CLOCK_REALTIME, NULL, &timer_id)) { msyslog(LOG_ERR, "timer_create failed, %m"); exit(1); } # endif signal_no_reset(SIGALRM, alarming); itimer.it_interval.tv_sec = itimer.it_value.tv_sec = (1 << EVENT_TIMEOUT); itimer.it_interval.itv_frac = itimer.it_value.itv_frac = 0; set_timer_or_die(&itimer); # else /* VMS follows */ vmsinc[0] = 10000000; /* 1 sec */ vmsinc[1] = 0; lib$emul(&(1<<EVENT_TIMEOUT), &vmsinc, &0, &vmsinc); sys$gettim(&vmstimer); /* that's "now" as abstime */ lib$addx(&vmsinc, &vmstimer, &vmstimer); sys$setimr(0, &vmstimer, alarming, alarming, 0); # endif /* VMS */ #else /* SYS_WINNT follows */ /* * Set up timer interrupts for every 2**EVENT_TIMEOUT seconds * Under Windows/NT, */ WaitableTimerHandle = CreateWaitableTimer(NULL, FALSE, NULL); if (WaitableTimerHandle == NULL) { msyslog(LOG_ERR, "CreateWaitableTimer failed: %m"); exit(1); } else { DWORD Period; LARGE_INTEGER DueTime; BOOL rc; Period = (1 << EVENT_TIMEOUT) * 1000; DueTime.QuadPart = Period * 10000i64; rc = SetWaitableTimer(WaitableTimerHandle, &DueTime, Period, NULL, NULL, FALSE); if (!rc) { msyslog(LOG_ERR, "SetWaitableTimer failed: %m"); exit(1); } } #endif /* SYS_WINNT */ }
/* * init_timer - initialize the timer data structures */ void init_timer(void) { # if defined SYS_WINNT & !defined(SYS_CYGWIN32) HANDLE hToken = INVALID_HANDLE_VALUE; TOKEN_PRIVILEGES tkp; # endif /* SYS_WINNT */ /* * Initialize... */ alarm_flag = 0; alarm_overflow = 0; adjust_timer = 1; stats_timer = 0; huffpuff_timer = 0; interface_timer = 0; current_time = 0; timer_overflows = 0; timer_xmtcalls = 0; timer_timereset = 0; #if !defined(SYS_WINNT) /* * Set up the alarm interrupt. The first comes 2**EVENT_TIMEOUT * seconds from now and they continue on every 2**EVENT_TIMEOUT * seconds. */ # if !defined(VMS) # if defined(HAVE_TIMER_CREATE) && defined(HAVE_TIMER_SETTIME) if (timer_create (CLOCK_REALTIME, NULL, &ntpd_timerid) == # ifdef SYS_VXWORKS ERROR # else -1 # endif ) { fprintf (stderr, "timer create FAILED\n"); exit (0); } (void) signal_no_reset(SIGALRM, alarming); itimer.it_interval.tv_sec = itimer.it_value.tv_sec = (1<<EVENT_TIMEOUT); itimer.it_interval.tv_nsec = itimer.it_value.tv_nsec = 0; timer_settime(ntpd_timerid, 0 /*!TIMER_ABSTIME*/, &itimer, NULL); # else (void) signal_no_reset(SIGALRM, alarming); itimer.it_interval.tv_sec = itimer.it_value.tv_sec = (1<<EVENT_TIMEOUT); itimer.it_interval.tv_usec = itimer.it_value.tv_usec = 0; setitimer(ITIMER_REAL, &itimer, (struct itimerval *)0); # endif # else /* VMS */ vmsinc[0] = 10000000; /* 1 sec */ vmsinc[1] = 0; lib$emul(&(1<<EVENT_TIMEOUT), &vmsinc, &0, &vmsinc); sys$gettim(&vmstimer); /* that's "now" as abstime */ lib$addx(&vmsinc, &vmstimer, &vmstimer); sys$setimr(0, &vmstimer, alarming, alarming, 0); # endif /* VMS */ #else /* SYS_WINNT */ _tzset(); /* * Get privileges needed for fiddling with the clock */ /* get the current process token handle */ if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) { msyslog(LOG_ERR, "OpenProcessToken failed: %m"); exit(1); } /* get the LUID for system-time privilege. */ LookupPrivilegeValue(NULL, SE_SYSTEMTIME_NAME, &tkp.Privileges[0].Luid); tkp.PrivilegeCount = 1; /* one privilege to set */ tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; /* get set-time privilege for this process. */ AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES) NULL, 0); /* cannot test return value of AdjustTokenPrivileges. */ if (GetLastError() != ERROR_SUCCESS) { msyslog(LOG_ERR, "AdjustTokenPrivileges failed: %m"); } /* * Set up timer interrupts for every 2**EVENT_TIMEOUT seconds * Under Windows/NT, */ WaitableTimerHandle = CreateWaitableTimer(NULL, FALSE, NULL); if (WaitableTimerHandle == NULL) { msyslog(LOG_ERR, "CreateWaitableTimer failed: %m"); exit(1); } else { DWORD Period = (1<<EVENT_TIMEOUT) * 1000; LARGE_INTEGER DueTime; DueTime.QuadPart = Period * 10000i64; if (!SetWaitableTimer(WaitableTimerHandle, &DueTime, Period, NULL, NULL, FALSE) != NO_ERROR) { msyslog(LOG_ERR, "SetWaitableTimer failed: %m"); exit(1); } } #endif /* SYS_WINNT */ }