From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753651AbcAVMxV (ORCPT ); Fri, 22 Jan 2016 07:53:21 -0500 Received: from e06smtp17.uk.ibm.com ([195.75.94.113]:56953 "EHLO e06smtp17.uk.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753600AbcAVMxO (ORCPT ); Fri, 22 Jan 2016 07:53:14 -0500 X-IBM-Helo: d06dlp02.portsmouth.uk.ibm.com X-IBM-MailFrom: cornelia.huck@de.ibm.com X-IBM-RcptTo: linux-kernel@vger.kernel.org Date: Fri, 22 Jan 2016 13:53:05 +0100 From: Cornelia Huck To: "Michael S. Tsirkin" Cc: linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: Re: [PATCH] tools/virtio: add ringtest utilities Message-ID: <20160122135305.3b708888.cornelia.huck@de.ibm.com> In-Reply-To: <1453380639-10459-1-git-send-email-mst@redhat.com> References: <1453380639-10459-1-git-send-email-mst@redhat.com> Organization: IBM Deutschland Research & Development GmbH Vorsitzende des Aufsichtsrats: Martina Koederitz =?UTF-8?B?R2VzY2jDpGZ0c2bDvGhydW5nOg==?= Dirk Wittkopp Sitz der Gesellschaft: =?UTF-8?B?QsO2Ymxpbmdlbg==?= Registergericht: Amtsgericht Stuttgart, HRB 243294 X-Mailer: Claws Mail 3.8.0 (GTK+ 2.24.10; i686-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16012212-0005-0000-0000-00000A175FC3 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 21 Jan 2016 14:52:32 +0200 "Michael S. Tsirkin" wrote: > +#if defined(__x86_64__) || defined(__i386__) > +#include "x86intrin.h" > + > +static inline void wait_cycles(unsigned long long cycles) > +{ > + unsigned long long t; > + > + t = __rdtsc(); > + while (__rdtsc() - t < cycles) {} > +} > + > +#define VMEXIT_CYCLES 500 > +#define VMENTRY_CYCLES 500 #elif defined(__s390x__) static inline void wait_cycles(unsigned long long cycles) { asm volatile("0: brctg %0,0b" : : "d" (cycles)); } /* tweak me */ #define VMEXIT_CYCLES 200 #define VMENTRY_CYCLES 200 Values are probably off... > + > +#else > +static inline void wait_cycles(unsigned long long cycles) > +{ > + _Exit(5); > +} > +#define VMEXIT_CYCLES 0 > +#define VMENTRY_CYCLES 0 > +#endif > +/* Compiler barrier - similar to what Linux uses */ > +#define barrier() asm volatile("" ::: "memory") > + > +/* Is there a portable way to do this? */ > +#if defined(__x86_64__) || defined(__i386__) > +#define cpu_relax() asm ("rep; nop" ::: "memory") > +#else > +#define cpu_relax() assert(0) Fall back to barrier() instead? > +#endif > diff --git a/tools/virtio/ringtest/run-on-all.sh b/tools/virtio/ringtest/run-on-all.sh > new file mode 100755 > index 0000000..52b0f71 > --- /dev/null > +++ b/tools/virtio/ringtest/run-on-all.sh > @@ -0,0 +1,24 @@ > +#!/bin/sh > + > +#use last CPU for host. Why not the first? > +#many devices tend to use cpu0 by default so > +#it tends to be busier > +HOST_AFFINITY=$(cd /dev/cpu; ls|grep -v '[a-z]'|sort -n|tail -1) > + > +#run command on all cpus > +for cpu in $(cd /dev/cpu; ls|grep -v '[a-z]'|sort -n); How portable is /dev/cpu/? Maybe look in sysfs instead? > +do > + #Don't run guest and host on same CPU > + #It actually works ok if using signalling > + if > + (echo "$@" | grep -e "--sleep" > /dev/null) || \ > + test $HOST_AFFINITY '!=' $cpu > + then > + echo "GUEST AFFINITY $cpu" > + "$@" --host-affinity $HOST_AFFINITY --guest-affinity $cpu > + fi > +done > +echo "NO GUEST AFFINITY" > +"$@" --host-affinity $HOST_AFFINITY > +echo "NO AFFINITY" > +"$@" It did not die on me for a basic (affinityless) run on s390. Let's see if I find time to look at the actual ring code next week.