From 5e5c0826b9623398a220b06fa37a0e5abf93be1a Mon Sep 17 00:00:00 2001 From: Mark Johnston Date: Wed, 1 Feb 2023 14:04:17 -0500 Subject: [PATCH 46/52] mips: Make it possible to dump the TLB on remote CPUs Now one sets debug.dump_tlb to the ID of the target CPU. --- sys/mips/mips/tlb.c | 46 ++++++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/sys/mips/mips/tlb.c b/sys/mips/mips/tlb.c index f0df25fddc79..284493b92a41 100644 --- a/sys/mips/mips/tlb.c +++ b/sys/mips/mips/tlb.c @@ -391,28 +391,17 @@ tlb_invalidate_one(unsigned i) tlb_write_indexed(); } -static int -tlb_sysctl(SYSCTL_HANDLER_ARGS) +static void +dump_tlb(void *arg __unused) { struct tlb_state *tlbs; - struct tlb_entry *tlbe; register_t s; - int error, val; - - val = 0; - error = sysctl_handle_int(oidp, &val, sizeof(val), req); - if (error != 0 || req->newptr == NULL || val == 0) - return (error); - - if (num_tlbentries > MIPS_MAX_TLB_ENTRIES) { - printf("num entries %d is larger than max\n", num_tlbentries); - return (EINVAL); - } s = intr_disable(); tlb_save(); tlbs = &tlb_state[curcpu]; for (int i = 0; i < num_tlbentries; i++) { + struct tlb_entry *tlbe; const char *pagesize, *region; register_t asid; vm_offset_t va; @@ -454,12 +443,39 @@ tlb_sysctl(SYSCTL_HANDLER_ARGS) TLBLO_PTE_TO_PA(tlbe->entrylo1)); } intr_restore(s); +} + +static int +tlb_sysctl(SYSCTL_HANDLER_ARGS) +{ + cpuset_t cpus; + int error, val; + + val = curcpu; + error = sysctl_handle_int(oidp, &val, sizeof(val), req); + if (error != 0 || req->newptr == NULL) + return (error); + + if (val < 0 || val > mp_maxid || CPU_ABSENT(val)) { + printf("invalid cpuid %d\n", val); + return (EINVAL); + } + + if (num_tlbentries > MIPS_MAX_TLB_ENTRIES) { + printf("num entries %d is larger than max\n", num_tlbentries); + return (EINVAL); + } + + CPU_ZERO(&cpus); + CPU_SET(val, &cpus); + smp_rendezvous_cpus(cpus, smp_no_rendezvous_barrier, dump_tlb, + smp_no_rendezvous_barrier, NULL); return (0); } SYSCTL_PROC(_debug, OID_AUTO, dump_tlb, CTLTYPE_INT | CTLFLAG_MPSAFE | CTLFLAG_RW, - 0, 0, tlb_sysctl, "I", "Dump current CPU's TLB entries"); + 0, 0, tlb_sysctl, "I", "Dump TLB entries from the specified CPU"); #ifdef DDB #include -- 2.41.0