From patchwork Thu Nov 16 10:18:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Chakravarty, Souvik K" X-Patchwork-Id: 10061243 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 88BAC604D4 for ; Thu, 16 Nov 2017 14:00:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7BD702A70B for ; Thu, 16 Nov 2017 14:00:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 70E0A2A763; Thu, 16 Nov 2017 14:00:05 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable 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 26C1E2A779 for ; Thu, 16 Nov 2017 14:00:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935170AbdKPN6c (ORCPT ); Thu, 16 Nov 2017 08:58:32 -0500 Received: from mga04.intel.com ([192.55.52.120]:26946 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935141AbdKPN6R (ORCPT ); Thu, 16 Nov 2017 08:58:17 -0500 Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Nov 2017 02:14:54 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,402,1505804400"; d="scan'208";a="176875102" Received: from skchakra-desk.iind.intel.com ([10.66.254.85]) by fmsmga006.fm.intel.com with ESMTP; 16 Nov 2017 02:14:52 -0800 From: Souvik Kumar Chakravarty To: platform-driver-x86@vger.kernel.org Cc: dvhart@infradead.org, andy@infradead.org, linux-kernel@vger.kernel.org, rajneesh.bhardwaj@intel.com, Souvik Kumar Chakravarty Subject: [PATCH v1 2/5] platform/x86: intel_telemetry: Fix suspend stats Date: Thu, 16 Nov 2017 15:48:14 +0530 Message-Id: <1510827497-25188-3-git-send-email-souvik.k.chakravarty@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1510827497-25188-1-git-send-email-souvik.k.chakravarty@intel.com> References: <1510827497-25188-1-git-send-email-souvik.k.chakravarty@intel.com> Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Suspend stats are not reported consistently due to a limitation in the PMC firmware. This limitation causes a delay in updating the s0ix counters and residencies in the telemetry log upon s0ix exit. As a consequence, reading these counters from the suspend-exit notifier may result in zero read. This patch fixes this issue by cross-verifying the s0ix residencies from the GCR TELEM registers in case the counters are not incremented in the telemetry log after suspend. This fixes https://bugzilla.kernel.org/show_bug.cgi?id=197833 Reported-and-tested-by: Rajneesh Bhardwaj Signed-off-by: Souvik Kumar Chakravarty --- drivers/platform/x86/intel_telemetry_debugfs.c | 39 ++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/drivers/platform/x86/intel_telemetry_debugfs.c b/drivers/platform/x86/intel_telemetry_debugfs.c index 4249e826..d0fce8c 100644 --- a/drivers/platform/x86/intel_telemetry_debugfs.c +++ b/drivers/platform/x86/intel_telemetry_debugfs.c @@ -74,6 +74,8 @@ #define TELEM_IOSS_DX_D0IX_EVTS 25 #define TELEM_IOSS_PG_EVTS 30 +#define TELEM_LO_HI_TO64(lo, hi) ((u64)(lo) + ((u64)(hi)<<32)) + #define TELEM_DEBUGFS_CPU(model, data) \ { X86_VENDOR_INTEL, 6, model, X86_FEATURE_ANY, (unsigned long)&data} @@ -858,6 +860,7 @@ static int pm_suspend_exit_cb(void) static u32 suspend_shlw_ctr_exit, suspend_deep_ctr_exit; static u64 suspend_shlw_res_exit, suspend_deep_res_exit; struct telemetry_debugfs_conf *conf = debugfs_conf; + u32 shlw_lo, shlw_hi, deep_lo, deep_hi; int ret, index; if (!suspend_prep_ok) @@ -890,6 +893,42 @@ static int pm_suspend_exit_cb(void) goto out; } + /* Due to some design limitations in the firmware, sometimes the + * counters do not get updated by the time we reach here. As a + * workaround, we try to see if this was a genuine case of sleep + * failure or not by cross-checking from PMC GCR registers directly. + */ + if ((suspend_shlw_ctr_exit == suspend_shlw_ctr_temp) && + (suspend_deep_ctr_exit == suspend_deep_ctr_temp)) { + ret = intel_pmc_gcr_read(PMC_GCR_TELEM_SHLW_S0IX_LO_REG, + &shlw_lo); + if (ret < 0) + goto out; + + ret = intel_pmc_gcr_read(PMC_GCR_TELEM_SHLW_S0IX_HI_REG, + &shlw_hi); + if (ret < 0) + goto out; + + ret = intel_pmc_gcr_read(PMC_GCR_TELEM_DEEP_S0IX_LO_REG, + &deep_lo); + if (ret < 0) + goto out; + + ret = intel_pmc_gcr_read(PMC_GCR_TELEM_DEEP_S0IX_HI_REG, + &deep_hi); + if (ret < 0) + goto out; + + suspend_shlw_res_exit = TELEM_LO_HI_TO64(shlw_lo, shlw_hi); + if (suspend_shlw_res_exit > suspend_shlw_res_temp) + suspend_shlw_ctr_exit++; + + suspend_deep_res_exit = TELEM_LO_HI_TO64(deep_lo, deep_hi); + if (suspend_deep_res_exit > suspend_deep_res_temp) + suspend_deep_ctr_exit++; + } + suspend_shlw_ctr_exit -= suspend_shlw_ctr_temp; suspend_deep_ctr_exit -= suspend_deep_ctr_temp; suspend_shlw_res_exit -= suspend_shlw_res_temp;