From dc0b5a43224999223a246870912b0f292b1980e9 Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Sat, 1 Apr 2017 02:58:16 +0200 Subject: procfs: Provide 'hostinfo'. * procfs/rootdir.c (rootdir_gc_hostinfo): New function. (rootdir_entries): New entry 'hostinfo'. --- procfs/rootdir.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) (limited to 'procfs/rootdir.c') diff --git a/procfs/rootdir.c b/procfs/rootdir.c index 50923f57..b654fa24 100644 --- a/procfs/rootdir.c +++ b/procfs/rootdir.c @@ -1,5 +1,5 @@ /* Hurd /proc filesystem, permanent files of the root directory. - Copyright (C) 2010,13,14 Free Software Foundation, Inc. + Copyright (C) 2010,13,14,17 Free Software Foundation, Inc. This file is part of the GNU Hurd. @@ -472,6 +472,57 @@ rootdir_gc_slabinfo (void *hook, char **contents, ssize_t *contents_len) return err; } +static error_t +rootdir_gc_hostinfo (void *hook, char **contents, ssize_t *contents_len) +{ + error_t err; + FILE *m; + host_basic_info_t basic; + host_sched_info_t sched; + host_load_info_t load; + + m = open_memstream (contents, (size_t *) contents_len); + if (m == NULL) + return ENOMEM; + + err = ps_host_basic_info (&basic); + if (! err) + fprintf (m, "Basic info:\n" + "max_cpus = %10u /* max number of cpus possible */\n" + "avail_cpus = %10u /* number of cpus now available */\n" + "memory_size = %10u /* size of memory in bytes */\n" + "cpu_type = %10u /* cpu type */\n" + "cpu_subtype = %10u /* cpu subtype */\n", + basic->max_cpus, + basic->avail_cpus, + basic->memory_size, + basic->cpu_type, + basic->cpu_subtype); + + err = ps_host_sched_info (&sched); + if (! err) + fprintf (m, "\nScheduling info:\n" + "min_timeout = %10u /* minimum timeout in milliseconds */\n" + "min_quantum = %10u /* minimum quantum in milliseconds */\n", + sched->min_timeout, + sched->min_quantum); + + err = ps_host_load_info (&load); + if (! err) + fprintf (m, "\nLoad info:\n" + "avenrun[3] = { %.2f, %.2f, %.2f }\n" + "mach_factor[3] = { %.2f, %.2f, %.2f }\n", + load->avenrun[0] / (double) LOAD_SCALE, + load->avenrun[1] / (double) LOAD_SCALE, + load->avenrun[2] / (double) LOAD_SCALE, + load->mach_factor[0] / (double) LOAD_SCALE, + load->mach_factor[1] / (double) LOAD_SCALE, + load->mach_factor[2] / (double) LOAD_SCALE); + + fclose (m); + return 0; +} + static error_t rootdir_gc_filesystems (void *hook, char **contents, ssize_t *contents_len) { @@ -744,6 +795,13 @@ static const struct procfs_dir_entry rootdir_entries[] = { .cleanup_contents = procfs_cleanup_contents_with_free, }, }, + { + .name = "hostinfo", + .hook = & (struct procfs_node_ops) { + .get_contents = rootdir_gc_hostinfo, + .cleanup_contents = procfs_cleanup_contents_with_free, + }, + }, { .name = "filesystems", .hook = & (struct procfs_node_ops) { -- cgit v1.2.3