Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp2594848rdb; Mon, 4 Dec 2023 01:53:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IH0Ofh2Xoq88BTFySZUe6RucrhLnt39RbOyjzFway0HwPGsl1Mwt3Bm8Pq84Vg/DSQnTDJ8 X-Received: by 2002:a17:90a:a08e:b0:286:6cc1:3f05 with SMTP id r14-20020a17090aa08e00b002866cc13f05mr3035915pjp.60.1701683605577; Mon, 04 Dec 2023 01:53:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701683605; cv=none; d=google.com; s=arc-20160816; b=GqTH84OB0To5oRR4DYpZ4MhcCXFykEfBKGdZIHTbK3/q4rhY2ZLjUsvI1zBU8mmyoE UxWCO4p+SPtA/dmyE2+gZb7JZpOLKXrb/lXh7d75pZiTFsSq0T7LWdzYSGGE27Alo9tA zWKpnnixyXr+pDdDnTHXaY/0drfsuJCgeKLYDrcH3LHCMxELqUfeITCEzdZb1T1eg2af owOic0HIs+5rstg+IWWnuKHmB4zGiUpNaSspBBG1IIrv6AKlNnoeHEXxlbZ8As/tQy3U oWB3MVO/zqb44N8Abefn+l9ppT8LTIB2h4rZP9NEqhZJbcXkjq/+uix1ABRpUb0qv3HS 4tMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=WqARk7fzedhZASB+ixpYpvasPr2FrtXK3g7WtNb8hEQ=; fh=R9IhIHbnRIMGn3r4ecI+8t4iXI/YSmwosyCMwRAVha4=; b=bIYV69UUsgNCWZnlSHE9zN+pIA1zxGQt6QyCs8dFCdDZH/BnRM/JCxV8af1bUxuhPc eHO/Rieb7CJ9V7hkwUVaM0F2Oyde4XWqiIoHrVmVnEnVXIb6s/aW0SZxyfC9I1v4EAzC nx0cpF52Nk7qHMiQ7ZuxxDoANBT2is+GNzfkVRINsO+nxXzl0k+4Qhv0yXrSXJwPJxb5 udMKoVbZnZNwZuADIQcrdLQnqblaWTBG2DWbAfF+6uEzBCB7XbtumUdXOSq1pGbLVTdS prVfLU54Z3cP69RXHADtPH/PQKVPiBAoncPSvOQ0YZdRCWaeCv58fzoDWVq1jNpZPF/2 4l3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=OpqegxrM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id t22-20020a17090ad51600b0028031f2f450si2909031pju.22.2023.12.04.01.53.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 01:53:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=OpqegxrM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 48647809FCB0; Mon, 4 Dec 2023 01:53:24 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230204AbjLDJxK (ORCPT + 99 others); Mon, 4 Dec 2023 04:53:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229532AbjLDJxH (ORCPT ); Mon, 4 Dec 2023 04:53:07 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75D20D6 for ; Mon, 4 Dec 2023 01:53:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701683592; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=WqARk7fzedhZASB+ixpYpvasPr2FrtXK3g7WtNb8hEQ=; b=OpqegxrMOzV0ZkqgflZp7I31dVpAAHjTHkc1daW2mXLqrR2dA751zHRJTAAc1cNH+JvG3c DuUwa+k1d0S08pzOwynmR4MK4CtfOPYONg2yfPQMX8vrGCcCOWluyiND+oJTbfVDRh8Fmn Q9VJwc15M+5SmKkO+nrmWd3JuLLCguU= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-82-DXcroBGOMK2mGA6pGqSkKA-1; Mon, 04 Dec 2023 04:53:08 -0500 X-MC-Unique: DXcroBGOMK2mGA6pGqSkKA-1 Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-5411d71889aso3253626a12.2 for ; Mon, 04 Dec 2023 01:53:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701683587; x=1702288387; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=WqARk7fzedhZASB+ixpYpvasPr2FrtXK3g7WtNb8hEQ=; b=gBDK8yKeTL5+4Vz4gZhUsAIEVs2GsB97h/7AcZnsDQzrnVJmEYvsi+ibw9mt1YOEmQ 1oygZl7szqL0bLkhoRnn1I7y4uc2UPwAcM/Ydh5WLr+k4DwAACnCxbvuSEX5rLpL/DNg cWJ+M5Vzgi2bIf6rn/DsVMys/cNHCjbrBoamAO14kKeerhClhi3Z/bpXGB5uTdy5tH5F IJGRVwoirYsyg7lHIwGWjaGRbqTzd3YpTXLk9tIC6tu7Judh50W1dMYV+J4RVM+ajO6x WyIAlrbnEDQ6JhbFRMpgW71d8tgcUap1IqfJDm0lIg+9cAVaayPIysvQ86SxRaVJl1Lo Mpqg== X-Gm-Message-State: AOJu0YzxWaImUbDq1TgjX1T0CgkIA0dmUFy+GRxwHRKpr2J2yHmtZHey 5pPacy46zYGhuEzxdHXyfphbvqoL/KFHVW3eouQ464GsWPV8qWcoaYfQHlfK9P3bXdLhJ9taKYY lzoBvsRbUqfk3AaiInJhgFb6Z X-Received: by 2002:a50:f60d:0:b0:54c:f3fe:b724 with SMTP id c13-20020a50f60d000000b0054cf3feb724mr153237edn.34.1701683587631; Mon, 04 Dec 2023 01:53:07 -0800 (PST) X-Received: by 2002:a50:f60d:0:b0:54c:f3fe:b724 with SMTP id c13-20020a50f60d000000b0054cf3feb724mr153211edn.34.1701683587289; Mon, 04 Dec 2023 01:53:07 -0800 (PST) Received: from fedora (g2.ign.cz. [91.219.240.8]) by smtp.gmail.com with ESMTPSA id a94-20020a509ee7000000b0054c9df4317dsm2169119edf.7.2023.12.04.01.53.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 01:53:06 -0800 (PST) From: Vitaly Kuznetsov To: Yury Norov , linux-kernel@vger.kernel.org, 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 , Bart Van Assche , Sergey Shtylyov Subject: Re: [PATCH v2 13/35] KVM: x86: hyper-v: optimize and cleanup kvm_hv_process_stimers() In-Reply-To: <20231203193307.542794-12-yury.norov@gmail.com> References: <20231203192422.539300-1-yury.norov@gmail.com> <20231203193307.542794-1-yury.norov@gmail.com> <20231203193307.542794-12-yury.norov@gmail.com> Date: Mon, 04 Dec 2023 10:53:05 +0100 Message-ID: <87h6kymgzi.fsf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE,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 lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Mon, 04 Dec 2023 01:53:24 -0800 (PST) Yury Norov writes: > The function traverses stimer_pending_bitmap in 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. > > CC: Vitaly Kuznetsov > 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..a0e45d20d451 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->config.enable && stimer->count) { > + if (!stimer->msg_pending) > + stimer_start(stimer); > + } else > + stimer_cleanup(stimer); Minor nitpick: it's better (and afair required by coding style) to use '{}' for both branches here: if (stimer->config.enable && stimer->count) { if (!stimer->msg_pending) stimer_start(stimer); } else { stimer_cleanup(stimer); } > + } > } > > void kvm_hv_vcpu_uninit(struct kvm_vcpu *vcpu) Reviewed-by: Vitaly Kuznetsov -- Vitaly