Commit 92773ed6 authored by Felix Janda's avatar Felix Janda Committed by Mike Frysinger

Add utility function ticks_per_second() to get jiffies per second (aka HZ)

Currently uses sysconf(_SC_TC_CLK) to be more portable.
parent 9bdfd2cc
...@@ -165,6 +165,7 @@ int rprint_cache6(int ext, int numeric) ...@@ -165,6 +165,7 @@ int rprint_cache6(int ext, int numeric)
int type, refcnt, prefix_len, location, state, gc; int type, refcnt, prefix_len, location, state, gc;
long tstamp, expire, ndflags, reachable, stale, delete; long tstamp, expire, ndflags, reachable, stale, delete;
FILE *fp = fopen(_PATH_PROCNET_NDISC, "r"); FILE *fp = fopen(_PATH_PROCNET_NDISC, "r");
long clk_tck = ticks_per_second();
char addr6p[8][5], haddrp[6][3]; char addr6p[8][5], haddrp[6][3];
if (!fp) { if (!fp) {
...@@ -257,11 +258,11 @@ int rprint_cache6(int ext, int numeric) ...@@ -257,11 +258,11 @@ int rprint_cache6(int ext, int numeric)
stale = reachable > tstamp ? reachable - tstamp : 0; stale = reachable > tstamp ? reachable - tstamp : 0;
delete = gc > tstamp ? gc - tstamp : 0; delete = gc > tstamp ? gc - tstamp : 0;
if (ext != 2) { if (ext != 2) {
printf(" %-9ld ", stale / HZ); printf(" %-9ld ", stale / clk_tck);
if (refcnt) if (refcnt)
printf(" * "); printf(" * ");
else else
printf(" %-7ld ", delete / HZ); printf(" %-7ld ", delete / clk_tck);
} }
printf("\n"); printf("\n");
} }
......
...@@ -64,6 +64,7 @@ static int INET_setroute(int action, int options, char **args) ...@@ -64,6 +64,7 @@ static int INET_setroute(int action, int options, char **args)
struct rtentry rt; struct rtentry rt;
char target[128], gateway[128] = "NONE", netmask[128] = "default"; char target[128], gateway[128] = "NONE", netmask[128] = "default";
int xflag, isnet; int xflag, isnet;
long clk_tck = ticks_per_second();
xflag = 0; xflag = 0;
...@@ -199,9 +200,9 @@ static int INET_setroute(int action, int options, char **args) ...@@ -199,9 +200,9 @@ static int INET_setroute(int action, int options, char **args)
#if HAVE_RTF_IRTT #if HAVE_RTF_IRTT
rt.rt_flags |= RTF_IRTT; rt.rt_flags |= RTF_IRTT;
rt.rt_irtt = atoi(*(args - 1)); rt.rt_irtt = atoi(*(args - 1));
rt.rt_irtt *= (HZ / 100); /* FIXME */ rt.rt_irtt *= (clk_tck / 100); /* FIXME */
#if 0 /* FIXME: do we need to check anything of this? */ #if 0 /* FIXME: do we need to check anything of this? */
if (rt.rt_irtt < 1 || rt.rt_irtt > (120 * HZ)) { if (rt.rt_irtt < 1 || rt.rt_irtt > (120 * clk_tck)) {
fprintf(stderr, _("route: Invalid initial rtt.\n")); fprintf(stderr, _("route: Invalid initial rtt.\n"));
return usage(E_OPTERR); return usage(E_OPTERR);
} }
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/utsname.h> #include <sys/utsname.h>
#include <unistd.h>
#include "util.h" #include "util.h"
...@@ -51,6 +52,10 @@ int kernel_version(void) ...@@ -51,6 +52,10 @@ int kernel_version(void)
return KRELEASE(major, minor, patch); return KRELEASE(major, minor, patch);
} }
long ticks_per_second(void)
{
return sysconf(_SC_CLK_TCK);
}
/* Like strncpy but make sure the resulting string is always 0 terminated. */ /* Like strncpy but make sure the resulting string is always 0 terminated. */
char *safe_strncpy(char *dst, const char *src, size_t size) char *safe_strncpy(char *dst, const char *src, size_t size)
......
...@@ -10,6 +10,7 @@ char *xstrdup(const char *src); ...@@ -10,6 +10,7 @@ char *xstrdup(const char *src);
int kernel_version(void); int kernel_version(void);
#define KRELEASE(maj,min,patch) ((maj) * 10000 + (min)*1000 + (patch)) #define KRELEASE(maj,min,patch) ((maj) * 10000 + (min)*1000 + (patch))
long ticks_per_second(void);
int nstrcmp(const char *, const char *); int nstrcmp(const char *, const char *);
......
...@@ -972,6 +972,7 @@ static void tcp_do_one(int lnr, const char *line, const char *prot) ...@@ -972,6 +972,7 @@ static void tcp_do_one(int lnr, const char *line, const char *prot)
#else #else
struct sockaddr_in localaddr, remaddr; struct sockaddr_in localaddr, remaddr;
#endif #endif
long clk_tck = ticks_per_second();
if (lnr == 0) if (lnr == 0)
return; return;
...@@ -1032,27 +1033,27 @@ static void tcp_do_one(int lnr, const char *line, const char *prot) ...@@ -1032,27 +1033,27 @@ static void tcp_do_one(int lnr, const char *line, const char *prot)
case 1: case 1:
snprintf(timers, sizeof(timers), _("on (%2.2f/%ld/%d)"), snprintf(timers, sizeof(timers), _("on (%2.2f/%ld/%d)"),
(double) time_len / HZ, retr, timeout); (double) time_len / clk_tck, retr, timeout);
break; break;
case 2: case 2:
snprintf(timers, sizeof(timers), _("keepalive (%2.2f/%ld/%d)"), snprintf(timers, sizeof(timers), _("keepalive (%2.2f/%ld/%d)"),
(double) time_len / HZ, retr, timeout); (double) time_len / clk_tck, retr, timeout);
break; break;
case 3: case 3:
snprintf(timers, sizeof(timers), _("timewait (%2.2f/%ld/%d)"), snprintf(timers, sizeof(timers), _("timewait (%2.2f/%ld/%d)"),
(double) time_len / HZ, retr, timeout); (double) time_len / clk_tck, retr, timeout);
break; break;
case 4: case 4:
snprintf(timers, sizeof(timers), _("probe (%2.2f/%ld/%d)"), snprintf(timers, sizeof(timers), _("probe (%2.2f/%ld/%d)"),
(double) time_len / HZ, retr, timeout); (double) time_len / clk_tck, retr, timeout);
break; break;
default: default:
snprintf(timers, sizeof(timers), _("unkn-%d (%2.2f/%ld/%d)"), snprintf(timers, sizeof(timers), _("unkn-%d (%2.2f/%ld/%d)"),
timer_run, (double) time_len / HZ, retr, timeout); timer_run, (double) time_len / clk_tck, retr, timeout);
break; break;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment