Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 20 Nov 2008 09:43:40 +0100
From:      Marc =?iso-8859-1?q?L=F6rner?= <marc.loerner@hob.de>
To:        freebsd-ia64@freebsd.org
Subject:   sys/ia64/include/pcpu.h patch proposal
Message-ID:  <200811200943.40672.marc.loerner@hob.de>

next in thread | raw e-mail | index | archive | help

--Boundary-00=_8MSJJ12FG44ZEXP
Content-Type: text/plain;
  charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hello,
attached is a patch of pcpu.h against current to make access of 
pcpu-structures preemption-ready (like in amd64).

Regards,
Marc Loerner

--Boundary-00=_8MSJJ12FG44ZEXP
Content-Type: text/x-diff;
  charset="iso-8859-1";
  name="pcpu.h.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="pcpu.h.patch"

--- pcpu.h.orig	2008-11-20 09:37:40.000000000 +0100
+++ pcpu.h	2008-11-20 09:36:13.000000000 +0100
@@ -45,11 +45,77 @@
 
 register struct pcpu *pcpup __asm__("r13");
 
+void pcpu_initclock(void);
+
+#if defined(lint)
 #define	PCPU_GET(member)	(pcpup->pc_ ## member)
 #define	PCPU_PTR(member)	(&pcpup->pc_ ## member)
 #define	PCPU_SET(member,value)	(pcpup->pc_ ## member = (value))
 
-void pcpu_initclock(void);
+#elif defined(__GNUCLIKE_ASM) && defined(__GNUCLIKE__TYPEOF)                 \
+    && defined(__GNUCLIKE__OFFSETOF)
+
+/*
+ * Evaluates to the byte offset of the per-cpu variable name.
+ */
+#define __pcpu_offset(name)                                                   \
+    __offsetof(struct pcpu, name)
+
+/*
+ * Evalutes to the type of the per-cpu variable name.
+ */
+#define __pcpu_type(name)                                                     \
+    __typeof(((struct pcpu *)0)->name)
+
+/* 
+ * Evaluates to the address of the per-cpu variable name.
+ */
+#define __PCPU_PTR(name) __extension__ ({                                     \
+    __pcpu_type(name) *__p;                                                   \
+                                                                              \
+    __asm__volatile("add %0=%1, r13\n\n"                                      \
+        : "=r" (__p)                                                          \
+        : "i" (__pcpu_offset(name)));                                         \
+                                                                              \
+    __p;                                                                      \
+})
+
+/*
+ * Evaluates to the value of the per-cpu variable name.
+ */
+#define __PCPU_GET(name) __extension__ ({                                     \
+    __pcpu_type(name) __result;                                               \
+                                                                              \
+    __result = *__PCPU_PTR(name);                                             \
+                                                                              \
+    __result;                                                                 \
+})
+
+/*
+ * Sets the value of the per-cpu variable name to value val.
+ */
+#define __PCPU_SET(name, val) {                                               \
+    __pcpu_type(name) __val = (val);                                          \
+                                                                              \
+    *__PCPU_PTR(name) = __val;                                                \
+}
+
+#define PCPU_GET(member)         __PCPU_GET(pc_ ## member)
+#define PCPU_PTR(member)         __PCPU_PTR(pc_ ## member)
+#define PCPU_SET(member, val)    __PCPU_SET(pc_ ## member, val)
+
+static __inline struct thread* __curthread(void)
+{
+    struct thread *td;
+
+    __asm__volatile("ld8 %0=[r13]\n\n" : "=r" (td));
+    return (td);
+}
+#define curthread (__curthread())
+
+#else
+#error this file needs to be ported to your compiler
+#endif
 
 #endif	/* _KERNEL */
 

--Boundary-00=_8MSJJ12FG44ZEXP--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200811200943.40672.marc.loerner>