[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250325121624.523258-40-guoren@kernel.org>
Date: Tue, 25 Mar 2025 08:16:20 -0400
From: guoren@...nel.org
To: arnd@...db.de,
gregkh@...uxfoundation.org,
torvalds@...ux-foundation.org,
paul.walmsley@...ive.com,
palmer@...belt.com,
anup@...infault.org,
atishp@...shpatra.org,
oleg@...hat.com,
kees@...nel.org,
tglx@...utronix.de,
will@...nel.org,
mark.rutland@....com,
brauner@...nel.org,
akpm@...ux-foundation.org,
rostedt@...dmis.org,
edumazet@...gle.com,
unicorn_wang@...look.com,
inochiama@...look.com,
gaohan@...as.ac.cn,
shihua@...as.ac.cn,
jiawei@...as.ac.cn,
wuwei2016@...as.ac.cn,
drew@...7.com,
prabhakar.mahadev-lad.rj@...renesas.com,
ctsai390@...estech.com,
wefu@...hat.com,
kuba@...nel.org,
pabeni@...hat.com,
josef@...icpanda.com,
dsterba@...e.com,
mingo@...hat.com,
peterz@...radead.org,
boqun.feng@...il.com,
guoren@...nel.org,
xiao.w.wang@...el.com,
qingfang.deng@...lower.com.cn,
leobras@...hat.com,
jszhang@...nel.org,
conor.dooley@...rochip.com,
samuel.holland@...ive.com,
yongxuan.wang@...ive.com,
luxu.kernel@...edance.com,
david@...hat.com,
ruanjinjie@...wei.com,
cuiyunhui@...edance.com,
wangkefeng.wang@...wei.com,
qiaozhe@...as.ac.cn
Cc: ardb@...nel.org,
ast@...nel.org,
linux-kernel@...r.kernel.org,
linux-riscv@...ts.infradead.org,
kvm@...r.kernel.org,
kvm-riscv@...ts.infradead.org,
linux-mm@...ck.org,
linux-crypto@...r.kernel.org,
bpf@...r.kernel.org,
linux-input@...r.kernel.org,
linux-perf-users@...r.kernel.org,
linux-serial@...r.kernel.org,
linux-fsdevel@...r.kernel.org,
linux-arch@...r.kernel.org,
maple-tree@...ts.infradead.org,
linux-trace-kernel@...r.kernel.org,
netdev@...r.kernel.org,
linux-atm-general@...ts.sourceforge.net,
linux-btrfs@...r.kernel.org,
netfilter-devel@...r.kernel.org,
coreteam@...filter.org,
linux-nfs@...r.kernel.org,
linux-sctp@...r.kernel.org,
linux-usb@...r.kernel.org,
linux-media@...r.kernel.org
Subject: [RFC PATCH V3 39/43] rv64ilp32_abi: sysinfo: Adapt sysinfo structure to lp64 uapi
From: "Guo Ren (Alibaba DAMO Academy)" <guoren@...nel.org>
The RISC-V 64ilp32 ABI leverages LP64 uapi and accommodates LP64
ABI userspace directly, necessitating updates to the sysinfo
struct's unsigned long and array types with u64.
Signed-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@...nel.org>
---
fs/proc/loadavg.c | 10 +++++++---
include/linux/sched/loadavg.h | 4 ++++
include/uapi/linux/sysinfo.h | 20 ++++++++++++++++++++
kernel/sched/loadavg.c | 4 ++++
4 files changed, 35 insertions(+), 3 deletions(-)
diff --git a/fs/proc/loadavg.c b/fs/proc/loadavg.c
index 817981e57223..643e06de3446 100644
--- a/fs/proc/loadavg.c
+++ b/fs/proc/loadavg.c
@@ -13,14 +13,18 @@
static int loadavg_proc_show(struct seq_file *m, void *v)
{
+#if defined(CONFIG_64BIT) && (BITS_PER_LONG == 32)
+ unsigned long long avnrun[3];
+#else
unsigned long avnrun[3];
+#endif
get_avenrun(avnrun, FIXED_1/200, 0);
seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %u/%d %d\n",
- LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
- LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
- LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
+ LOAD_INT((ulong)avnrun[0]), LOAD_FRAC((ulong)avnrun[0]),
+ LOAD_INT((ulong)avnrun[1]), LOAD_FRAC((ulong)avnrun[1]),
+ LOAD_INT((ulong)avnrun[2]), LOAD_FRAC((ulong)avnrun[2]),
nr_running(), nr_threads,
idr_get_cursor(&task_active_pid_ns(current)->idr) - 1);
return 0;
diff --git a/include/linux/sched/loadavg.h b/include/linux/sched/loadavg.h
index 83ec54b65e79..8f2d6a827ee9 100644
--- a/include/linux/sched/loadavg.h
+++ b/include/linux/sched/loadavg.h
@@ -13,7 +13,11 @@
* 11 bit fractions.
*/
extern unsigned long avenrun[]; /* Load averages */
+#if defined(CONFIG_64BIT) && (BITS_PER_LONG == 32)
+extern void get_avenrun(unsigned long long *loads, unsigned long offset, int shift);
+#else
extern void get_avenrun(unsigned long *loads, unsigned long offset, int shift);
+#endif
#define FSHIFT 11 /* nr of bits of precision */
#define FIXED_1 (1<<FSHIFT) /* 1.0 as fixed-point */
diff --git a/include/uapi/linux/sysinfo.h b/include/uapi/linux/sysinfo.h
index 435d5c23f0c0..cd29a3d3cd10 100644
--- a/include/uapi/linux/sysinfo.h
+++ b/include/uapi/linux/sysinfo.h
@@ -5,6 +5,25 @@
#include <linux/types.h>
#define SI_LOAD_SHIFT 16
+
+#if (__riscv_xlen == 64) && (__BITS_PER_LONG == 32)
+struct sysinfo {
+ __s64 uptime; /* Seconds since boot */
+ __u64 loads[3]; /* 1, 5, and 15 minute load averages */
+ __u64 totalram; /* Total usable main memory size */
+ __u64 freeram; /* Available memory size */
+ __u64 sharedram; /* Amount of shared memory */
+ __u64 bufferram; /* Memory used by buffers */
+ __u64 totalswap; /* Total swap space size */
+ __u64 freeswap; /* swap space still available */
+ __u16 procs; /* Number of current processes */
+ __u16 pad; /* Explicit padding for m68k */
+ __u64 totalhigh; /* Total high memory size */
+ __u64 freehigh; /* Available high memory size */
+ __u32 mem_unit; /* Memory unit size in bytes */
+ char _f[20-2*sizeof(__u64)-sizeof(__u32)]; /* Padding: libc5 uses this.. */
+};
+#else
struct sysinfo {
__kernel_long_t uptime; /* Seconds since boot */
__kernel_ulong_t loads[3]; /* 1, 5, and 15 minute load averages */
@@ -21,5 +40,6 @@ struct sysinfo {
__u32 mem_unit; /* Memory unit size in bytes */
char _f[20-2*sizeof(__kernel_ulong_t)-sizeof(__u32)]; /* Padding: libc5 uses this.. */
};
+#endif
#endif /* _LINUX_SYSINFO_H */
diff --git a/kernel/sched/loadavg.c b/kernel/sched/loadavg.c
index c48900b856a2..f1f5abc64dea 100644
--- a/kernel/sched/loadavg.c
+++ b/kernel/sched/loadavg.c
@@ -68,7 +68,11 @@ EXPORT_SYMBOL(avenrun); /* should be removed */
*
* These values are estimates at best, so no need for locking.
*/
+#if defined(CONFIG_64BIT) && (BITS_PER_LONG == 32)
+void get_avenrun(unsigned long long *loads, unsigned long offset, int shift)
+#else
void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
+#endif
{
loads[0] = (avenrun[0] + offset) << shift;
loads[1] = (avenrun[1] + offset) << shift;
--
2.40.1
Powered by blists - more mailing lists