Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp4331011ybe; Mon, 9 Sep 2019 07:48:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqzinx7bgXu1xJ05xn/lrbtnxvP3b1wsTEdM4H0MeoCbgcyqJbf2YfB7vusXrsrk6WUO+L2z X-Received: by 2002:a05:6402:1598:: with SMTP id c24mr24794913edv.174.1568040529403; Mon, 09 Sep 2019 07:48:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568040529; cv=none; d=google.com; s=arc-20160816; b=WLPZ7tXB415vN5DZYeijbG818VAgQPNFmBemyvHbrJfu3o7Kaj5O+igTNDEe9LgpDW PG2HZkuvBQhv20341ZwHntkD2rr+iyAxxNqcW5qe2qL87kp0xpNn9rfErI4fqB+J0cNj u/H6wME7Q20biZn3SXK1KcIgua3hjMIYn/tOF2WDfDNgH3DM0B9JdhBYKKwbRBBvEUd/ /r7d6hoPJKl/2FRVk/MLu+VHdEx9SaAYMG1+FNl8SW0BxPDjxwGzRd/4WmLM0R5/eP2c 4hymj3+iCqMby2ypCydUcocdEI1GVR4BSuH69KAifur4bdngjUdC2sFn43vujMfKD79Z tL0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:content-transfer-encoding:mime-version :message-id:date:subject:cc:from; bh=t3Yw6mHDHhvkwPG7FqVkXHxripuzONyydCL3N7ZLtOU=; b=XMoJwfDnXHTncU4zgkMZUpTnmO+aFr10GWNxDISkzL69dW/LHgOUK6z6qa1kcGgqKO OyJDMgnF+98JQqMYq2LRxuREOrjOoTjtt7eh7GWR1oibqhWoS4U69Yy0Bp7OYwL9KMFK Jg2nnn2mHTPt2YIVsgjD9PREXWEUb2l/c6BTSB4wxQ9tsnkQ7suCwUvNB6VP6geEX/kX IS3C8PU5IJL2Hy6IqqasxVXmFFMIihzOGmIDbERcl510Whwdgh9RwgbGWI3o7/dUvy0u Yk+yQalURjmFQF5+6HK93/bh0hpVU2/0iHrYvpW4VEXYCecn9mXN8gfKNQE6XjfmSQYy JWEw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g37si8682568edg.59.2019.09.09.07.48.25; Mon, 09 Sep 2019 07:48:49 -0700 (PDT) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733052AbfIIHjk (ORCPT + 99 others); Mon, 9 Sep 2019 03:39:40 -0400 Received: from mga17.intel.com ([192.55.52.151]:2203 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726026AbfIIHjk (ORCPT ); Mon, 9 Sep 2019 03:39:40 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Sep 2019 00:39:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,484,1559545200"; d="scan'208";a="196113218" Received: from fyin-dev.sh.intel.com ([10.239.143.122]) by orsmga002.jf.intel.com with ESMTP; 09 Sep 2019 00:39:38 -0700 From: Yin Fengwei Cc: "Rafael J. Wysocki" , Len Brown , linux-acpi@vger.kernel.org (open list:ACPI), linux-kernel@vger.kernel.org (open list) Subject: [RESEND] ACPI / processor_idle: use dead loop instead of io port access for wait Date: Mon, 9 Sep 2019 15:39:37 +0800 Message-Id: <20190909073937.31554-1-fengwei.yin@intel.com> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In function acpi_idle_do_entry(), we do an io port access to guarantee hardware behavior. But it could trigger unnecessary vmexit for virtualization environemnt. From the comments of this part of code, we could use busy wait instead of io port access to guarantee hardware behavior and avoid unnecessary vmexit. Signed-off-by: Yin Fengwei --- drivers/acpi/processor_idle.c | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c index ed56c6d20b08..676553228e8f 100644 --- a/drivers/acpi/processor_idle.c +++ b/drivers/acpi/processor_idle.c @@ -55,6 +55,8 @@ struct cpuidle_driver acpi_idle_driver = { }; #ifdef CONFIG_ACPI_PROCESSOR_CSTATE +static struct timespec64 dummy_delta = {0L, 0L}; + static DEFINE_PER_CPU(struct acpi_processor_cx * [CPUIDLE_STATE_MAX], acpi_cstate); @@ -64,6 +66,18 @@ static int disabled_by_idle_boot_param(void) boot_option_idle_override == IDLE_HALT; } +static void dummy_wait(void) +{ + struct timespec64 now, target; + + ktime_get_real_ts64(&now); + target = timespec64_add(now, dummy_delta); + + do { + ktime_get_real_ts64(&now); + } while (timespec64_compare(&now, &target) < 0); +} + /* * IBM ThinkPad R40e crashes mysteriously when going into C2 or C3. * For now disable this. Probably a bug somewhere else. @@ -660,8 +674,12 @@ static void __cpuidle acpi_idle_do_entry(struct acpi_processor_cx *cx) inb(cx->address); /* Dummy wait op - must do something useless after P_LVL2 read because chipsets cannot guarantee that STPCLK# signal - gets asserted in time to freeze execution properly. */ - inl(acpi_gbl_FADT.xpm_timer_block.address); + gets asserted in time to freeze execution properly. + + Previously, we do io port access here which could trigger + unnecessary trap to HV for virtualization env. We use dead + loop here to avoid the impact to virtualization env. */ + dummy_wait(); } } @@ -683,7 +701,7 @@ static int acpi_idle_play_dead(struct cpuidle_device *dev, int index) else if (cx->entry_method == ACPI_CSTATE_SYSTEMIO) { inb(cx->address); /* See comment in acpi_idle_do_entry() */ - inl(acpi_gbl_FADT.xpm_timer_block.address); + dummy_wait(); } else return -ENODEV; } @@ -902,6 +920,7 @@ static inline void acpi_processor_cstate_first_run_checks(void) { acpi_status status; static int first_run; + struct timespec64 ts0, ts1; if (first_run) return; @@ -912,6 +931,13 @@ static inline void acpi_processor_cstate_first_run_checks(void) max_cstate); first_run++; + /* profiling the time used for dummy wait op */ + ktime_get_real_ts64(&ts0); + inl(acpi_gbl_FADT.xpm_timer_block.address); + ktime_get_real_ts64(&ts1); + + dummy_delta = timespec64_sub(ts1, ts0); + if (acpi_gbl_FADT.cst_control && !nocst) { status = acpi_os_write_port(acpi_gbl_FADT.smi_command, acpi_gbl_FADT.cst_control, 8); @@ -920,6 +946,7 @@ static inline void acpi_processor_cstate_first_run_checks(void) "Notifying BIOS of _CST ability failed")); } } + #else static inline int disabled_by_idle_boot_param(void) { return 0; } -- 2.19.1