Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp5499891imd; Tue, 30 Oct 2018 19:39:42 -0700 (PDT) X-Google-Smtp-Source: AJdET5e/YCKNaeIGg+N1TS5qSsrAv4/zx1LuK/YhNKsdgukfLqCWunyzWQHtROz1iJeNpuve49rq X-Received: by 2002:a17:902:b289:: with SMTP id u9-v6mr1309699plr.273.1540953582124; Tue, 30 Oct 2018 19:39:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540953582; cv=none; d=google.com; s=arc-20160816; b=A7ngB9gWBc3mHxXcA0W1n+B1oYWYCjHU6qJ3PelPGpL7npeWSmT/Ik0pWQtbEuGGKk rwOGNSL0PBuWC4bg5ydXMrv5KLN0GHhHvoYcAoirP6IqzibIUcP2ZY0CPGRzTJNHksyj vNmdEqUgkpYoGB0m/UxDb8UsejDF5JcI/BkUxZPHZfm6jMDxLTNFLXrSU76gxQDI6oZC gADax47FMU0LdIHQ5JgFhemc3YQwJR7El0/7r7RGxWO8kLiydqbSFBG9qYCZFVhWpBat +WpTOWN6OYZIRP4nL70jJHlpDQx7suvz2x2NASd3HPYIMQr1vFEOG60/3U9YM4X/M7Yu eNAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=S3nnnigI+mwSJ2+DXwwr2rcxzyFvcPNDU/CG7BqsIl0=; b=PpUwXxjfpzd1sjgcGlTn6ZpS7Avd4ah6B7zJGAzqAN0h9H/SmB/5vbCpKSQUd9vKmO wG1zLQy/MCZ5e8ZVfJK/Sjvj59S0hwpmmAEeMCatqzQI83h36nczkNUTcxLD3DR/L1rT f/8GB7cm+jUCOy9BK8O8PhVPdTUf9G6+9b78GAOWMNjrqdUCgUuiD4D38afOgGe43Ynr lDUhUQyg/1+p4Kja0vU8dqloNiNqN83PkaEqNEtaGkz2OFna7uC4/PmJQwlL0Y9IcZBE mVWjs3AloHiAIMm/lfHaK0T+3R0kSrklpgadrpi08WKwgbRomZjb6V7tV0Fx/qxHho2/ 6uSg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p9-v6si26975991pgn.522.2018.10.30.19.39.27; Tue, 30 Oct 2018 19:39:42 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728739AbeJaLE4 (ORCPT + 99 others); Wed, 31 Oct 2018 07:04:56 -0400 Received: from mga17.intel.com ([192.55.52.151]:42689 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728665AbeJaLE4 (ORCPT ); Wed, 31 Oct 2018 07:04:56 -0400 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Oct 2018 19:08:59 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,446,1534834800"; d="scan'208";a="82861110" Received: from yisun1-ubuntu.bj.intel.com (HELO localhost) ([10.238.156.104]) by fmsmga008.fm.intel.com with ESMTP; 30 Oct 2018 19:08:57 -0700 Date: Wed, 31 Oct 2018 10:06:10 +0800 From: Yi Sun To: Michael Kelley Cc: "linux-kernel@vger.kernel.org" , "x86@kernel.org" , "tglx@linutronix.de" , "jgross@suse.com" , "chao.p.peng@intel.com" , "chao.gao@intel.com" , "isaku.yamahata@intel.com" , Tianyu Lan , KY Srinivasan , Haiyang Zhang , Stephen Hemminger Subject: Re: [PATCH v1 2/2] x86/hyperv: make HvNotifyLongSpinWait hypercall Message-ID: <20181031020610.GD15378@yi.y.sun> References: <1539954835-34035-1-git-send-email-yi.y.sun@linux.intel.com> <1539954835-34035-3-git-send-email-yi.y.sun@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org After syncing with Hyper-V team, we have got answers as below. On 18-10-24 16:53:00, Michael Kelley wrote: > From: Yi Sun Sent: Friday, October 19, 2018 6:14 AM > > > > The HvNotifyLongSpinWait hypercall (HVCALL_NOTIFY_LONG_SPIN_WAIT) > > is used by a guest OS to notify the hypervisor that the calling > > virtual processor is attempting to acquire a resource that is > > potentially held by another virtual processor within the same > > Virtual Machine. This scheduling hint improves the scalability of > > VMs with more than one virtual processor on Hyper-V. > > > > Per MSFT TLFS, the retry number (SpinWaitInfo) is sent to hypervisor > > only when the retry number exceeds the recommended number. If > > recommended number is 0xFFFFFFFF, never retry. > > The HvNotifyLongSpinWait hypercall should be understood to be > advisory only. As you noted, it is a scheduling hint to the > hypervisor that some virtual CPU in the VM holds a spin lock. Even > though Linux knows which vCPU holds the spin lock, the hypercall > does not provide a way to give that information to Hyper-V. The > hypercall always returns immediately. > > The "retry number" is a bit mis-named in the Hyper-V Top Level > Functional Spec (TLFS). It is essentially a threshold value. Hyper-V is > saying "don't bother to advise me about the spin lock until you have > done a certain number of spins." This threshold prevents > over-notifying Hyper-V such that the notification becomes somewhat > meaningless. It's not immediately clear to me why the hypercall passes > that value as an input, but maybe it lets the Hyper-V scheduler prioritize > among vCPUs based on how many times they have spun for a lock. I > think we were told that current Hyper-V implementations ignore this > input value anyway. > > I believe the description of the sentinel value 0xFFFFFFFF in the > Hyper-V TLFS is incorrect. Because it is the max possible threshold > value, that value in the EBX register just means to not ever bother to > notify. The description should be "0xFFFFFFFF indicates never to notify." > The value does *not* indicate anything about retrying to obtain the > spin lock. > You are right. 0xFFFFFFFF only indicates never to notify. We should not break the spin loop. > > static bool __initdata hv_pvspin = true; > > > > +bool hv_notify_long_spin_wait(int retry_num) > > retry_num should probably be declared as unsigned int. You > don't want it to be treated as a negative number if the high > order bit is set. > Yes, thanks! > > +{ > > + /* > > + * Per MSFT TLFS, the SpinWaitInfo is sent to hypervisor only when > > + * the retry number exceeds the recommended number. > > + * > > + * If recommended number is 0xFFFFFFFF, never retry. > > + */ > > + if (ms_hyperv.num_spin_retry == HYPERV_SPINLOCK_RETRY_NEVER) > > + return false; > > + > > + if ((0 == retry_num % ms_hyperv.num_spin_retry) && retry_num) > > I don't know if the "%" function is right here. Your implementation will > notify Hyper-V on every multiple of num_spin_retry. The alternative is to > notify once when the threshold is exceeded, and never again for this > particular attempt to obtain a spin lock. We should check with the Hyper-V > team for which approach they expect to be used. > We should send the notification on every multiple of the recommended number. > > + hv_do_fast_hypercall8(HVCALL_NOTIFY_LONG_SPIN_WAIT, > > + retry_num); > > The Hyper-V TLFS seems to be inconsistent on whether the input parameter > is 32-bits or 64-bits. In one place it is typed as UINT64, but in another place > it is shown as only 4 bytes. Need to clear this up with the Hyper-V team as > well. > It is 32-bits. > > + > > + return true; > > I don't see a need for this function to return true vs. false. Any calling code > should not change its behavior based on num_spin_retry. This function will > either notify Hyper-V or not notify Hyper-V, depending on whether the number > of attempts to obtain the spinlock meets the threshold. But calling code will > do the same thing regardless of whether such a notification is made. > You are right. I will change it to 'void'. > Michael