summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2023-11-29 19:26:26 -0500
committerKent Overstreet <kent.overstreet@linux.dev>2024-08-22 02:07:27 -0400
commit05724f40f5c383435fb62a75783f650a05a1345d (patch)
tree9a6105e6137d72ec9d9b24bbc6ecf061e561eca0
parent00e0201f4e91b3661d7241482eb7a1c6bd497882 (diff)
percpu: per_cpu_sum()
Add a little helper to replace open coded versions. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev> Cc: Alexander Viro <viro@zeniv.linux.org.uk> Cc: linux-fsdevel@vger.krenel.org Cc: Tejun Heo <tj@kernel.org> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
-rw-r--r--fs/bcachefs/util.h10
-rw-r--r--fs/dcache.c16
-rw-r--r--include/linux/percpu.h10
3 files changed, 13 insertions, 23 deletions
diff --git a/fs/bcachefs/util.h b/fs/bcachefs/util.h
index fb02c1c36004..e90c2f546007 100644
--- a/fs/bcachefs/util.h
+++ b/fs/bcachefs/util.h
@@ -584,16 +584,6 @@ do { \
} \
} while (0)
-#define per_cpu_sum(_p) \
-({ \
- typeof(*_p) _ret = 0; \
- \
- int cpu; \
- for_each_possible_cpu(cpu) \
- _ret += *per_cpu_ptr(_p, cpu); \
- _ret; \
-})
-
static inline u64 percpu_u64_get(u64 __percpu *src)
{
return per_cpu_sum(src);
diff --git a/fs/dcache.c b/fs/dcache.c
index 3d8daaecb6d1..64108cbd52f6 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -151,29 +151,19 @@ static struct dentry_stat_t dentry_stat = {
*/
static long get_nr_dentry(void)
{
- int i;
- long sum = 0;
- for_each_possible_cpu(i)
- sum += per_cpu(nr_dentry, i);
+ long sum = per_cpu_sum(&nr_dentry);
return sum < 0 ? 0 : sum;
}
static long get_nr_dentry_unused(void)
{
- int i;
- long sum = 0;
- for_each_possible_cpu(i)
- sum += per_cpu(nr_dentry_unused, i);
+ long sum = per_cpu_sum(&nr_dentry_unused);
return sum < 0 ? 0 : sum;
}
static long get_nr_dentry_negative(void)
{
- int i;
- long sum = 0;
-
- for_each_possible_cpu(i)
- sum += per_cpu(nr_dentry_negative, i);
+ long sum = per_cpu_sum(&nr_dentry_negative);
return sum < 0 ? 0 : sum;
}
diff --git a/include/linux/percpu.h b/include/linux/percpu.h
index 4b2047b78b67..0df28ff54f66 100644
--- a/include/linux/percpu.h
+++ b/include/linux/percpu.h
@@ -162,4 +162,14 @@ extern phys_addr_t per_cpu_ptr_to_phys(void *addr);
extern unsigned long pcpu_nr_pages(void);
+#define per_cpu_sum(_p) \
+({ \
+ typeof(*(_p)) sum = 0; \
+ int cpu; \
+ \
+ for_each_possible_cpu(cpu) \
+ sum += *per_cpu_ptr(_p, cpu); \
+ sum; \
+})
+
#endif /* __LINUX_PERCPU_H */