From owner-svn-src-all@FreeBSD.ORG Thu May 5 18:56:48 2011 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 60AC5106564A; Thu, 5 May 2011 18:56:48 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 4EA418FC20; Thu, 5 May 2011 18:56:48 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p45IumiX011826; Thu, 5 May 2011 18:56:48 GMT (envelope-from mav@svn.freebsd.org) Received: (from mav@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p45IumkV011824; Thu, 5 May 2011 18:56:48 GMT (envelope-from mav@svn.freebsd.org) Message-Id: <201105051856.p45IumkV011824@svn.freebsd.org> From: Alexander Motin Date: Thu, 5 May 2011 18:56:48 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r221508 - head/sys/x86/x86 X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 May 2011 18:56:48 -0000 Author: mav Date: Thu May 5 18:56:48 2011 New Revision: 221508 URL: http://svn.freebsd.org/changeset/base/221508 Log: Some changes around LAPIC timer programming. This fixes heavy interrupt storm and resulting system freeze when using LAPIC timer in one-shot mode under Xen HVM. There, unlike real hardware, programming timer with zero period almost immediately causes interrupt. Modified: head/sys/x86/x86/local_apic.c Modified: head/sys/x86/x86/local_apic.c ============================================================================== --- head/sys/x86/x86/local_apic.c Thu May 5 18:50:52 2011 (r221507) +++ head/sys/x86/x86/local_apic.c Thu May 5 18:56:48 2011 (r221508) @@ -159,9 +159,8 @@ static struct eventtimer lapic_et; static void lapic_enable(void); static void lapic_resume(struct pic *pic); -static void lapic_timer_enable_intr(void); -static void lapic_timer_oneshot(u_int count); -static void lapic_timer_periodic(u_int count); +static void lapic_timer_oneshot(u_int count, int enable_int); +static void lapic_timer_periodic(u_int count, int enable_int); static void lapic_timer_stop(void); static void lapic_timer_set_divisor(u_int divisor); static uint32_t lvt_mode(struct lapic *la, u_int pin, uint32_t value); @@ -379,13 +378,11 @@ lapic_setup(int boot) if (la->la_timer_mode != 0) { KASSERT(la->la_timer_period != 0, ("lapic%u: zero divisor", lapic_id())); - lapic_timer_stop(); lapic_timer_set_divisor(lapic_timer_divisor); - lapic_timer_enable_intr(); if (la->la_timer_mode == 1) - lapic_timer_periodic(la->la_timer_period); + lapic_timer_periodic(la->la_timer_period, 1); else - lapic_timer_oneshot(la->la_timer_period); + lapic_timer_oneshot(la->la_timer_period, 1); } /* Program error LVT and clear any existing errors. */ @@ -496,7 +493,7 @@ lapic_et_start(struct eventtimer *et, /* Try to calibrate the local APIC timer. */ do { lapic_timer_set_divisor(lapic_timer_divisor); - lapic_timer_oneshot(APIC_TIMER_MAX_COUNT); + lapic_timer_oneshot(APIC_TIMER_MAX_COUNT, 0); DELAY(1000000); value = APIC_TIMER_MAX_COUNT - lapic->ccr_timer; if (value != APIC_TIMER_MAX_COUNT) @@ -516,9 +513,7 @@ lapic_et_start(struct eventtimer *et, et->et_max_period.frac = ((0xfffffffeLLU << 32) / et->et_frequency) << 32; } - lapic_timer_stop(); lapic_timer_set_divisor(lapic_timer_divisor); - lapic_timer_enable_intr(); la = &lapics[lapic_id()]; if (period != NULL) { la->la_timer_mode = 1; @@ -526,14 +521,14 @@ lapic_et_start(struct eventtimer *et, (et->et_frequency * (period->frac >> 32)) >> 32; if (period->sec != 0) la->la_timer_period += et->et_frequency * period->sec; - lapic_timer_periodic(la->la_timer_period); + lapic_timer_periodic(la->la_timer_period, 1); } else { la->la_timer_mode = 2; la->la_timer_period = (et->et_frequency * (first->frac >> 32)) >> 32; if (first->sec != 0) la->la_timer_period += et->et_frequency * first->sec; - lapic_timer_oneshot(la->la_timer_period); + lapic_timer_oneshot(la->la_timer_period, 1); } return (0); } @@ -838,25 +833,29 @@ lapic_timer_set_divisor(u_int divisor) } static void -lapic_timer_oneshot(u_int count) +lapic_timer_oneshot(u_int count, int enable_int) { u_int32_t value; value = lapic->lvt_timer; value &= ~APIC_LVTT_TM; value |= APIC_LVTT_TM_ONE_SHOT; + if (enable_int) + value &= ~APIC_LVT_M; lapic->lvt_timer = value; lapic->icr_timer = count; } static void -lapic_timer_periodic(u_int count) +lapic_timer_periodic(u_int count, int enable_int) { u_int32_t value; value = lapic->lvt_timer; value &= ~APIC_LVTT_TM; value |= APIC_LVTT_TM_PERIODIC; + if (enable_int) + value &= ~APIC_LVT_M; lapic->lvt_timer = value; lapic->icr_timer = count; } @@ -870,17 +869,6 @@ lapic_timer_stop(void) value &= ~APIC_LVTT_TM; value |= APIC_LVT_M; lapic->lvt_timer = value; - lapic->icr_timer = 0; -} - -static void -lapic_timer_enable_intr(void) -{ - u_int32_t value; - - value = lapic->lvt_timer; - value &= ~APIC_LVT_M; - lapic->lvt_timer = value; } void