Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TLB to bypass the second stage translation(GPA to HPA) #179

Open
wants to merge 24 commits into
base: master
Choose a base branch
from

Conversation

BL-GS
Copy link
Contributor

@BL-GS BL-GS commented Sep 14, 2023

The origin 2-stage translation do not utilize TLB but walk the whole translation path, which consume a lot. I add a HOSTVMTLB for the translation from GPA to HPA.
Otherwise, I also add a TLB mapping GVA to PA.
The effect of acceleration depends on how long the VM stays. By test, it accelerates xvisor workload by 300%, and keep almost the same speed under KVM workload.

@@ -801,24 +804,24 @@ static word_t priv_instr(uint32_t op, const rtlreg_t *src) {
if(cpu.v) longjmp_exception(EX_VI);
if(cpu.mode == MODE_U) longjmp_exception(EX_II);
if(!(cpu.mode == MODE_M || (cpu.mode == MODE_S && !cpu.v))) longjmp_exception(EX_II);
mmu_tlb_flush(*src);
mmu_vmtlb_flush(*src);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read the function of "hfence.vvma" in the RISC-V Instruction Set Manual
Volume II: Privileged Architecture

break;
#ifdef CONFIG_RV_SVINVAL
case 0x13: // hinval.vvma
if(cpu.v) longjmp_exception(EX_VI);
if(cpu.mode == MODE_U) longjmp_exception(EX_II);
mmu_tlb_flush(*src);
mmu_vmtlb_flush(*src);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read the function of "hinval.vvma" in the RISC-V Instruction Set Manual
Volume II: Privileged Architecture

e->offset = guest_to_host(paddr) - vaddr;
e->gvpn = hosttlb_vpn(vaddr);
hosttlb_insert(vaddr, paddr, type);
hosttlb_insert(vaddr, paddr, type);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

insert tlb twice?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the problem about merging, I have fixed it.

extern bool has_two_stage_translation();
if(has_two_stage_translation()){
if (has_two_stage_translation()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason why I put two stage translation in this place is to skip tlb translation when NEMU don't have tlb for the second stage. If you add the second stage tlb to NEMU, you should change these codes.

Copy link
Contributor Author

@BL-GS BL-GS Oct 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I only add the TLB for the second stage, which means it still need to skip previous host tlb lookup(va -> pa).

P.S.
Maybe I can add a TLB mapping GVA to GPA. However, this cannot avoid adding judgement here. And I don't think adding this will effectively improve the performance because there will be another large table to be flushed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants