summaryrefslogtreecommitdiffstats
path: root/sys/i386/include/pcpu.h
diff options
context:
space:
mode:
authorattilio <attilio@FreeBSD.org>2007-06-04 21:38:48 +0000
committerattilio <attilio@FreeBSD.org>2007-06-04 21:38:48 +0000
commite333d0ff0eb23a5f94f36fd95b4bbcfda3ccbc8f (patch)
treea35bbd71798a97fd11a5f264ff97c562de001111 /sys/i386/include/pcpu.h
parent771efb08f5bfaf22da0498ae91647fdecb3cc6bb (diff)
downloadFreeBSD-src-e333d0ff0eb23a5f94f36fd95b4bbcfda3ccbc8f.zip
FreeBSD-src-e333d0ff0eb23a5f94f36fd95b4bbcfda3ccbc8f.tar.gz
Rework the PCPU_* (MD) interface:
- Rename PCPU_LAZY_INC into PCPU_INC - Add the PCPU_ADD interface which just does an add on the pcpu member given a specific value. Note that for most architectures PCPU_INC and PCPU_ADD are not safe. This is a point that needs some discussions/work in the next days. Reviewed by: alc, bde Approved by: jeff (mentor)
Diffstat (limited to 'sys/i386/include/pcpu.h')
-rw-r--r--sys/i386/include/pcpu.h29
1 files changed, 26 insertions, 3 deletions
diff --git a/sys/i386/include/pcpu.h b/sys/i386/include/pcpu.h
index e44eea1..67cb530 100644
--- a/sys/i386/include/pcpu.h
+++ b/sys/i386/include/pcpu.h
@@ -62,7 +62,8 @@
extern struct pcpu *pcpup;
#define PCPU_GET(member) (pcpup->pc_ ## member)
-#define PCPU_LAZY_INC(member) (++pcpup->pc_ ## member)
+#define PCPU_ADD(member, val) (pcpu->pc_ ## member += (val))
+#define PCPU_INC(member) PCPU_ADD(member, 1)
#define PCPU_PTR(member) (&pcpup->pc_ ## member)
#define PCPU_SET(member, val) (pcpup->pc_ ## member = (val))
@@ -116,10 +117,31 @@ extern struct pcpu *pcpup;
})
/*
+ * Adds a value of the per-cpu counter name. The implementation
+ * must be atomic with respect to interrupts.
+ */
+#define __PCPU_ADD(name, val) do { \
+ __pcpu_type(name) __val; \
+ struct __s { \
+ u_char __b[MIN(sizeof(__pcpu_type(name)), 4)]; \
+ } __s; \
+ \
+ __val = (val); \
+ if (sizeof(__val) == 1 || sizeof(__val) == 2 || \
+ sizeof(__val) == 4) { \
+ __s = *(struct __s *)(void *)&__val; \
+ __asm __volatile("add %1,%%fs:%0" \
+ : "=m" (*(struct __s *)(__pcpu_offset(name))) \
+ : "r" (__s)); \
+ } else \
+ *__PCPU_PTR(name) += __val; \
+} while (0)
+
+/*
* Increments the value of the per-cpu counter name. The implementation
* must be atomic with respect to interrupts.
*/
-#define __PCPU_LAZY_INC(name) do { \
+#define __PCPU_INC(name) do { \
CTASSERT(sizeof(__pcpu_type(name)) == 1 || \
sizeof(__pcpu_type(name)) == 2 || \
sizeof(__pcpu_type(name)) == 4); \
@@ -160,7 +182,8 @@ extern struct pcpu *pcpup;
}
#define PCPU_GET(member) __PCPU_GET(pc_ ## member)
-#define PCPU_LAZY_INC(member) __PCPU_LAZY_INC(pc_ ## member)
+#define PCPU_ADD(member, val) __PCPU_ADD(pc_ ## member, val)
+#define PCPU_INC(member) __PCPU_INC(pc_ ## member)
#define PCPU_PTR(member) __PCPU_PTR(pc_ ## member)
#define PCPU_SET(member, val) __PCPU_SET(pc_ ## member, val)
OpenPOWER on IntegriCloud