The Time
Scott Henry
scotth at corp.sgi.com
Fri Mar 8 19:03:48 AEST 1991
rb> We have a 4D80GT running 3.3.1 and it looses time at an rate just fast
rb> enough to be annoying. I think I read about a file somewhere which
rb> has a magic number in it that can be adjusted to speed up or slow down
rb> the system clock, but I can't figure out where this file is (or
rb> whether I was dreaming this whole scenario). If anyone else has had
rb> any experience with this I'd appreciate any hints (like what sort of
rb> changes are appropriate, whether the kernal has to be rebuilt, what
rb> man pages to read, etc.)
There is a kernel variable (timetrim) that adjusts the clock rate. It can
be set and read by a couple of SGI-specific system calls. You can look on
the syssgi(2) man page. Since I already have a couple of quick&dirty hack
programs to get & set timetrim, I thought I'd just post them. Timetrim is
in the units ns/sec (10^-9/sec). Values for machines that I've checked
range from (approximately) -560000 < timetrim < 30000. You need to be root
to set timetrim.
#!/bin/sh
# This is a shell archive (shar 3.24)
# made 03/08/1991 16:52 UTC by ???@harlie.c
# Source directory /u2/src/Xntp
#
# existing files will NOT be overwritten
#
# This shar contains:
# length mode name
# ------ ---------- ------------------------------------------
# 394 -rw-r--r-- gettimetrim.c
# 2006 -rw-r--r-- settimetrim.c
#
if touch 2>&1 | fgrep '[-amc]' > /dev/null
then TOUCH=touch
else TOUCH=true
fi
# ============= gettimetrim.c ==============
if test X"$1" != X"-c" -a -f 'gettimetrim.c'; then
echo "File already exists: skipping 'gettimetrim.c'"
else
echo "x - extracting gettimetrim.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > gettimetrim.c &&
X/* This is a quick hack to read the kernel timetrim on SGI machines.
X D. Watson for SGI 11/90
X*/
X
X#include <stdio.h>
X#include <sys/syssgi.h>
X#include <sys/errno.h>
X
X#define MILLION 1000000
X
Xmain(argc, argv)
Xint argc;
Xchar *argv[];
X
X{
X
X extern int errno;
X int tmp;
X
X if ((syssgi(SGI_GETTIMETRIM, &tmp)) == -1) {
X perror("gettimetrim");
X exit(1);
X }
X printf("Timetrim is %d\n", tmp);
X}
SHAR_EOF
$TOUCH -am 1102083390 gettimetrim.c &&
chmod 0644 gettimetrim.c ||
echo "restore of gettimetrim.c failed"
fi
# ============= settimetrim.c ==============
if test X"$1" != X"-c" -a -f 'settimetrim.c'; then
echo "File already exists: skipping 'settimetrim.c'"
else
echo "x - extracting settimetrim.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > settimetrim.c &&
X/* This is a quick hack to read and then write the kernel timetrim
X based on the contents of the file /usr/tmp/.timetrimtest.
X CAUTION: using this program can be dangerous to the sanity of
X any program that sets or depends on the clock!!
X D. Watson for SGI 11/90
X Based on code stolen from timeslave.
X modifications by S. Henry 01/91
X*/
X
X#include <stdio.h>
X#include <sys/syssgi.h>
X#include <sys/errno.h>
X#include <ctype.h>
X
X#define MILLION 1000000
X
Xmain(argc, argv)
Xint argc;
Xchar *argv[];
X
X{
X char *pgmname = argv[0];
X FILE *timetrim_st;
X char *timetrim_fn = 0;
X char *timetrim_pat = "long timetrim = %d;\n";
X extern int errno;
X long oldtimetrim, timetrim;
X int i;
X char *ptr;
X
X if ((syssgi(SGI_GETTIMETRIM, &oldtimetrim)) == -1)
X {
X perror("gettimetrim");
X exit(1);
X }
X printf("Old timetrim was %d\n", oldtimetrim);
X
X if (argc > 1)
X {
X if (strncmp(argv[1], "-f", 2) == 0)
X {
X timetrim_st = EOF;
X if (argc == 2)
X {
X timetrim_fn = "/usr/tmp/.timetrim";
X }
X else if (argv[2][0] == '-' && argv[2][1] == '\0')
X {
X timetrim_st = stdin;
X }
X else
X {
X timetrim_fn = argv[2];
X }
X if (timetrim_st < 0)
X {
X timetrim_st = fopen(timetrim_fn, "r+");
X }
X if (EOF == timetrim_st)
X {
X if (errno != ENOENT)
X {
X (void)fprintf(stderr, "%s: ", pgmname);
X perror(timetrim_fn);
X timetrim_fn = 0;
X }
X }
X i = fscanf(timetrim_st, timetrim_pat, &timetrim);
X }
X else
X {
X timetrim = atol(argv[argc-1]);
X i = 1;
X }
X }
X if (i != EOF)
X {
X if (i != 1 || timetrim > MILLION || timetrim < -MILLION)
X {
X (void)fprintf(stderr,
X "%s: %s: unrecognized contents\n",
X pgmname, timetrim_fn);
X }
X else
X {
X printf("Trimming time by %d\n", timetrim);
X if (0 > syssgi(SGI_SETTIMETRIM, timetrim))
X {
X (void)fprintf(stderr, "%s: ", pgmname);
X perror("syssgi(SETTIMETRIM)");
X }
X }
X }
X if (timetrim_st)
X (void)fclose(timetrim_st);
X timetrim_st = 0;
X}
SHAR_EOF
$TOUCH -am 0304165791 settimetrim.c &&
chmod 0644 settimetrim.c ||
echo "restore of settimetrim.c failed"
fi
exit 0
--
Scott Henry <scotth at sgi.com> / Traveller on Dragon Wings
Information Services, / Help! My disclaimer is missing!
Silicon Graphics, Inc / Politicians no baka!
More information about the Comp.sys.sgi
mailing list