From patchwork Wed Oct 26 07:47:08 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 9396193 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A22CC60231 for ; Wed, 26 Oct 2016 07:48:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6A9D4298DB for ; Wed, 26 Oct 2016 07:48:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5F277298DF; Wed, 26 Oct 2016 07:48:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1DE45298DB for ; Wed, 26 Oct 2016 07:48:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754696AbcJZHsP (ORCPT ); Wed, 26 Oct 2016 03:48:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36580 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753290AbcJZHsF (ORCPT ); Wed, 26 Oct 2016 03:48:05 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B5CD1624A1; Wed, 26 Oct 2016 07:47:40 +0000 (UTC) Received: from pxdev.xzpeter.org (vpn1-4-183.pek2.redhat.com [10.72.4.183]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9Q7lGm2024891; Wed, 26 Oct 2016 03:47:37 -0400 From: Peter Xu To: kvm@vger.kernel.org Cc: drjones@redhat.com, rkrcmar@redhat.com, peterx@redhat.com, agordeev@redhat.com, jan.kiszka@web.de, pbonzini@redhat.com Subject: [PATCH kvm-unit-tests 05/17] x86/asm: add cpu_relax() Date: Wed, 26 Oct 2016 15:47:08 +0800 Message-Id: <1477468040-21034-6-git-send-email-peterx@redhat.com> In-Reply-To: <1477468040-21034-1-git-send-email-peterx@redhat.com> References: <1477468040-21034-1-git-send-email-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 26 Oct 2016 07:47:40 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This will be useful to be put inside loops. Suggested-by: Andrew Jones Signed-off-by: Peter Xu Reviewed-by: Andrew Jones --- lib/x86/asm/barrier.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/x86/asm/barrier.h b/lib/x86/asm/barrier.h index 7c108bd..193fb4c 100644 --- a/lib/x86/asm/barrier.h +++ b/lib/x86/asm/barrier.h @@ -13,4 +13,15 @@ #define smp_rmb() barrier() #define smp_wmb() barrier() +/* REP NOP (PAUSE) is a good thing to insert into busy-wait loops. */ +static inline void rep_nop(void) +{ + asm volatile("rep; nop" ::: "memory"); +} + +static inline void cpu_relax(void) +{ + rep_nop(); +} + #endif