[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[RFC PATCH 04/10] preempt: use atomic_t to for preempt_count


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Date: Tue, 23 Feb 2021 02:34:56 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kphJiUy2kLhF2NKPvP/qP8YU2nqCVKOjptsGkk/vL84=; b=XW+boCnlFJzSuQpKzcrNOYYLys/jCIuqGUgaZy4WW+zx1AdojBFEenV5kiYsP0N5RbBbbWKWL40inH5ycgSMLVE/k/lnj+rLC5Y8BzBj1cOsj/a7zPkmG8mAATOX/bvN0LpRT1h2f03R167ZBcNns29KTzCUWJLh7p1So4KmqAfsq/Uu6euJcWU2Mzw5NHYPs9vEztkf6pKpM6LJuXjbv2lTKtMQ0VqvwidW917BRbCb3K7aQ5jCvbYv58525gh8JKvG4rQsAepjfDwRtkjGDfNyOh3//VMaX6h1QnwKumH3dEoJtGuVgNoTrJDO0L5+7b8U5y94OL3+daqFzpvjPg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SVd+3NStcB6wNxCQ0IH0EwlhcAgzILiv20hUtyCk2+R9ofOqYwZrGr9SU8d4fQhVSnZS3Kz3xuQfa2b7cgQEGWZmioNsBkW3ZXT0g3Alk+FO+yO3FB+2+jfcAoZZ/KPv8mC4zIx4dL0rCzUjqiQ2WinKheKOHzlQIeEX/8NDCobTBL+RT0juOXHHdD3AKr9N011+WWyXX3Y987QJHTMZxnNWwERliYQjk0NOCDmYuwdLEmz38mw3kVEB0ixl5hkXHvopXvkyXcnRlShMIamFVmOsVYDZUVpfEi0zjmP4LFN5/cDT/V/jwKqwICvx8toVQvPcznKi4WwrkR3Fd6iUwg==
  • Authentication-results: lists.xenproject.org; dkim=none (message not signed) header.d=none;lists.xenproject.org; dmarc=none action=none header.from=epam.com;
  • Cc: Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, Ian Jackson <iwj@xxxxxxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Tue, 23 Feb 2021 02:35:15 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHXCYx5c7ga2XxajUiE7SdBv/dfFA==
  • Thread-topic: [RFC PATCH 04/10] preempt: use atomic_t to for preempt_count

This ensures that preempt_count will be accounted correctly
during in-hypevisor context switches.

Signed-off-by: Volodymyr Babchuk <volodymyr_babchuk@xxxxxxxx>
---
 xen/common/preempt.c      | 6 +++---
 xen/include/xen/preempt.h | 9 ++++-----
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/xen/common/preempt.c b/xen/common/preempt.c
index 3b4178fd44..ad61c8419a 100644
--- a/xen/common/preempt.c
+++ b/xen/common/preempt.c
@@ -23,17 +23,17 @@
 #include <xen/irq.h>
 #include <asm/system.h>
 
-DEFINE_PER_CPU(unsigned int, __preempt_count);
+DEFINE_PER_CPU(atomic_t, __preempt_count);
 
 bool_t in_atomic(void)
 {
-    return preempt_count() || in_irq() || !local_irq_is_enabled();
+    return atomic_read(&preempt_count()) || in_irq() || local_irq_is_enabled();
 }
 
 #ifndef NDEBUG
 void ASSERT_NOT_IN_ATOMIC(void)
 {
-    ASSERT(!preempt_count());
+    ASSERT(!atomic_read(&preempt_count()));
     ASSERT(!in_irq());
     ASSERT(local_irq_is_enabled());
 }
diff --git a/xen/include/xen/preempt.h b/xen/include/xen/preempt.h
index bef83135a1..e217900d6e 100644
--- a/xen/include/xen/preempt.h
+++ b/xen/include/xen/preempt.h
@@ -9,21 +9,20 @@
 #ifndef __XEN_PREEMPT_H__
 #define __XEN_PREEMPT_H__
 
+#include <asm/atomic.h>
 #include <xen/types.h>
 #include <xen/percpu.h>
 
-DECLARE_PER_CPU(unsigned int, __preempt_count);
+DECLARE_PER_CPU(atomic_t, __preempt_count);
 
 #define preempt_count() (this_cpu(__preempt_count))
 
 #define preempt_disable() do {                  \
-    preempt_count()++;                          \
-    barrier();                                  \
+    atomic_inc(&preempt_count());               \
 } while (0)
 
 #define preempt_enable() do {                   \
-    barrier();                                  \
-    preempt_count()--;                          \
+    atomic_dec(&preempt_count());               \
 } while (0)
 
 bool_t in_atomic(void);
-- 
2.29.2



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.