The info is exposed via #vars. Signed-off-by: Barret Rhoden <[email protected]> --- user/parlib/include/parlib/sysinfo.h | 13 +++++++++++++ user/parlib/sysinfo.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 user/parlib/include/parlib/sysinfo.h create mode 100644 user/parlib/sysinfo.c
diff --git a/user/parlib/include/parlib/sysinfo.h b/user/parlib/include/parlib/sysinfo.h new file mode 100644 index 000000000000..2584d3d52be4 --- /dev/null +++ b/user/parlib/include/parlib/sysinfo.h @@ -0,0 +1,13 @@ +/* Copyright (c) 2016 Google Inc. + * Barret Rhoden <[email protected]> + * See LICENSE for details. + * + * Helper functions to query information about the system. */ + +#pragma once + +__BEGIN_DECLS + +int get_num_pcores(void); + +__END_DECLS diff --git a/user/parlib/sysinfo.c b/user/parlib/sysinfo.c new file mode 100644 index 000000000000..50ff1dc066d5 --- /dev/null +++ b/user/parlib/sysinfo.c @@ -0,0 +1,36 @@ +/* Copyright (c) 2016 Google Inc. + * Barret Rhoden <[email protected]> + * See LICENSE for details. + * + * Helper functions to query information about the system. */ + +#include <stdio.h> +#include <stdlib.h> +#include <stdint.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <assert.h> +#include <unistd.h> + +#include <parlib/sysinfo.h> +#include <ros/arch/arch.h> + +int get_num_pcores(void) +{ + int fd; + int ret; + char buf[128]; + + fd = open("#vars/num_cores!dw", O_RDONLY); + if (fd < 0) + return MAX_NUM_CORES; + if (read(fd, buf, sizeof(buf)) < 0) { + /* major bug */ + perror("#vars read"); + exit(-1); + } + ret = strtol(buf, 0, 0); + close(fd); + return ret; +} -- 2.7.0.rc3.207.g0ac5344 -- You received this message because you are subscribed to the Google Groups "Akaros" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. For more options, visit https://groups.google.com/d/optout.
