diff --git a/kernel/include/profile.h b/kernel/include/profile.h index 35a0fa92..ceee4a63 100644 --- a/kernel/include/profile.h +++ b/kernel/include/profile.h @@ -38,6 +38,7 @@ enum profile_event_type { PROFILE_page_fault_file, PROFILE_page_fault_dev_file, PROFILE_page_fault_file_clr, + PROFILE_remote_page_fault, PROFILE_mpol_alloc_missed, PROFILE_mmap_anon_contig_phys, PROFILE_mmap_anon_no_contig_phys, diff --git a/kernel/mem.c b/kernel/mem.c index c501ddc2..63d66b29 100644 --- a/kernel/mem.c +++ b/kernel/mem.c @@ -558,7 +558,7 @@ static void *mckernel_allocate_aligned_pages_node(int npages, int p2align, } else { #ifdef PROFILE_ENABLE - //profile_event_add(PROFILE_numa_alloc_missed, npages * 4096); + profile_event_add(PROFILE_mpol_alloc_missed, npages * 4096); #endif dkprintf("%s: couldn't fulfill explicit NUMA request for %d pages\n", __FUNCTION__, npages); @@ -983,7 +983,10 @@ void remote_flush_tlb_array_cpumask(struct process_vm *vm, void tlb_flush_handler(int vector) { #ifdef PROFILE_ENABLE - unsigned long t_s = rdtsc(); + unsigned long t_s = 0; + if (cpu_local_var(current)->profile) { + t_s = rdtsc(); + } #endif // PROFILE_ENABLE int flags = cpu_disable_interrupt_save(); @@ -1011,11 +1014,12 @@ void tlb_flush_handler(int vector) cpu_restore_interrupt(flags); #ifdef PROFILE_ENABLE { - unsigned long t_e = rdtsc(); - profile_event_add(PROFILE_tlb_invalidate, (t_e - t_s)); - if (cpu_local_var(current)->profile) + if (cpu_local_var(current)->profile) { + unsigned long t_e = rdtsc(); + profile_event_add(PROFILE_tlb_invalidate, (t_e - t_s)); cpu_local_var(current)->profile_elapsed_ts += (t_e - t_s); + } } #endif // PROFILE_ENABLE } @@ -1025,8 +1029,9 @@ static void page_fault_handler(void *fault_addr, uint64_t reason, void *regs) struct thread *thread = cpu_local_var(current); int error; #ifdef PROFILE_ENABLE - uint64_t t_s; - t_s = rdtsc(); + uint64_t t_s = 0; + if (thread->profile) + t_s = rdtsc(); #endif // PROFILE_ENABLE set_cputime(interrupt_from_user(regs)? 1: 2); @@ -1091,7 +1096,8 @@ out: check_need_resched(); set_cputime(0); #ifdef PROFILE_ENABLE - profile_event_add(PROFILE_page_fault, (rdtsc() - t_s)); + if (thread->profile) + profile_event_add(PROFILE_page_fault, (rdtsc() - t_s)); #endif // PROFILE_ENABLE return; } diff --git a/kernel/profile.c b/kernel/profile.c index da3c355c..f2c0cfc2 100644 --- a/kernel/profile.c +++ b/kernel/profile.c @@ -63,6 +63,7 @@ char *profile_event_names[] = "page_fault_file", "page_fault_dev_file", "page_fault_file_clr_mem", + "remote_page_fault", "mpol_alloc_missed", "mmap_anon_contig_phys", "mmap_anon_no_contig_phys", diff --git a/kernel/syscall.c b/kernel/syscall.c index 0bc6f224..c4a738ca 100644 --- a/kernel/syscall.c +++ b/kernel/syscall.c @@ -182,8 +182,12 @@ long do_syscall(struct syscall_request *req, int cpu, int pid) int mstatus = 0; #ifdef PROFILE_ENABLE - uint64_t t_s; - t_s = rdtsc(); + /* We cannot use thread->profile_start_ts here because the + * caller may be utilizing it already */ + unsigned long t_s = 0; + if (thread->profile) { + t_s = rdtsc(); + } #endif // PROFILE_ENABLE dkprintf("SC(%d)[%3d] sending syscall\n", @@ -273,6 +277,15 @@ long do_syscall(struct syscall_request *req, int cpu, int pid) } if (res.status == STATUS_PAGE_FAULT) { +#ifdef PROFILE_ENABLE + /* We cannot use thread->profile_start_ts here because the + * caller may be utilizing it already */ + unsigned long t_s = 0; + if (thread->profile) { + t_s = rdtsc(); + } +#endif // PROFILE_ENABLE + dkprintf("STATUS_PAGE_FAULT in syscall, pid: %d\n", cpu_local_var(current)->proc->pid); error = page_fault_process_vm(thread->vm, @@ -291,6 +304,10 @@ long do_syscall(struct syscall_request *req, int cpu, int pid) res.req_thread_status = IHK_SCD_REQ_THREAD_SPINNING; send_syscall(&req2, cpu, pid, &res); +#ifdef PROFILE_ENABLE + profile_event_add(PROFILE_remote_page_fault, + (rdtsc() - t_s)); +#endif // PROFILE_ENABLE } if (res.status == STATUS_SYACALL) { @@ -9382,7 +9399,7 @@ long syscall(int num, ihk_mc_user_context_t *ctx) } #ifdef PROFILE_ENABLE - if (thread->profile) { + { unsigned long ts = rdtsc(); /*