From patchwork Wed Oct 12 06:53:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Wanpeng Li X-Patchwork-Id: 9372145 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4604260839 for ; Wed, 12 Oct 2016 06:53:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 36DBC29323 for ; Wed, 12 Oct 2016 06:53:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2B76229C8E; Wed, 12 Oct 2016 06:53:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BC79A29C2E for ; Wed, 12 Oct 2016 06:53:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754426AbcJLGxa (ORCPT ); Wed, 12 Oct 2016 02:53:30 -0400 Received: from mail-pa0-f68.google.com ([209.85.220.68]:34499 "EHLO mail-pa0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754179AbcJLGxM (ORCPT ); Wed, 12 Oct 2016 02:53:12 -0400 Received: by mail-pa0-f68.google.com with SMTP id fn2so1949684pad.1 for ; Tue, 11 Oct 2016 23:53:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=gKjbtYBvtk+BmUqzgr4bDHdDO0HUd67UUvwjbqUMDPc=; b=hJ+O0dmvfCJ2NIN1GAX4ddU9YLdXP/JB0z0sx8mGo1Mzej6S0L/5eNMEfsYPLhfOtc U2DojaKmYJMnkfc6TymPrwuRfhbBjbo3izPjF5BkJTJH+9zTLPjdVtA6JCf+s0lObXfP m/VJNSk92S9whKuhkpLjX4alIpTGik4dNSdyFLmgE+5hq4ym9iIuE0WnTIsmXCFy3YPk NLCwMXbVmiJi67z7Ca9Hnxdzl5mLqe2ipr64kCSNStM++EiTvSojLMNkeZdsuRHkh8zm YAKZC/S+5TOVY5EWlbfZ7DBDeUDB1bdWdvP19Y0w3t5fkxIkvveBzeSoZ/AF64VdglDh dUFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=gKjbtYBvtk+BmUqzgr4bDHdDO0HUd67UUvwjbqUMDPc=; b=Ys1CUxmqRabwL5a6bXZfSWI6mNpWB5gUCMM7AkxyyqDYUOpv34e55r+0BuRnH2XvLI 5KJIcT+aHkZPdfUOBi3Uu0oGo9lhxf1bPvpByR7FIQHOe0Ed4NSxRn59m1jmS4SWM8FY w1Fki7RrycLKbzOLSV8PK+Qtl3f4S1GXBLaP8Ebf/rkElpAVCOS1mTJb8UIdbZ5R8L2i oOV08yJfWaEiEjI7PxyQT91yEVFdh+v7zmYmxloj0NqTW2fhkQqH5o9yy0mzH6+DRZ9o YN2GrRtcGBwsJ+nG6D5h/38zuUGikZODnZkWYtiEI4TkPPVVDHqdx9s9YiAZSWRwGGD2 GTSA== X-Gm-Message-State: AA6/9RnPaDPH91fHt5AAAvwyhUUkVXm3t4uVTjTMYhGnJjEBgA2SwSsqk5x2SlDQQ4So0A== X-Received: by 10.66.81.42 with SMTP id w10mr12687713pax.141.1476255192048; Tue, 11 Oct 2016 23:53:12 -0700 (PDT) Received: from kernel.kingsoft.cn ([114.255.44.132]) by smtp.gmail.com with ESMTPSA id d188sm8943080pfd.33.2016.10.11.23.53.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 11 Oct 2016 23:53:11 -0700 (PDT) From: Wanpeng Li X-Google-Original-From: Wanpeng Li To: kvm@vger.kernel.org Cc: Wanpeng Li , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= Subject: [kvm-unit-tests PATCH] x86: apic: add APIC Timer periodic mode testcase Date: Wed, 12 Oct 2016 14:53:07 +0800 Message-Id: <1476255187-3396-1-git-send-email-wanpeng.li@hotmail.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Wanpeng Li Add APIC Timer periodic mode testcase. Cc: Paolo Bonzini Cc: Radim Krčmář Signed-off-by: Wanpeng Li --- x86/apic.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/x86/apic.c b/x86/apic.c index 4dc7a7b..d0e0ac6 100644 --- a/x86/apic.c +++ b/x86/apic.c @@ -393,6 +393,41 @@ static void test_apic_timer_one_shot(void) (tsc2 - tsc1 >= interval)); } +static void test_apic_timer_periodic(void) +{ + uint64_t tsc1, tsc2; + static const uint32_t interval = 0x10000; + +#define APIC_LVT_TIMER_VECTOR (0xee) +#define LVTT_PERIODIC_ROUND 100 + + handle_irq(APIC_LVT_TIMER_VECTOR, lvtt_handler); + irq_enable(); + + /* Periodic mode */ + apic_write(APIC_LVTT, APIC_LVT_TIMER_PERIODIC | + APIC_LVT_TIMER_VECTOR); + /* Divider == 1 */ + apic_write(APIC_TDCR, 0x0000000b); + + tsc1 = rdtsc(); + /* Set "Initial Counter Register", which starts the timer */ + apic_write(APIC_TMICT, interval); + while (lvtt_counter != LVTT_PERIODIC_ROUND); + apic_write(APIC_TMICT, 0); + tsc2 = rdtsc(); + + /* + * For LVT Timer clock, SDM vol 3 10.5.4 says it should be + * derived from processor's bus clock (IIUC which is the same + * as TSC), however QEMU seems to be using nanosecond. In all + * cases, the following should satisfy on all modern + * processors. + */ + report("APIC LVT timer periodic", (lvtt_counter == + LVTT_PERIODIC_ROUND) && (tsc2 - tsc1 >= interval)); +} + int main() { setup_vm(); @@ -412,6 +447,7 @@ int main() test_multiple_nmi(); test_apic_timer_one_shot(); + test_apic_timer_periodic(); test_tsc_deadline_timer(); return report_summary();