diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2019-02-06 11:42:13 -0500 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-10-22 17:08:15 -0400 |
commit | 4c97e04aa8818da266a690543aca28e2e7c26820 (patch) | |
tree | 4e5568716eea0192460dc49c14ed94436485edc7 /fs/bcachefs/util.h | |
parent | fe112812ae41bfed0aa61cdfbe8233e4122e5cb8 (diff) |
bcachefs: percpu utility code
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/util.h')
-rw-r--r-- | fs/bcachefs/util.h | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/fs/bcachefs/util.h b/fs/bcachefs/util.h index fa1a3adc87df..dc40a52ac8c7 100644 --- a/fs/bcachefs/util.h +++ b/fs/bcachefs/util.h @@ -12,6 +12,7 @@ #include <linux/llist.h> #include <linux/log2.h> #include <linux/percpu.h> +#include <linux/preempt.h> #include <linux/ratelimit.h> #include <linux/slab.h> #include <linux/vmalloc.h> @@ -701,6 +702,28 @@ do { \ } \ } while (0) +static inline u64 percpu_u64_get(u64 __percpu *src) +{ + u64 ret = 0; + int cpu; + + for_each_possible_cpu(cpu) + ret += *per_cpu_ptr(src, cpu); + return ret; +} + +static inline void percpu_u64_set(u64 __percpu *dst, u64 src) +{ + int cpu; + + for_each_possible_cpu(cpu) + *per_cpu_ptr(dst, cpu) = 0; + + preempt_disable(); + *this_cpu_ptr(dst) = src; + preempt_enable(); +} + static inline void acc_u64s(u64 *acc, const u64 *src, unsigned nr) { unsigned i; |