diff --git a/cokernel/smp/x86/bootparam.h b/cokernel/smp/x86/bootparam.h index c016f9ec..5292afaa 100644 --- a/cokernel/smp/x86/bootparam.h +++ b/cokernel/smp/x86/bootparam.h @@ -98,6 +98,9 @@ struct smp_boot_param { unsigned long monitor; unsigned long monitor_size; + unsigned long rusage; + unsigned long rusage_size; + unsigned long nmi_mode_addr; unsigned long dma_address; diff --git a/cokernel/smp/x86/setup.c b/cokernel/smp/x86/setup.c index bc3d28c7..7351f2e0 100644 --- a/cokernel/smp/x86/setup.c +++ b/cokernel/smp/x86/setup.c @@ -223,6 +223,14 @@ int ihk_set_monitor(unsigned long addr, unsigned long size) return 0; } +int ihk_set_rusage(unsigned long addr, unsigned long size) +{ + boot_param->rusage = addr; + boot_param->rusage_size = size; + + return 0; +} + int ihk_set_nmi_mode_addr(unsigned long addr) { boot_param->nmi_mode_addr = addr; diff --git a/linux/core/host_driver.c b/linux/core/host_driver.c index 4d740aa9..1d129cf1 100644 --- a/linux/core/host_driver.c +++ b/linux/core/host_driver.c @@ -606,6 +606,39 @@ setup_monitor(struct ihk_host_linux_os_data *data) data->monitor_len = size; } +static void +setup_rusage(struct ihk_host_linux_os_data *data) +{ + unsigned long rpa; + unsigned long pa; + unsigned long size; + unsigned long psize; + + if (data->rusage) + return; + + if (__ihk_os_get_special_addr(data, IHK_SPADDR_RUSAGE, &rpa, &size)) { + dprintf("get_special_addr: failed.\n"); + return; + } + + psize = ((size + PAGE_SIZE - 1) / PAGE_SIZE) * PAGE_SIZE; + pa = __ihk_os_map_memory(data, rpa, psize); + +#ifdef CONFIG_MIC + if ((long)pa <= 0) { + return; + } + + data->rusage = ioremap_nocache(pa, psize); +#else + data->rusage = ihk_device_map_virtual(data->dev_data, pa, psize, + NULL, 0); +#endif + data->rusage_pa = pa; + data->rusage_len = size; +} + static int __ihk_os_status(struct ihk_host_linux_os_data *data, char __user *buf) { @@ -763,8 +796,7 @@ static int __ihk_os_thaw(struct ihk_host_linux_os_data *data) return error; } -static int -__ihk_os_get_usage(struct ihk_host_linux_os_data *data, unsigned long arg) +static int __ihk_os_get_usage(struct ihk_host_linux_os_data *data, unsigned long arg) { struct ihk_os_monitor *__user buf; @@ -781,8 +813,7 @@ __ihk_os_get_usage(struct ihk_host_linux_os_data *data, unsigned long arg) return 0; } -static int -__ihk_os_get_cpu_usage(struct ihk_host_linux_os_data *data, unsigned long arg) +static int __ihk_os_get_cpu_usage(struct ihk_host_linux_os_data *data, unsigned long arg) { struct ihk_os_cpu_monitor *__user buf; int size; @@ -1006,7 +1037,6 @@ static long ihk_host_os_ioctl(struct file *file, unsigned int request, dkprintf("__ihk_os_get_cpu_usage (ret=%d)\n",ret); break; - default: if (request >= IHK_OS_DEBUG_START && request <= IHK_OS_DEBUG_END) { @@ -1975,6 +2005,13 @@ struct ihk_cpu_info *ihk_os_get_cpu_info(ihk_os_t os) return __ihk_os_get_cpu_info(os); } +void *ihk_os_get_rusage(ihk_os_t ihk_os) +{ + struct ihk_host_linux_os_data *os = ihk_os; + setup_rusage(os); + return os->rusage; +} + ihk_device_t ihk_os_to_dev(ihk_os_t os) { return ((struct ihk_host_linux_os_data *)os)->dev_data; @@ -2329,3 +2366,4 @@ EXPORT_SYMBOL(ihk_device_linux_cpu_to_hw_id); EXPORT_SYMBOL(ihk_host_register_os_notifier); EXPORT_SYMBOL(ihk_host_deregister_os_notifier); EXPORT_SYMBOL(ihk_os_eventfd); +EXPORT_SYMBOL(ihk_os_get_rusage); diff --git a/linux/core/host_linux.h b/linux/core/host_linux.h index 2f8ac2f5..77658a42 100644 --- a/linux/core/host_linux.h +++ b/linux/core/host_linux.h @@ -79,6 +79,12 @@ struct ihk_host_linux_os_data { /** \brief Host physical address to monitor */ unsigned long monitor_pa; + void *rusage; + /** \brief Size of the rusage */ + unsigned long rusage_len; + /** \brief Host physical address to rusage */ + unsigned long rusage_pa; + /** \brief Flag whether the IKC is already initialized or not */ int ikc_initialized; /** \brief Lock for the channel list */ diff --git a/linux/driver/smp/smp-driver.c b/linux/driver/smp/smp-driver.c index 0e5eea79..2a775af2 100644 --- a/linux/driver/smp/smp-driver.c +++ b/linux/driver/smp/smp-driver.c @@ -1181,6 +1181,13 @@ static int smp_ihk_os_get_special_addr(ihk_os_t ihk_os, void *priv, return 0; } break; + case IHK_SPADDR_RUSAGE: + if (os->param->rusage) { + *addr = os->param->rusage; + *size = os->param->rusage_size; + return 0; + } + break; case IHK_SPADDR_NMI_MODE: if (os->param->nmi_mode_addr) { *addr = os->param->nmi_mode_addr; diff --git a/linux/include/ihk/kmsg.h b/linux/include/ihk/ihk_debug.h similarity index 62% rename from linux/include/ihk/kmsg.h rename to linux/include/ihk/ihk_debug.h index a31c126a..d1abce54 100644 --- a/linux/include/ihk/kmsg.h +++ b/linux/include/ihk/ihk_debug.h @@ -1,13 +1,13 @@ /** - * \file ihk_OS_KMSG.h + * \file ihk_debug.h * \brief * IHK-Master: OS status * \author Taku Shimosawa \par * Copyright (C) 2011-2012 Taku Shimosawa */ -#ifndef IHK_OS_KMSG_H_INCLUDED -#define IHK_OS_KMSG_H_INCLUDED +#ifndef IHK_DEBUG_H_INCLUDED +#define IHK_DEBUG_H_INCLUDED #define IHK_KMSG_SIZE (8*1024) -#endif /* !defined(IHK_OS_KMSG_H_INCLUDED) */ +#endif /* !defined(IHK_DEBUG_H_INCLUDED) */ diff --git a/linux/include/ihk/ihk_host_driver.h b/linux/include/ihk/ihk_host_driver.h index 50a1244f..a88ab823 100644 --- a/linux/include/ihk/ihk_host_driver.h +++ b/linux/include/ihk/ihk_host_driver.h @@ -11,8 +11,8 @@ #include #include -#include -#include +#include +#include /** \brief Status of a manycore device */ enum ihk_cpu_status { @@ -29,7 +29,8 @@ enum ihk_special_addr_type { IHK_SPADDR_MIKC_QUEUE_RECV = 2, IHK_SPADDR_MIKC_QUEUE_SEND = 3, IHK_SPADDR_MONITOR = 4, - IHK_SPADDR_NMI_MODE = 5, + IHK_SPADDR_RUSAGE = 5, + IHK_SPADDR_NMI_MODE = 6, }; /** \brief Type of an IHK device */ @@ -649,6 +650,8 @@ struct ihk_cpu_info { struct ihk_mem_info *ihk_os_get_memory_info(ihk_os_t os); /** \brief Get information of CPU cores which the OS kernel uses */ struct ihk_cpu_info *ihk_os_get_cpu_info(ihk_os_t os); +/** \brief Get address of memory area to which OS-global rerouce usage is recorded */ +void *ihk_os_get_rusage(ihk_os_t os); /** \brief Denote to allocate all the available cpus */ #define IHK_RESOURCE_CPU_ALL -1 diff --git a/linux/include/ihk/ihk_host_user.h b/linux/include/ihk/ihk_host_user.h index 584cad1f..db5c3c55 100644 --- a/linux/include/ihk/ihk_host_user.h +++ b/linux/include/ihk/ihk_host_user.h @@ -11,8 +11,8 @@ #define __HEADER_IHK_HOST_USER_H #include -#include -#include +#include +#include #define IHK_DEVICE_CREATE_OS 0x112900 #define IHK_DEVICE_DESTROY_OS 0x112901 @@ -69,6 +69,7 @@ #define IHK_OS_AUX_PERF_ENABLE 0x11290103 #define IHK_OS_AUX_PERF_DISABLE 0x11290104 #define IHK_OS_AUX_PERF_DESTROY 0x11290105 +#define IHK_OS_GETRUSAGE 0x11290106 #define FLAG_IHK_OS_SHUTDOWN_FORCE 0x40000000 diff --git a/linux/include/ihk/ihk_monitor.h b/linux/include/ihk/ihk_monitor.h new file mode 100644 index 00000000..b3aac18d --- /dev/null +++ b/linux/include/ihk/ihk_monitor.h @@ -0,0 +1,34 @@ +/** + * \file ihk_monitor.h + * \brief + * IHK-Master: OS status + * \author Tomoki Shirasawa \par + * Copyright (C) 2017 Tomoki Shirasawa + */ +#ifndef IHK_MONITOR_H_INCLUDED +#define IHK_MONITOR_H_INCLUDED + +/** \brief IHK-Monitor */ +struct ihk_os_cpu_monitor { + int status; +#define IHK_OS_MONITOR_NOT_BOOT 0 +#define IHK_OS_MONITOR_IDLE 1 +#define IHK_OS_MONITOR_USER 2 +#define IHK_OS_MONITOR_KERNEL 3 +#define IHK_OS_MONITOR_KERNEL_HEAVY 4 +#define IHK_OS_MONITOR_KERNEL_OFFLOAD 5 +#define IHK_OS_MONITOR_KERNEL_FREEZING 8 +#define IHK_OS_MONITOR_KERNEL_FROZEN 9 +#define IHK_OS_MONITOR_KERNEL_THAW 10 +#define IHK_OS_MONITOR_PANIC 99 + int status_bak; + unsigned long counter; + unsigned long ocounter; +}; + +struct ihk_os_monitor { + unsigned long num_processors; + unsigned long reserve[128]; + struct ihk_os_cpu_monitor cpu[0]; /* clv[i].monitor = &cpu[i] */ +}; +#endif /* !defined(IHK_MONITOR_H_INCLUDED) */ diff --git a/linux/include/ihk/ihklib_private.h b/linux/include/ihk/ihklib_private.h new file mode 100644 index 00000000..913692fc --- /dev/null +++ b/linux/include/ihk/ihklib_private.h @@ -0,0 +1,9 @@ +#ifndef IHKLIB_PRIVATE_H_INCLUDED +#define IHKLIB_PRIVATE_H_INCLUDED + +struct getrusage_desc { + void* rusage; + size_t size_rusage; +}; + +#endif /* !defined(IHKLIB_PRIVATE_H_INCLUDED) */ diff --git a/linux/include/ihk/monitor.h b/linux/include/ihk/monitor.h deleted file mode 100644 index d2c19d26..00000000 --- a/linux/include/ihk/monitor.h +++ /dev/null @@ -1,55 +0,0 @@ -/** - * \file ihk_os_monitor.h - * \brief - * IHK-Master: OS status - * \author Tomoki Shirasawa \par - * Copyright (C) 2017 Tomoki Shirasawa - */ -#ifndef IHK_OS_MONITOR_H_INCLUDED -#define IHK_OS_MONITOR_H_INCLUDED - -/** \brief IHK-Monitor */ -struct ihk_os_cpu_monitor { - int status; -#define IHK_OS_MONITOR_NOT_BOOT 0 -#define IHK_OS_MONITOR_IDLE 1 -#define IHK_OS_MONITOR_USER 2 -#define IHK_OS_MONITOR_KERNEL 3 -#define IHK_OS_MONITOR_KERNEL_HEAVY 4 -#define IHK_OS_MONITOR_KERNEL_OFFLOAD 5 -#define IHK_OS_MONITOR_KERNEL_FREEZING 8 -#define IHK_OS_MONITOR_KERNEL_FROZEN 9 -#define IHK_OS_MONITOR_KERNEL_THAW 10 -#define IHK_OS_MONITOR_PANIC 99 - int status_bak; - unsigned long counter; - unsigned long ocounter; - unsigned long user_tsc; - unsigned long system_tsc; -}; - -#define IHK_MAX_NUM_PGSIZES 4 -#define IHK_MAX_NUM_NUMA_NODES 1024 -#define IHK_MAX_NUMA_CPUS 1024 - -struct ihk_os_monitor { - long rusage_memory_stat_rss[IHK_MAX_NUM_PGSIZES]; - long rusage_memory_stat_mapped_file[IHK_MAX_NUM_PGSIZES]; - unsigned long rusage_memory_max_usage; - unsigned long rusage_max_num_threads; - unsigned long rusage_num_threads; - long rusage_rss_current; - unsigned long rusage_memory_kmem_usage; - unsigned long rusage_memory_kmem_max_usage; - unsigned long rusage_memory_numa_stat[IHK_MAX_NUM_NUMA_NODES]; - - unsigned long rusage_total_memory; - unsigned long rusage_total_memory_usage; - unsigned long rusage_total_memory_max_usage; - unsigned long num_processors; - unsigned long ns_per_tsc; - unsigned long reserve[128]; - - struct ihk_os_cpu_monitor cpu[0]; -}; -#endif /* !defined(IHK_OS_MONITOR_H_INCLUDED) */ diff --git a/linux/user/ihklib.c b/linux/user/ihklib.c index aa68c22a..f8d3100d 100644 --- a/linux/user/ihklib.c +++ b/linux/user/ihklib.c @@ -1,18 +1,15 @@ /** * \file ihklib.c */ -#include #include #include #include #include #include -#include "ihk/ihk_host_user.h" #include #include #include #include -#include "ihklib.h" #include #include #include @@ -25,6 +22,11 @@ #include #include +#include +#include +#include +#include + int __argc; char **__argv; @@ -1498,77 +1500,27 @@ int count_numa_node () { } #ifdef ENABLE_RUSAGE -int ihk_os_getrusage(int index, void *_rusage, size_t size_rusage) +int ihk_os_getrusage(int index, void *rusage, size_t size_rusage) { + char fn[128]; + int ret = 0; int fd; - char path[1024]; - struct ihk_os_monitor monitor; - struct ihk_os_cpu_monitor *cpu; - struct mckernel_rusage *rusage = (struct mckernel_rusage *)_rusage; - int rc; - int i; - unsigned long ut; - unsigned long st; - - sprintf(path, "/dev/mcos%d", index); - if ((fd = open(path, O_RDWR)) == -1) { - return -errno; - } + struct getrusage_desc desc = { .rusage = rusage, .size_rusage = size_rusage }; - if (ioctl(fd, IHK_OS_GET_USAGE, &monitor) == -1) { - rc = -errno; - close(fd); - return rc; - } - - cpu = malloc(sizeof(struct ihk_os_cpu_monitor) * - monitor.num_processors); - if (!cpu) { - close(fd); - return -ENOMEM; - } - - if (ioctl(fd, IHK_OS_GET_CPU_USAGE, cpu) == -1) { - rc = -errno; - close(fd); - free(cpu); - return rc; - } - - memset(rusage, 0, size_rusage); - - for (i = 0; i < IHK_MAX_NUM_PGSIZES; i++) { - rusage->memory_stat_rss[i] = monitor.rusage_memory_stat_rss[i]; - rusage->memory_stat_mapped_file[i] = monitor.rusage_memory_stat_mapped_file[i]; - } - rusage->memory_max_usage = monitor.rusage_memory_max_usage; - rusage->memory_kmem_usage = monitor.rusage_memory_kmem_usage; - rusage->memory_kmem_max_usage = monitor.rusage_memory_kmem_max_usage; - for (i = 0; i < IHK_MAX_NUM_NUMA_NODES; i++) { - rusage->memory_numa_stat[i] = monitor.rusage_memory_numa_stat[i]; - } - for (ut = 0, st = 0, i = 0; i < monitor.num_processors; i++) { - unsigned long wt; - - wt = cpu[i].user_tsc * monitor.ns_per_tsc / 1000; - ut += wt; - st += cpu[i].system_tsc * monitor.ns_per_tsc / 1000; - rusage->cpuacct_usage_percpu[i] = wt; - } - rusage->cpuacct_stat_system = st / 10000000; - rusage->cpuacct_stat_user = ut / 10000000; - rusage->cpuacct_usage = ut; - - rusage->num_threads = monitor.rusage_num_threads; - rusage->max_num_threads = monitor.rusage_max_num_threads; + sprintf(fn, "/dev/mcos%d", index); + fd = open(fn, O_RDONLY); + CHKANDJUMP(fd == -1, -ENOENT, "open failed: %s\n", strerror(errno)); + ret = ioctl(fd, IHK_OS_GETRUSAGE, &desc); + CHKANDJUMP(ret != 0, -EINVAL, "ioctl failed,ret=%d\n", ret); - close(fd); - free(cpu); - return 0; + fn_exit: + return ret; + fn_fail: + goto fn_exit; } #else /* ihk_getrusage */ -int ihk_os_getrusage(int index, void *_rusage, size_t size_rusage) +int ihk_os_getrusage(int index, void *rusage, size_t size_rusage) { eprintf("Specify --enable-rusage when configuring.\n"); return -EINVAL; @@ -1766,3 +1718,4 @@ int ihk_getperfevent (int index, unsigned long *counter, int n) } return ret; } + diff --git a/linux/user/ihklib.h.in b/linux/user/ihklib.h.in index 613dac93..62b459ff 100644 --- a/linux/user/ihklib.h.in +++ b/linux/user/ihklib.h.in @@ -107,25 +107,6 @@ typedef struct ihk_osinfo { int *ikc_map; } ihk_osinfo; -#define IHK_MAX_NUM_PGSIZES 4 -#define IHK_MAX_NUM_NUMA_NODES 1024 -#define IHK_MAX_NUM_CPUS 1024 - -struct mckernel_rusage { - unsigned long memory_stat_rss[IHK_MAX_NUM_PGSIZES]; - unsigned long memory_stat_mapped_file[IHK_MAX_NUM_PGSIZES]; - unsigned long memory_max_usage; - unsigned long memory_kmem_usage; - unsigned long memory_kmem_max_usage; - unsigned long memory_numa_stat[IHK_MAX_NUM_NUMA_NODES]; - unsigned long cpuacct_stat_system; - unsigned long cpuacct_stat_user; - unsigned long cpuacct_usage; - unsigned long cpuacct_usage_percpu[IHK_MAX_NUM_CPUS]; - int num_threads; - int max_num_threads; -}; - typedef struct ihk_perf_event_attr { unsigned long config; unsigned disabled:1;