From patchwork Mon Oct 10 07:56:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ani Sinha X-Patchwork-Id: 13002361 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2A536C433F5 for ; Mon, 10 Oct 2022 08:12:00 +0000 (UTC) Received: from localhost ([::1]:49348 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ohntH-0005s6-4k for qemu-devel@archiver.kernel.org; Mon, 10 Oct 2022 04:11:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58466) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ohnfG-0003np-Ia for qemu-devel@nongnu.org; Mon, 10 Oct 2022 03:57:30 -0400 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]:39698) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ohnfD-0005oJ-PF for qemu-devel@nongnu.org; Mon, 10 Oct 2022 03:57:30 -0400 Received: by mail-pf1-x430.google.com with SMTP id d10so10113276pfh.6 for ; Mon, 10 Oct 2022 00:57:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anisinha-ca.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=KZisjHdPUqoV3LQ/0AYa/w4ibA0/EsbwyKyP8Nj3pKs=; b=WTLU1maQaddv74GPl72aRzUoyhBwZCWL1BZFmZHv2hYM4gh3P+lBXTL9kR+0MJNGuA NkIa7VsZQMh+y35O7YQPc8MKAbyHZ4x8SbxQo1Ivd2/QE9dlOWyv5FTFyUhKxzymPa46 M45rWQin/H7JdMPHp2q8aIXUxaV2PjTzajpwURweIg8FqKlkgaLBdyNuV7E21qcDb1Ye g3jI/aDjXFy/5qRTObVNL13eDCjiN669HYW/qI59v5XxbqLbrqrMz/XuWxqDJ/4zKxQb 29aDoabrmRqBIww6bXsa7zK9l7iKwXu9qNEzJx29XMnSyx0gly80gLiR+o3bPyi6Apbc 9ZzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KZisjHdPUqoV3LQ/0AYa/w4ibA0/EsbwyKyP8Nj3pKs=; b=qjyzR0gOR0m+ix8kFJaqIo/3vBDPcU/bWJ+UjyO6A13VbDTKNDOx//U2cnXgiSrJny 9x5IuFYWfZjt13yBEKBHrqSLyUmJjj5zy3/hKLlFU8E01D+urbzSoRT3gI8KyHNm/bCm BIgRuj0AfozZMfCQ03eVBbb8VJ3prteZj3Epv4GyU+B5yXkwX0FS2tTfAbVLPFp+oC3h XZVeka/1geqyy8Grje1murNj5uxEQfLXg5/hg+dj3ItxghEZ6YuEX6IE/NupHqfGdixw PGFh08OA8zdXti1Z1CqtRmE+/FzO1THFUT24Vjp3WYN2s+4GIWVXIwOHddqp95y1hERa 69BQ== X-Gm-Message-State: ACrzQf14/cTx/SxZwKSxPnwrX8Qu8Uy9AgHP9VfB4+FwoHd/GW0ddpgr W/l3ftgyvsYk4m/XC7KprqGJbkzrxXVC7Q== X-Google-Smtp-Source: AMsMyM6AsX1fMgSk/g7PUxqvWu+zBBFsVe0mlfU35yI9aCMXoPeYAZDrPkpOSPPQn3sbbw1Ndyg8iA== X-Received: by 2002:a05:6a00:190d:b0:550:6db3:b9be with SMTP id y13-20020a056a00190d00b005506db3b9bemr18836690pfi.1.1665388645247; Mon, 10 Oct 2022 00:57:25 -0700 (PDT) Received: from anisinha-lenovo.ba.nuagenetworks.net ([203.163.239.238]) by smtp.googlemail.com with ESMTPSA id s2-20020a625e02000000b005624b4bd738sm6200379pfb.156.2022.10.10.00.57.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Oct 2022 00:57:24 -0700 (PDT) From: Ani Sinha To: qemu-devel@nongnu.org, Cleber Rosa , =?utf-8?q?Philipp?= =?utf-8?q?e_Mathieu-Daud=C3=A9?= , Wainer dos Santos Moschetta , Beraldo Leal Cc: mst@redhat.com, imammedo@redhat.com, Ani Sinha , =?utf-8?q?Daniel_P_=2E_Berrang=C3=A9?= , Paolo Bonzini , Maydell Peter , John Snow , Thomas Huth Subject: [PATCH v3 04/10] acpi/tests/avocado/bits: add smilatency test suite from bits in order to disable it Date: Mon, 10 Oct 2022 13:26:13 +0530 Message-Id: <20221010075619.4147111-5-ani@anisinha.ca> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221010075619.4147111-2-ani@anisinha.ca> References: <20221010075619.4147111-2-ani@anisinha.ca> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::430; envelope-from=ani@anisinha.ca; helo=mail-pf1-x430.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" smilatency tests does not reliably pass every time it is run from QEMU. This change adds the test file unchanged from bits so that the next change can disable the test. Cc: Daniel P. Berrangé Cc: Paolo Bonzini Cc: Maydell Peter Cc: John Snow Cc: Thomas Huth Signed-off-by: Ani Sinha --- .../acpi-bits/bits-tests/smilatency.py | 102 ++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 tests/avocado/acpi-bits/bits-tests/smilatency.py diff --git a/tests/avocado/acpi-bits/bits-tests/smilatency.py b/tests/avocado/acpi-bits/bits-tests/smilatency.py new file mode 100644 index 0000000000..fb1b7228e3 --- /dev/null +++ b/tests/avocado/acpi-bits/bits-tests/smilatency.py @@ -0,0 +1,102 @@ +# Copyright (c) 2015, Intel Corporation +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of Intel Corporation nor the names of its contributors +# may be used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +"""SMI latency test.""" + +import bits +from collections import namedtuple +import testsuite +import time +import usb + +def register_tests(): + testsuite.add_test("SMI latency test", smi_latency); + testsuite.add_test("SMI latency test with USB disabled via BIOS handoff", test_with_usb_disabled, runall=False); + +def smi_latency(): + MSR_SMI_COUNT = 0x34 + + print "Warning: touching the keyboard can affect the results of this test." + + tsc_per_sec = bits.tsc_per_sec() + tsc_per_usec = tsc_per_sec / (1000 * 1000) + bins = [long(tsc_per_usec * 10**i) for i in range(9)] + bin_descs = [ + "0 < t <= 1us", + "1us < t <= 10us", + "10us < t <= 100us", + "100us < t <= 1ms", + "1ms < t <= 10ms", + "10ms < t <= 100ms", + "100ms < t <= 1s ", + "1s < t <= 10s ", + "10s < t <= 100s ", + "100s < t ", + ] + + print "Starting test. Wait here, I will be back in 15 seconds." + (max_latency, smi_count_delta, bins) = bits.smi_latency(long(15 * tsc_per_sec), bins) + BinType = namedtuple('BinType', ("max", "total", "count", "times")) + bins = [BinType(*b) for b in bins] + + testsuite.test("SMI latency < 150us to minimize risk of OS timeouts", max_latency / tsc_per_usec <= 150) + if not testsuite.show_detail(): + return + + for bin, desc in zip(bins, bin_descs): + if bin.count == 0: + continue + testsuite.print_detail("{}; average = {}; count = {}".format(desc, bits.format_tsc(bin.total/bin.count), bin.count)) + deltas = (bits.format_tsc(t2 - t1) for t1,t2 in zip(bin.times, bin.times[1:])) + testsuite.print_detail(" Times between first few observations: {}".format(" ".join("{:>6}".format(delta) for delta in deltas))) + + if smi_count_delta is not None: + testsuite.print_detail("{} SMI detected using MSR_SMI_COUNT (MSR {:#x})".format(smi_count_delta, MSR_SMI_COUNT)) + + testsuite.print_detail("Summary of impact: observed maximum latency = {}".format(bits.format_tsc(max_latency))) + +def test_with_usb_disabled(): + if usb.handoff_to_os(): + smi_latency() + +def average_io_smi(port, value, count): + def f(): + tsc_start = bits.rdtsc() + bits.outb(port, value) + return bits.rdtsc() - tsc_start + counts = [f() for i in range(count)] + return sum(counts)/len(counts) + +def time_io_smi(port=0xb2, value=0, count=1000): + count_for_estimate = 10 + start = time.time() + average_io_smi(port, value, count_for_estimate) + avg10 = time.time() - start + estimate = avg10 * count/count_for_estimate + if estimate > 1: + print "Running test, estimated time: {}s".format(int(estimate)) + average = average_io_smi(port, value, count) + print "Average of {} SMIs (via outb, port={:#x}, value={:#x}): {}".format(count, port, value, bits.format_tsc(average))