Compare commits
82 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1e442cce10 | ||
|
|
3f870b69a6 | ||
|
|
0fef80cb19 | ||
|
|
9992fe0d72 | ||
|
|
2d19ed9391 | ||
|
|
2f2f04d5a1 | ||
|
|
1541b26086 | ||
|
|
e6c4d7731d | ||
|
|
94b527e027 | ||
|
|
8c9b207557 | ||
|
|
dacb05844b | ||
|
|
c3ec5d20ca | ||
|
|
92a40f92dd | ||
|
|
45bddf3caa | ||
|
|
b7671fedd3 | ||
|
|
c38d536aaa | ||
|
|
4ee0c05e08 | ||
|
|
f2ab0193e5 | ||
|
|
ef910fdf0e | ||
|
|
b97a8c5138 | ||
|
|
034d10b185 | ||
|
|
3fe2257929 | ||
|
|
eca4018ecb | ||
|
|
e936b2ebe1 | ||
|
|
d8112f92f8 | ||
|
|
1076010de4 | ||
|
|
da4a5ec44b | ||
|
|
d35aa9b100 | ||
|
|
ba8dbf1b19 | ||
|
|
6213f0e488 | ||
|
|
4ef82c2683 | ||
|
|
e066a8798c | ||
|
|
b702c9691e | ||
|
|
addbe91e59 | ||
|
|
b812848a0e | ||
|
|
ad214c8206 | ||
|
|
1bc3218fc1 | ||
|
|
5cc420a6c3 | ||
|
|
c7686fdf4e | ||
|
|
c1dae4d8b0 | ||
|
|
2473025201 | ||
|
|
fa5c1b23ca | ||
|
|
f2f499aace | ||
|
|
bd47b909bf | ||
|
|
d646c2a4b9 | ||
|
|
865ada46bf | ||
|
|
cdffc5e853 | ||
|
|
0e67e9266b | ||
|
|
1ff0afe6fb | ||
|
|
d34884f9a4 | ||
|
|
7a0c204dc1 | ||
|
|
25f67c9ef8 | ||
|
|
a776464a7e | ||
|
|
c40e7105e6 | ||
|
|
5bac38ce8b | ||
|
|
e3f0662130 | ||
|
|
21df56b233 | ||
|
|
393cec513c | ||
|
|
4437ecc69a | ||
|
|
40d75baca2 | ||
|
|
00f3fe0840 | ||
|
|
47a8b5bda5 | ||
|
|
ec75095073 | ||
|
|
1794232989 | ||
|
|
40978d162e | ||
|
|
536ce9f927 | ||
|
|
4e5ec74ffe | ||
|
|
a6d8125fd7 | ||
|
|
15d3a0361e | ||
|
|
6ad84a96a3 | ||
|
|
16e846e9b6 | ||
|
|
5bc7185f07 | ||
|
|
32462dfb2d | ||
|
|
e3ef88c0cf | ||
|
|
829aae7b8d | ||
|
|
b836b84825 | ||
|
|
3e1f154412 | ||
|
|
e7af537452 | ||
|
|
3565959af7 | ||
|
|
4667136a4c | ||
|
|
972d14611a | ||
|
|
e90eef8910 |
@@ -49,6 +49,7 @@ install::
|
|||||||
mkdir -p -m 755 $(SBINDIR); \
|
mkdir -p -m 755 $(SBINDIR); \
|
||||||
install -m 755 arch/x86/tools/mcreboot-smp-x86.sh $(SBINDIR)/mcreboot.sh; \
|
install -m 755 arch/x86/tools/mcreboot-smp-x86.sh $(SBINDIR)/mcreboot.sh; \
|
||||||
install -m 755 arch/x86/tools/mcstop+release-smp-x86.sh $(SBINDIR)/mcstop+release.sh; \
|
install -m 755 arch/x86/tools/mcstop+release-smp-x86.sh $(SBINDIR)/mcstop+release.sh; \
|
||||||
|
install -m 755 arch/x86/tools/eclair-dump-backtrace.exp $(SBINDIR)/eclair-dump-backtrace.exp;\
|
||||||
mkdir -p -m 755 $(ETCDIR); \
|
mkdir -p -m 755 $(ETCDIR); \
|
||||||
install -m 644 arch/x86/tools/irqbalance_mck.service $(ETCDIR)/irqbalance_mck.service; \
|
install -m 644 arch/x86/tools/irqbalance_mck.service $(ETCDIR)/irqbalance_mck.service; \
|
||||||
install -m 644 arch/x86/tools/irqbalance_mck.in $(ETCDIR)/irqbalance_mck.in; \
|
install -m 644 arch/x86/tools/irqbalance_mck.in $(ETCDIR)/irqbalance_mck.in; \
|
||||||
|
|||||||
@@ -1813,4 +1813,43 @@ int running_on_kvm(void) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
mod_nmi_ctx(void *nmi_ctx, void (*func)())
|
||||||
|
{
|
||||||
|
unsigned long *l = nmi_ctx;
|
||||||
|
int i;
|
||||||
|
unsigned long flags;
|
||||||
|
|
||||||
|
//struct x86_cpu_local_variables *v;
|
||||||
|
|
||||||
|
//if(!ihk_mc_get_processor_id()) {
|
||||||
|
//v = get_x86_this_cpu_local();
|
||||||
|
//}
|
||||||
|
asm volatile("pushf; pop %0" : "=r"(flags) : : "memory", "cc");
|
||||||
|
for (i = 0; i < 22; i++)
|
||||||
|
l[i] = l[i + 5];
|
||||||
|
l[i++] = (unsigned long)func; // return address
|
||||||
|
l[i++] = 0x20; // KERNEL CS
|
||||||
|
l[i++] = flags & ~RFLAGS_IF; // rflags (disable interrupt)
|
||||||
|
l[i++] = (unsigned long)(l + 27); // ols rsp
|
||||||
|
l[i++] = 0x28; // KERNEL DS
|
||||||
|
}
|
||||||
|
|
||||||
|
int arch_cpu_read_write_register(
|
||||||
|
struct mcctrl_os_cpu_register *desc,
|
||||||
|
enum mcctrl_os_cpu_operation op)
|
||||||
|
{
|
||||||
|
if (op == MCCTRL_OS_CPU_READ_REGISTER) {
|
||||||
|
desc->val = rdmsr(desc->addr);
|
||||||
|
}
|
||||||
|
else if (op == MCCTRL_OS_CPU_WRITE_REGISTER) {
|
||||||
|
wrmsr(desc->addr, desc->val);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*** end of file ***/
|
/*** end of file ***/
|
||||||
|
|||||||
@@ -215,4 +215,25 @@ static inline unsigned long atomic_cmpxchg4(unsigned int *addr,
|
|||||||
return oldval;
|
return oldval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void ihk_atomic_add_long(long i, long *v) {
|
||||||
|
asm volatile("lock addq %1,%0"
|
||||||
|
: "+m" (*v)
|
||||||
|
: "ir" (i));
|
||||||
|
}
|
||||||
|
static inline void ihk_atomic_add_ulong(long i, unsigned long *v) {
|
||||||
|
asm volatile("lock addq %1,%0"
|
||||||
|
: "+m" (*v)
|
||||||
|
: "ir" (i));
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline unsigned long ihk_atomic_add_long_return(long i, long *v) {
|
||||||
|
long __i;
|
||||||
|
|
||||||
|
__i = i;
|
||||||
|
asm volatile("lock xaddq %0, %1"
|
||||||
|
: "+r" (i), "+m" (*v)
|
||||||
|
: : "memory");
|
||||||
|
return i + __i;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ SYSCALL_HANDLED(603, pmc_stop)
|
|||||||
SYSCALL_HANDLED(604, pmc_reset)
|
SYSCALL_HANDLED(604, pmc_reset)
|
||||||
SYSCALL_HANDLED(700, get_cpu_id)
|
SYSCALL_HANDLED(700, get_cpu_id)
|
||||||
#ifdef TRACK_SYSCALLS
|
#ifdef TRACK_SYSCALLS
|
||||||
SYSCALL_HANDLED(701, syscall_offload_clr_cntrs)
|
SYSCALL_HANDLED(__NR_track_syscalls, track_syscalls)
|
||||||
#endif // TRACK_SYSCALLS
|
#endif // TRACK_SYSCALLS
|
||||||
|
|
||||||
/**** End of File ****/
|
/**** End of File ****/
|
||||||
|
|||||||
@@ -130,11 +130,40 @@ general_protection_exception:
|
|||||||
addq $8, %rsp
|
addq $8, %rsp
|
||||||
iretq
|
iretq
|
||||||
|
|
||||||
|
.global __freeze
|
||||||
|
__freeze:
|
||||||
|
PUSH_ALL_REGS
|
||||||
|
callq freeze
|
||||||
|
POP_ALL_REGS
|
||||||
|
iretq
|
||||||
|
|
||||||
.globl nmi
|
.globl nmi
|
||||||
nmi:
|
nmi:
|
||||||
#define PANICED 232
|
#define PANICED 232
|
||||||
#define PANIC_REGS 240
|
#define PANIC_REGS 240
|
||||||
movq %rax,%gs:PANIC_REGS+0x00
|
movq %rax,%gs:PANIC_REGS+0x00
|
||||||
|
movq %rsp,%gs:PANIC_REGS+0x08
|
||||||
|
|
||||||
|
movl nmi_mode(%rip),%eax
|
||||||
|
cmp $1,%rax
|
||||||
|
je 1f
|
||||||
|
cmp $2,%rax
|
||||||
|
jne 3f
|
||||||
|
1:
|
||||||
|
cld
|
||||||
|
movq %gs:PANIC_REGS+0x00,%rax
|
||||||
|
PUSH_ALL_REGS
|
||||||
|
subq $40, %rsp
|
||||||
|
movq %rsp,%gs:PANIC_REGS+0x10
|
||||||
|
movq %rsp, %rdi
|
||||||
|
call freeze_thaw
|
||||||
|
cmpq $0, %rax
|
||||||
|
jnz 2f
|
||||||
|
addq $40, %rsp
|
||||||
|
2:
|
||||||
|
POP_ALL_REGS
|
||||||
|
iretq
|
||||||
|
3:
|
||||||
movq %rbx,%gs:PANIC_REGS+0x08
|
movq %rbx,%gs:PANIC_REGS+0x08
|
||||||
movq %rcx,%gs:PANIC_REGS+0x10
|
movq %rcx,%gs:PANIC_REGS+0x10
|
||||||
movq %rdx,%gs:PANIC_REGS+0x18
|
movq %rdx,%gs:PANIC_REGS+0x18
|
||||||
|
|||||||
@@ -45,7 +45,11 @@ void *early_alloc_pages(int nr_pages)
|
|||||||
last_page = phys_to_virt(virt_to_phys(last_page));
|
last_page = phys_to_virt(virt_to_phys(last_page));
|
||||||
} else if (last_page == (void *)-1) {
|
} else if (last_page == (void *)-1) {
|
||||||
panic("Early allocator is already finalized. Do not use it.\n");
|
panic("Early allocator is already finalized. Do not use it.\n");
|
||||||
}
|
} else {
|
||||||
|
if(virt_to_phys(last_page) >= bootstrap_mem_end) {
|
||||||
|
panic("Early allocator: Out of memory\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
p = last_page;
|
p = last_page;
|
||||||
last_page += (nr_pages * PAGE_SIZE);
|
last_page += (nr_pages * PAGE_SIZE);
|
||||||
|
|
||||||
@@ -179,7 +183,7 @@ static void init_normal_area(struct page_table *pt)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct page_table *__alloc_new_pt(enum ihk_mc_ap_flag ap_flag)
|
static struct page_table *__alloc_new_pt(ihk_mc_ap_flag ap_flag)
|
||||||
{
|
{
|
||||||
struct page_table *newpt = ihk_mc_alloc_pages(1, ap_flag);
|
struct page_table *newpt = ihk_mc_alloc_pages(1, ap_flag);
|
||||||
|
|
||||||
@@ -278,7 +282,7 @@ void set_pte(pte_t *ppte, unsigned long phys, enum ihk_mc_pt_attribute attr)
|
|||||||
* and returns a pointer to the PTE corresponding to the
|
* and returns a pointer to the PTE corresponding to the
|
||||||
* virtual address.
|
* virtual address.
|
||||||
*/
|
*/
|
||||||
pte_t *get_pte(struct page_table *pt, void *virt, enum ihk_mc_pt_attribute attr, enum ihk_mc_ap_flag ap_flag)
|
pte_t *get_pte(struct page_table *pt, void *virt, enum ihk_mc_pt_attribute attr, ihk_mc_ap_flag ap_flag)
|
||||||
{
|
{
|
||||||
int l4idx, l3idx, l2idx, l1idx;
|
int l4idx, l3idx, l2idx, l1idx;
|
||||||
unsigned long v = (unsigned long)virt;
|
unsigned long v = (unsigned long)virt;
|
||||||
@@ -339,7 +343,7 @@ static int __set_pt_page(struct page_table *pt, void *virt, unsigned long phys,
|
|||||||
int l4idx, l3idx, l2idx, l1idx;
|
int l4idx, l3idx, l2idx, l1idx;
|
||||||
unsigned long v = (unsigned long)virt;
|
unsigned long v = (unsigned long)virt;
|
||||||
struct page_table *newpt;
|
struct page_table *newpt;
|
||||||
enum ihk_mc_ap_flag ap_flag;
|
ihk_mc_ap_flag ap_flag;
|
||||||
int in_kernel =
|
int in_kernel =
|
||||||
(((unsigned long long)virt) >= 0xffff000000000000ULL);
|
(((unsigned long long)virt) >= 0xffff000000000000ULL);
|
||||||
unsigned long init_pt_lock_flags;
|
unsigned long init_pt_lock_flags;
|
||||||
@@ -664,7 +668,7 @@ int ihk_mc_pt_prepare_map(page_table_t p, void *virt, unsigned long size,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct page_table *ihk_mc_pt_create(enum ihk_mc_ap_flag ap_flag)
|
struct page_table *ihk_mc_pt_create(ihk_mc_ap_flag ap_flag)
|
||||||
{
|
{
|
||||||
struct page_table *pt = ihk_mc_alloc_pages(1, ap_flag);
|
struct page_table *pt = ihk_mc_alloc_pages(1, ap_flag);
|
||||||
|
|
||||||
@@ -1097,7 +1101,8 @@ static int clear_range_l1(void *args0, pte_t *ptep, uint64_t base,
|
|||||||
page = phys_to_page(phys);
|
page = phys_to_page(phys);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (page && page_is_in_memobj(page) && (old & PFL1_DIRTY)) {
|
if (page && page_is_in_memobj(page) && (old & PFL1_DIRTY) && (args->memobj) &&
|
||||||
|
!(args->memobj->flags & MF_ZEROFILL)) {
|
||||||
memobj_flush_page(args->memobj, phys, PTL1_SIZE);
|
memobj_flush_page(args->memobj, phys, PTL1_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1271,6 +1276,9 @@ static int clear_range(struct page_table *pt, struct process_vm *vm,
|
|||||||
}
|
}
|
||||||
|
|
||||||
args.free_physical = free_physical;
|
args.free_physical = free_physical;
|
||||||
|
if (memobj && (memobj->flags & MF_DEV_FILE)) {
|
||||||
|
args.free_physical = 0;
|
||||||
|
}
|
||||||
args.memobj = memobj;
|
args.memobj = memobj;
|
||||||
args.vm = vm;
|
args.vm = vm;
|
||||||
|
|
||||||
@@ -2229,30 +2237,28 @@ int strcpy_from_user(char *dst, const char *src)
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
long getlong_user(const long *p)
|
long getlong_user(long *dest, const long *p)
|
||||||
{
|
{
|
||||||
int error;
|
int error;
|
||||||
long l;
|
|
||||||
|
|
||||||
error = copy_from_user(&l, p, sizeof(l));
|
error = copy_from_user(dest, p, sizeof(long));
|
||||||
if (error) {
|
if (error) {
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
return l;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getint_user(const int *p)
|
int getint_user(int *dest, const int *p)
|
||||||
{
|
{
|
||||||
int error;
|
int error;
|
||||||
int i;
|
|
||||||
|
|
||||||
error = copy_from_user(&i, p, sizeof(i));
|
error = copy_from_user(dest, p, sizeof(int));
|
||||||
if (error) {
|
if (error) {
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
return i;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int read_process_vm(struct process_vm *vm, void *kdst, const void *usrc, size_t siz)
|
int read_process_vm(struct process_vm *vm, void *kdst, const void *usrc, size_t siz)
|
||||||
@@ -2418,7 +2424,7 @@ int patch_process_vm(struct process_vm *vm, void *udst, const void *ksrc, size_t
|
|||||||
unsigned long pa;
|
unsigned long pa;
|
||||||
void *va;
|
void *va;
|
||||||
|
|
||||||
kprintf("patch_process_vm(%p,%p,%p,%lx)\n", vm, udst, ksrc, siz);
|
dkprintf("patch_process_vm(%p,%p,%p,%lx)\n", vm, udst, ksrc, siz);
|
||||||
if ((ustart < vm->region.user_start)
|
if ((ustart < vm->region.user_start)
|
||||||
|| (vm->region.user_end <= ustart)
|
|| (vm->region.user_end <= ustart)
|
||||||
|| ((vm->region.user_end - ustart) < siz)) {
|
|| ((vm->region.user_end - ustart) < siz)) {
|
||||||
@@ -2468,6 +2474,6 @@ int patch_process_vm(struct process_vm *vm, void *udst, const void *ksrc, size_t
|
|||||||
remain -= cpsize;
|
remain -= cpsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
kprintf("patch_process_vm(%p,%p,%p,%lx):%d\n", vm, udst, ksrc, siz, 0);
|
dkprintf("patch_process_vm(%p,%p,%p,%lx):%d\n", vm, udst, ksrc, siz, 0);
|
||||||
return 0;
|
return 0;
|
||||||
} /* patch_process_vm() */
|
} /* patch_process_vm() */
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ int ihk_mc_ikc_init_first_local(struct ihk_ikc_channel_desc *channel,
|
|||||||
|
|
||||||
memset(channel, 0, sizeof(struct ihk_ikc_channel_desc));
|
memset(channel, 0, sizeof(struct ihk_ikc_channel_desc));
|
||||||
|
|
||||||
mikc_queue_pages = ((num_processors * MASTER_IKCQ_PKTSIZE)
|
mikc_queue_pages = ((2 * num_processors * MASTER_IKCQ_PKTSIZE)
|
||||||
+ (PAGE_SIZE - 1)) / PAGE_SIZE;
|
+ (PAGE_SIZE - 1)) / PAGE_SIZE;
|
||||||
|
|
||||||
/* Place both sides in this side */
|
/* Place both sides in this side */
|
||||||
|
|||||||
@@ -1179,7 +1179,8 @@ done:
|
|||||||
if(pid != -1 && tthread->proc->pid != pid){
|
if(pid != -1 && tthread->proc->pid != pid){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(tthread->tid == tid){
|
if (tthread->tid == tid &&
|
||||||
|
tthread->status != PS_EXITED) {
|
||||||
found = 1;
|
found = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -1297,6 +1298,9 @@ done:
|
|||||||
sched_wakeup_thread(tthread, PS_STOPPED);
|
sched_wakeup_thread(tthread, PS_STOPPED);
|
||||||
tthread->proc->status = PS_RUNNING;
|
tthread->proc->status = PS_RUNNING;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
sched_wakeup_thread(tthread, PS_INTERRUPTIBLE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
release_thread(tthread);
|
release_thread(tthread);
|
||||||
@@ -1741,7 +1745,8 @@ int arch_map_vdso(struct process_vm *vm)
|
|||||||
vrflags = VR_REMOTE;
|
vrflags = VR_REMOTE;
|
||||||
vrflags |= VR_PROT_READ | VR_PROT_EXEC;
|
vrflags |= VR_PROT_READ | VR_PROT_EXEC;
|
||||||
vrflags |= VRFLAG_PROT_TO_MAXPROT(vrflags);
|
vrflags |= VRFLAG_PROT_TO_MAXPROT(vrflags);
|
||||||
error = add_process_memory_range(vm, (intptr_t)s, (intptr_t)e, NOPHYS, vrflags, NULL, 0, PAGE_SHIFT);
|
error = add_process_memory_range(vm, (intptr_t)s, (intptr_t)e,
|
||||||
|
NOPHYS, vrflags, NULL, 0, PAGE_SHIFT, NULL);
|
||||||
if (error) {
|
if (error) {
|
||||||
ekprintf("ERROR: adding memory range for vdso. %d\n", error);
|
ekprintf("ERROR: adding memory range for vdso. %d\n", error);
|
||||||
goto out;
|
goto out;
|
||||||
@@ -1772,7 +1777,8 @@ int arch_map_vdso(struct process_vm *vm)
|
|||||||
vrflags = VR_REMOTE;
|
vrflags = VR_REMOTE;
|
||||||
vrflags |= VR_PROT_READ;
|
vrflags |= VR_PROT_READ;
|
||||||
vrflags |= VRFLAG_PROT_TO_MAXPROT(vrflags);
|
vrflags |= VRFLAG_PROT_TO_MAXPROT(vrflags);
|
||||||
error = add_process_memory_range(vm, (intptr_t)s, (intptr_t)e, NOPHYS, vrflags, NULL, 0, PAGE_SHIFT);
|
error = add_process_memory_range(vm, (intptr_t)s, (intptr_t)e,
|
||||||
|
NOPHYS, vrflags, NULL, 0, PAGE_SHIFT, NULL);
|
||||||
if (error) {
|
if (error) {
|
||||||
ekprintf("ERROR: adding memory range for vvar. %d\n", error);
|
ekprintf("ERROR: adding memory range for vvar. %d\n", error);
|
||||||
goto out;
|
goto out;
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
* make sure that these are position-independent codes.
|
* make sure that these are position-independent codes.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <cls.h>
|
||||||
#include <syscall.h>
|
#include <syscall.h>
|
||||||
#include <ihk/atomic.h>
|
#include <ihk/atomic.h>
|
||||||
#include <arch/cpu.h>
|
#include <arch/cpu.h>
|
||||||
|
|||||||
67
arch/x86/tools/eclair-dump-backtrace.exp.in
Executable file
67
arch/x86/tools/eclair-dump-backtrace.exp.in
Executable file
@@ -0,0 +1,67 @@
|
|||||||
|
#!/usr/bin/expect
|
||||||
|
|
||||||
|
set INST_DIR "@prefix@"
|
||||||
|
|
||||||
|
spawn $INST_DIR/bin/eclair -d /tmp/mckernel.dump -k $INST_DIR/smp-x86/kernel/mckernel.img -i
|
||||||
|
|
||||||
|
set state "init"
|
||||||
|
set thread_id 0
|
||||||
|
|
||||||
|
expect {
|
||||||
|
"in ?? ()" {
|
||||||
|
switch -- $state {
|
||||||
|
"thread_chosen" {
|
||||||
|
set state "thread_skip"
|
||||||
|
}
|
||||||
|
"thread_bt" {
|
||||||
|
set state "thread_skip"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
exp_continue
|
||||||
|
}
|
||||||
|
"(eclair) " {
|
||||||
|
switch -- $state {
|
||||||
|
"init" {
|
||||||
|
set state "threads_list"
|
||||||
|
send "info threads\r"
|
||||||
|
}
|
||||||
|
"threads_list" {
|
||||||
|
incr thread_id
|
||||||
|
set state "thread_chosen"
|
||||||
|
send "thread $thread_id\r"
|
||||||
|
}
|
||||||
|
"thread_skip" {
|
||||||
|
incr thread_id
|
||||||
|
set state "thread_chosen"
|
||||||
|
send "thread $thread_id\r"
|
||||||
|
}
|
||||||
|
"thread_chosen" {
|
||||||
|
set state "thread_bt"
|
||||||
|
send "bt\r"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
exp_continue
|
||||||
|
}
|
||||||
|
"Type <return> to continue, or q <return> to quit" {
|
||||||
|
switch -- $state {
|
||||||
|
"threads_list" {
|
||||||
|
send "\r"
|
||||||
|
}
|
||||||
|
"thread_bt" {
|
||||||
|
send "\r"
|
||||||
|
}
|
||||||
|
"thread_skip" {
|
||||||
|
send "q\r"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exp_continue
|
||||||
|
}
|
||||||
|
" not known." {
|
||||||
|
expect "(eclair) " { send "quit\r" }
|
||||||
|
expect "Quit anyway? (y or n) " { send "y\r" }
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -3,7 +3,7 @@ Description=irqbalance daemon
|
|||||||
After=syslog.target
|
After=syslog.target
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
EnvironmentFile=@ETCDIR@/irqbalance_mck
|
EnvironmentFile=/tmp/irqbalance_mck
|
||||||
ExecStart=/usr/sbin/irqbalance --foreground $IRQBALANCE_ARGS
|
ExecStart=/usr/sbin/irqbalance --foreground $IRQBALANCE_ARGS
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ error_exit() {
|
|||||||
;&
|
;&
|
||||||
mcoverlayfs_loaded)
|
mcoverlayfs_loaded)
|
||||||
if [ "$enable_mcoverlay" == "yes" ]; then
|
if [ "$enable_mcoverlay" == "yes" ]; then
|
||||||
rmmod mcoverlay
|
rmmod mcoverlay 2>/dev/null
|
||||||
fi
|
fi
|
||||||
;&
|
;&
|
||||||
linux_proc_bind_mounted)
|
linux_proc_bind_mounted)
|
||||||
@@ -134,15 +134,7 @@ error_exit() {
|
|||||||
fi
|
fi
|
||||||
;&
|
;&
|
||||||
mcctrl_loaded)
|
mcctrl_loaded)
|
||||||
rmmod mcctrl || echo "warning: failed to remove mcctrl" >&2
|
rmmod mcctrl 2>/dev/null || echo "warning: failed to remove mcctrl" >&2
|
||||||
;&
|
|
||||||
mem_reserved)
|
|
||||||
mem=`${SBINDIR}/ihkconfig 0 query mem`
|
|
||||||
if [ "${mem}" != "" ]; then
|
|
||||||
if ! ${SBINDIR}/ihkconfig 0 release mem $mem > /dev/null; then
|
|
||||||
echo "warning: failed to release memory" >&2
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
;&
|
;&
|
||||||
cpus_reserved)
|
cpus_reserved)
|
||||||
cpus=`${SBINDIR}/ihkconfig 0 query cpu`
|
cpus=`${SBINDIR}/ihkconfig 0 query cpu`
|
||||||
@@ -152,11 +144,19 @@ error_exit() {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
;&
|
;&
|
||||||
|
mem_reserved)
|
||||||
|
mem=`${SBINDIR}/ihkconfig 0 query mem`
|
||||||
|
if [ "${mem}" != "" ]; then
|
||||||
|
if ! ${SBINDIR}/ihkconfig 0 release mem $mem > /dev/null; then
|
||||||
|
echo "warning: failed to release memory" >&2
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
;&
|
||||||
ihk_smp_loaded)
|
ihk_smp_loaded)
|
||||||
rmmod ihk_smp_x86 || echo "warning: failed to remove ihk_smp_x86" >&2
|
rmmod ihk_smp_x86 2>/dev/null || echo "warning: failed to remove ihk_smp_x86" >&2
|
||||||
;&
|
;&
|
||||||
ihk_loaded)
|
ihk_loaded)
|
||||||
rmmod ihk || echo "warning: failed to remove ihk" >&2
|
rmmod ihk 2>/dev/null || echo "warning: failed to remove ihk" >&2
|
||||||
;&
|
;&
|
||||||
irqbalance_stopped)
|
irqbalance_stopped)
|
||||||
if [ "`systemctl status irqbalance_mck.service 2> /dev/null |grep -E 'Active: active'`" != "" ]; then
|
if [ "`systemctl status irqbalance_mck.service 2> /dev/null |grep -E 'Active: active'`" != "" ]; then
|
||||||
@@ -174,6 +174,11 @@ error_exit() {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
;&
|
;&
|
||||||
|
aslr_disabled)
|
||||||
|
if [ -f /tmp/mckernel_randomize_va_space ]; then
|
||||||
|
cat /tmp/mckernel_randomize_va_space > /proc/sys/kernel/randomize_va_space
|
||||||
|
fi
|
||||||
|
;&
|
||||||
initial)
|
initial)
|
||||||
# Nothing more to revert
|
# Nothing more to revert
|
||||||
;;
|
;;
|
||||||
@@ -225,17 +230,23 @@ if [ "$cpus" == "" ]; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Disable address space layout randomization
|
||||||
|
if [ -f /proc/sys/kernel/randomize_va_space ] && [ "`cat /proc/sys/kernel/randomize_va_space`" != "0" ]; then
|
||||||
|
cat /proc/sys/kernel/randomize_va_space > /tmp/mckernel_randomize_va_space
|
||||||
|
echo "0" > /proc/sys/kernel/randomize_va_space
|
||||||
|
fi
|
||||||
|
|
||||||
# Remove mcoverlay if loaded
|
# Remove mcoverlay if loaded
|
||||||
if [ "$enable_mcoverlay" == "yes" ]; then
|
if [ "$enable_mcoverlay" == "yes" ]; then
|
||||||
if [ "`lsmod | grep mcoverlay`" != "" ]; then
|
if grep mcoverlay /proc/modules &>/dev/null; then
|
||||||
if [ "`cat /proc/mounts | grep /tmp/mcos/mcos0_sys`" != "" ]; then umount -l /tmp/mcos/mcos0_sys; fi
|
if [ "`cat /proc/mounts | grep /tmp/mcos/mcos0_sys`" != "" ]; then umount -l /tmp/mcos/mcos0_sys; fi
|
||||||
if [ "`cat /proc/mounts | grep /tmp/mcos/mcos0_proc`" != "" ]; then umount -l /tmp/mcos/mcos0_proc; fi
|
if [ "`cat /proc/mounts | grep /tmp/mcos/mcos0_proc`" != "" ]; then umount -l /tmp/mcos/mcos0_proc; fi
|
||||||
if [ "`cat /proc/mounts | grep /tmp/mcos/linux_proc`" != "" ]; then umount -l /tmp/mcos/linux_proc; fi
|
if [ "`cat /proc/mounts | grep /tmp/mcos/linux_proc`" != "" ]; then umount -l /tmp/mcos/linux_proc; fi
|
||||||
if [ "`cat /proc/mounts | grep /tmp/mcos`" != "" ]; then umount -l /tmp/mcos; fi
|
if [ "`cat /proc/mounts | grep /tmp/mcos`" != "" ]; then umount -l /tmp/mcos; fi
|
||||||
if [ -e /tmp/mcos ]; then rm -rf /tmp/mcos; fi
|
if [ -e /tmp/mcos ]; then rm -rf /tmp/mcos; fi
|
||||||
if ! rmmod mcoverlay; then
|
if ! rmmod mcoverlay 2>/dev/null; then
|
||||||
echo "error: removing mcoverlay" >&2
|
echo "error: removing mcoverlay" >&2
|
||||||
error_exit "initial"
|
error_exit "aslr_disabled"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@@ -245,36 +256,31 @@ if [ "${irqbalance_used}" == "yes" ]; then
|
|||||||
systemctl stop irqbalance_mck.service 2>/dev/null
|
systemctl stop irqbalance_mck.service 2>/dev/null
|
||||||
if ! systemctl stop irqbalance.service 2>/dev/null ; then
|
if ! systemctl stop irqbalance.service 2>/dev/null ; then
|
||||||
echo "error: stopping irqbalance" >&2
|
echo "error: stopping irqbalance" >&2
|
||||||
error_exit "initial"
|
error_exit "aslr_disabled"
|
||||||
fi;
|
fi;
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Start mcklogd. Note that McKernel blocks when kmsg buffer is full
|
|
||||||
# with '-k 1' until mcklogd unblocks it so starting mcklogd must preceed
|
|
||||||
# booting McKernel
|
|
||||||
if [ ${LOGMODE} -ne 0 ]; then
|
|
||||||
# Stop mcklogd which has survived McKernel shutdown because
|
|
||||||
# mcstop+release.sh is not used
|
|
||||||
pkill mcklogd
|
|
||||||
SBINDIR=${SBINDIR} ${SBINDIR}/mcklogd -i ${INTERVAL} -f ${facility}
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Load IHK if not loaded
|
# Load IHK if not loaded
|
||||||
if [ "`lsmod | grep ihk`" == "" ]; then
|
if ! grep -E 'ihk\s' /proc/modules &>/dev/null; then
|
||||||
if ! insmod ${KMODDIR}/ihk.ko; then
|
if ! insmod ${KMODDIR}/ihk.ko 2>/dev/null; then
|
||||||
echo "error: loading ihk" >&2
|
echo "error: loading ihk" >&2
|
||||||
error_exit "irqbalance_stopped"
|
error_exit "irqbalance_stopped"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Increase swappiness so that we have better chance to allocate memory for IHK
|
||||||
|
echo 100 > /proc/sys/vm/swappiness
|
||||||
|
|
||||||
# Drop Linux caches to free memory
|
# Drop Linux caches to free memory
|
||||||
sync && echo 3 > /proc/sys/vm/drop_caches
|
sync && echo 3 > /proc/sys/vm/drop_caches
|
||||||
|
|
||||||
# Merge free memory areas into large, physically contigous ones
|
# Merge free memory areas into large, physically contigous ones
|
||||||
echo 1 > /proc/sys/vm/compact_memory 2>/dev/null
|
echo 1 > /proc/sys/vm/compact_memory 2>/dev/null
|
||||||
|
|
||||||
|
sync
|
||||||
|
|
||||||
# Load IHK-SMP if not loaded and reserve CPUs and memory
|
# Load IHK-SMP if not loaded and reserve CPUs and memory
|
||||||
if [ "`lsmod | grep ihk_smp_x86`" == "" ]; then
|
if ! grep ihk_smp_x86 /proc/modules &>/dev/null; then
|
||||||
ihk_irq=""
|
ihk_irq=""
|
||||||
for i in `seq 64 255`; do
|
for i in `seq 64 255`; do
|
||||||
if [ ! -d /proc/irq/$i ] && [ "`cat /proc/interrupts | grep ":" | awk '{print $1}' | grep -o '[0-9]*' | grep -e '^$i$'`" == "" ]; then
|
if [ ! -d /proc/irq/$i ] && [ "`cat /proc/interrupts | grep ":" | awk '{print $1}' | grep -o '[0-9]*' | grep -e '^$i$'`" == "" ]; then
|
||||||
@@ -286,25 +292,38 @@ if [ "`lsmod | grep ihk_smp_x86`" == "" ]; then
|
|||||||
echo "error: no IRQ available" >&2
|
echo "error: no IRQ available" >&2
|
||||||
error_exit "ihk_loaded"
|
error_exit "ihk_loaded"
|
||||||
fi
|
fi
|
||||||
if ! insmod ${KMODDIR}/ihk-smp-x86.ko ihk_start_irq=$ihk_irq ihk_ikc_irq_core=$ihk_ikc_irq_core; then
|
if ! insmod ${KMODDIR}/ihk-smp-x86.ko ihk_start_irq=$ihk_irq ihk_ikc_irq_core=$ihk_ikc_irq_core 2>/dev/null; then
|
||||||
echo "error: loading ihk-smp-x86" >&2
|
echo "error: loading ihk-smp-x86" >&2
|
||||||
error_exit "ihk_loaded"
|
error_exit "ihk_loaded"
|
||||||
fi
|
fi
|
||||||
if ! ${SBINDIR}/ihkconfig 0 reserve cpu ${cpus}; then
|
|
||||||
echo "error: reserving CPUs" >&2;
|
# Free MCDRAM (special case for OFP SNC-4 mode)
|
||||||
error_exit "ihk_smp_loaded"
|
if [ "`hostname | grep "c[0-9][0-9][0-9][0-9].ofp"`" != "" ] && [ "`cat /sys/devices/system/node/online`" == "0-7" ]; then
|
||||||
|
for i in 4 5 6 7; do
|
||||||
|
find /sys/devices/system/node/node$i/memory*/ -name "online" | while read f; do
|
||||||
|
echo 0 > $f 2>&1 > /dev/null;
|
||||||
|
done
|
||||||
|
find /sys/devices/system/node/node$i/memory*/ -name "online" | while read f; do
|
||||||
|
echo 1 > $f 2>&1 > /dev/null;
|
||||||
|
done
|
||||||
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! ${SBINDIR}/ihkconfig 0 reserve mem ${mem}; then
|
if ! ${SBINDIR}/ihkconfig 0 reserve mem ${mem}; then
|
||||||
echo "error: reserving memory" >&2
|
echo "error: reserving memory" >&2
|
||||||
error_exit "cpus_reserved"
|
error_exit "ihk_smp_loaded"
|
||||||
|
fi
|
||||||
|
if ! ${SBINDIR}/ihkconfig 0 reserve cpu ${cpus}; then
|
||||||
|
echo "error: reserving CPUs" >&2;
|
||||||
|
error_exit "mem_reserved"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Load mcctrl if not loaded
|
# Load mcctrl if not loaded
|
||||||
if [ "`lsmod | grep mcctrl`" == "" ]; then
|
if ! grep mcctrl /proc/modules &>/dev/null; then
|
||||||
if ! insmod ${KMODDIR}/mcctrl.ko; then
|
if ! insmod ${KMODDIR}/mcctrl.ko 2>/dev/null; then
|
||||||
echo "error: inserting mcctrl.ko" >&2
|
echo "error: inserting mcctrl.ko" >&2
|
||||||
error_exit "mem_reserved"
|
error_exit "cpus_reserved"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -362,17 +381,21 @@ fi
|
|||||||
|
|
||||||
# Overlay /proc, /sys with McKernel specific contents
|
# Overlay /proc, /sys with McKernel specific contents
|
||||||
if [ "$enable_mcoverlay" == "yes" ]; then
|
if [ "$enable_mcoverlay" == "yes" ]; then
|
||||||
if [ ! -e /tmp/mcos ]; then mkdir -p /tmp/mcos; fi
|
if [ ! -e /tmp/mcos ]; then
|
||||||
|
mkdir -p /tmp/mcos;
|
||||||
|
fi
|
||||||
if ! mount -t tmpfs tmpfs /tmp/mcos; then
|
if ! mount -t tmpfs tmpfs /tmp/mcos; then
|
||||||
echo "error: mount /tmp/mcos" >&2
|
echo "error: mount /tmp/mcos" >&2
|
||||||
error_exit "tmp_mcos_created"
|
error_exit "tmp_mcos_created"
|
||||||
fi
|
fi
|
||||||
if [ ! -e /tmp/mcos/linux_proc ]; then mkdir -p /tmp/mcos/linux_proc; fi
|
if [ ! -e /tmp/mcos/linux_proc ]; then
|
||||||
|
mkdir -p /tmp/mcos/linux_proc;
|
||||||
|
fi
|
||||||
if ! mount --bind /proc /tmp/mcos/linux_proc; then
|
if ! mount --bind /proc /tmp/mcos/linux_proc; then
|
||||||
echo "error: mount /tmp/mcos/linux_proc" >&2
|
echo "error: mount /tmp/mcos/linux_proc" >&2
|
||||||
error_exit "tmp_mcos_mounted"
|
error_exit "tmp_mcos_mounted"
|
||||||
fi
|
fi
|
||||||
if ! insmod ${KMODDIR}/mcoverlay.ko; then
|
if ! insmod ${KMODDIR}/mcoverlay.ko 2>/dev/null; then
|
||||||
echo "error: inserting mcoverlay.ko" >&2
|
echo "error: inserting mcoverlay.ko" >&2
|
||||||
error_exit "linux_proc_bind_mounted"
|
error_exit "linux_proc_bind_mounted"
|
||||||
fi
|
fi
|
||||||
@@ -380,9 +403,15 @@ if [ "$enable_mcoverlay" == "yes" ]; then
|
|||||||
do
|
do
|
||||||
sleep 0.1
|
sleep 0.1
|
||||||
done
|
done
|
||||||
if [ ! -e /tmp/mcos/mcos0_proc ]; then mkdir -p /tmp/mcos/mcos0_proc; fi
|
if [ ! -e /tmp/mcos/mcos0_proc ]; then
|
||||||
if [ ! -e /tmp/mcos/mcos0_proc_upper ]; then mkdir -p /tmp/mcos/mcos0_proc_upper; fi
|
mkdir -p /tmp/mcos/mcos0_proc;
|
||||||
if [ ! -e /tmp/mcos/mcos0_proc_work ]; then mkdir -p /tmp/mcos/mcos0_proc_work; fi
|
fi
|
||||||
|
if [ ! -e /tmp/mcos/mcos0_proc_upper ]; then
|
||||||
|
mkdir -p /tmp/mcos/mcos0_proc_upper;
|
||||||
|
fi
|
||||||
|
if [ ! -e /tmp/mcos/mcos0_proc_work ]; then
|
||||||
|
mkdir -p /tmp/mcos/mcos0_proc_work;
|
||||||
|
fi
|
||||||
if ! mount -t mcoverlay mcoverlay -o lowerdir=/proc/mcos0:/proc,upperdir=/tmp/mcos/mcos0_proc_upper,workdir=/tmp/mcos/mcos0_proc_work,nocopyupw,nofscheck /tmp/mcos/mcos0_proc; then
|
if ! mount -t mcoverlay mcoverlay -o lowerdir=/proc/mcos0:/proc,upperdir=/tmp/mcos/mcos0_proc_upper,workdir=/tmp/mcos/mcos0_proc_work,nocopyupw,nofscheck /tmp/mcos/mcos0_proc; then
|
||||||
echo "error: mounting /tmp/mcos/mcos0_proc" >&2
|
echo "error: mounting /tmp/mcos/mcos0_proc" >&2
|
||||||
error_exit "mcoverlayfs_loaded"
|
error_exit "mcoverlayfs_loaded"
|
||||||
@@ -394,9 +423,15 @@ if [ "$enable_mcoverlay" == "yes" ]; then
|
|||||||
do
|
do
|
||||||
sleep 0.1
|
sleep 0.1
|
||||||
done
|
done
|
||||||
if [ ! -e /tmp/mcos/mcos0_sys ]; then mkdir -p /tmp/mcos/mcos0_sys; fi
|
if [ ! -e /tmp/mcos/mcos0_sys ]; then
|
||||||
if [ ! -e /tmp/mcos/mcos0_sys_upper ]; then mkdir -p /tmp/mcos/mcos0_sys_upper; fi
|
mkdir -p /tmp/mcos/mcos0_sys;
|
||||||
if [ ! -e /tmp/mcos/mcos0_sys_work ]; then mkdir -p /tmp/mcos/mcos0_sys_work; fi
|
fi
|
||||||
|
if [ ! -e /tmp/mcos/mcos0_sys_upper ]; then
|
||||||
|
mkdir -p /tmp/mcos/mcos0_sys_upper;
|
||||||
|
fi
|
||||||
|
if [ ! -e /tmp/mcos/mcos0_sys_work ]; then
|
||||||
|
mkdir -p /tmp/mcos/mcos0_sys_work;
|
||||||
|
fi
|
||||||
if ! mount -t mcoverlay mcoverlay -o lowerdir=/sys/devices/virtual/mcos/mcos0/sys:/sys,upperdir=/tmp/mcos/mcos0_sys_upper,workdir=/tmp/mcos/mcos0_sys_work,nocopyupw,nofscheck /tmp/mcos/mcos0_sys; then
|
if ! mount -t mcoverlay mcoverlay -o lowerdir=/sys/devices/virtual/mcos/mcos0/sys:/sys,upperdir=/tmp/mcos/mcos0_sys_upper,workdir=/tmp/mcos/mcos0_sys_work,nocopyupw,nofscheck /tmp/mcos/mcos0_sys; then
|
||||||
echo "error: mount /tmp/mcos/mcos0_sys" >&2
|
echo "error: mount /tmp/mcos/mcos0_sys" >&2
|
||||||
error_exit "mcos_proc_mounted"
|
error_exit "mcos_proc_mounted"
|
||||||
@@ -462,8 +497,9 @@ if [ "${irqbalance_used}" == "yes" ]; then
|
|||||||
|
|
||||||
banirq=`cat /proc/interrupts| perl -e 'while(<>) { if(/^\s*(\d+).*IHK\-SMP\s*$/) {print $1;}}'`
|
banirq=`cat /proc/interrupts| perl -e 'while(<>) { if(/^\s*(\d+).*IHK\-SMP\s*$/) {print $1;}}'`
|
||||||
|
|
||||||
sed "s/%mask%/$smp_affinity_mask/g" $ETCDIR/irqbalance_mck.in | sed "s/%banirq%/$banirq/g" > $ETCDIR/irqbalance_mck
|
sed "s/%mask%/$smp_affinity_mask/g" $ETCDIR/irqbalance_mck.in | sed "s/%banirq%/$banirq/g" > /tmp/irqbalance_mck
|
||||||
if ! systemctl link $ETCDIR/irqbalance_mck.service >/dev/null 2>/dev/null; then
|
systemctl disable irqbalance_mck.service >/dev/null 2>/dev/null
|
||||||
|
if ! systemctl link $ETCDIR/irqbalance_mck.service >/dev/null 2>/dev/null; then
|
||||||
echo "error: linking irqbalance_mck" >&2
|
echo "error: linking irqbalance_mck" >&2
|
||||||
error_exit "mcos_sys_mounted"
|
error_exit "mcos_sys_mounted"
|
||||||
fi
|
fi
|
||||||
@@ -475,3 +511,13 @@ if [ "${irqbalance_used}" == "yes" ]; then
|
|||||||
# echo cpus=$cpus mask=$smp_affinity_mask banirq=$banirq
|
# echo cpus=$cpus mask=$smp_affinity_mask banirq=$banirq
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Start mcklogd. Note that McKernel blocks when kmsg buffer is full
|
||||||
|
# with '-k 1' until mcklogd unblocks it so starting mcklogd must preceed
|
||||||
|
# booting McKernel
|
||||||
|
if [ ${LOGMODE} -ne 0 ]; then
|
||||||
|
# Stop mcklogd which has survived McKernel shutdown because
|
||||||
|
# mcstop+release.sh is not used
|
||||||
|
pkill mcklogd
|
||||||
|
SBINDIR=${SBINDIR} ${SBINDIR}/mcklogd -i ${INTERVAL} -f ${facility}
|
||||||
|
fi
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,13 @@ mem=""
|
|||||||
cpus=""
|
cpus=""
|
||||||
|
|
||||||
# No SMP module? Exit.
|
# No SMP module? Exit.
|
||||||
if [ "`lsmod | grep ihk_smp_x86`" == "" ]; then exit 0; fi
|
if ! grep ihk_smp_x86 /proc/modules &>/dev/null; then exit 0; fi
|
||||||
|
|
||||||
|
# Stop mcklogd
|
||||||
|
while pgrep "mcklogd" > /dev/null 2>&1;
|
||||||
|
do
|
||||||
|
pkill -9 mcklogd
|
||||||
|
done
|
||||||
|
|
||||||
# Destroy all LWK instances
|
# Destroy all LWK instances
|
||||||
if ls /dev/mcos* 1>/dev/null 2>&1; then
|
if ls /dev/mcos* 1>/dev/null 2>&1; then
|
||||||
@@ -59,44 +65,41 @@ if [ "${mem}" != "" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Remove delegator if loaded
|
# Remove delegator if loaded
|
||||||
if [ "`lsmod | grep mcctrl`" != "" ]; then
|
if grep mcctrl /proc/modules &>/dev/null; then
|
||||||
if ! rmmod mcctrl; then
|
if ! rmmod mcctrl 2>/dev/null; then
|
||||||
echo "error: removing mcctrl" >&2
|
echo "error: removing mcctrl" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Remove mcoverlay if loaded
|
# Remove mcoverlay if loaded
|
||||||
if [ "`lsmod | grep mcoverlay`" != "" ]; then
|
if grep mcoverlay /proc/modules &>/dev/null; then
|
||||||
if [ "`cat /proc/mounts | grep /tmp/mcos/mcos0_sys`" != "" ]; then umount -l /tmp/mcos/mcos0_sys; fi
|
if [ "`cat /proc/mounts | grep /tmp/mcos/mcos0_sys`" != "" ]; then umount -l /tmp/mcos/mcos0_sys; fi
|
||||||
if [ "`cat /proc/mounts | grep /tmp/mcos/mcos0_proc`" != "" ]; then umount -l /tmp/mcos/mcos0_proc; fi
|
if [ "`cat /proc/mounts | grep /tmp/mcos/mcos0_proc`" != "" ]; then umount -l /tmp/mcos/mcos0_proc; fi
|
||||||
if [ "`cat /proc/mounts | grep /tmp/mcos/linux_proc`" != "" ]; then umount -l /tmp/mcos/linux_proc; fi
|
if [ "`cat /proc/mounts | grep /tmp/mcos/linux_proc`" != "" ]; then umount -l /tmp/mcos/linux_proc; fi
|
||||||
if [ "`cat /proc/mounts | grep /tmp/mcos`" != "" ]; then umount -l /tmp/mcos; fi
|
if [ "`cat /proc/mounts | grep /tmp/mcos`" != "" ]; then umount -l /tmp/mcos; fi
|
||||||
if [ -e /tmp/mcos ]; then rm -rf /tmp/mcos; fi
|
if [ -e /tmp/mcos ]; then rm -rf /tmp/mcos; fi
|
||||||
if ! rmmod mcoverlay; then
|
if ! rmmod mcoverlay 2>/dev/null; then
|
||||||
echo "warning: failed to remove mcoverlay" >&2
|
echo "warning: failed to remove mcoverlay" >&2
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Remove SMP module
|
# Remove SMP module
|
||||||
if [ "`lsmod | grep ihk_smp_x86`" != "" ]; then
|
if grep ihk_smp_x86 /proc/modules &>/dev/null; then
|
||||||
if ! rmmod ihk_smp_x86; then
|
if ! rmmod ihk_smp_x86 2>/dev/null; then
|
||||||
echo "error: removing ihk_smp_x86" >&2
|
echo "error: removing ihk_smp_x86" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Remove core module
|
# Remove core module
|
||||||
if [ "`lsmod | grep -E 'ihk\s' | awk '{print $1}'`" != "" ]; then
|
if grep -E 'ihk\s' /proc/modules &>/dev/null; then
|
||||||
if ! rmmod ihk; then
|
if ! rmmod ihk 2>/dev/null; then
|
||||||
echo "error: removing ihk" >&2
|
echo "error: removing ihk" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Stop mcklogd
|
|
||||||
pkill mcklogd
|
|
||||||
|
|
||||||
# Start irqbalance with the original settings
|
# Start irqbalance with the original settings
|
||||||
if [ "`systemctl status irqbalance_mck.service 2> /dev/null |grep -E 'Active: active'`" != "" ]; then
|
if [ "`systemctl status irqbalance_mck.service 2> /dev/null |grep -E 'Active: active'`" != "" ]; then
|
||||||
if ! systemctl stop irqbalance_mck.service 2>/dev/null; then
|
if ! systemctl stop irqbalance_mck.service 2>/dev/null; then
|
||||||
@@ -113,3 +116,10 @@ if [ "`systemctl status irqbalance_mck.service 2> /dev/null |grep -E 'Active: ac
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Re-enable ASLR
|
||||||
|
if [ -f /tmp/mckernel_randomize_va_space ]; then
|
||||||
|
cat /tmp/mckernel_randomize_va_space > /proc/sys/kernel/randomize_va_space
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Set back default swappiness
|
||||||
|
echo 60 > /proc/sys/vm/swappiness
|
||||||
|
|||||||
21
configure.ac
21
configure.ac
@@ -17,6 +17,13 @@ DCFA_RELEASE_DATE=DCFA_RELEASE_DATE_m4
|
|||||||
|
|
||||||
AC_PREFIX_DEFAULT([/opt/ppos])
|
AC_PREFIX_DEFAULT([/opt/ppos])
|
||||||
|
|
||||||
|
AC_CHECK_HEADER([numa.h],[numa_header_found=yes])
|
||||||
|
AS_IF([test "x$numa_header_found" != "xyes"],
|
||||||
|
[AC_MSG_ERROR([Unable to find numa.h header file, missing numactl-devel?])])
|
||||||
|
AC_CHECK_LIB([numa],[numa_run_on_node],[numa_lib_found=yes])
|
||||||
|
AS_IF([test "x$numa_lib_found" != "xyes"],
|
||||||
|
[AC_MSG_ERROR([Unable to find NUMA library, missing numactl-devel?])])
|
||||||
|
|
||||||
AC_ARG_WITH([kernelsrc],
|
AC_ARG_WITH([kernelsrc],
|
||||||
AC_HELP_STRING(
|
AC_HELP_STRING(
|
||||||
[--with-kernelsrc=path],[Path to 'kernel src', default is /lib/modules/uname_r/build]),
|
[--with-kernelsrc=path],[Path to 'kernel src', default is /lib/modules/uname_r/build]),
|
||||||
@@ -48,6 +55,17 @@ AC_ARG_ENABLE([mcoverlayfs],
|
|||||||
[ENABLE_MCOVERLAYFS=$enableval],
|
[ENABLE_MCOVERLAYFS=$enableval],
|
||||||
[ENABLE_MCOVERLAYFS=yes])
|
[ENABLE_MCOVERLAYFS=yes])
|
||||||
|
|
||||||
|
AC_ARG_WITH([uname_r],
|
||||||
|
AC_HELP_STRING(
|
||||||
|
[--with-uname_r=uname_r],[Value of '`uname -r`' on the target platform, default is local value]),
|
||||||
|
[WITH_UNAME_R=$withval],[WITH_UNAME_R=yes])
|
||||||
|
|
||||||
|
case "X$WITH_UNAME_R" in
|
||||||
|
Xyes | Xno | X)
|
||||||
|
WITH_UNAME_R='`uname -r`'
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
case "X$WITH_KERNELSRC" in
|
case "X$WITH_KERNELSRC" in
|
||||||
Xyes | Xno | X)
|
Xyes | Xno | X)
|
||||||
WITH_KERNELSRC='/lib/modules/`uname -r`/build'
|
WITH_KERNELSRC='/lib/modules/`uname -r`/build'
|
||||||
@@ -163,6 +181,7 @@ case $WITH_TARGET in
|
|||||||
esac
|
esac
|
||||||
|
|
||||||
KDIR="$WITH_KERNELSRC"
|
KDIR="$WITH_KERNELSRC"
|
||||||
|
UNAME_R="$WITH_UNAME_R"
|
||||||
TARGET="$WITH_TARGET"
|
TARGET="$WITH_TARGET"
|
||||||
|
|
||||||
MCCTRL_LINUX_SYMTAB=""
|
MCCTRL_LINUX_SYMTAB=""
|
||||||
@@ -280,6 +299,7 @@ AC_SUBST(CC)
|
|||||||
AC_SUBST(XCC)
|
AC_SUBST(XCC)
|
||||||
AC_SUBST(ARCH)
|
AC_SUBST(ARCH)
|
||||||
AC_SUBST(KDIR)
|
AC_SUBST(KDIR)
|
||||||
|
AC_SUBST(UNAME_R)
|
||||||
AC_SUBST(TARGET)
|
AC_SUBST(TARGET)
|
||||||
AC_SUBST(BINDIR)
|
AC_SUBST(BINDIR)
|
||||||
AC_SUBST(SBINDIR)
|
AC_SUBST(SBINDIR)
|
||||||
@@ -315,6 +335,7 @@ AC_CONFIG_FILES([
|
|||||||
arch/x86/tools/mcreboot-builtin-x86.sh
|
arch/x86/tools/mcreboot-builtin-x86.sh
|
||||||
arch/x86/tools/mcreboot-smp-x86.sh
|
arch/x86/tools/mcreboot-smp-x86.sh
|
||||||
arch/x86/tools/mcstop+release-smp-x86.sh
|
arch/x86/tools/mcstop+release-smp-x86.sh
|
||||||
|
arch/x86/tools/eclair-dump-backtrace.exp
|
||||||
arch/x86/tools/mcshutdown-builtin-x86.sh
|
arch/x86/tools/mcshutdown-builtin-x86.sh
|
||||||
arch/x86/tools/mcreboot.1:arch/x86/tools/mcreboot.1in
|
arch/x86/tools/mcreboot.1:arch/x86/tools/mcreboot.1in
|
||||||
arch/x86/tools/irqbalance_mck.service
|
arch/x86/tools/irqbalance_mck.service
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ struct get_cpu_set_arg {
|
|||||||
void *cpu_set;
|
void *cpu_set;
|
||||||
size_t cpu_set_size; // Size in bytes
|
size_t cpu_set_size; // Size in bytes
|
||||||
int *target_core;
|
int *target_core;
|
||||||
|
int *mcexec_linux_numa; // NUMA domain to bind mcexec to
|
||||||
};
|
};
|
||||||
|
|
||||||
#define PLD_CPU_SET_MAX_CPUS 1024
|
#define PLD_CPU_SET_MAX_CPUS 1024
|
||||||
@@ -219,4 +220,34 @@ struct sys_unshare_desc {
|
|||||||
unsigned long unshare_flags;
|
unsigned long unshare_flags;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum perf_ctrl_type {
|
||||||
|
PERF_CTRL_SET,
|
||||||
|
PERF_CTRL_GET,
|
||||||
|
PERF_CTRL_ENABLE,
|
||||||
|
PERF_CTRL_DISABLE,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct perf_ctrl_desc {
|
||||||
|
enum perf_ctrl_type ctrl_type;
|
||||||
|
int status;
|
||||||
|
union {
|
||||||
|
/* for SET, GET */
|
||||||
|
struct {
|
||||||
|
unsigned int target_cntr;
|
||||||
|
unsigned long config;
|
||||||
|
unsigned long read_value;
|
||||||
|
unsigned disabled :1,
|
||||||
|
pinned :1,
|
||||||
|
exclude_user :1,
|
||||||
|
exclude_kernel :1,
|
||||||
|
exclude_hv :1,
|
||||||
|
exclude_idle :1;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* for START, STOP*/
|
||||||
|
struct {
|
||||||
|
unsigned long target_cntr_mask;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -64,6 +64,8 @@ reserve_user_space(struct mcctrl_usrdata *usrdata, unsigned long *startp, unsign
|
|||||||
unsigned long start = 0L;
|
unsigned long start = 0L;
|
||||||
unsigned long end;
|
unsigned long end;
|
||||||
|
|
||||||
|
mutex_lock(&usrdata->reserve_lock);
|
||||||
|
|
||||||
#define DESIRED_USER_END 0x800000000000
|
#define DESIRED_USER_END 0x800000000000
|
||||||
#define GAP_FOR_MCEXEC 0x008000000000UL
|
#define GAP_FOR_MCEXEC 0x008000000000UL
|
||||||
end = DESIRED_USER_END;
|
end = DESIRED_USER_END;
|
||||||
@@ -81,6 +83,8 @@ reserve_user_space(struct mcctrl_usrdata *usrdata, unsigned long *startp, unsign
|
|||||||
up_write(¤t->mm->mmap_sem);
|
up_write(¤t->mm->mmap_sem);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
mutex_unlock(&usrdata->reserve_lock);
|
||||||
|
|
||||||
if (IS_ERR_VALUE(start)) {
|
if (IS_ERR_VALUE(start)) {
|
||||||
return start;
|
return start;
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -27,6 +27,7 @@
|
|||||||
#include <linux/slab.h>
|
#include <linux/slab.h>
|
||||||
#include <linux/device.h>
|
#include <linux/device.h>
|
||||||
#include "mcctrl.h"
|
#include "mcctrl.h"
|
||||||
|
#include <ihk/ihk_host_user.h>
|
||||||
|
|
||||||
#define OS_MAX_MINOR 64
|
#define OS_MAX_MINOR 64
|
||||||
|
|
||||||
@@ -74,6 +75,12 @@ static struct ihk_os_user_call_handler mcctrl_uchs[] = {
|
|||||||
{ .request = MCEXEC_UP_SYS_UMOUNT, .func = mcctrl_ioctl },
|
{ .request = MCEXEC_UP_SYS_UMOUNT, .func = mcctrl_ioctl },
|
||||||
{ .request = MCEXEC_UP_SYS_UNSHARE, .func = mcctrl_ioctl },
|
{ .request = MCEXEC_UP_SYS_UNSHARE, .func = mcctrl_ioctl },
|
||||||
{ .request = MCEXEC_UP_DEBUG_LOG, .func = mcctrl_ioctl },
|
{ .request = MCEXEC_UP_DEBUG_LOG, .func = mcctrl_ioctl },
|
||||||
|
{ .request = IHK_OS_AUX_PERF_NUM, .func = mcctrl_ioctl },
|
||||||
|
{ .request = IHK_OS_AUX_PERF_SET, .func = mcctrl_ioctl },
|
||||||
|
{ .request = IHK_OS_AUX_PERF_GET, .func = mcctrl_ioctl },
|
||||||
|
{ .request = IHK_OS_AUX_PERF_ENABLE, .func = mcctrl_ioctl },
|
||||||
|
{ .request = IHK_OS_AUX_PERF_DISABLE, .func = mcctrl_ioctl },
|
||||||
|
{ .request = IHK_OS_AUX_PERF_DESTROY, .func = mcctrl_ioctl },
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct ihk_os_user_call mcctrl_uc_proto = {
|
static struct ihk_os_user_call mcctrl_uc_proto = {
|
||||||
|
|||||||
@@ -53,6 +53,9 @@ void mcexec_prepare_ack(ihk_os_t os, unsigned long arg, int err);
|
|||||||
static void mcctrl_ikc_init(ihk_os_t os, int cpu, unsigned long rphys, struct ihk_ikc_channel_desc *c);
|
static void mcctrl_ikc_init(ihk_os_t os, int cpu, unsigned long rphys, struct ihk_ikc_channel_desc *c);
|
||||||
int mcexec_syscall(struct mcctrl_usrdata *ud, struct ikc_scd_packet *packet);
|
int mcexec_syscall(struct mcctrl_usrdata *ud, struct ikc_scd_packet *packet);
|
||||||
void sig_done(unsigned long arg, int err);
|
void sig_done(unsigned long arg, int err);
|
||||||
|
void mcctrl_perf_ack(ihk_os_t os, struct ikc_scd_packet *packet);
|
||||||
|
void mcctrl_os_read_write_cpu_response(ihk_os_t os,
|
||||||
|
struct ikc_scd_packet *pisp);
|
||||||
|
|
||||||
/* XXX: this runs in atomic context! */
|
/* XXX: this runs in atomic context! */
|
||||||
static int syscall_packet_handler(struct ihk_ikc_channel_desc *c,
|
static int syscall_packet_handler(struct ihk_ikc_channel_desc *c,
|
||||||
@@ -80,7 +83,7 @@ static int syscall_packet_handler(struct ihk_ikc_channel_desc *c,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case SCD_MSG_PROCFS_ANSWER:
|
case SCD_MSG_PROCFS_ANSWER:
|
||||||
procfs_answer(pisp->arg, pisp->err);
|
procfs_answer(usrdata, pisp->pid);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SCD_MSG_SEND_SIGNAL:
|
case SCD_MSG_SEND_SIGNAL:
|
||||||
@@ -109,6 +112,14 @@ static int syscall_packet_handler(struct ihk_ikc_channel_desc *c,
|
|||||||
get_vdso_info(__os, pisp->arg);
|
get_vdso_info(__os, pisp->arg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case SCD_MSG_PERF_ACK:
|
||||||
|
mcctrl_perf_ack(__os, pisp);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SCD_MSG_CPU_RW_REG_RESP:
|
||||||
|
mcctrl_os_read_write_cpu_response(__os, pisp);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
printk(KERN_ERR "mcctrl:syscall_packet_handler:"
|
printk(KERN_ERR "mcctrl:syscall_packet_handler:"
|
||||||
"unknown message (%d.%d.%d.%d.%d.%#lx)\n",
|
"unknown message (%d.%d.%d.%d.%d.%#lx)\n",
|
||||||
@@ -283,12 +294,13 @@ int prepare_ikc_channels(ihk_os_t os)
|
|||||||
}
|
}
|
||||||
|
|
||||||
usrdata->os = os;
|
usrdata->os = os;
|
||||||
init_waitqueue_head(&usrdata->wq_prepare);
|
|
||||||
ihk_host_os_set_usrdata(os, usrdata);
|
ihk_host_os_set_usrdata(os, usrdata);
|
||||||
memcpy(&usrdata->listen_param, &listen_param, sizeof listen_param);
|
memcpy(&usrdata->listen_param, &listen_param, sizeof listen_param);
|
||||||
ihk_ikc_listen_port(os, &usrdata->listen_param);
|
ihk_ikc_listen_port(os, &usrdata->listen_param);
|
||||||
memcpy(&usrdata->listen_param2, &listen_param2, sizeof listen_param2);
|
memcpy(&usrdata->listen_param2, &listen_param2, sizeof listen_param2);
|
||||||
ihk_ikc_listen_port(os, &usrdata->listen_param2);
|
ihk_ikc_listen_port(os, &usrdata->listen_param2);
|
||||||
|
init_waitqueue_head(&usrdata->wq_procfs);
|
||||||
|
mutex_init(&usrdata->reserve_lock);
|
||||||
|
|
||||||
for (i = 0; i < MCCTRL_PER_PROC_DATA_HASH_SIZE; ++i) {
|
for (i = 0; i < MCCTRL_PER_PROC_DATA_HASH_SIZE; ++i) {
|
||||||
INIT_LIST_HEAD(&usrdata->per_proc_data_hash[i]);
|
INIT_LIST_HEAD(&usrdata->per_proc_data_hash[i]);
|
||||||
@@ -326,7 +338,6 @@ void destroy_ikc_channels(ihk_os_t os)
|
|||||||
// ihk_ikc_disconnect(usrdata->channels[i].c);
|
// ihk_ikc_disconnect(usrdata->channels[i].c);
|
||||||
ihk_ikc_free_channel(usrdata->channels[i].c);
|
ihk_ikc_free_channel(usrdata->channels[i].c);
|
||||||
__destroy_ikc_channel(os, usrdata->channels + i);
|
__destroy_ikc_channel(os, usrdata->channels + i);
|
||||||
printk("Channel #%d freed.\n", i);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,6 +44,7 @@
|
|||||||
#include <linux/rwlock.h>
|
#include <linux/rwlock.h>
|
||||||
#include <linux/threads.h>
|
#include <linux/threads.h>
|
||||||
#include "sysfs.h"
|
#include "sysfs.h"
|
||||||
|
#include "mcctrl_public.h"
|
||||||
|
|
||||||
#define SCD_MSG_PREPARE_PROCESS 0x1
|
#define SCD_MSG_PREPARE_PROCESS 0x1
|
||||||
#define SCD_MSG_PREPARE_PROCESS_ACKED 0x2
|
#define SCD_MSG_PREPARE_PROCESS_ACKED 0x2
|
||||||
@@ -92,6 +93,12 @@
|
|||||||
#define SCD_MSG_PROCFS_TID_CREATE 0x44
|
#define SCD_MSG_PROCFS_TID_CREATE 0x44
|
||||||
#define SCD_MSG_PROCFS_TID_DELETE 0x45
|
#define SCD_MSG_PROCFS_TID_DELETE 0x45
|
||||||
|
|
||||||
|
#define SCD_MSG_PERF_CTRL 0x50
|
||||||
|
#define SCD_MSG_PERF_ACK 0x51
|
||||||
|
|
||||||
|
#define SCD_MSG_CPU_RW_REG 0x52
|
||||||
|
#define SCD_MSG_CPU_RW_REG_RESP 0x53
|
||||||
|
|
||||||
#define DMA_PIN_SHIFT 21
|
#define DMA_PIN_SHIFT 21
|
||||||
|
|
||||||
#define DO_USER_MODE
|
#define DO_USER_MODE
|
||||||
@@ -103,6 +110,12 @@ struct coretable {
|
|||||||
unsigned long addr;
|
unsigned long addr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum mcctrl_os_cpu_operation {
|
||||||
|
MCCTRL_OS_CPU_READ_REGISTER,
|
||||||
|
MCCTRL_OS_CPU_WRITE_REGISTER,
|
||||||
|
MCCTRL_OS_CPU_MAX_OP
|
||||||
|
};
|
||||||
|
|
||||||
struct ikc_scd_packet {
|
struct ikc_scd_packet {
|
||||||
int msg;
|
int msg;
|
||||||
int err;
|
int err;
|
||||||
@@ -128,6 +141,13 @@ struct ikc_scd_packet {
|
|||||||
struct {
|
struct {
|
||||||
int ttid;
|
int ttid;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* SCD_MSG_CPU_RW_REG */
|
||||||
|
struct {
|
||||||
|
struct mcctrl_os_cpu_register desc;
|
||||||
|
enum mcctrl_os_cpu_operation op;
|
||||||
|
void *resp;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
char padding[12];
|
char padding[12];
|
||||||
};
|
};
|
||||||
@@ -187,19 +207,24 @@ struct mcctrl_per_thread_data {
|
|||||||
#define MCCTRL_PER_THREAD_DATA_HASH_MASK (MCCTRL_PER_THREAD_DATA_HASH_SIZE - 1)
|
#define MCCTRL_PER_THREAD_DATA_HASH_MASK (MCCTRL_PER_THREAD_DATA_HASH_SIZE - 1)
|
||||||
|
|
||||||
struct mcctrl_per_proc_data {
|
struct mcctrl_per_proc_data {
|
||||||
|
struct mcctrl_usrdata *ud;
|
||||||
struct list_head hash;
|
struct list_head hash;
|
||||||
int pid;
|
int pid;
|
||||||
unsigned long rpgtable; /* per process, not per OS */
|
unsigned long rpgtable; /* per process, not per OS */
|
||||||
|
|
||||||
struct list_head wq_list;
|
struct list_head wq_list; /* All these requests come from mcexec */
|
||||||
struct list_head wq_req_list;
|
struct list_head wq_req_list; /* These requests come from IKC IRQ handler (can be processed by any threads) */
|
||||||
struct list_head wq_list_exact;
|
struct list_head wq_list_exact; /* These requests come from IKC IRQ handler targeting a particular thread */
|
||||||
|
|
||||||
ihk_spinlock_t wq_list_lock;
|
ihk_spinlock_t wq_list_lock;
|
||||||
|
wait_queue_head_t wq_prepare;
|
||||||
|
wait_queue_head_t wq_procfs;
|
||||||
|
|
||||||
struct list_head per_thread_data_hash[MCCTRL_PER_THREAD_DATA_HASH_SIZE];
|
struct list_head per_thread_data_hash[MCCTRL_PER_THREAD_DATA_HASH_SIZE];
|
||||||
rwlock_t per_thread_data_hash_lock[MCCTRL_PER_THREAD_DATA_HASH_SIZE];
|
rwlock_t per_thread_data_hash_lock[MCCTRL_PER_THREAD_DATA_HASH_SIZE];
|
||||||
cpumask_t cpu_set;
|
cpumask_t cpu_set;
|
||||||
int ikc_target_cpu;
|
int ikc_target_cpu;
|
||||||
|
atomic_t refcount;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sysfsm_req {
|
struct sysfsm_req {
|
||||||
@@ -279,9 +304,9 @@ struct mcctrl_usrdata {
|
|||||||
int base_cpu;
|
int base_cpu;
|
||||||
int job_pos;
|
int job_pos;
|
||||||
int mcctrl_dma_abort;
|
int mcctrl_dma_abort;
|
||||||
|
struct mutex reserve_lock;
|
||||||
unsigned long last_thread_exec;
|
unsigned long last_thread_exec;
|
||||||
wait_queue_head_t wq_prepare;
|
wait_queue_head_t wq_procfs;
|
||||||
|
|
||||||
struct list_head per_proc_data_hash[MCCTRL_PER_PROC_DATA_HASH_SIZE];
|
struct list_head per_proc_data_hash[MCCTRL_PER_PROC_DATA_HASH_SIZE];
|
||||||
rwlock_t per_proc_data_hash_lock[MCCTRL_PER_PROC_DATA_HASH_SIZE];
|
rwlock_t per_proc_data_hash_lock[MCCTRL_PER_PROC_DATA_HASH_SIZE];
|
||||||
|
|
||||||
@@ -294,6 +319,7 @@ struct mcctrl_usrdata {
|
|||||||
struct list_head cpu_topology_list;
|
struct list_head cpu_topology_list;
|
||||||
struct list_head node_topology_list;
|
struct list_head node_topology_list;
|
||||||
struct mcctrl_part_exec part_exec;
|
struct mcctrl_part_exec part_exec;
|
||||||
|
int perf_event_num;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct mcctrl_signal {
|
struct mcctrl_signal {
|
||||||
@@ -315,8 +341,9 @@ int __do_in_kernel_syscall(ihk_os_t os, struct ikc_scd_packet *packet);
|
|||||||
int mcctrl_add_per_proc_data(struct mcctrl_usrdata *ud, int pid,
|
int mcctrl_add_per_proc_data(struct mcctrl_usrdata *ud, int pid,
|
||||||
struct mcctrl_per_proc_data *ppd);
|
struct mcctrl_per_proc_data *ppd);
|
||||||
int mcctrl_delete_per_proc_data(struct mcctrl_usrdata *ud, int pid);
|
int mcctrl_delete_per_proc_data(struct mcctrl_usrdata *ud, int pid);
|
||||||
inline struct mcctrl_per_proc_data *mcctrl_get_per_proc_data(
|
struct mcctrl_per_proc_data *mcctrl_get_per_proc_data(
|
||||||
struct mcctrl_usrdata *ud, int pid);
|
struct mcctrl_usrdata *ud, int pid);
|
||||||
|
void mcctrl_put_per_proc_data(struct mcctrl_per_proc_data *ppd);
|
||||||
|
|
||||||
int mcctrl_add_per_thread_data(struct mcctrl_per_proc_data* ppd,
|
int mcctrl_add_per_thread_data(struct mcctrl_per_proc_data* ppd,
|
||||||
struct task_struct *task, void *data);
|
struct task_struct *task, void *data);
|
||||||
@@ -348,7 +375,7 @@ struct procfs_file {
|
|||||||
char fname[PROCFS_NAME_MAX]; /* procfs filename (request) */
|
char fname[PROCFS_NAME_MAX]; /* procfs filename (request) */
|
||||||
};
|
};
|
||||||
|
|
||||||
void procfs_answer(unsigned int arg, int err);
|
void procfs_answer(struct mcctrl_usrdata *ud, int pid);
|
||||||
int procfsm_packet_handler(void *os, int msg, int pid, unsigned long arg);
|
int procfsm_packet_handler(void *os, int msg, int pid, unsigned long arg);
|
||||||
void add_tid_entry(int osnum, int pid, int tid);
|
void add_tid_entry(int osnum, int pid, int tid);
|
||||||
void add_pid_entry(int osnum, int pid);
|
void add_pid_entry(int osnum, int pid);
|
||||||
@@ -396,4 +423,14 @@ struct get_cpu_mapping_req {
|
|||||||
wait_queue_head_t wq;
|
wait_queue_head_t wq;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct ihk_perf_event_attr{
|
||||||
|
unsigned long config;
|
||||||
|
unsigned disabled:1;
|
||||||
|
unsigned pinned:1;
|
||||||
|
unsigned exclude_user:1;
|
||||||
|
unsigned exclude_kernel:1;
|
||||||
|
unsigned exclude_hv:1;
|
||||||
|
unsigned exclude_idle:1;
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
20
executer/kernel/mcctrl/mcctrl_public.h
Normal file
20
executer/kernel/mcctrl/mcctrl_public.h
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#ifndef __MCCTRL_PUBLIC_H
|
||||||
|
#define __MCCTRL_PUBLIC_H
|
||||||
|
|
||||||
|
#include <ihk/ihk_host_user.h>
|
||||||
|
#include <ikc/queue.h>
|
||||||
|
|
||||||
|
struct mcctrl_os_cpu_register {
|
||||||
|
unsigned long addr;
|
||||||
|
unsigned long val;
|
||||||
|
unsigned long addr_ext;
|
||||||
|
};
|
||||||
|
|
||||||
|
int mcctrl_os_read_cpu_register(ihk_os_t os, int cpu,
|
||||||
|
struct mcctrl_os_cpu_register *desc);
|
||||||
|
int mcctrl_os_write_cpu_register(ihk_os_t os, int cpu,
|
||||||
|
struct mcctrl_os_cpu_register *desc);
|
||||||
|
int mcctrl_get_request_os_cpu(ihk_os_t *os, int *cpu);
|
||||||
|
|
||||||
|
|
||||||
|
#endif // __MCCTRL_PUBLIC_H
|
||||||
@@ -59,7 +59,6 @@ static const struct procfs_entry base_entry_stuff[];
|
|||||||
static const struct file_operations mckernel_forward_ro;
|
static const struct file_operations mckernel_forward_ro;
|
||||||
static const struct file_operations mckernel_forward;
|
static const struct file_operations mckernel_forward;
|
||||||
|
|
||||||
static DECLARE_WAIT_QUEUE_HEAD(procfsq);
|
|
||||||
static ssize_t mckernel_procfs_read(struct file *file, char __user *buf,
|
static ssize_t mckernel_procfs_read(struct file *file, char __user *buf,
|
||||||
size_t nbytes, loff_t *ppos);
|
size_t nbytes, loff_t *ppos);
|
||||||
|
|
||||||
@@ -106,14 +105,28 @@ getpath(struct procfs_list_entry *e, char *buf, int bufsize)
|
|||||||
/**
|
/**
|
||||||
* \brief Process SCD_MSG_PROCFS_ANSWER message.
|
* \brief Process SCD_MSG_PROCFS_ANSWER message.
|
||||||
*
|
*
|
||||||
* \param arg sent argument
|
* \param ud mcctrl_usrdata pointer
|
||||||
* \param err error info (redundant)
|
* \param pid PID of the requesting process
|
||||||
*/
|
*/
|
||||||
void
|
void procfs_answer(struct mcctrl_usrdata *ud, int pid)
|
||||||
procfs_answer(unsigned int arg, int err)
|
|
||||||
{
|
{
|
||||||
dprintk("procfs: received SCD_MSG_PROCFS_ANSWER message(err = %d).\n", err);
|
struct mcctrl_per_proc_data *ppd = NULL;
|
||||||
wake_up_interruptible(&procfsq);
|
|
||||||
|
if (pid > 0) {
|
||||||
|
ppd = mcctrl_get_per_proc_data(ud, pid);
|
||||||
|
|
||||||
|
if (unlikely(!ppd)) {
|
||||||
|
kprintf("%s: ERROR: no per-process structure for PID %d\n",
|
||||||
|
__FUNCTION__, pid);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wake_up_all(pid > 0 ? &ppd->wq_procfs : &ud->wq_procfs);
|
||||||
|
|
||||||
|
if (pid > 0) {
|
||||||
|
mcctrl_put_per_proc_data(ppd);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct procfs_list_entry *
|
static struct procfs_list_entry *
|
||||||
@@ -248,9 +261,11 @@ get_pid_cred(int pid)
|
|||||||
{
|
{
|
||||||
struct task_struct *task = NULL;
|
struct task_struct *task = NULL;
|
||||||
|
|
||||||
if(pid > 0){
|
if (pid > 0) {
|
||||||
|
rcu_read_lock();
|
||||||
task = pid_task(find_vpid(pid), PIDTYPE_PID);
|
task = pid_task(find_vpid(pid), PIDTYPE_PID);
|
||||||
if(task){
|
rcu_read_unlock();
|
||||||
|
if (task) {
|
||||||
return __task_cred(task);
|
return __task_cred(task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -493,16 +508,17 @@ procfs_exit(int osnum)
|
|||||||
* This function conforms to the 2) way of fs/proc/generic.c
|
* This function conforms to the 2) way of fs/proc/generic.c
|
||||||
* from linux-2.6.39.4.
|
* from linux-2.6.39.4.
|
||||||
*/
|
*/
|
||||||
static ssize_t
|
static ssize_t __mckernel_procfs_read_write(
|
||||||
mckernel_procfs_read(struct file *file, char __user *buf, size_t nbytes,
|
struct file *file,
|
||||||
loff_t *ppos)
|
char __user *buf, size_t nbytes,
|
||||||
|
loff_t *ppos, int read_write)
|
||||||
{
|
{
|
||||||
struct inode * inode = file->f_inode;
|
struct inode * inode = file->f_inode;
|
||||||
char *kern_buffer = NULL;
|
char *kern_buffer = NULL;
|
||||||
int order = 0;
|
int order = 0;
|
||||||
volatile struct procfs_read *r = NULL;
|
volatile struct procfs_read *r = NULL;
|
||||||
struct ikc_scd_packet isp;
|
struct ikc_scd_packet isp;
|
||||||
int ret;
|
int ret, osnum, pid, retw;
|
||||||
unsigned long pbuf;
|
unsigned long pbuf;
|
||||||
unsigned long count = nbytes;
|
unsigned long count = nbytes;
|
||||||
#if LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0)
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0)
|
||||||
@@ -513,16 +529,63 @@ mckernel_procfs_read(struct file *file, char __user *buf, size_t nbytes,
|
|||||||
#endif
|
#endif
|
||||||
loff_t offset = *ppos;
|
loff_t offset = *ppos;
|
||||||
char pathbuf[PROCFS_NAME_MAX];
|
char pathbuf[PROCFS_NAME_MAX];
|
||||||
char *path;
|
char *path, *p;
|
||||||
|
ihk_os_t os = NULL;
|
||||||
path = getpath(e, pathbuf, 256);
|
struct mcctrl_usrdata *udp = NULL;
|
||||||
dprintk("mckernel_procfs_read: invoked for %s, offset: %lu, count: %d\n",
|
struct mcctrl_per_proc_data *ppd = NULL;
|
||||||
path, offset, count);
|
|
||||||
|
|
||||||
if (count <= 0 || offset < 0) {
|
if (count <= 0 || offset < 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
path = getpath(e, pathbuf, PROCFS_NAME_MAX);
|
||||||
|
dprintk("%s: invoked for %s, offset: %lu, count: %lu\n",
|
||||||
|
__FUNCTION__, path,
|
||||||
|
(unsigned long)offset, count);
|
||||||
|
|
||||||
|
/* Verify OS number */
|
||||||
|
ret = sscanf(path, "mcos%d/", &osnum);
|
||||||
|
if (ret != 1) {
|
||||||
|
printk("%s: error: couldn't determine OS number\n", __FUNCTION__);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (osnum != e->osnum) {
|
||||||
|
printk("%s: error: OS numbers don't match\n", __FUNCTION__);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Is this request for a specific process? */
|
||||||
|
p = strchr(path, '/') + 1;
|
||||||
|
ret = sscanf(p, "%d/", &pid);
|
||||||
|
if (ret != 1) {
|
||||||
|
pid = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
os = osnum_to_os(osnum);
|
||||||
|
if (!os) {
|
||||||
|
printk("%s: error: no IHK OS data found for OS %d\n",
|
||||||
|
__FUNCTION__, osnum);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
udp = ihk_host_os_get_usrdata(os);
|
||||||
|
if (!udp) {
|
||||||
|
printk("%s: error: no MCCTRL data found for OS %d\n",
|
||||||
|
__FUNCTION__, osnum);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pid > 0) {
|
||||||
|
ppd = mcctrl_get_per_proc_data(udp, pid);
|
||||||
|
|
||||||
|
if (unlikely(!ppd)) {
|
||||||
|
printk("%s: error: no per-process structure for PID %d",
|
||||||
|
__FUNCTION__, pid);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
while ((1 << order) < count) ++order;
|
while ((1 << order) < count) ++order;
|
||||||
if (order > 12) {
|
if (order > 12) {
|
||||||
order -= 12;
|
order -= 12;
|
||||||
@@ -534,8 +597,9 @@ mckernel_procfs_read(struct file *file, char __user *buf, size_t nbytes,
|
|||||||
/* NOTE: we need physically contigous memory to pass through IKC */
|
/* NOTE: we need physically contigous memory to pass through IKC */
|
||||||
kern_buffer = (char *)__get_free_pages(GFP_KERNEL, order);
|
kern_buffer = (char *)__get_free_pages(GFP_KERNEL, order);
|
||||||
if (!kern_buffer) {
|
if (!kern_buffer) {
|
||||||
printk("mckernel_procfs_read(): ERROR: allocating kernel buffer\n");
|
printk("%s: ERROR: allocating kernel buffer\n", __FUNCTION__);
|
||||||
return -ENOMEM;
|
ret = -ENOMEM;
|
||||||
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
pbuf = virt_to_phys(kern_buffer);
|
pbuf = virt_to_phys(kern_buffer);
|
||||||
@@ -551,13 +615,15 @@ mckernel_procfs_read(struct file *file, char __user *buf, size_t nbytes,
|
|||||||
r->status = 0;
|
r->status = 0;
|
||||||
r->offset = offset;
|
r->offset = offset;
|
||||||
r->count = count;
|
r->count = count;
|
||||||
r->readwrite = 0;
|
r->readwrite = read_write;
|
||||||
strncpy((char *)r->fname, path, PROCFS_NAME_MAX);
|
strncpy((char *)r->fname, path, PROCFS_NAME_MAX);
|
||||||
isp.msg = SCD_MSG_PROCFS_REQUEST;
|
isp.msg = SCD_MSG_PROCFS_REQUEST;
|
||||||
isp.ref = 0;
|
isp.ref = 0;
|
||||||
isp.arg = virt_to_phys(r);
|
isp.arg = virt_to_phys(r);
|
||||||
|
isp.pid = pid;
|
||||||
|
|
||||||
ret = mcctrl_ikc_send(osnum_to_os(e->osnum), 0, &isp);
|
ret = mcctrl_ikc_send(osnum_to_os(e->osnum),
|
||||||
|
(pid > 0) ? ppd->ikc_target_cpu : 0, &isp);
|
||||||
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
goto out; /* error */
|
goto out; /* error */
|
||||||
@@ -565,138 +631,80 @@ mckernel_procfs_read(struct file *file, char __user *buf, size_t nbytes,
|
|||||||
|
|
||||||
/* Wait for a reply. */
|
/* Wait for a reply. */
|
||||||
ret = -EIO; /* default exit code */
|
ret = -EIO; /* default exit code */
|
||||||
dprintk("now wait for a relpy\n");
|
dprintk("%s: waiting for reply\n", __FUNCTION__);
|
||||||
|
|
||||||
/* Wait for the status field of the procfs_read structure set ready. */
|
retry_wait:
|
||||||
if (wait_event_interruptible_timeout(procfsq, r->status != 0, HZ) == 0) {
|
/* Wait for the status field of the procfs_read structure,
|
||||||
kprintf("ERROR: mckernel_procfs_read: timeout (1 sec).\n");
|
* wait on per-process or OS specific data depending on
|
||||||
|
* who the request is for.
|
||||||
|
*/
|
||||||
|
if (pid > 0) {
|
||||||
|
retw = wait_event_interruptible_timeout(ppd->wq_procfs,
|
||||||
|
r->status != 0, HZ);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
retw = wait_event_interruptible_timeout(udp->wq_procfs,
|
||||||
|
r->status != 0, HZ);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Timeout? */
|
||||||
|
if (retw == 0 && r->status == 0) {
|
||||||
|
printk("%s: error: timeout (1 sec)\n", __FUNCTION__);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
/* Interrupted? */
|
||||||
|
else if (retw == -ERESTARTSYS) {
|
||||||
|
ret = -ERESTART;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
/* Were we woken up by a reply to another procfs request? */
|
||||||
|
else if (r->status == 0) {
|
||||||
|
/* TODO: r->status is not set atomically, we could be woken
|
||||||
|
* up with status == 0 and it could change to 1 while in this
|
||||||
|
* code, we could potentially miss the wake_up()...
|
||||||
|
*/
|
||||||
|
printk("%s: stale wake-up, retrying\n", __FUNCTION__);
|
||||||
|
goto retry_wait;
|
||||||
|
}
|
||||||
|
|
||||||
/* Wake up and check the result. */
|
/* Wake up and check the result. */
|
||||||
dprintk("mckernel_procfs_read: woke up. ret: %d, eof: %d\n", r->ret, r->eof);
|
dprintk("%s: woke up. ret: %d, eof: %d\n",
|
||||||
|
__FUNCTION__, r->ret, r->eof);
|
||||||
|
|
||||||
if (r->ret > 0) {
|
if (r->ret > 0) {
|
||||||
if (copy_to_user(buf, kern_buffer, r->ret)) {
|
if (read_write == 0) {
|
||||||
kprintf("ERROR: mckernel_procfs_read: copy_to_user failed.\n");
|
if (copy_to_user(buf, kern_buffer, r->ret)) {
|
||||||
ret = -EFAULT;
|
printk("%s: ERROR: copy_to_user failed.\n", __FUNCTION__);
|
||||||
goto out;
|
ret = -EFAULT;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*ppos += r->ret;
|
*ppos += r->ret;
|
||||||
}
|
}
|
||||||
ret = r->ret;
|
ret = r->ret;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
if(kern_buffer)
|
if (ppd)
|
||||||
|
mcctrl_put_per_proc_data(ppd);
|
||||||
|
if (kern_buffer)
|
||||||
free_pages((uintptr_t)kern_buffer, order);
|
free_pages((uintptr_t)kern_buffer, order);
|
||||||
if(r)
|
if (r)
|
||||||
kfree((void *)r);
|
kfree((void *)r);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t
|
static ssize_t mckernel_procfs_read(struct file *file,
|
||||||
mckernel_procfs_write(struct file *file, const char __user *buf, size_t nbytes,
|
char __user *buf, size_t nbytes, loff_t *ppos)
|
||||||
loff_t *ppos)
|
|
||||||
{
|
{
|
||||||
struct inode * inode = file->f_inode;
|
return __mckernel_procfs_read_write(file, buf, nbytes, ppos, 0);
|
||||||
char *kern_buffer = NULL;
|
}
|
||||||
int order = 0;
|
|
||||||
volatile struct procfs_read *r = NULL;
|
|
||||||
struct ikc_scd_packet isp;
|
|
||||||
int ret;
|
|
||||||
unsigned long pbuf;
|
|
||||||
unsigned long count = nbytes;
|
|
||||||
#if LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0)
|
|
||||||
struct proc_dir_entry *dp = PDE(inode);
|
|
||||||
struct procfs_list_entry *e = dp->data;
|
|
||||||
#else
|
|
||||||
struct procfs_list_entry *e = PDE_DATA(inode);
|
|
||||||
#endif
|
|
||||||
loff_t offset = *ppos;
|
|
||||||
char pathbuf[PROCFS_NAME_MAX];
|
|
||||||
char *path;
|
|
||||||
|
|
||||||
path = getpath(e, pathbuf, 256);
|
static ssize_t mckernel_procfs_write(struct file *file,
|
||||||
dprintk("mckernel_procfs_read: invoked for %s, offset: %lu, count: %d\n",
|
const char __user *buf, size_t nbytes, loff_t *ppos)
|
||||||
path, offset, count);
|
{
|
||||||
|
return __mckernel_procfs_read_write(file,
|
||||||
if (count <= 0 || offset < 0) {
|
(char __user *)buf, nbytes, ppos, 1);
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
while ((1 << order) < count) ++order;
|
|
||||||
if (order > 12) {
|
|
||||||
order -= 12;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
order = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* NOTE: we need physically contigous memory to pass through IKC */
|
|
||||||
kern_buffer = (char *)__get_free_pages(GFP_KERNEL, order);
|
|
||||||
if (!kern_buffer) {
|
|
||||||
printk("mckernel_procfs_read(): ERROR: allocating kernel buffer\n");
|
|
||||||
return -ENOMEM;
|
|
||||||
}
|
|
||||||
if (copy_from_user(kern_buffer, buf, nbytes)) {
|
|
||||||
ret = -EFAULT;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
pbuf = virt_to_phys(kern_buffer);
|
|
||||||
|
|
||||||
r = kmalloc(sizeof(struct procfs_read), GFP_KERNEL);
|
|
||||||
if (r == NULL) {
|
|
||||||
ret = -ENOMEM;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
dprintk("offset: %lx, count: %d, cpu: %d\n", offset, count, e->cpu);
|
|
||||||
|
|
||||||
r->pbuf = pbuf;
|
|
||||||
r->eof = 0;
|
|
||||||
r->ret = -EIO; /* default */
|
|
||||||
r->status = 0;
|
|
||||||
r->offset = offset;
|
|
||||||
r->count = count;
|
|
||||||
r->readwrite = 1;
|
|
||||||
strncpy((char *)r->fname, path, PROCFS_NAME_MAX);
|
|
||||||
isp.msg = SCD_MSG_PROCFS_REQUEST;
|
|
||||||
isp.ref = 0;
|
|
||||||
isp.arg = virt_to_phys(r);
|
|
||||||
|
|
||||||
ret = mcctrl_ikc_send(osnum_to_os(e->osnum), 0, &isp);
|
|
||||||
|
|
||||||
if (ret < 0) {
|
|
||||||
goto out; /* error */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Wait for a reply. */
|
|
||||||
ret = -EIO; /* default exit code */
|
|
||||||
dprintk("now wait for a relpy\n");
|
|
||||||
|
|
||||||
/* Wait for the status field of the procfs_read structure set ready. */
|
|
||||||
if (wait_event_interruptible_timeout(procfsq, r->status != 0, HZ) == 0) {
|
|
||||||
kprintf("ERROR: mckernel_procfs_read: timeout (1 sec).\n");
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Wake up and check the result. */
|
|
||||||
dprintk("mckernel_procfs_read: woke up. ret: %d, eof: %d\n", r->ret, r->eof);
|
|
||||||
|
|
||||||
if (r->ret > 0) {
|
|
||||||
*ppos += r->ret;
|
|
||||||
}
|
|
||||||
ret = r->ret;
|
|
||||||
|
|
||||||
out:
|
|
||||||
if(kern_buffer)
|
|
||||||
free_pages((uintptr_t)kern_buffer, order);
|
|
||||||
if(r)
|
|
||||||
kfree((void *)r);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static loff_t
|
static loff_t
|
||||||
|
|||||||
@@ -306,7 +306,7 @@ static int remote_page_fault(struct mcctrl_usrdata *usrdata, void *fault_addr, u
|
|||||||
error = -ENOENT;
|
error = -ENOENT;
|
||||||
printk("%s: no packet registered for TID %d\n",
|
printk("%s: no packet registered for TID %d\n",
|
||||||
__FUNCTION__, task_pid_vnr(current));
|
__FUNCTION__, task_pid_vnr(current));
|
||||||
goto out_no_unmap;
|
goto out_put_ppd;
|
||||||
}
|
}
|
||||||
|
|
||||||
req = &packet->req;
|
req = &packet->req;
|
||||||
@@ -326,6 +326,9 @@ retry_alloc:
|
|||||||
|
|
||||||
/* Prepare per-thread wait queue head */
|
/* Prepare per-thread wait queue head */
|
||||||
wqhln->task = current;
|
wqhln->task = current;
|
||||||
|
/* Save the TID explicitly, because mcexec_syscall(), where the request
|
||||||
|
* will be matched, is in IRQ context and can't call task_pid_vnr() */
|
||||||
|
wqhln->rtid = task_pid_vnr(current);
|
||||||
wqhln->req = 0;
|
wqhln->req = 0;
|
||||||
init_waitqueue_head(&wqhln->wq_syscall);
|
init_waitqueue_head(&wqhln->wq_syscall);
|
||||||
|
|
||||||
@@ -434,9 +437,11 @@ out:
|
|||||||
ihk_device_unmap_virtual(ihk_os_to_dev(usrdata->os), resp, sizeof(*resp));
|
ihk_device_unmap_virtual(ihk_os_to_dev(usrdata->os), resp, sizeof(*resp));
|
||||||
ihk_device_unmap_memory(ihk_os_to_dev(usrdata->os), phys, sizeof(*resp));
|
ihk_device_unmap_memory(ihk_os_to_dev(usrdata->os), phys, sizeof(*resp));
|
||||||
|
|
||||||
out_no_unmap:
|
out_put_ppd:
|
||||||
dprintk("%s: tid: %d, fault_addr: %lu, reason: %lu, error: %d\n",
|
dprintk("%s: tid: %d, fault_addr: %lu, reason: %lu, error: %d\n",
|
||||||
__FUNCTION__, task_pid_vnr(current), fault_addr, reason, error);
|
__FUNCTION__, task_pid_vnr(current), fault_addr, reason, error);
|
||||||
|
|
||||||
|
mcctrl_put_per_proc_data(ppd);
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -574,6 +579,7 @@ static int rus_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
|
|||||||
size_t pix;
|
size_t pix;
|
||||||
#endif
|
#endif
|
||||||
struct mcctrl_per_proc_data *ppd;
|
struct mcctrl_per_proc_data *ppd;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
dprintk("mcctrl:page fault:flags %#x pgoff %#lx va %p page %p\n",
|
dprintk("mcctrl:page fault:flags %#x pgoff %#lx va %p page %p\n",
|
||||||
vmf->flags, vmf->pgoff, vmf->virtual_address, vmf->page);
|
vmf->flags, vmf->pgoff, vmf->virtual_address, vmf->page);
|
||||||
@@ -584,7 +590,6 @@ static int rus_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
|
|||||||
ppd = mcctrl_get_per_proc_data(usrdata, vma->vm_mm->owner->pid);
|
ppd = mcctrl_get_per_proc_data(usrdata, vma->vm_mm->owner->pid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!ppd) {
|
if (!ppd) {
|
||||||
kprintf("%s: ERROR: no per-process structure for PID %d??\n",
|
kprintf("%s: ERROR: no per-process structure for PID %d??\n",
|
||||||
__FUNCTION__, task_tgid_vnr(current));
|
__FUNCTION__, task_tgid_vnr(current));
|
||||||
@@ -618,7 +623,8 @@ static int rus_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
|
|||||||
if (error) {
|
if (error) {
|
||||||
printk("mcctrl:page fault error:flags %#x pgoff %#lx va %p page %p\n",
|
printk("mcctrl:page fault error:flags %#x pgoff %#lx va %p page %p\n",
|
||||||
vmf->flags, vmf->pgoff, vmf->virtual_address, vmf->page);
|
vmf->flags, vmf->pgoff, vmf->virtual_address, vmf->page);
|
||||||
return VM_FAULT_SIGBUS;
|
ret = VM_FAULT_SIGBUS;
|
||||||
|
goto put_and_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
rva = (unsigned long)vmf->virtual_address & ~(pgsize - 1);
|
rva = (unsigned long)vmf->virtual_address & ~(pgsize - 1);
|
||||||
@@ -655,10 +661,15 @@ static int rus_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
|
|||||||
if (error) {
|
if (error) {
|
||||||
printk("mcctrl:page fault:remap error:flags %#x pgoff %#lx va %p page %p\n",
|
printk("mcctrl:page fault:remap error:flags %#x pgoff %#lx va %p page %p\n",
|
||||||
vmf->flags, vmf->pgoff, vmf->virtual_address, vmf->page);
|
vmf->flags, vmf->pgoff, vmf->virtual_address, vmf->page);
|
||||||
return VM_FAULT_SIGBUS;
|
ret = VM_FAULT_SIGBUS;
|
||||||
|
goto put_and_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
return VM_FAULT_NOPAGE;
|
ret = VM_FAULT_NOPAGE;
|
||||||
|
|
||||||
|
put_and_out:
|
||||||
|
mcctrl_put_per_proc_data(ppd);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct vm_operations_struct rus_vmops = {
|
static struct vm_operations_struct rus_vmops = {
|
||||||
@@ -757,6 +768,8 @@ enum {
|
|||||||
MF_IS_REMOVABLE = 0x0004,
|
MF_IS_REMOVABLE = 0x0004,
|
||||||
MF_PREFETCH = 0x0008,
|
MF_PREFETCH = 0x0008,
|
||||||
MF_ZEROFILL = 0x0010,
|
MF_ZEROFILL = 0x0010,
|
||||||
|
MF_REG_FILE = 0x1000,
|
||||||
|
MF_DEV_FILE = 0x2000,
|
||||||
MF_END
|
MF_END
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1623,6 +1636,7 @@ int __do_in_kernel_syscall(ihk_os_t os, struct ikc_scd_packet *packet)
|
|||||||
|
|
||||||
dprintk("%s: pid: %d, rpgtable: 0x%lx updated\n",
|
dprintk("%s: pid: %d, rpgtable: 0x%lx updated\n",
|
||||||
__FUNCTION__, ppd->pid, ppd->rpgtable);
|
__FUNCTION__, ppd->pid, ppd->rpgtable);
|
||||||
|
mcctrl_put_per_proc_data(ppd);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = clear_pte_range(sc->args[0], sc->args[1]);
|
ret = clear_pte_range(sc->args[0], sc->args[1]);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
ENABLE_MCOVERLAYFS=@ENABLE_MCOVERLAYFS@
|
ENABLE_MCOVERLAYFS=@ENABLE_MCOVERLAYFS@
|
||||||
|
RELEASE=@UNAME_R@
|
||||||
|
|
||||||
RELEASE=$(shell uname -r)
|
|
||||||
MAJOR=$(shell echo ${RELEASE} | sed -e 's/^\([0-9]*\).*/\1/')
|
MAJOR=$(shell echo ${RELEASE} | sed -e 's/^\([0-9]*\).*/\1/')
|
||||||
MINOR=$(shell echo ${RELEASE} | sed -e 's/^[0-9]*.\([0-9]*\).*/\1/')
|
MINOR=$(shell echo ${RELEASE} | sed -e 's/^[0-9]*.\([0-9]*\).*/\1/')
|
||||||
PATCH=$(shell echo ${RELEASE} | sed -e 's/^[0-9]*.[0-9]*.\([0-9]*\).*/\1/')
|
PATCH=$(shell echo ${RELEASE} | sed -e 's/^[0-9]*.[0-9]*.\([0-9]*\).*/\1/')
|
||||||
@@ -9,6 +9,7 @@ RHEL_RELEASE_TMP=$(shell echo ${RELEASE} | sed -e 's/^[0-9]*.[0-9]*.[0-9]*-\([0-
|
|||||||
RHEL_RELEASE=$(shell if [ "${RELEASE}" == "${RHEL_RELEASE_TMP}" ]; then echo ""; else echo ${RHEL_RELEASE_TMP}; fi)
|
RHEL_RELEASE=$(shell if [ "${RELEASE}" == "${RHEL_RELEASE_TMP}" ]; then echo ""; else echo ${RHEL_RELEASE_TMP}; fi)
|
||||||
BUILD_MODULE_TMP=$(shell if [ "${RHEL_RELEASE}" == "" ]; then echo "org"; else echo "rhel"; fi)
|
BUILD_MODULE_TMP=$(shell if [ "${RHEL_RELEASE}" == "" ]; then echo "org"; else echo "rhel"; fi)
|
||||||
BUILD_MODULE=none
|
BUILD_MODULE=none
|
||||||
|
#$(info "LINUX_VERSION_CODE: ${LINUX_VERSION_CODE}, RHEL_RELEASE: ${RHEL_RELEASE}")
|
||||||
ifeq ($(ENABLE_MCOVERLAYFS),yes)
|
ifeq ($(ENABLE_MCOVERLAYFS),yes)
|
||||||
ifeq ($(BUILD_MODULE_TMP),org)
|
ifeq ($(BUILD_MODULE_TMP),org)
|
||||||
ifeq ($(BUILD_MODULE),none)
|
ifeq ($(BUILD_MODULE),none)
|
||||||
@@ -20,7 +21,7 @@ endif
|
|||||||
endif
|
endif
|
||||||
ifeq ($(BUILD_MODULE_TMP),rhel)
|
ifeq ($(BUILD_MODULE_TMP),rhel)
|
||||||
ifeq ($(BUILD_MODULE),none)
|
ifeq ($(BUILD_MODULE),none)
|
||||||
BUILD_MODULE=$(shell if [ ${LINUX_VERSION_CODE} -eq 199168 -a ${RHEL_RELEASE} -eq 327 ]; then echo "linux-3.10.0-327.36.1.el7"; else echo "none"; fi)
|
BUILD_MODULE=$(shell if [ ${LINUX_VERSION_CODE} -eq 199168 -a ${RHEL_RELEASE} -ge 327 -a ${RHEL_RELEASE} -le 514 ]; then echo "linux-3.10.0-327.36.1.el7"; else echo "none"; fi)
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|||||||
@@ -420,8 +420,8 @@ struct inode *ovl_d_select_inode(struct dentry *dentry, unsigned file_flags)
|
|||||||
dentry, dentry->d_inode->i_ino);
|
dentry, dentry->d_inode->i_ino);
|
||||||
OVL_DEBUG("sysfs: realpath.dentry=%pd4, i_ino=%lu\n",
|
OVL_DEBUG("sysfs: realpath.dentry=%pd4, i_ino=%lu\n",
|
||||||
realpath.dentry, realpath.dentry->d_inode->i_ino);
|
realpath.dentry, realpath.dentry->d_inode->i_ino);
|
||||||
if (!dentry->d_inode->i_private) {
|
if (!ovl_find_d_fsdata(dentry)) {
|
||||||
dentry->d_inode->i_private = dentry->d_fsdata;
|
ovl_add_d_fsdata(dentry);
|
||||||
dentry->d_fsdata = realpath.dentry->d_fsdata;
|
dentry->d_fsdata = realpath.dentry->d_fsdata;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,6 +43,12 @@ enum ovl_opt_bit {
|
|||||||
#define OVL_OPT_NOCOPYUPW(opt) ((opt) & __OVL_OPT_NOCOPYUPW)
|
#define OVL_OPT_NOCOPYUPW(opt) ((opt) & __OVL_OPT_NOCOPYUPW)
|
||||||
#define OVL_OPT_NOFSCHECK(opt) ((opt) & __OVL_OPT_NOFSCHECK)
|
#define OVL_OPT_NOFSCHECK(opt) ((opt) & __OVL_OPT_NOFSCHECK)
|
||||||
|
|
||||||
|
struct ovl_d_fsdata {
|
||||||
|
struct list_head list;
|
||||||
|
struct dentry *d;
|
||||||
|
struct ovl_entry *oe;
|
||||||
|
};
|
||||||
|
|
||||||
static inline int ovl_do_rmdir(struct inode *dir, struct dentry *dentry)
|
static inline int ovl_do_rmdir(struct inode *dir, struct dentry *dentry)
|
||||||
{
|
{
|
||||||
int err = vfs_rmdir(dir, dentry);
|
int err = vfs_rmdir(dir, dentry);
|
||||||
@@ -149,6 +155,8 @@ static inline int ovl_do_whiteout(struct inode *dir, struct dentry *dentry)
|
|||||||
|
|
||||||
unsigned ovl_get_config_opt(struct dentry *dentry);
|
unsigned ovl_get_config_opt(struct dentry *dentry);
|
||||||
void ovl_reset_ovl_entry(struct ovl_entry **oe, struct dentry *dentry);
|
void ovl_reset_ovl_entry(struct ovl_entry **oe, struct dentry *dentry);
|
||||||
|
struct ovl_entry *ovl_find_d_fsdata(struct dentry *dentry);
|
||||||
|
int ovl_add_d_fsdata(struct dentry *dentry);
|
||||||
enum ovl_path_type ovl_path_type(struct dentry *dentry);
|
enum ovl_path_type ovl_path_type(struct dentry *dentry);
|
||||||
u64 ovl_dentry_version_get(struct dentry *dentry);
|
u64 ovl_dentry_version_get(struct dentry *dentry);
|
||||||
void ovl_dentry_version_inc(struct dentry *dentry);
|
void ovl_dentry_version_inc(struct dentry *dentry);
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ struct ovl_fs {
|
|||||||
long lower_namelen;
|
long lower_namelen;
|
||||||
/* pathnames of lower and upper dirs, for show_options */
|
/* pathnames of lower and upper dirs, for show_options */
|
||||||
struct ovl_config config;
|
struct ovl_config config;
|
||||||
|
struct list_head d_fsdata_list;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ovl_dir_cache;
|
struct ovl_dir_cache;
|
||||||
@@ -76,15 +77,76 @@ unsigned ovl_get_config_opt(struct dentry *dentry)
|
|||||||
void ovl_reset_ovl_entry(struct ovl_entry **oe, struct dentry *dentry)
|
void ovl_reset_ovl_entry(struct ovl_entry **oe, struct dentry *dentry)
|
||||||
{
|
{
|
||||||
unsigned opt = ovl_get_config_opt(dentry);
|
unsigned opt = ovl_get_config_opt(dentry);
|
||||||
|
struct ovl_entry *d_fsdata;
|
||||||
|
|
||||||
if (OVL_OPT_NOFSCHECK(opt)) {
|
if (OVL_OPT_NOFSCHECK(opt)) {
|
||||||
if (dentry->d_inode && dentry->d_inode->i_private &&
|
if (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode)) {
|
||||||
!S_ISDIR(dentry->d_inode->i_mode)) {
|
return;
|
||||||
*oe = dentry->d_inode->i_private;
|
}
|
||||||
|
|
||||||
|
d_fsdata = ovl_find_d_fsdata(dentry);
|
||||||
|
if (d_fsdata) {
|
||||||
|
OVL_DEBUG("reset: dentry=%pd4, 0x%p, oe=0x%p\n",
|
||||||
|
dentry, dentry, d_fsdata);
|
||||||
|
*oe = d_fsdata;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct ovl_entry *ovl_find_d_fsdata(struct dentry *dentry)
|
||||||
|
{
|
||||||
|
struct ovl_fs *ofs = dentry->d_sb->s_fs_info;
|
||||||
|
struct ovl_d_fsdata *d_fsdata;
|
||||||
|
|
||||||
|
list_for_each_entry(d_fsdata, &ofs->d_fsdata_list, list) {
|
||||||
|
if (dentry == d_fsdata->d) {
|
||||||
|
OVL_DEBUG("exist: dentry=%pd4, 0x%p, oe=0x%p\n",
|
||||||
|
d_fsdata->d, d_fsdata->d, d_fsdata->oe);
|
||||||
|
return d_fsdata->oe;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ovl_add_d_fsdata(struct dentry *dentry)
|
||||||
|
{
|
||||||
|
struct ovl_fs *ofs = dentry->d_sb->s_fs_info;
|
||||||
|
struct ovl_d_fsdata *d_fsdata;
|
||||||
|
|
||||||
|
d_fsdata = kzalloc(sizeof(struct ovl_d_fsdata), GFP_KERNEL);
|
||||||
|
if (!d_fsdata) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
d_fsdata->d = dentry;
|
||||||
|
d_fsdata->oe = dentry->d_fsdata;
|
||||||
|
|
||||||
|
list_add(&d_fsdata->list, &ofs->d_fsdata_list);
|
||||||
|
|
||||||
|
OVL_DEBUG("add: dentry=%pd4, 0x%p, oe=0x%p\n",
|
||||||
|
d_fsdata->d, d_fsdata->d, d_fsdata->oe);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int ovl_clear_d_fsdata(struct ovl_fs *ofs)
|
||||||
|
{
|
||||||
|
struct ovl_d_fsdata *d_fsdata;
|
||||||
|
struct ovl_d_fsdata *d_fsdata_next;
|
||||||
|
|
||||||
|
list_for_each_entry_safe(d_fsdata, d_fsdata_next, &ofs->d_fsdata_list,
|
||||||
|
list) {
|
||||||
|
OVL_DEBUG("delete: dentry=%pd4, 0x%p\n",
|
||||||
|
d_fsdata->d, d_fsdata->d);
|
||||||
|
list_del(&d_fsdata->list);
|
||||||
|
|
||||||
|
kfree(d_fsdata);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static struct dentry *__ovl_dentry_lower(struct ovl_entry *oe)
|
static struct dentry *__ovl_dentry_lower(struct ovl_entry *oe)
|
||||||
{
|
{
|
||||||
return oe->numlower ? oe->lowerstack[0].dentry : NULL;
|
return oe->numlower ? oe->lowerstack[0].dentry : NULL;
|
||||||
@@ -658,6 +720,8 @@ static void ovl_put_super(struct super_block *sb)
|
|||||||
struct ovl_fs *ufs = sb->s_fs_info;
|
struct ovl_fs *ufs = sb->s_fs_info;
|
||||||
unsigned i;
|
unsigned i;
|
||||||
|
|
||||||
|
ovl_clear_d_fsdata(ufs);
|
||||||
|
|
||||||
dput(ufs->workdir);
|
dput(ufs->workdir);
|
||||||
mntput(ufs->upper_mnt);
|
mntput(ufs->upper_mnt);
|
||||||
for (i = 0; i < ufs->numlower; i++)
|
for (i = 0; i < ufs->numlower; i++)
|
||||||
@@ -1049,6 +1113,7 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)
|
|||||||
if (!ufs)
|
if (!ufs)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
INIT_LIST_HEAD(&ufs->d_fsdata_list);
|
||||||
err = ovl_parse_opt((char *) data, &ufs->config);
|
err = ovl_parse_opt((char *) data, &ufs->config);
|
||||||
if (err)
|
if (err)
|
||||||
goto out_free_config;
|
goto out_free_config;
|
||||||
|
|||||||
@@ -6,14 +6,15 @@ VPATH=@abs_srcdir@
|
|||||||
TARGET=mcexec
|
TARGET=mcexec
|
||||||
@uncomment_if_ENABLE_MEMDUMP@TARGET+=eclair
|
@uncomment_if_ENABLE_MEMDUMP@TARGET+=eclair
|
||||||
LIBS=@LIBS@
|
LIBS=@LIBS@
|
||||||
|
IHKDIR ?= $(VPATH)/../../../ihk/linux/include/
|
||||||
|
|
||||||
all: $(TARGET)
|
all: $(TARGET)
|
||||||
|
|
||||||
mcexec: mcexec.c
|
mcexec: mcexec.c
|
||||||
$(CC) -I${KDIR} $(CFLAGS) $(EXTRA_CFLAGS) -fPIE -pie -lrt -pthread -o $@ $^ $(EXTRA_OBJS)
|
$(CC) -I${KDIR} $(CFLAGS) $(EXTRA_CFLAGS) -fPIE -pie -lrt -lnuma -pthread -o $@ $^ $(EXTRA_OBJS)
|
||||||
|
|
||||||
eclair: eclair.c
|
eclair: eclair.c
|
||||||
$(CC) $(CFLAGS) -o $@ $^ $(LIBS)
|
$(CC) $(CFLAGS) -I${IHKDIR} -o $@ $^ $(LIBS)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(RM) $(TARGET) *.o
|
$(RM) $(TARGET) *.o
|
||||||
|
|||||||
@@ -16,20 +16,8 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
/* From ihk/linux/include/ihk/ihk_host_user.h */
|
#include <ihk/ihk_host_user.h>
|
||||||
#define PHYS_CHUNKS_DESC_SIZE 8192
|
|
||||||
|
|
||||||
struct dump_mem_chunk {
|
|
||||||
unsigned long addr;
|
|
||||||
unsigned long size;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct dump_mem_chunks_s {
|
|
||||||
int nr_chunks;
|
|
||||||
struct dump_mem_chunk chunks[];
|
|
||||||
} dump_mem_chunks_t;
|
|
||||||
/* ---------- */
|
|
||||||
|
|
||||||
#define CPU_TID_BASE 1000000
|
#define CPU_TID_BASE 1000000
|
||||||
|
|
||||||
@@ -39,6 +27,10 @@ struct options {
|
|||||||
char *kernel_path;
|
char *kernel_path;
|
||||||
char *dump_path;
|
char *dump_path;
|
||||||
char *log_path;
|
char *log_path;
|
||||||
|
int interactive;
|
||||||
|
int os_id;
|
||||||
|
int mcos_fd;
|
||||||
|
int print_idle;
|
||||||
}; /* struct options */
|
}; /* struct options */
|
||||||
|
|
||||||
struct thread_info {
|
struct thread_info {
|
||||||
@@ -56,7 +48,7 @@ struct thread_info {
|
|||||||
int tid;
|
int tid;
|
||||||
int cpu;
|
int cpu;
|
||||||
int lcpu;
|
int lcpu;
|
||||||
int padding;
|
int idle;
|
||||||
uintptr_t process;
|
uintptr_t process;
|
||||||
uintptr_t clv;
|
uintptr_t clv;
|
||||||
uintptr_t x86_clv;
|
uintptr_t x86_clv;
|
||||||
@@ -150,7 +142,21 @@ static int read_mem(uintptr_t va, void *buf, size_t size) {
|
|||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
error = read_physmem(pa, buf, size);
|
|
||||||
|
if (opt.interactive) {
|
||||||
|
dumpargs_t args;
|
||||||
|
|
||||||
|
args.cmd = DUMP_READ;
|
||||||
|
args.start = pa;
|
||||||
|
args.size = size;
|
||||||
|
args.buf = buf;
|
||||||
|
|
||||||
|
error = ioctl(opt.mcos_fd, IHK_OS_DUMP, &args);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
error = read_physmem(pa, buf, size);
|
||||||
|
}
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
perror("read_mem:read_physmem");
|
perror("read_mem:read_physmem");
|
||||||
return 1;
|
return 1;
|
||||||
@@ -256,6 +262,7 @@ static int setup_threads(void) {
|
|||||||
perror("num_processors");
|
perror("num_processors");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
printf("%s: num_processors: %d\n", __FUNCTION__, num_processors);
|
||||||
|
|
||||||
error = read_symbol_64("locals", &locals);
|
error = read_symbol_64("locals", &locals);
|
||||||
if (error) {
|
if (error) {
|
||||||
@@ -278,64 +285,6 @@ static int setup_threads(void) {
|
|||||||
ihk_mc_switch_context = lookup_symbol("ihk_mc_switch_context");
|
ihk_mc_switch_context = lookup_symbol("ihk_mc_switch_context");
|
||||||
if (0) printf("ihk_mc_switch_context: %lx\n", ihk_mc_switch_context);
|
if (0) printf("ihk_mc_switch_context: %lx\n", ihk_mc_switch_context);
|
||||||
|
|
||||||
/* Set up idle threads first */
|
|
||||||
for (cpu = 0; cpu < num_processors; ++cpu) {
|
|
||||||
uintptr_t v;
|
|
||||||
uintptr_t thread;
|
|
||||||
uintptr_t proc;
|
|
||||||
int pid;
|
|
||||||
int tid;
|
|
||||||
struct thread_info *ti;
|
|
||||||
int status;
|
|
||||||
|
|
||||||
v = clv + (cpu * K(CPU_LOCAL_VAR_SIZE));
|
|
||||||
|
|
||||||
ti = malloc(sizeof(*ti));
|
|
||||||
if (!ti) {
|
|
||||||
perror("malloc");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
thread = v+K(IDLE_THREAD_OFFSET);
|
|
||||||
|
|
||||||
error = read_64(thread+K(PROC_OFFSET), &proc);
|
|
||||||
if (error) {
|
|
||||||
perror("proc");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
error = read_32(thread+K(STATUS_OFFSET), &status);
|
|
||||||
if (error) {
|
|
||||||
perror("status");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
error = read_32(proc+K(PID_OFFSET), &pid);
|
|
||||||
if (error) {
|
|
||||||
perror("pid");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
error = read_32(thread+K(TID_OFFSET), &tid);
|
|
||||||
if (error) {
|
|
||||||
perror("tid");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
ti->next = NULL;
|
|
||||||
ti->status = status;
|
|
||||||
ti->pid = pid;
|
|
||||||
ti->tid = tid;
|
|
||||||
ti->cpu = cpu;
|
|
||||||
ti->lcpu = cpu;
|
|
||||||
ti->process = thread;
|
|
||||||
ti->clv = v;
|
|
||||||
ti->x86_clv = locals + locals_span*cpu;
|
|
||||||
|
|
||||||
*titailp = ti;
|
|
||||||
titailp = &ti->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (cpu = 0; cpu < num_processors; ++cpu) {
|
for (cpu = 0; cpu < num_processors; ++cpu) {
|
||||||
uintptr_t v;
|
uintptr_t v;
|
||||||
uintptr_t head;
|
uintptr_t head;
|
||||||
@@ -400,15 +349,19 @@ static int setup_threads(void) {
|
|||||||
ti->status = status;
|
ti->status = status;
|
||||||
ti->pid = pid;
|
ti->pid = pid;
|
||||||
ti->tid = tid;
|
ti->tid = tid;
|
||||||
ti->cpu = (thread == current)? cpu: -1;
|
ti->cpu = (thread == current) ? cpu : -1;
|
||||||
ti->lcpu = cpu;
|
ti->lcpu = cpu;
|
||||||
ti->process = thread;
|
ti->process = thread;
|
||||||
|
ti->idle = 0;
|
||||||
ti->clv = v;
|
ti->clv = v;
|
||||||
ti->x86_clv = locals + locals_span*cpu;
|
ti->x86_clv = locals + locals_span*cpu;
|
||||||
|
|
||||||
*titailp = ti;
|
*titailp = ti;
|
||||||
titailp = &ti->next;
|
titailp = &ti->next;
|
||||||
|
|
||||||
|
if (!curr_thread)
|
||||||
|
curr_thread = ti;
|
||||||
|
|
||||||
error = read_64(entry, &entry);
|
error = read_64(entry, &entry);
|
||||||
if (error) {
|
if (error) {
|
||||||
perror("process2");
|
perror("process2");
|
||||||
@@ -417,8 +370,78 @@ static int setup_threads(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Set up idle threads */
|
||||||
|
if (opt.print_idle) {
|
||||||
|
for (cpu = 0; cpu < num_processors; ++cpu) {
|
||||||
|
uintptr_t v;
|
||||||
|
uintptr_t thread;
|
||||||
|
uintptr_t proc;
|
||||||
|
int pid;
|
||||||
|
int tid;
|
||||||
|
struct thread_info *ti;
|
||||||
|
int status;
|
||||||
|
|
||||||
|
v = clv + (cpu * K(CPU_LOCAL_VAR_SIZE));
|
||||||
|
|
||||||
|
error = read_64(v+K(CURRENT_OFFSET), ¤t);
|
||||||
|
if (error) {
|
||||||
|
perror("current");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ti = malloc(sizeof(*ti));
|
||||||
|
if (!ti) {
|
||||||
|
perror("malloc");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
thread = v+K(IDLE_THREAD_OFFSET);
|
||||||
|
|
||||||
|
error = read_64(thread+K(PROC_OFFSET), &proc);
|
||||||
|
if (error) {
|
||||||
|
perror("proc");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
error = read_32(thread+K(STATUS_OFFSET), &status);
|
||||||
|
if (error) {
|
||||||
|
perror("status");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
error = read_32(proc+K(PID_OFFSET), &pid);
|
||||||
|
if (error) {
|
||||||
|
perror("pid");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
error = read_32(thread+K(TID_OFFSET), &tid);
|
||||||
|
if (error) {
|
||||||
|
perror("tid");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ti->next = NULL;
|
||||||
|
ti->status = status;
|
||||||
|
ti->pid = 1;
|
||||||
|
ti->tid = 2000000000 + tid;
|
||||||
|
ti->cpu = (thread == current) ? cpu : -1;
|
||||||
|
ti->lcpu = cpu;
|
||||||
|
ti->process = thread;
|
||||||
|
ti->idle = 1;
|
||||||
|
ti->clv = v;
|
||||||
|
ti->x86_clv = locals + locals_span*cpu;
|
||||||
|
|
||||||
|
*titailp = ti;
|
||||||
|
titailp = &ti->next;
|
||||||
|
|
||||||
|
if (!curr_thread)
|
||||||
|
curr_thread = ti;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!tihead) {
|
if (!tihead) {
|
||||||
printf("thread not found. cpu mode forcibly\n");
|
printf("No threads found, forcing CPU mode.\n");
|
||||||
opt.cpu = 1;
|
opt.cpu = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -459,6 +482,7 @@ static int setup_threads(void) {
|
|||||||
ti->tid = CPU_TID_BASE + cpu;
|
ti->tid = CPU_TID_BASE + cpu;
|
||||||
ti->cpu = cpu;
|
ti->cpu = cpu;
|
||||||
ti->process = current;
|
ti->process = current;
|
||||||
|
ti->idle = 1;
|
||||||
ti->clv = v;
|
ti->clv = v;
|
||||||
ti->x86_clv = locals + locals_span*cpu;
|
ti->x86_clv = locals + locals_span*cpu;
|
||||||
|
|
||||||
@@ -471,7 +495,9 @@ static int setup_threads(void) {
|
|||||||
printf("thread not found\n");
|
printf("thread not found\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
curr_thread = tihead;
|
|
||||||
|
if (!curr_thread)
|
||||||
|
curr_thread = tihead;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
} /* setup_threads() */
|
} /* setup_threads() */
|
||||||
@@ -713,18 +739,21 @@ static void command(char *cmd, char *res) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//if (regs[17] > MAP_KERNEL) {}
|
||||||
pu8 = (void *)®s;
|
pu8 = (void *)®s;
|
||||||
for (i = 0; i < sizeof(regs)-4; ++i) {
|
for (i = 0; i < sizeof(regs)-4; ++i) {
|
||||||
rbp += sprintf(rbp, "%02x", pu8[i]);
|
rbp += sprintf(rbp, "%02x", pu8[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
else if (!strcmp(p, "mffffffff80018a82,1")) {
|
else if (!strcmp(p, "mffffffff80018a82,1")) {
|
||||||
rbp += sprintf(rbp, "b8");
|
rbp += sprintf(rbp, "b8");
|
||||||
}
|
}
|
||||||
else if (!strcmp(p, "mffffffff80018a82,9")) {
|
else if (!strcmp(p, "mffffffff80018a82,9")) {
|
||||||
rbp += sprintf(rbp, "b8f2ffffff41564155");
|
rbp += sprintf(rbp, "b8f2ffffff41564155");
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
else if (!strncmp(p, "m", 1)) {
|
else if (!strncmp(p, "m", 1)) {
|
||||||
int n;
|
int n;
|
||||||
uintptr_t start;
|
uintptr_t start;
|
||||||
@@ -820,33 +849,35 @@ static void command(char *cmd, char *res) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
q = buf;
|
q = buf;
|
||||||
|
q += sprintf(q, "PID %d, ", ti->pid);
|
||||||
if (ti->status & PS_RUNNING) {
|
if (ti->status & PS_RUNNING) {
|
||||||
q += sprintf(q, "running on cpu%d", ti->cpu);
|
q += sprintf(q, "%srunning on cpu %d",
|
||||||
|
ti->idle ? "idle " : "", ti->lcpu);
|
||||||
}
|
}
|
||||||
else if (ti->status & (PS_INTERRUPTIBLE | PS_UNINTERRUPTIBLE)) {
|
else if (ti->status & (PS_INTERRUPTIBLE | PS_UNINTERRUPTIBLE)) {
|
||||||
q += sprintf(q, "waiting on cpu%d", ti->lcpu);
|
q += sprintf(q, "%swaiting on cpu %d",
|
||||||
|
ti->idle ? "idle " : "", ti->lcpu);
|
||||||
}
|
}
|
||||||
else if (ti->status & PS_STOPPED) {
|
else if (ti->status & PS_STOPPED) {
|
||||||
q += sprintf(q, "stopped on cpu%d", ti->lcpu);
|
q += sprintf(q, "%sstopped on cpu %d",
|
||||||
|
ti->idle ? "idle " : "", ti->lcpu);
|
||||||
}
|
}
|
||||||
else if (ti->status & PS_TRACED) {
|
else if (ti->status & PS_TRACED) {
|
||||||
q += sprintf(q, "traced on cpu%d", ti->lcpu);
|
q += sprintf(q, "%straced on cpu %d",
|
||||||
|
ti->idle ? "idle " : "", ti->lcpu);
|
||||||
}
|
}
|
||||||
else if (ti->status == CS_IDLE) {
|
else if (ti->status == CS_IDLE) {
|
||||||
q += sprintf(q, "cpu%d idle", ti->cpu);
|
q += sprintf(q, "cpu %d idle", ti->cpu);
|
||||||
}
|
}
|
||||||
else if (ti->status == CS_RUNNING) {
|
else if (ti->status == CS_RUNNING) {
|
||||||
q += sprintf(q, "cpu%d running", ti->cpu);
|
q += sprintf(q, "cpu %d running", ti->cpu);
|
||||||
}
|
}
|
||||||
else if (ti->status == CS_RESERVED) {
|
else if (ti->status == CS_RESERVED) {
|
||||||
q += sprintf(q, "cpu%d reserved", ti->cpu);
|
q += sprintf(q, "cpu %d reserved", ti->cpu);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
q += sprintf(q, "status=%#x", ti->status);
|
q += sprintf(q, "status=%#x", ti->status);
|
||||||
}
|
}
|
||||||
if (ti->tid != ti->pid) {
|
|
||||||
q += sprintf(q, ",pid=%d", ti->pid);
|
|
||||||
}
|
|
||||||
rbp += print_hex(rbp, buf);
|
rbp += print_hex(rbp, buf);
|
||||||
}
|
}
|
||||||
} while (0);
|
} while (0);
|
||||||
@@ -859,11 +890,12 @@ static void options(int argc, char *argv[]) {
|
|||||||
memset(&opt, 0, sizeof(opt));
|
memset(&opt, 0, sizeof(opt));
|
||||||
opt.kernel_path = "./mckernel.img";
|
opt.kernel_path = "./mckernel.img";
|
||||||
opt.dump_path = "./mcdump";
|
opt.dump_path = "./mcdump";
|
||||||
|
opt.mcos_fd = -1;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
c = getopt(argc, argv, "cd:hk:");
|
c = getopt(argc, argv, "ilcd:hk:o:");
|
||||||
if (c < 0) {
|
if (c < 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -881,12 +913,32 @@ static void options(int argc, char *argv[]) {
|
|||||||
case 'd':
|
case 'd':
|
||||||
opt.dump_path = optarg;
|
opt.dump_path = optarg;
|
||||||
break;
|
break;
|
||||||
|
case 'i':
|
||||||
|
opt.interactive = 1;
|
||||||
|
break;
|
||||||
|
case 'o':
|
||||||
|
opt.os_id = atoi(optarg);
|
||||||
|
break;
|
||||||
|
case 'l':
|
||||||
|
opt.print_idle = 1;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (optind < argc) {
|
if (optind < argc) {
|
||||||
opt.help = 1;
|
opt.help = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (opt.interactive) {
|
||||||
|
char fn[128];
|
||||||
|
sprintf(fn, "/dev/mcos%d", opt.os_id);
|
||||||
|
|
||||||
|
opt.mcos_fd = open(fn, O_RDONLY);
|
||||||
|
if (opt.mcos_fd < 0) {
|
||||||
|
perror("open");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
} /* options() */
|
} /* options() */
|
||||||
|
|
||||||
@@ -969,7 +1021,7 @@ int main(int argc, char *argv[]) {
|
|||||||
uint8_t sum;
|
uint8_t sum;
|
||||||
uint8_t check;
|
uint8_t check;
|
||||||
static char lbuf[1024];
|
static char lbuf[1024];
|
||||||
static char rbuf[1024];
|
static char rbuf[8192];
|
||||||
static char cbuf[3];
|
static char cbuf[3];
|
||||||
char *lbp;
|
char *lbp;
|
||||||
char *p;
|
char *p;
|
||||||
|
|||||||
@@ -66,6 +66,8 @@
|
|||||||
#include "../include/uprotocol.h"
|
#include "../include/uprotocol.h"
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include "../config.h"
|
#include "../config.h"
|
||||||
|
#include <numa.h>
|
||||||
|
#include <numaif.h>
|
||||||
|
|
||||||
//#define DEBUG
|
//#define DEBUG
|
||||||
|
|
||||||
@@ -112,9 +114,9 @@ char **__glob_argv = 0;
|
|||||||
#define ENABLE_MCOVERLAYFS 1
|
#define ENABLE_MCOVERLAYFS 1
|
||||||
#endif // LINUX_VERSION_CODE == 4.6
|
#endif // LINUX_VERSION_CODE == 4.6
|
||||||
#else
|
#else
|
||||||
#if RHEL_RELEASE_CODE == RHEL_RELEASE_VERSION(7,2)
|
#if RHEL_RELEASE_CODE <= RHEL_RELEASE_VERSION(7,3)
|
||||||
#define ENABLE_MCOVERLAYFS 1
|
#define ENABLE_MCOVERLAYFS 1
|
||||||
#endif // RHEL_RELEASE_CODE == 7.2
|
#endif // RHEL_RELEASE_CODE <= 7.3
|
||||||
#endif // RHEL_RELEASE_CODE
|
#endif // RHEL_RELEASE_CODE
|
||||||
#endif // ENABLE_MCOVERLAYFS
|
#endif // ENABLE_MCOVERLAYFS
|
||||||
|
|
||||||
@@ -1623,11 +1625,13 @@ int main(int argc, char **argv)
|
|||||||
/* Partitioned execution, obtain CPU set */
|
/* Partitioned execution, obtain CPU set */
|
||||||
if (nr_processes > 0) {
|
if (nr_processes > 0) {
|
||||||
struct get_cpu_set_arg cpu_set_arg;
|
struct get_cpu_set_arg cpu_set_arg;
|
||||||
|
int mcexec_linux_numa = 0;
|
||||||
|
|
||||||
cpu_set_arg.cpu_set = (void *)&desc->cpu_set;
|
cpu_set_arg.cpu_set = (void *)&desc->cpu_set;
|
||||||
cpu_set_arg.cpu_set_size = sizeof(desc->cpu_set);
|
cpu_set_arg.cpu_set_size = sizeof(desc->cpu_set);
|
||||||
cpu_set_arg.nr_processes = nr_processes;
|
cpu_set_arg.nr_processes = nr_processes;
|
||||||
cpu_set_arg.target_core = &target_core;
|
cpu_set_arg.target_core = &target_core;
|
||||||
|
cpu_set_arg.mcexec_linux_numa = &mcexec_linux_numa;
|
||||||
|
|
||||||
if (ioctl(fd, MCEXEC_UP_GET_CPUSET, (void *)&cpu_set_arg) != 0) {
|
if (ioctl(fd, MCEXEC_UP_GET_CPUSET, (void *)&cpu_set_arg) != 0) {
|
||||||
perror("getting CPU set for partitioned execution");
|
perror("getting CPU set for partitioned execution");
|
||||||
@@ -1636,6 +1640,33 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
desc->cpu = target_core;
|
desc->cpu = target_core;
|
||||||
|
|
||||||
|
/* This call may not succeed, but that is fine */
|
||||||
|
if (numa_run_on_node(mcexec_linux_numa) < 0) {
|
||||||
|
__dprint("%s: WARNING: couldn't bind to NUMA %d\n",
|
||||||
|
__FUNCTION__, mcexec_linux_numa);
|
||||||
|
}
|
||||||
|
#ifdef DEBUG
|
||||||
|
else {
|
||||||
|
cpu_set_t cpuset;
|
||||||
|
char affinity[BUFSIZ];
|
||||||
|
|
||||||
|
CPU_ZERO(&cpuset);
|
||||||
|
if ((sched_getaffinity(0, sizeof(cpu_set_t), &cpuset)) != 0) {
|
||||||
|
perror("Error sched_getaffinity");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
affinity[0] = '\0';
|
||||||
|
for (i = 0; i < 512; i++) {
|
||||||
|
if (CPU_ISSET(i, &cpuset) == 1) {
|
||||||
|
sprintf(affinity, "%s %d", affinity, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
__dprint("%s: PID: %d affinity: %s\n",
|
||||||
|
__FUNCTION__, getpid(), affinity);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ioctl(fd, MCEXEC_UP_PREPARE_IMAGE, (unsigned long)desc) != 0) {
|
if (ioctl(fd, MCEXEC_UP_PREPARE_IMAGE, (unsigned long)desc) != 0) {
|
||||||
@@ -1746,8 +1777,8 @@ do_generic_syscall(
|
|||||||
|
|
||||||
/* Overlayfs /sys/X directory lseek() problem work around */
|
/* Overlayfs /sys/X directory lseek() problem work around */
|
||||||
if (w->sr.number == __NR_lseek && ret == -EINVAL) {
|
if (w->sr.number == __NR_lseek && ret == -EINVAL) {
|
||||||
char proc_path[512];
|
char proc_path[PATH_MAX];
|
||||||
char path[512];
|
char path[PATH_MAX];
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
|
|
||||||
sprintf(proc_path, "/proc/self/fd/%d", (int)w->sr.args[0]);
|
sprintf(proc_path, "/proc/self/fd/%d", (int)w->sr.args[0]);
|
||||||
@@ -1756,6 +1787,7 @@ do_generic_syscall(
|
|||||||
if (readlink(proc_path, path, sizeof(path)) < 0) {
|
if (readlink(proc_path, path, sizeof(path)) < 0) {
|
||||||
fprintf(stderr, "%s: error: readlink() failed for %s\n",
|
fprintf(stderr, "%s: error: readlink() failed for %s\n",
|
||||||
__FUNCTION__, proc_path);
|
__FUNCTION__, proc_path);
|
||||||
|
perror(": ");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2604,6 +2636,24 @@ return_execve2:
|
|||||||
do_syscall_return(fd, cpu, ret, 0, 0, 0, 0);
|
do_syscall_return(fd, cpu, ret, 0, 0, 0, 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case __NR_stat:
|
||||||
|
ret = do_strncpy_from_user(fd, pathbuf, (void *)w.sr.args[0], PATH_MAX);
|
||||||
|
if (ret >= PATH_MAX) {
|
||||||
|
ret = -ENAMETOOLONG;
|
||||||
|
}
|
||||||
|
if (ret < 0) {
|
||||||
|
do_syscall_return(fd, cpu, ret, 0, 0, 0, 0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn = chgpath(pathbuf, tmpbuf);
|
||||||
|
|
||||||
|
ret = stat(fn, (struct stat *)w.sr.args[1]);
|
||||||
|
__dprintf("stat: path=%s, ret=%ld\n", fn, ret);
|
||||||
|
SET_ERR(ret);
|
||||||
|
do_syscall_return(fd, cpu, ret, 0, 0, 0, 0);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
ret = do_generic_syscall(&w);
|
ret = do_generic_syscall(&w);
|
||||||
do_syscall_return(fd, cpu, ret, 0, 0, 0, 0);
|
do_syscall_return(fd, cpu, ret, 0, 0, 0, 0);
|
||||||
|
|||||||
@@ -1,12 +1,17 @@
|
|||||||
|
ENABLE_RUSAGE=@ENABLE_RUSAGE@
|
||||||
VPATH=@abs_srcdir@
|
VPATH=@abs_srcdir@
|
||||||
SRC=$(VPATH)
|
SRC=$(VPATH)
|
||||||
IHKDIR=$(IHKBASE)/$(TARGETDIR)
|
IHKDIR=$(IHKBASE)/$(TARGETDIR)
|
||||||
OBJS = init.o mem.o debug.o mikc.o listeners.o ap.o syscall.o cls.o host.o
|
OBJS = init.o mem.o debug.o mikc.o listeners.o ap.o syscall.o cls.o host.o
|
||||||
OBJS += process.o copy.o waitq.o futex.o timer.o plist.o fileobj.o shmobj.o
|
OBJS += process.o copy.o waitq.o futex.o timer.o plist.o fileobj.o shmobj.o
|
||||||
OBJS += zeroobj.o procfs.o devobj.o sysfs.o xpmem.o
|
OBJS += zeroobj.o procfs.o devobj.o sysfs.o xpmem.o rusage.o freeze.o
|
||||||
DEPSRCS=$(wildcard $(SRC)/*.c)
|
DEPSRCS=$(wildcard $(SRC)/*.c)
|
||||||
|
DOPT=
|
||||||
|
ifeq ($(ENABLE_RUSAGE),yes)
|
||||||
|
DOPT=-DENABLE_RUSAGE
|
||||||
|
endif
|
||||||
|
|
||||||
CFLAGS += -I$(SRC)/include -D__KERNEL__ -g -fno-omit-frame-pointer -fno-inline -fno-inline-small-functions
|
CFLAGS += -I$(SRC)/include -D__KERNEL__ $(DOPT) -g -fno-omit-frame-pointer -fno-inline -fno-inline-small-functions
|
||||||
LDFLAGS += -e arch_start
|
LDFLAGS += -e arch_start
|
||||||
IHKOBJ = ihk/ihk.o
|
IHKOBJ = ihk/ihk.o
|
||||||
|
|
||||||
|
|||||||
30
kernel/ap.c
30
kernel/ap.c
@@ -25,10 +25,27 @@
|
|||||||
#include <init.h>
|
#include <init.h>
|
||||||
#include <march.h>
|
#include <march.h>
|
||||||
#include <cls.h>
|
#include <cls.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <syscall.h>
|
||||||
|
#include <rusage.h>
|
||||||
|
|
||||||
|
//#define DEBUG_PRINT_AP
|
||||||
|
|
||||||
|
#ifdef DEBUG_PRINT_AP
|
||||||
|
#define dkprintf(...) kprintf(__VA_ARGS__)
|
||||||
|
#define ekprintf(...) kprintf(__VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define dkprintf(...) do { if (0) kprintf(__VA_ARGS__); } while (0)
|
||||||
|
#define ekprintf(...) kprintf(__VA_ARGS__)
|
||||||
|
#endif
|
||||||
|
|
||||||
int num_processors = 1;
|
int num_processors = 1;
|
||||||
static volatile int ap_stop = 1;
|
static volatile int ap_stop = 1;
|
||||||
|
|
||||||
|
mcs_lock_node_t ap_syscall_semaphore;
|
||||||
|
|
||||||
|
extern struct ihk_os_monitor *monitor;
|
||||||
|
|
||||||
static void ap_wait(void)
|
static void ap_wait(void)
|
||||||
{
|
{
|
||||||
init_tick();
|
init_tick();
|
||||||
@@ -43,7 +60,11 @@ static void ap_wait(void)
|
|||||||
arch_start_pvclock();
|
arch_start_pvclock();
|
||||||
|
|
||||||
if (find_command_line("hidos")) {
|
if (find_command_line("hidos")) {
|
||||||
|
mcs_lock_node_t mcs_node;
|
||||||
|
|
||||||
|
mcs_lock_lock_noirq(&ap_syscall_semaphore, &mcs_node);
|
||||||
init_host_syscall_channel();
|
init_host_syscall_channel();
|
||||||
|
mcs_lock_unlock_noirq(&ap_syscall_semaphore, &mcs_node);
|
||||||
}
|
}
|
||||||
|
|
||||||
pc_ap_init();
|
pc_ap_init();
|
||||||
@@ -57,6 +78,7 @@ static void ap_wait(void)
|
|||||||
void ap_start(void)
|
void ap_start(void)
|
||||||
{
|
{
|
||||||
init_tick();
|
init_tick();
|
||||||
|
mcs_lock_init(&ap_syscall_semaphore);
|
||||||
ap_stop = 0;
|
ap_stop = 0;
|
||||||
sync_tick();
|
sync_tick();
|
||||||
}
|
}
|
||||||
@@ -93,13 +115,17 @@ void ap_init(void)
|
|||||||
if (cpu_info->hw_ids[i] == bsp_hw_id) {
|
if (cpu_info->hw_ids[i] == bsp_hw_id) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
kprintf("AP Booting: %d (HW ID: %d @ NUMA %d)\n", i,
|
dkprintf("AP Booting: %d (HW ID: %d @ NUMA %d)\n", i,
|
||||||
cpu_info->hw_ids[i], cpu_info->nodes[i]);
|
cpu_info->hw_ids[i], cpu_info->nodes[i]);
|
||||||
ihk_mc_boot_cpu(cpu_info->hw_ids[i], (unsigned long)ap_wait);
|
ihk_mc_boot_cpu(cpu_info->hw_ids[i], (unsigned long)ap_wait);
|
||||||
|
|
||||||
num_processors++;
|
num_processors++;
|
||||||
}
|
}
|
||||||
kprintf("AP Booting: Done\n");
|
kprintf("BSP: booted %d AP CPUs\n", cpu_info->ncpus - 1);
|
||||||
|
#ifdef ENABLE_RUSAGE
|
||||||
|
rusage_num_threads = 0;
|
||||||
|
rusage_max_num_threads = 0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <sysfs.h>
|
#include <sysfs.h>
|
||||||
|
|||||||
@@ -24,16 +24,22 @@ extern int num_processors;
|
|||||||
|
|
||||||
struct cpu_local_var *clv;
|
struct cpu_local_var *clv;
|
||||||
int cpu_local_var_initialized = 0;
|
int cpu_local_var_initialized = 0;
|
||||||
|
extern struct ihk_os_monitor *monitor;
|
||||||
|
|
||||||
void cpu_local_var_init(void)
|
void cpu_local_var_init(void)
|
||||||
{
|
{
|
||||||
int z;
|
int z;
|
||||||
|
int i;
|
||||||
|
|
||||||
z = sizeof(struct cpu_local_var) * num_processors;
|
z = sizeof(struct cpu_local_var) * num_processors;
|
||||||
z = (z + PAGE_SIZE - 1) >> PAGE_SHIFT;
|
z = (z + PAGE_SIZE - 1) >> PAGE_SHIFT;
|
||||||
|
|
||||||
clv = ihk_mc_alloc_pages(z, IHK_MC_AP_CRITICAL);
|
clv = ihk_mc_alloc_pages(z, IHK_MC_AP_CRITICAL);
|
||||||
memset(clv, 0, z * PAGE_SIZE);
|
memset(clv, 0, z * PAGE_SIZE);
|
||||||
|
|
||||||
|
for(i = 0; i < num_processors; i++)
|
||||||
|
clv[i].monitor = monitor + i;
|
||||||
|
|
||||||
cpu_local_var_initialized = 1;
|
cpu_local_var_initialized = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ int devobj_create(int fd, size_t len, off_t off, struct memobj **objp, int *maxp
|
|||||||
__FUNCTION__, fd, len, off, result.handle, result.maxprot);
|
__FUNCTION__, fd, len, off, result.handle, result.maxprot);
|
||||||
|
|
||||||
obj->memobj.ops = &devobj_ops;
|
obj->memobj.ops = &devobj_ops;
|
||||||
obj->memobj.flags = MF_HAS_PAGER;
|
obj->memobj.flags = MF_HAS_PAGER | MF_DEV_FILE;
|
||||||
obj->memobj.size = len;
|
obj->memobj.size = len;
|
||||||
obj->handle = result.handle;
|
obj->handle = result.handle;
|
||||||
obj->ref = 1;
|
obj->ref = 1;
|
||||||
@@ -181,19 +181,21 @@ static void devobj_release(struct memobj *memobj)
|
|||||||
memobj_unlock(&obj->memobj);
|
memobj_unlock(&obj->memobj);
|
||||||
|
|
||||||
if (free_obj) {
|
if (free_obj) {
|
||||||
int error;
|
if (!(free_obj->memobj.flags & MF_HOST_RELEASED)) {
|
||||||
ihk_mc_user_context_t ctx;
|
int error;
|
||||||
|
ihk_mc_user_context_t ctx;
|
||||||
|
|
||||||
ihk_mc_syscall_arg0(&ctx) = PAGER_REQ_UNMAP;
|
ihk_mc_syscall_arg0(&ctx) = PAGER_REQ_UNMAP;
|
||||||
ihk_mc_syscall_arg1(&ctx) = handle;
|
ihk_mc_syscall_arg1(&ctx) = handle;
|
||||||
ihk_mc_syscall_arg2(&ctx) = 1;
|
ihk_mc_syscall_arg2(&ctx) = 1;
|
||||||
|
|
||||||
error = syscall_generic_forwarding(__NR_mmap, &ctx);
|
error = syscall_generic_forwarding(__NR_mmap, &ctx);
|
||||||
if (error) {
|
if (error) {
|
||||||
kprintf("devobj_release(%p %lx):"
|
kprintf("devobj_release(%p %lx):"
|
||||||
"release failed. %d\n",
|
"release failed. %d\n",
|
||||||
free_obj, handle, error);
|
free_obj, handle, error);
|
||||||
/* through */
|
/* through */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj->pfn_table) {
|
if (obj->pfn_table) {
|
||||||
|
|||||||
@@ -213,7 +213,7 @@ int fileobj_create(int fd, struct memobj **objp, int *maxprotp)
|
|||||||
|
|
||||||
memset(newobj, 0, sizeof(*newobj));
|
memset(newobj, 0, sizeof(*newobj));
|
||||||
newobj->memobj.ops = &fileobj_ops;
|
newobj->memobj.ops = &fileobj_ops;
|
||||||
newobj->memobj.flags = MF_HAS_PAGER;
|
newobj->memobj.flags = MF_HAS_PAGER | MF_REG_FILE;
|
||||||
newobj->handle = result.handle;
|
newobj->handle = result.handle;
|
||||||
newobj->sref = 1;
|
newobj->sref = 1;
|
||||||
newobj->cref = 1;
|
newobj->cref = 1;
|
||||||
@@ -294,6 +294,9 @@ static void fileobj_release(struct memobj *memobj)
|
|||||||
obj->sref -= free_sref;
|
obj->sref -= free_sref;
|
||||||
free_handle = obj->handle;
|
free_handle = obj->handle;
|
||||||
memobj_unlock(&obj->memobj);
|
memobj_unlock(&obj->memobj);
|
||||||
|
if (obj->memobj.flags & MF_HOST_RELEASED) {
|
||||||
|
free_sref = 0; // don't call syscall_generic_forwarding
|
||||||
|
}
|
||||||
|
|
||||||
if (free_obj) {
|
if (free_obj) {
|
||||||
dkprintf("%s: release obj 0x%lx cref: %d, free_obj: 0x%lx, %s\n",
|
dkprintf("%s: release obj 0x%lx cref: %d, free_obj: 0x%lx, %s\n",
|
||||||
@@ -497,7 +500,10 @@ static int fileobj_get_page(struct memobj *memobj, off_t off,
|
|||||||
|
|
||||||
if (!page) {
|
if (!page) {
|
||||||
npages = 1 << p2align;
|
npages = 1 << p2align;
|
||||||
virt = ihk_mc_alloc_pages(npages, IHK_MC_AP_NOWAIT);
|
|
||||||
|
virt = ihk_mc_alloc_pages(npages, IHK_MC_AP_NOWAIT |
|
||||||
|
(to_memobj(obj)->flags & MF_ZEROFILL) ? IHK_MC_AP_USER : 0);
|
||||||
|
|
||||||
if (!virt) {
|
if (!virt) {
|
||||||
error = -ENOMEM;
|
error = -ENOMEM;
|
||||||
kprintf("fileobj_get_page(%p,%lx,%x,%p):"
|
kprintf("fileobj_get_page(%p,%lx,%x,%p):"
|
||||||
|
|||||||
54
kernel/freeze.c
Normal file
54
kernel/freeze.c
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
#include <kmsg.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <ihk/cpu.h>
|
||||||
|
#include <ihk/debug.h>
|
||||||
|
#include <cls.h>
|
||||||
|
|
||||||
|
extern int nmi_mode;
|
||||||
|
extern void mod_nmi_ctx(void *, void(*)());
|
||||||
|
extern void lapic_ack();
|
||||||
|
extern void __freeze();
|
||||||
|
|
||||||
|
void
|
||||||
|
freeze()
|
||||||
|
{
|
||||||
|
struct ihk_os_monitor *monitor = cpu_local_var(monitor);
|
||||||
|
|
||||||
|
monitor->status_bak = monitor->status;
|
||||||
|
monitor->status = IHK_OS_MONITOR_KERNEL_FROZEN;
|
||||||
|
while (monitor->status == IHK_OS_MONITOR_KERNEL_FROZEN)
|
||||||
|
cpu_halt();
|
||||||
|
monitor->status = monitor->status_bak;
|
||||||
|
}
|
||||||
|
|
||||||
|
long
|
||||||
|
freeze_thaw(void *nmi_ctx)
|
||||||
|
{
|
||||||
|
struct ihk_os_monitor *monitor = cpu_local_var(monitor);
|
||||||
|
|
||||||
|
if (nmi_mode == 1) {
|
||||||
|
if (monitor->status != IHK_OS_MONITOR_KERNEL_FROZEN) {
|
||||||
|
#if 1
|
||||||
|
mod_nmi_ctx(nmi_ctx, __freeze);
|
||||||
|
return 1;
|
||||||
|
#else
|
||||||
|
unsigned long flags;
|
||||||
|
|
||||||
|
flags = cpu_disable_interrupt_save();
|
||||||
|
monitor->status_bak = monitor->status;
|
||||||
|
monitor->status = IHK_OS_MONITOR_KERNEL_FROZEN;
|
||||||
|
lapic_ack();
|
||||||
|
while (monitor->status == IHK_OS_MONITOR_KERNEL_FROZEN)
|
||||||
|
cpu_halt();
|
||||||
|
monitor->status = monitor->status_bak;
|
||||||
|
cpu_restore_interrupt(flags);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(nmi_mode == 2) {
|
||||||
|
if (monitor->status == IHK_OS_MONITOR_KERNEL_FROZEN) {
|
||||||
|
monitor->status = IHK_OS_MONITOR_KERNEL_THAW;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -248,9 +248,13 @@ static int cmpxchg_futex_value_locked(uint32_t __user *uaddr, uint32_t uval, uin
|
|||||||
|
|
||||||
static int get_futex_value_locked(uint32_t *dest, uint32_t *from)
|
static int get_futex_value_locked(uint32_t *dest, uint32_t *from)
|
||||||
{
|
{
|
||||||
/* RIKEN: futexes are always on not swappable pages */
|
/*
|
||||||
*dest = getint_user((int *)from);
|
* Officially we should call:
|
||||||
|
* return getint_user((int *)dest, (int *)from);
|
||||||
|
*
|
||||||
|
* but McKernel on x86 can just access user-space.
|
||||||
|
*/
|
||||||
|
*dest = *(volatile uint32_t *)from;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -670,25 +674,32 @@ static uint64_t futex_wait_queue_me(struct futex_hash_bucket *hb, struct futex_q
|
|||||||
uint64_t timeout)
|
uint64_t timeout)
|
||||||
{
|
{
|
||||||
uint64_t time_remain = 0;
|
uint64_t time_remain = 0;
|
||||||
|
unsigned long irqstate;
|
||||||
|
struct thread *thread = cpu_local_var(current);
|
||||||
/*
|
/*
|
||||||
* The task state is guaranteed to be set before another task can
|
* The task state is guaranteed to be set before another task can
|
||||||
* wake it. set_current_state() is implemented using set_mb() and
|
* wake it.
|
||||||
* queue_me() calls spin_unlock() upon completion, both serializing
|
* queue_me() calls spin_unlock() upon completion, serializing
|
||||||
* access to the hash list and forcing another memory barrier.
|
* access to the hash list and forcing a memory barrier.
|
||||||
*/
|
*/
|
||||||
xchg4(&(cpu_local_var(current)->status), PS_INTERRUPTIBLE);
|
xchg4(&(cpu_local_var(current)->status), PS_INTERRUPTIBLE);
|
||||||
|
|
||||||
|
/* Indicate spin sleep */
|
||||||
|
irqstate = ihk_mc_spinlock_lock(&thread->spin_sleep_lock);
|
||||||
|
thread->spin_sleep = 1;
|
||||||
|
ihk_mc_spinlock_unlock(&thread->spin_sleep_lock, irqstate);
|
||||||
|
|
||||||
queue_me(q, hb);
|
queue_me(q, hb);
|
||||||
|
|
||||||
if (!plist_node_empty(&q->list)) {
|
if (!plist_node_empty(&q->list)) {
|
||||||
|
|
||||||
/* RIKEN: use mcos timers */
|
|
||||||
if (timeout) {
|
if (timeout) {
|
||||||
dkprintf("futex_wait_queue_me(): tid: %d schedule_timeout()\n", cpu_local_var(current)->tid);
|
dkprintf("futex_wait_queue_me(): tid: %d schedule_timeout()\n", cpu_local_var(current)->tid);
|
||||||
time_remain = schedule_timeout(timeout);
|
time_remain = schedule_timeout(timeout);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
dkprintf("futex_wait_queue_me(): tid: %d schedule()\n", cpu_local_var(current)->tid);
|
dkprintf("futex_wait_queue_me(): tid: %d schedule()\n", cpu_local_var(current)->tid);
|
||||||
schedule();
|
spin_sleep_or_schedule();
|
||||||
time_remain = 0;
|
time_remain = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -697,6 +708,7 @@ static uint64_t futex_wait_queue_me(struct futex_hash_bucket *hb, struct futex_q
|
|||||||
|
|
||||||
/* This does not need to be serialized */
|
/* This does not need to be serialized */
|
||||||
cpu_local_var(current)->status = PS_RUNNING;
|
cpu_local_var(current)->status = PS_RUNNING;
|
||||||
|
thread->spin_sleep = 0;
|
||||||
|
|
||||||
return time_remain;
|
return time_remain;
|
||||||
}
|
}
|
||||||
@@ -743,14 +755,17 @@ static int futex_wait_setup(uint32_t __user *uaddr, uint32_t val, int fshared,
|
|||||||
*/
|
*/
|
||||||
q->key = FUTEX_KEY_INIT;
|
q->key = FUTEX_KEY_INIT;
|
||||||
ret = get_futex_key(uaddr, fshared, &q->key);
|
ret = get_futex_key(uaddr, fshared, &q->key);
|
||||||
if ((ret != 0))
|
if (ret != 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
*hb = queue_lock(q);
|
*hb = queue_lock(q);
|
||||||
|
|
||||||
ret = get_futex_value_locked(&uval, uaddr);
|
ret = get_futex_value_locked(&uval, uaddr);
|
||||||
|
if (ret) {
|
||||||
/* RIKEN: get_futex_value_locked() always returns 0 on mckernel */
|
queue_unlock(q, *hb);
|
||||||
|
put_futex_key(fshared, &q->key);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
if (uval != val) {
|
if (uval != val) {
|
||||||
queue_unlock(q, *hb);
|
queue_unlock(q, *hb);
|
||||||
@@ -776,8 +791,6 @@ static int futex_wait(uint32_t __user *uaddr, int fshared,
|
|||||||
q.bitset = bitset;
|
q.bitset = bitset;
|
||||||
q.requeue_pi_key = NULL;
|
q.requeue_pi_key = NULL;
|
||||||
|
|
||||||
/* RIKEN: futex_wait_queue_me() calls schedule_timeout() if timer is set */
|
|
||||||
|
|
||||||
retry:
|
retry:
|
||||||
/* Prepare to wait on uaddr. */
|
/* Prepare to wait on uaddr. */
|
||||||
ret = futex_wait_setup(uaddr, val, fshared, &q, &hb);
|
ret = futex_wait_setup(uaddr, val, fshared, &q, &hb);
|
||||||
|
|||||||
138
kernel/host.c
138
kernel/host.c
@@ -23,14 +23,15 @@
|
|||||||
#include <ihk/debug.h>
|
#include <ihk/debug.h>
|
||||||
#include <ihk/ikc.h>
|
#include <ihk/ikc.h>
|
||||||
#include <ikc/master.h>
|
#include <ikc/master.h>
|
||||||
#include <syscall.h>
|
|
||||||
#include <cls.h>
|
#include <cls.h>
|
||||||
|
#include <syscall.h>
|
||||||
#include <process.h>
|
#include <process.h>
|
||||||
#include <page.h>
|
#include <page.h>
|
||||||
#include <mman.h>
|
#include <mman.h>
|
||||||
#include <init.h>
|
#include <init.h>
|
||||||
#include <kmalloc.h>
|
#include <kmalloc.h>
|
||||||
#include <sysfs.h>
|
#include <sysfs.h>
|
||||||
|
#include <ihk/perfctr.h>
|
||||||
|
|
||||||
//#define DEBUG_PRINT_HOST
|
//#define DEBUG_PRINT_HOST
|
||||||
|
|
||||||
@@ -125,7 +126,7 @@ int prepare_process_ranges_args_envs(struct thread *thread,
|
|||||||
|
|
||||||
up = virt_to_phys(up_v);
|
up = virt_to_phys(up_v);
|
||||||
if (add_process_memory_range(vm, s, e, up, flags, NULL, 0,
|
if (add_process_memory_range(vm, s, e, up, flags, NULL, 0,
|
||||||
PAGE_SHIFT) != 0) {
|
PAGE_SHIFT, NULL) != 0) {
|
||||||
ihk_mc_free_pages(up_v, range_npages);
|
ihk_mc_free_pages(up_v, range_npages);
|
||||||
kprintf("ERROR: adding memory range for ELF section %i\n", i);
|
kprintf("ERROR: adding memory range for ELF section %i\n", i);
|
||||||
goto err;
|
goto err;
|
||||||
@@ -213,7 +214,7 @@ int prepare_process_ranges_args_envs(struct thread *thread,
|
|||||||
args_envs_p = virt_to_phys(args_envs);
|
args_envs_p = virt_to_phys(args_envs);
|
||||||
|
|
||||||
if(add_process_memory_range(vm, addr, e, args_envs_p,
|
if(add_process_memory_range(vm, addr, e, args_envs_p,
|
||||||
flags, NULL, 0, PAGE_SHIFT) != 0){
|
flags, NULL, 0, PAGE_SHIFT, NULL) != 0){
|
||||||
ihk_mc_free_pages(args_envs, ARGENV_PAGE_COUNT);
|
ihk_mc_free_pages(args_envs, ARGENV_PAGE_COUNT);
|
||||||
kprintf("ERROR: adding memory range for args/envs\n");
|
kprintf("ERROR: adding memory range for args/envs\n");
|
||||||
goto err;
|
goto err;
|
||||||
@@ -434,9 +435,6 @@ static int process_msg_prepare_process(unsigned long rphys)
|
|||||||
vm->region.map_end = vm->region.map_start;
|
vm->region.map_end = vm->region.map_start;
|
||||||
memcpy(proc->rlimit, pn->rlimit, sizeof(struct rlimit) * MCK_RLIM_MAX);
|
memcpy(proc->rlimit, pn->rlimit, sizeof(struct rlimit) * MCK_RLIM_MAX);
|
||||||
|
|
||||||
/* TODO: Clear it at the proper timing */
|
|
||||||
cpu_local_var(scp).post_idx = 0;
|
|
||||||
|
|
||||||
if (prepare_process_ranges_args_envs(thread, pn, p, attr,
|
if (prepare_process_ranges_args_envs(thread, pn, p, attr,
|
||||||
NULL, 0, NULL, 0) != 0) {
|
NULL, 0, NULL, 0) != 0) {
|
||||||
kprintf("error: preparing process ranges, args, envs, stack\n");
|
kprintf("error: preparing process ranges, args, envs, stack\n");
|
||||||
@@ -461,70 +459,6 @@ err:
|
|||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void process_msg_init(struct ikc_scd_init_param *pcp, struct syscall_params *lparam)
|
|
||||||
{
|
|
||||||
lparam->response_va = ihk_mc_alloc_pages(RESPONSE_PAGE_COUNT, 0);
|
|
||||||
lparam->response_pa = virt_to_phys(lparam->response_va);
|
|
||||||
|
|
||||||
pcp->request_page = 0;
|
|
||||||
pcp->doorbell_page = 0;
|
|
||||||
pcp->response_page = lparam->response_pa;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void process_msg_init_acked(struct ihk_ikc_channel_desc *c, unsigned long pphys)
|
|
||||||
{
|
|
||||||
struct ikc_scd_init_param *param = phys_to_virt(pphys);
|
|
||||||
struct syscall_params *lparam;
|
|
||||||
enum ihk_mc_pt_attribute attr;
|
|
||||||
|
|
||||||
attr = PTATTR_NO_EXECUTE | PTATTR_WRITABLE | PTATTR_FOR_USER;
|
|
||||||
|
|
||||||
lparam = &cpu_local_var(scp);
|
|
||||||
if(cpu_local_var(syscall_channel2) == c)
|
|
||||||
lparam = &cpu_local_var(scp2);
|
|
||||||
lparam->request_rpa = param->request_page;
|
|
||||||
lparam->request_pa = ihk_mc_map_memory(NULL, param->request_page,
|
|
||||||
REQUEST_PAGE_COUNT * PAGE_SIZE);
|
|
||||||
if((lparam->request_va = ihk_mc_map_virtual(lparam->request_pa,
|
|
||||||
REQUEST_PAGE_COUNT,
|
|
||||||
attr)) == NULL){
|
|
||||||
// TODO:
|
|
||||||
panic("ENOMEM");
|
|
||||||
}
|
|
||||||
|
|
||||||
lparam->doorbell_rpa = param->doorbell_page;
|
|
||||||
lparam->doorbell_pa = ihk_mc_map_memory(NULL, param->doorbell_page,
|
|
||||||
DOORBELL_PAGE_COUNT *
|
|
||||||
PAGE_SIZE);
|
|
||||||
if((lparam->doorbell_va = ihk_mc_map_virtual(lparam->doorbell_pa,
|
|
||||||
DOORBELL_PAGE_COUNT,
|
|
||||||
attr)) == NULL){
|
|
||||||
// TODO:
|
|
||||||
panic("ENOMEM");
|
|
||||||
}
|
|
||||||
|
|
||||||
lparam->post_rpa = param->post_page;
|
|
||||||
lparam->post_pa = ihk_mc_map_memory(NULL, param->post_page,
|
|
||||||
PAGE_SIZE);
|
|
||||||
if((lparam->post_va = ihk_mc_map_virtual(lparam->post_pa, 1,
|
|
||||||
attr)) == NULL){
|
|
||||||
// TODO:
|
|
||||||
panic("ENOMEM");
|
|
||||||
}
|
|
||||||
|
|
||||||
lparam->post_fin = 1;
|
|
||||||
|
|
||||||
dkprintf("Syscall parameters: (%d)\n", ihk_mc_get_processor_id());
|
|
||||||
dkprintf(" Response: %lx, %p\n",
|
|
||||||
lparam->response_pa, lparam->response_va);
|
|
||||||
dkprintf(" Request : %lx, %lx, %p\n",
|
|
||||||
lparam->request_pa, lparam->request_rpa, lparam->request_va);
|
|
||||||
dkprintf(" Doorbell: %lx, %lx, %p\n",
|
|
||||||
lparam->doorbell_pa, lparam->doorbell_rpa, lparam->doorbell_va);
|
|
||||||
dkprintf(" Post: %lx, %lx, %p\n",
|
|
||||||
lparam->post_pa, lparam->post_rpa, lparam->post_va);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void syscall_channel_send(struct ihk_ikc_channel_desc *c,
|
static void syscall_channel_send(struct ihk_ikc_channel_desc *c,
|
||||||
struct ikc_scd_packet *packet)
|
struct ikc_scd_packet *packet)
|
||||||
{
|
{
|
||||||
@@ -532,7 +466,7 @@ static void syscall_channel_send(struct ihk_ikc_channel_desc *c,
|
|||||||
}
|
}
|
||||||
|
|
||||||
extern unsigned long do_kill(struct thread *, int, int, int, struct siginfo *, int ptracecont);
|
extern unsigned long do_kill(struct thread *, int, int, int, struct siginfo *, int ptracecont);
|
||||||
extern void process_procfs_request(unsigned long rarg);
|
extern void process_procfs_request(struct ikc_scd_packet *rpacket);
|
||||||
extern void terminate_host(int pid);
|
extern void terminate_host(int pid);
|
||||||
extern void debug_log(long);
|
extern void debug_log(long);
|
||||||
|
|
||||||
@@ -555,11 +489,12 @@ static int syscall_packet_handler(struct ihk_ikc_channel_desc *c,
|
|||||||
unsigned long pp;
|
unsigned long pp;
|
||||||
int cpuid;
|
int cpuid;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
struct perf_ctrl_desc *pcd;
|
||||||
|
unsigned int mode = 0;
|
||||||
|
|
||||||
switch (packet->msg) {
|
switch (packet->msg) {
|
||||||
case SCD_MSG_INIT_CHANNEL_ACKED:
|
case SCD_MSG_INIT_CHANNEL_ACKED:
|
||||||
dkprintf("SCD_MSG_INIT_CHANNEL_ACKED\n");
|
dkprintf("SCD_MSG_INIT_CHANNEL_ACKED\n");
|
||||||
process_msg_init_acked(c, packet->arg);
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -640,7 +575,7 @@ static int syscall_packet_handler(struct ihk_ikc_channel_desc *c,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case SCD_MSG_PROCFS_REQUEST:
|
case SCD_MSG_PROCFS_REQUEST:
|
||||||
process_procfs_request(packet->arg);
|
process_procfs_request(packet);
|
||||||
ret = 0;
|
ret = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -665,6 +600,61 @@ static int syscall_packet_handler(struct ihk_ikc_channel_desc *c,
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case SCD_MSG_PERF_CTRL:
|
||||||
|
pp = ihk_mc_map_memory(NULL, packet->arg, sizeof(struct perf_ctrl_desc));
|
||||||
|
pcd = (struct perf_ctrl_desc *)ihk_mc_map_virtual(pp, 1, PTATTR_WRITABLE | PTATTR_ACTIVE);
|
||||||
|
|
||||||
|
switch (pcd->ctrl_type) {
|
||||||
|
case PERF_CTRL_SET:
|
||||||
|
if (!pcd->exclude_kernel) {
|
||||||
|
mode |= PERFCTR_KERNEL_MODE;
|
||||||
|
}
|
||||||
|
if (!pcd->exclude_user) {
|
||||||
|
mode |= PERFCTR_USER_MODE;
|
||||||
|
}
|
||||||
|
ihk_mc_perfctr_init_raw(pcd->target_cntr, pcd->config, mode);
|
||||||
|
ihk_mc_perfctr_stop(1 << pcd->target_cntr);
|
||||||
|
ihk_mc_perfctr_reset(pcd->target_cntr);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PERF_CTRL_ENABLE:
|
||||||
|
ihk_mc_perfctr_start(pcd->target_cntr_mask);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PERF_CTRL_DISABLE:
|
||||||
|
ihk_mc_perfctr_stop(pcd->target_cntr_mask);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PERF_CTRL_GET:
|
||||||
|
pcd->read_value = ihk_mc_perfctr_read(pcd->target_cntr);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
kprintf("%s: SCD_MSG_PERF_CTRL unexpected ctrl_type\n", __FUNCTION__);
|
||||||
|
}
|
||||||
|
|
||||||
|
ihk_mc_unmap_virtual(pcd, 1, 0);
|
||||||
|
ihk_mc_unmap_memory(NULL, pp, sizeof(struct perf_ctrl_desc));
|
||||||
|
|
||||||
|
pckt.msg = SCD_MSG_PERF_ACK;
|
||||||
|
pckt.err = 0;
|
||||||
|
pckt.arg = packet->arg;
|
||||||
|
ihk_ikc_send(c, &pckt, 0);
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SCD_MSG_CPU_RW_REG:
|
||||||
|
|
||||||
|
pckt.msg = SCD_MSG_CPU_RW_REG_RESP;
|
||||||
|
memcpy(&pckt.desc, &packet->desc,
|
||||||
|
sizeof(struct mcctrl_os_cpu_register));
|
||||||
|
pckt.resp = packet->resp;
|
||||||
|
pckt.err = arch_cpu_read_write_register(&pckt.desc, pckt.op);
|
||||||
|
|
||||||
|
ihk_ikc_send(c, &pckt, 0);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
kprintf("syscall_pakcet_handler:unknown message "
|
kprintf("syscall_pakcet_handler:unknown message "
|
||||||
"(%d.%d.%d.%d.%d.%#lx)\n",
|
"(%d.%d.%d.%d.%d.%#lx)\n",
|
||||||
@@ -699,7 +689,6 @@ void init_host_syscall_channel(void)
|
|||||||
|
|
||||||
get_this_cpu_local_var()->syscall_channel = param.channel;
|
get_this_cpu_local_var()->syscall_channel = param.channel;
|
||||||
|
|
||||||
process_msg_init(&cpu_local_var(iip), &cpu_local_var(scp));
|
|
||||||
pckt.msg = SCD_MSG_INIT_CHANNEL;
|
pckt.msg = SCD_MSG_INIT_CHANNEL;
|
||||||
pckt.ref = ihk_mc_get_processor_id();
|
pckt.ref = ihk_mc_get_processor_id();
|
||||||
pckt.arg = virt_to_phys(&cpu_local_var(iip));
|
pckt.arg = virt_to_phys(&cpu_local_var(iip));
|
||||||
@@ -726,7 +715,6 @@ void init_host_syscall_channel2(void)
|
|||||||
|
|
||||||
get_this_cpu_local_var()->syscall_channel2 = param.channel;
|
get_this_cpu_local_var()->syscall_channel2 = param.channel;
|
||||||
|
|
||||||
process_msg_init(&cpu_local_var(iip2), &cpu_local_var(scp2));
|
|
||||||
pckt.msg = SCD_MSG_INIT_CHANNEL;
|
pckt.msg = SCD_MSG_INIT_CHANNEL;
|
||||||
pckt.ref = ihk_mc_get_processor_id();
|
pckt.ref = ihk_mc_get_processor_id();
|
||||||
pckt.arg = virt_to_phys(&cpu_local_var(iip2));
|
pckt.arg = virt_to_phys(&cpu_local_var(iip2));
|
||||||
|
|||||||
@@ -28,6 +28,26 @@ struct kmalloc_header {
|
|||||||
/* 32 bytes */
|
/* 32 bytes */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#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
|
||||||
|
|
||||||
|
struct ihk_os_monitor {
|
||||||
|
int status;
|
||||||
|
int status_bak;
|
||||||
|
unsigned long counter;
|
||||||
|
unsigned long ocounter;
|
||||||
|
unsigned long user_tsc;
|
||||||
|
unsigned long system_tsc;
|
||||||
|
};
|
||||||
|
|
||||||
#include <ihk/lock.h>
|
#include <ihk/lock.h>
|
||||||
#define CPU_STATUS_DISABLE (0)
|
#define CPU_STATUS_DISABLE (0)
|
||||||
#define CPU_STATUS_IDLE (1)
|
#define CPU_STATUS_IDLE (1)
|
||||||
@@ -56,11 +76,9 @@ struct cpu_local_var {
|
|||||||
size_t runq_len;
|
size_t runq_len;
|
||||||
|
|
||||||
struct ihk_ikc_channel_desc *syscall_channel;
|
struct ihk_ikc_channel_desc *syscall_channel;
|
||||||
struct syscall_params scp;
|
|
||||||
struct ikc_scd_init_param iip;
|
struct ikc_scd_init_param iip;
|
||||||
|
|
||||||
struct ihk_ikc_channel_desc *syscall_channel2;
|
struct ihk_ikc_channel_desc *syscall_channel2;
|
||||||
struct syscall_params scp2;
|
|
||||||
struct ikc_scd_init_param iip2;
|
struct ikc_scd_init_param iip2;
|
||||||
struct resource_set *resource_set;
|
struct resource_set *resource_set;
|
||||||
|
|
||||||
@@ -77,6 +95,7 @@ struct cpu_local_var {
|
|||||||
int no_preempt;
|
int no_preempt;
|
||||||
int timer_enabled;
|
int timer_enabled;
|
||||||
int kmalloc_initialized;
|
int kmalloc_initialized;
|
||||||
|
struct ihk_os_monitor *monitor;
|
||||||
} __attribute__((aligned(64)));
|
} __attribute__((aligned(64)));
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ extern void init_host_syscall_channel2(void);
|
|||||||
extern void sched_init(void);
|
extern void sched_init(void);
|
||||||
extern void pc_ap_init(void);
|
extern void pc_ap_init(void);
|
||||||
extern void cpu_sysfs_setup(void);
|
extern void cpu_sysfs_setup(void);
|
||||||
|
extern void rusage_sysfs_setup(void);
|
||||||
|
extern void status_sysfs_setup(void);
|
||||||
|
|
||||||
extern char *find_command_line(char *name);
|
extern char *find_command_line(char *name);
|
||||||
|
|
||||||
|
|||||||
@@ -28,9 +28,9 @@ r;\
|
|||||||
})
|
})
|
||||||
#define kfree(ptr) _kfree(ptr, __FILE__, __LINE__)
|
#define kfree(ptr) _kfree(ptr, __FILE__, __LINE__)
|
||||||
#define memcheck(ptr, msg) _memcheck(ptr, msg, __FILE__, __LINE__, 0)
|
#define memcheck(ptr, msg) _memcheck(ptr, msg, __FILE__, __LINE__, 0)
|
||||||
void *_kmalloc(int size, enum ihk_mc_ap_flag flag, char *file, int line);
|
void *_kmalloc(int size, ihk_mc_ap_flag flag, char *file, int line);
|
||||||
void _kfree(void *ptr, char *file, int line);
|
void _kfree(void *ptr, char *file, int line);
|
||||||
void *__kmalloc(int size, enum ihk_mc_ap_flag flag);
|
void *__kmalloc(int size, ihk_mc_ap_flag flag);
|
||||||
void __kfree(void *ptr);
|
void __kfree(void *ptr);
|
||||||
|
|
||||||
int _memcheck(void *ptr, char *msg, char *file, int line, int free);
|
int _memcheck(void *ptr, char *msg, char *file, int line, int free);
|
||||||
|
|||||||
@@ -34,6 +34,9 @@ enum {
|
|||||||
MF_IS_REMOVABLE = 0x0004,
|
MF_IS_REMOVABLE = 0x0004,
|
||||||
MF_PREFETCH = 0x0008,
|
MF_PREFETCH = 0x0008,
|
||||||
MF_ZEROFILL = 0x0010,
|
MF_ZEROFILL = 0x0010,
|
||||||
|
MF_REG_FILE = 0x1000,
|
||||||
|
MF_DEV_FILE = 0x2000,
|
||||||
|
MF_HOST_RELEASED = 0x80000000,
|
||||||
MF_END
|
MF_END
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -232,8 +232,6 @@ enum mpol_rebind_step {
|
|||||||
#include <waitq.h>
|
#include <waitq.h>
|
||||||
#include <futex.h>
|
#include <futex.h>
|
||||||
|
|
||||||
//#define TRACK_SYSCALLS
|
|
||||||
|
|
||||||
struct resource_set;
|
struct resource_set;
|
||||||
struct process_hash;
|
struct process_hash;
|
||||||
struct thread_hash;
|
struct thread_hash;
|
||||||
@@ -244,6 +242,28 @@ struct process_vm;
|
|||||||
struct vm_regions;
|
struct vm_regions;
|
||||||
struct vm_range;
|
struct vm_range;
|
||||||
|
|
||||||
|
//#define TRACK_SYSCALLS
|
||||||
|
|
||||||
|
#ifdef TRACK_SYSCALLS
|
||||||
|
#define TRACK_SYSCALLS_MAX 300
|
||||||
|
#define __NR_track_syscalls 701
|
||||||
|
|
||||||
|
#define TRACK_SYSCALLS_CLEAR 0x01
|
||||||
|
#define TRACK_SYSCALLS_ON 0x02
|
||||||
|
#define TRACK_SYSCALLS_OFF 0x04
|
||||||
|
#define TRACK_SYSCALLS_PRINT 0x08
|
||||||
|
#define TRACK_SYSCALLS_PRINT_PROC 0x10
|
||||||
|
|
||||||
|
void track_syscalls_print_thread_stats(struct thread *thread);
|
||||||
|
void track_syscalls_print_proc_stats(struct process *proc);
|
||||||
|
void track_syscalls_accumulate_counters(struct thread *thread,
|
||||||
|
struct process *proc);
|
||||||
|
void track_syscalls_alloc_counters(struct thread *thread);
|
||||||
|
void track_syscalls_dealloc_thread_counters(struct thread *thread);
|
||||||
|
void track_syscalls_dealloc_proc_counters(struct process *proc);
|
||||||
|
#endif // TRACK_SYSCALLS
|
||||||
|
|
||||||
|
|
||||||
#define HASH_SIZE 73
|
#define HASH_SIZE 73
|
||||||
|
|
||||||
struct resource_set {
|
struct resource_set {
|
||||||
@@ -369,6 +389,7 @@ struct vm_range {
|
|||||||
off_t objoff;
|
off_t objoff;
|
||||||
int pgshift; /* page size. 0 means THP */
|
int pgshift; /* page size. 0 means THP */
|
||||||
int padding;
|
int padding;
|
||||||
|
void *private_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct vm_range_numa_policy {
|
struct vm_range_numa_policy {
|
||||||
@@ -539,6 +560,13 @@ struct process {
|
|||||||
#define PP_COUNT 2
|
#define PP_COUNT 2
|
||||||
#define PP_STOP 3
|
#define PP_STOP 3
|
||||||
struct mc_perf_event *monitoring_event;
|
struct mc_perf_event *monitoring_event;
|
||||||
|
#ifdef TRACK_SYSCALLS
|
||||||
|
mcs_lock_node_t st_lock;
|
||||||
|
uint64_t *syscall_times;
|
||||||
|
uint32_t *syscall_cnts;
|
||||||
|
uint64_t *offload_times;
|
||||||
|
uint32_t *offload_cnts;
|
||||||
|
#endif // TRACK_SYSCALLS
|
||||||
};
|
};
|
||||||
|
|
||||||
void hold_thread(struct thread *ftn);
|
void hold_thread(struct thread *ftn);
|
||||||
@@ -612,7 +640,7 @@ struct thread {
|
|||||||
int in_syscall_offload;
|
int in_syscall_offload;
|
||||||
|
|
||||||
#ifdef TRACK_SYSCALLS
|
#ifdef TRACK_SYSCALLS
|
||||||
int socc_enabled;
|
int track_syscalls;
|
||||||
uint64_t *syscall_times;
|
uint64_t *syscall_times;
|
||||||
uint32_t *syscall_cnts;
|
uint32_t *syscall_cnts;
|
||||||
uint64_t *offload_times;
|
uint64_t *offload_times;
|
||||||
@@ -637,9 +665,14 @@ struct thread {
|
|||||||
struct sig_pending *ptrace_sendsig;
|
struct sig_pending *ptrace_sendsig;
|
||||||
|
|
||||||
// cpu time
|
// cpu time
|
||||||
|
/*
|
||||||
struct timespec stime;
|
struct timespec stime;
|
||||||
struct timespec utime;
|
struct timespec utime;
|
||||||
struct timespec btime;
|
struct timespec btime;
|
||||||
|
*/
|
||||||
|
unsigned long system_tsc;
|
||||||
|
unsigned long user_tsc;
|
||||||
|
unsigned long base_tsc;
|
||||||
int times_update;
|
int times_update;
|
||||||
int in_kernel;
|
int in_kernel;
|
||||||
|
|
||||||
@@ -716,9 +749,10 @@ void free_process_memory_ranges(struct process_vm *vm);
|
|||||||
int populate_process_memory(struct process_vm *vm, void *start, size_t len);
|
int populate_process_memory(struct process_vm *vm, void *start, size_t len);
|
||||||
|
|
||||||
int add_process_memory_range(struct process_vm *vm,
|
int add_process_memory_range(struct process_vm *vm,
|
||||||
unsigned long start, unsigned long end,
|
unsigned long start, unsigned long end,
|
||||||
unsigned long phys, unsigned long flag,
|
unsigned long phys, unsigned long flag,
|
||||||
struct memobj *memobj, off_t objoff, int pgshift);
|
struct memobj *memobj, off_t offset,
|
||||||
|
int pgshift, struct vm_range **rp);
|
||||||
int remove_process_memory_range(struct process_vm *vm, unsigned long start,
|
int remove_process_memory_range(struct process_vm *vm, unsigned long start,
|
||||||
unsigned long end, int *ro_freedp);
|
unsigned long end, int *ro_freedp);
|
||||||
int split_process_memory_range(struct process_vm *vm,
|
int split_process_memory_range(struct process_vm *vm,
|
||||||
@@ -758,9 +792,11 @@ extern enum ihk_mc_pt_attribute arch_vrflag_to_ptattr(unsigned long flag, uint64
|
|||||||
enum ihk_mc_pt_attribute common_vrflag_to_ptattr(unsigned long flag, uint64_t fault, pte_t *ptep);
|
enum ihk_mc_pt_attribute common_vrflag_to_ptattr(unsigned long flag, uint64_t fault, pte_t *ptep);
|
||||||
|
|
||||||
void schedule(void);
|
void schedule(void);
|
||||||
|
void spin_sleep_or_schedule(void);
|
||||||
void runq_add_thread(struct thread *thread, int cpu_id);
|
void runq_add_thread(struct thread *thread, int cpu_id);
|
||||||
void runq_del_thread(struct thread *thread, int cpu_id);
|
void runq_del_thread(struct thread *thread, int cpu_id);
|
||||||
int sched_wakeup_thread(struct thread *thread, int valid_states);
|
int sched_wakeup_thread(struct thread *thread, int valid_states);
|
||||||
|
int sched_wakeup_thread_locked(struct thread *thread, int valid_states);
|
||||||
|
|
||||||
void sched_request_migrate(int cpu_id, struct thread *thread);
|
void sched_request_migrate(int cpu_id, struct thread *thread);
|
||||||
void check_need_resched(void);
|
void check_need_resched(void);
|
||||||
|
|||||||
79
kernel/include/rusage.h
Normal file
79
kernel/include/rusage.h
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
#ifndef __RUSAGE_H
|
||||||
|
#define __RUSAGE_H
|
||||||
|
|
||||||
|
#define RUSAGE_DEFAULT_SIZE 10
|
||||||
|
|
||||||
|
enum RUSAGE_MEMBER {
|
||||||
|
RUSAGE_RSS,
|
||||||
|
RUSAGE_CACHE,
|
||||||
|
RUSAGE_RSS_HUGE,
|
||||||
|
RUSAGE_MAPPED_FILE,
|
||||||
|
RUSAGE_MAX_USAGE,
|
||||||
|
RUSAGE_KMEM_USAGE,
|
||||||
|
RUSAGE_KMAX_USAGE,
|
||||||
|
RUSAGE_NUM_NUMA_NODES,
|
||||||
|
RUSAGE_NUMA_STAT,
|
||||||
|
RUSAGE_HUGETLB ,
|
||||||
|
RUSAGE_HUGETLB_MAX ,
|
||||||
|
RUSAGE_STAT_SYSTEM ,
|
||||||
|
RUSAGE_STAT_USER ,
|
||||||
|
RUSAGE_USAGE ,
|
||||||
|
RUSAGE_USAGE_PER_CPU ,
|
||||||
|
RUSAGE_NUM_THREADS ,
|
||||||
|
RUSAGE_MAX_NUM_THREADS
|
||||||
|
};
|
||||||
|
|
||||||
|
struct r_data{
|
||||||
|
unsigned long pid;
|
||||||
|
unsigned long rss;
|
||||||
|
unsigned long cache;
|
||||||
|
unsigned long rss_huge;
|
||||||
|
unsigned long mapped_file;
|
||||||
|
unsigned long max_usage;
|
||||||
|
unsigned long kmem_usage;
|
||||||
|
unsigned long kmax_usage;
|
||||||
|
unsigned long hugetlb;
|
||||||
|
unsigned long hugetlb_max;
|
||||||
|
unsigned long stat_system;
|
||||||
|
unsigned long stat_user;
|
||||||
|
unsigned long usage;
|
||||||
|
struct r_data *next;
|
||||||
|
} ;
|
||||||
|
typedef struct r_data rusage_data;
|
||||||
|
|
||||||
|
rusage_data *rdata[RUSAGE_DEFAULT_SIZE];
|
||||||
|
unsigned long rusage_max_num_threads;
|
||||||
|
unsigned long rusage_num_threads;
|
||||||
|
|
||||||
|
enum ihk_os_status {
|
||||||
|
IHK_STATUS_INACTIVE,
|
||||||
|
IHK_STATUS_BOOTING,
|
||||||
|
IHK_STATUS_RUNNING,
|
||||||
|
IHK_STATUS_SHUTDOWN,
|
||||||
|
IHK_STATUS_PANIC,
|
||||||
|
IHK_STATUS_HUNGUP,
|
||||||
|
IHK_STATUS_FREEZING,
|
||||||
|
IHK_STATUS_FROZEN,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum ihk_os_status os_status;
|
||||||
|
unsigned long sys_delegate_count;
|
||||||
|
enum sys_delegate_state_enum {
|
||||||
|
ENTER_KERNEL,
|
||||||
|
EXIT_KERNEL,
|
||||||
|
};
|
||||||
|
enum sys_delegate_state_enum sys_delegate_state;
|
||||||
|
|
||||||
|
unsigned long rusage_rss[sizeof(cpu_set_t)/8];
|
||||||
|
unsigned long rusage_rss_max;
|
||||||
|
long rusage_rss_current;
|
||||||
|
unsigned long rusage_kmem_usage;
|
||||||
|
unsigned long rusage_kmem_max_usage;
|
||||||
|
unsigned long rusage_hugetlb_usage;
|
||||||
|
unsigned long rusage_hugetlb_max_usage;
|
||||||
|
unsigned long rusage_numa_stat[1024];
|
||||||
|
unsigned long rusage_max_memory;
|
||||||
|
|
||||||
|
#define RUSAGE_MEM_LIMIT 2000000
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -73,6 +73,13 @@
|
|||||||
/* #define SCD_MSG_SYSFS_RESP_CLEANUP 0x43 */
|
/* #define SCD_MSG_SYSFS_RESP_CLEANUP 0x43 */
|
||||||
#define SCD_MSG_PROCFS_TID_CREATE 0x44
|
#define SCD_MSG_PROCFS_TID_CREATE 0x44
|
||||||
#define SCD_MSG_PROCFS_TID_DELETE 0x45
|
#define SCD_MSG_PROCFS_TID_DELETE 0x45
|
||||||
|
#define SCD_MSG_EVENT_SIGNAL 0x46
|
||||||
|
|
||||||
|
#define SCD_MSG_PERF_CTRL 0x50
|
||||||
|
#define SCD_MSG_PERF_ACK 0x51
|
||||||
|
|
||||||
|
#define SCD_MSG_CPU_RW_REG 0x52
|
||||||
|
#define SCD_MSG_CPU_RW_REG_RESP 0x53
|
||||||
|
|
||||||
/* Cloning flags. */
|
/* Cloning flags. */
|
||||||
# define CSIGNAL 0x000000ff /* Signal mask to be sent at exit. */
|
# define CSIGNAL 0x000000ff /* Signal mask to be sent at exit. */
|
||||||
@@ -206,6 +213,18 @@ struct syscall_request {
|
|||||||
unsigned long args[6];
|
unsigned long args[6];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct mcctrl_os_cpu_register {
|
||||||
|
unsigned long addr;
|
||||||
|
unsigned long val;
|
||||||
|
unsigned long addr_ext;
|
||||||
|
};
|
||||||
|
|
||||||
|
enum mcctrl_os_cpu_operation {
|
||||||
|
MCCTRL_OS_CPU_READ_REGISTER,
|
||||||
|
MCCTRL_OS_CPU_WRITE_REGISTER,
|
||||||
|
MCCTRL_OS_CPU_MAX_OP
|
||||||
|
};
|
||||||
|
|
||||||
struct ikc_scd_packet {
|
struct ikc_scd_packet {
|
||||||
int msg;
|
int msg;
|
||||||
int err;
|
int err;
|
||||||
@@ -231,6 +250,13 @@ struct ikc_scd_packet {
|
|||||||
struct {
|
struct {
|
||||||
int ttid;
|
int ttid;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* SCD_MSG_CPU_RW_REG */
|
||||||
|
struct {
|
||||||
|
struct mcctrl_os_cpu_register desc;
|
||||||
|
enum mcctrl_os_cpu_operation op;
|
||||||
|
void *resp;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
char padding[12];
|
char padding[12];
|
||||||
};
|
};
|
||||||
@@ -255,22 +281,6 @@ struct syscall_post {
|
|||||||
unsigned long v[8];
|
unsigned long v[8];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct syscall_params {
|
|
||||||
unsigned long request_rpa, request_pa;
|
|
||||||
struct syscall_request *request_va;
|
|
||||||
unsigned long response_pa;
|
|
||||||
struct syscall_response *response_va;
|
|
||||||
|
|
||||||
unsigned long doorbell_rpa, doorbell_pa;
|
|
||||||
unsigned long *doorbell_va;
|
|
||||||
|
|
||||||
unsigned int post_idx;
|
|
||||||
unsigned long post_rpa, post_pa;
|
|
||||||
struct syscall_post *post_va;
|
|
||||||
unsigned long post_fin;
|
|
||||||
struct syscall_post post_buf IHK_DMA_ALIGN;
|
|
||||||
};
|
|
||||||
|
|
||||||
#define SYSCALL_DECLARE(name) long sys_##name(int n, ihk_mc_user_context_t *ctx)
|
#define SYSCALL_DECLARE(name) long sys_##name(int n, ihk_mc_user_context_t *ctx)
|
||||||
#define SYSCALL_HEADER struct syscall_request request IHK_DMA_ALIGN; \
|
#define SYSCALL_HEADER struct syscall_request request IHK_DMA_ALIGN; \
|
||||||
request.number = n
|
request.number = n
|
||||||
@@ -390,6 +400,29 @@ struct tod_data_s {
|
|||||||
};
|
};
|
||||||
extern struct tod_data_s tod_data; /* residing in arch-dependent file */
|
extern struct tod_data_s tod_data; /* residing in arch-dependent file */
|
||||||
|
|
||||||
|
static inline void tsc_to_ts(unsigned long tsc, struct timespec *ts)
|
||||||
|
{
|
||||||
|
time_t sec_delta;
|
||||||
|
long ns_delta;
|
||||||
|
|
||||||
|
sec_delta = tsc / tod_data.clocks_per_sec;
|
||||||
|
ns_delta = NS_PER_SEC * (tsc % tod_data.clocks_per_sec)
|
||||||
|
/ tod_data.clocks_per_sec;
|
||||||
|
/* calc. of ns_delta overflows if clocks_per_sec exceeds 18.44 GHz */
|
||||||
|
|
||||||
|
ts->tv_sec = sec_delta;
|
||||||
|
ts->tv_nsec = ns_delta;
|
||||||
|
if (ts->tv_nsec >= NS_PER_SEC) {
|
||||||
|
ts->tv_nsec -= NS_PER_SEC;
|
||||||
|
++ts->tv_sec;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline unsigned long timespec_to_jiffy(const struct timespec *ats)
|
||||||
|
{
|
||||||
|
return ats->tv_sec * 100 + ats->tv_nsec / 10000000;
|
||||||
|
}
|
||||||
|
|
||||||
void reset_cputime();
|
void reset_cputime();
|
||||||
void set_cputime(int mode);
|
void set_cputime(int mode);
|
||||||
int do_munmap(void *addr, size_t len);
|
int do_munmap(void *addr, size_t len);
|
||||||
@@ -401,6 +434,8 @@ int do_shmget(key_t key, size_t size, int shmflg);
|
|||||||
struct process_vm;
|
struct process_vm;
|
||||||
int arch_map_vdso(struct process_vm *vm); /* arch dependent */
|
int arch_map_vdso(struct process_vm *vm); /* arch dependent */
|
||||||
int arch_setup_vdso(void);
|
int arch_setup_vdso(void);
|
||||||
|
int arch_cpu_read_write_register(struct mcctrl_os_cpu_register *desc,
|
||||||
|
enum mcctrl_os_cpu_operation op);
|
||||||
|
|
||||||
#define VDSO_MAXPAGES 2
|
#define VDSO_MAXPAGES 2
|
||||||
struct vdso {
|
struct vdso {
|
||||||
@@ -437,4 +472,34 @@ struct get_cpu_mapping_req {
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum perf_ctrl_type {
|
||||||
|
PERF_CTRL_SET,
|
||||||
|
PERF_CTRL_GET,
|
||||||
|
PERF_CTRL_ENABLE,
|
||||||
|
PERF_CTRL_DISABLE,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct perf_ctrl_desc {
|
||||||
|
enum perf_ctrl_type ctrl_type;
|
||||||
|
int status;
|
||||||
|
union {
|
||||||
|
/* for SET, GET */
|
||||||
|
struct {
|
||||||
|
unsigned int target_cntr;
|
||||||
|
unsigned long config;
|
||||||
|
unsigned long read_value;
|
||||||
|
unsigned disabled :1,
|
||||||
|
pinned :1,
|
||||||
|
exclude_user :1,
|
||||||
|
exclude_kernel :1,
|
||||||
|
exclude_hv :1,
|
||||||
|
exclude_idle :1;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* for START, STOP*/
|
||||||
|
struct {
|
||||||
|
unsigned long target_cntr_mask;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ typedef int (*waitq_func_t)(struct waitq_entry *wait, unsigned mode,
|
|||||||
|
|
||||||
int default_wake_function(struct waitq_entry *wait, unsigned mode, int flags,
|
int default_wake_function(struct waitq_entry *wait, unsigned mode, int flags,
|
||||||
void *key);
|
void *key);
|
||||||
|
int locked_wake_function(struct waitq_entry *wait, unsigned mode, int flags,
|
||||||
|
void *key);
|
||||||
|
|
||||||
typedef struct waitq {
|
typedef struct waitq {
|
||||||
ihk_spinlock_t lock;
|
ihk_spinlock_t lock;
|
||||||
@@ -57,6 +59,13 @@ typedef struct waitq_entry {
|
|||||||
.link = { &(name).link, &(name).link } \
|
.link = { &(name).link, &(name).link } \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define DECLARE_WAITQ_ENTRY_LOCKED(name, tsk) \
|
||||||
|
waitq_entry_t name = { \
|
||||||
|
.private = tsk, \
|
||||||
|
.func = locked_wake_function, \
|
||||||
|
.link = { &(name).link, &(name).link } \
|
||||||
|
}
|
||||||
|
|
||||||
extern void waitq_init(waitq_t *waitq);
|
extern void waitq_init(waitq_t *waitq);
|
||||||
extern void waitq_init_entry(waitq_entry_t *entry, struct thread *proc);
|
extern void waitq_init_entry(waitq_entry_t *entry, struct thread *proc);
|
||||||
extern int waitq_active(waitq_t *waitq);
|
extern int waitq_active(waitq_t *waitq);
|
||||||
|
|||||||
@@ -11,11 +11,16 @@
|
|||||||
#ifndef _XPMEM_H
|
#ifndef _XPMEM_H
|
||||||
#define _XPMEM_H
|
#define _XPMEM_H
|
||||||
|
|
||||||
|
#include <process.h>
|
||||||
#include <ihk/context.h>
|
#include <ihk/context.h>
|
||||||
|
|
||||||
#define XPMEM_DEV_PATH "/dev/xpmem"
|
#define XPMEM_DEV_PATH "/dev/xpmem"
|
||||||
|
|
||||||
extern int xpmem_open(ihk_mc_user_context_t *ctx);
|
extern int xpmem_open(ihk_mc_user_context_t *ctx);
|
||||||
|
extern int xpmem_remove_process_memory_range(struct process_vm *vm,
|
||||||
|
struct vm_range *vmr);
|
||||||
|
extern int xpmem_fault_process_memory_range(struct process_vm *vm,
|
||||||
|
struct vm_range *vmr, unsigned long vaddr, uint64_t reason);
|
||||||
|
|
||||||
#endif /* _XPMEM_H */
|
#endif /* _XPMEM_H */
|
||||||
|
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ static inline int xpmem_ap_hashtable_index(xpmem_apid_t apid)
|
|||||||
|
|
||||||
index = ((xpmem_id_t *)&apid)->xpmem_id.uniq % XPMEM_AP_HASHTABLE_SIZE;
|
index = ((xpmem_id_t *)&apid)->xpmem_id.uniq % XPMEM_AP_HASHTABLE_SIZE;
|
||||||
|
|
||||||
XPMEM_DEBUG("return: apid=%lu, index=%d", apid, index);
|
XPMEM_DEBUG("return: apid=0x%lx, index=%d", apid, index);
|
||||||
|
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
@@ -174,22 +174,20 @@ struct xpmem_thread_group {
|
|||||||
uid_t uid; /* tg's uid */
|
uid_t uid; /* tg's uid */
|
||||||
gid_t gid; /* tg's gid */
|
gid_t gid; /* tg's gid */
|
||||||
volatile int flags; /* tg attributes and state */
|
volatile int flags; /* tg attributes and state */
|
||||||
ihk_atomic_t uniq_segid;
|
ihk_atomic_t uniq_segid; /* segid uniq */
|
||||||
ihk_atomic_t uniq_apid;
|
ihk_atomic_t uniq_apid; /* apid uniq */
|
||||||
mcs_rwlock_lock_t seg_list_lock;
|
mcs_rwlock_lock_t seg_list_lock; /* tg's list of segs lock */
|
||||||
struct list_head seg_list; /* tg's list of segs */
|
struct list_head seg_list; /* tg's list of segs */
|
||||||
ihk_atomic_t refcnt; /* references to tg */
|
ihk_atomic_t refcnt; /* references to tg */
|
||||||
ihk_atomic_t n_pinned; /* #of pages pinned by this tg */
|
ihk_atomic_t n_pinned; /* #of pages pinned by this tg */
|
||||||
struct list_head tg_hashlist; /* tg hash list */
|
struct list_head tg_hashlist; /* tg hash list */
|
||||||
struct thread *group_leader; /* thread group leader */
|
struct thread *group_leader; /* thread group leader */
|
||||||
struct process_vm *vm; /* tg's mm */
|
struct process_vm *vm; /* tg's process_vm */
|
||||||
ihk_atomic_t n_recall_PFNs; /* #of recall of PFNs in progress */
|
|
||||||
struct xpmem_hashlist ap_hashtable[]; /* locks + ap hash lists */
|
struct xpmem_hashlist ap_hashtable[]; /* locks + ap hash lists */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct xpmem_segment {
|
struct xpmem_segment {
|
||||||
ihk_spinlock_t lock; /* seg lock */
|
ihk_spinlock_t lock; /* seg lock */
|
||||||
mcs_rwlock_lock_t seg_lock; /* seg sema */
|
|
||||||
xpmem_segid_t segid; /* unique segid */
|
xpmem_segid_t segid; /* unique segid */
|
||||||
unsigned long vaddr; /* starting address */
|
unsigned long vaddr; /* starting address */
|
||||||
size_t size; /* size of seg */
|
size_t size; /* size of seg */
|
||||||
@@ -216,18 +214,16 @@ struct xpmem_access_permit {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct xpmem_attachment {
|
struct xpmem_attachment {
|
||||||
mcs_rwlock_lock_t at_lock; /* att lock for serialization */
|
mcs_rwlock_lock_t at_lock; /* att lock */
|
||||||
struct mcs_rwlock_node_irqsave at_irqsave; /* att lock for serialization */
|
|
||||||
unsigned long vaddr; /* starting address of seg attached */
|
unsigned long vaddr; /* starting address of seg attached */
|
||||||
unsigned long at_vaddr; /* address where seg is attached */
|
unsigned long at_vaddr; /* address where seg is attached */
|
||||||
size_t at_size; /* size of seg attachment */
|
size_t at_size; /* size of seg attachment */
|
||||||
struct vm_range *at_vma; /* vma where seg is attachment */
|
struct vm_range *at_vmr; /* vm_range where seg is attachment */
|
||||||
volatile int flags; /* att attributes and state */
|
volatile int flags; /* att attributes and state */
|
||||||
ihk_atomic_t refcnt; /* references to att */
|
ihk_atomic_t refcnt; /* references to att */
|
||||||
struct xpmem_access_permit *ap; /* associated access permit */
|
struct xpmem_access_permit *ap; /* associated access permit */
|
||||||
struct list_head att_list; /* atts linked to access permit */
|
struct list_head att_list; /* atts linked to access permit */
|
||||||
struct process_vm *vm; /* mm struct attached to */
|
struct process_vm *vm; /* process_vm attached to */
|
||||||
mcs_rwlock_lock_t invalidate_lock; /* to serialize page table invalidates */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct xpmem_partition {
|
struct xpmem_partition {
|
||||||
@@ -249,8 +245,10 @@ struct xpmem_perm {
|
|||||||
#define XPMEM_PERM_IRUSR 00400
|
#define XPMEM_PERM_IRUSR 00400
|
||||||
#define XPMEM_PERM_IWUSR 00200
|
#define XPMEM_PERM_IWUSR 00200
|
||||||
|
|
||||||
|
extern struct xpmem_partition *xpmem_my_part;
|
||||||
|
|
||||||
static int xpmem_ioctl(struct mckfd *mckfd, ihk_mc_user_context_t *ctx);
|
static int xpmem_ioctl(struct mckfd *mckfd, ihk_mc_user_context_t *ctx);
|
||||||
static int xpmem_close( struct mckfd *mckfd, ihk_mc_user_context_t *ctx);
|
static int xpmem_close(struct mckfd *mckfd, ihk_mc_user_context_t *ctx);
|
||||||
|
|
||||||
static int xpmem_init(void);
|
static int xpmem_init(void);
|
||||||
static void xpmem_exit(void);
|
static void xpmem_exit(void);
|
||||||
@@ -263,10 +261,47 @@ static xpmem_segid_t xpmem_make_segid(struct xpmem_thread_group *);
|
|||||||
static int xpmem_remove(xpmem_segid_t);
|
static int xpmem_remove(xpmem_segid_t);
|
||||||
static void xpmem_remove_seg(struct xpmem_thread_group *,
|
static void xpmem_remove_seg(struct xpmem_thread_group *,
|
||||||
struct xpmem_segment *);
|
struct xpmem_segment *);
|
||||||
|
static void xpmem_remove_segs_of_tg(struct xpmem_thread_group *seg_tg);
|
||||||
|
|
||||||
|
static int xpmem_get(xpmem_segid_t, int, int, void *, xpmem_apid_t *);
|
||||||
|
static int xpmem_check_permit_mode(int, struct xpmem_segment *);
|
||||||
|
static int xpmem_perms(struct xpmem_perm *, short);
|
||||||
|
static xpmem_apid_t xpmem_make_apid(struct xpmem_thread_group *);
|
||||||
|
|
||||||
|
static int xpmem_release(xpmem_apid_t);
|
||||||
|
static void xpmem_release_ap(struct xpmem_thread_group *,
|
||||||
|
struct xpmem_access_permit *);
|
||||||
|
static void xpmem_release_aps_of_tg(struct xpmem_thread_group *ap_tg);
|
||||||
|
|
||||||
|
static int xpmem_attach(struct mckfd *, xpmem_apid_t, off_t, size_t,
|
||||||
|
unsigned long, int, int, unsigned long *);
|
||||||
|
|
||||||
|
static int xpmem_detach(unsigned long);
|
||||||
|
static int xpmem_vm_munmap(struct process_vm *vm, void *addr, size_t len);
|
||||||
|
static int xpmem_remove_process_range(struct process_vm *vm,
|
||||||
|
unsigned long start, unsigned long end, int *ro_freedp);
|
||||||
|
static int xpmem_free_process_memory_range(struct process_vm *vm,
|
||||||
|
struct vm_range *range);
|
||||||
|
static void xpmem_detach_att(struct xpmem_access_permit *,
|
||||||
|
struct xpmem_attachment *);
|
||||||
static void xpmem_clear_PTEs(struct xpmem_segment *);
|
static void xpmem_clear_PTEs(struct xpmem_segment *);
|
||||||
|
static void xpmem_clear_PTEs_range(struct xpmem_segment *, unsigned long,
|
||||||
|
unsigned long);
|
||||||
|
static void xpmem_clear_PTEs_of_ap(struct xpmem_access_permit *, unsigned long,
|
||||||
|
unsigned long);
|
||||||
|
static void xpmem_clear_PTEs_of_att(struct xpmem_attachment *, unsigned long,
|
||||||
|
unsigned long);
|
||||||
|
|
||||||
extern struct xpmem_partition *xpmem_my_part;
|
static int xpmem_remap_pte(struct process_vm *, struct vm_range *,
|
||||||
|
unsigned long, uint64_t, struct xpmem_segment *, unsigned long);
|
||||||
|
|
||||||
|
static int xpmem_ensure_valid_page(struct xpmem_segment *, unsigned long);
|
||||||
|
static pte_t * xpmem_vaddr_to_pte(struct process_vm *, unsigned long,
|
||||||
|
size_t *pgsize);
|
||||||
|
static int xpmem_pin_page(struct xpmem_thread_group *, struct thread *,
|
||||||
|
struct process_vm *, unsigned long);
|
||||||
|
static void xpmem_unpin_pages(struct xpmem_segment *, struct process_vm *,
|
||||||
|
unsigned long, size_t);
|
||||||
|
|
||||||
static struct xpmem_thread_group * __xpmem_tg_ref_by_tgid_nolock_internal(
|
static struct xpmem_thread_group * __xpmem_tg_ref_by_tgid_nolock_internal(
|
||||||
pid_t, int, int);
|
pid_t, int, int);
|
||||||
@@ -317,10 +352,17 @@ static inline struct xpmem_thread_group *__xpmem_tg_ref_by_tgid_nolock(
|
|||||||
#define xpmem_tg_ref_by_tgid_all_nolock(t) __xpmem_tg_ref_by_tgid_nolock(t, 1)
|
#define xpmem_tg_ref_by_tgid_all_nolock(t) __xpmem_tg_ref_by_tgid_nolock(t, 1)
|
||||||
|
|
||||||
static struct xpmem_thread_group * xpmem_tg_ref_by_segid(xpmem_segid_t);
|
static struct xpmem_thread_group * xpmem_tg_ref_by_segid(xpmem_segid_t);
|
||||||
|
static struct xpmem_thread_group * xpmem_tg_ref_by_apid(xpmem_apid_t);
|
||||||
static void xpmem_tg_deref(struct xpmem_thread_group *);
|
static void xpmem_tg_deref(struct xpmem_thread_group *);
|
||||||
static struct xpmem_segment *xpmem_seg_ref_by_segid(struct xpmem_thread_group *,
|
static struct xpmem_segment *xpmem_seg_ref_by_segid(struct xpmem_thread_group *,
|
||||||
xpmem_segid_t);
|
xpmem_segid_t);
|
||||||
static void xpmem_seg_deref(struct xpmem_segment *);
|
static void xpmem_seg_deref(struct xpmem_segment *);
|
||||||
|
static struct xpmem_access_permit * xpmem_ap_ref_by_apid(
|
||||||
|
struct xpmem_thread_group *, xpmem_apid_t);
|
||||||
|
static void xpmem_ap_deref(struct xpmem_access_permit *);
|
||||||
|
static void xpmem_att_deref(struct xpmem_attachment *);
|
||||||
|
static int xpmem_validate_access(struct xpmem_access_permit *, off_t, size_t,
|
||||||
|
int, unsigned long *);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Inlines that mark an internal driver structure as being destroyable or not.
|
* Inlines that mark an internal driver structure as being destroyable or not.
|
||||||
@@ -363,6 +405,42 @@ static inline void xpmem_seg_destroyable(
|
|||||||
XPMEM_DEBUG("return: ");
|
XPMEM_DEBUG("return: ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void xpmem_ap_not_destroyable(
|
||||||
|
struct xpmem_access_permit *ap)
|
||||||
|
{
|
||||||
|
ihk_atomic_set(&ap->refcnt, 1);
|
||||||
|
|
||||||
|
XPMEM_DEBUG("return: ap->refcnt=%d", ap->refcnt);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void xpmem_ap_destroyable(
|
||||||
|
struct xpmem_access_permit *ap)
|
||||||
|
{
|
||||||
|
XPMEM_DEBUG("call: ");
|
||||||
|
|
||||||
|
xpmem_ap_deref(ap);
|
||||||
|
|
||||||
|
XPMEM_DEBUG("return: ");
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void xpmem_att_not_destroyable(
|
||||||
|
struct xpmem_attachment *att)
|
||||||
|
{
|
||||||
|
ihk_atomic_set(&att->refcnt, 1);
|
||||||
|
|
||||||
|
XPMEM_DEBUG("return: att->refcnt=%d", att->refcnt);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void xpmem_att_destroyable(
|
||||||
|
struct xpmem_attachment *att)
|
||||||
|
{
|
||||||
|
XPMEM_DEBUG("call: ");
|
||||||
|
|
||||||
|
xpmem_att_deref(att);
|
||||||
|
|
||||||
|
XPMEM_DEBUG("return: ");
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Inlines that increment the refcnt for the specified structure.
|
* Inlines that increment the refcnt for the specified structure.
|
||||||
*/
|
*/
|
||||||
@@ -384,5 +462,29 @@ static inline void xpmem_seg_ref(
|
|||||||
XPMEM_DEBUG("return: seg->refcnt=%d", seg->refcnt);
|
XPMEM_DEBUG("return: seg->refcnt=%d", seg->refcnt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void xpmem_ap_ref(
|
||||||
|
struct xpmem_access_permit *ap)
|
||||||
|
{
|
||||||
|
DBUG_ON(ihk_atomic_read(&ap->refcnt) <= 0);
|
||||||
|
ihk_atomic_inc(&ap->refcnt);
|
||||||
|
|
||||||
|
XPMEM_DEBUG("return: ap->refcnt=%d", ap->refcnt);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void xpmem_att_ref(
|
||||||
|
struct xpmem_attachment *att)
|
||||||
|
{
|
||||||
|
DBUG_ON(ihk_atomic_read(&att->refcnt) <= 0);
|
||||||
|
ihk_atomic_inc(&att->refcnt);
|
||||||
|
|
||||||
|
XPMEM_DEBUG("return: att->refcnt=%d", att->refcnt);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int xpmem_is_private_data(
|
||||||
|
struct vm_range *vmr)
|
||||||
|
{
|
||||||
|
return (vmr->private_data != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* _XPMEM_PRIVATE_H */
|
#endif /* _XPMEM_PRIVATE_H */
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
#include <cls.h>
|
#include <cls.h>
|
||||||
#include <syscall.h>
|
#include <syscall.h>
|
||||||
#include <sysfs.h>
|
#include <sysfs.h>
|
||||||
|
#include <rusage.h>
|
||||||
|
|
||||||
//#define IOCTL_FUNC_EXTENSION
|
//#define IOCTL_FUNC_EXTENSION
|
||||||
#ifdef IOCTL_FUNC_EXTENSION
|
#ifdef IOCTL_FUNC_EXTENSION
|
||||||
@@ -239,6 +240,31 @@ static void time_init(void)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct ihk_os_monitor *monitor;
|
||||||
|
|
||||||
|
static void monitor_init()
|
||||||
|
{
|
||||||
|
int z;
|
||||||
|
unsigned long phys;
|
||||||
|
|
||||||
|
z = sizeof(struct ihk_os_monitor) * num_processors;
|
||||||
|
z = (z + PAGE_SIZE -1) >> PAGE_SHIFT;
|
||||||
|
monitor = ihk_mc_alloc_pages(z, IHK_MC_AP_CRITICAL);
|
||||||
|
memset(monitor, 0, z * PAGE_SIZE);
|
||||||
|
phys = virt_to_phys(monitor);
|
||||||
|
ihk_set_monitor(phys, sizeof(struct ihk_os_monitor) * num_processors);
|
||||||
|
}
|
||||||
|
|
||||||
|
int nmi_mode;
|
||||||
|
|
||||||
|
static void nmi_init()
|
||||||
|
{
|
||||||
|
unsigned long phys;
|
||||||
|
|
||||||
|
phys = virt_to_phys(&nmi_mode);
|
||||||
|
ihk_set_nmi_mode_addr(phys);
|
||||||
|
}
|
||||||
|
|
||||||
static void rest_init(void)
|
static void rest_init(void)
|
||||||
{
|
{
|
||||||
handler_init();
|
handler_init();
|
||||||
@@ -250,7 +276,9 @@ static void rest_init(void)
|
|||||||
//pc_test();
|
//pc_test();
|
||||||
|
|
||||||
ap_init();
|
ap_init();
|
||||||
|
monitor_init();
|
||||||
cpu_local_var_init();
|
cpu_local_var_init();
|
||||||
|
nmi_init();
|
||||||
time_init();
|
time_init();
|
||||||
kmalloc_init();
|
kmalloc_init();
|
||||||
|
|
||||||
@@ -320,6 +348,10 @@ static void setup_remote_snooping_samples(void)
|
|||||||
static void populate_sysfs(void)
|
static void populate_sysfs(void)
|
||||||
{
|
{
|
||||||
cpu_sysfs_setup();
|
cpu_sysfs_setup();
|
||||||
|
#ifdef ENABLE_RUSAGE
|
||||||
|
rusage_sysfs_setup();
|
||||||
|
status_sysfs_setup();
|
||||||
|
#endif
|
||||||
//setup_remote_snooping_samples();
|
//setup_remote_snooping_samples();
|
||||||
} /* populate_sysfs() */
|
} /* populate_sysfs() */
|
||||||
|
|
||||||
@@ -336,11 +368,8 @@ static void post_init(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (find_command_line("hidos")) {
|
if (find_command_line("hidos")) {
|
||||||
extern ihk_spinlock_t syscall_lock;
|
|
||||||
|
|
||||||
init_host_syscall_channel();
|
init_host_syscall_channel();
|
||||||
init_host_syscall_channel2();
|
init_host_syscall_channel2();
|
||||||
ihk_mc_spinlock_init(&syscall_lock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
arch_setup_vdso();
|
arch_setup_vdso();
|
||||||
@@ -364,6 +393,21 @@ int main(void)
|
|||||||
char *ptr;
|
char *ptr;
|
||||||
int mode = 0;
|
int mode = 0;
|
||||||
|
|
||||||
|
#ifdef ENABLE_RUSAGE
|
||||||
|
int i;
|
||||||
|
os_status = IHK_STATUS_INACTIVE;
|
||||||
|
rusage_hugetlb_usage = 0;
|
||||||
|
rusage_hugetlb_max_usage = 0;
|
||||||
|
for (i = 0; i < sizeof(cpu_set_t)/8; i++) {
|
||||||
|
rusage_rss[i] = 0;
|
||||||
|
}
|
||||||
|
for (i = 0; i < 1024; i++) {
|
||||||
|
rusage_numa_stat[i] = 0;
|
||||||
|
}
|
||||||
|
rusage_rss_current = 0;
|
||||||
|
rusage_rss_max = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
ptr = find_command_line("ksyslogd=");
|
ptr = find_command_line("ksyslogd=");
|
||||||
if (ptr) {
|
if (ptr) {
|
||||||
mode = ptr[9] - 0x30;
|
mode = ptr[9] - 0x30;
|
||||||
@@ -372,7 +416,9 @@ int main(void)
|
|||||||
kmsg_init(mode);
|
kmsg_init(mode);
|
||||||
|
|
||||||
kputs("IHK/McKernel started.\n");
|
kputs("IHK/McKernel started.\n");
|
||||||
|
#ifdef ENABLE_RUSAGE
|
||||||
|
os_status = IHK_STATUS_BOOTING;
|
||||||
|
#endif
|
||||||
ihk_set_kmsg(virt_to_phys(&kmsg_buf), IHK_KMSG_SIZE);
|
ihk_set_kmsg(virt_to_phys(&kmsg_buf), IHK_KMSG_SIZE);
|
||||||
arch_init();
|
arch_init();
|
||||||
|
|
||||||
@@ -395,6 +441,9 @@ int main(void)
|
|||||||
futex_init();
|
futex_init();
|
||||||
|
|
||||||
kputs("IHK/McKernel booted.\n");
|
kputs("IHK/McKernel booted.\n");
|
||||||
|
#ifdef ENABLE_RUSAGE
|
||||||
|
os_status = IHK_STATUS_RUNNING;
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef DCFA_KMOD
|
#ifdef DCFA_KMOD
|
||||||
mc_cmd_client_init();
|
mc_cmd_client_init();
|
||||||
|
|||||||
134
kernel/mem.c
134
kernel/mem.c
@@ -37,6 +37,7 @@
|
|||||||
#include <cpulocal.h>
|
#include <cpulocal.h>
|
||||||
#include <init.h>
|
#include <init.h>
|
||||||
#include <cas.h>
|
#include <cas.h>
|
||||||
|
#include <rusage.h>
|
||||||
|
|
||||||
//#define DEBUG_PRINT_MEM
|
//#define DEBUG_PRINT_MEM
|
||||||
|
|
||||||
@@ -49,7 +50,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
static unsigned long pa_start, pa_end;
|
static unsigned long pa_start, pa_end;
|
||||||
static struct ihk_mc_numa_node *memory_nodes = NULL;
|
static struct ihk_mc_numa_node memory_nodes[512];
|
||||||
|
|
||||||
extern void unhandled_page_fault(struct thread *, void *, void *);
|
extern void unhandled_page_fault(struct thread *, void *, void *);
|
||||||
extern int interrupt_from_user(void *);
|
extern int interrupt_from_user(void *);
|
||||||
@@ -65,12 +66,12 @@ extern void early_alloc_invalidate(void);
|
|||||||
|
|
||||||
static char *memdebug = NULL;
|
static char *memdebug = NULL;
|
||||||
|
|
||||||
static void *___kmalloc(int size, enum ihk_mc_ap_flag flag);
|
static void *___kmalloc(int size, ihk_mc_ap_flag flag);
|
||||||
static void ___kfree(void *ptr);
|
static void ___kfree(void *ptr);
|
||||||
|
|
||||||
static void *___ihk_mc_alloc_aligned_pages(int npages,
|
static void *___ihk_mc_alloc_aligned_pages_node(int npages,
|
||||||
int p2align, enum ihk_mc_ap_flag flag);
|
int p2align, ihk_mc_ap_flag flag, int node);
|
||||||
static void *___ihk_mc_alloc_pages(int npages, enum ihk_mc_ap_flag flag);
|
static void *___ihk_mc_alloc_pages(int npages, ihk_mc_ap_flag flag);
|
||||||
static void ___ihk_mc_free_pages(void *p, int npages);
|
static void ___ihk_mc_free_pages(void *p, int npages);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -151,14 +152,15 @@ struct pagealloc_track_entry *__pagealloc_track_find_entry(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Top level routines called from macros */
|
/* Top level routines called from macros */
|
||||||
void *_ihk_mc_alloc_aligned_pages(int npages, int p2align,
|
void *_ihk_mc_alloc_aligned_pages_node(int npages, int p2align,
|
||||||
enum ihk_mc_ap_flag flag, char *file, int line)
|
ihk_mc_ap_flag flag, int node, char *file, int line)
|
||||||
{
|
{
|
||||||
unsigned long irqflags;
|
unsigned long irqflags;
|
||||||
struct pagealloc_track_entry *entry;
|
struct pagealloc_track_entry *entry;
|
||||||
struct pagealloc_track_addr_entry *addr_entry;
|
struct pagealloc_track_addr_entry *addr_entry;
|
||||||
int hash, addr_hash;
|
int hash, addr_hash;
|
||||||
void *r = ___ihk_mc_alloc_aligned_pages(npages, p2align, flag);
|
void *r = ___ihk_mc_alloc_aligned_pages_node(npages,
|
||||||
|
p2align, flag, node);
|
||||||
|
|
||||||
if (!memdebug || !pagealloc_track_initialized)
|
if (!memdebug || !pagealloc_track_initialized)
|
||||||
return r;
|
return r;
|
||||||
@@ -230,12 +232,6 @@ out:
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *_ihk_mc_alloc_pages(int npages, enum ihk_mc_ap_flag flag,
|
|
||||||
char *file, int line)
|
|
||||||
{
|
|
||||||
return _ihk_mc_alloc_aligned_pages(npages, PAGE_P2ALIGN, flag, file, line);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _ihk_mc_free_pages(void *ptr, int npages, char *file, int line)
|
void _ihk_mc_free_pages(void *ptr, int npages, char *file, int line)
|
||||||
{
|
{
|
||||||
unsigned long irqflags;
|
unsigned long irqflags;
|
||||||
@@ -449,18 +445,18 @@ void pagealloc_memcheck(void)
|
|||||||
|
|
||||||
|
|
||||||
/* Actual allocation routines */
|
/* Actual allocation routines */
|
||||||
static void *___ihk_mc_alloc_aligned_pages(int npages, int p2align,
|
static void *___ihk_mc_alloc_aligned_pages_node(int npages, int p2align,
|
||||||
enum ihk_mc_ap_flag flag)
|
ihk_mc_ap_flag flag, int node)
|
||||||
{
|
{
|
||||||
if (pa_ops)
|
if (pa_ops)
|
||||||
return pa_ops->alloc_page(npages, p2align, flag);
|
return pa_ops->alloc_page(npages, p2align, flag, node);
|
||||||
else
|
else
|
||||||
return early_alloc_pages(npages);
|
return early_alloc_pages(npages);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *___ihk_mc_alloc_pages(int npages, enum ihk_mc_ap_flag flag)
|
static void *___ihk_mc_alloc_pages(int npages, ihk_mc_ap_flag flag)
|
||||||
{
|
{
|
||||||
return ___ihk_mc_alloc_aligned_pages(npages, PAGE_P2ALIGN, flag);
|
return ___ihk_mc_alloc_aligned_pages_node(npages, PAGE_P2ALIGN, flag, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ___ihk_mc_free_pages(void *p, int npages)
|
static void ___ihk_mc_free_pages(void *p, int npages)
|
||||||
@@ -495,8 +491,8 @@ static void reserve_pages(struct ihk_page_allocator_desc *pa_allocator,
|
|||||||
}
|
}
|
||||||
|
|
||||||
extern int cpu_local_var_initialized;
|
extern int cpu_local_var_initialized;
|
||||||
static void *allocate_aligned_pages(int npages, int p2align,
|
static void *mckernel_allocate_aligned_pages_node(int npages, int p2align,
|
||||||
enum ihk_mc_ap_flag flag)
|
ihk_mc_ap_flag flag, int pref_node)
|
||||||
{
|
{
|
||||||
unsigned long pa = 0;
|
unsigned long pa = 0;
|
||||||
int i, node;
|
int i, node;
|
||||||
@@ -509,15 +505,31 @@ static void *allocate_aligned_pages(int npages, int p2align,
|
|||||||
goto distance_based;
|
goto distance_based;
|
||||||
|
|
||||||
/* User requested policy? */
|
/* User requested policy? */
|
||||||
|
if (!(flag & IHK_MC_AP_USER)) {
|
||||||
|
goto distance_based;
|
||||||
|
}
|
||||||
|
|
||||||
|
node = ihk_mc_get_numa_id();
|
||||||
|
if (!memory_nodes[node].nodes_by_distance)
|
||||||
|
goto order_based;
|
||||||
|
|
||||||
switch (cpu_local_var(current)->vm->numa_mem_policy) {
|
switch (cpu_local_var(current)->vm->numa_mem_policy) {
|
||||||
case MPOL_BIND:
|
case MPOL_BIND:
|
||||||
case MPOL_PREFERRED:
|
case MPOL_PREFERRED:
|
||||||
for_each_set_bit(node,
|
|
||||||
cpu_local_var(current)->proc->vm->numa_mask,
|
/* Look at nodes in the order of distance but consider
|
||||||
ihk_mc_get_nr_numa_nodes()) {
|
* only the ones requested in user policy */
|
||||||
|
for (i = 0; i < ihk_mc_get_nr_numa_nodes(); ++i) {
|
||||||
|
|
||||||
|
/* Not part of user requested policy? */
|
||||||
|
if (!test_bit(memory_nodes[node].nodes_by_distance[i].id,
|
||||||
|
cpu_local_var(current)->proc->vm->numa_mask)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
list_for_each_entry(pa_allocator,
|
list_for_each_entry(pa_allocator,
|
||||||
&memory_nodes[node].allocators, list) {
|
&memory_nodes[memory_nodes[node].
|
||||||
|
nodes_by_distance[i].id].allocators, list) {
|
||||||
pa = ihk_pagealloc_alloc(pa_allocator, npages, p2align);
|
pa = ihk_pagealloc_alloc(pa_allocator, npages, p2align);
|
||||||
|
|
||||||
if (pa) {
|
if (pa) {
|
||||||
@@ -526,6 +538,9 @@ static void *allocate_aligned_pages(int npages, int p2align,
|
|||||||
__FUNCTION__,
|
__FUNCTION__,
|
||||||
ihk_mc_get_numa_id(),
|
ihk_mc_get_numa_id(),
|
||||||
npages, node);
|
npages, node);
|
||||||
|
#ifdef ENABLE_RUSAGE
|
||||||
|
rusage_numa_stat[ihk_mc_get_numa_id()] += npages * PAGE_SIZE;
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -542,8 +557,13 @@ static void *allocate_aligned_pages(int npages, int p2align,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pa)
|
if (pa) {
|
||||||
return phys_to_virt(pa);
|
return phys_to_virt(pa);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
dkprintf("%s: couldn't fulfill user policy for %d pages\n",
|
||||||
|
__FUNCTION__, npages);
|
||||||
|
}
|
||||||
|
|
||||||
distance_based:
|
distance_based:
|
||||||
node = ihk_mc_get_numa_id();
|
node = ihk_mc_get_numa_id();
|
||||||
@@ -566,6 +586,9 @@ distance_based:
|
|||||||
ihk_mc_get_numa_id(),
|
ihk_mc_get_numa_id(),
|
||||||
npages,
|
npages,
|
||||||
memory_nodes[node].nodes_by_distance[i].id);
|
memory_nodes[node].nodes_by_distance[i].id);
|
||||||
|
#ifdef ENABLE_RUSAGE
|
||||||
|
rusage_numa_stat[ihk_mc_get_numa_id()] += npages * PAGE_SIZE;
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -586,7 +609,9 @@ order_based:
|
|||||||
&memory_nodes[(node + i) %
|
&memory_nodes[(node + i) %
|
||||||
ihk_mc_get_nr_numa_nodes()].allocators, list) {
|
ihk_mc_get_nr_numa_nodes()].allocators, list) {
|
||||||
pa = ihk_pagealloc_alloc(pa_allocator, npages, p2align);
|
pa = ihk_pagealloc_alloc(pa_allocator, npages, p2align);
|
||||||
|
#ifdef ENABLE_RUSAGE
|
||||||
|
rusage_numa_stat[ihk_mc_get_numa_id()] += npages * PAGE_SIZE;
|
||||||
|
#endif
|
||||||
if (pa) break;
|
if (pa) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -602,12 +627,7 @@ order_based:
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *allocate_pages(int npages, enum ihk_mc_ap_flag flag)
|
static void __mckernel_free_pages_in_allocator(void *va, int npages)
|
||||||
{
|
|
||||||
return allocate_aligned_pages(npages, PAGE_P2ALIGN, flag);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void __free_pages_in_allocator(void *va, int npages)
|
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
unsigned long pa_start = virt_to_phys(va);
|
unsigned long pa_start = virt_to_phys(va);
|
||||||
@@ -623,6 +643,9 @@ static void __free_pages_in_allocator(void *va, int npages)
|
|||||||
if (pa_start >= pa_allocator->start &&
|
if (pa_start >= pa_allocator->start &&
|
||||||
pa_end <= pa_allocator->end) {
|
pa_end <= pa_allocator->end) {
|
||||||
ihk_pagealloc_free(pa_allocator, pa_start, npages);
|
ihk_pagealloc_free(pa_allocator, pa_start, npages);
|
||||||
|
#ifdef ENABLE_RUSAGE
|
||||||
|
rusage_numa_stat[i] -= npages * PAGE_SIZE;
|
||||||
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -630,7 +653,7 @@ static void __free_pages_in_allocator(void *va, int npages)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void free_pages(void *va, int npages)
|
static void mckernel_free_pages(void *va, int npages)
|
||||||
{
|
{
|
||||||
struct list_head *pendings = &cpu_local_var(pending_free_pages);
|
struct list_head *pendings = &cpu_local_var(pending_free_pages);
|
||||||
struct page *page;
|
struct page *page;
|
||||||
@@ -638,7 +661,8 @@ static void free_pages(void *va, int npages)
|
|||||||
page = phys_to_page(virt_to_phys(va));
|
page = phys_to_page(virt_to_phys(va));
|
||||||
if (page) {
|
if (page) {
|
||||||
if (page->mode != PM_NONE) {
|
if (page->mode != PM_NONE) {
|
||||||
panic("free_pages:not PM_NONE");
|
kprintf("%s: WARNING: page phys 0x%lx is not PM_NONE",
|
||||||
|
__FUNCTION__, page->phys);
|
||||||
}
|
}
|
||||||
if (pendings->next != NULL) {
|
if (pendings->next != NULL) {
|
||||||
page->mode = PM_PENDING_FREE;
|
page->mode = PM_PENDING_FREE;
|
||||||
@@ -648,7 +672,7 @@ static void free_pages(void *va, int npages)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
__free_pages_in_allocator(va, npages);
|
__mckernel_free_pages_in_allocator(va, npages);
|
||||||
}
|
}
|
||||||
|
|
||||||
void begin_free_pages_pending(void) {
|
void begin_free_pages_pending(void) {
|
||||||
@@ -677,7 +701,7 @@ void finish_free_pages_pending(void)
|
|||||||
}
|
}
|
||||||
page->mode = PM_NONE;
|
page->mode = PM_NONE;
|
||||||
list_del(&page->list);
|
list_del(&page->list);
|
||||||
__free_pages_in_allocator(phys_to_virt(page_to_phys(page)),
|
__mckernel_free_pages_in_allocator(phys_to_virt(page_to_phys(page)),
|
||||||
page->offset);
|
page->offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -686,8 +710,8 @@ void finish_free_pages_pending(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static struct ihk_mc_pa_ops allocator = {
|
static struct ihk_mc_pa_ops allocator = {
|
||||||
.alloc_page = allocate_aligned_pages,
|
.alloc_page = mckernel_allocate_aligned_pages_node,
|
||||||
.free_page = free_pages,
|
.free_page = mckernel_free_pages,
|
||||||
};
|
};
|
||||||
|
|
||||||
void sbox_write(int offset, unsigned int value);
|
void sbox_write(int offset, unsigned int value);
|
||||||
@@ -948,12 +972,14 @@ out:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static struct ihk_page_allocator_desc *page_allocator_init(uint64_t start,
|
static struct ihk_page_allocator_desc *page_allocator_init(uint64_t start,
|
||||||
uint64_t end, int initial)
|
uint64_t end)
|
||||||
{
|
{
|
||||||
struct ihk_page_allocator_desc *pa_allocator;
|
struct ihk_page_allocator_desc *pa_allocator;
|
||||||
unsigned long page_map_pa, pages;
|
unsigned long page_map_pa, pages;
|
||||||
void *page_map;
|
void *page_map;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
extern char _end[];
|
||||||
|
unsigned long phys_end = virt_to_phys(_end);
|
||||||
|
|
||||||
start &= PAGE_MASK;
|
start &= PAGE_MASK;
|
||||||
pa_start = (start + PAGE_SIZE - 1) & PAGE_MASK;
|
pa_start = (start + PAGE_SIZE - 1) & PAGE_MASK;
|
||||||
@@ -966,7 +992,12 @@ static struct ihk_page_allocator_desc *page_allocator_init(uint64_t start,
|
|||||||
*/
|
*/
|
||||||
page_map_pa = 0x100000;
|
page_map_pa = 0x100000;
|
||||||
#else
|
#else
|
||||||
page_map_pa = initial ? virt_to_phys(get_last_early_heap()) : pa_start;
|
if (pa_start <= phys_end && phys_end <= pa_end) {
|
||||||
|
page_map_pa = virt_to_phys(get_last_early_heap());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
page_map_pa = pa_start;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
page_map = phys_to_virt(page_map_pa);
|
page_map = phys_to_virt(page_map_pa);
|
||||||
@@ -997,14 +1028,16 @@ static struct ihk_page_allocator_desc *page_allocator_init(uint64_t start,
|
|||||||
static void numa_init(void)
|
static void numa_init(void)
|
||||||
{
|
{
|
||||||
int i, j;
|
int i, j;
|
||||||
memory_nodes = early_alloc_pages((sizeof(*memory_nodes) *
|
|
||||||
ihk_mc_get_nr_numa_nodes() + PAGE_SIZE - 1)
|
|
||||||
>> PAGE_SHIFT);
|
|
||||||
|
|
||||||
for (i = 0; i < ihk_mc_get_nr_numa_nodes(); ++i) {
|
for (i = 0; i < ihk_mc_get_nr_numa_nodes(); ++i) {
|
||||||
int linux_numa_id, type;
|
int linux_numa_id, type;
|
||||||
|
|
||||||
ihk_mc_get_numa_node(i, &linux_numa_id, &type);
|
if (ihk_mc_get_numa_node(i, &linux_numa_id, &type) != 0) {
|
||||||
|
kprintf("%s: error: obtaining NUMA info for node %d\n",
|
||||||
|
__FUNCTION__, i);
|
||||||
|
panic("");
|
||||||
|
}
|
||||||
|
|
||||||
memory_nodes[i].id = i;
|
memory_nodes[i].id = i;
|
||||||
memory_nodes[i].linux_numa_id = linux_numa_id;
|
memory_nodes[i].linux_numa_id = linux_numa_id;
|
||||||
memory_nodes[i].type = type;
|
memory_nodes[i].type = type;
|
||||||
@@ -1022,7 +1055,7 @@ static void numa_init(void)
|
|||||||
|
|
||||||
ihk_mc_get_memory_chunk(j, &start, &end, &numa_id);
|
ihk_mc_get_memory_chunk(j, &start, &end, &numa_id);
|
||||||
|
|
||||||
allocator = page_allocator_init(start, end, (j == 0));
|
allocator = page_allocator_init(start, end);
|
||||||
list_add_tail(&allocator->list, &memory_nodes[numa_id].allocators);
|
list_add_tail(&allocator->list, &memory_nodes[numa_id].allocators);
|
||||||
|
|
||||||
kprintf("Physical memory: 0x%lx - 0x%lx, %lu bytes, %d pages available @ NUMA: %d\n",
|
kprintf("Physical memory: 0x%lx - 0x%lx, %lu bytes, %d pages available @ NUMA: %d\n",
|
||||||
@@ -1030,6 +1063,9 @@ static void numa_init(void)
|
|||||||
ihk_pagealloc_count(allocator) * PAGE_SIZE,
|
ihk_pagealloc_count(allocator) * PAGE_SIZE,
|
||||||
ihk_pagealloc_count(allocator),
|
ihk_pagealloc_count(allocator),
|
||||||
numa_id);
|
numa_id);
|
||||||
|
#ifdef ENABLE_RUSAGE
|
||||||
|
rusage_max_memory = ihk_pagealloc_count(allocator) * PAGE_SIZE;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1472,7 +1508,7 @@ struct kmalloc_track_entry *__kmalloc_track_find_entry(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Top level routines called from macro */
|
/* Top level routines called from macro */
|
||||||
void *_kmalloc(int size, enum ihk_mc_ap_flag flag, char *file, int line)
|
void *_kmalloc(int size, ihk_mc_ap_flag flag, char *file, int line)
|
||||||
{
|
{
|
||||||
unsigned long irqflags;
|
unsigned long irqflags;
|
||||||
struct kmalloc_track_entry *entry;
|
struct kmalloc_track_entry *entry;
|
||||||
@@ -1662,7 +1698,7 @@ void kmalloc_memcheck(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Redirection routines registered in alloc structure */
|
/* Redirection routines registered in alloc structure */
|
||||||
void *__kmalloc(int size, enum ihk_mc_ap_flag flag)
|
void *__kmalloc(int size, ihk_mc_ap_flag flag)
|
||||||
{
|
{
|
||||||
return kmalloc(size, flag);
|
return kmalloc(size, flag);
|
||||||
}
|
}
|
||||||
@@ -1760,7 +1796,7 @@ void kmalloc_consolidate_free_list(void)
|
|||||||
#define KMALLOC_MIN_MASK (KMALLOC_MIN_SIZE - 1)
|
#define KMALLOC_MIN_MASK (KMALLOC_MIN_SIZE - 1)
|
||||||
|
|
||||||
/* Actual low-level allocation routines */
|
/* Actual low-level allocation routines */
|
||||||
static void *___kmalloc(int size, enum ihk_mc_ap_flag flag)
|
static void *___kmalloc(int size, ihk_mc_ap_flag flag)
|
||||||
{
|
{
|
||||||
struct kmalloc_header *chunk_iter;
|
struct kmalloc_header *chunk_iter;
|
||||||
struct kmalloc_header *chunk = NULL;
|
struct kmalloc_header *chunk = NULL;
|
||||||
|
|||||||
380
kernel/process.c
380
kernel/process.c
@@ -31,6 +31,8 @@
|
|||||||
#include <auxvec.h>
|
#include <auxvec.h>
|
||||||
#include <timer.h>
|
#include <timer.h>
|
||||||
#include <mman.h>
|
#include <mman.h>
|
||||||
|
#include <xpmem.h>
|
||||||
|
#include <rusage.h>
|
||||||
|
|
||||||
//#define DEBUG_PRINT_PROCESS
|
//#define DEBUG_PRINT_PROCESS
|
||||||
|
|
||||||
@@ -65,6 +67,7 @@ extern void procfs_create_thread(struct thread *);
|
|||||||
extern void procfs_delete_thread(struct thread *);
|
extern void procfs_delete_thread(struct thread *);
|
||||||
extern void perf_start(struct mc_perf_event *event);
|
extern void perf_start(struct mc_perf_event *event);
|
||||||
extern void perf_reset(struct mc_perf_event *event);
|
extern void perf_reset(struct mc_perf_event *event);
|
||||||
|
extern void event_signal();
|
||||||
|
|
||||||
struct list_head resource_set_list;
|
struct list_head resource_set_list;
|
||||||
mcs_rwlock_lock_t resource_set_lock;
|
mcs_rwlock_lock_t resource_set_lock;
|
||||||
@@ -101,6 +104,13 @@ init_process(struct process *proc, struct process *parent)
|
|||||||
waitq_init(&proc->waitpid_q);
|
waitq_init(&proc->waitpid_q);
|
||||||
ihk_atomic_set(&proc->refcount, 2);
|
ihk_atomic_set(&proc->refcount, 2);
|
||||||
proc->monitoring_event = NULL;
|
proc->monitoring_event = NULL;
|
||||||
|
#ifdef TRACK_SYSCALLS
|
||||||
|
mcs_lock_init(&proc->st_lock);
|
||||||
|
proc->syscall_times = NULL;
|
||||||
|
proc->syscall_cnts = NULL;
|
||||||
|
proc->offload_times = NULL;
|
||||||
|
proc->offload_cnts = NULL;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -321,7 +331,25 @@ struct thread *create_thread(unsigned long user_pc,
|
|||||||
|
|
||||||
ihk_mc_spinlock_init(&thread->spin_sleep_lock);
|
ihk_mc_spinlock_init(&thread->spin_sleep_lock);
|
||||||
thread->spin_sleep = 0;
|
thread->spin_sleep = 0;
|
||||||
|
#ifdef ENABLE_RUSAGE
|
||||||
|
{
|
||||||
|
int processor_id;
|
||||||
|
unsigned long curr;
|
||||||
|
processor_id = ihk_mc_get_processor_id();
|
||||||
|
rusage_rss[processor_id] += KERNEL_STACK_NR_PAGES * PAGE_SIZE;
|
||||||
|
curr = ihk_atomic_add_long_return ( KERNEL_STACK_NR_PAGES * PAGE_SIZE, &rusage_rss_current);
|
||||||
|
if (rusage_rss_max < curr) {
|
||||||
|
atomic_cmpxchg8(&rusage_rss_max, rusage_rss_max, curr);
|
||||||
|
}
|
||||||
|
if (rusage_max_memory - curr < RUSAGE_MEM_LIMIT) {
|
||||||
|
event_signal();
|
||||||
|
}
|
||||||
|
ihk_atomic_add_ulong ( 1, &rusage_num_threads);
|
||||||
|
if (rusage_max_num_threads < rusage_num_threads) {
|
||||||
|
atomic_cmpxchg8(&rusage_max_num_threads, rusage_max_num_threads, rusage_num_threads);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
return thread;
|
return thread;
|
||||||
|
|
||||||
err:
|
err:
|
||||||
@@ -469,6 +497,32 @@ clone_thread(struct thread *org, unsigned long pc, unsigned long sp,
|
|||||||
ihk_mc_spinlock_init(&thread->spin_sleep_lock);
|
ihk_mc_spinlock_init(&thread->spin_sleep_lock);
|
||||||
thread->spin_sleep = 0;
|
thread->spin_sleep = 0;
|
||||||
|
|
||||||
|
#ifdef ENABLE_RUSAGE
|
||||||
|
{
|
||||||
|
int processor_id;
|
||||||
|
long curr;
|
||||||
|
processor_id = ihk_mc_get_processor_id();
|
||||||
|
rusage_rss[processor_id] += KERNEL_STACK_NR_PAGES * PAGE_SIZE;
|
||||||
|
curr = ihk_atomic_add_long_return (KERNEL_STACK_NR_PAGES * PAGE_SIZE, &rusage_rss_current);
|
||||||
|
if (rusage_rss_max < curr) {
|
||||||
|
atomic_cmpxchg8(&rusage_rss_max, rusage_rss_max, curr);
|
||||||
|
}
|
||||||
|
if (rusage_max_memory - curr < RUSAGE_MEM_LIMIT) {
|
||||||
|
event_signal();
|
||||||
|
}
|
||||||
|
|
||||||
|
ihk_atomic_add_ulong ( 1, &rusage_num_threads);
|
||||||
|
|
||||||
|
if (rusage_max_num_threads < rusage_num_threads) {
|
||||||
|
atomic_cmpxchg8(&rusage_max_num_threads, rusage_max_num_threads, rusage_num_threads);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef TRACK_SYSCALLS
|
||||||
|
thread->track_syscalls = org->track_syscalls;
|
||||||
|
#endif
|
||||||
|
|
||||||
return thread;
|
return thread;
|
||||||
|
|
||||||
err_free_proc:
|
err_free_proc:
|
||||||
@@ -627,6 +681,7 @@ static int copy_user_ranges(struct process_vm *vm, struct process_vm *orgvm)
|
|||||||
range->memobj = src_range->memobj;
|
range->memobj = src_range->memobj;
|
||||||
range->objoff = src_range->objoff;
|
range->objoff = src_range->objoff;
|
||||||
range->pgshift = src_range->pgshift;
|
range->pgshift = src_range->pgshift;
|
||||||
|
range->private_data = src_range->private_data;
|
||||||
if (range->memobj) {
|
if (range->memobj) {
|
||||||
memobj_ref(range->memobj);
|
memobj_ref(range->memobj);
|
||||||
}
|
}
|
||||||
@@ -724,6 +779,7 @@ int split_process_memory_range(struct process_vm *vm, struct vm_range *range,
|
|||||||
newrange->end = range->end;
|
newrange->end = range->end;
|
||||||
newrange->flag = range->flag;
|
newrange->flag = range->flag;
|
||||||
newrange->pgshift = range->pgshift;
|
newrange->pgshift = range->pgshift;
|
||||||
|
newrange->private_data = range->private_data;
|
||||||
|
|
||||||
if (range->memobj) {
|
if (range->memobj) {
|
||||||
memobj_ref(range->memobj);
|
memobj_ref(range->memobj);
|
||||||
@@ -943,6 +999,10 @@ int remove_process_memory_range(struct process_vm *vm,
|
|||||||
ro_freed = 1;
|
ro_freed = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (freerange->private_data) {
|
||||||
|
xpmem_remove_process_memory_range(vm, freerange);
|
||||||
|
}
|
||||||
|
|
||||||
error = free_process_memory_range(vm, freerange);
|
error = free_process_memory_range(vm, freerange);
|
||||||
if (error) {
|
if (error) {
|
||||||
ekprintf("remove_process_memory_range(%p,%lx,%lx):"
|
ekprintf("remove_process_memory_range(%p,%lx,%lx):"
|
||||||
@@ -1018,21 +1078,18 @@ enum ihk_mc_pt_attribute common_vrflag_to_ptattr(unsigned long flag, uint64_t fa
|
|||||||
}
|
}
|
||||||
|
|
||||||
int add_process_memory_range(struct process_vm *vm,
|
int add_process_memory_range(struct process_vm *vm,
|
||||||
unsigned long start, unsigned long end,
|
unsigned long start, unsigned long end,
|
||||||
unsigned long phys, unsigned long flag,
|
unsigned long phys, unsigned long flag,
|
||||||
struct memobj *memobj, off_t offset,
|
struct memobj *memobj, off_t offset,
|
||||||
int pgshift)
|
int pgshift, struct vm_range **rp)
|
||||||
{
|
{
|
||||||
struct vm_range *range;
|
struct vm_range *range;
|
||||||
int rc;
|
int rc;
|
||||||
#if 0
|
|
||||||
extern void __host_update_process_range(struct thread *process,
|
|
||||||
struct vm_range *range);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if ((start < vm->region.user_start)
|
if ((start < vm->region.user_start)
|
||||||
|| (vm->region.user_end < end)) {
|
|| (vm->region.user_end < end)) {
|
||||||
kprintf("range(%#lx - %#lx) is not in user avail(%#lx - %#lx)\n",
|
kprintf("%s: error: range %lx - %lx is not in user available area\n",
|
||||||
|
__FUNCTION__,
|
||||||
start, end, vm->region.user_start,
|
start, end, vm->region.user_start,
|
||||||
vm->region.user_end);
|
vm->region.user_end);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
@@ -1040,9 +1097,10 @@ int add_process_memory_range(struct process_vm *vm,
|
|||||||
|
|
||||||
range = kmalloc(sizeof(struct vm_range), IHK_MC_AP_NOWAIT);
|
range = kmalloc(sizeof(struct vm_range), IHK_MC_AP_NOWAIT);
|
||||||
if (!range) {
|
if (!range) {
|
||||||
kprintf("ERROR: allocating pages for range\n");
|
kprintf("%s: ERROR: allocating pages for range\n", __FUNCTION__);
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
INIT_LIST_HEAD(&range->list);
|
INIT_LIST_HEAD(&range->list);
|
||||||
range->start = start;
|
range->start = start;
|
||||||
range->end = end;
|
range->end = end;
|
||||||
@@ -1050,49 +1108,36 @@ int add_process_memory_range(struct process_vm *vm,
|
|||||||
range->memobj = memobj;
|
range->memobj = memobj;
|
||||||
range->objoff = offset;
|
range->objoff = offset;
|
||||||
range->pgshift = pgshift;
|
range->pgshift = pgshift;
|
||||||
|
range->private_data = NULL;
|
||||||
|
|
||||||
if(range->flag & VR_DEMAND_PAGING) {
|
rc = 0;
|
||||||
dkprintf("range: 0x%lX - 0x%lX => physicall memory area is allocated on demand (%ld) [%lx]\n",
|
if (phys == NOPHYS) {
|
||||||
range->start, range->end, range->end - range->start,
|
/* Nothing to map */
|
||||||
range->flag);
|
}
|
||||||
} else {
|
else if (flag & VR_REMOTE) {
|
||||||
dkprintf("range: 0x%lX - 0x%lX (%ld) [%lx]\n",
|
|
||||||
range->start, range->end, range->end - range->start,
|
|
||||||
range->flag);
|
|
||||||
}
|
|
||||||
|
|
||||||
rc = 0;
|
|
||||||
if (0) {
|
|
||||||
/* dummy */
|
|
||||||
}
|
|
||||||
else if (phys == NOPHYS) {
|
|
||||||
/* nothing to map */
|
|
||||||
}
|
|
||||||
else if (flag & VR_REMOTE) {
|
|
||||||
rc = update_process_page_table(vm, range, phys, IHK_PTA_REMOTE);
|
rc = update_process_page_table(vm, range, phys, IHK_PTA_REMOTE);
|
||||||
} else if (flag & VR_IO_NOCACHE) {
|
}
|
||||||
|
else if (flag & VR_IO_NOCACHE) {
|
||||||
rc = update_process_page_table(vm, range, phys, PTATTR_UNCACHABLE);
|
rc = update_process_page_table(vm, range, phys, PTATTR_UNCACHABLE);
|
||||||
} else if(flag & VR_DEMAND_PAGING){
|
}
|
||||||
//demand paging no need to update process table now
|
else if (flag & VR_DEMAND_PAGING) {
|
||||||
dkprintf("demand paging do not update process page table\n");
|
dkprintf("%s: range: 0x%lx - 0x%lx is demand paging\n",
|
||||||
rc = 0;
|
__FUNCTION__, range->start, range->end);
|
||||||
} else if ((range->flag & VR_PROT_MASK) == VR_PROT_NONE) {
|
|
||||||
rc = 0;
|
rc = 0;
|
||||||
} else {
|
}
|
||||||
|
else if ((range->flag & VR_PROT_MASK) == VR_PROT_NONE) {
|
||||||
|
rc = 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
rc = update_process_page_table(vm, range, phys, 0);
|
rc = update_process_page_table(vm, range, phys, 0);
|
||||||
}
|
}
|
||||||
if(rc != 0){
|
|
||||||
kprintf("ERROR: preparing page tables\n");
|
if (rc != 0) {
|
||||||
|
kprintf("%s: ERROR: preparing page tables\n", __FUNCTION__);
|
||||||
kfree(range);
|
kfree(range);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0 // disable __host_update_process_range() in add_process_memory_range(), because it has no effect on the actual mapping on the MICs side.
|
|
||||||
if (!(flag & VR_REMOTE)) {
|
|
||||||
__host_update_process_range(process, range);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
insert_vm_range_list(vm, range);
|
insert_vm_range_list(vm, range);
|
||||||
|
|
||||||
/* Clear content! */
|
/* Clear content! */
|
||||||
@@ -1101,6 +1146,11 @@ int add_process_memory_range(struct process_vm *vm,
|
|||||||
memset((void*)phys_to_virt(phys), 0, end - start);
|
memset((void*)phys_to_virt(phys), 0, end - start);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Return range object if requested */
|
||||||
|
if (rp) {
|
||||||
|
*rp = range;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1794,7 +1844,12 @@ static int do_page_fault_process_vm(struct process_vm *vm, void *fault_addr0, ui
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
error = page_fault_process_memory_range(vm, range, fault_addr, reason);
|
if (!range->private_data) {
|
||||||
|
error = page_fault_process_memory_range(vm, range, fault_addr, reason);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
error = xpmem_fault_process_memory_range(vm, range, fault_addr, reason);
|
||||||
|
}
|
||||||
if (error == -ERESTART) {
|
if (error == -ERESTART) {
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
@@ -1852,6 +1907,7 @@ int init_process_stack(struct thread *thread, struct program_load_desc *pn,
|
|||||||
unsigned long minsz;
|
unsigned long minsz;
|
||||||
unsigned long at_rand;
|
unsigned long at_rand;
|
||||||
struct process *proc = thread->proc;
|
struct process *proc = thread->proc;
|
||||||
|
unsigned long __flag;
|
||||||
|
|
||||||
/* create stack range */
|
/* create stack range */
|
||||||
end = STACK_TOP(&thread->vm->region);
|
end = STACK_TOP(&thread->vm->region);
|
||||||
@@ -1870,12 +1926,15 @@ int init_process_stack(struct thread *thread, struct program_load_desc *pn,
|
|||||||
vrflag |= VR_MAXPROT_READ | VR_MAXPROT_WRITE | VR_MAXPROT_EXEC;
|
vrflag |= VR_MAXPROT_READ | VR_MAXPROT_WRITE | VR_MAXPROT_EXEC;
|
||||||
#define NOPHYS ((uintptr_t)-1)
|
#define NOPHYS ((uintptr_t)-1)
|
||||||
if ((rc = add_process_memory_range(thread->vm, start, end, NOPHYS,
|
if ((rc = add_process_memory_range(thread->vm, start, end, NOPHYS,
|
||||||
vrflag, NULL, 0, PAGE_SHIFT)) != 0) {
|
vrflag, NULL, 0, PAGE_SHIFT, NULL)) != 0) {
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__flag = (size >= 16777216) ? IHK_MC_AP_USER : 0;
|
||||||
/* map physical pages for initial stack frame */
|
/* map physical pages for initial stack frame */
|
||||||
stack = ihk_mc_alloc_pages(minsz >> PAGE_SHIFT, IHK_MC_AP_NOWAIT);
|
stack = ihk_mc_alloc_pages(minsz >> PAGE_SHIFT,
|
||||||
|
IHK_MC_AP_NOWAIT | __flag);
|
||||||
|
|
||||||
if (!stack) {
|
if (!stack) {
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
@@ -1948,6 +2007,24 @@ int init_process_stack(struct thread *thread, struct program_load_desc *pn,
|
|||||||
end + sizeof(unsigned long) * s_ind);
|
end + sizeof(unsigned long) * s_ind);
|
||||||
thread->vm->region.stack_end = end;
|
thread->vm->region.stack_end = end;
|
||||||
thread->vm->region.stack_start = start;
|
thread->vm->region.stack_start = start;
|
||||||
|
|
||||||
|
#ifdef ENABLE_RUSAGE
|
||||||
|
{
|
||||||
|
int processor_id;
|
||||||
|
long curr;
|
||||||
|
|
||||||
|
processor_id = ihk_mc_get_processor_id();
|
||||||
|
rusage_rss[processor_id] += (minsz >> PAGE_SHIFT) * PAGE_SIZE;
|
||||||
|
curr = ihk_atomic_add_long_return ((minsz >> PAGE_SHIFT) * PAGE_SIZE, &rusage_rss_current);
|
||||||
|
if (rusage_rss_max < curr) {
|
||||||
|
atomic_cmpxchg8(&rusage_rss_max, rusage_rss_max, curr);
|
||||||
|
}
|
||||||
|
if (rusage_max_memory - curr < RUSAGE_MEM_LIMIT) {
|
||||||
|
event_signal();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1989,7 +2066,7 @@ unsigned long extend_process_region(struct process_vm *vm,
|
|||||||
}
|
}
|
||||||
if((rc = add_process_memory_range(vm, old_aligned_end,
|
if((rc = add_process_memory_range(vm, old_aligned_end,
|
||||||
aligned_end, virt_to_phys(p), flag,
|
aligned_end, virt_to_phys(p), flag,
|
||||||
LARGE_PAGE_SHIFT)) != 0){
|
LARGE_PAGE_SHIFT, NULL)) != 0){
|
||||||
ihk_mc_free_pages(p, (aligned_end - old_aligned_end) >> PAGE_SHIFT);
|
ihk_mc_free_pages(p, (aligned_end - old_aligned_end) >> PAGE_SHIFT);
|
||||||
return end;
|
return end;
|
||||||
}
|
}
|
||||||
@@ -2019,7 +2096,7 @@ unsigned long extend_process_region(struct process_vm *vm,
|
|||||||
|
|
||||||
if((rc = add_process_memory_range(vm, aligned_end,
|
if((rc = add_process_memory_range(vm, aligned_end,
|
||||||
aligned_new_end, virt_to_phys((void *)p_aligned),
|
aligned_new_end, virt_to_phys((void *)p_aligned),
|
||||||
flag, LARGE_PAGE_SHIFT)) != 0){
|
flag, LARGE_PAGE_SHIFT, NULL)) != 0){
|
||||||
ihk_mc_free_pages(p, (aligned_new_end - aligned_end + LARGE_PAGE_SIZE) >> PAGE_SHIFT);
|
ihk_mc_free_pages(p, (aligned_new_end - aligned_end + LARGE_PAGE_SIZE) >> PAGE_SHIFT);
|
||||||
return end;
|
return end;
|
||||||
}
|
}
|
||||||
@@ -2038,19 +2115,34 @@ unsigned long extend_process_region(struct process_vm *vm,
|
|||||||
p=0;
|
p=0;
|
||||||
}else{
|
}else{
|
||||||
|
|
||||||
p = ihk_mc_alloc_pages((aligned_new_end - aligned_end) >> PAGE_SHIFT, IHK_MC_AP_NOWAIT);
|
p = ihk_mc_alloc_pages((aligned_new_end - aligned_end) >> PAGE_SHIFT,
|
||||||
|
IHK_MC_AP_NOWAIT | IHK_MC_AP_USER);
|
||||||
|
|
||||||
if (!p) {
|
if (!p) {
|
||||||
return end;
|
return end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if((rc = add_process_memory_range(vm, aligned_end, aligned_new_end,
|
if ((rc = add_process_memory_range(vm, aligned_end, aligned_new_end,
|
||||||
(p==0?0:virt_to_phys(p)), flag, NULL, 0,
|
(p == 0 ? 0 : virt_to_phys(p)), flag, NULL, 0,
|
||||||
PAGE_SHIFT)) != 0){
|
PAGE_SHIFT, NULL)) != 0) {
|
||||||
ihk_mc_free_pages(p, (aligned_new_end - aligned_end) >> PAGE_SHIFT);
|
ihk_mc_free_pages(p, (aligned_new_end - aligned_end) >> PAGE_SHIFT);
|
||||||
return end;
|
return end;
|
||||||
}
|
}
|
||||||
|
#ifdef ENABLE_RUSAGE
|
||||||
|
{
|
||||||
|
int processor_id;
|
||||||
|
long curr;
|
||||||
|
processor_id = ihk_mc_get_processor_id();
|
||||||
|
rusage_rss[processor_id] += ((aligned_new_end - aligned_end) >> PAGE_SHIFT) * PAGE_SIZE;
|
||||||
|
curr = ihk_atomic_add_long_return (((aligned_new_end - aligned_end) >> PAGE_SHIFT) * PAGE_SIZE, &rusage_rss_current);
|
||||||
|
if (rusage_rss_max < curr) {
|
||||||
|
atomic_cmpxchg8(&rusage_rss_max, rusage_rss_max, curr);
|
||||||
|
}
|
||||||
|
if (rusage_max_memory - curr < RUSAGE_MEM_LIMIT) {
|
||||||
|
event_signal();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
return address;
|
return address;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2161,6 +2253,10 @@ release_process(struct process *proc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (proc->tids) kfree(proc->tids);
|
if (proc->tids) kfree(proc->tids);
|
||||||
|
#ifdef TRACK_SYSCALLS
|
||||||
|
track_syscalls_print_proc_stats(proc);
|
||||||
|
track_syscalls_dealloc_proc_counters(proc);
|
||||||
|
#endif // TRACK_SYSCALLS
|
||||||
kfree(proc);
|
kfree(proc);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2178,6 +2274,9 @@ free_all_process_memory_range(struct process_vm *vm)
|
|||||||
|
|
||||||
ihk_mc_spinlock_lock_noirq(&vm->memory_range_lock);
|
ihk_mc_spinlock_lock_noirq(&vm->memory_range_lock);
|
||||||
list_for_each_entry_safe(range, next, &vm->vm_range_list, list) {
|
list_for_each_entry_safe(range, next, &vm->vm_range_list, list) {
|
||||||
|
if (range->memobj) {
|
||||||
|
range->memobj->flags |= MF_HOST_RELEASED;
|
||||||
|
}
|
||||||
error = free_process_memory_range(vm, range);
|
error = free_process_memory_range(vm, range);
|
||||||
if (error) {
|
if (error) {
|
||||||
ekprintf("free_process_memory(%p):"
|
ekprintf("free_process_memory(%p):"
|
||||||
@@ -2198,6 +2297,19 @@ release_process_vm(struct process_vm *vm)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
long irqstate;
|
||||||
|
struct mckfd *fdp;
|
||||||
|
|
||||||
|
irqstate = ihk_mc_spinlock_lock(&proc->mckfd_lock);
|
||||||
|
for (fdp = proc->mckfd; fdp; fdp = fdp->next) {
|
||||||
|
if (fdp->close_cb) {
|
||||||
|
fdp->close_cb(fdp, NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ihk_mc_spinlock_unlock(&proc->mckfd_lock, irqstate);
|
||||||
|
}
|
||||||
|
|
||||||
if(vm->free_cb)
|
if(vm->free_cb)
|
||||||
vm->free_cb(vm, vm->opt);
|
vm->free_cb(vm, vm->opt);
|
||||||
|
|
||||||
@@ -2325,6 +2437,16 @@ void destroy_thread(struct thread *thread)
|
|||||||
|
|
||||||
release_sigcommon(thread->sigcommon);
|
release_sigcommon(thread->sigcommon);
|
||||||
|
|
||||||
|
#ifdef ENABLE_RUSAGE
|
||||||
|
{
|
||||||
|
int processor_id;
|
||||||
|
processor_id = ihk_mc_get_processor_id();
|
||||||
|
rusage_rss[processor_id] -= KERNEL_STACK_NR_PAGES * PAGE_SIZE;
|
||||||
|
ihk_atomic_add_long_return(KERNEL_STACK_NR_PAGES * PAGE_SIZE * (-1) , &rusage_rss_current);
|
||||||
|
ihk_atomic_add_ulong ( -1, &rusage_num_threads);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
ihk_mc_free_pages(thread, KERNEL_STACK_NR_PAGES);
|
ihk_mc_free_pages(thread, KERNEL_STACK_NR_PAGES);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2332,18 +2454,26 @@ void release_thread(struct thread *thread)
|
|||||||
{
|
{
|
||||||
struct process_vm *vm;
|
struct process_vm *vm;
|
||||||
struct mcs_rwlock_node lock;
|
struct mcs_rwlock_node lock;
|
||||||
|
struct timespec ats;
|
||||||
|
|
||||||
if (!ihk_atomic_dec_and_test(&thread->refcount)) {
|
if (!ihk_atomic_dec_and_test(&thread->refcount)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mcs_rwlock_writer_lock_noirq(&thread->proc->update_lock, &lock);
|
mcs_rwlock_writer_lock_noirq(&thread->proc->update_lock, &lock);
|
||||||
ts_add(&thread->proc->stime, &thread->stime);
|
tsc_to_ts(thread->system_tsc, &ats);
|
||||||
ts_add(&thread->proc->utime, &thread->utime);
|
ts_add(&thread->proc->stime, &ats);
|
||||||
|
tsc_to_ts(thread->user_tsc, &ats);
|
||||||
|
ts_add(&thread->proc->utime, &ats);
|
||||||
mcs_rwlock_writer_unlock_noirq(&thread->proc->update_lock, &lock);
|
mcs_rwlock_writer_unlock_noirq(&thread->proc->update_lock, &lock);
|
||||||
|
|
||||||
vm = thread->vm;
|
vm = thread->vm;
|
||||||
|
|
||||||
|
#ifdef TRACK_SYSCALLS
|
||||||
|
track_syscalls_accumulate_counters(thread, thread->proc);
|
||||||
|
//track_syscalls_print_thread_stats(thread);
|
||||||
|
track_syscalls_dealloc_thread_counters(thread);
|
||||||
|
#endif // TRACK_SYSCALLS
|
||||||
procfs_delete_thread(thread);
|
procfs_delete_thread(thread);
|
||||||
destroy_thread(thread);
|
destroy_thread(thread);
|
||||||
|
|
||||||
@@ -2352,7 +2482,7 @@ void release_thread(struct thread *thread)
|
|||||||
|
|
||||||
void cpu_set(int cpu, cpu_set_t *cpu_set, ihk_spinlock_t *lock)
|
void cpu_set(int cpu, cpu_set_t *cpu_set, ihk_spinlock_t *lock)
|
||||||
{
|
{
|
||||||
unsigned int flags;
|
unsigned long flags;
|
||||||
flags = ihk_mc_spinlock_lock(lock);
|
flags = ihk_mc_spinlock_lock(lock);
|
||||||
CPU_SET(cpu, cpu_set);
|
CPU_SET(cpu, cpu_set);
|
||||||
ihk_mc_spinlock_unlock(lock, flags);
|
ihk_mc_spinlock_unlock(lock, flags);
|
||||||
@@ -2360,7 +2490,7 @@ void cpu_set(int cpu, cpu_set_t *cpu_set, ihk_spinlock_t *lock)
|
|||||||
|
|
||||||
void cpu_clear(int cpu, cpu_set_t *cpu_set, ihk_spinlock_t *lock)
|
void cpu_clear(int cpu, cpu_set_t *cpu_set, ihk_spinlock_t *lock)
|
||||||
{
|
{
|
||||||
unsigned int flags;
|
unsigned long flags;
|
||||||
flags = ihk_mc_spinlock_lock(lock);
|
flags = ihk_mc_spinlock_lock(lock);
|
||||||
CPU_CLR(cpu, cpu_set);
|
CPU_CLR(cpu, cpu_set);
|
||||||
ihk_mc_spinlock_unlock(lock, flags);
|
ihk_mc_spinlock_unlock(lock, flags);
|
||||||
@@ -2369,7 +2499,7 @@ void cpu_clear(int cpu, cpu_set_t *cpu_set, ihk_spinlock_t *lock)
|
|||||||
void cpu_clear_and_set(int c_cpu, int s_cpu,
|
void cpu_clear_and_set(int c_cpu, int s_cpu,
|
||||||
cpu_set_t *cpu_set, ihk_spinlock_t *lock)
|
cpu_set_t *cpu_set, ihk_spinlock_t *lock)
|
||||||
{
|
{
|
||||||
unsigned int flags;
|
unsigned long flags;
|
||||||
flags = ihk_mc_spinlock_lock(lock);
|
flags = ihk_mc_spinlock_lock(lock);
|
||||||
CPU_CLR(c_cpu, cpu_set);
|
CPU_CLR(c_cpu, cpu_set);
|
||||||
CPU_SET(s_cpu, cpu_set);
|
CPU_SET(s_cpu, cpu_set);
|
||||||
@@ -2382,6 +2512,7 @@ static void do_migrate(void);
|
|||||||
static void idle(void)
|
static void idle(void)
|
||||||
{
|
{
|
||||||
struct cpu_local_var *v = get_this_cpu_local_var();
|
struct cpu_local_var *v = get_this_cpu_local_var();
|
||||||
|
struct ihk_os_monitor *monitor = v->monitor;
|
||||||
|
|
||||||
/* Release runq_lock before starting the idle loop.
|
/* Release runq_lock before starting the idle loop.
|
||||||
* See comments at release_runq_lock().
|
* See comments at release_runq_lock().
|
||||||
@@ -2394,7 +2525,9 @@ static void idle(void)
|
|||||||
cpu_enable_interrupt();
|
cpu_enable_interrupt();
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
cpu_local_var(current)->status = PS_STOPPED;
|
||||||
schedule();
|
schedule();
|
||||||
|
cpu_local_var(current)->status = PS_RUNNING;
|
||||||
cpu_disable_interrupt();
|
cpu_disable_interrupt();
|
||||||
|
|
||||||
/* See if we need to migrate a process somewhere */
|
/* See if we need to migrate a process somewhere */
|
||||||
@@ -2440,7 +2573,12 @@ static void idle(void)
|
|||||||
v->status == CPU_STATUS_RESERVED) {
|
v->status == CPU_STATUS_RESERVED) {
|
||||||
/* No work to do? Consolidate the kmalloc free list */
|
/* No work to do? Consolidate the kmalloc free list */
|
||||||
kmalloc_consolidate_free_list();
|
kmalloc_consolidate_free_list();
|
||||||
|
monitor->status = IHK_OS_MONITOR_IDLE;
|
||||||
|
cpu_local_var(current)->status = PS_INTERRUPTIBLE;
|
||||||
cpu_safe_halt();
|
cpu_safe_halt();
|
||||||
|
monitor->status = IHK_OS_MONITOR_KERNEL;
|
||||||
|
monitor->counter++;
|
||||||
|
cpu_local_var(current)->status = PS_RUNNING;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
cpu_enable_interrupt();
|
cpu_enable_interrupt();
|
||||||
@@ -2637,13 +2775,13 @@ static void do_migrate(void)
|
|||||||
&req->thread->vm->address_space->cpu_set,
|
&req->thread->vm->address_space->cpu_set,
|
||||||
&req->thread->vm->address_space->cpu_set_lock);
|
&req->thread->vm->address_space->cpu_set_lock);
|
||||||
|
|
||||||
dkprintf("do_migrate(): migrated TID %d from CPU %d to CPU %d\n",
|
dkprintf("%s: migrated TID %d from CPU %d to CPU %d\n",
|
||||||
req->thread->tid, old_cpu_id, cpu_id);
|
__FUNCTION__, req->thread->tid, old_cpu_id, cpu_id);
|
||||||
|
|
||||||
v->flags |= CPU_FLAG_NEED_RESCHED;
|
v->flags |= CPU_FLAG_NEED_RESCHED;
|
||||||
ihk_mc_interrupt_cpu(get_x86_cpu_local_variable(cpu_id)->apic_id, 0xd1);
|
waitq_wakeup(&req->wq);
|
||||||
double_rq_unlock(cur_v, v, irqstate);
|
double_rq_unlock(cur_v, v, irqstate);
|
||||||
|
continue;
|
||||||
ack:
|
ack:
|
||||||
waitq_wakeup(&req->wq);
|
waitq_wakeup(&req->wq);
|
||||||
}
|
}
|
||||||
@@ -2670,6 +2808,65 @@ set_timer()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* NOTE: it is assumed that a wait-queue (or futex queue) is
|
||||||
|
* set before calling this function.
|
||||||
|
* NOTE: one must set thread->spin_sleep to 1 before evaluating
|
||||||
|
* the wait condition to avoid lost wake-ups.
|
||||||
|
*/
|
||||||
|
void spin_sleep_or_schedule(void)
|
||||||
|
{
|
||||||
|
struct thread *thread = cpu_local_var(current);
|
||||||
|
struct cpu_local_var *v;
|
||||||
|
int do_schedule = 0;
|
||||||
|
int woken = 0;
|
||||||
|
long irqstate;
|
||||||
|
|
||||||
|
/* Try to spin sleep */
|
||||||
|
irqstate = ihk_mc_spinlock_lock(&thread->spin_sleep_lock);
|
||||||
|
if (thread->spin_sleep == 0) {
|
||||||
|
dkprintf("%s: caught a lost wake-up!\n", __FUNCTION__);
|
||||||
|
}
|
||||||
|
ihk_mc_spinlock_unlock(&thread->spin_sleep_lock, irqstate);
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
/* Check if we need to reschedule */
|
||||||
|
irqstate =
|
||||||
|
ihk_mc_spinlock_lock(&(get_this_cpu_local_var()->runq_lock));
|
||||||
|
v = get_this_cpu_local_var();
|
||||||
|
|
||||||
|
if (v->flags & CPU_FLAG_NEED_RESCHED || v->runq_len > 1) {
|
||||||
|
do_schedule = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ihk_mc_spinlock_unlock(&v->runq_lock, irqstate);
|
||||||
|
|
||||||
|
/* Check if we were woken up */
|
||||||
|
irqstate = ihk_mc_spinlock_lock(&thread->spin_sleep_lock);
|
||||||
|
if (thread->spin_sleep == 0) {
|
||||||
|
woken = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Indicate that we are not spinning any more */
|
||||||
|
if (do_schedule) {
|
||||||
|
thread->spin_sleep = 0;
|
||||||
|
}
|
||||||
|
ihk_mc_spinlock_unlock(&thread->spin_sleep_lock, irqstate);
|
||||||
|
|
||||||
|
if (woken) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (do_schedule) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
cpu_pause();
|
||||||
|
}
|
||||||
|
|
||||||
|
schedule();
|
||||||
|
}
|
||||||
|
|
||||||
void schedule(void)
|
void schedule(void)
|
||||||
{
|
{
|
||||||
struct cpu_local_var *v;
|
struct cpu_local_var *v;
|
||||||
@@ -2832,39 +3029,38 @@ void check_need_resched(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int __sched_wakeup_thread(struct thread *thread,
|
||||||
sched_wakeup_thread(struct thread *thread, int valid_states)
|
int valid_states, int runq_locked)
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
int spin_slept = 0;
|
|
||||||
unsigned long irqstate;
|
unsigned long irqstate;
|
||||||
struct cpu_local_var *v = get_cpu_local_var(thread->cpu_id);
|
struct cpu_local_var *v = get_cpu_local_var(thread->cpu_id);
|
||||||
struct process *proc = thread->proc;
|
struct process *proc = thread->proc;
|
||||||
struct mcs_rwlock_node updatelock;
|
struct mcs_rwlock_node updatelock;
|
||||||
|
|
||||||
dkprintf("sched_wakeup_process,proc->pid=%d,valid_states=%08x,proc->status=%08x,proc->cpu_id=%d,my cpu_id=%d\n",
|
dkprintf("%s: proc->pid=%d, valid_states=%08x, "
|
||||||
proc->pid, valid_states, thread->status, thread->cpu_id, ihk_mc_get_processor_id());
|
"proc->status=%08x, proc->cpu_id=%d,my cpu_id=%d\n",
|
||||||
|
__FUNCTION__,
|
||||||
|
proc->pid, valid_states, thread->status,
|
||||||
|
thread->cpu_id, ihk_mc_get_processor_id());
|
||||||
|
|
||||||
irqstate = ihk_mc_spinlock_lock(&(thread->spin_sleep_lock));
|
irqstate = ihk_mc_spinlock_lock(&(thread->spin_sleep_lock));
|
||||||
if (thread->spin_sleep > 0) {
|
if (thread->spin_sleep == 1) {
|
||||||
dkprintf("sched_wakeup_process() spin wakeup: cpu_id: %d\n",
|
dkprintf("%s: spin wakeup: cpu_id: %d\n",
|
||||||
thread->cpu_id);
|
__FUNCTION__, thread->cpu_id);
|
||||||
|
|
||||||
spin_slept = 1;
|
|
||||||
status = 0;
|
status = 0;
|
||||||
}
|
}
|
||||||
--thread->spin_sleep;
|
thread->spin_sleep = 0;
|
||||||
ihk_mc_spinlock_unlock(&(thread->spin_sleep_lock), irqstate);
|
ihk_mc_spinlock_unlock(&(thread->spin_sleep_lock), irqstate);
|
||||||
|
|
||||||
if (spin_slept) {
|
if (!runq_locked) {
|
||||||
return status;
|
irqstate = ihk_mc_spinlock_lock(&(v->runq_lock));
|
||||||
}
|
}
|
||||||
|
|
||||||
irqstate = ihk_mc_spinlock_lock(&(v->runq_lock));
|
|
||||||
|
|
||||||
if (thread->status & valid_states) {
|
if (thread->status & valid_states) {
|
||||||
mcs_rwlock_writer_lock_noirq(&proc->update_lock, &updatelock);
|
mcs_rwlock_writer_lock_noirq(&proc->update_lock, &updatelock);
|
||||||
if(proc->status != PS_EXITED)
|
if (proc->status != PS_EXITED)
|
||||||
proc->status = PS_RUNNING;
|
proc->status = PS_RUNNING;
|
||||||
mcs_rwlock_writer_unlock_noirq(&proc->update_lock, &updatelock);
|
mcs_rwlock_writer_unlock_noirq(&proc->update_lock, &updatelock);
|
||||||
xchg4((int *)(&thread->status), PS_RUNNING);
|
xchg4((int *)(&thread->status), PS_RUNNING);
|
||||||
@@ -2874,18 +3070,32 @@ sched_wakeup_thread(struct thread *thread, int valid_states)
|
|||||||
status = -EINVAL;
|
status = -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ihk_mc_spinlock_unlock(&(v->runq_lock), irqstate);
|
if (!runq_locked) {
|
||||||
|
ihk_mc_spinlock_unlock(&(v->runq_lock), irqstate);
|
||||||
|
}
|
||||||
|
|
||||||
if (!status && (thread->cpu_id != ihk_mc_get_processor_id())) {
|
if (!status && (thread->cpu_id != ihk_mc_get_processor_id())) {
|
||||||
dkprintf("sched_wakeup_process,issuing IPI,thread->cpu_id=%d\n",
|
dkprintf("%s: issuing IPI, thread->cpu_id=%d\n",
|
||||||
thread->cpu_id);
|
__FUNCTION__, thread->cpu_id);
|
||||||
ihk_mc_interrupt_cpu(get_x86_cpu_local_variable(thread->cpu_id)->apic_id,
|
ihk_mc_interrupt_cpu(
|
||||||
0xd1);
|
get_x86_cpu_local_variable(thread->cpu_id)->apic_id,
|
||||||
|
0xd1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int sched_wakeup_thread_locked(struct thread *thread, int valid_states)
|
||||||
|
{
|
||||||
|
return __sched_wakeup_thread(thread, valid_states, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int sched_wakeup_thread(struct thread *thread, int valid_states)
|
||||||
|
{
|
||||||
|
return __sched_wakeup_thread(thread, valid_states, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 1. Add current process to waitq
|
* 1. Add current process to waitq
|
||||||
* 2. Queue migration request into the target CPU's queue
|
* 2. Queue migration request into the target CPU's queue
|
||||||
@@ -2909,7 +3119,7 @@ void sched_request_migrate(int cpu_id, struct thread *thread)
|
|||||||
struct cpu_local_var *v = get_cpu_local_var(cpu_id);
|
struct cpu_local_var *v = get_cpu_local_var(cpu_id);
|
||||||
struct migrate_request req = { .thread = thread };
|
struct migrate_request req = { .thread = thread };
|
||||||
unsigned long irqstate;
|
unsigned long irqstate;
|
||||||
DECLARE_WAITQ_ENTRY(entry, cpu_local_var(current));
|
DECLARE_WAITQ_ENTRY_LOCKED(entry, cpu_local_var(current));
|
||||||
|
|
||||||
waitq_init(&req.wq);
|
waitq_init(&req.wq);
|
||||||
waitq_prepare_to_wait(&req.wq, &entry, PS_UNINTERRUPTIBLE);
|
waitq_prepare_to_wait(&req.wq, &entry, PS_UNINTERRUPTIBLE);
|
||||||
@@ -2926,6 +3136,8 @@ void sched_request_migrate(int cpu_id, struct thread *thread)
|
|||||||
if (cpu_id != ihk_mc_get_processor_id())
|
if (cpu_id != ihk_mc_get_processor_id())
|
||||||
ihk_mc_interrupt_cpu(/* Kick scheduler */
|
ihk_mc_interrupt_cpu(/* Kick scheduler */
|
||||||
get_x86_cpu_local_variable(cpu_id)->apic_id, 0xd1);
|
get_x86_cpu_local_variable(cpu_id)->apic_id, 0xd1);
|
||||||
|
dkprintf("%s: tid: %d -> cpu: %d\n",
|
||||||
|
__FUNCTION__, thread->tid, cpu_id);
|
||||||
|
|
||||||
schedule();
|
schedule();
|
||||||
waitq_finish_wait(&req.wq, &entry);
|
waitq_finish_wait(&req.wq, &entry);
|
||||||
|
|||||||
@@ -17,8 +17,8 @@
|
|||||||
#include <ihk/debug.h>
|
#include <ihk/debug.h>
|
||||||
#include <ihk/ikc.h>
|
#include <ihk/ikc.h>
|
||||||
#include <ikc/master.h>
|
#include <ikc/master.h>
|
||||||
#include <syscall.h>
|
|
||||||
#include <cls.h>
|
#include <cls.h>
|
||||||
|
#include <syscall.h>
|
||||||
#include <kmalloc.h>
|
#include <kmalloc.h>
|
||||||
#include <process.h>
|
#include <process.h>
|
||||||
#include <page.h>
|
#include <page.h>
|
||||||
@@ -76,11 +76,11 @@ procfs_delete_thread(struct thread *thread)
|
|||||||
*
|
*
|
||||||
* \param rarg returned argument
|
* \param rarg returned argument
|
||||||
*/
|
*/
|
||||||
void
|
void process_procfs_request(struct ikc_scd_packet *rpacket)
|
||||||
process_procfs_request(unsigned long rarg)
|
|
||||||
{
|
{
|
||||||
|
unsigned long rarg = rpacket->arg;
|
||||||
unsigned long parg, pbuf;
|
unsigned long parg, pbuf;
|
||||||
struct thread *thread = NULL;
|
struct thread *thread = NULL;
|
||||||
struct process *proc = NULL;
|
struct process *proc = NULL;
|
||||||
struct process_vm *vm = NULL;
|
struct process_vm *vm = NULL;
|
||||||
struct procfs_read *r;
|
struct procfs_read *r;
|
||||||
@@ -161,7 +161,7 @@ process_procfs_request(unsigned long rarg)
|
|||||||
*/
|
*/
|
||||||
ret = sscanf(p, "%d/", &pid);
|
ret = sscanf(p, "%d/", &pid);
|
||||||
if (ret == 1) {
|
if (ret == 1) {
|
||||||
struct mcs_rwlock_node tlock;
|
struct mcs_rwlock_node_irqsave tlock;
|
||||||
int tids;
|
int tids;
|
||||||
struct thread *thread1 = NULL;
|
struct thread *thread1 = NULL;
|
||||||
|
|
||||||
@@ -178,7 +178,7 @@ process_procfs_request(unsigned long rarg)
|
|||||||
else
|
else
|
||||||
tid = pid;
|
tid = pid;
|
||||||
|
|
||||||
mcs_rwlock_reader_lock_noirq(&proc->threads_lock, &tlock);
|
mcs_rwlock_reader_lock(&proc->threads_lock, &tlock);
|
||||||
list_for_each_entry(thread, &proc->threads_list, siblings_list){
|
list_for_each_entry(thread, &proc->threads_list, siblings_list){
|
||||||
if(thread->tid == tid)
|
if(thread->tid == tid)
|
||||||
break;
|
break;
|
||||||
@@ -188,15 +188,15 @@ process_procfs_request(unsigned long rarg)
|
|||||||
if(thread == NULL){
|
if(thread == NULL){
|
||||||
kprintf("process_procfs_request: no such tid %d-%d\n", pid, tid);
|
kprintf("process_procfs_request: no such tid %d-%d\n", pid, tid);
|
||||||
if(tids){
|
if(tids){
|
||||||
|
mcs_rwlock_reader_unlock(&proc->threads_lock, &tlock);
|
||||||
process_unlock(proc, &lock);
|
process_unlock(proc, &lock);
|
||||||
mcs_rwlock_reader_unlock_noirq(&proc->threads_lock, &tlock);
|
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
thread = thread1;
|
thread = thread1;
|
||||||
}
|
}
|
||||||
if(thread)
|
if(thread)
|
||||||
hold_thread(thread);
|
hold_thread(thread);
|
||||||
mcs_rwlock_reader_unlock_noirq(&proc->threads_lock, &tlock);
|
mcs_rwlock_reader_unlock(&proc->threads_lock, &tlock);
|
||||||
hold_process(proc);
|
hold_process(proc);
|
||||||
vm = proc->vm;
|
vm = proc->vm;
|
||||||
if(vm)
|
if(vm)
|
||||||
@@ -633,6 +633,7 @@ dataunavail:
|
|||||||
|
|
||||||
packet.msg = SCD_MSG_PROCFS_ANSWER;
|
packet.msg = SCD_MSG_PROCFS_ANSWER;
|
||||||
packet.arg = rarg;
|
packet.arg = rarg;
|
||||||
|
packet.pid = rpacket->pid;
|
||||||
|
|
||||||
ret = ihk_ikc_send(syscall_channel, &packet, 0);
|
ret = ihk_ikc_send(syscall_channel, &packet, 0);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
|
|||||||
389
kernel/rusage.c
Normal file
389
kernel/rusage.c
Normal file
@@ -0,0 +1,389 @@
|
|||||||
|
/**
|
||||||
|
* \file rusage.c
|
||||||
|
*/
|
||||||
|
#include <types.h>
|
||||||
|
#include <kmsg.h>
|
||||||
|
#include <ihk/cpu.h>
|
||||||
|
#include <ihk/mm.h>
|
||||||
|
#include <ihk/debug.h>
|
||||||
|
#include <process.h>
|
||||||
|
#include <init.h>
|
||||||
|
#include <march.h>
|
||||||
|
#include <cls.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <syscall.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <rusage.h>
|
||||||
|
|
||||||
|
//#define DEBUG_PRINT_AP
|
||||||
|
|
||||||
|
#ifdef DEBUG_PRINT_AP
|
||||||
|
#define dkprintf(...) kprintf(__VA_ARGS__)
|
||||||
|
#define ekprintf(...) kprintf(__VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define dkprintf(...) do { if (0) kprintf(__VA_ARGS__); } while (0)
|
||||||
|
#define ekprintf(...) kprintf(__VA_ARGS__)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
extern int num_processors ;
|
||||||
|
static volatile int ap_stop = 1;
|
||||||
|
|
||||||
|
mcs_lock_node_t ap_syscall_semaphore;
|
||||||
|
|
||||||
|
extern struct ihk_os_monitor *monitor;
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef ENABLE_RUSAGE
|
||||||
|
/* count total rss */
|
||||||
|
unsigned long count_rss () {
|
||||||
|
int i;
|
||||||
|
unsigned long val = 0;
|
||||||
|
for(i = 0; i < sizeof(cpu_set_t)/8; i++){
|
||||||
|
val += rusage_rss[i];
|
||||||
|
}
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* count total cache */
|
||||||
|
unsigned long count_cache () {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* count total rss_huge */
|
||||||
|
unsigned long count_rss_huge () {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* count total mapped_file */
|
||||||
|
unsigned long count_mapped_file () {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* count total max_usage */
|
||||||
|
unsigned long count_max_usage() {
|
||||||
|
return rusage_rss_max;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* count total kmem_usage */
|
||||||
|
unsigned long count_kmem_usage() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* count total kmax_usage */
|
||||||
|
unsigned long count_kmem_max_usage() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <sysfs.h>
|
||||||
|
#include <vsprintf.h>
|
||||||
|
|
||||||
|
#ifdef ENABLE_RUSAGE
|
||||||
|
char* strcat_rusage(char *s1, char *s2) {
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
for (i = 0; s1[i] != '\0'; i++); //skip chars.
|
||||||
|
for (j = 0; s2[j] != '\0'; j++) {
|
||||||
|
s1[i+j] = s2[j];
|
||||||
|
}
|
||||||
|
s1[i+j] = '\0';
|
||||||
|
return s1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static ssize_t
|
||||||
|
show_rusage_memory_data(struct sysfs_ops *ops, void *instance, void *buf, size_t size)
|
||||||
|
{
|
||||||
|
return snprintf(buf, size, "rss %lu\ncache %lu\nrss_huge %lu\nmapped_file %lu\n",
|
||||||
|
count_rss(),
|
||||||
|
count_cache(),
|
||||||
|
count_rss_huge(),
|
||||||
|
count_mapped_file()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static ssize_t
|
||||||
|
show_rusage_memory_max_usage_data(struct sysfs_ops *ops, void *instance, void *buf, size_t size)
|
||||||
|
{
|
||||||
|
return snprintf(buf,size,"%lu\n",count_max_usage());
|
||||||
|
}
|
||||||
|
|
||||||
|
static ssize_t
|
||||||
|
show_rusage_memory_kmem_usage_data(struct sysfs_ops *ops, void *instance, void *buf, size_t size)
|
||||||
|
{
|
||||||
|
return snprintf(buf,size,"%lu\n",count_kmem_usage());
|
||||||
|
}
|
||||||
|
|
||||||
|
static ssize_t
|
||||||
|
show_rusage_memory_kmem_max_usage_data(struct sysfs_ops *ops, void *instance, void *buf, size_t size)
|
||||||
|
{
|
||||||
|
return snprintf(buf,size,"%lu\n",count_kmem_max_usage());
|
||||||
|
}
|
||||||
|
|
||||||
|
static ssize_t
|
||||||
|
show_rusage_num_numa_nodes_data(struct sysfs_ops *ops, void *instance, void *buf, size_t size)
|
||||||
|
{
|
||||||
|
return snprintf(buf,size,"%d\n",ihk_mc_get_nr_numa_nodes());
|
||||||
|
}
|
||||||
|
|
||||||
|
static ssize_t
|
||||||
|
show_rusage_memory_numa_stat_data(struct sysfs_ops *ops, void *instance, void *buf, size_t size)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int num_numa;
|
||||||
|
char tmp_buf1[1024];
|
||||||
|
char tmp_buf2[1024];
|
||||||
|
unsigned long total = 0;
|
||||||
|
memset(tmp_buf1, 0, 1024);
|
||||||
|
num_numa = ihk_mc_get_nr_numa_nodes();
|
||||||
|
|
||||||
|
for (i = 0; i < num_numa; i++) {
|
||||||
|
total += rusage_numa_stat[i];
|
||||||
|
}
|
||||||
|
sprintf(tmp_buf1, "total=%lu ", total);
|
||||||
|
|
||||||
|
for (i = 0; i < num_numa; i++) {
|
||||||
|
sprintf(tmp_buf2, "N%d=%lu ", i, rusage_numa_stat[i]);
|
||||||
|
strcat_rusage(tmp_buf1, tmp_buf2);
|
||||||
|
memset(tmp_buf2, 0, 1024);
|
||||||
|
}
|
||||||
|
return snprintf(buf, size, "%s\n", tmp_buf1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static ssize_t
|
||||||
|
show_rusage_hugetlb_usage_data(struct sysfs_ops *ops, void *instance, void *buf, size_t size)
|
||||||
|
{
|
||||||
|
return snprintf(buf, size, "%lu\n", rusage_hugetlb_usage);
|
||||||
|
}
|
||||||
|
|
||||||
|
static ssize_t
|
||||||
|
show_rusage_hugetlb_max_usage_data(struct sysfs_ops *ops, void *instance, void *buf, size_t size)
|
||||||
|
{
|
||||||
|
return snprintf(buf, size, "%lu\n", rusage_hugetlb_max_usage);
|
||||||
|
}
|
||||||
|
static ssize_t
|
||||||
|
show_rusage_cpuacct_stat_data(struct sysfs_ops *ops, void *instance, void *buf, size_t size)
|
||||||
|
{
|
||||||
|
struct timespec uts;
|
||||||
|
struct timespec sts;
|
||||||
|
int i;
|
||||||
|
int r = 0;
|
||||||
|
|
||||||
|
uts.tv_sec = 0;
|
||||||
|
uts.tv_nsec = 0;
|
||||||
|
sts.tv_sec = 0;
|
||||||
|
sts.tv_nsec = 0;
|
||||||
|
if (monitor)
|
||||||
|
for (i = 0; i < num_processors; i++) {
|
||||||
|
struct timespec ats;
|
||||||
|
|
||||||
|
tsc_to_ts(monitor[i].user_tsc, &ats);
|
||||||
|
ts_add(&uts, &ats);
|
||||||
|
tsc_to_ts(monitor[i].system_tsc, &ats);
|
||||||
|
ts_add(&sts, &ats);
|
||||||
|
}
|
||||||
|
r = snprintf(buf, size, "user %lu\n", timespec_to_jiffy(&uts));
|
||||||
|
r += snprintf(strchr(buf, '\0'), size - r, "system %lu\n",
|
||||||
|
timespec_to_jiffy(&sts));
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
static ssize_t
|
||||||
|
show_rusage_cpuacct_usage_data(struct sysfs_ops *ops, void *instance, void *buf, size_t size)
|
||||||
|
{
|
||||||
|
struct timespec uts;
|
||||||
|
int i;
|
||||||
|
int r = 0;
|
||||||
|
|
||||||
|
uts.tv_sec = 0;
|
||||||
|
uts.tv_nsec = 0;
|
||||||
|
if (monitor)
|
||||||
|
for (i = 0; i < num_processors; i++) {
|
||||||
|
struct timespec ats;
|
||||||
|
|
||||||
|
tsc_to_ts(monitor[i].user_tsc + monitor[i].system_tsc,
|
||||||
|
&ats);
|
||||||
|
ts_add(&uts, &ats);
|
||||||
|
}
|
||||||
|
if (uts.tv_sec)
|
||||||
|
r = snprintf(buf, size, "%lu%09lu\n", uts.tv_sec, uts.tv_nsec);
|
||||||
|
else
|
||||||
|
r = snprintf(buf, size, "%lu\n", uts.tv_nsec);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static ssize_t
|
||||||
|
show_rusage_cpuacct_usage_percpu_data(struct sysfs_ops *ops, void *instance, void *buf, size_t size)
|
||||||
|
{
|
||||||
|
struct timespec uts;
|
||||||
|
int i;
|
||||||
|
int r = 0;
|
||||||
|
|
||||||
|
((char *)buf)[0] = '\0';
|
||||||
|
for (i = 0; i < num_processors; i++) {
|
||||||
|
if (monitor) {
|
||||||
|
tsc_to_ts(monitor[i].user_tsc + monitor[i].system_tsc,
|
||||||
|
&uts);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
uts.tv_sec = 0;
|
||||||
|
uts.tv_nsec = 0;
|
||||||
|
}
|
||||||
|
if (uts.tv_sec)
|
||||||
|
r += snprintf(strchr(buf, '\0'), size - r,
|
||||||
|
"%lu%09lu ", uts.tv_sec, uts.tv_nsec);
|
||||||
|
else
|
||||||
|
r += snprintf(strchr(buf, '\0'), size - r,
|
||||||
|
"%lu ", uts.tv_nsec);
|
||||||
|
}
|
||||||
|
((char *)buf)[r - 1] = '\n';
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* callback funciton of rusage(threads) sysfs */
|
||||||
|
static ssize_t
|
||||||
|
show_rusage_num_threads_data(struct sysfs_ops *ops, void *instance, void *buf, size_t size)
|
||||||
|
{
|
||||||
|
return snprintf(buf, size, "%lu\n", rusage_num_threads);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* callback funciton of rusage(max threads) sysfs */
|
||||||
|
static ssize_t
|
||||||
|
show_rusage_max_num_threads_data(struct sysfs_ops *ops, void *instance, void *buf, size_t size)
|
||||||
|
{
|
||||||
|
return snprintf(buf, size, "%lu\n", rusage_max_num_threads);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* definition of sysfs ops */
|
||||||
|
struct sysfs_ops show_rusage_memory = {
|
||||||
|
.show = &show_rusage_memory_data,
|
||||||
|
};
|
||||||
|
struct sysfs_ops show_rusage_memory_max_usage = {
|
||||||
|
.show = &show_rusage_memory_max_usage_data,
|
||||||
|
};
|
||||||
|
struct sysfs_ops show_rusage_memory_kmem_usage = {
|
||||||
|
.show = &show_rusage_memory_kmem_usage_data,
|
||||||
|
};
|
||||||
|
struct sysfs_ops show_rusage_memory_kmem_max_usage = {
|
||||||
|
.show = &show_rusage_memory_kmem_max_usage_data,
|
||||||
|
};
|
||||||
|
struct sysfs_ops show_rusage_num_numa_nodes = {
|
||||||
|
.show = &show_rusage_num_numa_nodes_data,
|
||||||
|
};
|
||||||
|
struct sysfs_ops show_rusage_memory_numa_stat = {
|
||||||
|
.show = &show_rusage_memory_numa_stat_data,
|
||||||
|
};
|
||||||
|
struct sysfs_ops show_rusage_hugetlb_usage = {
|
||||||
|
.show = &show_rusage_hugetlb_usage_data,
|
||||||
|
};
|
||||||
|
struct sysfs_ops show_rusage_hugetlb_max_usage = {
|
||||||
|
.show = &show_rusage_hugetlb_max_usage_data,
|
||||||
|
};
|
||||||
|
struct sysfs_ops show_rusage_cpuacct_stat = {
|
||||||
|
.show = &show_rusage_cpuacct_stat_data,
|
||||||
|
};
|
||||||
|
struct sysfs_ops show_rusage_cpuacct_usage = {
|
||||||
|
.show = &show_rusage_cpuacct_usage_data,
|
||||||
|
};
|
||||||
|
struct sysfs_ops show_rusage_num_threads = {
|
||||||
|
.show = &show_rusage_num_threads_data,
|
||||||
|
};
|
||||||
|
struct sysfs_ops show_rusage_cpuacct_usage_percpu = {
|
||||||
|
.show = &show_rusage_cpuacct_usage_percpu_data,
|
||||||
|
};
|
||||||
|
struct sysfs_ops show_rusage_max_num_threads = {
|
||||||
|
.show = &show_rusage_max_num_threads_data,
|
||||||
|
};
|
||||||
|
|
||||||
|
/* create sysfs files for rusage. */
|
||||||
|
void rusage_sysfs_setup(void) {
|
||||||
|
int error;
|
||||||
|
error = sysfs_createf(&show_rusage_memory, &rdata, 0444,
|
||||||
|
"/sys/fs/cgroup/memory/memory.stat");
|
||||||
|
if (error) {
|
||||||
|
panic("rusage_sysfs_setup:sysfs_createf() failed\n");
|
||||||
|
}
|
||||||
|
error = sysfs_createf(&show_rusage_memory_max_usage, &rdata, 0444,
|
||||||
|
"/sys/fs/cgroup/memory/memory.max_usage_in_bytes");
|
||||||
|
if (error) {
|
||||||
|
panic("rusage_sysfs_setup:sysfs_createf() failed\n");
|
||||||
|
}
|
||||||
|
error = sysfs_createf(&show_rusage_memory_kmem_usage, &rdata, 0444,
|
||||||
|
"/sys/fs/cgroup/memory/memory.kmem.usage_in_bytes");
|
||||||
|
if (error) {
|
||||||
|
panic("rusage_sysfs_setup:sysfs_createf() failed\n");
|
||||||
|
}
|
||||||
|
error = sysfs_createf(&show_rusage_memory_kmem_max_usage, &rdata, 0444,
|
||||||
|
"/sys/fs/cgroup/memory/memory.kmem.max_usage_in_bytes");
|
||||||
|
if (error) {
|
||||||
|
panic("rusage_sysfs_setup:sysfs_createf() failed\n");
|
||||||
|
}
|
||||||
|
error = sysfs_createf(&show_rusage_num_numa_nodes, &rdata, 0444,
|
||||||
|
"/sys/fs/cgroup/cpu/num_numa_nodes.txt");
|
||||||
|
if (error) {
|
||||||
|
panic("rusage_sysfs_setup:sysfs_createf() failed\n");
|
||||||
|
}
|
||||||
|
error = sysfs_createf(&show_rusage_memory_numa_stat, &rdata, 0444,
|
||||||
|
"/sys/fs/cgroup/memory/memory.numa_stat");
|
||||||
|
if (error) {
|
||||||
|
panic("rusage_sysfs_setup:sysfs_createf() failed\n");
|
||||||
|
}
|
||||||
|
error = sysfs_createf(&show_rusage_hugetlb_usage, &rdata, 0444,
|
||||||
|
"/sys/fs/cgroup/hugetlb/hugetlb.1GB.usage_in_bytes");
|
||||||
|
if (error) {
|
||||||
|
panic("rusage_sysfs_setup:sysfs_createf() failed\n");
|
||||||
|
}
|
||||||
|
error = sysfs_createf(&show_rusage_hugetlb_max_usage, &rdata, 0444,
|
||||||
|
"/sys/fs/cgroup/hugetlb/hugetlb.1GB.max_usage_in_bytes");
|
||||||
|
if (error) {
|
||||||
|
panic("rusage_sysfs_setup:sysfs_createf() failed\n");
|
||||||
|
}
|
||||||
|
error = sysfs_createf(&show_rusage_cpuacct_stat, &rdata, 0444,
|
||||||
|
"/sys/fs/cgroup/cpuacct/cpuacct.stat");
|
||||||
|
if (error) {
|
||||||
|
panic("rusage_sysfs_setup:sysfs_createf() failed\n");
|
||||||
|
}
|
||||||
|
error = sysfs_createf(&show_rusage_cpuacct_usage, &rdata, 0444,
|
||||||
|
"/sys/fs/cgroup/cpuacct/cpuacct.usage");
|
||||||
|
if (error) {
|
||||||
|
panic("rusage_sysfs_setup:sysfs_createf() failed\n");
|
||||||
|
}
|
||||||
|
error = sysfs_createf(&show_rusage_cpuacct_usage_percpu, &rdata, 0444,
|
||||||
|
"/sys/fs/cgroup/cpuacct/cpuacct.usage_percpu");
|
||||||
|
if (error) {
|
||||||
|
panic("rusage_sysfs_setup:sysfs_createf() failed\n");
|
||||||
|
}
|
||||||
|
error = sysfs_createf(&show_rusage_num_threads, &rdata, 0444,
|
||||||
|
"/sys/fs/cgroup/num_threads");
|
||||||
|
if (error) {
|
||||||
|
panic("rusage_sysfs_setup:sysfs_createf() failed\n");
|
||||||
|
}
|
||||||
|
error = sysfs_createf(&show_rusage_max_num_threads, &rdata, 0444,
|
||||||
|
"/sys/fs/cgroup/max_num_threads");
|
||||||
|
if (error) {
|
||||||
|
panic("rusage_sysfs_setup:sysfs_createf() failed\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* callback funciton of os_status sysfs */
|
||||||
|
static ssize_t
|
||||||
|
show_ihk_status_data(struct sysfs_ops *ops, void *instance, void *buf, size_t size)
|
||||||
|
{
|
||||||
|
return snprintf(buf, size, "%d\n", os_status);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct sysfs_ops show_ihk_status = {
|
||||||
|
.show = &show_ihk_status_data,
|
||||||
|
};
|
||||||
|
|
||||||
|
/* create sysfs files for monitoring status.*/
|
||||||
|
void status_sysfs_setup(void) {
|
||||||
|
int error;
|
||||||
|
error = sysfs_createf(&show_ihk_status, &rdata, 0444,
|
||||||
|
"/sys/fs/cgroup/mck_status");
|
||||||
|
if (error) {
|
||||||
|
panic("status_sysfs_setup:sysfs_createf() failed\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
439
kernel/syscall.c
439
kernel/syscall.c
@@ -55,6 +55,7 @@
|
|||||||
#include <bitops.h>
|
#include <bitops.h>
|
||||||
#include <bitmap.h>
|
#include <bitmap.h>
|
||||||
#include <xpmem.h>
|
#include <xpmem.h>
|
||||||
|
#include <rusage.h>
|
||||||
|
|
||||||
/* Headers taken from kitten LWK */
|
/* Headers taken from kitten LWK */
|
||||||
#include <lwk/stddef.h>
|
#include <lwk/stddef.h>
|
||||||
@@ -94,8 +95,8 @@ static long (*syscall_table[])(int, ihk_mc_user_context_t *) = {
|
|||||||
#define MCKERNEL_UNUSED __attribute__ ((unused))
|
#define MCKERNEL_UNUSED __attribute__ ((unused))
|
||||||
static char *syscall_name[] MCKERNEL_UNUSED = {
|
static char *syscall_name[] MCKERNEL_UNUSED = {
|
||||||
#define DECLARATOR(number,name) [number] = #name,
|
#define DECLARATOR(number,name) [number] = #name,
|
||||||
#define SYSCALL_HANDLED(number,name) DECLARATOR(number,sys_##name)
|
#define SYSCALL_HANDLED(number,name) DECLARATOR(number,#name)
|
||||||
#define SYSCALL_DELEGATED(number,name) DECLARATOR(number,sys_##name)
|
#define SYSCALL_DELEGATED(number,name) DECLARATOR(number,#name)
|
||||||
#include <syscall_list.h>
|
#include <syscall_list.h>
|
||||||
#undef DECLARATOR
|
#undef DECLARATOR
|
||||||
#undef SYSCALL_HANDLED
|
#undef SYSCALL_HANDLED
|
||||||
@@ -132,24 +133,20 @@ static void do_mod_exit(int status);
|
|||||||
|
|
||||||
#ifdef TRACK_SYSCALLS
|
#ifdef TRACK_SYSCALLS
|
||||||
|
|
||||||
#define SOCC_CLEAR 1
|
void track_syscalls_print_thread_stats(struct thread *thread)
|
||||||
#define SOCC_ON 2
|
|
||||||
#define SOCC_OFF 4
|
|
||||||
#define SOCC_PRINT 8
|
|
||||||
|
|
||||||
void print_syscall_stats(struct thread *thread)
|
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
|
|
||||||
flags = kprintf_lock();
|
flags = kprintf_lock();
|
||||||
|
|
||||||
for (i = 0; i < 300; ++i) {
|
for (i = 0; i < TRACK_SYSCALLS_MAX; ++i) {
|
||||||
if (!thread->syscall_cnts[i] &&
|
if (!thread->syscall_cnts[i] &&
|
||||||
!thread->offload_cnts[i]) continue;
|
!thread->offload_cnts[i]) continue;
|
||||||
|
|
||||||
//__kprintf("(%20s): sys.cnt: %3lu (%15lukC)\n",
|
//__kprintf("(%20s): sys.cnt: %3lu (%15lukC)\n",
|
||||||
__kprintf("(%3d,%20s): sys.cnt: %5lu (%10lukC), offl.cnt: %5lu (%10lukC)\n",
|
__kprintf("TID: %4d (%3d,%20s): sys: %6u %6lukC offl: %6u %6lukC\n",
|
||||||
|
thread->tid,
|
||||||
i,
|
i,
|
||||||
syscall_name[i],
|
syscall_name[i],
|
||||||
thread->syscall_cnts[i],
|
thread->syscall_cnts[i],
|
||||||
@@ -166,38 +163,150 @@ void print_syscall_stats(struct thread *thread)
|
|||||||
kprintf_unlock(flags);
|
kprintf_unlock(flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
void alloc_syscall_counters(struct thread *thread)
|
void track_syscalls_print_proc_stats(struct process *proc)
|
||||||
{
|
{
|
||||||
thread->syscall_times = kmalloc(sizeof(*thread->syscall_times) * 300, IHK_MC_AP_NOWAIT);
|
int i;
|
||||||
thread->syscall_cnts = kmalloc(sizeof(*thread->syscall_cnts) * 300, IHK_MC_AP_NOWAIT);
|
unsigned long flags;
|
||||||
thread->offload_times = kmalloc(sizeof(*thread->offload_times) * 300, IHK_MC_AP_NOWAIT);
|
|
||||||
thread->offload_cnts = kmalloc(sizeof(*thread->offload_cnts) * 300, IHK_MC_AP_NOWAIT);
|
flags = kprintf_lock();
|
||||||
|
|
||||||
|
for (i = 0; i < TRACK_SYSCALLS_MAX; ++i) {
|
||||||
|
if (!proc->syscall_cnts[i] &&
|
||||||
|
!proc->offload_cnts[i]) continue;
|
||||||
|
|
||||||
|
//__kprintf("(%20s): sys.cnt: %3lu (%15lukC)\n",
|
||||||
|
__kprintf("PID: %4d (%3d,%20s): sys: %6u %6lukC offl: %6u %6lukC\n",
|
||||||
|
proc->pid,
|
||||||
|
i,
|
||||||
|
syscall_name[i],
|
||||||
|
proc->syscall_cnts[i],
|
||||||
|
(proc->syscall_times[i] /
|
||||||
|
(proc->syscall_cnts[i] ? proc->syscall_cnts[i] : 1))
|
||||||
|
/ 1000,
|
||||||
|
proc->offload_cnts[i],
|
||||||
|
(proc->offload_times[i] /
|
||||||
|
(proc->offload_cnts[i] ? proc->offload_cnts[i] : 1))
|
||||||
|
/ 1000
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
kprintf_unlock(flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
void track_syscalls_accumulate_counters(struct thread *thread,
|
||||||
|
struct process *proc)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
struct mcs_lock_node mcs_node;
|
||||||
|
|
||||||
|
mcs_lock_lock(&proc->st_lock, &mcs_node);
|
||||||
|
for (i = 0; i < TRACK_SYSCALLS_MAX; ++i) {
|
||||||
|
if (thread->syscall_cnts[i]) {
|
||||||
|
proc->syscall_times[i] += thread->syscall_times[i];
|
||||||
|
proc->syscall_cnts[i] += thread->syscall_cnts[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (thread->offload_cnts[i]) {
|
||||||
|
proc->offload_times[i] += thread->offload_times[i];
|
||||||
|
proc->offload_cnts[i] += thread->offload_cnts[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mcs_lock_unlock(&proc->st_lock, &mcs_node);
|
||||||
|
}
|
||||||
|
|
||||||
|
void track_syscalls_alloc_counters(struct thread *thread)
|
||||||
|
{
|
||||||
|
struct process *proc = thread->proc;
|
||||||
|
struct mcs_lock_node mcs_node;
|
||||||
|
|
||||||
|
thread->syscall_times = kmalloc(sizeof(*thread->syscall_times) *
|
||||||
|
TRACK_SYSCALLS_MAX, IHK_MC_AP_NOWAIT);
|
||||||
|
thread->syscall_cnts = kmalloc(sizeof(*thread->syscall_cnts) *
|
||||||
|
TRACK_SYSCALLS_MAX, IHK_MC_AP_NOWAIT);
|
||||||
|
thread->offload_times = kmalloc(sizeof(*thread->offload_times) *
|
||||||
|
TRACK_SYSCALLS_MAX, IHK_MC_AP_NOWAIT);
|
||||||
|
thread->offload_cnts = kmalloc(sizeof(*thread->offload_cnts) *
|
||||||
|
TRACK_SYSCALLS_MAX, IHK_MC_AP_NOWAIT);
|
||||||
|
|
||||||
if (!thread->syscall_times ||
|
if (!thread->syscall_times ||
|
||||||
!thread->syscall_cnts ||
|
!thread->syscall_cnts ||
|
||||||
!thread->offload_times ||
|
!thread->offload_times ||
|
||||||
!thread->offload_cnts) {
|
!thread->offload_cnts) {
|
||||||
kprintf("ERROR: allocating counters\n");
|
kprintf("%s: ERROR: allocating thread private counters\n",
|
||||||
|
__FUNCTION__);
|
||||||
panic("");
|
panic("");
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(thread->syscall_times, 0, sizeof(*thread->syscall_times) * 300);
|
memset(thread->syscall_times, 0, sizeof(*thread->syscall_times) *
|
||||||
memset(thread->syscall_cnts, 0, sizeof(*thread->syscall_cnts) * 300);
|
TRACK_SYSCALLS_MAX);
|
||||||
memset(thread->offload_times, 0, sizeof(*thread->offload_times) * 300);
|
memset(thread->syscall_cnts, 0, sizeof(*thread->syscall_cnts) *
|
||||||
memset(thread->offload_cnts, 0, sizeof(*thread->offload_cnts) * 300);
|
TRACK_SYSCALLS_MAX);
|
||||||
|
memset(thread->offload_times, 0, sizeof(*thread->offload_times) *
|
||||||
|
TRACK_SYSCALLS_MAX);
|
||||||
|
memset(thread->offload_cnts, 0, sizeof(*thread->offload_cnts) *
|
||||||
|
TRACK_SYSCALLS_MAX);
|
||||||
|
|
||||||
|
mcs_lock_lock(&proc->st_lock, &mcs_node);
|
||||||
|
if (!proc->syscall_times) {
|
||||||
|
proc->syscall_times = kmalloc(sizeof(*proc->syscall_times) *
|
||||||
|
TRACK_SYSCALLS_MAX, IHK_MC_AP_NOWAIT);
|
||||||
|
proc->syscall_cnts = kmalloc(sizeof(*proc->syscall_cnts) *
|
||||||
|
TRACK_SYSCALLS_MAX, IHK_MC_AP_NOWAIT);
|
||||||
|
proc->offload_times = kmalloc(sizeof(*proc->offload_times) *
|
||||||
|
TRACK_SYSCALLS_MAX, IHK_MC_AP_NOWAIT);
|
||||||
|
proc->offload_cnts = kmalloc(sizeof(*proc->offload_cnts) *
|
||||||
|
TRACK_SYSCALLS_MAX, IHK_MC_AP_NOWAIT);
|
||||||
|
|
||||||
|
if (!proc->syscall_times ||
|
||||||
|
!proc->syscall_cnts ||
|
||||||
|
!proc->offload_times ||
|
||||||
|
!proc->offload_cnts) {
|
||||||
|
kprintf("%s: ERROR: allocating process private counters\n",
|
||||||
|
__FUNCTION__);
|
||||||
|
panic("");
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(proc->syscall_times, 0, sizeof(*proc->syscall_times) *
|
||||||
|
TRACK_SYSCALLS_MAX);
|
||||||
|
memset(proc->syscall_cnts, 0, sizeof(*proc->syscall_cnts) *
|
||||||
|
TRACK_SYSCALLS_MAX);
|
||||||
|
memset(proc->offload_times, 0, sizeof(*proc->offload_times) *
|
||||||
|
TRACK_SYSCALLS_MAX);
|
||||||
|
memset(proc->offload_cnts, 0, sizeof(*proc->offload_cnts) *
|
||||||
|
TRACK_SYSCALLS_MAX);
|
||||||
|
}
|
||||||
|
mcs_lock_unlock(&proc->st_lock, &mcs_node);
|
||||||
}
|
}
|
||||||
|
|
||||||
SYSCALL_DECLARE(syscall_offload_clr_cntrs)
|
void track_syscalls_dealloc_thread_counters(struct thread *thread)
|
||||||
|
{
|
||||||
|
kfree(thread->syscall_times);
|
||||||
|
kfree(thread->syscall_cnts);
|
||||||
|
kfree(thread->offload_times);
|
||||||
|
kfree(thread->offload_cnts);
|
||||||
|
}
|
||||||
|
|
||||||
|
void track_syscalls_dealloc_proc_counters(struct process *proc)
|
||||||
|
{
|
||||||
|
kfree(proc->syscall_times);
|
||||||
|
kfree(proc->syscall_cnts);
|
||||||
|
kfree(proc->offload_times);
|
||||||
|
kfree(proc->offload_cnts);
|
||||||
|
}
|
||||||
|
|
||||||
|
int do_track_syscalls(int flag)
|
||||||
{
|
{
|
||||||
int flag = (int)ihk_mc_syscall_arg0(ctx);
|
|
||||||
struct thread *thread = cpu_local_var(current);
|
struct thread *thread = cpu_local_var(current);
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (flag & SOCC_PRINT)
|
if (flag & TRACK_SYSCALLS_PRINT)
|
||||||
print_syscall_stats(thread);
|
track_syscalls_print_thread_stats(thread);
|
||||||
|
|
||||||
if (flag & SOCC_CLEAR) {
|
if (flag & TRACK_SYSCALLS_PRINT_PROC)
|
||||||
for (i = 0; i < 300; ++i) {
|
track_syscalls_print_proc_stats(thread->proc);
|
||||||
|
|
||||||
|
if (flag & TRACK_SYSCALLS_CLEAR) {
|
||||||
|
for (i = 0; i < TRACK_SYSCALLS_MAX; ++i) {
|
||||||
if (!thread->syscall_cnts[i] &&
|
if (!thread->syscall_cnts[i] &&
|
||||||
!thread->offload_cnts[i]) continue;
|
!thread->offload_cnts[i]) continue;
|
||||||
|
|
||||||
@@ -208,15 +317,21 @@ SYSCALL_DECLARE(syscall_offload_clr_cntrs)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flag & SOCC_ON) {
|
if (flag & TRACK_SYSCALLS_ON) {
|
||||||
thread->socc_enabled = 1;
|
thread->track_syscalls = 1;
|
||||||
}
|
}
|
||||||
else if (flag & SOCC_OFF) {
|
else if (flag & TRACK_SYSCALLS_OFF) {
|
||||||
thread->socc_enabled = 0;
|
thread->track_syscalls = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SYSCALL_DECLARE(track_syscalls)
|
||||||
|
{
|
||||||
|
int flag = (int)ihk_mc_syscall_arg0(ctx);
|
||||||
|
return do_track_syscalls(flag);
|
||||||
|
}
|
||||||
#endif // TRACK_SYSCALLS
|
#endif // TRACK_SYSCALLS
|
||||||
|
|
||||||
static void send_syscall(struct syscall_request *req, int cpu, int pid, struct syscall_response *res)
|
static void send_syscall(struct syscall_request *req, int cpu, int pid, struct syscall_response *res)
|
||||||
@@ -267,18 +382,17 @@ static void send_syscall(struct syscall_request *req, int cpu, int pid, struct s
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
ihk_spinlock_t syscall_lock;
|
|
||||||
|
|
||||||
long do_syscall(struct syscall_request *req, int cpu, int pid)
|
long do_syscall(struct syscall_request *req, int cpu, int pid)
|
||||||
{
|
{
|
||||||
struct syscall_response res;
|
struct syscall_response res;
|
||||||
struct syscall_request req2 IHK_DMA_ALIGN;
|
struct syscall_request req2 IHK_DMA_ALIGN;
|
||||||
int error;
|
int error;
|
||||||
long rc;
|
long rc;
|
||||||
int islock = 0;
|
|
||||||
unsigned long irqstate;
|
|
||||||
struct thread *thread = cpu_local_var(current);
|
struct thread *thread = cpu_local_var(current);
|
||||||
struct process *proc = thread->proc;
|
struct process *proc = thread->proc;
|
||||||
|
struct ihk_os_monitor *monitor = cpu_local_var(monitor);
|
||||||
|
int mstatus = 0;
|
||||||
|
|
||||||
#ifdef TRACK_SYSCALLS
|
#ifdef TRACK_SYSCALLS
|
||||||
uint64_t t_s;
|
uint64_t t_s;
|
||||||
t_s = rdtsc();
|
t_s = rdtsc();
|
||||||
@@ -288,7 +402,9 @@ long do_syscall(struct syscall_request *req, int cpu, int pid)
|
|||||||
ihk_mc_get_processor_id(),
|
ihk_mc_get_processor_id(),
|
||||||
req->number);
|
req->number);
|
||||||
|
|
||||||
irqstate = 0; /* for avoidance of warning */
|
mstatus = monitor->status;
|
||||||
|
monitor->status = IHK_OS_MONITOR_KERNEL_OFFLOAD;
|
||||||
|
|
||||||
barrier();
|
barrier();
|
||||||
|
|
||||||
if(req->number != __NR_exit_group){
|
if(req->number != __NR_exit_group){
|
||||||
@@ -299,11 +415,6 @@ long do_syscall(struct syscall_request *req, int cpu, int pid)
|
|||||||
++thread->in_syscall_offload;
|
++thread->in_syscall_offload;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(req->number == __NR_exit_group ||
|
|
||||||
req->number == __NR_kill){ // interrupt syscall
|
|
||||||
islock = 1;
|
|
||||||
irqstate = ihk_mc_spinlock_lock(&syscall_lock);
|
|
||||||
}
|
|
||||||
/* The current thread is the requester and any thread from
|
/* The current thread is the requester and any thread from
|
||||||
* the pool may serve the request */
|
* the pool may serve the request */
|
||||||
req->rtid = cpu_local_var(current)->tid;
|
req->rtid = cpu_local_var(current)->tid;
|
||||||
@@ -394,30 +505,30 @@ long do_syscall(struct syscall_request *req, int cpu, int pid)
|
|||||||
__FUNCTION__, req->number, res.ret);
|
__FUNCTION__, req->number, res.ret);
|
||||||
|
|
||||||
rc = res.ret;
|
rc = res.ret;
|
||||||
if(islock){
|
|
||||||
ihk_mc_spinlock_unlock(&syscall_lock, irqstate);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(req->number != __NR_exit_group){
|
if(req->number != __NR_exit_group){
|
||||||
--thread->in_syscall_offload;
|
--thread->in_syscall_offload;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef TRACK_SYSCALLS
|
#ifdef TRACK_SYSCALLS
|
||||||
if (req->number < 300) {
|
if (req->number < TRACK_SYSCALLS_MAX) {
|
||||||
if (!cpu_local_var(current)->offload_cnts) {
|
if (!cpu_local_var(current)->offload_cnts) {
|
||||||
alloc_syscall_counters(cpu_local_var(current));
|
track_syscalls_alloc_counters(cpu_local_var(current));
|
||||||
}
|
}
|
||||||
if (cpu_local_var(current)->socc_enabled) {
|
if (cpu_local_var(current)->track_syscalls) {
|
||||||
cpu_local_var(current)->offload_times[req->number] +=
|
cpu_local_var(current)->offload_times[req->number] +=
|
||||||
(rdtsc() - t_s);
|
(rdtsc() - t_s);
|
||||||
cpu_local_var(current)->offload_cnts[req->number]++;
|
cpu_local_var(current)->offload_cnts[req->number] += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
dkprintf("offload syscall > 300?? : %d\n", req->number);
|
dkprintf("%s: offload syscall > %d ?? : %d\n",
|
||||||
|
__FUNCTION__, TRACK_SYSCALLS_MAX, req->number);
|
||||||
}
|
}
|
||||||
#endif // TRACK_SYSCALLS
|
#endif // TRACK_SYSCALLS
|
||||||
|
|
||||||
|
monitor->status = mstatus;
|
||||||
|
monitor->counter++;
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -999,6 +1110,18 @@ terminate_host(int pid)
|
|||||||
do_kill(cpu_local_var(current), pid, -1, SIGKILL, NULL, 0);
|
do_kill(cpu_local_var(current), pid, -1, SIGKILL, NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
event_signal()
|
||||||
|
{
|
||||||
|
struct ihk_ikc_channel_desc *syscall_channel;
|
||||||
|
struct ikc_scd_packet pckt;
|
||||||
|
|
||||||
|
syscall_channel = get_cpu_local_var(0)->syscall_channel2;
|
||||||
|
memset(&pckt, '\0', sizeof pckt);
|
||||||
|
pckt.msg = SCD_MSG_EVENT_SIGNAL;
|
||||||
|
ihk_ikc_send(syscall_channel, &pckt, 0);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
interrupt_syscall(int pid, int tid)
|
interrupt_syscall(int pid, int tid)
|
||||||
{
|
{
|
||||||
@@ -1135,6 +1258,7 @@ do_mmap(const intptr_t addr0, const size_t len0, const int prot,
|
|||||||
struct vm_regions *region = &thread->vm->region;
|
struct vm_regions *region = &thread->vm->region;
|
||||||
intptr_t addr = addr0;
|
intptr_t addr = addr0;
|
||||||
size_t len = len0;
|
size_t len = len0;
|
||||||
|
size_t populate_len;
|
||||||
off_t off;
|
off_t off;
|
||||||
int error;
|
int error;
|
||||||
intptr_t npages;
|
intptr_t npages;
|
||||||
@@ -1151,6 +1275,7 @@ do_mmap(const intptr_t addr0, const size_t len0, const int prot,
|
|||||||
struct process *proc = thread->proc;
|
struct process *proc = thread->proc;
|
||||||
struct mckfd *fdp = NULL;
|
struct mckfd *fdp = NULL;
|
||||||
int pgshift;
|
int pgshift;
|
||||||
|
struct vm_range *range = NULL;
|
||||||
|
|
||||||
dkprintf("do_mmap(%lx,%lx,%x,%x,%d,%lx)\n",
|
dkprintf("do_mmap(%lx,%lx,%x,%x,%d,%lx)\n",
|
||||||
addr0, len0, prot, flags, fd, off0);
|
addr0, len0, prot, flags, fd, off0);
|
||||||
@@ -1234,16 +1359,9 @@ do_mmap(const intptr_t addr0, const size_t len0, const int prot,
|
|||||||
vrflags |= (flags & MAP_LOCKED)? VR_LOCKED: 0;
|
vrflags |= (flags & MAP_LOCKED)? VR_LOCKED: 0;
|
||||||
vrflags |= VR_DEMAND_PAGING;
|
vrflags |= VR_DEMAND_PAGING;
|
||||||
if (flags & MAP_ANONYMOUS) {
|
if (flags & MAP_ANONYMOUS) {
|
||||||
if (!anon_on_demand) {
|
if (!anon_on_demand && (flags & MAP_PRIVATE)) {
|
||||||
populated_mapping = 1;
|
|
||||||
}
|
|
||||||
#ifdef USE_NOCACHE_MMAP
|
|
||||||
#define X_MAP_NOCACHE MAP_32BIT
|
|
||||||
else if (flags & X_MAP_NOCACHE) {
|
|
||||||
vrflags &= ~VR_DEMAND_PAGING;
|
vrflags &= ~VR_DEMAND_PAGING;
|
||||||
vrflags |= VR_IO_NOCACHE;
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & (MAP_POPULATE | MAP_LOCKED)) {
|
if (flags & (MAP_POPULATE | MAP_LOCKED)) {
|
||||||
@@ -1252,6 +1370,9 @@ do_mmap(const intptr_t addr0, const size_t len0, const int prot,
|
|||||||
|
|
||||||
/* XXX: Intel MPI 128MB mapping.. */
|
/* XXX: Intel MPI 128MB mapping.. */
|
||||||
if (len == 134217728) {
|
if (len == 134217728) {
|
||||||
|
dkprintf("%s: %ld bytes mapping -> no prefault\n",
|
||||||
|
__FUNCTION__, len);
|
||||||
|
vrflags |= VR_DEMAND_PAGING;
|
||||||
populated_mapping = 0;
|
populated_mapping = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1309,19 +1430,39 @@ do_mmap(const intptr_t addr0, const size_t len0, const int prot,
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/* Prepopulated ANONYMOUS mapping */
|
||||||
else if (!(vrflags & VR_DEMAND_PAGING)
|
else if (!(vrflags & VR_DEMAND_PAGING)
|
||||||
&& ((vrflags & VR_PROT_MASK) != VR_PROT_NONE)) {
|
&& ((vrflags & VR_PROT_MASK) != VR_PROT_NONE)) {
|
||||||
npages = len >> PAGE_SHIFT;
|
npages = len >> PAGE_SHIFT;
|
||||||
p = ihk_mc_alloc_aligned_pages(npages, p2align, IHK_MC_AP_NOWAIT);
|
/* Small allocations mostly benefit from closest RAM,
|
||||||
|
* otherwise follow user requested policy */
|
||||||
|
unsigned long __flag = (len >= 2097152) ? IHK_MC_AP_USER : 0;
|
||||||
|
|
||||||
|
p = ihk_mc_alloc_aligned_pages(npages, p2align,
|
||||||
|
IHK_MC_AP_NOWAIT | __flag);
|
||||||
if (p == NULL) {
|
if (p == NULL) {
|
||||||
ekprintf("do_mmap:allocate_pages(%d,%d) failed.\n",
|
dkprintf("%s: warning: failed to allocate %d contiguous pages "
|
||||||
npages, p2align);
|
" (bytes: %lu, pgshift: %d), enabling demand paging\n",
|
||||||
error = -ENOMEM;
|
__FUNCTION__,
|
||||||
goto out;
|
npages, npages * PAGE_SIZE, p2align);
|
||||||
|
|
||||||
|
/* Give demand paging a chance */
|
||||||
|
vrflags |= VR_DEMAND_PAGING;
|
||||||
|
populated_mapping = 0;
|
||||||
|
|
||||||
|
error = zeroobj_create(&memobj);
|
||||||
|
if (error) {
|
||||||
|
ekprintf("%s: zeroobj_create failed, error: %d\n",
|
||||||
|
__FUNCTION__, error);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
dkprintf("%s: 0x%x:%lu MAP_ANONYMOUS "
|
||||||
|
"allocated %d pages, p2align: %lx\n",
|
||||||
|
__FUNCTION__, addr, len, npages, p2align);
|
||||||
|
phys = virt_to_phys(p);
|
||||||
}
|
}
|
||||||
dkprintf("%s: 0x%x:%lu allocated %d pages, p2align: %lx\n",
|
|
||||||
__FUNCTION__, addr, len, npages, p2align);
|
|
||||||
phys = virt_to_phys(p);
|
|
||||||
}
|
}
|
||||||
else if (flags & MAP_SHARED) {
|
else if (flags & MAP_SHARED) {
|
||||||
memset(&ads, 0, sizeof(ads));
|
memset(&ads, 0, sizeof(ads));
|
||||||
@@ -1354,7 +1495,7 @@ do_mmap(const intptr_t addr0, const size_t len0, const int prot,
|
|||||||
vrflags |= VRFLAG_PROT_TO_MAXPROT(PROT_TO_VR_FLAG(maxprot));
|
vrflags |= VRFLAG_PROT_TO_MAXPROT(PROT_TO_VR_FLAG(maxprot));
|
||||||
|
|
||||||
error = add_process_memory_range(thread->vm, addr, addr+len, phys,
|
error = add_process_memory_range(thread->vm, addr, addr+len, phys,
|
||||||
vrflags, memobj, off, pgshift);
|
vrflags, memobj, off, pgshift, &range);
|
||||||
if (error) {
|
if (error) {
|
||||||
kprintf("%s: add_process_memory_range failed for 0x%lx:%lu"
|
kprintf("%s: add_process_memory_range failed for 0x%lx:%lu"
|
||||||
" flags: %lx, vrflags: %lx, pgshift: %d, error: %d\n",
|
" flags: %lx, vrflags: %lx, pgshift: %d, error: %d\n",
|
||||||
@@ -1363,12 +1504,18 @@ do_mmap(const intptr_t addr0, const size_t len0, const int prot,
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
memobj_lock(memobj);
|
/* Determine pre-populated size */
|
||||||
if (memobj->status == MEMOBJ_TO_BE_PREFETCHED) {
|
populate_len = len;
|
||||||
memobj->status = MEMOBJ_READY;
|
|
||||||
populated_mapping = 1;
|
if (!(flags & MAP_ANONYMOUS)) {
|
||||||
|
memobj_lock(memobj);
|
||||||
|
if (memobj->status == MEMOBJ_TO_BE_PREFETCHED) {
|
||||||
|
memobj->status = MEMOBJ_READY;
|
||||||
|
populated_mapping = 1;
|
||||||
|
populate_len = memobj->size;
|
||||||
|
}
|
||||||
|
memobj_unlock(memobj);
|
||||||
}
|
}
|
||||||
memobj_unlock(memobj);
|
|
||||||
|
|
||||||
error = 0;
|
error = 0;
|
||||||
p = NULL;
|
p = NULL;
|
||||||
@@ -1382,7 +1529,9 @@ out:
|
|||||||
ihk_mc_spinlock_unlock_noirq(&thread->vm->memory_range_lock);
|
ihk_mc_spinlock_unlock_noirq(&thread->vm->memory_range_lock);
|
||||||
|
|
||||||
if (!error && populated_mapping && !((vrflags & VR_PROT_MASK) == VR_PROT_NONE)) {
|
if (!error && populated_mapping && !((vrflags & VR_PROT_MASK) == VR_PROT_NONE)) {
|
||||||
error = populate_process_memory(thread->vm, (void *)addr, len);
|
error = populate_process_memory(thread->vm,
|
||||||
|
(void *)addr, populate_len);
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
ekprintf("%s: WARNING: populate_process_memory(): "
|
ekprintf("%s: WARNING: populate_process_memory(): "
|
||||||
"vm: %p, addr: %p, len: %d (flags: %s%s) failed %d\n",
|
"vm: %p, addr: %p, len: %d (flags: %s%s) failed %d\n",
|
||||||
@@ -1895,6 +2044,7 @@ SYSCALL_DECLARE(execve)
|
|||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
dkprintf("execve(): ERROR: host failed to load elf header, errno: %d\n",
|
dkprintf("execve(): ERROR: host failed to load elf header, errno: %d\n",
|
||||||
ret);
|
ret);
|
||||||
|
ihk_mc_free_pages(desc, 1);
|
||||||
return -ret;
|
return -ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1918,6 +2068,7 @@ SYSCALL_DECLARE(execve)
|
|||||||
kprintf("ERROR: no argv for executable: %s?\n", kfilename? kfilename: "");
|
kprintf("ERROR: no argv for executable: %s?\n", kfilename? kfilename: "");
|
||||||
if(kfilename)
|
if(kfilename)
|
||||||
kfree(kfilename);
|
kfree(kfilename);
|
||||||
|
ihk_mc_free_pages(desc, 1);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1986,6 +2137,10 @@ SYSCALL_DECLARE(execve)
|
|||||||
dkprintf("execve(): switching to new process\n");
|
dkprintf("execve(): switching to new process\n");
|
||||||
proc->execed = 1;
|
proc->execed = 1;
|
||||||
|
|
||||||
|
ihk_mc_free_pages(desc, 1);
|
||||||
|
kfree(argv_flat);
|
||||||
|
kfree(envp_flat);
|
||||||
|
|
||||||
/* Lock run queue because enter_user_mode expects to release it */
|
/* Lock run queue because enter_user_mode expects to release it */
|
||||||
cpu_local_var(runq_irqstate) =
|
cpu_local_var(runq_irqstate) =
|
||||||
ihk_mc_spinlock_lock(&(get_this_cpu_local_var()->runq_lock));
|
ihk_mc_spinlock_lock(&(get_this_cpu_local_var()->runq_lock));
|
||||||
@@ -2272,11 +2427,13 @@ SYSCALL_DECLARE(set_tid_address)
|
|||||||
return cpu_local_var(current)->proc->pid;
|
return cpu_local_var(current)->proc->pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
static unsigned long
|
static unsigned long
|
||||||
timespec_to_jiffy(const struct timespec *ats)
|
timespec_to_jiffy(const struct timespec *ats)
|
||||||
{
|
{
|
||||||
return ats->tv_sec * 100 + ats->tv_nsec / 10000000;
|
return ats->tv_sec * 100 + ats->tv_nsec / 10000000;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
SYSCALL_DECLARE(times)
|
SYSCALL_DECLARE(times)
|
||||||
{
|
{
|
||||||
@@ -2292,8 +2449,10 @@ SYSCALL_DECLARE(times)
|
|||||||
struct process *proc = thread->proc;
|
struct process *proc = thread->proc;
|
||||||
struct timespec ats;
|
struct timespec ats;
|
||||||
|
|
||||||
mytms.tms_utime = timespec_to_jiffy(&thread->utime);
|
tsc_to_ts(thread->user_tsc, &ats);
|
||||||
mytms.tms_stime = timespec_to_jiffy(&thread->stime);
|
mytms.tms_utime = timespec_to_jiffy(&ats);
|
||||||
|
tsc_to_ts(thread->system_tsc, &ats);
|
||||||
|
mytms.tms_stime = timespec_to_jiffy(&ats);
|
||||||
ats.tv_sec = proc->utime.tv_sec;
|
ats.tv_sec = proc->utime.tv_sec;
|
||||||
ats.tv_nsec = proc->utime.tv_nsec;
|
ats.tv_nsec = proc->utime.tv_nsec;
|
||||||
ts_add(&ats, &proc->utime_children);
|
ts_add(&ats, &proc->utime_children);
|
||||||
@@ -3400,6 +3559,9 @@ SYSCALL_DECLARE(rt_sigtimedwait)
|
|||||||
int sig;
|
int sig;
|
||||||
struct timespec ats;
|
struct timespec ats;
|
||||||
struct timespec ets;
|
struct timespec ets;
|
||||||
|
struct ihk_os_monitor *monitor = cpu_local_var(monitor);
|
||||||
|
|
||||||
|
monitor->status = IHK_OS_MONITOR_KERNEL_HEAVY;
|
||||||
|
|
||||||
if (sigsetsize > sizeof(sigset_t))
|
if (sigsetsize > sizeof(sigset_t))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
@@ -3555,6 +3717,9 @@ do_sigsuspend(struct thread *thread, const sigset_t *set)
|
|||||||
struct list_head *head;
|
struct list_head *head;
|
||||||
mcs_rwlock_lock_t *lock;
|
mcs_rwlock_lock_t *lock;
|
||||||
struct mcs_rwlock_node_irqsave mcs_rw_node;
|
struct mcs_rwlock_node_irqsave mcs_rw_node;
|
||||||
|
struct ihk_os_monitor *monitor = cpu_local_var(monitor);
|
||||||
|
|
||||||
|
monitor->status = IHK_OS_MONITOR_KERNEL_HEAVY;
|
||||||
|
|
||||||
wset = set->__val[0];
|
wset = set->__val[0];
|
||||||
wset &= ~__sigmask(SIGKILL);
|
wset &= ~__sigmask(SIGKILL);
|
||||||
@@ -3563,9 +3728,28 @@ do_sigsuspend(struct thread *thread, const sigset_t *set)
|
|||||||
thread->sigmask.__val[0] = wset;
|
thread->sigmask.__val[0] = wset;
|
||||||
|
|
||||||
thread->sigevent = 1;
|
thread->sigevent = 1;
|
||||||
for(;;){
|
for (;;) {
|
||||||
while(thread->sigevent == 0)
|
while (thread->sigevent == 0) {
|
||||||
cpu_pause();
|
int do_schedule = 0;
|
||||||
|
struct cpu_local_var *v;
|
||||||
|
long runq_irqstate;
|
||||||
|
runq_irqstate =
|
||||||
|
ihk_mc_spinlock_lock(&(get_this_cpu_local_var()->runq_lock));
|
||||||
|
v = get_this_cpu_local_var();
|
||||||
|
|
||||||
|
if (v->flags & CPU_FLAG_NEED_RESCHED) {
|
||||||
|
do_schedule = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ihk_mc_spinlock_unlock(&v->runq_lock, runq_irqstate);
|
||||||
|
|
||||||
|
if (do_schedule) {
|
||||||
|
schedule();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
cpu_pause();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
lock = &thread->sigcommon->lock;
|
lock = &thread->sigcommon->lock;
|
||||||
head = &thread->sigcommon->sigpending;
|
head = &thread->sigcommon->sigpending;
|
||||||
@@ -4318,7 +4502,7 @@ SYSCALL_DECLARE(shmat)
|
|||||||
memobj_ref(&obj->memobj);
|
memobj_ref(&obj->memobj);
|
||||||
|
|
||||||
error = add_process_memory_range(vm, addr, addr+len, -1,
|
error = add_process_memory_range(vm, addr, addr+len, -1,
|
||||||
vrflags, &obj->memobj, 0, obj->pgshift);
|
vrflags, &obj->memobj, 0, obj->pgshift, NULL);
|
||||||
if (error) {
|
if (error) {
|
||||||
if (!(prot & PROT_WRITE)) {
|
if (!(prot & PROT_WRITE)) {
|
||||||
(void)set_host_vma(addr, len, PROT_READ|PROT_WRITE);
|
(void)set_host_vma(addr, len, PROT_READ|PROT_WRITE);
|
||||||
@@ -4644,6 +4828,9 @@ SYSCALL_DECLARE(futex)
|
|||||||
uint32_t *uaddr2 = (uint32_t *)ihk_mc_syscall_arg4(ctx);
|
uint32_t *uaddr2 = (uint32_t *)ihk_mc_syscall_arg4(ctx);
|
||||||
uint32_t val3 = (uint32_t)ihk_mc_syscall_arg5(ctx);
|
uint32_t val3 = (uint32_t)ihk_mc_syscall_arg5(ctx);
|
||||||
int flags = op;
|
int flags = op;
|
||||||
|
struct ihk_os_monitor *monitor = cpu_local_var(monitor);
|
||||||
|
|
||||||
|
monitor->status = IHK_OS_MONITOR_KERNEL_HEAVY;
|
||||||
|
|
||||||
/* Cross-address space futex? */
|
/* Cross-address space futex? */
|
||||||
if (op & FUTEX_PRIVATE_FLAG) {
|
if (op & FUTEX_PRIVATE_FLAG) {
|
||||||
@@ -4755,6 +4942,9 @@ SYSCALL_DECLARE(exit)
|
|||||||
|
|
||||||
if(nproc == 1){ // process has only one thread
|
if(nproc == 1){ // process has only one thread
|
||||||
terminate(exit_status, 0);
|
terminate(exit_status, 0);
|
||||||
|
#ifdef ENABLE_RUSAGE
|
||||||
|
rusage_num_threads--;
|
||||||
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4781,6 +4971,9 @@ SYSCALL_DECLARE(exit)
|
|||||||
if(proc->status == PS_EXITED){
|
if(proc->status == PS_EXITED){
|
||||||
mcs_rwlock_reader_unlock(&proc->threads_lock, &lock);
|
mcs_rwlock_reader_unlock(&proc->threads_lock, &lock);
|
||||||
terminate(exit_status, 0);
|
terminate(exit_status, 0);
|
||||||
|
#ifdef ENABLE_RUSAGE
|
||||||
|
rusage_num_threads--;
|
||||||
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
thread->status = PS_EXITED;
|
thread->status = PS_EXITED;
|
||||||
@@ -4789,6 +4982,9 @@ SYSCALL_DECLARE(exit)
|
|||||||
release_thread(thread);
|
release_thread(thread);
|
||||||
|
|
||||||
schedule();
|
schedule();
|
||||||
|
#ifdef ENABLE_RUSAGE
|
||||||
|
rusage_num_threads--;
|
||||||
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -4913,6 +5109,7 @@ SYSCALL_DECLARE(getrusage)
|
|||||||
struct timespec utime;
|
struct timespec utime;
|
||||||
struct timespec stime;
|
struct timespec stime;
|
||||||
struct mcs_rwlock_node lock;
|
struct mcs_rwlock_node lock;
|
||||||
|
struct timespec ats;
|
||||||
|
|
||||||
if(who != RUSAGE_SELF &&
|
if(who != RUSAGE_SELF &&
|
||||||
who != RUSAGE_CHILDREN &&
|
who != RUSAGE_CHILDREN &&
|
||||||
@@ -4944,8 +5141,10 @@ SYSCALL_DECLARE(getrusage)
|
|||||||
list_for_each_entry(child, &proc->threads_list, siblings_list){
|
list_for_each_entry(child, &proc->threads_list, siblings_list){
|
||||||
while(!child->times_update)
|
while(!child->times_update)
|
||||||
cpu_pause();
|
cpu_pause();
|
||||||
ts_add(&utime, &child->utime);
|
tsc_to_ts(child->user_tsc, &ats);
|
||||||
ts_add(&stime, &child->stime);
|
ts_add(&utime, &ats);
|
||||||
|
tsc_to_ts(child->system_tsc, &ats);
|
||||||
|
ts_add(&stime, &ats);
|
||||||
}
|
}
|
||||||
mcs_rwlock_reader_unlock_noirq(&proc->threads_lock, &lock);
|
mcs_rwlock_reader_unlock_noirq(&proc->threads_lock, &lock);
|
||||||
ts_to_tv(&kusage.ru_utime, &utime);
|
ts_to_tv(&kusage.ru_utime, &utime);
|
||||||
@@ -4954,14 +5153,18 @@ SYSCALL_DECLARE(getrusage)
|
|||||||
kusage.ru_maxrss = proc->maxrss / 1024;
|
kusage.ru_maxrss = proc->maxrss / 1024;
|
||||||
}
|
}
|
||||||
else if(who == RUSAGE_CHILDREN){
|
else if(who == RUSAGE_CHILDREN){
|
||||||
ts_to_tv(&kusage.ru_utime, &proc->utime_children);
|
tsc_to_ts(thread->user_tsc, &ats);
|
||||||
ts_to_tv(&kusage.ru_stime, &proc->stime_children);
|
ts_to_tv(&kusage.ru_utime, &ats);
|
||||||
|
tsc_to_ts(thread->system_tsc, &ats);
|
||||||
|
ts_to_tv(&kusage.ru_stime, &ats);
|
||||||
|
|
||||||
kusage.ru_maxrss = proc->maxrss_children / 1024;
|
kusage.ru_maxrss = proc->maxrss_children / 1024;
|
||||||
}
|
}
|
||||||
else if(who == RUSAGE_THREAD){
|
else if(who == RUSAGE_THREAD){
|
||||||
ts_to_tv(&kusage.ru_utime, &thread->utime);
|
tsc_to_ts(thread->user_tsc, &ats);
|
||||||
ts_to_tv(&kusage.ru_stime, &thread->stime);
|
ts_to_tv(&kusage.ru_utime, &ats);
|
||||||
|
tsc_to_ts(thread->system_tsc, &ats);
|
||||||
|
ts_to_tv(&kusage.ru_stime, &ats);
|
||||||
|
|
||||||
kusage.ru_maxrss = proc->maxrss / 1024;
|
kusage.ru_maxrss = proc->maxrss / 1024;
|
||||||
}
|
}
|
||||||
@@ -6297,10 +6500,11 @@ SYSCALL_DECLARE(clock_gettime)
|
|||||||
ats.tv_nsec = proc->utime.tv_nsec;
|
ats.tv_nsec = proc->utime.tv_nsec;
|
||||||
ts_add(&ats, &proc->stime);
|
ts_add(&ats, &proc->stime);
|
||||||
list_for_each_entry(child, &proc->threads_list, siblings_list){
|
list_for_each_entry(child, &proc->threads_list, siblings_list){
|
||||||
|
struct timespec wts;
|
||||||
while(!child->times_update)
|
while(!child->times_update)
|
||||||
cpu_pause();
|
cpu_pause();
|
||||||
ts_add(&ats, &child->utime);
|
tsc_to_ts(child->user_tsc + child->system_tsc, &wts);
|
||||||
ts_add(&ats, &child->stime);
|
ts_add(&ats, &wts);
|
||||||
}
|
}
|
||||||
mcs_rwlock_reader_unlock_noirq(&proc->threads_lock, &lock);
|
mcs_rwlock_reader_unlock_noirq(&proc->threads_lock, &lock);
|
||||||
return copy_to_user(ts, &ats, sizeof ats);
|
return copy_to_user(ts, &ats, sizeof ats);
|
||||||
@@ -6308,9 +6512,7 @@ SYSCALL_DECLARE(clock_gettime)
|
|||||||
else if(clock_id == CLOCK_THREAD_CPUTIME_ID){
|
else if(clock_id == CLOCK_THREAD_CPUTIME_ID){
|
||||||
struct thread *thread = cpu_local_var(current);
|
struct thread *thread = cpu_local_var(current);
|
||||||
|
|
||||||
ats.tv_sec = thread->utime.tv_sec;
|
tsc_to_ts(thread->user_tsc + thread->system_tsc, &ats);
|
||||||
ats.tv_nsec = thread->utime.tv_nsec;
|
|
||||||
ts_add(&ats, &thread->stime);
|
|
||||||
return copy_to_user(ts, &ats, sizeof ats);
|
return copy_to_user(ts, &ats, sizeof ats);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -6413,6 +6615,9 @@ SYSCALL_DECLARE(nanosleep)
|
|||||||
struct timespec *tv = (struct timespec *)ihk_mc_syscall_arg0(ctx);
|
struct timespec *tv = (struct timespec *)ihk_mc_syscall_arg0(ctx);
|
||||||
struct timespec *rem = (struct timespec *)ihk_mc_syscall_arg1(ctx);
|
struct timespec *rem = (struct timespec *)ihk_mc_syscall_arg1(ctx);
|
||||||
struct syscall_request request IHK_DMA_ALIGN;
|
struct syscall_request request IHK_DMA_ALIGN;
|
||||||
|
struct ihk_os_monitor *monitor = cpu_local_var(monitor);
|
||||||
|
|
||||||
|
monitor->status = IHK_OS_MONITOR_KERNEL_HEAVY;
|
||||||
|
|
||||||
/* Do it locally if supported */
|
/* Do it locally if supported */
|
||||||
if (gettime_local_support) {
|
if (gettime_local_support) {
|
||||||
@@ -7078,7 +7283,7 @@ SYSCALL_DECLARE(mremap)
|
|||||||
error = add_process_memory_range(thread->vm, newstart, newend, -1,
|
error = add_process_memory_range(thread->vm, newstart, newend, -1,
|
||||||
range->flag, range->memobj,
|
range->flag, range->memobj,
|
||||||
range->objoff + (oldstart - range->start),
|
range->objoff + (oldstart - range->start),
|
||||||
range->pgshift);
|
range->pgshift, NULL);
|
||||||
if (error) {
|
if (error) {
|
||||||
ekprintf("sys_mremap(%#lx,%#lx,%#lx,%#x,%#lx):"
|
ekprintf("sys_mremap(%#lx,%#lx,%#lx,%#x,%#lx):"
|
||||||
"add failed. %d\n",
|
"add failed. %d\n",
|
||||||
@@ -8327,8 +8532,7 @@ reset_cputime()
|
|||||||
if(!(thread = cpu_local_var(current)))
|
if(!(thread = cpu_local_var(current)))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
thread->btime.tv_sec = 0;
|
thread->base_tsc = 0;
|
||||||
thread->btime.tv_nsec = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -8340,8 +8544,9 @@ void
|
|||||||
set_cputime(int mode)
|
set_cputime(int mode)
|
||||||
{
|
{
|
||||||
struct thread *thread;
|
struct thread *thread;
|
||||||
struct timespec ats;
|
unsigned long tsc;
|
||||||
struct cpu_local_var *v;
|
struct cpu_local_var *v;
|
||||||
|
struct ihk_os_monitor *monitor;
|
||||||
|
|
||||||
if(clv == NULL)
|
if(clv == NULL)
|
||||||
return;
|
return;
|
||||||
@@ -8349,38 +8554,48 @@ set_cputime(int mode)
|
|||||||
v = get_this_cpu_local_var();
|
v = get_this_cpu_local_var();
|
||||||
if(!(thread = v->current))
|
if(!(thread = v->current))
|
||||||
return;
|
return;
|
||||||
|
if(thread == &v->idle)
|
||||||
|
return;
|
||||||
|
monitor = v->monitor;
|
||||||
|
if(mode == 0){
|
||||||
|
monitor->status = IHK_OS_MONITOR_USER;
|
||||||
|
}
|
||||||
|
else if(mode == 1){
|
||||||
|
monitor->counter++;
|
||||||
|
monitor->status = IHK_OS_MONITOR_KERNEL;
|
||||||
|
}
|
||||||
|
|
||||||
if(!gettime_local_support){
|
if(!gettime_local_support){
|
||||||
thread->times_update = 1;
|
thread->times_update = 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
calculate_time_from_tsc(&ats);
|
tsc = rdtsc();
|
||||||
if(thread->btime.tv_sec != 0 && thread->btime.tv_nsec != 0){
|
if(thread->base_tsc != 0){
|
||||||
|
unsigned long dtsc = tsc - thread->base_tsc;
|
||||||
struct timespec dts;
|
struct timespec dts;
|
||||||
|
|
||||||
dts.tv_sec = ats.tv_sec;
|
tsc_to_ts(dtsc, &dts);
|
||||||
dts.tv_nsec = ats.tv_nsec;
|
|
||||||
ts_sub(&dts, &thread->btime);
|
|
||||||
if(mode == 1){
|
if(mode == 1){
|
||||||
ts_add(&thread->utime, &dts);
|
thread->user_tsc += dtsc;
|
||||||
|
monitor->user_tsc += dtsc;
|
||||||
ts_add(&thread->itimer_virtual_value, &dts);
|
ts_add(&thread->itimer_virtual_value, &dts);
|
||||||
ts_add(&thread->itimer_prof_value, &dts);
|
ts_add(&thread->itimer_prof_value, &dts);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
ts_add(&thread->stime, &dts);
|
thread->system_tsc += dtsc;
|
||||||
|
monitor->system_tsc += dtsc;
|
||||||
ts_add(&thread->itimer_prof_value, &dts);
|
ts_add(&thread->itimer_prof_value, &dts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(mode == 2){
|
if(mode == 2){
|
||||||
thread->btime.tv_sec = 0;
|
thread->base_tsc = 0;
|
||||||
thread->btime.tv_nsec = 0;
|
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
thread->btime.tv_sec = ats.tv_sec;
|
thread->base_tsc = tsc;
|
||||||
thread->btime.tv_nsec = ats.tv_nsec;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
thread->times_update = 1;
|
thread->times_update = 1;
|
||||||
thread->in_kernel = mode;
|
thread->in_kernel = mode;
|
||||||
|
|
||||||
@@ -8443,6 +8658,7 @@ long syscall(int num, ihk_mc_user_context_t *ctx)
|
|||||||
#ifdef TRACK_SYSCALLS
|
#ifdef TRACK_SYSCALLS
|
||||||
uint64_t t_s;
|
uint64_t t_s;
|
||||||
#endif // TRACK_SYSCALLS
|
#endif // TRACK_SYSCALLS
|
||||||
|
struct thread *thread = cpu_local_var(current);
|
||||||
|
|
||||||
set_cputime(1);
|
set_cputime(1);
|
||||||
if(cpu_local_var(current)->proc->status == PS_EXITED &&
|
if(cpu_local_var(current)->proc->status == PS_EXITED &&
|
||||||
@@ -8485,6 +8701,7 @@ long syscall(int num, ihk_mc_user_context_t *ctx)
|
|||||||
dkprintf("\n");
|
dkprintf("\n");
|
||||||
|
|
||||||
#ifdef TRACK_SYSCALLS
|
#ifdef TRACK_SYSCALLS
|
||||||
|
if (num == __NR_clone) cpu_local_var(current)->track_syscalls = 1;
|
||||||
t_s = rdtsc();
|
t_s = rdtsc();
|
||||||
#endif // TRACK_SYSCALLS
|
#endif // TRACK_SYSCALLS
|
||||||
|
|
||||||
@@ -8503,24 +8720,26 @@ long syscall(int num, ihk_mc_user_context_t *ctx)
|
|||||||
l = syscall_generic_forwarding(num, ctx);
|
l = syscall_generic_forwarding(num, ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (num != __NR_sched_yield &&
|
if (!list_empty(&thread->sigpending) ||
|
||||||
num != __NR_futex) {
|
!list_empty(&thread->sigcommon->sigpending)) {
|
||||||
check_signal(l, NULL, num);
|
check_signal(l, NULL, num);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef TRACK_SYSCALLS
|
#ifdef TRACK_SYSCALLS
|
||||||
if (num < 300) {
|
if (num < TRACK_SYSCALLS_MAX) {
|
||||||
if (!cpu_local_var(current)->syscall_cnts) {
|
if (!cpu_local_var(current)->syscall_cnts) {
|
||||||
alloc_syscall_counters(cpu_local_var(current));
|
track_syscalls_alloc_counters(cpu_local_var(current));
|
||||||
}
|
}
|
||||||
if (cpu_local_var(current)->socc_enabled) {
|
if (cpu_local_var(current)->track_syscalls) {
|
||||||
cpu_local_var(current)->syscall_times[num] += (rdtsc() - t_s);
|
cpu_local_var(current)->syscall_times[num] += (rdtsc() - t_s);
|
||||||
cpu_local_var(current)->syscall_cnts[num]++;
|
cpu_local_var(current)->syscall_cnts[num]++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (num != 701)
|
if (num != __NR_track_syscalls) {
|
||||||
kprintf("syscall > 300?? : %d\n", num);
|
dkprintf("%s: syscall > %d ?? : %d\n",
|
||||||
|
__FUNCTION__, TRACK_SYSCALLS_MAX, num);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif // TRACK_SYSCALLS
|
#endif // TRACK_SYSCALLS
|
||||||
|
|
||||||
|
|||||||
129
kernel/timer.c
129
kernel/timer.c
@@ -55,135 +55,74 @@ void init_timers(void)
|
|||||||
|
|
||||||
uint64_t schedule_timeout(uint64_t timeout)
|
uint64_t schedule_timeout(uint64_t timeout)
|
||||||
{
|
{
|
||||||
struct waitq_entry my_wait;
|
|
||||||
struct timer my_timer;
|
|
||||||
struct thread *thread = cpu_local_var(current);
|
struct thread *thread = cpu_local_var(current);
|
||||||
int irqstate;
|
long irqstate;
|
||||||
int spin_sleep;
|
|
||||||
|
|
||||||
irqstate = ihk_mc_spinlock_lock(&thread->spin_sleep_lock);
|
|
||||||
dkprintf("schedule_timeout() spin sleep timeout: %lu\n", timeout);
|
|
||||||
spin_sleep = ++thread->spin_sleep;
|
|
||||||
ihk_mc_spinlock_unlock(&thread->spin_sleep_lock, irqstate);
|
|
||||||
|
|
||||||
/* Spin sleep.. */
|
/* Spin sleep.. */
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
int need_schedule;
|
||||||
|
struct cpu_local_var *v = get_this_cpu_local_var();
|
||||||
uint64_t t_s = rdtsc();
|
uint64_t t_s = rdtsc();
|
||||||
uint64_t t_e;
|
uint64_t t_e;
|
||||||
int spin_over = 0;
|
|
||||||
|
|
||||||
irqstate = ihk_mc_spinlock_lock(&thread->spin_sleep_lock);
|
irqstate = ihk_mc_spinlock_lock(&thread->spin_sleep_lock);
|
||||||
|
|
||||||
/* Woken up by someone? */
|
/* Woken up by someone? */
|
||||||
if (thread->spin_sleep < 1) {
|
if (thread->spin_sleep == 0) {
|
||||||
t_e = rdtsc();
|
t_e = rdtsc();
|
||||||
|
|
||||||
spin_over = 1;
|
|
||||||
if ((t_e - t_s) < timeout) {
|
if ((t_e - t_s) < timeout) {
|
||||||
timeout -= (t_e - t_s);
|
timeout -= (t_e - t_s);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
timeout = 1;
|
timeout = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ihk_mc_spinlock_unlock(&thread->spin_sleep_lock, irqstate);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ihk_mc_spinlock_unlock(&thread->spin_sleep_lock, irqstate);
|
ihk_mc_spinlock_unlock(&thread->spin_sleep_lock, irqstate);
|
||||||
|
|
||||||
if (!spin_over) {
|
/* Give a chance to another thread (if any) in case the core is
|
||||||
t_s = rdtsc();
|
* oversubscribed, but make sure we will be re-scheduled */
|
||||||
int need_schedule;
|
irqstate = ihk_mc_spinlock_lock(&(v->runq_lock));
|
||||||
struct cpu_local_var *v = get_this_cpu_local_var();
|
need_schedule = v->runq_len > 1 ? 1 : 0;
|
||||||
int irqstate = ihk_mc_spinlock_lock(&(v->runq_lock));
|
|
||||||
need_schedule = v->runq_len > 1 ? 1 : 0;
|
if (need_schedule) {
|
||||||
|
xchg4(&(cpu_local_var(current)->status), PS_RUNNING);
|
||||||
ihk_mc_spinlock_unlock(&(v->runq_lock), irqstate);
|
ihk_mc_spinlock_unlock(&(v->runq_lock), irqstate);
|
||||||
|
schedule();
|
||||||
|
|
||||||
/* Give a chance to another thread (if any) in case the core is
|
/* Recheck if woken */
|
||||||
* oversubscribed, but make sure we will be re-scheduled */
|
continue;
|
||||||
if (need_schedule) {
|
}
|
||||||
xchg4(&(cpu_local_var(current)->status), PS_RUNNING);
|
else {
|
||||||
schedule();
|
ihk_mc_spinlock_unlock(&(v->runq_lock), irqstate);
|
||||||
xchg4(&(cpu_local_var(current)->status),
|
|
||||||
PS_INTERRUPTIBLE);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
/* Spin wait */
|
|
||||||
while ((rdtsc() - t_s) < LOOP_TIMEOUT) {
|
|
||||||
cpu_pause();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (timeout < LOOP_TIMEOUT) {
|
|
||||||
timeout = 0;
|
|
||||||
spin_over = 1;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
timeout -= LOOP_TIMEOUT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (spin_over) {
|
/* Spin wait */
|
||||||
dkprintf("schedule_timeout() spin woken up, timeout: %lu\n",
|
while ((rdtsc() - t_s) < LOOP_TIMEOUT) {
|
||||||
timeout);
|
cpu_pause();
|
||||||
|
}
|
||||||
|
|
||||||
/* Give a chance to another thread (if any) in case we timed out,
|
/* Time out? */
|
||||||
* but make sure we will be re-scheduled */
|
if (timeout < LOOP_TIMEOUT) {
|
||||||
if (timeout == 0) {
|
timeout = 0;
|
||||||
int need_schedule;
|
|
||||||
struct cpu_local_var *v = get_this_cpu_local_var();
|
|
||||||
|
|
||||||
int irqstate =
|
|
||||||
ihk_mc_spinlock_lock(&(v->runq_lock));
|
|
||||||
need_schedule = v->runq_len > 1 ? 1 : 0;
|
|
||||||
ihk_mc_spinlock_unlock(&(v->runq_lock), irqstate);
|
|
||||||
|
|
||||||
if (need_schedule) {
|
|
||||||
xchg4(&(cpu_local_var(current)->status), PS_RUNNING);
|
|
||||||
schedule();
|
|
||||||
xchg4(&(cpu_local_var(current)->status),
|
|
||||||
PS_INTERRUPTIBLE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/* We are not sleeping any more */
|
||||||
irqstate = ihk_mc_spinlock_lock(&thread->spin_sleep_lock);
|
irqstate = ihk_mc_spinlock_lock(&thread->spin_sleep_lock);
|
||||||
if (spin_sleep == thread->spin_sleep) {
|
thread->spin_sleep = 0;
|
||||||
--thread->spin_sleep;
|
|
||||||
}
|
|
||||||
ihk_mc_spinlock_unlock(&thread->spin_sleep_lock, irqstate);
|
ihk_mc_spinlock_unlock(&thread->spin_sleep_lock, irqstate);
|
||||||
|
|
||||||
return timeout;
|
break;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
timeout -= LOOP_TIMEOUT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Init waitq and wait entry for this timer */
|
return timeout;
|
||||||
my_timer.timeout = (timeout < LOOP_TIMEOUT) ? LOOP_TIMEOUT : timeout;
|
|
||||||
my_timer.thread = cpu_local_var(current);
|
|
||||||
waitq_init(&my_timer.processes);
|
|
||||||
waitq_init_entry(&my_wait, cpu_local_var(current));
|
|
||||||
|
|
||||||
/* Add ourself to the timer queue */
|
|
||||||
ihk_mc_spinlock_lock_noirq(&timers_lock);
|
|
||||||
list_add_tail(&my_timer.list, &timers);
|
|
||||||
|
|
||||||
dkprintf("schedule_timeout() sleep timeout: %lu\n", my_timer.timeout);
|
|
||||||
|
|
||||||
/* Add ourself to the waitqueue and sleep */
|
|
||||||
waitq_prepare_to_wait(&my_timer.processes, &my_wait, PS_INTERRUPTIBLE);
|
|
||||||
ihk_mc_spinlock_unlock_noirq(&timers_lock);
|
|
||||||
schedule();
|
|
||||||
waitq_finish_wait(&my_timer.processes, &my_wait);
|
|
||||||
|
|
||||||
ihk_mc_spinlock_lock_noirq(&timers_lock);
|
|
||||||
|
|
||||||
/* Waken up by someone else then timeout? */
|
|
||||||
if (my_timer.timeout) {
|
|
||||||
list_del(&my_timer.list);
|
|
||||||
}
|
|
||||||
ihk_mc_spinlock_unlock_noirq(&timers_lock);
|
|
||||||
|
|
||||||
dkprintf("schedule_timeout() woken up, timeout: %lu\n",
|
|
||||||
my_timer.timeout);
|
|
||||||
|
|
||||||
return my_timer.timeout;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,13 @@ default_wake_function(waitq_entry_t *entry, unsigned mode,
|
|||||||
return sched_wakeup_thread(entry->private, PS_NORMAL);
|
return sched_wakeup_thread(entry->private, PS_NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
locked_wake_function(waitq_entry_t *entry, unsigned mode,
|
||||||
|
int flags, void *key)
|
||||||
|
{
|
||||||
|
return sched_wakeup_thread_locked(entry->private, PS_NORMAL);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
waitq_init(waitq_t *waitq)
|
waitq_init(waitq_t *waitq)
|
||||||
{
|
{
|
||||||
|
|||||||
1682
kernel/xpmem.c
1682
kernel/xpmem.c
File diff suppressed because it is too large
Load Diff
@@ -1,8 +1,17 @@
|
|||||||
#include <ihk/debug.h>
|
#include <ihk/debug.h>
|
||||||
#include <ihk/cpu.h>
|
#include <ihk/cpu.h>
|
||||||
|
#include <cls.h>
|
||||||
|
#include <ihk/rusage.h>
|
||||||
|
|
||||||
|
extern struct cpu_local_var *clv;
|
||||||
|
|
||||||
void panic(const char *msg)
|
void panic(const char *msg)
|
||||||
{
|
{
|
||||||
|
if (clv) {
|
||||||
|
struct ihk_os_monitor *monitor = cpu_local_var(monitor);
|
||||||
|
|
||||||
|
monitor->status = IHK_OS_MONITOR_PANIC;
|
||||||
|
}
|
||||||
cpu_disable_interrupt();
|
cpu_disable_interrupt();
|
||||||
|
|
||||||
kprintf(msg);
|
kprintf(msg);
|
||||||
|
|||||||
@@ -34,18 +34,25 @@ enum ihk_mc_gma_type {
|
|||||||
IHK_MC_RESERVED_AREA_END,
|
IHK_MC_RESERVED_AREA_END,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern unsigned long bootstrap_mem_end;
|
||||||
|
|
||||||
enum ihk_mc_ma_type {
|
enum ihk_mc_ma_type {
|
||||||
IHK_MC_MA_AVAILABLE,
|
IHK_MC_MA_AVAILABLE,
|
||||||
IHK_MC_MA_RESERVED,
|
IHK_MC_MA_RESERVED,
|
||||||
IHK_MC_MA_SPECIAL,
|
IHK_MC_MA_SPECIAL,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum ihk_mc_ap_flag {
|
typedef unsigned long ihk_mc_ap_flag;
|
||||||
IHK_MC_AP_FLAG,
|
/* Panic on no memory space */
|
||||||
IHK_MC_AP_CRITICAL, /* panic on no memory space */
|
#define IHK_MC_AP_CRITICAL 0x000001
|
||||||
IHK_MC_AP_NOWAIT, /* error return on no memory space */
|
/* Error return on no memory space */
|
||||||
IHK_MC_AP_WAIT /* wait on no memory space */
|
#define IHK_MC_AP_NOWAIT 0x000002
|
||||||
};
|
/* Wait on no memory space */
|
||||||
|
#define IHK_MC_AP_WAIT 0x000004
|
||||||
|
#define IHK_MC_AP_USER 0x001000
|
||||||
|
|
||||||
|
#define IHK_MC_AP_BANDWIDTH 0x010000
|
||||||
|
#define IHK_MC_AP_LATENCY 0x020000
|
||||||
|
|
||||||
enum ihk_mc_pt_prepare_flag {
|
enum ihk_mc_pt_prepare_flag {
|
||||||
IHK_MC_PT_FIRST_LEVEL,
|
IHK_MC_PT_FIRST_LEVEL,
|
||||||
@@ -79,10 +86,10 @@ void ihk_mc_reserve_arch_pages(struct ihk_page_allocator_desc *pa_allocator,
|
|||||||
unsigned long, unsigned long, int));
|
unsigned long, unsigned long, int));
|
||||||
|
|
||||||
struct ihk_mc_pa_ops {
|
struct ihk_mc_pa_ops {
|
||||||
void *(*alloc_page)(int, int, enum ihk_mc_ap_flag);
|
void *(*alloc_page)(int, int, ihk_mc_ap_flag, int node);
|
||||||
void (*free_page)(void *, int);
|
void (*free_page)(void *, int);
|
||||||
|
|
||||||
void *(*alloc)(int, enum ihk_mc_ap_flag);
|
void *(*alloc)(int, ihk_mc_ap_flag);
|
||||||
void (*free)(void *);
|
void (*free)(void *);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -103,17 +110,20 @@ void ihk_mc_map_micpa(unsigned long host_pa, unsigned long* mic_pa);
|
|||||||
int ihk_mc_free_micpa(unsigned long mic_pa);
|
int ihk_mc_free_micpa(unsigned long mic_pa);
|
||||||
void ihk_mc_clean_micpa(void);
|
void ihk_mc_clean_micpa(void);
|
||||||
|
|
||||||
void *_ihk_mc_alloc_aligned_pages(int npages, int p2align,
|
void *_ihk_mc_alloc_aligned_pages_node(int npages, int p2align,
|
||||||
enum ihk_mc_ap_flag flag, char *file, int line);
|
ihk_mc_ap_flag flag, int node, char *file, int line);
|
||||||
#define ihk_mc_alloc_aligned_pages(npages, p2align, flag) ({\
|
#define ihk_mc_alloc_aligned_pages_node(npages, p2align, flag, node) ({\
|
||||||
void *r = _ihk_mc_alloc_aligned_pages(npages, p2align, flag, __FILE__, __LINE__);\
|
void *r = _ihk_mc_alloc_aligned_pages_node(npages, p2align, flag, node, __FILE__, __LINE__);\
|
||||||
|
r;\
|
||||||
|
})
|
||||||
|
|
||||||
|
#define ihk_mc_alloc_aligned_pages(npages, p2align, flag) ({\
|
||||||
|
void *r = _ihk_mc_alloc_aligned_pages_node(npages, p2align, flag, -1, __FILE__, __LINE__);\
|
||||||
r;\
|
r;\
|
||||||
})
|
})
|
||||||
|
|
||||||
void *_ihk_mc_alloc_pages(int npages, enum ihk_mc_ap_flag flag,
|
|
||||||
char *file, int line);
|
|
||||||
#define ihk_mc_alloc_pages(npages, flag) ({\
|
#define ihk_mc_alloc_pages(npages, flag) ({\
|
||||||
void *r = _ihk_mc_alloc_pages(npages, flag, __FILE__, __LINE__);\
|
void *r = _ihk_mc_alloc_aligned_pages_node(npages, PAGE_P2ALIGN, flag, -1, __FILE__, __LINE__);\
|
||||||
r;\
|
r;\
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -160,7 +170,7 @@ int visit_pte_range(page_table_t pt, void *start, void *end, int pgshift,
|
|||||||
int move_pte_range(page_table_t pt, struct process_vm *vm,
|
int move_pte_range(page_table_t pt, struct process_vm *vm,
|
||||||
void *src, void *dest, size_t size);
|
void *src, void *dest, size_t size);
|
||||||
|
|
||||||
struct page_table *ihk_mc_pt_create(enum ihk_mc_ap_flag ap_flag);
|
struct page_table *ihk_mc_pt_create(ihk_mc_ap_flag ap_flag);
|
||||||
/* XXX: proper use of struct page_table and page_table_t is unknown */
|
/* XXX: proper use of struct page_table and page_table_t is unknown */
|
||||||
void ihk_mc_pt_destroy(struct page_table *pt);
|
void ihk_mc_pt_destroy(struct page_table *pt);
|
||||||
void ihk_mc_load_page_table(struct page_table *pt);
|
void ihk_mc_load_page_table(struct page_table *pt);
|
||||||
@@ -188,6 +198,9 @@ void remote_flush_tlb_cpumask(struct process_vm *vm,
|
|||||||
int ihk_set_kmsg(unsigned long addr, unsigned long size);
|
int ihk_set_kmsg(unsigned long addr, unsigned long size);
|
||||||
char *ihk_get_kargs();
|
char *ihk_get_kargs();
|
||||||
|
|
||||||
|
int ihk_set_monitor(unsigned long addr, unsigned long size);
|
||||||
|
int ihk_set_nmi_mode_addr(unsigned long addr);
|
||||||
|
|
||||||
extern void (*__tlb_flush_handler)(int vector);
|
extern void (*__tlb_flush_handler)(int vector);
|
||||||
|
|
||||||
struct tlb_flush_entry {
|
struct tlb_flush_entry {
|
||||||
|
|||||||
74
lib/include/ihk/rusage.h
Normal file
74
lib/include/ihk/rusage.h
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
#ifndef __RUSAGE_H
|
||||||
|
#define __RUSAGE_H
|
||||||
|
|
||||||
|
#define RUSAGE_DEFAULT_SIZE 10
|
||||||
|
|
||||||
|
enum RUSAGE_MEMBER {
|
||||||
|
RUSAGE_RSS,
|
||||||
|
RUSAGE_CACHE,
|
||||||
|
RUSAGE_RSS_HUGE,
|
||||||
|
RUSAGE_MAPPED_FILE,
|
||||||
|
RUSAGE_MAX_USAGE,
|
||||||
|
RUSAGE_KMEM_USAGE,
|
||||||
|
RUSAGE_KMAX_USAGE,
|
||||||
|
RUSAGE_NUM_NUMA_NODES,
|
||||||
|
RUSAGE_NUMA_STAT,
|
||||||
|
RUSAGE_HUGETLB ,
|
||||||
|
RUSAGE_HUGETLB_MAX ,
|
||||||
|
RUSAGE_STAT_SYSTEM ,
|
||||||
|
RUSAGE_STAT_USER ,
|
||||||
|
RUSAGE_USAGE ,
|
||||||
|
RUSAGE_USAGE_PER_CPU ,
|
||||||
|
RUSAGE_NUM_THREADS ,
|
||||||
|
RUSAGE_MAX_NUM_THREADS
|
||||||
|
};
|
||||||
|
|
||||||
|
struct r_data{
|
||||||
|
unsigned long pid;
|
||||||
|
unsigned long rss;
|
||||||
|
unsigned long cache;
|
||||||
|
unsigned long rss_huge;
|
||||||
|
unsigned long mapped_file;
|
||||||
|
unsigned long max_usage;
|
||||||
|
unsigned long kmem_usage;
|
||||||
|
unsigned long kmax_usage;
|
||||||
|
unsigned long hugetlb;
|
||||||
|
unsigned long hugetlb_max;
|
||||||
|
unsigned long stat_system;
|
||||||
|
unsigned long stat_user;
|
||||||
|
unsigned long usage;
|
||||||
|
struct r_data *next;
|
||||||
|
} ;
|
||||||
|
typedef struct r_data rusage_data;
|
||||||
|
|
||||||
|
rusage_data *rdata[RUSAGE_DEFAULT_SIZE];
|
||||||
|
unsigned long rusage_max_num_threads;
|
||||||
|
unsigned long rusage_num_threads;
|
||||||
|
|
||||||
|
enum ihk_os_status {
|
||||||
|
IHK_STATUS_INACTIVE,
|
||||||
|
IHK_STATUS_BOOTING,
|
||||||
|
IHK_STATUS_RUNNING,
|
||||||
|
IHK_STATUS_SHUTDOWN,
|
||||||
|
IHK_STATUS_PANIC,
|
||||||
|
IHK_STATUS_HUNGUP,
|
||||||
|
IHK_STATUS_FREEZING,
|
||||||
|
IHK_STATUS_FROZEN,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum ihk_os_status os_status;
|
||||||
|
unsigned long sys_delegate_count;
|
||||||
|
enum sys_delegate_state_enum {
|
||||||
|
ENTER_KERNEL,
|
||||||
|
EXIT_KERNEL,
|
||||||
|
};
|
||||||
|
enum sys_delegate_state_enum sys_delegate_state;
|
||||||
|
|
||||||
|
unsigned long rusage_kmem_usage;
|
||||||
|
unsigned long rusage_kmem_max_usage;
|
||||||
|
unsigned long rusage_hugetlb_usage;
|
||||||
|
unsigned long rusage_hugetlb_max_usage;
|
||||||
|
unsigned long rusage_usage_per_cpu[sizeof(cpu_set_t)/8];
|
||||||
|
unsigned long rusage_numa_stat[1024];
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -35,8 +35,8 @@ void *phys_to_virt(unsigned long p);
|
|||||||
int copy_from_user(void *dst, const void *src, size_t siz);
|
int copy_from_user(void *dst, const void *src, size_t siz);
|
||||||
int strlen_user(const char *s);
|
int strlen_user(const char *s);
|
||||||
int strcpy_from_user(char *dst, const char *src);
|
int strcpy_from_user(char *dst, const char *src);
|
||||||
long getlong_user(const long *p);
|
long getlong_user(long *dest, const long *p);
|
||||||
int getint_user(const int *p);
|
int getint_user(int *dest, const int *p);
|
||||||
int read_process_vm(struct process_vm *vm, void *kdst, const void *usrc, size_t siz);
|
int read_process_vm(struct process_vm *vm, void *kdst, const void *usrc, size_t siz);
|
||||||
int copy_to_user(void *dst, const void *src, size_t siz);
|
int copy_to_user(void *dst, const void *src, size_t siz);
|
||||||
int setlong_user(long *dst, long data);
|
int setlong_user(long *dst, long data);
|
||||||
|
|||||||
@@ -19,7 +19,6 @@
|
|||||||
#include <memory.h>
|
#include <memory.h>
|
||||||
#include <bitops.h>
|
#include <bitops.h>
|
||||||
|
|
||||||
void *allocate_pages(int npages, enum ihk_mc_ap_flag flag);
|
|
||||||
void free_pages(void *, int npages);
|
void free_pages(void *, int npages);
|
||||||
|
|
||||||
#define MAP_INDEX(n) ((n) >> 6)
|
#define MAP_INDEX(n) ((n) >> 6)
|
||||||
|
|||||||
33
lib/string.c
33
lib/string.c
@@ -275,13 +275,21 @@ int flatten_strings_from_user(int nr_strings, char *first, char **strings, char
|
|||||||
long *_flat;
|
long *_flat;
|
||||||
char *p;
|
char *p;
|
||||||
long r;
|
long r;
|
||||||
int n;
|
int n, ret;
|
||||||
|
|
||||||
/* How many strings do we have? */
|
/* How many strings do we have? */
|
||||||
if (nr_strings == -1) {
|
if (nr_strings == -1) {
|
||||||
for (nr_strings = 0; (r = getlong_user((void *)(strings + nr_strings))) > 0; ++nr_strings);
|
nr_strings = 0;
|
||||||
if(r < 0)
|
for (;;) {
|
||||||
return r;
|
ret = getlong_user(&r, (void *)(strings + nr_strings));
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
if (r == 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
++nr_strings;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Count full length */
|
/* Count full length */
|
||||||
@@ -295,8 +303,14 @@ int flatten_strings_from_user(int nr_strings, char *first, char **strings, char
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (string_i = 0; string_i < nr_strings; ++string_i) {
|
for (string_i = 0; string_i < nr_strings; ++string_i) {
|
||||||
char *userp = (char *)getlong_user((void *)(strings + string_i));
|
char *userp;
|
||||||
int len = strlen_user(userp);
|
int len;
|
||||||
|
|
||||||
|
ret = getlong_user((long *)&userp, (void *)(strings + string_i));
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
len = strlen_user(userp);
|
||||||
|
|
||||||
if(len < 0)
|
if(len < 0)
|
||||||
return len;
|
return len;
|
||||||
@@ -326,8 +340,13 @@ int flatten_strings_from_user(int nr_strings, char *first, char **strings, char
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (string_i = 0; string_i < nr_strings; ++string_i) {
|
for (string_i = 0; string_i < nr_strings; ++string_i) {
|
||||||
char *userp = (char *)getlong_user((void *)(strings + string_i));
|
char *userp;
|
||||||
_flat[n++] = p - (char *)_flat;
|
_flat[n++] = p - (char *)_flat;
|
||||||
|
|
||||||
|
ret = getlong_user((long *)&userp, (void *)(strings + string_i));
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
strcpy_from_user(p, userp);
|
strcpy_from_user(p, userp);
|
||||||
p = strchr(p, '\0') + 1;
|
p = strchr(p, '\0') + 1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user