Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2385682ybv; Fri, 21 Feb 2020 14:42:59 -0800 (PST) X-Google-Smtp-Source: APXvYqxFn783pgtR37laexsJjK5CuPPiYqXGe+fGa1nkR9+yboZRO+1if14dus9Nr8kqDoMjm47D X-Received: by 2002:a05:6830:1608:: with SMTP id g8mr28853526otr.169.1582324979216; Fri, 21 Feb 2020 14:42:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582324979; cv=none; d=google.com; s=arc-20160816; b=lcPqpYYla+CJNYXOXaVn6RTPr2giewGSqWNXbHwnpCjZEkL/5IxhPjerk/BboNO+U5 EHdh9I7Aok7dlYSE0bNM+wYK1sUC2xqeFMUxPAiO0MQoRIuV2Z8SxjxVLQMl7Vk2BYG6 TW5twt7tVzBnfxiRMw11RbxSiLbq/69FBIxpFT+W7Ac9u87HDFshNKDMYjsXe0vrj576 7wV6gwI69Np8Ph+xuyH7wQfkmRiI38lizGQWYDZnSMlK6nTxJFz5tybEgcLRlxqQ5lRf QVyBfJ8RkBOUs2Bqvj2Y6L0uPGfsV32AonplAAheiDmnuejatjIfwkGF555wpuDs8e19 3e9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:mime-version :message-id:date:dkim-signature; bh=AYMrtaQFpEAhf4N2/PSLyY8BVuR8zCZktSQFDW5VeUU=; b=sVhMP0Ea3KhwuJYd8anofUHB6kMNNDc/Zz7PWtfpI9P8XeDiBJW9/HJYXnr25hm2ab 2RrTO2sqVECwJ3sNLRDVkHwqNvbwypwlRNa8+EydF3BriEk71gnxb8DOiCeQ5iQcGmw+ 3fjUfi/ZdxZDGGjsm8ioex/0vElYqPcPf4N1iEn4de9iqGTbKCJzCPgoi2t8MzCw/g4k pBPi2MWlCo68bYctrXAflwfxWMrsYmnZ0qukg61Wj7X4OtvX58nJgv8zWdJXXY+sRk5y xEyI+T0FGjoAn/gok/l1Y3IB9Te+a/RmUoW54SPV4ffeDtqft2QkZaYHEpRFJM8xCqHN qkEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=J41etYRp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u204si1330201oia.55.2020.02.21.14.42.45; Fri, 21 Feb 2020 14:42:59 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=J41etYRp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728624AbgBUWmd (ORCPT + 99 others); Fri, 21 Feb 2020 17:42:33 -0500 Received: from mail-pg1-f202.google.com ([209.85.215.202]:50023 "EHLO mail-pg1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726802AbgBUWmd (ORCPT ); Fri, 21 Feb 2020 17:42:33 -0500 Received: by mail-pg1-f202.google.com with SMTP id u14so1955380pgq.16 for ; Fri, 21 Feb 2020 14:42:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=AYMrtaQFpEAhf4N2/PSLyY8BVuR8zCZktSQFDW5VeUU=; b=J41etYRpVeAqdqvHtns7EtNVVbjYCZAT4uPwTfXxmVxBP1EywH9V7naMIWd8JKOJSi K7Wn5PluMFO1qq21ZIL07fltzyJR/7kmvXNlng5dPs2SQ8GpoYrGYofV1WWHdxo3ts8x mrzNRWXAy2ANyWXWY9qp1ZADnIWwUhGpXShQ8UJAjBuePE7EXawDC7WOrps0GlX3lhfW nPR40Ce5lQAJwEmjc+x6h5EAsEP3JLWMUmEnEQA3zfzLNt9/C01LO/6l+IPk1wNCwsxz tNV/VKd+lyqLwVRLzzhKr/fkvAgWtgSWZREkCmpno7vHpmkwqywbD+kq5YMkBGM5Is2n 4Gkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=AYMrtaQFpEAhf4N2/PSLyY8BVuR8zCZktSQFDW5VeUU=; b=cscn3JcB9/KUEJWki6xwBTJZKkbDLtv50mjgeukTo5FVc4jGJlc54DmE3E+Z3D+Jbf KMbHtxMq2BTurrvL3SL8xmEU+XgXYimTN9bgHLyGlvyMXLi3FsF9+vzsv2N5Co0cV4Sg pIgAvuywMZAObf2A9IOAh3O//EKtMmh47RIaROzY4EMHo5PucEvpp4AFGKkjz2ef5TwY +ec/WUpRgGJAXoiNnx/kZT/eXL3sdMKMRupc70O4mBSlMhovCem4q2s3ARXXPrhmTLfB +pTkJ87VKCxiVHgM5jxXO8voWbyO01J4c9jtBDJ4QXfU0hhwCQJOMOgFNrOgVLSei2Qh yVqw== X-Gm-Message-State: APjAAAUBhmdScI0gMShdupZh5Yy3792aQsD1yQ0pCi2ef/DGa/eOVvzz vZpxq43NQH5xpsME46OvMkfqluDqC47MwtE= X-Received: by 2002:a63:aa07:: with SMTP id e7mr40537889pgf.90.1582324952547; Fri, 21 Feb 2020 14:42:32 -0800 (PST) Date: Fri, 21 Feb 2020 14:41:33 -0800 Message-Id: <20200221224133.103377-1-ehankland@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog Subject: [kvm-unit-tests PATCH] x86: pmu: Test perfctr overflow after WRMSR on a running counter From: Eric Hankland To: Jim Mattson , Peter Shier Cc: Paolo Bonzini , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Eric Hankland Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Ensure that a WRMSR on a running counter will correctly update when the counter should overflow (similar to the existing overflow test case but with the counter being written to while it is running). Signed-off-by: Eric Hankland --- x86/pmu.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/x86/pmu.c b/x86/pmu.c index c8096b8..f45621a 100644 --- a/x86/pmu.c +++ b/x86/pmu.c @@ -422,17 +422,34 @@ static void check_rdpmc(void) static void check_running_counter_wrmsr(void) { + uint64_t status; pmu_counter_t evt = { .ctr = MSR_IA32_PERFCTR0, .config = EVNTSEL_OS | EVNTSEL_USR | gp_events[1].unit_sel, .count = 0, }; + report_prefix_push("running counter wrmsr"); + start_event(&evt); loop(); wrmsr(MSR_IA32_PERFCTR0, 0); stop_event(&evt); - report(evt.count < gp_events[1].min, "running counter wrmsr"); + report(evt.count < gp_events[1].min, "cntr"); + + /* clear status before overflow test */ + wrmsr(MSR_CORE_PERF_GLOBAL_OVF_CTRL, + rdmsr(MSR_CORE_PERF_GLOBAL_STATUS)); + + evt.count = 0; + start_event(&evt); + wrmsr(MSR_IA32_PERFCTR0, -1); + loop(); + stop_event(&evt); + status = rdmsr(MSR_CORE_PERF_GLOBAL_STATUS); + report(status & 1, "status"); + + report_prefix_pop(); } int main(int ac, char **av)