rusage: Move pgsize_to_pgshift to arch-memory.h

Change-Id: Ia10b6e5c7d078d345347a79a3e98c06c16d28d6a
This commit is contained in:
Masamichi Takagi
2019-06-21 19:13:28 +09:00
parent 0267a0c8ea
commit 3b74b0a093
5 changed files with 87 additions and 40 deletions

View File

@ -586,6 +586,40 @@ static inline int pgsize_to_tbllv(size_t pgsize)
return level;
}
static inline int pgsize_to_pgshift(size_t pgsize)
{
/* We need to use if instead of switch because
* sometimes PTLX_CONT_SIZE == PTLX_SIZE
*/
if (pgsize == PTL4_CONT_SIZE) {
if (CONFIG_ARM64_PGTABLE_LEVELS > 3) {
return PTL4_CONT_SHIFT;
}
} else if (pgsize == PTL4_SIZE) {
if (CONFIG_ARM64_PGTABLE_LEVELS > 3) {
return PTL4_SHIFT;
}
} else if (pgsize == PTL3_CONT_SIZE) {
if (CONFIG_ARM64_PGTABLE_LEVELS > 2) {
return PTL3_CONT_SHIFT;
}
} else if (pgsize == PTL3_SIZE) {
if (CONFIG_ARM64_PGTABLE_LEVELS > 2) {
return PTL3_SHIFT;
}
} else if (pgsize == PTL2_CONT_SIZE) {
return PTL2_CONT_SHIFT;
} else if (pgsize == PTL2_SIZE) {
return PTL2_SHIFT;
} else if (pgsize == PTL1_CONT_SIZE) {
return PTL1_CONT_SHIFT;
} else if (pgsize == PTL1_SIZE) {
return PTL1_SHIFT;
}
return -EINVAL;
}
static inline size_t tbllv_to_pgsize(int level)
{
size_t pgsize = 0;

View File

@ -17,6 +17,7 @@
#define __HEADER_X86_COMMON_ARCH_MEMORY_H
#include <ihk/types.h>
#include <errno.h>
#define KERNEL_CS_ENTRY 4
#define KERNEL_DS_ENTRY 5
@ -365,6 +366,17 @@ static inline int pgsize_to_tbllv(size_t pgsize)
return 0;
}
static inline int pgsize_to_pgshift(size_t pgsize)
{
switch (pgsize) {
case PTL1_SIZE: return PTL1_SHIFT;
case PTL2_SIZE: return PTL2_SHIFT;
case PTL3_SIZE: return PTL3_SHIFT;
case PTL4_SIZE: return PTL4_SHIFT;
default: return -EINVAL;
}
}
static inline size_t tbllv_to_pgsize(int level)
{
switch (level) {

2
ihk

Submodule ihk updated: c505d9c25e...9a7bb111e7

View File

@ -9,45 +9,6 @@
extern struct rusage_global rusage;
static inline int rusage_pgsize_to_pgtype(size_t pgsize)
{
int ret = IHK_OS_PGSIZE_4KB;
int pgshift = pgsize_to_pgshift(pgsize);
switch (pgshift) {
case 12:
ret = IHK_OS_PGSIZE_4KB;
break;
case 16:
ret = IHK_OS_PGSIZE_64KB;
break;
case 21:
ret = IHK_OS_PGSIZE_2MB;
break;
case 25:
ret = IHK_OS_PGSIZE_32MB;
break;
case 30:
ret = IHK_OS_PGSIZE_1GB;
break;
case 34:
ret = IHK_OS_PGSIZE_16GB;
break;
case 29:
ret = IHK_OS_PGSIZE_512MB;
break;
case 42:
ret = IHK_OS_PGSIZE_4TB;
break;
default:
kprintf("%s: Error: Unknown pgsize=%ld\n",
__func__, pgsize);
break;
}
return ret;
}
struct rusage_percpu {
unsigned long user_tsc;
unsigned long system_tsc;

View File

@ -10,6 +10,7 @@
#include <rusage.h>
#include <ihk/ihk_monitor.h>
#include <ihk/debug.h>
#include <memory.h>
#ifdef ENABLE_RUSAGE
@ -17,6 +18,45 @@
extern void eventfd(int type);
static inline int rusage_pgsize_to_pgtype(size_t pgsize)
{
int ret = IHK_OS_PGSIZE_4KB;
int pgshift = pgsize_to_pgshift(pgsize);
switch (pgshift) {
case 12:
ret = IHK_OS_PGSIZE_4KB;
break;
case 16:
ret = IHK_OS_PGSIZE_64KB;
break;
case 21:
ret = IHK_OS_PGSIZE_2MB;
break;
case 25:
ret = IHK_OS_PGSIZE_32MB;
break;
case 30:
ret = IHK_OS_PGSIZE_1GB;
break;
case 34:
ret = IHK_OS_PGSIZE_16GB;
break;
case 29:
ret = IHK_OS_PGSIZE_512MB;
break;
case 42:
ret = IHK_OS_PGSIZE_4TB;
break;
default:
kprintf("%s: Error: Unknown pgsize=%ld\n",
__func__, pgsize);
break;
}
return ret;
}
static inline void
rusage_total_memory_add(unsigned long size)
{