Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3434023pxj; Mon, 24 May 2021 06:43:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyiknh0CUXD8qEcKunI7nw3/ixLB6yCXjtdT+J581Xqe2hYHJNNW8gVoRUjqzCNtH8Wn47J X-Received: by 2002:a92:c607:: with SMTP id p7mr16502852ilm.97.1621863826687; Mon, 24 May 2021 06:43:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621863826; cv=none; d=google.com; s=arc-20160816; b=YboVA7KOUiJjuXYfp/cHSAtFw7AzLBj/v3AdA60ib2Cx46RPSzWmXfVbHsQc8pRqkW YNBYv0KTWw+ONzojFFVEQTexZK+c2HH02VbYpDP76gr4mjuFwLT/YYjaak4C5jaX6slh Jkz7yB4Pt5bhTxlrJ1kxj2mO56K63fPyghD24sgaEYG3l1LUa0aJTw875WrDzsvDGyjf RQ2+eioXO1fZp6t5BtViElsJ+ZIZGFX2CKnpO8oZBp4OUsHYe5u+70qGQR6nYvV5Juew 7pKYxrfpZDr1tusHVy/1i1UbWSOvbDZtYDnhwCwHyNnwViRPhlM1IrT0doz57Ew+zamU PC4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=DUGrASOClCVVu+4hqHSu8VfIIMkQ9/UZu/ZQ1hqek/8=; b=v+ugAh6Qpy7jUxbo5v9Isc7a2lGD7iWTY58V6lbGka1MF3qPBWdSeFqOUKlfyeVO27 v3yRdH8cOhQ2JVbXuOaeFiGJTix6CNwRvTJP3yVVYvQtvajso4T/NHtiNVrP0TxWcXHF ElRZWlru/aqZUKVC+6K7XvYNzM83KSldN2lfllb6Ui0sP1qzoQMZsLDcNfArcOXxmGzZ 3zws/3evHH9EoqeS8xZhaItDGK/v+2vCi0PnSjb629cFocENgwcypT8XP1WgxZWilTFJ dXYsFi4b8WCItIHxBWKnUiNpC+fPr8GCEdABVU/U51IgqSDt3M7U83bxXYCKos6WmyH+ MSFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MhufEkbu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b15si15268545jat.59.2021.05.24.06.43.32; Mon, 24 May 2021 06:43:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MhufEkbu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232907AbhEXNoD (ORCPT + 99 others); Mon, 24 May 2021 09:44:03 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:51960 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232903AbhEXNoC (ORCPT ); Mon, 24 May 2021 09:44:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621863754; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DUGrASOClCVVu+4hqHSu8VfIIMkQ9/UZu/ZQ1hqek/8=; b=MhufEkbuLsU/q2UUxz3q0qfgNtYZS4QaH/huXqzjS1u0IGv60q9bQY18wS0bYYTj9IFugG XFNz4xxQCBnDjI5s1joChw9aVO2bLgNd/8QD0stnt4hTnKCf8tk4mUpXVeayGeHfKivV71 IKuhkMRpKpE40dIBLMFPCE9lr4h9D+4= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-388-cSNDkjNnNH-thcDR-ePhpA-1; Mon, 24 May 2021 09:42:32 -0400 X-MC-Unique: cSNDkjNnNH-thcDR-ePhpA-1 Received: by mail-ed1-f71.google.com with SMTP id q18-20020a50cc920000b029038cf491864cso15566664edi.14 for ; Mon, 24 May 2021 06:42:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=DUGrASOClCVVu+4hqHSu8VfIIMkQ9/UZu/ZQ1hqek/8=; b=p7GeztU/2Syj81rXmY57PEJhCWQ8IhZBnXMuj0zCmTw1WNlv6A5HMSyAtqtPvt5yRI CgP/OA07h/1t3OxS5Boyv454aBeuuOhqrA0GsaDOSDEI58jN1F+aPwAHq7TOjMvxup3V S3qRDq6YjiYvrD/D6SS2sZAlT2DHbvcRRDq+bYhqcQFMzZtoqF0+GxhzPKM4ln2J1L02 zsr38wx+e6lfjm9z4Sj1vt6E44yNU2/btaT64st5BXkMcuWErvSag+EuKe7mF4I17BrU 5r1D0e3R+X9sI25i05D0SKE2LcrJqspBDz7eepYPQlRo3epWJwljR4d2WFdWUswpq5UA 8FvQ== X-Gm-Message-State: AOAM531AR6CFFK4VfuVB3drCsZUU9MpShj45DJ/AZV7Eego7InRcxy4c h8E5OZJ8DiJFQqxGYw7as9kPyAvn9Mz8Pnp+bkBuhUADA5XCr+tdrtEclkvmEZjlnE4yz6aIITZ fUzFRUmIWdK79T+glO6iaH32k X-Received: by 2002:a17:906:d1d1:: with SMTP id bs17mr23600358ejb.492.1621863751795; Mon, 24 May 2021 06:42:31 -0700 (PDT) X-Received: by 2002:a17:906:d1d1:: with SMTP id bs17mr23600344ejb.492.1621863751659; Mon, 24 May 2021 06:42:31 -0700 (PDT) Received: from ?IPv6:2001:b07:6468:f312:c8dd:75d4:99ab:290a? ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id q16sm7960408ejm.12.2021.05.24.06.42.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 24 May 2021 06:42:31 -0700 (PDT) Subject: Re: [PATCH v4 2/5] KVM: X86: Bail out of direct yield in case of under-committed scenarios To: Wanpeng Li , Sean Christopherson Cc: LKML , kvm , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel References: <1621339235-11131-1-git-send-email-wanpengli@tencent.com> <1621339235-11131-2-git-send-email-wanpengli@tencent.com> From: Paolo Bonzini Message-ID: <889a0a43-0641-70ce-d2a5-ed71bd54e59c@redhat.com> Date: Mon, 24 May 2021 15:42:30 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 19/05/21 04:57, Wanpeng Li wrote: > Looks good. Hope Paolo can update the patch description when applying.:) > > "In case of under-committed scenarios, vCPU can get scheduling easily, > kvm_vcpu_yield_to add extra overhead, we can observe a lot of races > between vcpu->ready is true and yield fails due to p->state is > TASK_RUNNING. Let's bail out in such scenarios by checking the length > of current cpu runqueue, it can be treated as a hint of under-committed > instead of guaranteeing accuracy. 30%+ of directed-yield attempts can > avoid the expensive lookups in kvm_sched_yield() in an under-committed > scenario. " > Here is what I used: In case of under-committed scenarios, vCPUs can be scheduled easily; kvm_vcpu_yield_to adds extra overhead, and it is also common to see when vcpu->ready is true but yield later failing due to p->state is TASK_RUNNING. Let's bail out in such scenarios by checking the length of current cpu runqueue, which can be treated as a hint of under-committed instead of guarantee of accuracy. 30%+ of directed-yield attempts can now avoid the expensive lookups in kvm_sched_yield() in an under-committed scenario. Paolo