sysinfo, procfs: Support memory info partially

Change-Id: I597dae4f82d64d3f23889cef960db18ae879ff06
refs: #1389
This commit is contained in:
Ken Sato
2020-04-07 12:55:52 +09:00
committed by Masamichi Takagi
parent 8e42c2a254
commit 8f74888f87
14 changed files with 506 additions and 0 deletions

View File

@@ -69,6 +69,24 @@ rusage_total_memory_add(unsigned long size)
#endif
}
static inline unsigned long
rusage_get_total_memory()
{
return rusage.total_memory;
}
static inline unsigned long
rusage_get_free_memory()
{
return rusage.total_memory - rusage.total_memory_usage;
}
static inline unsigned long
rusage_get_usage_memory()
{
return rusage.total_memory_usage;
}
static inline void
rusage_rss_add(unsigned long size)
{
@@ -412,6 +430,24 @@ rusage_rss_add(unsigned long size)
{
}
static inline unsigned long
rusage_get_total_memory()
{
return 0;
}
static inline unsigned long
rusage_get_free_memory()
{
return 0;
}
static inline unsigned long
rusage_get_usage_memory()
{
return 0;
}
static inline void
rusage_rss_sub(unsigned long size)
{

View File

@@ -443,6 +443,22 @@ struct rusage {
long ru_nivcsw;
};
struct sysinfo {
long uptime; /* Seconds since boot */
unsigned long loads[3]; /* 1, 5, and 15 minute load averages */
unsigned long totalram; /* Total usable main memory size */
unsigned long freeram; /* Available memory size */
unsigned long sharedram; /* Amount of shared memory */
unsigned long bufferram; /* Memory used by buffers */
unsigned long totalswap; /* Total swap space size */
unsigned long freeswap; /* swap space still available */
unsigned short procs; /* Number of current processes */
unsigned long totalhigh; /* Total high memory size */
unsigned long freehigh; /* Available high memory size */
unsigned int mem_unit; /* Memory unit size in bytes */
char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding for libc5 */
};
extern void terminate(int, int);
struct tod_data_s {

View File

@@ -26,6 +26,7 @@
#include <mman.h>
#include <bitmap.h>
#include <init.h>
#include <rusage_private.h>
//#define DEBUG_PRINT_PROCFS
@@ -359,6 +360,28 @@ static int _process_procfs_request(struct ikc_scd_packet *rpacket, int *result)
goto end;
}
#endif /* POSTK_DEBUG_ARCH_DEP_42 */
else if (!strcmp(p, "meminfo")) {
ans = snprintf(buf, count,
"MemTotal: %10d kB\n"
"MemFree: %10d kB\n"
"SwapTotal: %10d kB\n"
"SwapFree: %10d kB\n"
"CommitLimit: %10d kB\n"
"Committed_AS: %10d kB\n",
rusage_get_total_memory() >> 10,
rusage_get_free_memory() >> 10,
0, 0,
rusage_get_free_memory() >> 10,
rusage_get_usage_memory() >> 10);
if (ans < 0 || ans > count ||
buf_add(&buf_top, &buf_cur, buf, ans) < 0) {
goto err;
}
ans = 0;
goto end;
}
else {
kprintf("unsupported procfs entry: %s\n", p);
goto end;

View File

@@ -6623,6 +6623,27 @@ SYSCALL_DECLARE(getrusage)
return 0;
}
SYSCALL_DECLARE(sysinfo)
{
struct sysinfo *sysinfo = (struct sysinfo *)ihk_mc_syscall_arg0(ctx);
struct sysinfo __sysinfo;
int ret = 0;
memset(&__sysinfo, '\0', sizeof(struct sysinfo));
__sysinfo.totalram = rusage_get_total_memory();
__sysinfo.freeram = rusage_get_free_memory();
__sysinfo.mem_unit = 1; // always one unit for McKernel
if (copy_to_user(sysinfo, &__sysinfo, sizeof(struct sysinfo))) {
ret = -EFAULT;
goto out;
}
out:
return ret;
}
extern int ptrace_traceme(void);
extern void set_single_step(struct thread *thread);