From: Simon Glass <simon.glass@canonical.com>
Create a new header file for per-CPU variable and operation stubs.
U-Boot is single-threaded, so per-CPU variables are just regular
variables and per-CPU operations are simple direct accesses.
The new header includes:
- DEFINE_PER_CPU, per_cpu, per_cpu_ptr, this_cpu_inc, this_cpu_read
- for_each_possible_cpu, smp_processor_id, num_possible_cpus
- alloc_percpu, free_percpu
- struct percpu_rw_semaphore and related operations
This consolidates scattered per-CPU definitions from ext4_uboot.h and
removes the function implementations from stub.c.
Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
---
fs/ext4l/ext4_uboot.h | 33 +++++---------------------
fs/ext4l/stub.c | 11 ++-------
include/linux/percpu.h | 54 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 62 insertions(+), 36 deletions(-)
create mode 100644 include/linux/percpu.h
@@ -103,8 +103,9 @@ typedef struct { atomic_t refs; } refcount_t;
/* RB tree types - from <linux/rbtree.h> included above */
-/* percpu_counter - use Linux header */
+/* percpu - use Linux headers */
#include <linux/percpu_counter.h>
+#include <linux/percpu.h>
/* Project ID type */
typedef struct { unsigned int val; } kprojid_t;
@@ -232,15 +233,7 @@ struct fiemap_extent_info {
/* fscrypt_str, qstr are now in ext4_fscrypt.h */
-/* percpu rw semaphore - stubs */
-struct percpu_rw_semaphore {
- int dummy;
-};
-
-#define percpu_down_read(sem) do { } while (0)
-#define percpu_up_read(sem) do { } while (0)
-#define percpu_down_write(sem) do { } while (0)
-#define percpu_up_write(sem) do { } while (0)
+/* percpu rw semaphore is in linux/percpu.h */
/* Memory allocation context - stubs */
static inline unsigned int memalloc_nofs_save(void) { return 0; }
@@ -2095,9 +2088,7 @@ void fsnotify_sb_error(struct super_block *sb, struct inode *inode, int error);
char *file_path(struct file *file, char *buf, int buflen);
struct block_device *file_bdev(struct file *file);
-/* Percpu rwsem - declarations for stub.c */
-int percpu_init_rwsem(struct percpu_rw_semaphore *sem);
-void percpu_free_rwsem(struct percpu_rw_semaphore *sem);
+/* percpu_init_rwsem/percpu_free_rwsem are in linux/percpu.h */
/* Block device sync - declarations for stub.c */
int sync_blockdev(struct block_device *bdev);
@@ -2302,14 +2293,7 @@ struct xarray {
int dummy;
};
-/* Per-CPU stubs - U-Boot is single-threaded */
-#define DEFINE_PER_CPU(type, name) type name
-#define per_cpu(var, cpu) (var)
-#define per_cpu_ptr(ptr, cpu) (ptr)
-#define this_cpu_inc(var) ((var)++)
-#define this_cpu_read(var) (var)
-#define for_each_possible_cpu(cpu) for ((cpu) = 0; (cpu) < 1; (cpu)++)
-#define smp_processor_id() 0
+/* Per-CPU stubs are in linux/percpu.h */
/* XArray function stubs */
#define xa_init(xa) do { } while (0)
@@ -2392,12 +2376,7 @@ struct seq_operations {
/* Block layer constants */
#define BLK_MAX_SEGMENT_SIZE 65536
-/* num_possible_cpus - number of possible CPUs (always 1 in U-Boot) */
-#define num_possible_cpus() 1
-
-/* Per-CPU allocation stubs */
-#define alloc_percpu(type) ((type *)kzalloc(sizeof(type), GFP_KERNEL))
-#define free_percpu(ptr) kfree(ptr)
+/* num_possible_cpus, alloc_percpu, free_percpu are in linux/percpu.h */
/* Block device properties */
#define bdev_nonrot(bdev) ({ (void)(bdev); 0; })
@@ -455,10 +455,7 @@ void ext4_unregister_sysfs(void *sb)
/* jbd2_journal_destroy is now in journal.c */
-/* percpu rwsem */
-void percpu_free_rwsem(struct percpu_rw_semaphore *sem)
-{
-}
+/* percpu_free_rwsem is now in linux/percpu.h */
/* Block device ops */
int sync_blockdev(struct block_device *bdev)
@@ -589,11 +586,7 @@ void iput(struct inode *inode)
}
}
-/* percpu init rwsem */
-int percpu_init_rwsem(struct percpu_rw_semaphore *sem)
-{
- return 0;
-}
+/* percpu_init_rwsem is now in linux/percpu.h */
/* atomic_add and atomic64_add are now in asm-generic/atomic.h */
new file mode 100644
@@ -0,0 +1,54 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Per-CPU variable and operation stubs for U-Boot
+ *
+ * U-Boot is single-threaded, so per-CPU variables are just regular
+ * variables and per-CPU operations are simple direct accesses.
+ */
+#ifndef _LINUX_PERCPU_H
+#define _LINUX_PERCPU_H
+
+#include <linux/types.h>
+#include <malloc.h>
+
+/*
+ * Per-CPU variable definitions - just regular variables in U-Boot
+ */
+#define DEFINE_PER_CPU(type, name) type name
+#define per_cpu(var, cpu) (var)
+#define per_cpu_ptr(ptr, cpu) (ptr)
+#define this_cpu_inc(var) ((var)++)
+#define this_cpu_read(var) (var)
+
+/* CPU iteration - only one CPU in U-Boot */
+#define for_each_possible_cpu(cpu) for ((cpu) = 0; (cpu) < 1; (cpu)++)
+#define smp_processor_id() 0
+#define num_possible_cpus() 1
+
+/* Per-CPU allocation - just regular allocation in U-Boot */
+#define alloc_percpu(type) ((type *)kzalloc(sizeof(type), GFP_KERNEL))
+#define free_percpu(ptr) kfree(ptr)
+
+/*
+ * Per-CPU read-write semaphore stubs
+ * U-Boot is single-threaded, so these are no-ops
+ */
+struct percpu_rw_semaphore {
+ int dummy;
+};
+
+#define percpu_down_read(sem) do { } while (0)
+#define percpu_up_read(sem) do { } while (0)
+#define percpu_down_write(sem) do { } while (0)
+#define percpu_up_write(sem) do { } while (0)
+
+static inline int percpu_init_rwsem(struct percpu_rw_semaphore *sem)
+{
+ return 0;
+}
+
+static inline void percpu_free_rwsem(struct percpu_rw_semaphore *sem)
+{
+}
+
+#endif /* _LINUX_PERCPU_H */