set_timer: Start timer when runnable thread count is bigger than one

Change-Id: Ie32799fff2936ffc057f166db5681edccdbf5920
This commit is contained in:
Masamichi Takagi
2018-08-16 16:54:11 +09:00
parent 00a34a8ba3
commit cd00fc3a78
3 changed files with 24 additions and 7 deletions

View File

@@ -837,7 +837,7 @@ void process_unlock(struct process *proc, struct mcs_rwlock_node_irqsave *lock);
void chain_process(struct process *);
void chain_thread(struct thread *);
void proc_init(void);
void set_timer(void);
void set_timer(int runq_locked);
struct sig_pending *hassigpending(struct thread *thread);
void release_fp_regs(struct thread *proc);

View File

@@ -3063,13 +3063,26 @@ ack:
ihk_mc_spinlock_unlock(&cur_v->migq_lock, irqstate);
}
void
set_timer()
void set_timer(int runq_locked)
{
struct cpu_local_var *v = get_this_cpu_local_var();
struct thread *thread;
int num_running = 0;
unsigned long irqstate;
if (!runq_locked) {
irqstate = ihk_mc_spinlock_lock(&(v->runq_lock));
}
list_for_each_entry(thread, &v->runq, sched_list) {
if (thread->status != PS_RUNNING) {
continue;
}
num_running++;
}
/* Toggle timesharing if CPU core is oversubscribed */
if (v->runq_len > 1 || v->current->itimer_enabled) {
if (num_running > 1 || v->current->itimer_enabled) {
if (!cpu_local_var(timer_enabled)) {
lapic_timer_enable(/*10000000*/1000000);
cpu_local_var(timer_enabled) = 1;
@@ -3081,6 +3094,10 @@ set_timer()
cpu_local_var(timer_enabled) = 0;
}
}
if (!runq_locked) {
ihk_mc_spinlock_unlock(&(v->runq_lock), irqstate);
}
}
/*
@@ -3222,7 +3239,7 @@ void schedule(void)
reset_cputime();
}
set_timer();
set_timer(1);
if (switch_ctx) {
dkprintf("schedule: %d => %d \n",

View File

@@ -7050,7 +7050,7 @@ SYSCALL_DECLARE(setitimer)
timer_start = 0;
}
thread->itimer_enabled = timer_start;
set_timer();
set_timer(0);
return 0;
}
@@ -9499,7 +9499,7 @@ set_cputime(int mode)
thread->itimer_prof.it_value.tv_sec == 0 &&
thread->itimer_prof.it_value.tv_usec == 0){
thread->itimer_enabled = 0;
set_timer();
set_timer(0);
}
}
}