]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/amd64/amd64/mp_machdep.c
Update LLDB snapshot to upstream r241361
[FreeBSD/FreeBSD.git] / sys / amd64 / amd64 / mp_machdep.c
1 /*-
2  * Copyright (c) 1996, by Steve Passe
3  * Copyright (c) 2003, by Peter Wemm
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. The name of the developer may NOT be used to endorse or promote products
12  *    derived from this software without specific prior written permission.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  */
26
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
29
30 #include "opt_cpu.h"
31 #include "opt_ddb.h"
32 #include "opt_kstack_pages.h"
33 #include "opt_sched.h"
34 #include "opt_smp.h"
35
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/bus.h>
39 #include <sys/cpuset.h>
40 #ifdef GPROF 
41 #include <sys/gmon.h>
42 #endif
43 #include <sys/kernel.h>
44 #include <sys/ktr.h>
45 #include <sys/lock.h>
46 #include <sys/malloc.h>
47 #include <sys/memrange.h>
48 #include <sys/mutex.h>
49 #include <sys/pcpu.h>
50 #include <sys/proc.h>
51 #include <sys/sched.h>
52 #include <sys/smp.h>
53 #include <sys/sysctl.h>
54
55 #include <vm/vm.h>
56 #include <vm/vm_param.h>
57 #include <vm/pmap.h>
58 #include <vm/vm_kern.h>
59 #include <vm/vm_extern.h>
60
61 #include <x86/apicreg.h>
62 #include <machine/clock.h>
63 #include <machine/cputypes.h>
64 #include <machine/cpufunc.h>
65 #include <x86/mca.h>
66 #include <machine/md_var.h>
67 #include <machine/pcb.h>
68 #include <machine/psl.h>
69 #include <machine/smp.h>
70 #include <machine/specialreg.h>
71 #include <machine/tss.h>
72 #include <machine/cpu.h>
73 #include <x86/init.h>
74
75 #define WARMBOOT_TARGET         0
76 #define WARMBOOT_OFF            (KERNBASE + 0x0467)
77 #define WARMBOOT_SEG            (KERNBASE + 0x0469)
78
79 #define CMOS_REG                (0x70)
80 #define CMOS_DATA               (0x71)
81 #define BIOS_RESET              (0x0f)
82 #define BIOS_WARM               (0x0a)
83
84 extern  struct pcpu __pcpu[];
85
86 /* Temporary variables for init_secondary()  */
87 char *doublefault_stack;
88 char *nmi_stack;
89
90 /* Variables needed for SMP tlb shootdown. */
91 static vm_offset_t smp_tlb_addr1, smp_tlb_addr2;
92 static pmap_t smp_tlb_pmap;
93 volatile int smp_tlb_wait;
94
95 extern inthand_t IDTVEC(fast_syscall), IDTVEC(fast_syscall32);
96
97 /*
98  * Local data and functions.
99  */
100
101 static int      start_ap(int apic_id);
102
103 static u_int    bootMP_size;
104 static u_int    boot_address;
105
106 /*
107  * Calculate usable address in base memory for AP trampoline code.
108  */
109 u_int
110 mp_bootaddress(u_int basemem)
111 {
112
113         bootMP_size = mptramp_end - mptramp_start;
114         boot_address = trunc_page(basemem * 1024); /* round down to 4k boundary */
115         if (((basemem * 1024) - boot_address) < bootMP_size)
116                 boot_address -= PAGE_SIZE;      /* not enough, lower by 4k */
117         /* 3 levels of page table pages */
118         mptramp_pagetables = boot_address - (PAGE_SIZE * 3);
119
120         return mptramp_pagetables;
121 }
122
123 /*
124  * Initialize the IPI handlers and start up the AP's.
125  */
126 void
127 cpu_mp_start(void)
128 {
129         int i;
130
131         /* Initialize the logical ID to APIC ID table. */
132         for (i = 0; i < MAXCPU; i++) {
133                 cpu_apic_ids[i] = -1;
134                 cpu_ipi_pending[i] = 0;
135         }
136
137         /* Install an inter-CPU IPI for TLB invalidation */
138         if (pmap_pcid_enabled) {
139                 if (invpcid_works) {
140                         setidt(IPI_INVLTLB, IDTVEC(invltlb_invpcid),
141                             SDT_SYSIGT, SEL_KPL, 0);
142                 } else {
143                         setidt(IPI_INVLTLB, IDTVEC(invltlb_pcid), SDT_SYSIGT,
144                             SEL_KPL, 0);
145                 }
146         } else {
147                 setidt(IPI_INVLTLB, IDTVEC(invltlb), SDT_SYSIGT, SEL_KPL, 0);
148         }
149         setidt(IPI_INVLPG, IDTVEC(invlpg), SDT_SYSIGT, SEL_KPL, 0);
150         setidt(IPI_INVLRNG, IDTVEC(invlrng), SDT_SYSIGT, SEL_KPL, 0);
151
152         /* Install an inter-CPU IPI for cache invalidation. */
153         setidt(IPI_INVLCACHE, IDTVEC(invlcache), SDT_SYSIGT, SEL_KPL, 0);
154
155         /* Install an inter-CPU IPI for all-CPU rendezvous */
156         setidt(IPI_RENDEZVOUS, IDTVEC(rendezvous), SDT_SYSIGT, SEL_KPL, 0);
157
158         /* Install generic inter-CPU IPI handler */
159         setidt(IPI_BITMAP_VECTOR, IDTVEC(ipi_intr_bitmap_handler),
160                SDT_SYSIGT, SEL_KPL, 0);
161
162         /* Install an inter-CPU IPI for CPU stop/restart */
163         setidt(IPI_STOP, IDTVEC(cpustop), SDT_SYSIGT, SEL_KPL, 0);
164
165         /* Install an inter-CPU IPI for CPU suspend/resume */
166         setidt(IPI_SUSPEND, IDTVEC(cpususpend), SDT_SYSIGT, SEL_KPL, 0);
167
168         /* Set boot_cpu_id if needed. */
169         if (boot_cpu_id == -1) {
170                 boot_cpu_id = PCPU_GET(apic_id);
171                 cpu_info[boot_cpu_id].cpu_bsp = 1;
172         } else
173                 KASSERT(boot_cpu_id == PCPU_GET(apic_id),
174                     ("BSP's APIC ID doesn't match boot_cpu_id"));
175
176         /* Probe logical/physical core configuration. */
177         topo_probe();
178
179         assign_cpu_ids();
180
181         /* Start each Application Processor */
182         init_ops.start_all_aps();
183
184         set_interrupt_apic_ids();
185 }
186
187
188 /*
189  * AP CPU's call this to initialize themselves.
190  */
191 void
192 init_secondary(void)
193 {
194         struct pcpu *pc;
195         struct nmi_pcpu *np;
196         u_int64_t msr, cr0;
197         int cpu, gsel_tss, x;
198         struct region_descriptor ap_gdt;
199
200         /* Set by the startup code for us to use */
201         cpu = bootAP;
202
203         /* Init tss */
204         common_tss[cpu] = common_tss[0];
205         common_tss[cpu].tss_rsp0 = 0;   /* not used until after switch */
206         common_tss[cpu].tss_iobase = sizeof(struct amd64tss) +
207             IOPERM_BITMAP_SIZE;
208         common_tss[cpu].tss_ist1 = (long)&doublefault_stack[PAGE_SIZE];
209
210         /* The NMI stack runs on IST2. */
211         np = ((struct nmi_pcpu *) &nmi_stack[PAGE_SIZE]) - 1;
212         common_tss[cpu].tss_ist2 = (long) np;
213
214         /* Prepare private GDT */
215         gdt_segs[GPROC0_SEL].ssd_base = (long) &common_tss[cpu];
216         for (x = 0; x < NGDT; x++) {
217                 if (x != GPROC0_SEL && x != (GPROC0_SEL + 1) &&
218                     x != GUSERLDT_SEL && x != (GUSERLDT_SEL + 1))
219                         ssdtosd(&gdt_segs[x], &gdt[NGDT * cpu + x]);
220         }
221         ssdtosyssd(&gdt_segs[GPROC0_SEL],
222             (struct system_segment_descriptor *)&gdt[NGDT * cpu + GPROC0_SEL]);
223         ap_gdt.rd_limit = NGDT * sizeof(gdt[0]) - 1;
224         ap_gdt.rd_base =  (long) &gdt[NGDT * cpu];
225         lgdt(&ap_gdt);                  /* does magic intra-segment return */
226
227         /* Get per-cpu data */
228         pc = &__pcpu[cpu];
229
230         /* prime data page for it to use */
231         pcpu_init(pc, cpu, sizeof(struct pcpu));
232         dpcpu_init(dpcpu, cpu);
233         pc->pc_apic_id = cpu_apic_ids[cpu];
234         pc->pc_prvspace = pc;
235         pc->pc_curthread = 0;
236         pc->pc_tssp = &common_tss[cpu];
237         pc->pc_commontssp = &common_tss[cpu];
238         pc->pc_rsp0 = 0;
239         pc->pc_tss = (struct system_segment_descriptor *)&gdt[NGDT * cpu +
240             GPROC0_SEL];
241         pc->pc_fs32p = &gdt[NGDT * cpu + GUFS32_SEL];
242         pc->pc_gs32p = &gdt[NGDT * cpu + GUGS32_SEL];
243         pc->pc_ldt = (struct system_segment_descriptor *)&gdt[NGDT * cpu +
244             GUSERLDT_SEL];
245         pc->pc_curpmap = kernel_pmap;
246         pc->pc_pcid_gen = 1;
247         pc->pc_pcid_next = PMAP_PCID_KERN + 1;
248
249         /* Save the per-cpu pointer for use by the NMI handler. */
250         np->np_pcpu = (register_t) pc;
251
252         wrmsr(MSR_FSBASE, 0);           /* User value */
253         wrmsr(MSR_GSBASE, (u_int64_t)pc);
254         wrmsr(MSR_KGSBASE, (u_int64_t)pc);      /* XXX User value while we're in the kernel */
255
256         lidt(&r_idt);
257
258         gsel_tss = GSEL(GPROC0_SEL, SEL_KPL);
259         ltr(gsel_tss);
260
261         /*
262          * Set to a known state:
263          * Set by mpboot.s: CR0_PG, CR0_PE
264          * Set by cpu_setregs: CR0_NE, CR0_MP, CR0_TS, CR0_WP, CR0_AM
265          */
266         cr0 = rcr0();
267         cr0 &= ~(CR0_CD | CR0_NW | CR0_EM);
268         load_cr0(cr0);
269
270         /* Set up the fast syscall stuff */
271         msr = rdmsr(MSR_EFER) | EFER_SCE;
272         wrmsr(MSR_EFER, msr);
273         wrmsr(MSR_LSTAR, (u_int64_t)IDTVEC(fast_syscall));
274         wrmsr(MSR_CSTAR, (u_int64_t)IDTVEC(fast_syscall32));
275         msr = ((u_int64_t)GSEL(GCODE_SEL, SEL_KPL) << 32) |
276               ((u_int64_t)GSEL(GUCODE32_SEL, SEL_UPL) << 48);
277         wrmsr(MSR_STAR, msr);
278         wrmsr(MSR_SF_MASK, PSL_NT|PSL_T|PSL_I|PSL_C|PSL_D);
279
280         /* signal our startup to the BSP. */
281         mp_naps++;
282
283         /* Spin until the BSP releases the AP's. */
284         while (!aps_ready)
285                 ia32_pause();
286
287         init_secondary_tail();
288 }
289
290 /*******************************************************************
291  * local functions and data
292  */
293
294 /*
295  * start each AP in our list
296  */
297 int
298 native_start_all_aps(void)
299 {
300         vm_offset_t va = boot_address + KERNBASE;
301         u_int64_t *pt4, *pt3, *pt2;
302         u_int32_t mpbioswarmvec;
303         int apic_id, cpu, i;
304         u_char mpbiosreason;
305
306         mtx_init(&ap_boot_mtx, "ap boot", NULL, MTX_SPIN);
307
308         /* install the AP 1st level boot code */
309         pmap_kenter(va, boot_address);
310         pmap_invalidate_page(kernel_pmap, va);
311         bcopy(mptramp_start, (void *)va, bootMP_size);
312
313         /* Locate the page tables, they'll be below the trampoline */
314         pt4 = (u_int64_t *)(uintptr_t)(mptramp_pagetables + KERNBASE);
315         pt3 = pt4 + (PAGE_SIZE) / sizeof(u_int64_t);
316         pt2 = pt3 + (PAGE_SIZE) / sizeof(u_int64_t);
317
318         /* Create the initial 1GB replicated page tables */
319         for (i = 0; i < 512; i++) {
320                 /* Each slot of the level 4 pages points to the same level 3 page */
321                 pt4[i] = (u_int64_t)(uintptr_t)(mptramp_pagetables + PAGE_SIZE);
322                 pt4[i] |= PG_V | PG_RW | PG_U;
323
324                 /* Each slot of the level 3 pages points to the same level 2 page */
325                 pt3[i] = (u_int64_t)(uintptr_t)(mptramp_pagetables + (2 * PAGE_SIZE));
326                 pt3[i] |= PG_V | PG_RW | PG_U;
327
328                 /* The level 2 page slots are mapped with 2MB pages for 1GB. */
329                 pt2[i] = i * (2 * 1024 * 1024);
330                 pt2[i] |= PG_V | PG_RW | PG_PS | PG_U;
331         }
332
333         /* save the current value of the warm-start vector */
334         mpbioswarmvec = *((u_int32_t *) WARMBOOT_OFF);
335         outb(CMOS_REG, BIOS_RESET);
336         mpbiosreason = inb(CMOS_DATA);
337
338         /* setup a vector to our boot code */
339         *((volatile u_short *) WARMBOOT_OFF) = WARMBOOT_TARGET;
340         *((volatile u_short *) WARMBOOT_SEG) = (boot_address >> 4);
341         outb(CMOS_REG, BIOS_RESET);
342         outb(CMOS_DATA, BIOS_WARM);     /* 'warm-start' */
343
344         /* start each AP */
345         for (cpu = 1; cpu < mp_ncpus; cpu++) {
346                 apic_id = cpu_apic_ids[cpu];
347
348                 /* allocate and set up an idle stack data page */
349                 bootstacks[cpu] = (void *)kmem_malloc(kernel_arena,
350                     KSTACK_PAGES * PAGE_SIZE, M_WAITOK | M_ZERO);
351                 doublefault_stack = (char *)kmem_malloc(kernel_arena,
352                     PAGE_SIZE, M_WAITOK | M_ZERO);
353                 nmi_stack = (char *)kmem_malloc(kernel_arena, PAGE_SIZE,
354                     M_WAITOK | M_ZERO);
355                 dpcpu = (void *)kmem_malloc(kernel_arena, DPCPU_SIZE,
356                     M_WAITOK | M_ZERO);
357
358                 bootSTK = (char *)bootstacks[cpu] + KSTACK_PAGES * PAGE_SIZE - 8;
359                 bootAP = cpu;
360
361                 /* attempt to start the Application Processor */
362                 if (!start_ap(apic_id)) {
363                         /* restore the warmstart vector */
364                         *(u_int32_t *) WARMBOOT_OFF = mpbioswarmvec;
365                         panic("AP #%d (PHY# %d) failed!", cpu, apic_id);
366                 }
367
368                 CPU_SET(cpu, &all_cpus);        /* record AP in CPU map */
369         }
370
371         /* restore the warmstart vector */
372         *(u_int32_t *) WARMBOOT_OFF = mpbioswarmvec;
373
374         outb(CMOS_REG, BIOS_RESET);
375         outb(CMOS_DATA, mpbiosreason);
376
377         /* number of APs actually started */
378         return mp_naps;
379 }
380
381
382 /*
383  * This function starts the AP (application processor) identified
384  * by the APIC ID 'physicalCpu'.  It does quite a "song and dance"
385  * to accomplish this.  This is necessary because of the nuances
386  * of the different hardware we might encounter.  It isn't pretty,
387  * but it seems to work.
388  */
389 static int
390 start_ap(int apic_id)
391 {
392         int vector, ms;
393         int cpus;
394
395         /* calculate the vector */
396         vector = (boot_address >> 12) & 0xff;
397
398         /* used as a watchpoint to signal AP startup */
399         cpus = mp_naps;
400
401         ipi_startup(apic_id, vector);
402
403         /* Wait up to 5 seconds for it to start. */
404         for (ms = 0; ms < 5000; ms++) {
405                 if (mp_naps > cpus)
406                         return 1;       /* return SUCCESS */
407                 DELAY(1000);
408         }
409         return 0;               /* return FAILURE */
410 }
411
412 /*
413  * Flush the TLB on other CPU's
414  */
415
416 static void
417 smp_targeted_tlb_shootdown(cpuset_t mask, u_int vector, pmap_t pmap,
418     vm_offset_t addr1, vm_offset_t addr2)
419 {
420         int cpu, ncpu, othercpus;
421
422         othercpus = mp_ncpus - 1;       /* does not shootdown self */
423
424         /*
425          * Check for other cpus.  Return if none.
426          */
427         if (CPU_ISFULLSET(&mask)) {
428                 if (othercpus < 1)
429                         return;
430         } else {
431                 CPU_CLR(PCPU_GET(cpuid), &mask);
432                 if (CPU_EMPTY(&mask))
433                         return;
434         }
435
436         if (!(read_rflags() & PSL_I))
437                 panic("%s: interrupts disabled", __func__);
438         mtx_lock_spin(&smp_ipi_mtx);
439         smp_tlb_addr1 = addr1;
440         smp_tlb_addr2 = addr2;
441         smp_tlb_pmap = pmap;
442         atomic_store_rel_int(&smp_tlb_wait, 0);
443         if (CPU_ISFULLSET(&mask)) {
444                 ncpu = othercpus;
445                 ipi_all_but_self(vector);
446         } else {
447                 ncpu = 0;
448                 while ((cpu = CPU_FFS(&mask)) != 0) {
449                         cpu--;
450                         CPU_CLR(cpu, &mask);
451                         CTR3(KTR_SMP, "%s: cpu: %d ipi: %x", __func__,
452                             cpu, vector);
453                         ipi_send_cpu(cpu, vector);
454                         ncpu++;
455                 }
456         }
457         while (smp_tlb_wait < ncpu)
458                 ia32_pause();
459         mtx_unlock_spin(&smp_ipi_mtx);
460 }
461
462 void
463 smp_masked_invltlb(cpuset_t mask, pmap_t pmap)
464 {
465
466         if (smp_started) {
467                 smp_targeted_tlb_shootdown(mask, IPI_INVLTLB, pmap, 0, 0);
468 #ifdef COUNT_XINVLTLB_HITS
469                 ipi_global++;
470 #endif
471         }
472 }
473
474 void
475 smp_masked_invlpg(cpuset_t mask, vm_offset_t addr)
476 {
477
478         if (smp_started) {
479                 smp_targeted_tlb_shootdown(mask, IPI_INVLPG, NULL, addr, 0);
480 #ifdef COUNT_XINVLTLB_HITS
481                 ipi_page++;
482 #endif
483         }
484 }
485
486 void
487 smp_masked_invlpg_range(cpuset_t mask, vm_offset_t addr1, vm_offset_t addr2)
488 {
489
490         if (smp_started) {
491                 smp_targeted_tlb_shootdown(mask, IPI_INVLRNG, NULL,
492                     addr1, addr2);
493 #ifdef COUNT_XINVLTLB_HITS
494                 ipi_range++;
495                 ipi_range_size += (addr2 - addr1) / PAGE_SIZE;
496 #endif
497         }
498 }
499
500 void
501 smp_cache_flush(void)
502 {
503
504         if (smp_started) {
505                 smp_targeted_tlb_shootdown(all_cpus, IPI_INVLCACHE, NULL,
506                     0, 0);
507         }
508 }
509
510 /*
511  * Handlers for TLB related IPIs
512  */
513 void
514 invltlb_handler(void)
515 {
516 #ifdef COUNT_XINVLTLB_HITS
517         xhits_gbl[PCPU_GET(cpuid)]++;
518 #endif /* COUNT_XINVLTLB_HITS */
519 #ifdef COUNT_IPIS
520         (*ipi_invltlb_counts[PCPU_GET(cpuid)])++;
521 #endif /* COUNT_IPIS */
522
523         invltlb();
524         atomic_add_int(&smp_tlb_wait, 1);
525 }
526
527 void
528 invltlb_invpcid_handler(void)
529 {
530         struct invpcid_descr d;
531
532 #ifdef COUNT_XINVLTLB_HITS
533         xhits_gbl[PCPU_GET(cpuid)]++;
534 #endif /* COUNT_XINVLTLB_HITS */
535 #ifdef COUNT_IPIS
536         (*ipi_invltlb_counts[PCPU_GET(cpuid)])++;
537 #endif /* COUNT_IPIS */
538
539         d.pcid = smp_tlb_pmap->pm_pcids[PCPU_GET(cpuid)].pm_pcid;
540         d.pad = 0;
541         d.addr = 0;
542         invpcid(&d, smp_tlb_pmap == kernel_pmap ? INVPCID_CTXGLOB :
543             INVPCID_CTX);
544         atomic_add_int(&smp_tlb_wait, 1);
545 }
546
547 void
548 invltlb_pcid_handler(void)
549 {
550 #ifdef COUNT_XINVLTLB_HITS
551         xhits_gbl[PCPU_GET(cpuid)]++;
552 #endif /* COUNT_XINVLTLB_HITS */
553 #ifdef COUNT_IPIS
554         (*ipi_invltlb_counts[PCPU_GET(cpuid)])++;
555 #endif /* COUNT_IPIS */
556
557         if (smp_tlb_pmap == kernel_pmap) {
558                 invltlb_globpcid();
559         } else {
560                 /*
561                  * The current pmap might not be equal to
562                  * smp_tlb_pmap.  The clearing of the pm_gen in
563                  * pmap_invalidate_all() takes care of TLB
564                  * invalidation when switching to the pmap on this
565                  * CPU.
566                  */
567                 if (PCPU_GET(curpmap) == smp_tlb_pmap) {
568                         load_cr3(smp_tlb_pmap->pm_cr3 |
569                             smp_tlb_pmap->pm_pcids[PCPU_GET(cpuid)].pm_pcid);
570                 }
571         }
572         atomic_add_int(&smp_tlb_wait, 1);
573 }
574
575 void
576 invlpg_handler(void)
577 {
578 #ifdef COUNT_XINVLTLB_HITS
579         xhits_pg[PCPU_GET(cpuid)]++;
580 #endif /* COUNT_XINVLTLB_HITS */
581 #ifdef COUNT_IPIS
582         (*ipi_invlpg_counts[PCPU_GET(cpuid)])++;
583 #endif /* COUNT_IPIS */
584
585         invlpg(smp_tlb_addr1);
586         atomic_add_int(&smp_tlb_wait, 1);
587 }
588
589 void
590 invlrng_handler(void)
591 {
592         vm_offset_t addr;
593
594 #ifdef COUNT_XINVLTLB_HITS
595         xhits_rng[PCPU_GET(cpuid)]++;
596 #endif /* COUNT_XINVLTLB_HITS */
597 #ifdef COUNT_IPIS
598         (*ipi_invlrng_counts[PCPU_GET(cpuid)])++;
599 #endif /* COUNT_IPIS */
600
601         addr = smp_tlb_addr1;
602         do {
603                 invlpg(addr);
604                 addr += PAGE_SIZE;
605         } while (addr < smp_tlb_addr2);
606
607         atomic_add_int(&smp_tlb_wait, 1);
608 }