Add set_cputime() kernel to kernel case and mode enum.

Change-Id: Id4584389f39f255335d3bf7b5606f054f108ad51
Fujitsu: POSTK_DEBUG_TEMP_FIX_84
This commit is contained in:
Shiratori, Takehiro
2018-11-22 17:17:39 +09:00
committed by Masamichi Takagi
parent c585a37440
commit dc1f96fee3
4 changed files with 36 additions and 25 deletions

View File

@ -889,7 +889,8 @@ void handle_interrupt(int vector, struct x86_user_context *regs)
lapic_ack(); lapic_ack();
++v->in_interrupt; ++v->in_interrupt;
set_cputime(interrupt_from_user(regs)? 1: 2); set_cputime(interrupt_from_user(regs) ?
CPUTIME_MODE_U2K : CPUTIME_MODE_K2K_IN);
dkprintf("CPU[%d] got interrupt, vector: %d, RIP: 0x%lX\n", dkprintf("CPU[%d] got interrupt, vector: %d, RIP: 0x%lX\n",
ihk_mc_get_processor_id(), vector, regs->gpr.rip); ihk_mc_get_processor_id(), vector, regs->gpr.rip);
@ -1004,7 +1005,8 @@ void handle_interrupt(int vector, struct x86_user_context *regs)
} }
interrupt_exit(regs); interrupt_exit(regs);
set_cputime(interrupt_from_user(regs)? 0: 1); set_cputime(interrupt_from_user(regs) ?
CPUTIME_MODE_K2U : CPUTIME_MODE_K2K_OUT);
--v->in_interrupt; --v->in_interrupt;
@ -1017,7 +1019,8 @@ void handle_interrupt(int vector, struct x86_user_context *regs)
void gpe_handler(struct x86_user_context *regs) void gpe_handler(struct x86_user_context *regs)
{ {
set_cputime(interrupt_from_user(regs)? 1: 2); set_cputime(interrupt_from_user(regs) ?
CPUTIME_MODE_U2K : CPUTIME_MODE_K2K_IN);
kprintf("General protection fault (err: %lx, %lx:%lx)\n", kprintf("General protection fault (err: %lx, %lx:%lx)\n",
regs->gpr.error, regs->gpr.cs, regs->gpr.rip); regs->gpr.error, regs->gpr.cs, regs->gpr.rip);
arch_show_interrupt_context(regs); arch_show_interrupt_context(regs);
@ -1026,7 +1029,8 @@ void gpe_handler(struct x86_user_context *regs)
} }
set_signal(SIGSEGV, regs, NULL); set_signal(SIGSEGV, regs, NULL);
interrupt_exit(regs); interrupt_exit(regs);
set_cputime(interrupt_from_user(regs)? 0: 1); set_cputime(interrupt_from_user(regs) ?
CPUTIME_MODE_K2U : CPUTIME_MODE_K2K_OUT);
panic("GPF"); panic("GPF");
} }
@ -1036,7 +1040,8 @@ void debug_handler(struct x86_user_context *regs)
int si_code = 0; int si_code = 0;
struct siginfo info; struct siginfo info;
set_cputime(interrupt_from_user(regs)? 1: 2); set_cputime(interrupt_from_user(regs) ?
CPUTIME_MODE_U2K : CPUTIME_MODE_K2K_IN);
#ifdef DEBUG_PRINT_CPU #ifdef DEBUG_PRINT_CPU
kprintf("debug exception (err: %lx, %lx:%lx)\n", kprintf("debug exception (err: %lx, %lx:%lx)\n",
regs->gpr.error, regs->gpr.cs, regs->gpr.rip); regs->gpr.error, regs->gpr.cs, regs->gpr.rip);
@ -1055,14 +1060,16 @@ void debug_handler(struct x86_user_context *regs)
info.si_code = si_code; info.si_code = si_code;
set_signal(SIGTRAP, regs, &info); set_signal(SIGTRAP, regs, &info);
interrupt_exit(regs); interrupt_exit(regs);
set_cputime(interrupt_from_user(regs)? 0: 1); set_cputime(interrupt_from_user(regs) ?
CPUTIME_MODE_K2U : CPUTIME_MODE_K2K_OUT);
} }
void int3_handler(struct x86_user_context *regs) void int3_handler(struct x86_user_context *regs)
{ {
struct siginfo info; struct siginfo info;
set_cputime(interrupt_from_user(regs)? 1: 2); set_cputime(interrupt_from_user(regs) ?
CPUTIME_MODE_U2K : CPUTIME_MODE_K2K_IN);
#ifdef DEBUG_PRINT_CPU #ifdef DEBUG_PRINT_CPU
kprintf("int3 exception (err: %lx, %lx:%lx)\n", kprintf("int3 exception (err: %lx, %lx:%lx)\n",
regs->gpr.error, regs->gpr.cs, regs->gpr.rip); regs->gpr.error, regs->gpr.cs, regs->gpr.rip);
@ -1073,7 +1080,8 @@ void int3_handler(struct x86_user_context *regs)
info.si_code = TRAP_BRKPT; info.si_code = TRAP_BRKPT;
set_signal(SIGTRAP, regs, &info); set_signal(SIGTRAP, regs, &info);
interrupt_exit(regs); interrupt_exit(regs);
set_cputime(interrupt_from_user(regs)? 0: 1); set_cputime(interrupt_from_user(regs) ?
CPUTIME_MODE_K2U : CPUTIME_MODE_K2K_OUT);
} }
void void

View File

@ -465,7 +465,13 @@ static inline unsigned long timespec_to_jiffy(const struct timespec *ats)
} }
void reset_cputime(void); void reset_cputime(void);
void set_cputime(int mode); enum set_cputime_mode {
CPUTIME_MODE_K2U = 0,
CPUTIME_MODE_U2K,
CPUTIME_MODE_K2K_IN,
CPUTIME_MODE_K2K_OUT,
};
void set_cputime(enum set_cputime_mode mode);
int do_munmap(void *addr, size_t len, int holding_memory_range_lock); int do_munmap(void *addr, size_t len, int holding_memory_range_lock);
intptr_t do_mmap(uintptr_t addr0, size_t len0, int prot, int flags, int fd, intptr_t do_mmap(uintptr_t addr0, size_t len0, int prot, int flags, int fd,
off_t off0); off_t off0);

View File

@ -1158,7 +1158,8 @@ static void page_fault_handler(void *fault_addr, uint64_t reason, void *regs)
t_s = rdtsc(); t_s = rdtsc();
#endif // PROFILE_ENABLE #endif // PROFILE_ENABLE
set_cputime(interrupt_from_user(regs)? 1: 2); set_cputime(interrupt_from_user(regs) ?
CPUTIME_MODE_U2K : CPUTIME_MODE_K2K_IN);
dkprintf("%s: addr: %p, reason: %lx, regs: %p\n", dkprintf("%s: addr: %p, reason: %lx, regs: %p\n",
__FUNCTION__, fault_addr, reason, regs); __FUNCTION__, fault_addr, reason, regs);
@ -1219,7 +1220,8 @@ out:
check_need_resched(); check_need_resched();
check_signal(0, regs, -1); check_signal(0, regs, -1);
} }
set_cputime(interrupt_from_user(regs)? 0: 1); set_cputime(interrupt_from_user(regs) ?
CPUTIME_MODE_K2U : CPUTIME_MODE_K2K_OUT);
#ifdef PROFILE_ENABLE #ifdef PROFILE_ENABLE
if (thread->profile) if (thread->profile)
profile_event_add(PROFILE_page_fault, (rdtsc() - t_s)); profile_event_add(PROFILE_page_fault, (rdtsc() - t_s));

View File

@ -9574,13 +9574,8 @@ reset_cputime()
thread->base_tsc = 0; thread->base_tsc = 0;
} }
/**
* mode == 0: kernel -> user
* mode == 1: user -> kernel
* mode == 2: kernel -> kernel
*/
void void
set_cputime(int mode) set_cputime(enum set_cputime_mode mode)
{ {
struct thread *thread; struct thread *thread;
unsigned long tsc; unsigned long tsc;
@ -9597,10 +9592,10 @@ set_cputime(int mode)
if(thread == &v->idle) if(thread == &v->idle)
return; return;
monitor = v->monitor; monitor = v->monitor;
if(mode == 0){ if (mode == CPUTIME_MODE_K2U) {
monitor->status = IHK_OS_MONITOR_USER; monitor->status = IHK_OS_MONITOR_USER;
} }
else if(mode == 1){ else if (mode == CPUTIME_MODE_U2K) {
monitor->counter++; monitor->counter++;
monitor->status = IHK_OS_MONITOR_KERNEL; monitor->status = IHK_OS_MONITOR_KERNEL;
} }
@ -9617,7 +9612,7 @@ set_cputime(int mode)
struct timespec dts; struct timespec dts;
tsc_to_ts(dtsc, &dts); tsc_to_ts(dtsc, &dts);
if(mode == 1){ if (mode == CPUTIME_MODE_U2K) {
thread->user_tsc += dtsc; thread->user_tsc += dtsc;
v->rusage->user_tsc += dtsc; v->rusage->user_tsc += dtsc;
ts_add(&thread->itimer_virtual_value, &dts); ts_add(&thread->itimer_virtual_value, &dts);
@ -9630,7 +9625,7 @@ set_cputime(int mode)
} }
} }
if(mode == 2){ if (mode == CPUTIME_MODE_K2K_IN) {
thread->base_tsc = 0; thread->base_tsc = 0;
} }
else{ else{
@ -9638,7 +9633,7 @@ set_cputime(int mode)
} }
thread->times_update = 1; thread->times_update = 1;
thread->in_kernel = mode; thread->in_kernel = (int)mode;
if(thread->itimer_enabled){ if(thread->itimer_enabled){
struct timeval tv; struct timeval tv;
@ -9703,7 +9698,7 @@ long syscall(int num, ihk_mc_user_context_t *ctx)
#ifdef DISABLE_SCHED_YIELD #ifdef DISABLE_SCHED_YIELD
if (num != __NR_sched_yield) if (num != __NR_sched_yield)
#endif // DISABLE_SCHED_YIELD #endif // DISABLE_SCHED_YIELD
set_cputime(1); set_cputime(CPUTIME_MODE_U2K);
//kprintf("syscall=%d\n", num); //kprintf("syscall=%d\n", num);
#ifdef PROFILE_ENABLE #ifdef PROFILE_ENABLE
@ -9718,7 +9713,7 @@ long syscall(int num, ihk_mc_user_context_t *ctx)
(num != __NR_exit && num != __NR_exit_group)){ (num != __NR_exit && num != __NR_exit_group)){
save_syscall_return_value(num, -EINVAL); save_syscall_return_value(num, -EINVAL);
check_signal(-EINVAL, NULL, -1); check_signal(-EINVAL, NULL, -1);
set_cputime(0); set_cputime(CPUTIME_MODE_K2U);
return -EINVAL; return -EINVAL;
} }
@ -9812,7 +9807,7 @@ long syscall(int num, ihk_mc_user_context_t *ctx)
#ifdef DISABLE_SCHED_YIELD #ifdef DISABLE_SCHED_YIELD
if (num != __NR_sched_yield) if (num != __NR_sched_yield)
#endif // DISABLE_SCHED_YIELD #endif // DISABLE_SCHED_YIELD
set_cputime(0); set_cputime(CPUTIME_MODE_K2U);
if (thread->proc->nohost) { // mcexec termination was detected if (thread->proc->nohost) { // mcexec termination was detected
terminate(0, SIGKILL); terminate(0, SIGKILL);