From: Sepherosa Ziehau Date: Mon, 14 May 2018 14:35:04 +0000 (+0800) Subject: x86_64/lapic: Use function pointer for EOI. X-Git-Tag: v5.5.0~644 X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/3c38fc608f7d9d68b18b2e437a14d4365725691d x86_64/lapic: Use function pointer for EOI. This helps upcoming X2APIC support and virtualization EOI optmization, e.g. Hyper-V can be configured to do auto-EOI. Discussed-with: Imre Vadasz --- diff --git a/sys/conf/options b/sys/conf/options index db30ea7b03..257dca2748 100644 --- a/sys/conf/options +++ b/sys/conf/options @@ -535,6 +535,7 @@ KTR_IF_EMX opt_ktr.h KTR_IF_START opt_ktr.h KTR_IPIQ opt_ktr.h KTR_KERNENTRY opt_ktr.h +KTR_LAPIC opt_ktr.h KTR_MEMORY opt_ktr.h KTR_SERIALIZER opt_ktr.h KTR_SPIN_CONTENTION opt_ktr.h diff --git a/sys/platform/pc64/apic/apic_vector.s b/sys/platform/pc64/apic/apic_vector.s index c7ef77e633..5372432bcd 100644 --- a/sys/platform/pc64/apic/apic_vector.s +++ b/sys/platform/pc64/apic/apic_vector.s @@ -121,8 +121,8 @@ IDTVEC(ioapic_intr##irq_num) ; \ APIC_PUSH_FRAME_TFRIP ; \ FAKE_MCOUNT(TF_RIP(%rsp)) ; \ MASK_LEVEL_IRQ(irq_num) ; \ - movq lapic, %rax ; \ - movl $0, LA_EOI(%rax) ; \ + movq lapic_eoi, %rax ; \ + callq *%rax ; \ movq PCPU(curthread),%rbx ; \ testl $-1,TD_NEST_COUNT(%rbx) ; \ jne 1f ; \ @@ -188,8 +188,8 @@ Xspuriousint: .globl Xinvltlb Xinvltlb: APIC_PUSH_FRAME_TFRIP - movq lapic, %rax - movl $0, LA_EOI(%rax) /* End Of Interrupt to APIC */ + movq lapic_eoi, %rax + callq *%rax /* End Of Interrupt to APIC */ FAKE_MCOUNT(TF_RIP(%rsp)) incl PCPU(cnt) + V_IPI movq PCPU(curthread),%rbx @@ -213,8 +213,8 @@ Xinvltlb: .globl Xsniff Xsniff: APIC_PUSH_FRAME_TFRIP - movq lapic, %rax - movl $0, LA_EOI(%rax) /* End Of Interrupt to APIC */ + movq lapic_eoi, %rax + callq *%rax /* End Of Interrupt to APIC */ FAKE_MCOUNT(TF_RIP(%rsp)) incl PCPU(cnt) + V_IPI movq TF_RIP(%rsp),%rax @@ -239,8 +239,8 @@ Xsniff: .globl Xcpustop Xcpustop: APIC_PUSH_FRAME_TFRIP - movq lapic, %rax - movl $0, LA_EOI(%rax) /* End Of Interrupt to APIC */ + movq lapic_eoi, %rax + callq *%rax /* End Of Interrupt to APIC */ movl PCPU(cpuid), %eax imull $PCB_SIZE, %eax @@ -337,8 +337,8 @@ Xcpustop: .globl Xipiq Xipiq: APIC_PUSH_FRAME_TFRIP - movq lapic, %rax - movl $0, LA_EOI(%rax) /* End Of Interrupt to APIC */ + movq lapic_eoi, %rax + callq *%rax /* End Of Interrupt to APIC */ FAKE_MCOUNT(TF_RIP(%rsp)) incl PCPU(cnt) + V_IPI @@ -369,8 +369,8 @@ Xipiq: .globl Xtimer Xtimer: APIC_PUSH_FRAME_TFRIP - movq lapic, %rax - movl $0, LA_EOI(%rax) /* End Of Interrupt to APIC */ + movq lapic_eoi, %rax + callq *%rax /* End Of Interrupt to APIC */ FAKE_MCOUNT(TF_RIP(%rsp)) subq $8,%rsp /* make same as interrupt frame */ diff --git a/sys/platform/pc64/apic/lapic.c b/sys/platform/pc64/apic/lapic.c index e7b7cdb1f4..9d8b166e25 100644 --- a/sys/platform/pc64/apic/lapic.c +++ b/sys/platform/pc64/apic/lapic.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -49,6 +50,13 @@ #include #include +#if !defined(KTR_LAPIC) +#define KTR_LAPIC KTR_ALL +#endif +KTR_INFO_MASTER(lapic); +KTR_INFO(KTR_LAPIC, lapic, eoi, 0, "eoi"); +#define log_lapic(name) KTR_LOG(lapic_ ## name) + extern int naps; volatile lapic_t *lapic; @@ -120,6 +128,10 @@ struct deadlines { }; struct deadlines *tsc_deadlines = NULL; +static void lapic_eoi_func(void); + +void (*lapic_eoi)(void); + /* * Enable LAPIC, configure interrupts. */ @@ -1117,12 +1129,21 @@ lapic_fixup_noioapic(void) lapic->lvt_lint1 = temp; } +static void +lapic_eoi_func(void) +{ + log_lapic(eoi); + lapic->eoi = 0; +} + static void lapic_sysinit(void *dummy __unused) { if (lapic_enable) { int error; + lapic_eoi = lapic_eoi_func; + error = lapic_config(); if (error) lapic_enable = 0; diff --git a/sys/platform/pc64/apic/lapic.h b/sys/platform/pc64/apic/lapic.h index 7e01aef046..41055c15b3 100644 --- a/sys/platform/pc64/apic/lapic.h +++ b/sys/platform/pc64/apic/lapic.h @@ -55,6 +55,7 @@ extern volatile lapic_t *lapic; extern int cpu_id_to_apic_id[]; extern int apic_id_to_cpu_id[]; extern int lapic_enable; +extern void (*lapic_eoi)(void); void apic_dump(char*); void lapic_init(boolean_t); diff --git a/sys/platform/pc64/x86_64/genassym.c b/sys/platform/pc64/x86_64/genassym.c index fbdae28002..d559453bfb 100644 --- a/sys/platform/pc64/x86_64/genassym.c +++ b/sys/platform/pc64/x86_64/genassym.c @@ -257,8 +257,6 @@ ASSYM(RQF_TIMER, RQF_TIMER); ASSYM(RQF_AST_MASK, RQF_AST_MASK); ASSYM(RQF_QUICKRET, RQF_QUICKRET); -ASSYM(LA_EOI, offsetof(struct LAPIC, eoi)); - ASSYM(KCSEL, GSEL(GCODE_SEL, SEL_KPL)); ASSYM(KDSEL, GSEL(GDATA_SEL, SEL_KPL)); ASSYM(KUCSEL, GSEL(GUCODE_SEL, SEL_UPL)); diff --git a/sys/platform/pc64/x86_64/msi_vector.s b/sys/platform/pc64/x86_64/msi_vector.s index 853b975a8d..b2e8f9e14f 100644 --- a/sys/platform/pc64/x86_64/msi_vector.s +++ b/sys/platform/pc64/x86_64/msi_vector.s @@ -48,8 +48,8 @@ IDTVEC(msi_intr##irq_num) ; \ MSI_PUSH_FRAME ; \ FAKE_MCOUNT(TF_RIP(%rsp)) ; \ - movq lapic, %rax ; \ - movl $0, LA_EOI(%rax) ; \ + movq lapic_eoi, %rax ; \ + callq *%rax ; \ movq PCPU(curthread),%rbx ; \ testl $-1,TD_NEST_COUNT(%rbx) ; \ jne 1f ; \