From patchwork Wed Jan 14 22:56:02 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1506 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768431465; bh=fc9STlbzvbhqgpGhofBy48zL7ESRd3QLWkc/MfQaUos=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=YB8PyOHNuSqOQuD9oEnHMWPRfV6w4Tm0uECwPbLfMVSSdFm3gH6znn7NHS+6g0PQ7 m4pSK9TyqvBMhyr7Dyl5j4iBsDBkYFs4n/eMbx5KyZJqx7YEqdoTFVzSdVWxwHm3ab hQ7sRETB6o1JzhNafeQCbmlWxu23N9KK/BIrmihVTQP3j0SUfoW09Ulh0H1+puz8NC NnjPZI+PkFtbhuILcDs2DAbDotyS8obYAnhjOOK01Sb8i1K5SfisCHv0h4iZj8VPUe tIgQfeAJgmC+POAdkQWS4EOJiWjgnYn43gme7bY5cN6Pvwn/02EiHLDxeQUiqN2t7r rvWRSRDthXgAg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id AB87D69342 for ; Wed, 14 Jan 2026 15:57:45 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id iu6BQ6I5vwpv for ; Wed, 14 Jan 2026 15:57:45 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768431465; bh=fc9STlbzvbhqgpGhofBy48zL7ESRd3QLWkc/MfQaUos=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=YB8PyOHNuSqOQuD9oEnHMWPRfV6w4Tm0uECwPbLfMVSSdFm3gH6znn7NHS+6g0PQ7 m4pSK9TyqvBMhyr7Dyl5j4iBsDBkYFs4n/eMbx5KyZJqx7YEqdoTFVzSdVWxwHm3ab hQ7sRETB6o1JzhNafeQCbmlWxu23N9KK/BIrmihVTQP3j0SUfoW09Ulh0H1+puz8NC NnjPZI+PkFtbhuILcDs2DAbDotyS8obYAnhjOOK01Sb8i1K5SfisCHv0h4iZj8VPUe tIgQfeAJgmC+POAdkQWS4EOJiWjgnYn43gme7bY5cN6Pvwn/02EiHLDxeQUiqN2t7r rvWRSRDthXgAg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 969BA69345 for ; Wed, 14 Jan 2026 15:57:45 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768431463; bh=P8mq6JFtg2ffIJSNAHH/JTLCSX6tCgszNGKfQcD+dwM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tV/LunJQfiYEMsz3rSQgf3Gcw1SJ56lp66XcVuN5vNHHh3OEqbOj6gsYWVl3zm9BJ wmIa/I1rG+hvsAQ5x9bVg8MbPjVEjU3WqN/d1GOvMJa1USiodcFlBg7efjDgCb60d5 ZLealyDrPiraWiPtdBAqGmEeUBrSuDglFaMSj+hilUTczEGW/d7Q/R9UCZT/3+W241 fMo/+uxXvsRh1JcWtevbBAHiCQsDdK5pyr44OTahcr+1/Vlp14icDEK0ZTBdxYhR49 RRHcNPoDdeGkfE34WKV0L2fstKLakXhG+B0Ps2CiDdf2qb3fzAprhYQlJaasXwUkch JcAd6NPZ0sc0g== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id E291069342; Wed, 14 Jan 2026 15:57:43 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id 1BHm6TTYnPUu; Wed, 14 Jan 2026 15:57:43 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768431459; bh=U04mlLgshgyVo+rTWZdUDho8IHazSKwXn60X1XzRgVQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HFBYtNPu/okr97oYEqqcak+4vrYms8isU0ARv2jQnau+kMViPvdS9qBS4gcRhdnM2 6uKjrZC9YqXj+HLk+HZ4tVCIb7GuaJ5aFEvFpOT+CNGp/PWZlxy652Vgez+/K3OiJp WsR+Kw6608LxnjWu1xMVBv4L+tPyXqZ+8VQFF5Cdwu/JEpZEnwU+XR0e+dSTZ7A3e7 XY6yrwUs5ScaBTJmXogW351UgiuWWoFl9u3GD3vKMAbKJwiEjFOXzHYTAUb/IjkKBj r9zUE8bJ8bkFHQYnGL4O83MKfSjwcTL+3aoVYVT2Ar9b/kXk0DG/QXCz0dcUyov4EG kbDb+wjzHWmCQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 8E669692EF; Wed, 14 Jan 2026 15:57:39 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Wed, 14 Jan 2026 15:56:02 -0700 Message-ID: <20260114225635.3407989-13-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260114225635.3407989-1-sjg@u-boot.org> References: <20260114225635.3407989-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: CBHFV2MWBM6TOTMMTUJ373RNREEFJGDT X-Message-ID-Hash: CBHFV2MWBM6TOTMMTUJ373RNREEFJGDT X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Simon Glass , "Claude Opus 4 . 5" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 12/34] ext4l: Create linux/percpu.h for per-CPU stubs List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass 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 Signed-off-by: Simon Glass --- 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 diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index ef40658753b..166768985b1 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -103,8 +103,9 @@ typedef struct { atomic_t refs; } refcount_t; /* RB tree types - from included above */ -/* percpu_counter - use Linux header */ +/* percpu - use Linux headers */ #include +#include /* 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; }) diff --git a/fs/ext4l/stub.c b/fs/ext4l/stub.c index 378ee76b8b5..a0c21dfd14c 100644 --- a/fs/ext4l/stub.c +++ b/fs/ext4l/stub.c @@ -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 */ diff --git a/include/linux/percpu.h b/include/linux/percpu.h new file mode 100644 index 00000000000..3aa71c1451f --- /dev/null +++ b/include/linux/percpu.h @@ -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 +#include + +/* + * 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 */