diff options
| author | Jeremie Koenig <jk@jk.fr.eu.org> | 2010-08-22 20:17:54 +0000 |
|---|---|---|
| committer | Jeremie Koenig <jk@jk.fr.eu.org> | 2010-08-30 14:29:51 +0200 |
| commit | 9ab114b6a7e0723135555ed202886f47c032f511 (patch) | |
| tree | 5bf42de63a6a0d579e32f861509a7cab6baef50b | |
| parent | 24fa47890c0d180b807de8abb1a284755cba9c96 (diff) | |
Add --clk-tck to set the clock unit
* main.c (argp_parser, main): Add and parse the --clk-tck option.
* main.h: Publish opt_clk_tck.
* process.c (sc_tc): Use the user-provided clock frequency.
* rootdir.c (rootdir_gc_stat): Likewise.
| -rw-r--r-- | main.c | 40 | ||||
| -rw-r--r-- | main.h | 2 | ||||
| -rw-r--r-- | process.c | 3 | ||||
| -rw-r--r-- | rootdir.c | 3 |
4 files changed, 45 insertions, 3 deletions
@@ -1,5 +1,6 @@ #include <mach.h> #include <hurd.h> +#include <unistd.h> #include <error.h> #include <argp.h> #include <hurd/netfs.h> @@ -7,6 +8,42 @@ #include "proclist.h" #include "rootdir.h" #include "dircat.h" +#include "main.h" + +/* Command-line options */ +int opt_clk_tck; + +static error_t +argp_parser (int key, char *arg, struct argp_state *state) +{ + char *endp; + + switch (key) + { + case 'h': + opt_clk_tck = strtol (arg, &endp, 0); + if (*endp || ! *arg || opt_clk_tck <= 0) + error (1, 0, "--clk-tck: HZ should be a positive integer"); + break; + } + + return 0; +} + +struct argp argp = { + .options = (struct argp_option []) { + { "clk-tck", 'h', "HZ", 0, + "Unit used for the values expressed in system clock ticks " + "(default: sysconf(_SC_CLK_TCK))" }, + {} + }, + .parser = argp_parser, + .doc = "A virtual filesystem emulating the Linux procfs.", + .children = (struct argp_child []) { + { &netfs_std_startup_argp, }, + {} + }, +}; error_t root_make_node (struct node **np) @@ -43,7 +80,8 @@ int main (int argc, char **argv) { mach_port_t bootstrap; - argp_parse (&netfs_std_startup_argp, argc, argv, 0, 0, 0); + opt_clk_tck = sysconf(_SC_CLK_TCK); + argp_parse (&argp, argc, argv, 0, 0, 0); task_get_bootstrap_port (mach_task_self (), &bootstrap); if (bootstrap == MACH_PORT_NULL) @@ -0,0 +1,2 @@ +/* Startup options */ +extern int opt_clk_tck; @@ -8,6 +8,7 @@ #include "procfs.h" #include "procfs_dir.h" #include "process.h" +#include "main.h" /* Implementations for the process_file_desc.get_contents callback. */ @@ -39,7 +40,7 @@ static char state_char (struct proc_stat *ps) static long int sc_tv (time_value_t tv) { double usecs = ((double) tv.seconds) * 1000000 + tv.microseconds; - return usecs * sysconf(_SC_CLK_TCK) / 1000000; + return usecs * opt_clk_tck / 1000000; } static long long int jiff_tv (time_value_t tv) @@ -7,6 +7,7 @@ #include <ps.h> #include "procfs.h" #include "procfs_dir.h" +#include "main.h" /* This implements a directory node with the static files in /proc */ @@ -105,7 +106,7 @@ rootdir_gc_stat (void *hook, void **contents, size_t *contents_len) return EIO; timersub (&time, &boottime, &time); - up_ticks = sysconf(_SC_CLK_TCK) * (time.tv_sec + time.tv_usec / 1000000.); + up_ticks = opt_clk_tck * (time.tv_sec + time.tv_usec / 1000000.); *contents_len = asprintf ((char **) contents, /* Does Mach keeps track of any of this? */ |
