Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7330986rwb; Tue, 6 Dec 2022 04:31:57 -0800 (PST) X-Google-Smtp-Source: AA0mqf6hMgmd2PMRJa3//lqWOJ1uNnUy4uJCp9Xsr8LDIdpItxz9xGjr58UdURJQ80+0rvg1REdP X-Received: by 2002:a17:903:214c:b0:189:b5a3:8144 with SMTP id s12-20020a170903214c00b00189b5a38144mr23580027ple.100.1670329917244; Tue, 06 Dec 2022 04:31:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670329917; cv=none; d=google.com; s=arc-20160816; b=eKXt1RD0HsQteSJFB4GoWZRixjR5sRPgxbLRR7XsB7a6flMHhkY7pnaOunkvX0ZkLB 7/wnFpksXNNm8rXcDTBRA1tpImGfgqBR0pkRLL0tP5OZtqwbHu1jS2LuatYXIZ7PQKrY y2otBjGLFlF6vUQZgOwaYyvSHmQSlwnFHgkseiPFIfAlVT0jv8kIrkN2baoRHCwnHzC9 OjMHpOwT3d0oPmfsXgQlMKp0F6xcodva0UXbCJy52QmWz/rVkbIf2xaPKm3lWnjsr6C+ gIL7VjaIpBVX+jPhYO5tKNOU8ZGgmSEIYr1a70r36JDxTFlnBVFD8vabayxKUPQYMOQI zhOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=+mGLgjowZaCmnCPsw0ckZL1G6OY59bS094DGttlz+1o=; b=sgrArBZVznB+tVjuBBeYxL4DAT9XqVNacg2q13tuyMcNcorFoLcM3jMG882mrx6S0e yLiirtCQly8D5nFXZa/uTRLZzpFi7bX+hmLgxLvOzeYqN9HUeBvF695Z0wTnKup3k8Qd wCS6RezJu8so8rHcm+j3DHM0TI8eFIqI9ZGEegJOWJqLCkXYxk2RiaZUlf9Ix1jBHgS1 KC0sQVd1uSu/ihjzL33T/wFd+2Z7uJRp1BVzuP5j/4DBISIY3KBVPWFiI/3SxnxBMYac Zn+glD9Ucy06G1rQ4rY97d6Gsd5FAhx/GzqPN69Rysr5mjEKJtViUq1ztVcLgCnTEo/8 toeQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u25-20020a634719000000b004774c91af0dsi16944969pga.841.2022.12.06.04.31.45; Tue, 06 Dec 2022 04:31:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234658AbiLFMBc (ORCPT + 80 others); Tue, 6 Dec 2022 07:01:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234883AbiLFMAy (ORCPT ); Tue, 6 Dec 2022 07:00:54 -0500 Received: from mail-qk1-f176.google.com (mail-qk1-f176.google.com [209.85.222.176]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84F9A2A275; Tue, 6 Dec 2022 03:59:14 -0800 (PST) Received: by mail-qk1-f176.google.com with SMTP id p18so7250501qkg.2; Tue, 06 Dec 2022 03:59:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=+mGLgjowZaCmnCPsw0ckZL1G6OY59bS094DGttlz+1o=; b=Z4Wm+xjfSK8rwmUOSnpgJGiC8t7vXMfgZUVFmKHSdc3+jc6+EgO8UgQZOmOnPMFRt4 //vOGFYRfIu2GPZfAMVTfD+wWcVyrjDOcJVgbc2l2Fb0q6pU59IoiKZ1CjqkQoj7fTgz VjfxyJbS+hTPv3mafCXq2K2hzk5aGt7KbF9kNLi9+BUKITvDkjZVU0lsWG5pTKrM1aH3 JVV6YQiZSwqzzKj4F35xM2oFH0nYwCM0ifwFfXfLIsZP3zhd24oW/iu7EUXHXYzMhFUG L4bRznzNxa3zbN2KK8J9HPVkCQmKExahbRpauO8hbJCPyF40qiq3JvjHoBdLA2qLm/SM CttA== X-Gm-Message-State: ANoB5pnchnxOGQtkuOWSoDzUkyT4N+tD50FJlGMbX2x9JCkUd6/fQHio u8KLVvqH4rFbL/mmttEZAEowic20RIrBzceah9I76U5lTNQ= X-Received: by 2002:a05:620a:22fa:b0:6fb:c38e:e5dd with SMTP id p26-20020a05620a22fa00b006fbc38ee5ddmr76278468qki.23.1670327953581; Tue, 06 Dec 2022 03:59:13 -0800 (PST) MIME-Version: 1.0 References: <1670308998-12313-1-git-send-email-lirongqing@baidu.com> In-Reply-To: <1670308998-12313-1-git-send-email-lirongqing@baidu.com> From: "Rafael J. Wysocki" Date: Tue, 6 Dec 2022 12:59:02 +0100 Message-ID: Subject: Re: [PATCH] cpuidle-haltpoll: Disable kvm guest polling when mwait_idle is used To: lirongqing@baidu.com Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, rafael@kernel.org, daniel.lezcano@linaro.org, peterz@infradead.org, akpm@linux-foundation.org, tony.luck@intel.com, jpoimboe@kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Dec 6, 2022 at 7:43 AM wrote: > > From: Li RongQing First off, can you please write the changelog as proper text in English using capital letters and periods where applicable? It is hard to read the way it is. > when KVM guest has mwait and mwait_idle is used as default idle function, > Loading cpuidle-haltpoll will make idle function back to default_idle which > is using HLT, Which is because the ->enter callback pointer of state 1 in the haltpoll driver points to default_enter_idle() which in turn invokes default_idle() directly, right? > As the commit aebef63cf7ff ("x86: Remove vendor checks from > prefer_mwait_c1_over_halt") explains that mwait is preferred > > so disable kvm guest polling in this conditions to improve performance, > like sockperf localhost test shows that latency is reduced by about 20% > > Signed-off-by: Li RongQing > --- > arch/x86/include/asm/processor.h | 2 ++ > arch/x86/kernel/process.c | 6 ++++++ > drivers/cpuidle/cpuidle-haltpoll.c | 4 ++++ > 3 files changed, 12 insertions(+) > > diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h > index 67c9d73..159ef33 100644 > --- a/arch/x86/include/asm/processor.h > +++ b/arch/x86/include/asm/processor.h > @@ -862,4 +862,6 @@ bool arch_is_platform_page(u64 paddr); > #define arch_is_platform_page arch_is_platform_page > #endif > > +bool is_mwait_idle(void); > + > #endif /* _ASM_X86_PROCESSOR_H */ > diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c > index c21b734..330972c 100644 > --- a/arch/x86/kernel/process.c > +++ b/arch/x86/kernel/process.c > @@ -896,6 +896,12 @@ void select_idle_routine(const struct cpuinfo_x86 *c) > x86_idle = default_idle; > } > > +bool is_mwait_idle(void) > +{ > + return x86_idle == mwait_idle; > +} > +EXPORT_SYMBOL_GPL(is_mwait_idle); > + > void amd_e400_c1e_apic_setup(void) > { > if (boot_cpu_has_bug(X86_BUG_AMD_APIC_C1E)) { > diff --git a/drivers/cpuidle/cpuidle-haltpoll.c b/drivers/cpuidle/cpuidle-haltpoll.c > index 3a39a7f..8cf1ddf 100644 > --- a/drivers/cpuidle/cpuidle-haltpoll.c > +++ b/drivers/cpuidle/cpuidle-haltpoll.c > @@ -17,6 +17,7 @@ > #include > #include > #include > +#include > > static bool force __read_mostly; > module_param(force, bool, 0444); > @@ -111,6 +112,9 @@ static int __init haltpoll_init(void) > if (!kvm_para_available() || !haltpoll_want()) > return -ENODEV; > > + if (is_mwait_idle()) > + return -ENODEV; > + So perhaps you could make default_enter_idle() be a bit more careful about what it calls as the "default idle" routine? > cpuidle_poll_state_init(drv); > > ret = cpuidle_register_driver(drv); > -- Anyway, this is unlikely to get into 6.2, so please defer it until 6.2-rc1 is out.