diff mbox

[v5,04/18] include/processor.h: define cpu_relax()

Message ID 20160518182946.GA8386@flamenco
State New
Headers show

Commit Message

Emilio Cota May 18, 2016, 6:29 p.m. UTC
On Wed, May 18, 2016 at 20:47:56 +0300, Sergey Fedorov wrote:
> Why don't do like this:
> 
> #if defined(__foo__)
> #  define ...
> #elif defined(__bar__)
> #  define ...
> #else
> #  define ...
> #endif

Good point. Changed to:

commit ad31d6cff8e309e41bd4bed110f173e473c27c5a
Author: Emilio G. Cota <cota@braap.org>
Date:   Wed Apr 6 18:21:08 2016 -0400

    include/processor.h: define cpu_relax()
    
    Taken from the linux kernel.
    
    Reviewed-by: Richard Henderson <rth@twiddle.net>
    Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
    Signed-off-by: Emilio G. Cota <cota@braap.org>

Comments

Sergey Fedorov May 18, 2016, 6:37 p.m. UTC | #1
On 18/05/16 21:29, Emilio G. Cota wrote:
> On Wed, May 18, 2016 at 20:47:56 +0300, Sergey Fedorov wrote:
>> Why don't do like this:
>>
>> #if defined(__foo__)
>> #  define ...
>> #elif defined(__bar__)
>> #  define ...
>> #else
>> #  define ...
>> #endif
> Good point. Changed to:
>
> commit ad31d6cff8e309e41bd4bed110f173e473c27c5a
> Author: Emilio G. Cota <cota@braap.org>
> Date:   Wed Apr 6 18:21:08 2016 -0400
>
>     include/processor.h: define cpu_relax()
>     
>     Taken from the linux kernel.
>     
>     Reviewed-by: Richard Henderson <rth@twiddle.net>
>     Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
>     Signed-off-by: Emilio G. Cota <cota@braap.org>
>
> diff --git a/include/qemu/processor.h b/include/qemu/processor.h
> new file mode 100644
> index 0000000..42bcc99
> --- /dev/null
> +++ b/include/qemu/processor.h
> @@ -0,0 +1,30 @@
> +/*
> + * Copyright (C) 2016, Emilio G. Cota <cota@braap.org>
> + *
> + * License: GNU GPL, version 2.
> + *   See the COPYING file in the top-level directory.
> + */
> +#ifndef QEMU_PROCESSOR_H
> +#define QEMU_PROCESSOR_H
> +
> +#include "qemu/atomic.h"
> +
> +#if defined(__i386__) || defined(__x86_64__)
> +# define cpu_relax() asm volatile("rep; nop" ::: "memory")
> +
> +#elif defined(__ia64__)
> +# define cpu_relax() asm volatile("hint @pause" ::: "memory")
> +
> +#elif defined(__aarch64__)
> +# define cpu_relax() asm volatile("yield" ::: "memory")
> +
> +#elif defined(__powerpc64__)
> +/* set Hardware Multi-Threading (HMT) priority to low; then back to medium */
> +# define cpu_relax() asm volatile("or 1, 1, 1;"
> +                                  "or 2, 2, 2;" ::: "memory")
> +
> +#else
> +# define cpu_relax() barrier()
> +#endif
> +
> +#endif /* QEMU_PROCESSOR_H */

Looks like you prefer "sparse" code :)

-Sergey
diff mbox

Patch

diff --git a/include/qemu/processor.h b/include/qemu/processor.h
new file mode 100644
index 0000000..42bcc99
--- /dev/null
+++ b/include/qemu/processor.h
@@ -0,0 +1,30 @@ 
+/*
+ * Copyright (C) 2016, Emilio G. Cota <cota@braap.org>
+ *
+ * License: GNU GPL, version 2.
+ *   See the COPYING file in the top-level directory.
+ */
+#ifndef QEMU_PROCESSOR_H
+#define QEMU_PROCESSOR_H
+
+#include "qemu/atomic.h"
+
+#if defined(__i386__) || defined(__x86_64__)
+# define cpu_relax() asm volatile("rep; nop" ::: "memory")
+
+#elif defined(__ia64__)
+# define cpu_relax() asm volatile("hint @pause" ::: "memory")
+
+#elif defined(__aarch64__)
+# define cpu_relax() asm volatile("yield" ::: "memory")
+
+#elif defined(__powerpc64__)
+/* set Hardware Multi-Threading (HMT) priority to low; then back to medium */
+# define cpu_relax() asm volatile("or 1, 1, 1;"
+                                  "or 2, 2, 2;" ::: "memory")
+
+#else
+# define cpu_relax() barrier()
+#endif
+
+#endif /* QEMU_PROCESSOR_H */