Lines Matching +full:up +full:- +full:to

2  * refclock_shm - clock driver for utc via shared memory
3 * - under construction -
4 * To add new modes: Extend or union the shmTime-struct. Do not
6 * will specify wrong size of shared memory-segment
52 #define PRECISION (-1) /* precision assumed (0.5 s) */
78 shm_start, /* start up driver */
88 int mode; /* 0 - if valid is set:
91 * 1 - if valid is set:
111 struct shmTime *shm; /* pointer to shared memory segment */
114 /* debugging/monitoring counters - reset when printed */
115 int ticks; /* number of attempts to read data*/
139 * Big units will give non-ascii but that's OK in getShmTime()
144 if (shmid == -1) { /* error */ in getShmTime()
149 if (p == (struct shmTime *)-1) { /* error */ in getShmTime()
213 * shm_start - attach to shared memory
221 struct refclockproc * const pp = peer->procptr; in shm_start()
222 struct shmunit * const up = emalloc_zero(sizeof(*up)); in shm_start() local
224 pp->io.clock_recv = noentry; in shm_start()
225 pp->io.srcclock = peer; in shm_start()
226 pp->io.datalen = 0; in shm_start()
227 pp->io.fd = -1; in shm_start()
229 up->forall = (unit >= 2) && !(peer->ttl & SHM_MODE_PRIVATE); in shm_start()
231 up->shm = getShmTime(unit, up->forall); in shm_start()
236 memcpy((char *)&pp->refid, REFID, 4); in shm_start()
237 if (up->shm != 0) { in shm_start()
238 pp->unitptr = up; in shm_start()
239 up->shm->precision = PRECISION; in shm_start()
240 peer->precision = up->shm->precision; in shm_start()
241 up->shm->valid = 0; in shm_start()
242 up->shm->nsamples = NSAMPLES; in shm_start()
243 pp->clockdesc = DESCRIPTION; in shm_start()
244 /* items to be changed later in 'shm_control()': */ in shm_start()
245 up->max_delay = 5; in shm_start()
246 up->max_delta = 4*3600; in shm_start()
249 free(up); in shm_start()
250 pp->unitptr = NULL; in shm_start()
257 * shm_control - configure flag1/time2 params
259 * These are not yet available during 'shm_start', so we have to do any
260 * pre-computations we want to avoid during regular poll/timer callbacks
271 struct refclockproc * const pp = peer->procptr; in shm_control()
272 struct shmunit * const up = pp->unitptr; in shm_control() local
277 if (NULL == up) in shm_control()
279 if (pp->sloppyclockflag & CLK_FLAG1) in shm_control()
280 up->max_delta = 0; in shm_control()
281 else if (pp->fudgetime2 < 1. || pp->fudgetime2 > 86400.) in shm_control()
282 up->max_delta = 4*3600; in shm_control()
284 up->max_delta = (time_t)floor(pp->fudgetime2 + 0.5); in shm_control()
289 * shm_shutdown - shut down the clock
297 struct refclockproc * const pp = peer->procptr; in shm_shutdown()
298 struct shmunit * const up = pp->unitptr; in shm_shutdown() local
301 if (NULL == up) in shm_shutdown()
306 (void)shmdt((char *)up->shm); in shm_shutdown()
310 UnmapViewOfFile(up->shm); in shm_shutdown()
313 free(up); in shm_shutdown()
318 * shm_poll - called by the transmit procedure
326 struct refclockproc * const pp = peer->procptr; in shm_poll()
327 struct shmunit * const up = pp->unitptr; in shm_poll() local
330 pp->polls++; in shm_poll()
333 major_error = max(up->notready, up->bad); in shm_poll()
334 major_error = max(major_error, up->clash); in shm_poll()
340 if (pp->coderecv != pp->codeproc) { in shm_poll()
342 pp->lastref = pp->lastrec; in shm_poll()
345 } else if (NULL == up->shm) { /* is this possible at all? */ in shm_poll()
348 } else if (major_error == up->clash) { in shm_poll()
351 } else if (major_error == up->bad) { in shm_poll()
383 /* try to grab a sample from the specified SHM segment */ in shm_query()
396 shm_stat->status = NO_SEGMENT; in shm_query()
400 /*@-type@*//* splint is confused about struct timespec */ in shm_query()
401 shm_stat->tvc.tv_sec = shm_stat->tvc.tv_nsec = 0; in shm_query()
406 shm_stat->tvc.tv_sec = now; in shm_query()
409 /* relying on word access to be atomic here */ in shm_query()
410 if (shm->valid == 0) { in shm_query()
411 shm_stat->status = NOT_READY; in shm_query()
415 cnt = shm->count; in shm_query()
420 * (b) memset compiles to an uninterruptible single-instruction bitblt. in shm_query()
424 shm->valid = 0; in shm_query()
429 * Not supported in mode 0, and word access to the count field in shm_query()
430 * must be atomic for this to work. in shm_query()
432 if (shmcopy.mode > 0 && cnt != shm->count) { in shm_query()
433 shm_stat->status = CLASH; in shm_query()
434 return shm_stat->status; in shm_query()
437 shm_stat->status = OK; in shm_query()
438 shm_stat->mode = shmcopy.mode; in shm_query()
442 shm_stat->tvr.tv_sec = shmcopy.receiveTimeStampSec; in shm_query()
443 shm_stat->tvr.tv_nsec = shmcopy.receiveTimeStampUSec * 1000; in shm_query()
445 shm_stat->tvt.tv_sec = shmcopy.clockTimeStampSec; in shm_query()
446 shm_stat->tvt.tv_nsec = shmcopy.clockTimeStampUSec * 1000; in shm_query()
456 ** *rounded* usecs, and the logic to deal with in shm_query()
457 ** wrap-arounds in the presence of rounded values is in shm_query()
460 if ( ((cns_new - (unsigned)shm_stat->tvt.tv_nsec) < 1000) in shm_query()
461 && ((rns_new - (unsigned)shm_stat->tvr.tv_nsec) < 1000)) { in shm_query()
462 shm_stat->tvt.tv_nsec = cns_new; in shm_query()
463 shm_stat->tvr.tv_nsec = rns_new; in shm_query()
465 /* At this point shm_stat->tvr and shm_stat->tvt contain valid ns-level in shm_query()
467 ** us-level timestamps in shm_query()
473 shm_stat->tvr.tv_sec = shmcopy.receiveTimeStampSec; in shm_query()
474 shm_stat->tvr.tv_nsec = shmcopy.receiveTimeStampUSec * 1000; in shm_query()
476 shm_stat->tvt.tv_sec = shmcopy.clockTimeStampSec; in shm_query()
477 shm_stat->tvt.tv_nsec = shmcopy.clockTimeStampUSec * 1000; in shm_query()
483 if ( ((cns_new - (unsigned)shm_stat->tvt.tv_nsec) < 1000) in shm_query()
484 && ((rns_new - (unsigned)shm_stat->tvr.tv_nsec) < 1000)) { in shm_query()
485 shm_stat->tvt.tv_nsec = cns_new; in shm_query()
486 shm_stat->tvr.tv_nsec = rns_new; in shm_query()
488 /* At this point shm_stat->tvr and shm_stat->tvt contains valid ns-level in shm_query()
490 ** us-level timestamps in shm_query()
495 shm_stat->status = BAD_MODE; in shm_query()
498 /*@-type@*/ in shm_query()
505 shm_stat->leap = shmcopy.leap; in shm_query()
506 shm_stat->precision = shmcopy.precision; in shm_query()
508 return shm_stat->status; in shm_query()
512 * shm_timer - called once every second.
514 * This tries to grab a sample from the SHM segment, filtering bad ones
522 struct refclockproc * const pp = peer->procptr; in shm_timer()
523 struct shmunit * const up = pp->unitptr; in shm_timer() local
539 up->ticks++; in shm_timer()
540 if ((shm = up->shm) == NULL) { in shm_timer()
541 /* try to map again - this may succeed if meanwhile some- in shm_timer()
543 shm = up->shm = getShmTime(unit, up->forall); in shm_timer()
546 refnumtoa(&peer->srcadr))); in shm_timer()
557 refnumtoa(&peer->srcadr), shm_stat.mode)); in shm_timer()
563 DPRINTF(1, ("%s: SHM not ready\n",refnumtoa(&peer->srcadr))); in shm_timer()
564 up->notready++; in shm_timer()
568 refnumtoa(&peer->srcadr), shm->mode)); in shm_timer()
569 up->bad++; in shm_timer()
571 shm->mode); in shm_timer()
575 refnumtoa(&peer->srcadr))); in shm_timer()
577 up->clash++; in shm_timer()
581 refnumtoa(&peer->srcadr))); in shm_timer()
583 up->bad++; in shm_timer()
588 /* format the last time code in human-readable form into in shm_timer()
589 * 'pp->a_lastcode'. Someone claimed: "NetBSD has incompatible in shm_timer()
598 /* add ntpq -c cv timecode in ISO 8601 format */ in shm_timer()
599 c = snprintf(pp->a_lastcode, sizeof(pp->a_lastcode), in shm_timer()
600 "%04u-%02u-%02uT%02u:%02u:%02u.%09ldZ", in shm_timer()
604 pp->lencode = (c > 0 && (size_t)c < sizeof(pp->a_lastcode)) ? c : 0; in shm_timer()
607 tt = shm_stat.tvc.tv_sec - shm_stat.tvr.tv_sec; in shm_timer()
608 if (tt < 0 || tt > up->max_delay) { in shm_timer()
610 refnumtoa(&peer->srcadr), (long long)tt)); in shm_timer()
611 up->bad++; in shm_timer()
618 tt = shm_stat.tvr.tv_sec - shm_stat.tvt.tv_sec - (shm_stat.tvr.tv_nsec < shm_stat.tvt.tv_nsec); in shm_timer()
620 tt = -tt; in shm_timer()
621 if (up->max_delta > 0 && tt > up->max_delta) { in shm_timer()
623 refnumtoa(&peer->srcadr), (long long)tt)); in shm_timer()
624 up->bad++; in shm_timer()
630 /* if we really made it to this point... we're winners! */ in shm_timer()
632 refnumtoa(&peer->srcadr))); in shm_timer()
635 pp->leap = shm_stat.leap; in shm_timer()
636 peer->precision = shm_stat.precision; in shm_timer()
637 refclock_process_offset(pp, tsref, tsrcv, pp->fudgetime1); in shm_timer()
638 up->good++; in shm_timer()
642 * shm_clockstats - dump and reset counters
649 struct refclockproc * const pp = peer->procptr; in shm_clockstats()
650 struct shmunit * const up = pp->unitptr; in shm_clockstats() local
653 if (pp->sloppyclockflag & CLK_FLAG4) { in shm_clockstats()
655 &peer->srcadr, "%3d %3d %3d %3d %3d", in shm_clockstats()
656 up->ticks, up->good, up->notready, in shm_clockstats()
657 up->bad, up->clash); in shm_clockstats()
659 up->ticks = up->good = up->notready = up->bad = up->clash = 0; in shm_clockstats()