예제 #1
0
int validate_freq(void)
{
	struct timex tx;
	int ret, pass = 0;
	int i;

	clear_time_state();

	memset(&tx, 0, sizeof(struct timex));
	/* Set the leap second insert flag */

	printf("Testing ADJ_FREQ... ");
	fflush(stdout);
	for (i = 0; i < NUM_FREQ_VALID; i++) {
		tx.modes = ADJ_FREQUENCY;
		tx.freq = valid_freq[i];

		ret = adjtimex(&tx);
		if (ret < 0) {
			printf("[FAIL]\n");
			printf("Error: adjtimex(ADJ_FREQ, %ld - %ld ppm\n",
				valid_freq[i], valid_freq[i]>>16);
			pass = -1;
			goto out;
		}
		tx.modes = 0;
		ret = adjtimex(&tx);
		if (tx.freq != valid_freq[i]) {
			printf("Warning: freq value %ld not what we set it (%ld)!\n",
					tx.freq, valid_freq[i]);
		}
	}
예제 #2
0
파일: raw_skew.c 프로젝트: 020gzh/linux
int main(int argv, char **argc)
{
	struct timespec mon, raw, start, end;
	long long delta1, delta2, interval, eppm, ppm;
	struct timex tx1, tx2;

	setbuf(stdout, NULL);

	if (clock_gettime(CLOCK_MONOTONIC_RAW, &raw)) {
		printf("ERR: NO CLOCK_MONOTONIC_RAW\n");
		return -1;
	}

	tx1.modes = 0;
	adjtimex(&tx1);
	get_monotonic_and_raw(&mon, &raw);
	start = mon;
	delta1 = diff_timespec(mon, raw);

	if (tx1.offset)
		printf("WARNING: ADJ_OFFSET in progress, this will cause inaccurate results\n");

	printf("Estimating clock drift: ");
	sleep(120);

	get_monotonic_and_raw(&mon, &raw);
	end = mon;
	tx2.modes = 0;
	adjtimex(&tx2);
	delta2 = diff_timespec(mon, raw);

	interval = diff_timespec(start, end);

	/* calculate measured ppm between MONOTONIC and MONOTONIC_RAW */
	eppm = ((delta2-delta1)*NSEC_PER_SEC)/interval;
	eppm = -eppm;
	printf("%lld.%i(est)", eppm/1000, abs((int)(eppm%1000)));

	/* Avg the two actual freq samples adjtimex gave us */
	ppm = (tx1.freq + tx2.freq) * 1000 / 2;
	ppm = (long long)tx1.freq * 1000;
	ppm = shift_right(ppm, 16);
	printf(" %lld.%i(act)", ppm/1000, abs((int)(ppm%1000)));

	if (llabs(eppm - ppm) > 1000) {
		printf("	[FAILED]\n");
		return ksft_exit_fail();
	}
	printf("	[OK]\n");
	return  ksft_exit_pass();
}
예제 #3
0
static void adjtimex_status(struct timex *tx, int status)
{
	const char *const msgs[6] = {
		"clock synchronized",
		"insert leap second",
		"delete leap second",
		"leap second in progress",
		"leap second has occurred",
		"clock not synchronized",
	};
	int r;
	struct timespec now;

	tx->modes = ADJ_STATUS;
	tx->status = status;
	r = adjtimex(tx);
	now.tv_sec = tx->time.tv_sec;
	now.tv_nsec = tx->time.tv_usec * 1000;

	if ((tx->status & status) != status)
		tst_brkm(TBROK, cleanup, "adjtimex status %d not set", status);
	else if (r < 0)
		tst_brkm(TBROK | TERRNO, cleanup, "adjtimex");
	else if (r < 6)
		tst_resm(TINFO, "%s adjtimex: %s", strtime(&now), msgs[r]);
	else
		tst_resm(TINFO, "%s adjtimex: clock state %d",
			 strtime(&now), r);
}
예제 #4
0
파일: adjtimex02.c 프로젝트: ArnoldWu/ltp
/* setup() - performs all ONE TIME setup for this test */
void setup(void)
{

	tim_save.modes = 0;

	/* Check whether we are root */
	if (geteuid() != 0) {
		tst_brkm(TBROK, NULL, "Test must be run as root");
	}

	tst_sig(NOFORK, DEF_HANDLER, cleanup);

	/* set the expected errnos... */
	TEST_EXP_ENOS(exp_enos);

	/* set the HZ from sysconf */
	hz = sysconf(_SC_CLK_TCK);
	if (hz == -1) {
		tst_brkm(TBROK, NULL, "Failed to read the HZ from sysconf\n");
	}

	TEST_PAUSE;

	/* Save current parameters in tim_save */
	if ((adjtimex(&tim_save)) == -1) {
		tst_brkm(TBROK, NULL, "Failed to save current parameters");
	}
}
예제 #5
0
int
main(
	int argc,
	char *argv[]
	)
{
	if (argc > 2)
	{
		fprintf(stderr, "Usage: %s [tick_value]\n", argv[0]);
		exit(-1);
	}
	else if (argc == 2)
	{
#ifdef ADJ_TIMETICK
		if ( (txc.time_tick = atoi(argv[1])) < 1 )
#else
		if ( (txc.tick = atoi(argv[1])) < 1 )
#endif
		{
			fprintf(stderr, "Silly value for tick: %s\n", argv[1]);
			exit(-1);
		}
#ifdef ADJ_TIMETICK
		txc.modes = ADJ_TIMETICK;
#else
#ifdef MOD_OFFSET
		txc.modes = ADJ_TICK;
#else
		txc.mode = ADJ_TICK;
#endif
#endif
	}
	else
	{
#ifdef ADJ_TIMETICK
		txc.modes = 0;
#else
#ifdef MOD_OFFSET
		txc.modes = 0;
#else
		txc.mode = 0;
#endif
#endif
	}

	if (adjtimex(&txc) < 0)
	{
		perror("adjtimex");
	}
	else
	{
#ifdef ADJ_TIMETICK
		printf("tick     = %ld\ntick_adj = %ld\n", txc.time_tick, txc.tickadj);
#else
		printf("tick = %ld\n", txc.tick);
#endif
	}

	exit(0);
}
예제 #6
0
파일: lntp.c 프로젝트: nmacs/lm3s-uclinux
static int clock_adjust(struct p *p)
{
	int i;
	int ret = NTP_OK;
	double old;
	double offset;
	struct timex tx;
	dprint("clock_adjust: p->offset:%f\n", p->offset);
	if (p->offset < CLOCK_MAX) {
		memset(&tx, 0, sizeof(tx));
		tx.modes = ADJ_OFFSET_SINGLESHOT;
		ret = get_old_offset(&old);
		if (ret) return ret;
		offset = p->offset + old;
		tx.offset = (long)(offset * USEC_IN_SEC);
		if (adjtimex(&tx) < 0) return NTP_ERR_SYS;
		for (i = 0; i < NSTAGE; i++)
			if (p->f[i].t > p->t && p->f[i].disp < MAXDISPERSE)
				p->f[i].offset -= p->offset;
		ret = freq_adjust(p);
		dprint("clock_adjust: freq_adjust_ret:%i\n", ret);
	}
	else {
		ret = movetime(p->offset);
		offset = p->offset;
		peer_clear(p);
		if (ret) return ret;
	}

	p->effective_offset = offset;
	return ret;
}
예제 #7
0
파일: adjtimex01.c 프로젝트: Nan619/ltp-ddt
int main(int ac, char **av)
{

	int lc;
	char *msg;

	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);

	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {

		Tst_count = 0;

		/* Call adjtimex(2) */
		tim_save.modes = SET_MODE;

		TEST(adjtimex(&tim_save));

		if ((TEST_RETURN >= 0) && (TEST_RETURN <= 5)) {
			tst_resm(TPASS, "adjtimex() returned %ld", TEST_RETURN);
		} else {
			tst_resm(TFAIL | TTERRNO, "Test Failed, adjtimex()"
				 "returned %ld", TEST_RETURN);
		}
	}

	cleanup();

	tst_exit();
}
예제 #8
0
파일: sys.c 프로젝트: artasoftkey/ptpv2d
Boolean adjFreq(Integer32 adj)
{
#ifndef __WINDOWS__
#ifndef CONFIG_MPC831X
  struct timex t;
#endif
#endif
  
  if(adj > ADJ_FREQ_MAX)
    adj = ADJ_FREQ_MAX;
  else if(adj < -ADJ_FREQ_MAX)
    adj = -ADJ_FREQ_MAX;
  
#ifdef CONFIG_MPC831X
  if (++temp_debug_max_adjustments < 10000)
    mpc831x_adj_addend(adj);
  return (TRUE);
#elif defined(__WINDOWS__)
  return(!( SetSystemTimeAdjustment((adj/100),FALSE)));
#else
  t.modes = MOD_FREQUENCY;
  t.freq = adj*((1<<16)/1000);

  return !adjtimex(&t);
#endif
}
예제 #9
0
파일: adjtimex01.c 프로젝트: AbhiramiP/ltp
int main(int ac, char **av)
{
	int lc;

	tst_parse_opts(ac, av, NULL, NULL);

	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {

		tst_count = 0;

		/* Call adjtimex(2) */
		tim_save.modes = SET_MODE;

		TEST(adjtimex(&tim_save));

		if ((TEST_RETURN >= 0) && (TEST_RETURN <= 5)) {
			tst_resm(TPASS, "adjtimex() with mode %u returned %ld",
				 SET_MODE, TEST_RETURN);
		} else {
			tst_resm(TFAIL | TTERRNO,
				"Test Failed, adjtimex() with mode %u "
				"returned %ld", SET_MODE, TEST_RETURN);
		}

		/* Call adjtimex(2) */
		tim_save.modes = ADJ_OFFSET_SINGLESHOT;

		TEST(adjtimex(&tim_save));

		if ((TEST_RETURN >= 0) && (TEST_RETURN <= 5)) {
			tst_resm(TPASS, "adjtimex() with mode %u returned %ld",
				 ADJ_OFFSET_SINGLESHOT, TEST_RETURN);
		} else {
			tst_resm(TFAIL | TTERRNO,
				"Test Failed, adjtimex() with mode %u returned "
				"%ld", ADJ_OFFSET_SINGLESHOT, TEST_RETURN);
		}
	}

	cleanup();

	tst_exit();
}
예제 #10
0
int get_tai(void)
{
	struct timex tx;

	memset(&tx, 0, sizeof(tx));

	adjtimex(&tx);
	return tx.tai;
}
예제 #11
0
파일: lntp.c 프로젝트: nmacs/lm3s-uclinux
static int get_old_offset(double *offset)
{
	struct timex tx;
	memset(&tx, 0, sizeof(tx));
	tx.modes = ADJ_OFFSET_SS_READ;
	if (adjtimex(&tx) < 0) return NTP_ERR_SYS;
	*offset = (double)tx.offset / USEC_IN_SEC;
	return NTP_OK;
}
예제 #12
0
/* clear NTP time_status & time_state */
void clear_time_state(void)
{
	struct timex tx;
	int ret;

	/*
	 * We have to call adjtime twice here, as kernels
	 * prior to 6b1859dba01c7 (included in 3.5 and
	 * -stable), had an issue with the state machine
	 * and wouldn't clear the STA_INS/DEL flag directly.
	 */
	tx.modes = ADJ_STATUS;
	tx.status = STA_PLL;
	ret = adjtimex(&tx);

	tx.modes = ADJ_STATUS;
	tx.status = 0;
	ret = adjtimex(&tx);
}
예제 #13
0
/* clear NTP time_status & time_state */
int clear_time_state(void)
{
	struct timex tx;
	int ret;

	tx.modes = ADJ_STATUS;
	tx.status = 0;
	ret = adjtimex(&tx);
	return ret;
}
예제 #14
0
파일: rdconf.cpp 프로젝트: WMTH/rivendell
bool RDTimeSynced()
{
  struct timex timex;

  memset(&timex,0,sizeof(struct timex));
  if(adjtimex(&timex)==TIME_OK) {
    return true;
  }
  return false;
}
예제 #15
0
int set_tai(int offset)
{
	struct timex tx;

	memset(&tx, 0, sizeof(tx));

	tx.modes = ADJ_TAI;
	tx.constant = offset;

	return adjtimex(&tx);
}
예제 #16
0
파일: time-util.c 프로젝트: nnz1024/systemd
bool ntp_synced(void) {
        struct timex txc = {};

        if (adjtimex(&txc) < 0)
                return false;

        if (txc.status & STA_UNSYNC)
                return false;

        return true;
}
예제 #17
0
static GVariant *get_clock_synchronized(void) {
	struct timex t;
	gboolean ret;

	/* Consider the system clock synchronized if the maximum error reported
	   by adjtimex() is smaller than 10 seconds. Ignore the STA_UNSYNC flag
	   as it may be set to prevent the kernel from touching the RTC. */
	t.modes = 0;
	ret = adjtimex(&t) >= 0 && t.maxerror < 10000000;

	return g_variant_new_boolean(ret);
}
예제 #18
0
파일: freq-step.c 프로젝트: mdamt/linux
static void reset_ntp_error(void)
{
	struct timex txc;

	txc.modes = ADJ_SETOFFSET;
	txc.time.tv_sec = 0;
	txc.time.tv_usec = 0;

	if (adjtimex(&txc) < 0) {
		perror("[FAIL] adjtimex");
		ksft_exit_fail();
	}
}
예제 #19
0
int main(int argc, char** argv)
{
	struct timex tx;
	int ret;
	int i;

	clear_time_state();

	/* Set the leap second insert flag */
	tx.modes = ADJ_SETOFFSET | ADJ_NANO;

	printf("Testing ADJ_SETOFFSET: ");
	for (i=0; i < NUM_VALID; i++) {
		tx.time.tv_sec = valid_vals[i].tv_sec;
		tx.time.tv_usec = valid_vals[i].tv_nsec;

		ret = adjtimex(&tx);
		if (ret < 0 ) {
			printf("FAIL\n");
			printf("Error: adjtimex(ADJ_SETOFFSET, %ld:%ld)\n",
				valid_vals[i].tv_sec,valid_vals[i].tv_nsec);
			return -1;
		}
	}

	for (i=0; i < NUM_INVALID; i++) {
		tx.time.tv_sec = invalid_vals[i].tv_sec;
		tx.time.tv_usec = invalid_vals[i].tv_nsec;
		ret = adjtimex(&tx);
		if (ret >= 0 ) {
			printf("FAIL\n");
			printf("Error: invalid adjtimex(ADJ_SETOFFSET, %ld:%ld)\n",
				invalid_vals[i].tv_sec,invalid_vals[i].tv_nsec);
			return -1;
		}
	}
	printf("PASS\n");
	return 0;
}
예제 #20
0
static double
getFrequency (ClockDriver * self) {

	struct timex tmx;
	memset(&tmx, 0, sizeof(tmx));
	if(adjtimex(&tmx) < 0) {
	    PERROR(THIS_COMPONENT"Could not get frequency of clock %s ", self->name);
	    return 0;
	}

	return((tmx.freq + 0.0) / 65.536);

}
예제 #21
0
파일: adjtimex02.c 프로젝트: MohdVara/ltp
/*
 *cleanup() -  performs all ONE TIME cleanup for this test at
 *		completion or premature exit.
 */
void cleanup(void)
{

	tim_save.modes = SET_MODE;
	/* Restore saved parameters */
	if ((adjtimex(&tim_save)) == -1) {
		tst_resm(TWARN, "Failed to restore saved parameters");
	}
	/*
	 * print timing stats if that option was specified.
	 * print errno log if that option was specified.
	 */
	TEST_CLEANUP;
}
예제 #22
0
파일: sys.c 프로젝트: astraw/ptpd
Boolean adjFreq(Integer32 adj)
{
  struct timex t;
  
  if(adj > ADJ_FREQ_MAX)
    adj = ADJ_FREQ_MAX;
  else if(adj < -ADJ_FREQ_MAX)
    adj = -ADJ_FREQ_MAX;
  
  t.modes = MOD_FREQUENCY;
  t.freq = adj*((1<<16)/1000);
  
  return !adjtimex(&t);
}
예제 #23
0
static int get_current_freq(void)
{
	/* OS dependent routine to get the current value of clock frequency.
	 */
#ifdef __linux__
	struct timex txc;
	txc.modes=0;
	if (adjtimex(&txc) < 0) {
		perror("adjtimex"); exit(1);
	}
	return txc.freq;
#else
	return 0;
#endif
}
예제 #24
0
파일: adjtimex01.c 프로젝트: AbhiramiP/ltp
static void setup(void)
{
	tst_require_root(NULL);

	tim_save.modes = 0;

	tst_sig(NOFORK, DEF_HANDLER, cleanup);

	TEST_PAUSE;

	/* Save current parameters in tim_save */
	if ((adjtimex(&tim_save)) == -1)
		tst_brkm(TBROK | TERRNO, cleanup,
			 "failed to save current parameters");
}
예제 #25
0
파일: freq-step.c 프로젝트: mdamt/linux
static void set_frequency(double freq)
{
	struct timex txc;
	int tick_offset;

	tick_offset = 1e6 * freq / user_hz;

	txc.modes = ADJ_TICK | ADJ_FREQUENCY;
	txc.tick = 1000000 / user_hz + tick_offset;
	txc.freq = (1e6 * freq - user_hz * tick_offset) * (1 << 16);

	if (adjtimex(&txc) < 0) {
		perror("[FAIL] adjtimex");
		ksft_exit_fail();
	}
}
예제 #26
0
static int set_freq(int new_freq)
{
	/* OS dependent routine to set a new value of clock frequency.
	 */
#ifdef __linux__
	struct timex txc;
	txc.modes = ADJ_FREQUENCY;
	txc.freq = new_freq;
	if (adjtimex(&txc) < 0) {
		perror("adjtimex"); exit(1);
	}
	return txc.freq;
#else
	return 0;
#endif
}
예제 #27
0
static int get_current_freq(void)
{
	/* OS dependent routine to get the current value of clock frequency.
	 */
#ifdef __linux__
	struct timex txc;
	txc.modes=0;
	if (adjtimex(&txc) < 0) {
		logit(LOG_ERR, errno, "Failed adjtimex(GET)");
		exit(1);
	}
	return txc.freq;
#else
	return 0;
#endif
}
예제 #28
0
Bool
TimeSync_PLLSetFrequency(int64 ppmCorrection)
{
   struct timex tx;
   int error;

   tx.modes = ADJ_FREQUENCY;
   tx.freq = ppmCorrection;

   error = adjtimex(&tx);
   if (error == -1) {
      g_debug("%s: adjtimex failed: %d %s\n", __FUNCTION__,
              error, strerror(errno));
         return FALSE;
   }
   TimeSyncLogPLLState(__FUNCTION__, &tx);

   return TRUE;
}
예제 #29
0
/* setup() - performs all ONE TIME setup for this test */
void setup()
{
	/* Check whether we are root */
	if (geteuid() != 0) {
		tst_brkm(TBROK, tst_exit, "Test must be run as root");
	}

	tim_save.modes = 0;

	/* capture signals */
	tst_sig(NOFORK, DEF_HANDLER, cleanup);

	/* Pause if that option was specified */
	TEST_PAUSE;

	/* Save current parameters in tim_save */
	if ((adjtimex(&tim_save)) == -1) {
		tst_brkm(TBROK, cleanup, "Failed to save current parameters");
	}
}				/* End setup() */
예제 #30
0
int main(int ac, char **av)
{

	int lc;			/* loop counter */
	char *msg;		/* message returned from parse_opts */

	/* parse standard options */
	if ((msg = parse_opts(ac, av, (option_t *) NULL, NULL))
	    != (char *)NULL) {
		tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg);
	}

	/* perform global setup for test */
	setup();

	/* check looping state if -i option given */
	for (lc = 0; TEST_LOOPING(lc); lc++) {

		/* reset Tst_count in case we are looping. */
		Tst_count = 0;

		/* Call adjtimex(2) */
		tim_save.modes = SET_MODE;

		TEST(adjtimex(&tim_save));

		if ((TEST_RETURN >= 0) && (TEST_RETURN <= 5)) {
			tst_resm(TPASS, "adjtimex() returned %ld", TEST_RETURN);
		} else {
			tst_resm(TFAIL|TTERRNO, "Test Failed, adjtimex()"
				 "returned %ld", TEST_RETURN);
		}
	}			/* End for TEST_LOOPING */

	/* cleanup and exit */
	cleanup();

	 /*NOTREACHED*/ return 0;

}				/* End main */