Index: uspace/app/dummy_load/Makefile
===================================================================
--- uspace/app/dummy_load/Makefile	(revision d8e3467358e76057c47d6b02a28d442a944676e6)
+++ uspace/app/dummy_load/Makefile	(revision 9dae191e774f517d5430fc726e4aef5787b1fcd0)
@@ -29,5 +29,5 @@
 
 USPACE_PREFIX = ../..
-BINARY = dummy_load
+# BINARY = dummy_load
 
 SOURCES = \
Index: uspace/app/ps/func.c
===================================================================
--- uspace/app/ps/func.c	(revision d8e3467358e76057c47d6b02a28d442a944676e6)
+++ uspace/app/ps/func.c	(revision 9dae191e774f517d5430fc726e4aef5787b1fcd0)
@@ -33,9 +33,8 @@
 /**
  * @file
- * @brief	Miscellaneous functions.
+ * @brief Miscellaneous functions.
  */
 
-#include <stdio.h>
-
+#include <stdint.h>
 #include "func.h"
 
Index: uspace/app/ps/func.h
===================================================================
--- uspace/app/ps/func.h	(revision d8e3467358e76057c47d6b02a28d442a944676e6)
+++ uspace/app/ps/func.h	(revision 9dae191e774f517d5430fc726e4aef5787b1fcd0)
@@ -36,4 +36,6 @@
 #define FUNC_H_
 
+#include <stdint.h>
+
 extern void order(const uint64_t val, uint64_t *rv, char *suffix);
 
Index: uspace/app/ps/ps.c
===================================================================
--- uspace/app/ps/ps.c	(revision d8e3467358e76057c47d6b02a28d442a944676e6)
+++ uspace/app/ps/ps.c	(revision 9dae191e774f517d5430fc726e4aef5787b1fcd0)
@@ -38,63 +38,71 @@
 #include <task.h>
 #include <thread.h>
-#include <ps.h>
+#include <stats.h>
 #include <errno.h>
 #include <stdlib.h>
 #include <malloc.h>
-#include <load.h>
-#include <sysinfo.h>
-
+#include <inttypes.h>
+#include <arg_parse.h>
 #include "func.h"
 
-#define TASK_COUNT 10
-#define THREAD_COUNT 50
-
-#define ECHOLOAD1(x) ((x) >> 11)
-#define ECHOLOAD2(x) (((x) & 0x7ff) / 2)
+#define NAME  "ps"
+
+#define TASK_COUNT    10
+#define THREAD_COUNT  50
+
+#define PRINT_LOAD1(x)  ((x) >> 11)
+#define PRINT_LOAD2(x)  (((x) & 0x7ff) / 2)
 
 /** Thread states */
-static const char *thread_states[] = {
-	"Invalid",
-	"Running",
-	"Sleeping",
-	"Ready",
-	"Entering",
-	"Exiting",
-	"Lingering"
-}; 
+//static const char *thread_states[] = {
+//	"Invalid",
+//	"Running",
+//	"Sleeping",
+//	"Ready",
+//	"Entering",
+//	"Exiting",
+//	"Lingering"
+//};
 
 static void list_tasks(void)
 {
-	int task_count = TASK_COUNT;
-	task_id_t *tasks = malloc(task_count * sizeof(task_id_t));
-	int result = get_task_ids(tasks, sizeof(task_id_t) * task_count);
-
-	while (result > task_count) {
-		task_count *= 2;
-		tasks = realloc(tasks, task_count * sizeof(task_id_t));
-		result = get_task_ids(tasks, sizeof(task_id_t) * task_count);
-	}
-
-	printf("      ID  Threads      Mem       uCycles       kCycles   Cycle fault Name\n");
-
-	int i;
-	for (i = 0; i < result; ++i) {
-		task_info_t taskinfo;
-		get_task_info(tasks[i], &taskinfo);
-		uint64_t mem, ucycles, kcycles;
-		char memsuffix, usuffix, ksuffix;
-		order(taskinfo.virt_mem, &mem, &memsuffix);
-		order(taskinfo.ucycles, &ucycles, &usuffix);
-		order(taskinfo.kcycles, &kcycles, &ksuffix);
-		printf("%8llu %8u %8llu%c %12llu%c %12llu%c %s\n", tasks[i],
-			taskinfo.thread_count, mem, memsuffix, ucycles, usuffix,
-			kcycles, ksuffix, taskinfo.name);
-	}
-
-	free(tasks);
-}
-
-static void list_threads(task_id_t taskid)
-{
+	size_t count;
+	task_id_t *ids =
+	    (task_id_t *) get_stats_tasks(&count);
+	
+	if (ids == NULL) {
+		fprintf(stderr, "%s: Unable to get tasks\n", NAME);
+		return;
+	}
+	
+	printf("      ID  Threads      Mem       uCycles       kCycles   Name\n");
+	
+	size_t i;
+	for (i = 0; i < count; i++) {
+		stats_task_t *stats_task = get_stats_task(ids[i]);
+		if (stats_task != NULL) {
+			uint64_t virtmem, ucycles, kcycles;
+			char vmsuffix, usuffix, ksuffix;
+			
+			order(stats_task->virtmem, &virtmem, &vmsuffix);
+			order(stats_task->ucycles, &ucycles, &usuffix);
+			order(stats_task->kcycles, &kcycles, &ksuffix);
+			
+			printf("%8" PRIu64 "%8u %8" PRIu64"%c %12"
+			    PRIu64"%c %12" PRIu64"%c %s\n", ids[i], stats_task->threads,
+			    virtmem, vmsuffix, ucycles, usuffix, kcycles, ksuffix,
+			    stats_task->name);
+			
+			free(stats_task);
+		} else
+			printf("%8" PRIu64 "\n", ids[i]);
+	}
+	
+	free(ids);
+}
+
+static void list_threads(task_id_t task_id)
+{
+	/* TODO:
 	size_t thread_count = THREAD_COUNT;
 	thread_info_t *threads = malloc(thread_count * sizeof(thread_info_t));
@@ -128,78 +136,144 @@
 	}
 
-	free(threads);
-}
-
-static void echo_load(void)
-{
-	unsigned long load[3];
-	get_load(load);
-	printf("load avarage: ");
-	print_load_fragment(load[0], 2);
-	puts(" ");
-	print_load_fragment(load[1], 2);
-	puts(" ");
-	print_load_fragment(load[2], 2);
-	puts("\n");
-}
-
-static void echo_cpus(void)
-{
-	size_t cpu_count = sysinfo_value("cpu.count");
-	printf("Found %u cpu's:\n", cpu_count);
-	uspace_cpu_info_t *cpus = malloc(cpu_count * sizeof(uspace_cpu_info_t));
-	get_cpu_info(cpus);
-	size_t i;
-	for (i = 0; i < cpu_count; ++i) {
-		printf("%2u (%4u Mhz): Busy ticks: %6llu, Idle ticks: %6llu\n", cpus[i].id,
-				(size_t)cpus[i].frequency_mhz, cpus[i].busy_ticks, cpus[i].idle_ticks);
-	}
+	free(threads); */
+}
+
+static void print_load(void)
+{
+	size_t count;
+	load_t *load = get_stats_load(&count);
+	
+	if (load == NULL) {
+		fprintf(stderr, "%s: Unable to get load\n", NAME);
+		return;
+	}
+	
+	printf("%s: Load avarage: ", NAME);
+	
+	size_t i;
+	for (i = 0; i < count; i++) {
+		if (i > 0)
+			printf(" ");
+		
+		print_load_fragment(load[i], 2);
+	}
+	
+	printf("\n");
+	
+	free(load);
+}
+
+static void list_cpus(void)
+{
+	size_t count;
+	stats_cpu_t *cpus = get_stats_cpus(&count);
+	
+	if (cpus == NULL) {
+		fprintf(stderr, "%s: Unable to get CPU statistics\n", NAME);
+		return;
+	}
+	
+	printf("%s: %u CPU(s) detected\n", NAME, count);
+	
+	size_t i;
+	for (i = 0; i < count; i++) {
+		printf("cpu%u: %" PRIu16 " MHz, busy ticks: "
+		    "%" PRIu64 ", idle ticks: %" PRIu64 "\n",
+		    cpus[i].id, cpus[i].frequency_mhz, cpus[i].busy_ticks,
+		    cpus[i].idle_ticks);
+	}
+	
+	free(cpus);
 }
 
 static void usage()
 {
-	printf("Usage: ps [-t pid|-l|-c]\n");
+	printf(
+	    "Usage: ps [-t task_id] [-l] [-c]\n" \
+	    "\n" \
+	    "Options:\n" \
+	    "\t-t task_id\n" \
+	    "\t--task=task_id\n" \
+	    "\t\tList threads of the given task\n" \
+	    "\n" \
+	    "\t-l\n" \
+	    "\t--load\n" \
+	    "\t\tPrint system load\n" \
+	    "\n" \
+	    "\t-c\n" \
+	    "\t--cpu\n" \
+	    "\t\tList CPUs\n" \
+	    "\n" \
+	    "\t-h\n" \
+	    "\t--help\n" \
+	    "\t\tPrint this usage information\n"
+	    "\n" \
+	    "Without any options all tasks are listed\n"
+	);
 }
 
 int main(int argc, char *argv[])
 {
-	--argc; ++argv;
-
-	if (argc > 0)
-	{
-		if (str_cmp(*argv, "-t") == 0) {
-			--argc; ++argv;
-			if (argc != 1) {
-				printf("Bad argument count!\n");
-				usage();
-				exit(1);
+	bool toggle_tasks = true;
+	bool toggle_threads = false;
+	bool toggle_load = false;
+	bool toggle_cpus = false;
+	
+	task_id_t task_id;
+	
+	int i;
+	for (i = 1; i < argc; i++) {
+		int off;
+		
+		/* Usage */
+		if ((off = arg_parse_short_long(argv[i], "-h", "--help")) != -1) {
+			usage();
+			return 0;
+		}
+		
+		/* Load */
+		if ((off = arg_parse_short_long(argv[i], "-l", "--load")) != -1) {
+			toggle_tasks = false;
+			toggle_load = true;
+			continue;
+		}
+		
+		/* CPUs */
+		if ((off = arg_parse_short_long(argv[i], "-c", "--cpus")) != -1) {
+			toggle_tasks = false;
+			toggle_cpus = true;
+			continue;
+		}
+		
+		/* Threads */
+		if ((off = arg_parse_short_long(argv[i], "-t", "--task=")) != -1) {
+			// TODO: Support for 64b range
+			int tmp;
+			int ret = arg_parse_int(argc, argv, &i, &tmp, off);
+			if (ret != EOK) {
+				printf("%s: Malformed task_id '%s'\n", NAME, argv[i]);
+				return -1;
 			}
-			task_id_t taskid = strtol(*argv, NULL, 10);
-			list_threads(taskid);
-		} else if (str_cmp(*argv, "-l") == 0) {
-			--argc; ++argv;
-			if (argc != 0) {
-				printf("Bad argument count!\n");
-				usage();
-				exit(1);
-			}
-			echo_load();
-		} else if (str_cmp(*argv, "-c") == 0) {
-			--argc; ++argv;
-			if (argc != 0) {
-				printf("Bad argument count!\n");
-				usage();
-				exit(1);
-			}
-			echo_cpus();
-		} else {
-			printf("Unknown argument %s!\n", *argv);
-			usage();
-			exit(1);
-		}
-	} else {
+			
+			task_id = tmp;
+			
+			toggle_tasks = false;
+			toggle_threads = true;
+			continue;
+		}
+	}
+	
+	if (toggle_tasks)
 		list_tasks();
-	}
-
+	
+	if (toggle_threads)
+		list_threads(task_id);
+	
+	if (toggle_load)
+		print_load();
+	
+	if (toggle_cpus)
+		list_cpus();
+	
 	return 0;
 }
Index: uspace/app/top/Makefile
===================================================================
--- uspace/app/top/Makefile	(revision d8e3467358e76057c47d6b02a28d442a944676e6)
+++ uspace/app/top/Makefile	(revision 9dae191e774f517d5430fc726e4aef5787b1fcd0)
@@ -29,5 +29,5 @@
 
 USPACE_PREFIX = ../..
-BINARY = top
+# BINARY = top
 
 SOURCES = \
Index: uspace/app/top/func.c
===================================================================
--- uspace/app/top/func.c	(revision d8e3467358e76057c47d6b02a28d442a944676e6)
+++ uspace/app/top/func.c	(revision 9dae191e774f517d5430fc726e4aef5787b1fcd0)
@@ -33,9 +33,8 @@
 /**
  * @file
- * @brief	Miscellaneous functions.
+ * @brief Miscellaneous functions.
  */
 
-#include <stdio.h>
-
+#include <stdint.h>
 #include "func.h"
 
Index: uspace/app/top/func.h
===================================================================
--- uspace/app/top/func.h	(revision d8e3467358e76057c47d6b02a28d442a944676e6)
+++ uspace/app/top/func.h	(revision 9dae191e774f517d5430fc726e4aef5787b1fcd0)
@@ -27,5 +27,5 @@
  */
 
-/** @addtogroup ps
+/** @addtogroup top
  * @{
  */
@@ -36,5 +36,7 @@
 #define FUNC_H_
 
-extern void order(const uint64_t val, uint64_t *rv, char *suffix);
+#include <stdint.h>
+
+extern void order(const uint64_t, uint64_t *, char *);
 
 #endif
Index: uspace/app/uptime/uptime.c
===================================================================
--- uspace/app/uptime/uptime.c	(revision d8e3467358e76057c47d6b02a28d442a944676e6)
+++ uspace/app/uptime/uptime.c	(revision 9dae191e774f517d5430fc726e4aef5787b1fcd0)
@@ -28,5 +28,5 @@
 
 /** @addtogroup uptime
- * @brief Echo system uptime.
+ * @brief Print system uptime.
  * @{
  */
@@ -36,39 +36,45 @@
 
 #include <stdio.h>
-#include <uptime.h>
+#include <stats.h>
 #include <sys/time.h>
-#include <load.h>
+#include <inttypes.h>
 
-#define DAY 86400
-#define HOUR 3600
-#define MINUTE 60
+#define NAME  "uptime"
+
+#define DAY     86400
+#define HOUR    3600
+#define MINUTE  60
 
 int main(int argc, char *argv[])
 {
 	struct timeval time;
-	uint64_t sec;
 	if (gettimeofday(&time, NULL) != 0) {
-		printf("Cannot get time of day!\n");
-		return 1;
+		fprintf(stderr, "%s: Cannot get time of day\n", NAME);
+		return -1;
 	}
-	sec = time.tv_sec;
-	printf("%02llu:%02llu:%02llu", (sec % DAY) / HOUR,
-			(sec % HOUR) / MINUTE, sec % MINUTE);
-
-	uint64_t uptime;
-	get_uptime(&uptime);
-	printf(", up %4llu days, %02llu:%02llu:%02llu",
-		uptime / DAY, (uptime % DAY) / HOUR, (uptime % HOUR) / MINUTE, uptime % MINUTE);
-
-	unsigned long load[3];
-	get_load(load);
-	puts(", load avarage: ");
-	print_load_fragment(load[0], 2);
-	puts(" ");
-	print_load_fragment(load[1], 2);
-	puts(" ");
-	print_load_fragment(load[2], 2);
-
-	puts("\n");
+	
+	uint64_t sec = time.tv_sec;
+	printf("%02" PRIu64 ":%02" PRIu64 ":%02" PRIu64, (sec % DAY) / HOUR,
+	    (sec % HOUR) / MINUTE, sec % MINUTE);
+	
+	sysarg_t uptime = get_stats_uptime();
+	printf(", up %u days, %02u:%02u:%02u", uptime / DAY,
+	    (uptime % DAY) / HOUR, (uptime % HOUR) / MINUTE, uptime % MINUTE);
+	
+	size_t count;
+	load_t *load = get_stats_load(&count);
+	if (load != NULL) {
+		printf(", load avarage: ");
+		
+		size_t i;
+		for (i = 0; i < count; i++) {
+			if (i > 0)
+				printf(" ");
+			
+			print_load_fragment(load[i], 2);
+		}
+	}
+	
+	printf("\n");
 	return 0;
 }
Index: uspace/lib/c/Makefile
===================================================================
--- uspace/lib/c/Makefile	(revision d8e3467358e76057c47d6b02a28d442a944676e6)
+++ uspace/lib/c/Makefile	(revision 9dae191e774f517d5430fc726e4aef5787b1fcd0)
@@ -96,9 +96,5 @@
 	generic/stacktrace.c \
 	generic/arg_parse.c \
-	generic/ps.c \
-	generic/cpuinfo.c \
-	generic/meminfo.c \
-	generic/load.c \
-	generic/uptime.c
+	generic/stats.c
 
 SOURCES = \
Index: uspace/lib/c/generic/cpuinfo.c
===================================================================
--- uspace/lib/c/generic/cpuinfo.c	(revision d8e3467358e76057c47d6b02a28d442a944676e6)
+++ 	(revision )
@@ -1,52 +1,0 @@
-/*
- * Copyright (c) 2010 Stanislav Kozina
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup libc
- * @{
- */
-/** @file
- */
-
-#include <libc.h>
-#include <ps.h>
-
-/** Get infos about system CPUs.
- *
- * @param cpus		Pointer where info structures will be stored.
- * 			Use \ref sysinfo() to get cpu.count value.
- *
- * @return		EOK.
- *
- */
-int get_cpu_info(uspace_cpu_info_t *cpus)
-{
-	return __SYSCALL1(SYS_PS_GET_CPU_INFO, (sysarg_t) cpus);
-}
-
-/** @}
- */
Index: uspace/lib/c/generic/load.c
===================================================================
--- uspace/lib/c/generic/load.c	(revision d8e3467358e76057c47d6b02a28d442a944676e6)
+++ 	(revision )
@@ -1,66 +1,0 @@
-/*
- * Copyright (c) 2010 Stanislav Kozina
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup libc
- * @{
- */
-/** @file
- */
-
-#include <load.h>
-#include <libc.h>
-#include <stdio.h>
-
-/** Get current system load
- *
- * @param load		Pointer where load will be stored.
- *
- * @return		EOK.
- *
- */
-int get_load(unsigned long *load)
-{
-	return __SYSCALL1(SYS_PS_GET_LOAD, (sysarg_t) load);
-}
-
-void print_load_fragment(unsigned long upper, int dec_length)
-{
-	int i;
-	/* Magic value from BSD */
-	unsigned long lower = 65536;
-	/* Print whole part */
-	printf("%u.", upper / lower);
-	unsigned long rest = (upper % lower) * 10;
-	for (i = 0; i < dec_length; ++i) {
-		printf("%d", rest / lower);
-		rest = (rest % lower) * 10;
-	}
-}
-
-/** @}
- */
Index: uspace/lib/c/generic/meminfo.c
===================================================================
--- uspace/lib/c/generic/meminfo.c	(revision d8e3467358e76057c47d6b02a28d442a944676e6)
+++ 	(revision )
@@ -1,51 +1,0 @@
-/*
- * Copyright (c) 2010 Stanislav Kozina
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup libc
- * @{
- */
-/** @file
- */
-
-#include <libc.h>
-#include <ps.h>
-
-/** Get infos about system memory.
- *
- * @param cpus		Pointer where info structures will be stored.
- *
- * @return		EOK.
- *
- */
-int get_mem_info(uspace_mem_info_t *meminfo)
-{
-	return __SYSCALL1(SYS_PS_GET_MEM_INFO, (sysarg_t) meminfo);
-}
-
-/** @}
- */
Index: uspace/lib/c/generic/ps.c
===================================================================
--- uspace/lib/c/generic/ps.c	(revision d8e3467358e76057c47d6b02a28d442a944676e6)
+++ 	(revision )
@@ -1,83 +1,0 @@
-/*
- * Copyright (c) 2010 Stanislav Kozina
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup libc
- * @{
- */
-/** @file
- */
-
-#include <task.h>
-#include <thread.h>
-#include <ps.h>
-#include <libc.h>
-
-/** Get the list of task ids.
- *
- * @param ids		Pointer to space where list of ids will be stored.
- * @param size		Total size of allocated space under ids.
- *
- * @return		Count of written task ids. If higher than size, there
- * 			was not enough space.
- *
- */
-size_t get_task_ids(task_id_t *ids, size_t size)
-{
-	return __SYSCALL2(SYS_PS_GET_TASKS, (sysarg_t) ids, (sysarg_t) size);
-}
-
-/** Get task info.
- *
- * @param id		Id of the task to get info about.
- * @param info		Pointer to out info struct.
- *
- * @return		0 on success.
- *
- */
-int get_task_info(task_id_t id, task_info_t *info)
-{
-	return __SYSCALL2(SYS_PS_GET_TASK_INFO, (sysarg_t) &id, (sysarg_t) info);
-}
-
-/** Get thread infos of the selected task.
- *
- * @param taskid 	Id of the selected task.
- * @param infos		Pointer to out array of thread_info_t structures.
- * @param size		Size of the infos array.
- *
- * @return		Count of written thread_infos. If higher than size, there
- * 			was not enough space.
- *
- */
-size_t get_task_threads(thread_info_t *infos, size_t size)
-{
-	return __SYSCALL2(SYS_PS_GET_THREADS, (sysarg_t) infos, (sysarg_t) size);
-}
-
-/** @}
- */
Index: uspace/lib/c/generic/stats.c
===================================================================
--- uspace/lib/c/generic/stats.c	(revision 9dae191e774f517d5430fc726e4aef5787b1fcd0)
+++ uspace/lib/c/generic/stats.c	(revision 9dae191e774f517d5430fc726e4aef5787b1fcd0)
@@ -0,0 +1,133 @@
+/*
+ * Copyright (c) 2010 Stanislav Kozina
+ * Copyright (c) 2010 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libc
+ * @{
+ */
+/** @file
+ */
+
+#include <stats.h>
+#include <sysinfo.h>
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include <inttypes.h>
+
+#define SYSINFO_STATS_MAX_PATH  64
+
+stats_cpu_t *get_stats_cpus(size_t *count)
+{
+	size_t size = 0;
+	stats_cpu_t *stats_cpus =
+	    (stats_cpu_t *) sysinfo_get_data("system.cpus", &size);
+	
+	assert((size % sizeof(stats_cpu_t)) == 0);
+	
+	*count = size / sizeof(stats_cpu_t);
+	return stats_cpus;
+}
+
+stats_physmem_t *get_stats_physmem(void)
+{
+	size_t size = 0;
+	stats_physmem_t *stats_physmem =
+	    (stats_physmem_t *) sysinfo_get_data("system.physmem", &size);
+	
+	assert((size == sizeof(stats_physmem_t)) || (size == 0));
+	
+	return stats_physmem;
+}
+
+task_id_t *get_stats_tasks(size_t *count)
+{
+	size_t size = 0;
+	task_id_t *ids =
+	    (task_id_t *) sysinfo_get_data("system.tasks", &size);
+	
+	assert((size % sizeof(task_id_t)) == 0);
+	
+	*count = size / sizeof(task_id_t);
+	return ids;
+}
+
+stats_task_t *get_stats_task(task_id_t task_id)
+{
+	char name[SYSINFO_STATS_MAX_PATH];
+	snprintf(name, SYSINFO_STATS_MAX_PATH, "system.tasks.%" PRIu64, task_id);
+	
+	size_t size = 0;
+	stats_task_t *stats_task =
+	    (stats_task_t *) sysinfo_get_data(name, &size);
+	
+	assert((size == sizeof(stats_task_t)) || (size == 0));
+	
+	return stats_task;
+}
+
+load_t *get_stats_load(size_t *count)
+{
+	size_t size = 0;
+	load_t *load =
+	    (load_t *) sysinfo_get_data("system.load", &size);
+	
+	assert((size % sizeof(load_t)) == 0);
+	
+	*count = size / sizeof(load_t);
+	return load;
+}
+
+sysarg_t get_stats_uptime(void)
+{
+	sysarg_t uptime;
+	if (sysinfo_get_value("system.uptime", &uptime) != EOK)
+		uptime = 0;
+	
+	return uptime;
+}
+
+void print_load_fragment(load_t upper, unsigned int dec_length)
+{
+	/* Magic value from BSD */
+	load_t lower = 65536;
+	
+	/* Print the whole part */
+	printf("%u.", upper / lower);
+	
+	load_t rest = (upper % lower) * 10;
+	
+	unsigned int i;
+	for (i = 0; i < dec_length; i++) {
+		printf("%u", rest / lower);
+		rest = (rest % lower) * 10;
+	}
+}
+
+/** @}
+ */
Index: uspace/lib/c/generic/sysinfo.c
===================================================================
--- uspace/lib/c/generic/sysinfo.c	(revision d8e3467358e76057c47d6b02a28d442a944676e6)
+++ uspace/lib/c/generic/sysinfo.c	(revision 9dae191e774f517d5430fc726e4aef5787b1fcd0)
@@ -58,5 +58,5 @@
 }
 
-extern void *sysinfo_get_data(const char *path, size_t *size)
+void *sysinfo_get_data(const char *path, size_t *size)
 {
 	while (true) {
@@ -74,8 +74,8 @@
 			return data;
 		
+		free(data);
+		
 		if (ret != ENOMEM)
 			return NULL;
-		
-		free(data);
 	}
 }
Index: uspace/lib/c/generic/uptime.c
===================================================================
--- uspace/lib/c/generic/uptime.c	(revision d8e3467358e76057c47d6b02a28d442a944676e6)
+++ 	(revision )
@@ -1,51 +1,0 @@
-/*
- * Copyright (c) 2010 Stanislav Kozina
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup libc
- * @{
- */
-/** @file
- */
-
-#include <libc.h>
-#include <uptime.h>
-
-/** Get current system uptime
- *
- * @param load		Pointer where uptime will be stored.
- *
- * @return		EOK.
- *
- */
-int get_uptime(uint64_t *uptime)
-{
-	return __SYSCALL1(SYS_PS_GET_UPTIME, (sysarg_t) uptime);
-}
-
-/** @}
- */
Index: uspace/lib/c/include/load.h
===================================================================
--- uspace/lib/c/include/load.h	(revision d8e3467358e76057c47d6b02a28d442a944676e6)
+++ 	(revision )
@@ -1,47 +1,0 @@
-/*
- * Copyright (c) 2010 Stanislav Kozina
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup libc
- * @{
- */
-/** @file
- */ 
-
-#ifndef LIBC_LOAD_H_
-#define LIBC_LOAD_H_
-
-#include <sys/types.h>
-#include <libarch/types.h>
-
-extern int get_load(unsigned long *load);
-extern void print_load_fragment(unsigned long upper, int dec_length);
-
-#endif
-
-/** @}
- */
Index: uspace/lib/c/include/ps.h
===================================================================
--- uspace/lib/c/include/ps.h	(revision d8e3467358e76057c47d6b02a28d442a944676e6)
+++ 	(revision )
@@ -1,52 +1,0 @@
-/*
- * Copyright (c) 2010 Stanislav Kozina
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup libc
- * @{
- */
-/** @file
- */ 
-
-#ifndef LIBC_PS_H_
-#define LIBC_PS_H_
-
-#include <task.h>
-#include <kernel/ps/taskinfo.h>
-#include <kernel/ps/cpuinfo.h>
-#include <kernel/ps/meminfo.h>
-
-extern int get_cpu_info(uspace_cpu_info_t *cpus);
-extern int get_mem_info(uspace_mem_info_t *meminfo);
-extern size_t get_task_ids(task_id_t *ids, size_t size);
-extern int get_task_info(task_id_t id, task_info_t *info);
-extern size_t get_task_threads(thread_info_t *infos, size_t size);
-
-#endif
-
-/** @}
- */
Index: uspace/lib/c/include/stats.h
===================================================================
--- uspace/lib/c/include/stats.h	(revision 9dae191e774f517d5430fc726e4aef5787b1fcd0)
+++ uspace/lib/c/include/stats.h	(revision 9dae191e774f517d5430fc726e4aef5787b1fcd0)
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2010 Stanislav Kozina
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libc
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_STATS_H_
+#define LIBC_STATS_H_
+
+#include <task.h>
+#include <kernel/sysinfo/abi.h>
+
+extern stats_cpu_t *get_stats_cpus(size_t *);
+extern stats_physmem_t *get_stats_physmem(void);
+extern task_id_t *get_stats_tasks(size_t *);
+extern stats_task_t *get_stats_task(task_id_t);
+extern load_t *get_stats_load(size_t *);
+extern sysarg_t get_stats_uptime(void);
+
+extern void print_load_fragment(load_t, unsigned int);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/include/uptime.h
===================================================================
--- uspace/lib/c/include/uptime.h	(revision d8e3467358e76057c47d6b02a28d442a944676e6)
+++ 	(revision )
@@ -1,46 +1,0 @@
-/*
- * Copyright (c) 2010 Stanislav Kozina
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup libc
- * @{
- */
-/** @file
- */ 
-
-#ifndef LIBC_UPTIME_H_
-#define LIBC_UPTIME_H_
-
-#include <sys/types.h>
-#include <libarch/types.h>
-
-extern int get_uptime(uint64_t *uptime);
-
-#endif
-
-/** @}
- */
