flush instruction cache at context switch time if necessary

Change-Id: Ic09415ea772a9de6dca43a98168a8346ca86d3e7
This commit is contained in:
Balazs Gerofi
2019-08-04 23:31:47 +00:00
committed by Masamichi Takagi
parent f0bc1a6b07
commit 2dd8687974
7 changed files with 32 additions and 0 deletions

View File

@ -73,6 +73,7 @@ struct cpu_local_var {
ihk_spinlock_t runq_lock;
unsigned long runq_irqstate;
struct thread *current;
int prevpid;
struct list_head runq;
size_t runq_len;
size_t runq_reserved; /* Number of threads which are about to be added to runq */

View File

@ -3324,6 +3324,7 @@ void schedule(void)
struct thread *next, *prev, *thread, *tmp = NULL;
int switch_ctx = 0;
struct thread *last;
int prevpid;
if (cpu_local_var(no_preempt)) {
kprintf("%s: WARNING can't schedule() while no preemption, cnt: %d\n",
@ -3337,6 +3338,7 @@ void schedule(void)
next = NULL;
prev = v->current;
prevpid = v->prevpid;
v->flags &= ~CPU_FLAG_NEED_RESCHED;
@ -3381,6 +3383,8 @@ void schedule(void)
if (prev != next) {
switch_ctx = 1;
v->prevpid = v->current && v->current->proc ?
v->current->proc->pid : 0;
v->current = next;
reset_cputime();
}
@ -3420,6 +3424,18 @@ void schedule(void)
next->vm->address_space->page_table)
ihk_mc_load_page_table(next->vm->address_space->page_table);
/*
* Unless switching to a thread in the same process,
* to the idle thread, or to the same process that ran
* before the idle, clear the instruction cache.
*/
if ((prev && prev->proc != next->proc) &&
next != &cpu_local_var(idle) &&
(prevpid != next->proc->pid ||
prev != &cpu_local_var(idle))) {
arch_flush_icache_all();
}
last = arch_switch_context(prev, next);
/*
@ -3433,6 +3449,8 @@ void schedule(void)
cpu_local_var(runq_irqstate));
if ((last != NULL) && (last->status == PS_EXITED)) {
v->prevpid = 0;
arch_flush_icache_all();
release_thread(last);
rusage_num_threads_dec();
#ifdef RUSAGE_DEBUG