Skip to content

Commit eae570b

Browse files
committed
target/loongarch: Use loongarch_tlb_search_cb in helper_invtlb_page_asid
With function helper_invtlb_page_asid(), currently it is to search TLB entry one by one. Instead STLB can be searched at first with hash method, and then search MTLB with one by one method Here common API loongarch_tlb_search_cb() is used in function helper_invtlb_page_asid() Signed-off-by: Bibo Mao <maobibo@loongson.cn> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
1 parent 96e654c commit eae570b

File tree

1 file changed

+13
-23
lines changed

1 file changed

+13
-23
lines changed

target/loongarch/tcg/tlb_helper.c

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ static bool tlb_match_any(bool global, int asid, int tlb_asid)
2828
return global || tlb_asid == asid;
2929
}
3030

31+
static bool tlb_match_asid(bool global, int asid, int tlb_asid)
32+
{
33+
return !global && tlb_asid == asid;
34+
}
35+
3136
bool check_ps(CPULoongArchState *env, uint8_t tlb_ps)
3237
{
3338
if (tlb_ps >= 64) {
@@ -529,31 +534,16 @@ void helper_invtlb_all_asid(CPULoongArchState *env, target_ulong info)
529534
void helper_invtlb_page_asid(CPULoongArchState *env, target_ulong info,
530535
target_ulong addr)
531536
{
532-
uint16_t asid = info & 0x3ff;
533-
534-
for (int i = 0; i < LOONGARCH_TLB_MAX; i++) {
535-
LoongArchTLB *tlb = &env->tlb[i];
536-
uint8_t tlb_g = FIELD_EX64(tlb->tlb_entry0, TLBENTRY, G);
537-
uint16_t tlb_asid = FIELD_EX64(tlb->tlb_misc, TLB_MISC, ASID);
538-
uint64_t vpn, tlb_vppn;
539-
uint8_t tlb_ps, compare_shift;
540-
uint8_t tlb_e = FIELD_EX64(tlb->tlb_misc, TLB_MISC, E);
541-
542-
if (!tlb_e) {
543-
continue;
544-
}
545-
546-
tlb_ps = FIELD_EX64(tlb->tlb_misc, TLB_MISC, PS);
547-
tlb_vppn = FIELD_EX64(tlb->tlb_misc, TLB_MISC, VPPN);
548-
vpn = (addr & TARGET_VIRT_MASK) >> (tlb_ps + 1);
549-
compare_shift = tlb_ps + 1 - R_TLB_MISC_VPPN_SHIFT;
537+
int asid = info & 0x3ff;
538+
LoongArchTLB *tlb;
539+
tlb_match func;
550540

551-
if (!tlb_g && (tlb_asid == asid) &&
552-
(vpn == (tlb_vppn >> compare_shift))) {
553-
tlb->tlb_misc = FIELD_DP64(tlb->tlb_misc, TLB_MISC, E, 0);
554-
}
541+
func = tlb_match_asid;
542+
tlb = loongarch_tlb_search_cb(env, addr, asid, func);
543+
if (tlb) {
544+
tlb->tlb_misc = FIELD_DP64(tlb->tlb_misc, TLB_MISC, E, 0);
545+
tlb_flush(env_cpu(env));
555546
}
556-
tlb_flush(env_cpu(env));
557547
}
558548

559549
void helper_invtlb_page_asid_or_g(CPULoongArchState *env,

0 commit comments

Comments
 (0)