mirror of https://gitee.com/openkylin/linux.git
KYLIN: osinfo: Add /proc/osinfo interface
Mainline: NA From: NA Category: Feature CVE: NA 内核新增 /proc/osinfo 接口,主要目的是为了方便在特定的情况下 进行内核的信息收集,方便后端开发者快速定位潜在的问题。 Cc: nh <nh@tj.kylinos.cn> #linux-hwe-5.15 Signed-off-by: Jackie Liu <liuyun01@kylinos.cn> Change-Id: Icf07252a70c76ca0883e001667c8bfc0707ecb62 Signed-off-by: chen zhang <chenzhang@kylinos.cn> Reviewed-on: http://gerrit.kylin.com/c/kfocal/+/23609
This commit is contained in:
parent
9dd3dc484c
commit
036f6986ce
5
Makefile
5
Makefile
|
@ -359,6 +359,8 @@ include $(srctree)/scripts/Kbuild.include
|
|||
# Read KERNELRELEASE from include/config/kernel.release (if it exists)
|
||||
KERNELRELEASE = $(shell cat include/config/kernel.release 2> /dev/null)
|
||||
KERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION)
|
||||
SOURCEVERSION = $(shell git rev-parse HEAD 2> /dev/null)
|
||||
|
||||
export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION
|
||||
|
||||
include $(srctree)/scripts/subarch.include
|
||||
|
@ -1248,7 +1250,8 @@ define filechk_utsrelease.h
|
|||
echo '"$(KERNELRELEASE)" exceeds $(uts_len) characters' >&2; \
|
||||
exit 1; \
|
||||
fi; \
|
||||
echo \#define UTS_RELEASE \"$(KERNELRELEASE)\"
|
||||
(echo \#define UTS_RELEASE \"$(KERNELRELEASE)\"; \
|
||||
echo \#define SOURCE_VERSION \"$(SOURCEVERSION)\";)
|
||||
endef
|
||||
|
||||
define filechk_version.h
|
||||
|
|
|
@ -11,6 +11,9 @@ proc-$(CONFIG_MMU) := task_mmu.o
|
|||
|
||||
proc-y += inode.o root.o base.o generic.o array.o \
|
||||
fd.o
|
||||
|
||||
$(obj)/osinfo.o: include/generated/compile.h
|
||||
|
||||
proc-$(CONFIG_TTY) += proc_tty.o
|
||||
proc-y += cmdline.o
|
||||
proc-y += consoles.o
|
||||
|
@ -19,6 +22,7 @@ proc-y += devices.o
|
|||
proc-y += interrupts.o
|
||||
proc-y += loadavg.o
|
||||
proc-y += meminfo.o
|
||||
proc-y += osinfo.o
|
||||
proc-y += stat.o
|
||||
proc-y += uptime.o
|
||||
proc-y += util.o
|
||||
|
@ -34,3 +38,17 @@ proc-$(CONFIG_PROC_VMCORE) += vmcore.o
|
|||
proc-$(CONFIG_PRINTK) += kmsg.o
|
||||
proc-$(CONFIG_PROC_PAGE_MONITOR) += page.o
|
||||
proc-$(CONFIG_BOOT_CONFIG) += bootconfig.o
|
||||
|
||||
# compile.h changes depending on hostname, generation number, etc,
|
||||
# so we regenerate it always.
|
||||
# mkcompile_h will make sure to only update the
|
||||
# actual file if its content has changed.
|
||||
|
||||
chk_compile.h = :
|
||||
quiet_chk_compile.h = echo ' CHK $@'
|
||||
silent_chk_compile.h = :
|
||||
include/generated/compile.h: FORCE
|
||||
@$($(quiet)chk_compile.h)
|
||||
$(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkcompile_h $@ \
|
||||
"$(UTS_MACHINE)" "$(CONFIG_SMP)" "$(CONFIG_PREEMPT)" \
|
||||
"$(CONFIG_PREEMPT_RT)" "$(CC) $(KBUILD_CFLAGS)"
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* fs/proc/osinfo.c
|
||||
*
|
||||
* Authors: Jackie Liu <liuyun01@kylinos.cn>
|
||||
* Copyright (C) 2020, KylinSoft Co., Ltd.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
#include <linux/fs.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/proc_fs.h>
|
||||
#include <linux/seq_file.h>
|
||||
#include <linux/cpumask.h>
|
||||
#include <linux/mm.h>
|
||||
#include <generated/utsrelease.h>
|
||||
#include <generated/compile.h>
|
||||
|
||||
static int osinfo_proc_show(struct seq_file *m, void *v)
|
||||
{
|
||||
struct sysinfo i;
|
||||
struct timespec64 uptime;
|
||||
|
||||
si_meminfo(&i);
|
||||
ktime_get_boottime_ts64(&uptime);
|
||||
|
||||
seq_printf(m, "Kernel Version:\t\t%s\n", UTS_RELEASE);
|
||||
seq_printf(m, "Source Version:\t\t%s\n",
|
||||
strlen(SOURCE_VERSION) ? SOURCE_VERSION : "Unknown");
|
||||
seq_printf(m, "Build Time:\t\t%s\n", UTS_VERSION);
|
||||
seq_printf(m, "Architecture:\t\t%s\n", UTS_MACHINE);
|
||||
seq_printf(m, "Online CPUs:\t\t%d\n", num_online_cpus());
|
||||
seq_printf(m, "MemTotal:\t\t%ld KB\n"
|
||||
"PageSize:\t\t%ld KB\n", i.totalram << (PAGE_SHIFT - 10),
|
||||
PAGE_SIZE >> 10);
|
||||
seq_printf(m, "Uptime:\t\t\t%lu.%02lu Sec\n", (unsigned long) uptime.tv_sec,
|
||||
(uptime.tv_nsec / (NSEC_PER_SEC / 100)));
|
||||
seq_printf(m, "Cmdline:\t\t%s\n", saved_command_line);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int osinfo_proc_open(struct inode *inode, struct file *file)
|
||||
{
|
||||
return single_open(file, osinfo_proc_show, NULL);
|
||||
}
|
||||
|
||||
static const struct proc_ops osinfo_proc_ops = {
|
||||
.proc_open = osinfo_proc_open,
|
||||
.proc_read = seq_read,
|
||||
.proc_lseek = seq_lseek,
|
||||
.proc_release = single_release,
|
||||
};
|
||||
|
||||
static int __init proc_osinfo_init(void)
|
||||
{
|
||||
proc_create("osinfo", 0, NULL, &osinfo_proc_ops);
|
||||
return 0;
|
||||
}
|
||||
fs_initcall(proc_osinfo_init);
|
Loading…
Reference in New Issue