Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp1230280rdb; Sat, 18 Nov 2023 07:53:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IEcJejOXc7Rd/9LPgRoeFpWevQotc8fmiNfdcujzubm0KlqGR69Ir7TsXBdmGafg0NZfPxM X-Received: by 2002:a05:6808:2a02:b0:3ac:a522:5461 with SMTP id ez2-20020a0568082a0200b003aca5225461mr3159866oib.36.1700322799929; Sat, 18 Nov 2023 07:53:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700322799; cv=none; d=google.com; s=arc-20160816; b=SNecBQI6br4+tWmCGBel1fJQWz0HSKg1l3kWW/2xnCmRR6YCpWdvjuL1H1k2xzfoni qGGq8vRtxhiZBPqZszJbZ8MTQg7EMX8VOntf236k6aXJ/zcqQk9o6iD11lSW/0ZCNQ9o B15h62Cgpdbrqn5U9x3C/m8Rp9hwstRD8AJBBwdDG26D3hZeHxtk1fVUYQwN0RK+9n9V 3agPnJaYBqFK59XAnhaSJbovV5qmLJvwQDthk1Q49elk3qPD2EdX3NgAdPQBRM9g6hxL baFknxfWAhON93+YTL4aqq4W8+DsVth4ZQHG4lC8WD85rDY0SoEiWKFjAyFmBmk2sqDv cQcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=FWIlOk1FsRTd5Pg1eEMJS0d0MbiyZx68JIVX7B57ps0=; fh=c1BYRk7JYcxDfDmE70ijSNOm8k5Gejuj5f742qPnA0g=; b=gMdwdMd+xeIig7/oTQqI5ITDyCiyE9Zr8i2I53HInB+jw6423aUvtNA6Zh6iGjHdvm tyvNWzubUrhCP0g9GZMGYr4USF/okxOeb7XGyo7cLX8cI2fDeAp48LOvAf5BqhopB7qP GEXfxu+/izMgjZ8+4aGiwXH4fiO+nnwivlzMN3gTs6vusDHDldG/2zjvZcIuetrbAGvy V0ornxEqM0WziRxzL0VjWVvYRdIKtBQsOMYlvNYw86GJ4v0et4AGB9CZvANodH8cr8+y 8R3PpaFqynltgCXYoTVsCHXFmYE3RWe16kRlCAM836P/nM3suUUtp7laHW9i0/7AXmbk zbWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=mXAB05eH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id r35-20020a63fc63000000b005b8ee1c0c67si4272307pgk.594.2023.11.18.07.53.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Nov 2023 07:53:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=mXAB05eH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 53DCC8051A20; Sat, 18 Nov 2023 07:53:16 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231397AbjKRPxA (ORCPT + 99 others); Sat, 18 Nov 2023 10:53:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230216AbjKRPw3 (ORCPT ); Sat, 18 Nov 2023 10:52:29 -0500 Received: from mail-yw1-x112f.google.com (mail-yw1-x112f.google.com [IPv6:2607:f8b0:4864:20::112f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DECA11985; Sat, 18 Nov 2023 07:51:31 -0800 (PST) Received: by mail-yw1-x112f.google.com with SMTP id 00721157ae682-5a7fb84f6ceso29711467b3.1; Sat, 18 Nov 2023 07:51:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700322689; x=1700927489; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FWIlOk1FsRTd5Pg1eEMJS0d0MbiyZx68JIVX7B57ps0=; b=mXAB05eHIJUK3SjzKjiL/jMGPGujkItEHsnP4JJFtHV57ZvtkIiEdaTnoDuv1Hs+PV q+RK/R0TZffv6D/9MK8vRCS/tu/WtD0ZU4maYuIQPvmu03BJRHoNnjg5bVNFBtyBBh+F pTjRxP8YTIsxyUnwv8dltoKsA6Hd6DzZbvkrNop+hsS9NicxayHvVTc5wU4w3ZY5oPvb R5Q2Ipe3rm4pvAwQolwXK2TFIKUpkc2zbbaxrRlHFo2m7rPa9Gj9HrS5Cq3/B61TBpMD Du9r4Obt9Cnfgv9N2PfJHRg8uxbiycN2uAbLYN0/uMVaT9EDs1RGmOPO6W79HNKEodfB 8Y4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700322689; x=1700927489; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FWIlOk1FsRTd5Pg1eEMJS0d0MbiyZx68JIVX7B57ps0=; b=tr5nUVMepAS5806kNAfiJvw17Ug5+cV96trbomLUI6k/U/4tGwSlVYsIRRsgn+Xitt MnCq8qNrMnnavztvIBGQwvwVyD6Wt4XXDnS4WB7KFhPuGAhLEKz3pQzKt855Mc0B4Kdt /CkxHQA7+a/dKliqecawq974HYnGhdYTiuLvE7X08MmoXL//GI7cv/qwhv4s1/O/uPWm vIVwrc9/1ZPu/lgWBO7yWo4BYgNg7oRC+ORkAuLfBc7dqhvKCh8btFn+BykAjY/q3FyR gCGTMb0NYUeNgHGsv5i0e+aLxrcsjUXLlz5c7D5iDjcetI8eWMInfKyS4G543oY0D6EM IRvQ== X-Gm-Message-State: AOJu0YyRJRAOANLV/nOITrWhUmxTZRto3nmONas9CLQ74T1GXCB/1jz+ oNNTxrPgSKS1Y2jFW9osoLvNrdxtjgRcCiNI X-Received: by 2002:a0d:d54e:0:b0:5a7:ba53:be73 with SMTP id x75-20020a0dd54e000000b005a7ba53be73mr2010066ywd.15.1700322689525; Sat, 18 Nov 2023 07:51:29 -0800 (PST) Received: from localhost ([2601:344:8301:57f0:48a9:bd4c:868d:dc97]) by smtp.gmail.com with ESMTPSA id k186-20020a0dfac3000000b00559f1cb8444sm1186208ywf.70.2023.11.18.07.51.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Nov 2023 07:51:29 -0800 (PST) From: Yury Norov To: linux-kernel@vger.kernel.org, Vitaly Kuznetsov , Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , kvm@vger.kernel.org Cc: Yury Norov , Jan Kara , Mirsad Todorovac , Matthew Wilcox , Rasmus Villemoes , Andy Shevchenko , Maxim Kuvyrkov , Alexey Klimov Subject: [PATCH 13/34] KVM: x86: hyper-v: optimize and cleanup kvm_hv_process_stimers() Date: Sat, 18 Nov 2023 07:50:44 -0800 Message-Id: <20231118155105.25678-14-yury.norov@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231118155105.25678-1-yury.norov@gmail.com> References: <20231118155105.25678-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Sat, 18 Nov 2023 07:53:16 -0800 (PST) The function traverses stimer_pending_bitmap n a for-loop bit by bit. We can do it faster by using atomic find_and_set_bit(). While here, refactor the logic by decreasing indentation level and dropping 2nd check for stimer->config.enable. Signed-off-by: Yury Norov --- arch/x86/kvm/hyperv.c | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c index 238afd7335e4..460e300b558b 100644 --- a/arch/x86/kvm/hyperv.c +++ b/arch/x86/kvm/hyperv.c @@ -870,27 +870,26 @@ void kvm_hv_process_stimers(struct kvm_vcpu *vcpu) if (!hv_vcpu) return; - for (i = 0; i < ARRAY_SIZE(hv_vcpu->stimer); i++) - if (test_and_clear_bit(i, hv_vcpu->stimer_pending_bitmap)) { - stimer = &hv_vcpu->stimer[i]; - if (stimer->config.enable) { - exp_time = stimer->exp_time; - - if (exp_time) { - time_now = - get_time_ref_counter(vcpu->kvm); - if (time_now >= exp_time) - stimer_expiration(stimer); - } - - if ((stimer->config.enable) && - stimer->count) { - if (!stimer->msg_pending) - stimer_start(stimer); - } else - stimer_cleanup(stimer); - } + for_each_test_and_clear_bit(i, hv_vcpu->stimer_pending_bitmap, + ARRAY_SIZE(hv_vcpu->stimer)) { + stimer = &hv_vcpu->stimer[i]; + if (!stimer->config.enable) + continue; + + exp_time = stimer->exp_time; + + if (exp_time) { + time_now = get_time_ref_counter(vcpu->kvm); + if (time_now >= exp_time) + stimer_expiration(stimer); } + + if (stimer->count) { + if (!stimer->msg_pending) + stimer_start(stimer); + } else + stimer_cleanup(stimer); + } } void kvm_hv_vcpu_uninit(struct kvm_vcpu *vcpu) -- 2.39.2