diff options
author | alc <alc@FreeBSD.org> | 2007-03-11 05:54:29 +0000 |
---|---|---|
committer | alc <alc@FreeBSD.org> | 2007-03-11 05:54:29 +0000 |
commit | b03ddb707bfa75419cca3c62c43a52a0e43e11fe (patch) | |
tree | c82f4d045af3dd306e3ada863f05a02bf267342a /sys/amd64/include/pcpu.h | |
parent | be15acebb297e61c62592db36b982bda336df47f (diff) | |
download | FreeBSD-src-b03ddb707bfa75419cca3c62c43a52a0e43e11fe.zip FreeBSD-src-b03ddb707bfa75419cca3c62c43a52a0e43e11fe.tar.gz |
Push down the implementation of PCPU_LAZY_INC() into the machine-dependent
header file. Reimplement PCPU_LAZY_INC() on amd64 and i386 making it
atomic with respect to interrupts.
Reviewed by: bde, jhb
Diffstat (limited to 'sys/amd64/include/pcpu.h')
-rw-r--r-- | sys/amd64/include/pcpu.h | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/sys/amd64/include/pcpu.h b/sys/amd64/include/pcpu.h index 28659c7..47d9b0e 100644 --- a/sys/amd64/include/pcpu.h +++ b/sys/amd64/include/pcpu.h @@ -56,6 +56,7 @@ extern struct pcpu *pcpup; #define PCPU_GET(member) (pcpup->pc_ ## member) +#define PCPU_LAZY_INC(member) (++pcpup->pc_ ## member) #define PCPU_PTR(member) (&pcpup->pc_ ## member) #define PCPU_SET(member, val) (pcpup->pc_ ## member = (val)) @@ -109,6 +110,34 @@ extern struct pcpu *pcpup; }) /* + * Increments the value of the per-cpu counter name. The implementation + * must be atomic with respect to interrupts. + */ +#define __PCPU_LAZY_INC(name) do { \ + CTASSERT(sizeof(__pcpu_type(name)) == 1 || \ + sizeof(__pcpu_type(name)) == 2 || \ + sizeof(__pcpu_type(name)) == 4 || \ + sizeof(__pcpu_type(name)) == 8); \ + if (sizeof(__pcpu_type(name)) == 1) { \ + __asm __volatile("incb %%gs:%0" \ + : "=m" (*(__pcpu_type(name) *)(__pcpu_offset(name)))\ + : "m" (*(__pcpu_type(name) *)(__pcpu_offset(name))));\ + } else if (sizeof(__pcpu_type(name)) == 2) { \ + __asm __volatile("incw %%gs:%0" \ + : "=m" (*(__pcpu_type(name) *)(__pcpu_offset(name)))\ + : "m" (*(__pcpu_type(name) *)(__pcpu_offset(name))));\ + } else if (sizeof(__pcpu_type(name)) == 4) { \ + __asm __volatile("incl %%gs:%0" \ + : "=m" (*(__pcpu_type(name) *)(__pcpu_offset(name)))\ + : "m" (*(__pcpu_type(name) *)(__pcpu_offset(name))));\ + } else if (sizeof(__pcpu_type(name)) == 8) { \ + __asm __volatile("incq %%gs:%0" \ + : "=m" (*(__pcpu_type(name) *)(__pcpu_offset(name)))\ + : "m" (*(__pcpu_type(name) *)(__pcpu_offset(name))));\ + } \ +} while (0) + +/* * Sets the value of the per-cpu variable name to value val. */ #define __PCPU_SET(name, val) { \ @@ -130,6 +159,7 @@ extern struct pcpu *pcpup; } #define PCPU_GET(member) __PCPU_GET(pc_ ## member) +#define PCPU_LAZY_INC(member) __PCPU_LAZY_INC(pc_ ## member) #define PCPU_PTR(member) __PCPU_PTR(pc_ ## member) #define PCPU_SET(member, val) __PCPU_SET(pc_ ## member, val) |