Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp1728267ybg; Sat, 19 Oct 2019 01:12:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqyQxEb/BgTjh/Fub9qz0z2xR2ZP43jEg7DU1Fnv9VX0dhtD16L75alScHqHoG8pqz+TkBWh X-Received: by 2002:a05:6402:7cc:: with SMTP id u12mr14181318edy.63.1571472771619; Sat, 19 Oct 2019 01:12:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571472771; cv=none; d=google.com; s=arc-20160816; b=BpK7SjZOyJ8plBl8XCH84pVQdkqAw/YWffPLr8F0MmPKSQGwOGrQGog/f6/vTqt96I GXEPfb1E1C1lSey4P7eB1kYSMgkgiR8cGLkAZxGuijSIPztx0xFEaCX+CgtKXk3o5zts pbu6KNylN8kD+GQXynXnivgipBuMqb+V7TWtpLJlnt+h78+qDhhMW8vyXs/gsr9pozZP 8iHZoBflPqCUXpGGhNLOhc/gt6IpXFI9MnGBeLpDUj5FH0Lygw0PKyY9VD9+02zblFhX Vb9qQSRuS4PhSpx7xpPFyqD07NZhRF/lwHYZ4AgTiMoq4l1fNkrLgdWFMhGhEAPuj2JI 32Qg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=W2VSQIZfo6QyvDNGrsBxANz0M1L66BWwI/FGUyFptFw=; b=uCnH8XquTSWMAMUC5t6oLUkILPfKg1zbQXOFbX4pJ2CaQ4BgV4uuCIVCL/2uu4RIcR pBvLik953He3gAj2uOtw09649v+ILyDpKUVej0tE4TGUwMUS7EUV0vT3DUwXMg9v3cEB a0XYkhm0Ry78P6++TVLjlHLv3HtTa3tJDXqtgDy7XQtKOT2thpTTJ8XvU2sUSMJQkOTf il6lg8Wc9xMdgj7OUshycSFK8/LSFIcJ/4m0Q9cixdn1DIKfvVDuh4kr8AMjMpGRCOZe 2dz+AX/fjuGKnbEGYEeZEhPOk9oveyf24ZuyRaWoH7tLVMAH8RndBMkX1bUaNbHTBVWQ womQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l23si4847444ejr.296.2019.10.19.01.12.28; Sat, 19 Oct 2019 01:12:51 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2633301AbfJRKM6 (ORCPT + 99 others); Fri, 18 Oct 2019 06:12:58 -0400 Received: from cloudserver094114.home.pl ([79.96.170.134]:41123 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387545AbfJRKM6 (ORCPT ); Fri, 18 Oct 2019 06:12:58 -0400 Received: from 79.184.255.51.ipv4.supernova.orange.pl (79.184.255.51) (HELO kreacher.localnet) by serwer1319399.home.pl (79.96.170.134) with SMTP (IdeaSmtpServer 0.83.292) id 49e72b95e28af242; Fri, 18 Oct 2019 12:12:54 +0200 From: "Rafael J. Wysocki" To: "Yin, Fengwei" Cc: David Laight , "lenb@kernel.org" , "linux-acpi@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH v2] ACPI / processor_idle: use ndelay instead of io port access for wait Date: Fri, 18 Oct 2019 12:12:54 +0200 Message-ID: <2566427.rT6C98KLSe@kreacher> In-Reply-To: <2b3ce9e9-e805-1b8d-86c3-c8f498a4d3dd@intel.com> References: <20191015080404.6013-1-fengwei.yin@intel.com> <2b3ce9e9-e805-1b8d-86c3-c8f498a4d3dd@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wednesday, October 16, 2019 7:56:17 AM CEST Yin, Fengwei wrote: > Hi David, > > On 10/15/2019 7:48 PM, David Laight wrote: > > From: Yin Fengwei > >> Sent: 15 October 2019 09:04 > >> In function acpi_idle_do_entry(), an ioport access is used for dummy > >> wait to guarantee hardware behavior. But it could trigger unnecessary > >> vmexit in virtualization environment. > >> > >> If we run linux as guest and export all available native C state to > >> guest, we did see many PM timer access triggered VMexit when guest > >> enter deeper C state in our environment (We used ACRN hypervisor > >> instead of kvm or xen which has PM timer emulated and exports all > >> native C state to guest). > >> > >> According to the original comments of this part of code, io port > >> access is only for dummy wait. We could use busy wait instead of io > >> port access to guarantee hardware behavior and avoid unnecessary > >> VMexit. > > > > You need some hard synchronisation instruction(s) after the inb() > > and before any kind of delay to ensure your delay code is executed > > after the inb() completes. > > > > I'm pretty sure that inb() is only synchronised with memory reads. > Thanks a lot for the comments. > > I didn't find the common serializing instructions API in kernel (only > memory barrier which is used to make sure of memory access). For Intel > x86, cpuid could be used as serializing instruction. But it's not > suitable for common code here. Do you have any suggestion? In the virt guest case you don't need to worry at all AFAICS, because the inb() itself will trap to the HV. > > > > ... > >> + /* 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); You may as well use ktime_get() for this, as it's almost the same code as ktime_get_real_ts64() AFAICS, only simpler. Plus, static vars need not be initialized to 0. > > > > That could be dominated by the cost of ktime_get_real_ts64(). > > It also need synchronising instructions. > I did some testing. ktime_get_real_ts64() takes much less time than io > port access. > > The test code is like: > 1. > local_irq_save(flag); > ktime_get_real_ts64(&ts0); > inl(acpi_gbl_FADT.xpm_timer_block.address); > ktime_get_real_ts64(&ts1); > local_irq_restore(flag); > > 2. > local_irq_save(flag); > ktime_get_real_ts64(&ts0); > ktime_get_real_ts64(&ts1); > local_irq_restore(flag); > > The delta in 1 is about 500000ns. And delta in 2 is about > 2000ns. The date is gotten on Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz. > So I suppose the impact of ktime_get_real_ts64 is small. You may not be hitting the worst case for ktime_get_real_ts64(), though. I wonder if special casing the virt guest would be a better approach. Then, you could leave the code as is for non-virt and I'm not sure if the delay is needed in the virt guest case at all. So maybe do something like "if not in a virt guest, do the dummy inl()" and that would be it?