From patchwork Fri Jul 12 02:28:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 11041287 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B4C5C14DB for ; Fri, 12 Jul 2019 02:28:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A641728BB7 for ; Fri, 12 Jul 2019 02:28:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9ACBC28BB6; Fri, 12 Jul 2019 02:28:42 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI 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 4962F28BB6 for ; Fri, 12 Jul 2019 02:28:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728885AbfGLC2l (ORCPT ); Thu, 11 Jul 2019 22:28:41 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:43113 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728890AbfGLC2k (ORCPT ); Thu, 11 Jul 2019 22:28:40 -0400 Received: by mail-pl1-f196.google.com with SMTP id cl9so3985459plb.10 for ; Thu, 11 Jul 2019 19:28:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4Shs1mPjCZ9q2Cf9BC1SlIhJhmVvlv0+gzbQGhV8nv4=; b=Gci8ZBBYe+iWxKvaGLrUKLQhe9scq2Yq1PFwqfJIRZShtOqiJiZLFibetNwDDFi3OR 7u73wCTdQP+1kdEHptrBn+CRRCDXZnwMPpTInediebbZPm03sCMMn3O+3Mw0hiWVlb0R 6E0PmlQdQpGxrq5unZwMkjVgcv/0T4eJGfNVZgdUw5CgI+/DPFXEHpBE4TRrWfbR9PAK 5wOHqMQX+8E1dw6rQ7iYfB9NRbnyNMalv5myiy4i9BXElu6EsEIhEldmEleIkcq8v0ju F2pHP/tGrc89T07ONGysrwUN27I/Q3YWeJbhdjFpyzK3WVu1pkROsccKFtUceGkaNQ1w /pOw== X-Gm-Message-State: APjAAAV3RyGlaR6mQSo8GL4yTHKzQTPr63esQ5+ZKqQAaYAqDLbr9q7h P+fmlISnWiH/89X8yEIbJhQPwBZMF+EtQA== X-Google-Smtp-Source: APXvYqwhA4da0Y/lhyRt4NCloh5qj6TBSTxTIpUqG9pc2JP32ljyo5Q4NDS6hKe1Zbb85KlCL0/0qw== X-Received: by 2002:a17:902:2be6:: with SMTP id l93mr8488822plb.0.1562898519799; Thu, 11 Jul 2019 19:28:39 -0700 (PDT) Received: from xz-x1.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id f15sm7389259pje.17.2019.07.11.19.28.36 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 11 Jul 2019 19:28:39 -0700 (PDT) From: Peter Xu X-Google-Original-From: Peter Xu To: kvm@vger.kernel.org Cc: Paolo Bonzini , =?utf-8?b?UmFkaW0gS3LEjW3DocWZ?= , Sean Christopherson , Luiz Capitulino , peterx@redhat.com, Marcelo Tosatti Subject: [kvm-unit-tests PATCH v2 1/3] tscdeadline_latency: Check condition first before loop Date: Fri, 12 Jul 2019 10:28:23 +0800 Message-Id: <20190712022825.1366-2-peterx@redhat.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190712022825.1366-1-peterx@redhat.com> References: <20190712022825.1366-1-peterx@redhat.com> 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 This patch fixes a tscdeadline_latency hang when specifying a very small breakmax value. It's easily reproduced on my host when set breakmax to e.g. 10 TSC clocks. The problem is test_tsc_deadline_timer() can be very slow because we've got printf() in there. So when reach the main loop we might have already triggered the IRQ handler for multiple times and we might have triggered the hitmax condition which will turn IRQ off. Then with no IRQ that first HLT instruction can last forever. Fix this by don't enable irq and use safe_halt() as suggested by Sean Christopherson. Signed-off-by: Peter Xu --- x86/tscdeadline_latency.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/x86/tscdeadline_latency.c b/x86/tscdeadline_latency.c index 0617a1b..3ad2950 100644 --- a/x86/tscdeadline_latency.c +++ b/x86/tscdeadline_latency.c @@ -70,8 +70,6 @@ static void tsc_deadline_timer_isr(isr_regs_t *regs) static void start_tsc_deadline_timer(void) { handle_irq(TSC_DEADLINE_TIMER_VECTOR, tsc_deadline_timer_isr); - irq_enable(); - wrmsr(MSR_IA32_TSCDEADLINE, rdmsr(MSR_IA32_TSC)+delta); asm volatile ("nop"); } @@ -116,10 +114,9 @@ int main(int argc, char **argv) breakmax = argc <= 3 ? 0 : atol(argv[3]); printf("breakmax=%d\n", breakmax); test_tsc_deadline_timer(); - irq_enable(); do { - asm volatile("hlt"); + safe_halt(); } while (!hitmax && table_idx < size); for (i = 0; i < table_idx; i++) { From patchwork Fri Jul 12 02:28:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 11041289 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B24FC14DB for ; Fri, 12 Jul 2019 02:28:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A352B28BB6 for ; Fri, 12 Jul 2019 02:28:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9702128BB8; Fri, 12 Jul 2019 02:28:45 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI 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 4CC8C28BB6 for ; Fri, 12 Jul 2019 02:28:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728927AbfGLC2o (ORCPT ); Thu, 11 Jul 2019 22:28:44 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:32914 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728890AbfGLC2o (ORCPT ); Thu, 11 Jul 2019 22:28:44 -0400 Received: by mail-pl1-f196.google.com with SMTP id c14so4001240plo.0 for ; Thu, 11 Jul 2019 19:28:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SQuqtPUHvOhARMEh7aacQAGcSKsUznBxgps/OyxKb0I=; b=N+e4o2VPKDp7uQGRUvK32NwGZn2yUJVp8gUHHojnfOxFxycQd7k0O+dAbXTZpjAPnk zXqOVGWDaL4fE8aIoKA0FifqFQnURTaQgYVxhMvw/4SzqIHnksGyspFdTcUQxtbo4pk2 g88rceg7nBt355qBmyEBbmmBc4EYwd2rh5y/Lq8/oOAV8VZLV1AoMj6NIMLqjAMAnYtt atS+ULBORZHCzI1zydsvMivFjgylGPNEMuRW0d8a4/+fNqDCE595Kfjc38Dm5GIw7DVI y1kJz5UrbMO0BpzfrGn47vFapwn6BtlobAI/6slulG1UDeSyNwFVBuuXk2JO6LymLUX4 ZTfg== X-Gm-Message-State: APjAAAXM6UxdmnUmX7DUVcUuhynNxEPE6vx25lQMGH2Mp5+IzqTAA/ya Ju34aUBAcip6K/eDSJws4s/8UaRl14VmjQ== X-Google-Smtp-Source: APXvYqzl9LBPKM9pYxH51GuGOH8IZzPA8PjNbqNwOL8rtS3HhWjvApmHzcSyGXXM7dFgflf/5qTygA== X-Received: by 2002:a17:902:4501:: with SMTP id m1mr8396879pld.111.1562898522991; Thu, 11 Jul 2019 19:28:42 -0700 (PDT) Received: from xz-x1.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id f15sm7389259pje.17.2019.07.11.19.28.40 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 11 Jul 2019 19:28:42 -0700 (PDT) From: Peter Xu X-Google-Original-From: Peter Xu To: kvm@vger.kernel.org Cc: Paolo Bonzini , =?utf-8?b?UmFkaW0gS3LEjW3DocWZ?= , Sean Christopherson , Luiz Capitulino , peterx@redhat.com, Marcelo Tosatti Subject: [kvm-unit-tests PATCH v2 2/3] tscdeadline_latency: Limit size Date: Fri, 12 Jul 2019 10:28:24 +0800 Message-Id: <20190712022825.1366-3-peterx@redhat.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190712022825.1366-1-peterx@redhat.com> References: <20190712022825.1366-1-peterx@redhat.com> 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 When size>TABLE_SIZE it can hang as well (say, 10001), because when we get TABLE_SIZE IRQs we'll stop increasing table_idx, then we'll never be able to get out of the main loop. Signed-off-by: Peter Xu --- x86/tscdeadline_latency.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/x86/tscdeadline_latency.c b/x86/tscdeadline_latency.c index 3ad2950..0a3532d 100644 --- a/x86/tscdeadline_latency.c +++ b/x86/tscdeadline_latency.c @@ -112,7 +112,11 @@ int main(int argc, char **argv) delta = argc <= 1 ? 200000 : atol(argv[1]); size = argc <= 2 ? TABLE_SIZE : atol(argv[2]); breakmax = argc <= 3 ? 0 : atol(argv[3]); - printf("breakmax=%d\n", breakmax); + + if (size >= TABLE_SIZE) + size = TABLE_SIZE; + printf("delta=%d, size=%d, breakmax=%d\n", delta, size, breakmax); + test_tsc_deadline_timer(); do { From patchwork Fri Jul 12 02:28:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 11041291 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A7A6A13BD for ; Fri, 12 Jul 2019 02:28:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9898928BB6 for ; Fri, 12 Jul 2019 02:28:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8CF7628BB8; Fri, 12 Jul 2019 02:28:48 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI 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 3F42F28BB6 for ; Fri, 12 Jul 2019 02:28:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728931AbfGLC2r (ORCPT ); Thu, 11 Jul 2019 22:28:47 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:42493 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728932AbfGLC2r (ORCPT ); Thu, 11 Jul 2019 22:28:47 -0400 Received: by mail-pg1-f196.google.com with SMTP id t132so3808721pgb.9 for ; Thu, 11 Jul 2019 19:28:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cFN7IARNf/dh9h3GTyQlVk7K9Z+EtPM855+7HZjT3Oc=; b=OLKvXfdw9tSqtmd+pQljPQr9CKk43E0zGGXRRKMgJz1e3wK/0VrtXAD4rCU08oye8P j67zzzp/V49nUdnQqjJc+MN7I6Ag3KXVEqizi0ncf0Yz9DZXOuRRnVKv9NXN29Qynnkf 5yuC0btwfalLvPpU27znD+M2wpdUsjq3zzsdP02BMFpKscxOLSM+R+EHInGMX0jppOEt pf75Idjz2aLMAQJyjMQaLs5+0NcA4dxjfHeOMm/kSo9Wdt8Jk5XuadY1QMa6kVcB2mvT tleIyGL2GY9ApL75o8suJTKyeLAoP+bdG21w9uNXsOPxWqG0vYD31nDKWT61qZB42/Vo 4NtA== X-Gm-Message-State: APjAAAVQnOZV0T09cuDc8wOOjoxI5bN0j3O1REOFB0k7M9KxsXA5yIKc Wd3KxjGB2YHQ6KOSnkmHkuDxtmpbZgOlWw== X-Google-Smtp-Source: APXvYqygaxpxWjhPdVksaAv3LG4n8/WiRRkQJp+HSmKUI14J8m8IDfn2bajnPkr84EDoIssyPfMPCA== X-Received: by 2002:a65:4841:: with SMTP id i1mr7833657pgs.316.1562898526157; Thu, 11 Jul 2019 19:28:46 -0700 (PDT) Received: from xz-x1.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id f15sm7389259pje.17.2019.07.11.19.28.43 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 11 Jul 2019 19:28:45 -0700 (PDT) From: Peter Xu X-Google-Original-From: Peter Xu To: kvm@vger.kernel.org Cc: Paolo Bonzini , =?utf-8?b?UmFkaW0gS3LEjW3DocWZ?= , Sean Christopherson , Luiz Capitulino , peterx@redhat.com, Marcelo Tosatti Subject: [kvm-unit-tests PATCH v2 3/3] tscdeadline_latency: Stop timer when reach max loop Date: Fri, 12 Jul 2019 10:28:25 +0800 Message-Id: <20190712022825.1366-4-peterx@redhat.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190712022825.1366-1-peterx@redhat.com> References: <20190712022825.1366-1-peterx@redhat.com> 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 This fixes another possible hang of this test when delay is configured too small (e.g., 2000) so that the IRQ handler will trigger forever. Let's stop the timer if we've collected enough data so that the program can quit always. Signed-off-by: Peter Xu --- x86/tscdeadline_latency.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/x86/tscdeadline_latency.c b/x86/tscdeadline_latency.c index 0a3532d..a63f98b 100644 --- a/x86/tscdeadline_latency.c +++ b/x86/tscdeadline_latency.c @@ -50,18 +50,24 @@ int breakmax = 0; static void tsc_deadline_timer_isr(isr_regs_t *regs) { - u64 now = rdtsc(); + u64 now = rdtsc(), delay; ++tdt_count; - if (table_idx < TABLE_SIZE && tdt_count > 1) - table[table_idx++] = now - exptime; + if (tdt_count == 1) + /* Skip the 1st IRQ */ + goto setup_next; - if (breakmax && tdt_count > 1 && (now - exptime) > breakmax) { - hitmax = 1; + table[table_idx++] = delay = now - exptime; + + /* Stop if either we finished collection or hit max */ + if ((breakmax && delay > breakmax) || table_idx >= TABLE_SIZE) { + if (breakmax) + hitmax = 1; apic_write(APIC_EOI, 0); return; } +setup_next: exptime = now+delta; wrmsr(MSR_IA32_TSCDEADLINE, now+delta); apic_write(APIC_EOI, 0);