Compare commits
186 Commits
OpenHarmon
...
weekly_202
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
997e61ed53 | ||
|
|
6c2b163c7d | ||
|
|
979a8a8f27 | ||
|
|
b6f9dbbdba | ||
|
|
a776c04a3d | ||
|
|
f7932bd006 | ||
|
|
b0d31cb43f | ||
|
|
53addea304 | ||
|
|
954e7eb0cf | ||
|
|
0e48a0dd12 | ||
|
|
52c12f7c9d | ||
|
|
1e875d921b | ||
|
|
1db7aa7ada | ||
|
|
6a0c169780 | ||
|
|
bdb9864436 | ||
|
|
bc69ca104c | ||
|
|
0d325c56a1 | ||
|
|
5bed688ca6 | ||
|
|
63e71feca0 | ||
|
|
2ada41c826 | ||
|
|
9b397173fe | ||
|
|
2fa85a2c72 | ||
|
|
63a0fcaefb | ||
|
|
144214869f | ||
|
|
e1512566e3 | ||
|
|
6e886d4233 | ||
|
|
67e31f7b45 | ||
|
|
26c09d26fc | ||
|
|
1a8e22dcf1 | ||
|
|
8e614bb161 | ||
|
|
f88608e5a4 | ||
|
|
30d5badbce | ||
|
|
c8c07261ca | ||
|
|
2cd03c55b7 | ||
|
|
b3489d49d7 | ||
|
|
d955790a44 | ||
|
|
540b2017c5 | ||
|
|
212d1bd1e8 | ||
|
|
ba8438257a | ||
|
|
64e49aba7c | ||
|
|
3e7cfaa520 | ||
|
|
e748fdbe57 | ||
|
|
48f645db84 | ||
|
|
d73aff846b | ||
|
|
ce4323ff16 | ||
|
|
f6a7003c16 | ||
|
|
c12bef84b2 | ||
|
|
7a7c67cbdd | ||
|
|
d2a2f96adf | ||
|
|
5db6c62313 | ||
|
|
011a55ff21 | ||
|
|
68f9f49c2a | ||
|
|
fe4082ca9e | ||
|
|
ac08912230 | ||
|
|
a32a7c4fad | ||
|
|
bba832ea08 | ||
|
|
09fd11bc38 | ||
|
|
9ba725c3d4 | ||
|
|
2bddff54c8 | ||
|
|
bc32a1ec0f | ||
|
|
5d5df3a5d7 | ||
|
|
07cab40473 | ||
|
|
5ce70a50c3 | ||
|
|
0f878febb7 | ||
|
|
f63ce99399 | ||
|
|
e317f9b5b5 | ||
|
|
cc6e11281e | ||
|
|
9525ca2826 | ||
|
|
a412bfb275 | ||
|
|
3b8083815c | ||
|
|
a2fed9a56c | ||
|
|
2251b8a2d1 | ||
|
|
5077b1793f | ||
|
|
e99aba9d0f | ||
|
|
eedde91826 | ||
|
|
cdc0877f16 | ||
|
|
0f8ff8f545 | ||
|
|
f06e090a10 | ||
|
|
38163de8f3 | ||
|
|
fcb21ffc8a | ||
|
|
2e3bbf1e61 | ||
|
|
466996b2e1 | ||
|
|
52379242c1 | ||
|
|
e0a6e1f9f0 | ||
|
|
e54eb9e34d | ||
|
|
ef1d9f848d | ||
|
|
ebfac57d54 | ||
|
|
3074449c79 | ||
|
|
78a297fd4e | ||
|
|
5004ef4d87 | ||
|
|
79839a4325 | ||
|
|
b2274a009e | ||
|
|
a55f68f957 | ||
|
|
0f0e85b7a6 | ||
|
|
308750199f | ||
|
|
2f6cd46372 | ||
|
|
ea45982e1f | ||
|
|
f2f5c5fdc3 | ||
|
|
91c1737d1b | ||
|
|
557f4ccb66 | ||
|
|
1ed28b4c80 | ||
|
|
6827bd2a22 | ||
|
|
614cdccf91 | ||
|
|
23c4f2b81b | ||
|
|
d6f48477a4 | ||
|
|
7676cdb886 | ||
|
|
bd0c0835fc | ||
|
|
24ba16a01e | ||
|
|
f6ac03d3e3 | ||
|
|
f601c16b9e | ||
|
|
c121d0eea3 | ||
|
|
cf8446c941 | ||
|
|
e328c528b1 | ||
|
|
2be59680f2 | ||
|
|
805a67ae2f | ||
|
|
37bc11fa88 | ||
|
|
0507b9e8ea | ||
|
|
acd631c731 | ||
|
|
c1c2be2a87 | ||
|
|
bda00e6747 | ||
|
|
cb423f8454 | ||
|
|
d3b618887a | ||
|
|
e8f5a286aa | ||
|
|
b551270ef5 | ||
|
|
4ecc473843 | ||
|
|
8096d9f575 | ||
|
|
6d249618ae | ||
|
|
40338918d9 | ||
|
|
fd4b97e3f8 | ||
|
|
13e1e70358 | ||
|
|
c360a97bab | ||
|
|
665c152c27 | ||
|
|
3f71be7535 | ||
|
|
298ccea3fe | ||
|
|
56a92f9207 | ||
|
|
d21b05c0f6 | ||
|
|
29df5dc1f2 | ||
|
|
e4a06623ce | ||
|
|
e1b36bfe41 | ||
|
|
3dd952b0b7 | ||
|
|
06ea03715f | ||
|
|
48ca854bf0 | ||
|
|
c7da23695c | ||
|
|
2c33cfce86 | ||
|
|
9bf580b1f6 | ||
|
|
3be31d1cfb | ||
|
|
ee72b21aff | ||
|
|
6e0a3f10bb | ||
|
|
e1b85a4570 | ||
|
|
9726ba11a7 | ||
|
|
0fa1310a32 | ||
|
|
f7d010dfa4 | ||
|
|
bf030b6bb5 | ||
|
|
63fd8bc39b | ||
|
|
7d7cff4c51 | ||
|
|
9ab3e351d3 | ||
|
|
492264b8e6 | ||
|
|
d59aad1f3a | ||
|
|
9b07aece2d | ||
|
|
de8bd2866a | ||
|
|
1150f86d46 | ||
|
|
9fdb80f85f | ||
|
|
93e74c5f0b | ||
|
|
d23f2fc73f | ||
|
|
c0721f4f0b | ||
|
|
a375bf5668 | ||
|
|
52d1d8d8d0 | ||
|
|
c79bcd028e | ||
|
|
ecd9ca7781 | ||
|
|
38a6b804e9 | ||
|
|
92f33ab9c4 | ||
|
|
b3d96d166c | ||
|
|
0326cbf12e | ||
|
|
c3facd1b95 | ||
|
|
8713997548 | ||
|
|
a627cdba0c | ||
|
|
214f44e935 | ||
|
|
ba977dd5ab | ||
|
|
1ecacc15b1 | ||
|
|
33d0c1bd0b | ||
|
|
e095e87682 | ||
|
|
597ced7948 | ||
|
|
f67c4dae51 | ||
|
|
5e87d8c183 | ||
|
|
7019fdfcbb | ||
|
|
5a80d4e1a3 |
162
BUILD.gn
162
BUILD.gn
@@ -29,17 +29,14 @@
|
||||
|
||||
import("//build/lite/config/component/lite_component.gni")
|
||||
|
||||
LITEOS_MENUCONFIG_H = rebase_path("$root_out_dir/config.h")
|
||||
|
||||
declare_args() {
|
||||
tee_enable = false
|
||||
liteos_name = "OHOS_Image"
|
||||
liteos_skip_make = false
|
||||
}
|
||||
|
||||
cmd = "if [ -f $device_path/BUILD.gn ]; then echo true; else echo false; fi"
|
||||
HAVE_DEVICE_SDK = exec_script("//build/lite/run_shell_cmd.py", [ cmd ], "value")
|
||||
|
||||
LITEOS_MENUCONFIG_H = rebase_path("$root_out_dir/config.h")
|
||||
|
||||
tee = ""
|
||||
if (tee_enable) {
|
||||
tee = "_tee"
|
||||
@@ -49,29 +46,27 @@ declare_args() {
|
||||
liteos_config_file = "${ohos_build_type}${tee}.config"
|
||||
}
|
||||
|
||||
liteos_config_file = rebase_path(liteos_config_file, "", "$product_path/kernel_configs")
|
||||
liteos_config_file =
|
||||
rebase_path(liteos_config_file, "", "$product_path/kernel_configs")
|
||||
print("liteos_config_file:", liteos_config_file)
|
||||
|
||||
exec_script("//build/lite/run_shell_cmd.py",
|
||||
[
|
||||
"env" +
|
||||
" CONFIG_=LOSCFG_" +
|
||||
" KCONFIG_CONFIG_HEADER='y=true'" +
|
||||
" KCONFIG_CONFIG=$liteos_config_file" +
|
||||
" DEVICE_PATH=$device_path" +
|
||||
" srctree=" + rebase_path(".") +
|
||||
" genconfig" +
|
||||
" --header-path $LITEOS_MENUCONFIG_H" +
|
||||
" --file-list kconfig_files.txt" +
|
||||
" --env-list kconfig_env.txt" +
|
||||
" --config-out config.gni",
|
||||
], "", [ liteos_config_file ])
|
||||
[ "env" + " CONFIG_=LOSCFG_" + " KCONFIG_CONFIG_HEADER='y=true'" +
|
||||
" KCONFIG_CONFIG=$liteos_config_file" +
|
||||
" DEVICE_PATH=$device_path" + " srctree=" + rebase_path(".") +
|
||||
" genconfig" + " --header-path $LITEOS_MENUCONFIG_H" +
|
||||
" --file-list kconfig_files.txt" +
|
||||
" --env-list kconfig_env.txt" + " --config-out config.gni" ],
|
||||
"",
|
||||
[ liteos_config_file ])
|
||||
|
||||
import("liteos.gni")
|
||||
|
||||
assert(ARCH != "", "ARCH not set!")
|
||||
assert(ARCH == arch, "ARCH not match! details: $ARCH != $arch")
|
||||
assert(tee_enable == defined(LOSCFG_TEE_ENABLE), "TEE switch not match!")
|
||||
assert(ohos_build_compiler == "clang" == defined(LOSCFG_COMPILER_CLANG_LLVM),
|
||||
"compiler not match!")
|
||||
|
||||
generate_notice_file("kernel_notice_file") {
|
||||
module_name = "kernel"
|
||||
@@ -113,7 +108,7 @@ config("arch_config") {
|
||||
ldflags = cflags
|
||||
if (defined(LOSCFG_ARCH_ARM_AARCH32)) {
|
||||
if (!defined(LOSCFG_COMPILER_CLANG_LLVM)) {
|
||||
cflags += ["-mthumb-interwork"]
|
||||
cflags += [ "-mthumb-interwork" ]
|
||||
}
|
||||
}
|
||||
if (defined(LOSCFG_THUMB)) {
|
||||
@@ -127,7 +122,9 @@ config("arch_config") {
|
||||
}
|
||||
|
||||
config("stdinc_config") {
|
||||
std_include = exec_script("//build/lite/run_shell_cmd.py", [ "$cc -print-file-name=include" ], "trim string")
|
||||
std_include = exec_script("//build/lite/run_shell_cmd.py",
|
||||
[ "$cc -print-file-name=include" ],
|
||||
"trim string")
|
||||
cflags = [
|
||||
"-isystem",
|
||||
std_include,
|
||||
@@ -177,7 +174,7 @@ config("optimize_config") {
|
||||
if (defined(LOSCFG_COMPILER_CLANG_LLVM)) {
|
||||
cflags += [ "-flto=thin" ]
|
||||
} else {
|
||||
cflags += [ "-flto" ]
|
||||
#cflags += [ "-flto" ]
|
||||
}
|
||||
}
|
||||
cflags += [ optimization_cflag ]
|
||||
@@ -199,8 +196,10 @@ config("warn_config") {
|
||||
"-Wpointer-arith",
|
||||
"-Wstrict-prototypes",
|
||||
"-Winvalid-pch",
|
||||
"-Wno-address-of-packed-member",
|
||||
]
|
||||
if (defined(LOSCFG_COMPILER_CLANG_LLVM)) {
|
||||
cflags += [ "-Wno-address-of-packed-member" ]
|
||||
}
|
||||
asmflags = cflags
|
||||
}
|
||||
|
||||
@@ -211,6 +210,7 @@ config("dialect_config") {
|
||||
|
||||
config("misc_config") {
|
||||
defines = [ "__LITEOS__" ]
|
||||
defines += [ "__LITEOS_A__" ]
|
||||
if (!defined(LOSCFG_DEBUG_VERSION)) {
|
||||
defines += [ "NDEBUG" ]
|
||||
}
|
||||
@@ -250,62 +250,12 @@ config("los_config") {
|
||||
]
|
||||
}
|
||||
|
||||
executable("liteos") {
|
||||
configs = [] # clear default configs
|
||||
configs += [ ":arch_config" ]
|
||||
configs += [ ":public" ]
|
||||
|
||||
ldflags = [
|
||||
"-static",
|
||||
"-nostdlib",
|
||||
"-Wl,--gc-sections",
|
||||
"-Wl,-Map=$liteos_name.map",
|
||||
"-Wl,--no-eh-frame-hdr",
|
||||
]
|
||||
|
||||
libgcc = exec_script("//build/lite/run_shell_cmd.py", [ "$cc -print-libgcc-file-name" ], "trim string")
|
||||
libs = [ libgcc ]
|
||||
if (defined(LOSCFG_COMPILER_CLANG_LLVM)) {
|
||||
ldflags += [ "-Wl,-T" + rebase_path("tools/build/liteos_llvm.ld", root_build_dir) ]
|
||||
inputs = [ "tools/build/liteos_llvm.ld" ]
|
||||
} else {
|
||||
ldflags += [ "-Wl,-T" + rebase_path("tools/build/liteos.ld", root_build_dir) ]
|
||||
ldflags += [ "-Wl,-nostartfiles" ]
|
||||
inputs = [ "tools/build/liteos.ld" ]
|
||||
}
|
||||
|
||||
inputs += [ "$root_out_dir/board.ld" ]
|
||||
|
||||
output_dir = target_out_dir
|
||||
|
||||
deps = [
|
||||
"platform:copy_board.ld",
|
||||
":modules",
|
||||
]
|
||||
}
|
||||
|
||||
copy("copy_liteos") {
|
||||
deps = [ ":liteos" ]
|
||||
sources = [ "$target_out_dir/unstripped/bin/liteos" ]
|
||||
outputs = [ "$root_out_dir/$liteos_name" ]
|
||||
}
|
||||
|
||||
build_ext_component("build_kernel_image") {
|
||||
deps = [ ":copy_liteos" ]
|
||||
exec_path = rebase_path(root_out_dir)
|
||||
|
||||
objcopy = "${compile_prefix}objcopy$toolchain_cmd_suffix"
|
||||
objdump = "${compile_prefix}objdump$toolchain_cmd_suffix"
|
||||
|
||||
command = "$objcopy -O binary $liteos_name $liteos_name.bin"
|
||||
command += " && sh -c '$objdump -t $liteos_name | sort >$liteos_name.sym.sorted'"
|
||||
command += " && sh -c '$objdump -d $liteos_name >$liteos_name.asm'"
|
||||
}
|
||||
cmd = "if [ -f $device_path/BUILD.gn ]; then echo true; else echo false; fi"
|
||||
HAVE_DEVICE_SDK = exec_script("//build/lite/run_shell_cmd.py", [ cmd ], "value")
|
||||
|
||||
config("public") {
|
||||
configs = [
|
||||
"arch:public",
|
||||
"platform:public",
|
||||
"kernel:public",
|
||||
"compat:public",
|
||||
"bsd:public",
|
||||
@@ -337,15 +287,14 @@ group("modules") {
|
||||
"kernel",
|
||||
"lib",
|
||||
"net",
|
||||
"platform",
|
||||
"security",
|
||||
"shell",
|
||||
"syscall",
|
||||
]
|
||||
|
||||
deps += [
|
||||
HDFTOPDIR,
|
||||
"//drivers/liteos",
|
||||
HDFTOPDIR,
|
||||
]
|
||||
|
||||
if (HAVE_DEVICE_SDK) {
|
||||
@@ -369,10 +318,69 @@ group("liteos_a") {
|
||||
deps = [
|
||||
":apps",
|
||||
":kernel",
|
||||
":make",
|
||||
":tests",
|
||||
"//prebuilts/lite/sysroot/build:strip",
|
||||
]
|
||||
}
|
||||
|
||||
executable("liteos") {
|
||||
configs = [] # clear default configs
|
||||
configs += [ ":arch_config" ]
|
||||
configs += [ ":public" ]
|
||||
|
||||
ldflags = [
|
||||
"-static",
|
||||
"-nostdlib",
|
||||
"-Wl,--gc-sections",
|
||||
"-Wl,-Map=$liteos_name.map",
|
||||
"-Wl,--no-eh-frame-hdr",
|
||||
]
|
||||
|
||||
libgcc = exec_script("//build/lite/run_shell_cmd.py",
|
||||
[ "$cc -print-libgcc-file-name" ],
|
||||
"trim string")
|
||||
libs = [ libgcc ]
|
||||
if (defined(LOSCFG_COMPILER_CLANG_LLVM)) {
|
||||
ldflags +=
|
||||
[ "-Wl,-T" + rebase_path("tools/build/liteos_llvm.ld", root_build_dir) ]
|
||||
inputs = [ "tools/build/liteos_llvm.ld" ]
|
||||
} else {
|
||||
ldflags +=
|
||||
[ "-Wl,-T" + rebase_path("tools/build/liteos.ld", root_build_dir) ]
|
||||
ldflags += [ "-Wl,-nostartfiles" ]
|
||||
inputs = [ "tools/build/liteos.ld" ]
|
||||
}
|
||||
|
||||
inputs += [ "$root_out_dir/board.ld" ]
|
||||
|
||||
output_dir = target_out_dir
|
||||
|
||||
deps = [
|
||||
":modules",
|
||||
"platform:copy_board.ld",
|
||||
]
|
||||
}
|
||||
|
||||
copy("copy_liteos") {
|
||||
deps = [ ":liteos" ]
|
||||
sources = [ "$target_out_dir/unstripped/bin/liteos" ]
|
||||
outputs = [ "$root_out_dir/$liteos_name" ]
|
||||
}
|
||||
|
||||
build_ext_component("build_kernel_image") {
|
||||
deps = [ ":copy_liteos" ]
|
||||
exec_path = rebase_path(root_out_dir)
|
||||
|
||||
objcopy = "${compile_prefix}objcopy$toolchain_cmd_suffix"
|
||||
objdump = "${compile_prefix}objdump$toolchain_cmd_suffix"
|
||||
|
||||
command = "$objcopy -O binary $liteos_name $liteos_name.bin"
|
||||
command +=
|
||||
" && sh -c '$objdump -t $liteos_name | sort >$liteos_name.sym.sorted'"
|
||||
command += " && sh -c '$objdump -d $liteos_name >$liteos_name.asm'"
|
||||
}
|
||||
|
||||
build_ext_component("make") {
|
||||
exec_path = rebase_path(".", root_build_dir)
|
||||
outdir = rebase_path("$target_out_dir/${target_name}_out")
|
||||
|
||||
63
Kconfig
63
Kconfig
@@ -94,15 +94,6 @@ source "platform/Kconfig"
|
||||
######################### config options of cpu arch ################
|
||||
source "arch/Kconfig"
|
||||
|
||||
######################### config options of rootfs #####################
|
||||
source "kernel/common/rootfs/Kconfig"
|
||||
######################### config options of patchfs #####################
|
||||
source "kernel/common/patchfs/Kconfig"
|
||||
######################### config options of blackbox #####################
|
||||
source "kernel/common/blackbox/Kconfig"
|
||||
######################### config options of hidumper #####################
|
||||
source "kernel/common/hidumper/Kconfig"
|
||||
|
||||
config QUICK_START
|
||||
bool "Enable QUICK_START"
|
||||
default n
|
||||
@@ -123,36 +114,7 @@ endmenu
|
||||
|
||||
######################## config options of filesystem ##################
|
||||
menu "FileSystem"
|
||||
source "fs/vfs/Kconfig"
|
||||
source "fs/fat/Kconfig"
|
||||
source "fs/ramfs/Kconfig"
|
||||
source "fs/romfs/Kconfig"
|
||||
source "fs/nfs/Kconfig"
|
||||
source "fs/proc/Kconfig"
|
||||
source "fs/jffs2/Kconfig"
|
||||
source "fs/zpfs/Kconfig"
|
||||
config ENABLE_READ_BUFFER
|
||||
bool "Enable read buffer Option"
|
||||
default n
|
||||
depends on FS_VFS
|
||||
help
|
||||
Answer Y to add enable read buffer Option.
|
||||
|
||||
config MAX_VNODE_SIZE
|
||||
int "Vnode max number"
|
||||
range 0 512
|
||||
default 512
|
||||
depends on FS_VFS
|
||||
help
|
||||
vnode number, range from 0 to 512.
|
||||
|
||||
config MAX_PATH_CACHE_SIZE
|
||||
int "PathCache max number"
|
||||
range 0 1024
|
||||
default 512
|
||||
depends on FS_VFS
|
||||
help
|
||||
pathCache number, range from 0 to 1024.
|
||||
source "fs/Kconfig"
|
||||
endmenu
|
||||
|
||||
######################## config options of net ############################
|
||||
@@ -324,29 +286,10 @@ endmenu
|
||||
|
||||
######################## config options os drivers ########################
|
||||
menu "Driver"
|
||||
config DRIVERS
|
||||
bool "Enable Driver"
|
||||
default y
|
||||
help
|
||||
Answer Y to enable LiteOS support driver.
|
||||
|
||||
source "bsd/dev/usb/Kconfig"
|
||||
source "../../drivers/adapter/khdf/liteos/Kconfig"
|
||||
|
||||
# Device driver Kconfig import
|
||||
source "$(DEVICE_PATH)/drivers/Kconfig"
|
||||
|
||||
source "drivers/char/mem/Kconfig"
|
||||
source "drivers/char/quickstart/Kconfig"
|
||||
source "drivers/char/random/Kconfig"
|
||||
source "drivers/char/video/Kconfig"
|
||||
source "drivers/char/trace/Kconfig"
|
||||
|
||||
source "../../drivers/liteos/tzdriver/Kconfig"
|
||||
source "../../drivers/liteos/hievent/Kconfig"
|
||||
|
||||
source "drivers/Kconfig"
|
||||
endmenu
|
||||
|
||||
######################## config options os security #######################
|
||||
menu "Security"
|
||||
source "security/Kconfig"
|
||||
endmenu
|
||||
|
||||
17
Makefile
17
Makefile
@@ -61,12 +61,6 @@ endif
|
||||
|
||||
KCONFIG_CONFIG ?= $(CONFIG)
|
||||
SYSROOT_PATH ?= $(OUT)/sysroot
|
||||
LITEOS_MENUCONFIG_H ?= $(LITEOSTOPDIR)/config.h
|
||||
LITEOS_CONFIG_FILE ?= $(LITEOSTOPDIR)/.config
|
||||
|
||||
# export los_config.mk related environment variables
|
||||
export LITEOS_MENUCONFIG_H
|
||||
export LITEOS_CONFIG_FILE
|
||||
|
||||
# export subdir Makefile related environment variables
|
||||
export SYSROOT_PATH
|
||||
@@ -125,7 +119,6 @@ help:
|
||||
|
||||
sysroot:
|
||||
$(HIDE)echo "sysroot:" $(abspath $(SYSROOT_PATH))
|
||||
ifeq ($(LOSCFG_COMPILER_CLANG_LLVM), y)
|
||||
ifeq ($(origin SYSROOT_PATH),file)
|
||||
$(HIDE)mkdir -p $(SYSROOT_PATH)/build && cd $(SYSROOT_PATH)/build && \
|
||||
ln -snf $(LITEOSTOPDIR)/../../prebuilts/lite/sysroot/build/Makefile && \
|
||||
@@ -135,20 +128,18 @@ ifeq ($(origin SYSROOT_PATH),file)
|
||||
ARCH_CFLAGS="$(LITEOS_CORE_COPTS) -w" \
|
||||
TOPDIR="$(LITEOSTOPDIR)/../.." \
|
||||
SYSROOTDIR="$(SYSROOT_PATH)" \
|
||||
CLANG="$(LITEOS_COMPILER_PATH)clang" \
|
||||
BUILD_ALL_MULTILIB=false \
|
||||
$(if $(LOSCFG_COMPILER_CLANG_LLVM),CLANG="$(LITEOS_COMPILER_PATH)clang",GCC="$(CC)") \
|
||||
BUILD_DEBUG=$(if $(patsubst y,,$(or $(RELEASE:1=y),n)),true,false)
|
||||
endif
|
||||
endif
|
||||
|
||||
$(KCONFIG_CMDS):
|
||||
$(filter-out menuconfig,$(KCONFIG_CMDS)):
|
||||
$(HIDE)$@ $(args)
|
||||
|
||||
$(LITEOS_CONFIG_FILE): $(KCONFIG_CONFIG)
|
||||
$(HIDE)env KCONFIG_CONFIG=$< genconfig --config-out $@ --header-path $(LITEOS_MENUCONFIG_H)
|
||||
|
||||
update_config:
|
||||
$(HIDE)test -f "$(CONFIG)" && cp -v "$(CONFIG)" .config && menuconfig && savedefconfig --out "$(CONFIG)"
|
||||
update_config menuconfig:
|
||||
$(HIDE)test -f "$(CONFIG)" && cp -v "$(CONFIG)" .config && menuconfig $(args) && savedefconfig --out "$(CONFIG)"
|
||||
|
||||
$(LITEOS_LIBS_TARGET): sysroot
|
||||
$(HIDE)for dir in $(LIB_SUBDIRS); do $(MAKE) -C $$dir all || exit 1; done
|
||||
|
||||
@@ -34,8 +34,8 @@ group("apps") {
|
||||
|
||||
if (defined(LOSCFG_SHELL)) {
|
||||
deps += [
|
||||
"shell",
|
||||
"mksh",
|
||||
"shell",
|
||||
"toybox",
|
||||
]
|
||||
}
|
||||
@@ -51,4 +51,12 @@ group("apps") {
|
||||
if (defined(LOSCFG_DRIVERS_TRACE)) {
|
||||
deps += [ "trace" ]
|
||||
}
|
||||
|
||||
if (defined(LOSCFG_DRIVERS_PERF)) {
|
||||
deps += [ "perf" ]
|
||||
}
|
||||
|
||||
if (defined(LOSCFG_KERNEL_LMS)) {
|
||||
deps += [ "lms:sample_usr_lms" ]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,14 +34,7 @@ export APPSTOPDIR
|
||||
|
||||
include $(APPSTOPDIR)/config.mk
|
||||
|
||||
all:
|
||||
ifneq ($(APP_SUBDIRS), )
|
||||
$(HIDE) for dir in $(APP_SUBDIRS); do $(MAKE) -C $$dir all || exit 1; done
|
||||
endif
|
||||
|
||||
clean:
|
||||
ifneq ($(APP_SUBDIRS), )
|
||||
$(HIDE) for dir in $(APP_SUBDIRS); do $(MAKE) -C $$dir clean || exit 1; done
|
||||
endif
|
||||
all clean:
|
||||
$(HIDE) for dir in $(APP_SUBDIRS); do $(MAKE) -C $$dir $@ || exit 1; done
|
||||
|
||||
.PHONY: all clean
|
||||
|
||||
86
apps/app.mk
86
apps/app.mk
@@ -27,88 +27,6 @@
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
OBJOUT := $(BUILD)$(dir $(subst $(LITEOSTOPDIR),,$(shell pwd)))$(APP_NAME)
|
||||
override TARGET = $(OUT)/bin/$(APP_NAME)
|
||||
|
||||
APP := $(OUT)/bin/$(APP_NAME)
|
||||
|
||||
# create a separate list of objects per source type
|
||||
|
||||
LOCAL_CSRCS := $(filter %.c,$(LOCAL_SRCS))
|
||||
LOCAL_CPPSRCS := $(filter %.cpp,$(LOCAL_SRCS))
|
||||
LOCAL_ASMSRCS := $(filter %.S,$(LOCAL_SRCS))
|
||||
LOCAL_ASMSRCS2 := $(filter %.s,$(LOCAL_SRCS))
|
||||
LOCAL_CCSRCS := $(filter %.cc,$(LOCAL_SRCS))
|
||||
|
||||
LOCAL_COBJS := $(patsubst %.c,$(OBJOUT)/%.o,$(LOCAL_CSRCS))
|
||||
LOCAL_CPPOBJS := $(patsubst %.cpp,$(OBJOUT)/%.o,$(LOCAL_CPPSRCS))
|
||||
LOCAL_ASMOBJS := $(patsubst %.S,$(OBJOUT)/%.o,$(LOCAL_ASMSRCS))
|
||||
LOCAL_ASMOBJS2 := $(patsubst %.s,$(OBJOUT)/%.o,$(LOCAL_ASMSRCS2))
|
||||
LOCAL_CCOBJS := $(patsubst %.cc,$(OBJOUT)/%.o,$(LOCAL_CCSRCS))
|
||||
|
||||
LOCAL_OBJS := $(LOCAL_COBJS) $(LOCAL_CPPOBJS) $(LOCAL_ASMOBJS) $(LOCAL_ASMOBJS2) $(LOCAL_CCOBJS)
|
||||
|
||||
LOCAL_CGCH := $(patsubst %.h,%.h.gch,$(LOCAL_CHS))
|
||||
LOCAL_CPPGCH := $(patsubst %.h,%.h.gch,$(LOCAL_CPPHS))
|
||||
|
||||
all : $(APP)
|
||||
|
||||
define ECHO =
|
||||
ifeq ($$(HIDE),@)
|
||||
_$(1) := $($(1))
|
||||
$(1) = echo " $(1)" $$(patsubst $$(OUT)/%,%,$$@) && $$(_$(1))
|
||||
endif
|
||||
endef
|
||||
$(foreach cmd,CC GPP AS,$(eval $(call ECHO,$(cmd))))
|
||||
|
||||
LOCAL_FLAGS += -MD -MP
|
||||
-include $(LOCAL_OBJS:%.o=%.d)
|
||||
|
||||
$(LOCAL_COBJS): $(OBJOUT)/%.o: %.c
|
||||
$(HIDE)$(OBJ_MKDIR)
|
||||
$(HIDE)$(CC) $(CFLAGS) $(LOCAL_FLAGS) $(LOCAL_CFLAGS) -c $< -o $@
|
||||
|
||||
$(LOCAL_CPPOBJS): $(OBJOUT)/%.o: %.cpp
|
||||
$(HIDE)$(OBJ_MKDIR)
|
||||
$(HIDE)$(GPP) $(CXXFLAGS) $(LOCAL_FLAGS) $(LOCAL_CPPFLAGS) -c $< -o $@
|
||||
|
||||
$(LOCAL_ASMOBJS): $(OBJOUT)/%.o: %.S
|
||||
$(HIDE)$(OBJ_MKDIR)
|
||||
$(HIDE)$(CC) $(CFLAGS) $(LOCAL_FLAGS) $(LOCAL_ASFLAGS) -c $< -o $@
|
||||
|
||||
$(LOCAL_ASMOBJS2): $(OBJOUT)/%.o: %.s
|
||||
$(HIDE)$(OBJ_MKDIR)
|
||||
$(HIDE)$(AS) $(ASFLAGS) $(LOCAL_FLAGS) $(LOCAL_ASFLAGS) -c $< -o $@
|
||||
|
||||
$(LOCAL_CCOBJS): $(OBJOUT)/%.o: %.cc
|
||||
$(HIDE)$(OBJ_MKDIR)
|
||||
$(HIDE)$(GPP) $(CXXFLAGS) $(LOCAL_FLAGS) $(LOCAL_CPPFLAGS) -c $< -o $@
|
||||
|
||||
$(LOCAL_CGCH): %.h.gch : %.h
|
||||
$(HIDE)$(CC) $(CFLAGS) $(LOCAL_FLAGS) $(LOCAL_CFLAGS) $> $^
|
||||
|
||||
$(LOCAL_CPPGCH): %.h.gch : %.h
|
||||
$(HIDE)$(GPP) $(CXXFLAGS) $(LOCAL_FLAGS) $(LOCAL_CPPFLAGS) -x c++-header $> $^
|
||||
|
||||
LOCAL_GCH := $(LOCAL_CGCH) $(LOCAL_CPPGCH)
|
||||
|
||||
$(LOCAL_OBJS): $(LOCAL_GCH)
|
||||
$(APP): $(LOCAL_OBJS)
|
||||
$(HIDE)$(OBJ_MKDIR)
|
||||
$(HIDE)$(GPP) $(LDFLAGS) -o $@ $^
|
||||
|
||||
clean:
|
||||
$(HIDE)$(RM) $(APP) $(OBJOUT) $(LOCAL_GCH) *.bak *~
|
||||
|
||||
.PHONY: all clean
|
||||
|
||||
# clear some variables we set here
|
||||
LOCAL_CSRCS :=
|
||||
LOCAL_CPPSRCS :=
|
||||
LOCAL_ASMSRCS :=
|
||||
LOCAL_COBJS :=
|
||||
LOCAL_CPPOBJS :=
|
||||
LOCAL_ASMOBJS :=
|
||||
LOCAL_ASMOBJS2 :=
|
||||
|
||||
# LOCAL_OBJS is passed back
|
||||
#LOCAL_OBJS :=
|
||||
include $(MODULE)
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
include $(LITEOSTOPDIR)/config.mk
|
||||
|
||||
# common flags config
|
||||
BASE_OPTS := -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE $(LITEOS_GCOV_OPTS)
|
||||
BASE_OPTS := -D_FORTIFY_SOURCE=2 -D_XOPEN_SOURCE=700
|
||||
|
||||
ASFLAGS :=
|
||||
CFLAGS := $(LITEOS_COPTS) $(BASE_OPTS) -fPIE
|
||||
@@ -70,11 +70,6 @@ ifeq ($(LOSCFG_DRIVERS_TRACE), y)
|
||||
APP_SUBDIRS += trace
|
||||
endif
|
||||
|
||||
# clear all local variables
|
||||
LOCAL_FLAGS :=
|
||||
LOCAL_CFLAGS :=
|
||||
LOCAL_CPPFLAGS :=
|
||||
LOCAL_ASFLAGS :=
|
||||
LOCAL_SRCS :=
|
||||
LOCAL_CHS :=
|
||||
LOCAL_CPPHS :=
|
||||
ifeq ($(LOSCFG_DRIVERS_PERF), y)
|
||||
APP_SUBDIRS += perf
|
||||
endif
|
||||
|
||||
77
apps/lms/BUILD.gn
Normal file
77
apps/lms/BUILD.gn
Normal file
@@ -0,0 +1,77 @@
|
||||
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
# conditions and the following disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
# of conditions and the following disclaimer in the documentation and/or other materials
|
||||
# provided with the distribution.
|
||||
#
|
||||
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
# to endorse or promote products derived from this software without specific prior written
|
||||
# permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
import("//build/lite/config/component/lite_component.gni")
|
||||
lite_component("LMS-Sample") {
|
||||
features = [ ":sample_usr_lms" ]
|
||||
}
|
||||
executable("sample_usr_lms") {
|
||||
output_name = "sample_usr_lms"
|
||||
sources = [ "src/sample_usr_lms.c" ]
|
||||
include_dirs = []
|
||||
defines = []
|
||||
if (ohos_build_compiler == "gcc") {
|
||||
cflags_c = [
|
||||
"-O0",
|
||||
"-fsanitize=kernel-address",
|
||||
"-funwind-tables",
|
||||
"-fasynchronous-unwind-tables",
|
||||
]
|
||||
} else {
|
||||
cflags_c = [
|
||||
"-O0",
|
||||
"-fsanitize=kernel-address",
|
||||
"-mllvm",
|
||||
"-asan-instrumentation-with-call-threshold=0",
|
||||
"-mllvm",
|
||||
"-asan-stack=0",
|
||||
"-mllvm",
|
||||
"-asan-globals=0",
|
||||
"-funwind-tables",
|
||||
"-fasynchronous-unwind-tables",
|
||||
]
|
||||
}
|
||||
ldflags = [
|
||||
"-rdynamic",
|
||||
"-lunwind",
|
||||
"-lusrlms",
|
||||
"-Wl,--wrap=realloc",
|
||||
"-Wl,--wrap=calloc",
|
||||
"-Wl,--wrap=malloc",
|
||||
"-Wl,--wrap=free",
|
||||
"-Wl,--wrap=valloc",
|
||||
"-Wl,--wrap=aligned_alloc",
|
||||
"-Wl,--wrap=memset",
|
||||
"-Wl,--wrap=memcpy",
|
||||
"-Wl,--wrap=memmove",
|
||||
"-Wl,--wrap=strcpy",
|
||||
"-Wl,--wrap=strcat",
|
||||
]
|
||||
deps = [ "//kernel/liteos_a/kernel/extended/lms/usr:usrlmslib" ]
|
||||
}
|
||||
208
apps/lms/src/sample_usr_lms.c
Executable file
208
apps/lms/src/sample_usr_lms.c
Executable file
@@ -0,0 +1,208 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static void BufWriteTest(void *buf, int start, int end)
|
||||
{
|
||||
for (int i = start; i <= end; i++) {
|
||||
((char *)buf)[i] = 'a';
|
||||
}
|
||||
}
|
||||
|
||||
static void BufReadTest(void *buf, int start, int end)
|
||||
{
|
||||
char tmp;
|
||||
for (int i = start; i <= end; i++) {
|
||||
tmp = ((char *)buf)[i];
|
||||
}
|
||||
}
|
||||
|
||||
static void LmsMallocTest(void)
|
||||
{
|
||||
printf("\n-------- LmsMallocTest Start --------\n");
|
||||
char *buf = (char *)malloc(16);
|
||||
printf("[LmsMallocTest] malloc addr:%p size:%d\n", buf, 16);
|
||||
|
||||
printf("[LmsMallocTest] read overflow & underflow error should be triggered, read range[-1,16]\n");
|
||||
BufReadTest(buf, -1, 16);
|
||||
printf("[LmsMallocTest] write overflow error should be triggered, write range[0,16]\n");
|
||||
BufWriteTest(buf, 0, 16);
|
||||
|
||||
free(buf);
|
||||
printf("\n-------- LmsMallocTest End --------\n");
|
||||
}
|
||||
|
||||
static void LmsReallocTest(void)
|
||||
{
|
||||
printf("\n-------- LmsReallocTest Start --------\n");
|
||||
char *buf = (char *)malloc(64);
|
||||
printf("[LmsReallocTest] malloc addr:%p size:%d\n", buf, 64);
|
||||
printf("[LmsReallocTest] read overflow & underflow error should be triggered, read range[-1,64]\n");
|
||||
BufReadTest(buf, -1, 64);
|
||||
buf = (char *)realloc(buf, 32);
|
||||
printf("[LmsReallocTest] realloc addr:%p size:%d\n", buf, 32);
|
||||
printf("[LmsReallocTest] read overflow & underflow error should be triggered, read range[-1,32]\n");
|
||||
BufReadTest(buf, -1, 32);
|
||||
free(buf);
|
||||
printf("\n-------- LmsReallocTest End --------\n");
|
||||
}
|
||||
|
||||
static void LmsCallocTest(void)
|
||||
{
|
||||
printf("\n-------- LmsCallocTest Start --------\n");
|
||||
char *buf = (char *)calloc(4, 4);
|
||||
printf("[LmsCallocTest] calloc addr:%p size:%d\n", buf, 16);
|
||||
printf("[LmsCallocTest] read overflow & underflow error should be triggered, read range[-1,16]\n");
|
||||
BufReadTest(buf, -1, 16);
|
||||
free(buf);
|
||||
printf("\n-------- LmsCallocTest End --------\n");
|
||||
}
|
||||
|
||||
static void LmsVallocTest(void)
|
||||
{
|
||||
printf("\n-------- LmsVallocTest Start --------\n");
|
||||
char *buf = (char *)valloc(4096);
|
||||
printf("[LmsVallocTest] valloc addr:%p size:%d\n", buf, 4096);
|
||||
printf("[LmsVallocTest] read overflow & underflow error should be triggered, read range[-1,4096]\n");
|
||||
BufReadTest(buf, -1, 4096);
|
||||
free(buf);
|
||||
printf("\n-------- LmsVallocTest End --------\n");
|
||||
}
|
||||
|
||||
static void LmsAlignedAllocTest(void)
|
||||
{
|
||||
printf("\n-------- LmsAlignedAllocTest Start --------\n");
|
||||
char *buf = (char *)aligned_alloc(64, 128);
|
||||
printf("[LmsAlignedAllocTest] aligned_alloc boundsize:%d addr:%p size:%d\n", 64, buf, 128);
|
||||
printf("[LmsAlignedAllocTest] read overflow & underflow error should be triggered, read range[-1,128]\n");
|
||||
BufReadTest(buf, -1, 128);
|
||||
free(buf);
|
||||
printf("\n-------- LmsAlignedAllocTest End --------\n");
|
||||
}
|
||||
|
||||
static void LmsMemsetTest(void)
|
||||
{
|
||||
printf("\n-------- LmsMemsetTest Start --------\n");
|
||||
char *buf = (char *)malloc(32);
|
||||
printf("[LmsMemsetTest] malloc addr:%p size:%d\n", buf, 32);
|
||||
printf("[LmsMemsetTest] memset overflow & underflow error should be triggered, memset size:%d\n", 33);
|
||||
memset(buf, 0, 33);
|
||||
free(buf);
|
||||
printf("\n-------- LmsMemsetTest End --------\n");
|
||||
}
|
||||
|
||||
static void LmsMemcpyTest(void)
|
||||
{
|
||||
printf("\n-------- LmsMemcpyTest Start --------\n");
|
||||
char *buf = (char *)malloc(20);
|
||||
printf("[LmsMemcpyTest] malloc addr:%p size:%d\n", buf, 20);
|
||||
char localBuf[32] = {0};
|
||||
printf("[LmsMemcpyTest] memcpy overflow error should be triggered, memcpy size:%d\n", 21);
|
||||
memcpy(buf, localBuf, 21);
|
||||
free(buf);
|
||||
printf("\n-------- LmsMemcpyTest End --------\n");
|
||||
}
|
||||
|
||||
static void LmsMemmoveTest(void)
|
||||
{
|
||||
printf("\n-------- LmsMemmoveTest Start --------\n");
|
||||
char *buf = (char *)malloc(20);
|
||||
printf("[LmsMemmoveTest] malloc addr:%p size:%d\n", buf, 20);
|
||||
printf("[LmsMemmoveTest] memmove overflow error should be triggered, dest addr:%p src addr:%p size:%d\n", buf + 12,
|
||||
buf, 10);
|
||||
memmove(buf + 12, buf, 10);
|
||||
free(buf);
|
||||
printf("\n-------- LmsMemmoveTest End --------\n");
|
||||
}
|
||||
|
||||
static void LmsStrcpyTest(void)
|
||||
{
|
||||
printf("\n-------- LmsStrcpyTest Start --------\n");
|
||||
char *buf = (char *)malloc(16);
|
||||
printf("[LmsStrcpyTest] malloc addr:%p size:%d\n", buf, 16);
|
||||
char *testStr = "bbbbbbbbbbbbbbbbb";
|
||||
printf("[LmsStrcpyTest] strcpy overflow error should be triggered, src string buf size:%d\n", strlen(testStr) + 1);
|
||||
strcpy(buf, testStr);
|
||||
free(buf);
|
||||
printf("\n-------- LmsStrcpyTest End --------\n");
|
||||
}
|
||||
|
||||
static void LmsStrcatTest(void)
|
||||
{
|
||||
printf("\n-------- LmsStrcatTest Start --------\n");
|
||||
char *buf = (char *)malloc(16);
|
||||
printf("[LmsStrcatTest] malloc addr:%p size:%d\n", buf, 16);
|
||||
buf[0] = 'a';
|
||||
buf[1] = 'b';
|
||||
buf[2] = 0;
|
||||
char *testStr = "cccccccccccccc";
|
||||
printf("[LmsStrcatTest] strcat overflow error should be triggered, src string:%s dest string:%s"
|
||||
"total buf size:%d\n",
|
||||
testStr, buf, strlen(testStr) + strlen(buf) + 1);
|
||||
strcat(buf, testStr);
|
||||
free(buf);
|
||||
printf("\n-------- LmsStrcatTest End --------\n");
|
||||
}
|
||||
|
||||
static void LmsFreeTest(void)
|
||||
{
|
||||
printf("\n-------- LmsFreeTest Start --------\n");
|
||||
char *buf = (char *)malloc(16);
|
||||
printf("[LmsFreeTest] malloc addr:%p size:%d\n", buf, 16);
|
||||
printf("[LmsFreeTest] free addr:%p\n", buf, 16);
|
||||
free(buf);
|
||||
printf("[LmsFreeTest] Use after free error should be triggered, read addr:%p range[1,1]\n", buf);
|
||||
BufReadTest(buf, 1, 1);
|
||||
printf("[LmsFreeTest] double free error should be triggered, free addr:%p\n", buf);
|
||||
free(buf);
|
||||
printf("\n-------- LmsFreeTest End --------\n");
|
||||
}
|
||||
|
||||
int main(int argc, char * const * argv)
|
||||
{
|
||||
printf("\n############### Lms Test start ###############\n");
|
||||
char *tmp = (char *)malloc(5000);
|
||||
LmsMallocTest();
|
||||
LmsReallocTest();
|
||||
LmsCallocTest();
|
||||
LmsVallocTest();
|
||||
LmsAlignedAllocTest();
|
||||
LmsMemsetTest();
|
||||
LmsMemcpyTest();
|
||||
LmsMemmoveTest();
|
||||
LmsStrcpyTest();
|
||||
LmsStrcatTest();
|
||||
LmsFreeTest();
|
||||
printf("\n############### Lms Test End ###############\n");
|
||||
}
|
||||
63
apps/perf/BUILD.gn
Normal file
63
apps/perf/BUILD.gn
Normal file
@@ -0,0 +1,63 @@
|
||||
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
# conditions and the following disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
# of conditions and the following disclaimer in the documentation and/or other materials
|
||||
# provided with the distribution.
|
||||
#
|
||||
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
# to endorse or promote products derived from this software without specific prior written
|
||||
# permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
import("//kernel/liteos_a/liteos.gni")
|
||||
|
||||
executable("perf") {
|
||||
sources = [
|
||||
"src/main.c",
|
||||
"src/option.c",
|
||||
"src/perf.c",
|
||||
"src/perf_list.c",
|
||||
"src/perf_record.c",
|
||||
"src/perf_stat.c",
|
||||
]
|
||||
include_dirs = [ "include" ]
|
||||
defines = []
|
||||
|
||||
if (defined(LOSCFG_PERF_HW_PMU)) {
|
||||
defines += [ "LOSCFG_PERF_HW_PMU" ]
|
||||
}
|
||||
|
||||
if (defined(LOSCFG_PERF_TIMED_PMU)) {
|
||||
defines += [ "LOSCFG_PERF_TIMED_PMU" ]
|
||||
}
|
||||
|
||||
if (defined(LOSCFG_PERF_SW_PMU)) {
|
||||
defines += [ "LOSCFG_PERF_SW_PMU" ]
|
||||
}
|
||||
|
||||
if (defined(LOSCFG_FS_VFS)) {
|
||||
defines += [ "LOSCFG_FS_VFS" ]
|
||||
}
|
||||
|
||||
defines += [ "LOSCFG_PERF_BUFFER_SIZE=$LOSCFG_PERF_BUFFER_SIZE" ]
|
||||
|
||||
deps = [ "$LITEOSTHIRDPARTY/bounds_checking_function:libsec_static" ]
|
||||
}
|
||||
62
apps/perf/Makefile
Normal file
62
apps/perf/Makefile
Normal file
@@ -0,0 +1,62 @@
|
||||
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
# conditions and the following disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
# of conditions and the following disclaimer in the documentation and/or other materials
|
||||
# provided with the distribution.
|
||||
#
|
||||
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
# to endorse or promote products derived from this software without specific prior written
|
||||
# permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
include $(APPSTOPDIR)/config.mk
|
||||
|
||||
APP_NAME := $(notdir $(shell pwd))
|
||||
|
||||
SECUREC_DIR := $(LITEOSTHIRDPARTY)/bounds_checking_function
|
||||
|
||||
LOCAL_SRCS = $(wildcard src/*.c)
|
||||
LOCAL_SRCS += $(wildcard $(SECUREC_DIR)/src/*.c)
|
||||
|
||||
LOCAL_INCLUDE := \
|
||||
-I include \
|
||||
-I $(SECUREC_DIR)/include
|
||||
|
||||
LOCAL_FLAGS += $(LOCAL_INCLUDE)
|
||||
|
||||
ifeq ($(LOSCFG_PERF_HW_PMU), y)
|
||||
CFLAGS += -DLOSCFG_PERF_HW_PMU
|
||||
endif
|
||||
|
||||
ifeq ($(LOSCFG_PERF_TIMED_PMU), y)
|
||||
CFLAGS += -DLOSCFG_PERF_TIMED_PMU
|
||||
endif
|
||||
|
||||
ifeq ($(LOSCFG_PERF_SW_PMU), y)
|
||||
CFLAGS += -DLOSCFG_PERF_SW_PMU
|
||||
endif
|
||||
|
||||
ifeq ($(LOSCFG_FS_VFS), y)
|
||||
CFLAGS += -DLOSCFG_FS_VFS
|
||||
endif
|
||||
|
||||
CFLAGS += -DLOSCFG_PERF_BUFFER_SIZE=$(LOSCFG_PERF_BUFFER_SIZE)
|
||||
include $(APP)
|
||||
81
apps/perf/include/option.h
Normal file
81
apps/perf/include/option.h
Normal file
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _OPTION_H
|
||||
#define _OPTION_H
|
||||
|
||||
#include "perf.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define CMD_MAX_PARAMS 10
|
||||
typedef int (*CALL_BACK)(const char *argv);
|
||||
|
||||
enum OptionType {
|
||||
OPTION_TYPE_UINT,
|
||||
OPTION_TYPE_STRING,
|
||||
OPTION_TYPE_CALLBACK,
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
int type;
|
||||
const char *name;
|
||||
const char **str;
|
||||
unsigned int *value;
|
||||
CALL_BACK cb;
|
||||
} PerfOption;
|
||||
|
||||
typedef struct {
|
||||
const char *path;
|
||||
char *params[CMD_MAX_PARAMS];
|
||||
} SubCmd;
|
||||
|
||||
#define OPTION_END() {.name = ""}
|
||||
#define OPTION_UINT(n, v) {.type = OPTION_TYPE_UINT, .name = (n), .value = (v)}
|
||||
#define OPTION_STRING(n, s) {.type = OPTION_TYPE_STRING, .name = (n), .str = (s)}
|
||||
#define OPTION_CALLBACK(n, c) {.type = OPTION_TYPE_CALLBACK, .name = (n), .cb = (c)}
|
||||
|
||||
int ParseOptions(int argc, char **argv, PerfOption *opt, SubCmd *cmd);
|
||||
int ParseEvents(const char *argv, PerfEventConfig *eventsCfg, unsigned int *len);
|
||||
int ParseIds(const char *argv, int *arr, unsigned int *len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif /* _OPTION_H */
|
||||
163
apps/perf/include/perf.h
Normal file
163
apps/perf/include/perf.h
Normal file
@@ -0,0 +1,163 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _PERF_H
|
||||
#define _PERF_H
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define PERF_MAX_EVENT 7
|
||||
#define PERF_MAX_FILTER_TSKS 32
|
||||
|
||||
#ifdef PERF_DEBUG
|
||||
#define printf_debug(fmt, ...) printf(fmt, ##__VA_ARGS__)
|
||||
#else
|
||||
#define printf_debug(fmt, ...)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Perf types
|
||||
*/
|
||||
enum PerfEventType {
|
||||
PERF_EVENT_TYPE_HW, /* boards common hw events */
|
||||
PERF_EVENT_TYPE_TIMED, /* hrtimer timed events */
|
||||
PERF_EVENT_TYPE_SW, /* software trace events */
|
||||
PERF_EVENT_TYPE_RAW, /* boards special hw events, see enum PmuEventType in corresponding arch headfile */
|
||||
|
||||
PERF_EVENT_TYPE_MAX
|
||||
};
|
||||
|
||||
/*
|
||||
* Common hardware pmu events
|
||||
*/
|
||||
enum PmuHwId {
|
||||
PERF_COUNT_HW_CPU_CYCLES = 0, /* cpu cycle event */
|
||||
PERF_COUNT_HW_INSTRUCTIONS, /* instruction event */
|
||||
PERF_COUNT_HW_DCACHE_REFERENCES, /* dcache access event */
|
||||
PERF_COUNT_HW_DCACHE_MISSES, /* dcache miss event */
|
||||
PERF_COUNT_HW_ICACHE_REFERENCES, /* icache access event */
|
||||
PERF_COUNT_HW_ICACHE_MISSES, /* icache miss event */
|
||||
PERF_COUNT_HW_BRANCH_INSTRUCTIONS, /* software change of pc event */
|
||||
PERF_COUNT_HW_BRANCH_MISSES, /* branch miss event */
|
||||
|
||||
PERF_COUNT_HW_MAX,
|
||||
};
|
||||
|
||||
/*
|
||||
* Common hrtimer timed events
|
||||
*/
|
||||
enum PmuTimedId {
|
||||
PERF_COUNT_CPU_CLOCK = 0, /* hrtimer timed event */
|
||||
};
|
||||
|
||||
/*
|
||||
* Common software pmu events
|
||||
*/
|
||||
enum PmuSwId {
|
||||
PERF_COUNT_SW_TASK_SWITCH = 1, /* task switch event */
|
||||
PERF_COUNT_SW_IRQ_RESPONSE, /* irq response event */
|
||||
PERF_COUNT_SW_MEM_ALLOC, /* memory alloc event */
|
||||
PERF_COUNT_SW_MUX_PEND, /* mutex pend event */
|
||||
|
||||
PERF_COUNT_SW_MAX,
|
||||
};
|
||||
|
||||
/*
|
||||
* perf sample data types
|
||||
* Config it through PerfConfigAttr->sampleType.
|
||||
*/
|
||||
enum PerfSampleType {
|
||||
PERF_RECORD_CPU = 1U << 0, /* record current cpuid */
|
||||
PERF_RECORD_TID = 1U << 1, /* record current task id */
|
||||
PERF_RECORD_TYPE = 1U << 2, /* record event type */
|
||||
PERF_RECORD_PERIOD = 1U << 3, /* record event period */
|
||||
PERF_RECORD_TIMESTAMP = 1U << 4, /* record timestamp */
|
||||
PERF_RECORD_IP = 1U << 5, /* record instruction pointer */
|
||||
PERF_RECORD_CALLCHAIN = 1U << 6, /* record backtrace */
|
||||
PERF_RECORD_PID = 1U << 7, /* record current process id */
|
||||
};
|
||||
|
||||
/*
|
||||
* perf configuration sub event information
|
||||
*
|
||||
* This structure is used to config specific events attributes.
|
||||
*/
|
||||
typedef struct {
|
||||
unsigned int type; /* enum PerfEventType */
|
||||
struct {
|
||||
unsigned int eventId; /* the specific event corresponds to the PerfEventType */
|
||||
unsigned int period; /* event period, for every "period"th occurrence of the event a
|
||||
sample will be recorded */
|
||||
} events[PERF_MAX_EVENT]; /* perf event list */
|
||||
unsigned int eventsNr; /* total perf event number */
|
||||
size_t predivided; /* whether to prescaler (once every 64 counts),
|
||||
which only take effect on cpu cycle hardware event */
|
||||
} PerfEventConfig;
|
||||
|
||||
/*
|
||||
* perf configuration main information
|
||||
*
|
||||
* This structure is used to set perf sampling attributes, including events, tasks and other information.
|
||||
*/
|
||||
typedef struct {
|
||||
PerfEventConfig eventsCfg; /* perf event config */
|
||||
unsigned int taskIds[PERF_MAX_FILTER_TSKS]; /* perf task filter list (allowlist) */
|
||||
unsigned int taskIdsNr; /* task numbers of task filter allowlist,
|
||||
if set 0 perf will sample all tasks */
|
||||
unsigned int processIds[PERF_MAX_FILTER_TSKS]; /* perf process filter list (allowlist) */
|
||||
unsigned int processIdsNr; /* process numbers of process filter allowlist,
|
||||
if set 0 perf will sample all processes */
|
||||
unsigned int sampleType; /* type of data to sample defined in PerfSampleType */
|
||||
size_t needSample; /* whether to sample data */
|
||||
} PerfConfigAttr;
|
||||
|
||||
void PerfUsage(void);
|
||||
void PerfDumpAttr(PerfConfigAttr *attr);
|
||||
int PerfConfig(int fd, PerfConfigAttr *attr);
|
||||
void PerfStart(int fd, size_t sectionId);
|
||||
void PerfStop(int fd);
|
||||
ssize_t PerfRead(int fd, char *buf, size_t size);
|
||||
void PerfPrintBuffer(const char *buf, ssize_t num);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif /* _PERF_H */
|
||||
@@ -29,28 +29,29 @@
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup los_pmm physical memory management
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#ifndef __LOS_PMM_H__
|
||||
#define __LOS_PMM_H__
|
||||
#ifndef _PERF_LIST_H
|
||||
#define _PERF_LIST_H
|
||||
|
||||
#include "los_typedef.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
BOOL OsIsPaddrValid(paddr_t pa);
|
||||
typedef struct {
|
||||
const char *name;
|
||||
int event;
|
||||
int type;
|
||||
} PerfEvent;
|
||||
|
||||
extern const PerfEvent g_events[];
|
||||
void PerfList(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif /* __LOS_PMM_H__ */
|
||||
#endif /* _PERF_LIST_H */
|
||||
49
apps/perf/include/perf_record.h
Normal file
49
apps/perf/include/perf_record.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _PERF_RECORD_H
|
||||
#define _PERF_RECORD_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
void PerfRecord(int fd, int argc, char **argv);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif /* _PERF_RECORD_H */
|
||||
49
apps/perf/include/perf_stat.h
Normal file
49
apps/perf/include/perf_stat.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _PERF_STAT_H
|
||||
#define _PERF_STAT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
void PerfStat(int fd, int argc, char **argv);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif /* _PERF_STAT_H */
|
||||
82
apps/perf/src/main.c
Normal file
82
apps/perf/src/main.c
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include "perf.h"
|
||||
#include "perf_list.h"
|
||||
#include "perf_stat.h"
|
||||
#include "perf_record.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
#define TWO_ARGS 2
|
||||
#define THREE_ARGS 3
|
||||
int fd = open("/dev/perf", O_RDWR);
|
||||
if (fd == -1) {
|
||||
printf("Perf open failed.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (argc == 1) {
|
||||
PerfUsage();
|
||||
} else if ((argc == TWO_ARGS) && strcmp(argv[1], "start") == 0) {
|
||||
PerfStart(fd, 0);
|
||||
} else if ((argc == THREE_ARGS) && strcmp(argv[1], "start") == 0) {
|
||||
size_t id = strtoul(argv[THREE_ARGS - 1], NULL, 0);
|
||||
PerfStart(fd, id);
|
||||
} else if ((argc == TWO_ARGS) && strcmp(argv[1], "stop") == 0) {
|
||||
PerfStop(fd);
|
||||
} else if ((argc == THREE_ARGS) && strcmp(argv[1], "read") == 0) {
|
||||
size_t size = strtoul(argv[THREE_ARGS - 1], NULL, 0);
|
||||
char *buf = (char *)malloc(size);
|
||||
int len = PerfRead(fd, buf, size);
|
||||
PerfPrintBuffer(buf, len);
|
||||
free(buf);
|
||||
} else if ((argc == TWO_ARGS) && strcmp(argv[1], "list") == 0) {
|
||||
PerfList();
|
||||
} else if ((argc >= THREE_ARGS) && strcmp(argv[1], "stat") == 0) {
|
||||
PerfStat(fd, argc, argv);
|
||||
} else if ((argc >= THREE_ARGS) && strcmp(argv[1], "record") == 0) {
|
||||
PerfRecord(fd, argc, argv);
|
||||
} else {
|
||||
printf("Unsupported perf command.\n");
|
||||
PerfUsage();
|
||||
}
|
||||
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
182
apps/perf/src/option.c
Normal file
182
apps/perf/src/option.c
Normal file
@@ -0,0 +1,182 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "option.h"
|
||||
#include "perf_list.h"
|
||||
|
||||
static int ParseOption(char **argv, int *index, PerfOption *opts)
|
||||
{
|
||||
int ret = 0;
|
||||
const char *str = NULL;
|
||||
|
||||
while ((opts->name != NULL) && (*opts->name != 0)) {
|
||||
if (strcmp(argv[*index], opts->name) == 0) {
|
||||
switch (opts->type) {
|
||||
case OPTION_TYPE_UINT:
|
||||
*opts->value = strtoul(argv[++(*index)], NULL, 0);
|
||||
break;
|
||||
case OPTION_TYPE_STRING:
|
||||
*opts->str = argv[++(*index)];
|
||||
break;
|
||||
case OPTION_TYPE_CALLBACK:
|
||||
str = argv[++(*index)];
|
||||
if ((*opts->cb)(str) != 0) {
|
||||
printf("parse error\n");
|
||||
ret = -1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
printf("invalid option\n");
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
opts++;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ParseOptions(int argc, char **argv, PerfOption *opts, SubCmd *cmd)
|
||||
{
|
||||
int i;
|
||||
int index = 0;
|
||||
|
||||
while ((index < argc) && (argv[index] != NULL) && (*argv[index] == '-')) {
|
||||
if (ParseOption(argv, &index, opts) != 0) {
|
||||
return -1;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
|
||||
if ((index < argc) && (argv[index] != NULL)) {
|
||||
cmd->path = argv[index];
|
||||
cmd->params[0] = argv[index];
|
||||
index++;
|
||||
} else {
|
||||
printf("no subcmd to execute\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (i = 1; (index < argc) && (i < CMD_MAX_PARAMS); index++, i++) {
|
||||
cmd->params[i] = argv[index];
|
||||
}
|
||||
printf_debug("subcmd = %s\n", cmd->path);
|
||||
for (int j = 0; j < i; j++) {
|
||||
printf_debug("paras[%d]:%s\n", j, cmd->params[j]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ParseIds(const char *argv, int *arr, unsigned int *len)
|
||||
{
|
||||
int res, ret;
|
||||
unsigned int index = 0;
|
||||
char *sp = NULL;
|
||||
char *this = NULL;
|
||||
char *list = strdup(argv);
|
||||
|
||||
if (list == NULL) {
|
||||
printf("no memory for ParseIds\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
sp = strtok_r(list, ",", &this);
|
||||
while (sp) {
|
||||
res = strtoul(sp, NULL, 0);
|
||||
if (res < 0) {
|
||||
ret = -1;
|
||||
goto EXIT;
|
||||
}
|
||||
arr[index++] = res;
|
||||
sp = strtok_r(NULL, ",", &this);
|
||||
}
|
||||
*len = index;
|
||||
ret = 0;
|
||||
EXIT:
|
||||
free(list);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline const PerfEvent *StrToEvent(const char *str)
|
||||
{
|
||||
const PerfEvent *evt = &g_events[0];
|
||||
|
||||
for (; evt->event != -1; evt++) {
|
||||
if (strcmp(str, evt->name) == 0) {
|
||||
return evt;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int ParseEvents(const char *argv, PerfEventConfig *eventsCfg, unsigned int *len)
|
||||
{
|
||||
int ret;
|
||||
unsigned int index = 0;
|
||||
const PerfEvent *event = NULL;
|
||||
char *sp = NULL;
|
||||
char *this = NULL;
|
||||
char *list = strdup(argv);
|
||||
|
||||
if (list == NULL) {
|
||||
printf("no memory for ParseEvents\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
sp = strtok_r(list, ",", &this);
|
||||
while (sp) {
|
||||
event = StrToEvent(sp);
|
||||
if (event == NULL) {
|
||||
ret = -1;
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
if (index == 0) {
|
||||
eventsCfg->type = event->type;
|
||||
} else if (eventsCfg->type != event->type) {
|
||||
printf("events type must be same\n");
|
||||
ret = -1;
|
||||
goto EXIT;
|
||||
}
|
||||
eventsCfg->events[index].eventId = event->event;
|
||||
sp = strtok_r(NULL, ",", &this);
|
||||
index++;
|
||||
}
|
||||
*len = index;
|
||||
ret = 0;
|
||||
EXIT:
|
||||
free(list);
|
||||
return ret;
|
||||
}
|
||||
136
apps/perf/src/perf.c
Normal file
136
apps/perf/src/perf.c
Normal file
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include "perf.h"
|
||||
|
||||
#define PERF_IOC_MAGIC 'T'
|
||||
#define PERF_START _IO(PERF_IOC_MAGIC, 1)
|
||||
#define PERF_STOP _IO(PERF_IOC_MAGIC, 2)
|
||||
|
||||
void PerfUsage(void)
|
||||
{
|
||||
printf("\nUsage: ./perf start [id]. Start perf.\n");
|
||||
printf("\nUsage: ./perf stop. Stop perf.\n");
|
||||
printf("\nUsage: ./perf read <nBytes>. Read nBytes raw data from perf buffer and print out.\n");
|
||||
printf("\nUsage: ./perf list. List events to be used in -e.\n");
|
||||
printf("\nUsage: ./perf stat/record [option] <command>. \n"
|
||||
"-e, event selector. use './perf list' to list available events.\n"
|
||||
"-p, event period.\n"
|
||||
"-o, perf data output filename.\n"
|
||||
"-t, taskId filter(allowlist), if not set perf will sample all tasks.\n"
|
||||
"-s, type of data to sample defined in PerfSampleType los_perf.h.\n"
|
||||
"-P, processId filter(allowlist), if not set perf will sample all processes.\n"
|
||||
"-d, whether to prescaler (once every 64 counts),"
|
||||
"which only take effect on cpu cycle hardware event.\n"
|
||||
);
|
||||
}
|
||||
|
||||
static void PerfSetPeriod(PerfConfigAttr *attr)
|
||||
{
|
||||
int i;
|
||||
for (i = 1; i < attr->eventsCfg.eventsNr; i++) {
|
||||
attr->eventsCfg.events[i].period = attr->eventsCfg.events[0].period;
|
||||
}
|
||||
}
|
||||
|
||||
void PerfPrintBuffer(const char *buf, ssize_t num)
|
||||
{
|
||||
#define BYTES_PER_LINE 4
|
||||
ssize_t i;
|
||||
for (i = 0; i < num; i++) {
|
||||
printf(" %02x", (unsigned char)buf[i]);
|
||||
if (((i + 1) % BYTES_PER_LINE) == 0) {
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void PerfDumpAttr(PerfConfigAttr *attr)
|
||||
{
|
||||
int i;
|
||||
printf_debug("attr->type: %d\n", attr->eventsCfg.type);
|
||||
for (i = 0; i < attr->eventsCfg.eventsNr; i++) {
|
||||
printf_debug("attr->events[%d]: %d, 0x%x\n", i, attr->eventsCfg.events[i].eventId,
|
||||
attr->eventsCfg.events[i].period);
|
||||
}
|
||||
printf_debug("attr->predivided: %d\n", attr->eventsCfg.predivided);
|
||||
printf_debug("attr->sampleType: 0x%x\n", attr->sampleType);
|
||||
|
||||
for (i = 0; i < attr->taskIdsNr; i++) {
|
||||
printf_debug("attr->taskIds[%d]: %d\n", i, attr->taskIds[i]);
|
||||
}
|
||||
|
||||
for (i = 0; i < attr->processIdsNr; i++) {
|
||||
printf_debug("attr->processIds[%d]: %d\n", i, attr->processIds[i]);
|
||||
}
|
||||
|
||||
printf_debug("attr->needSample: %d\n", attr->needSample);
|
||||
}
|
||||
|
||||
|
||||
void PerfStart(int fd, size_t sectionId)
|
||||
{
|
||||
(void)ioctl(fd, PERF_START, sectionId);
|
||||
}
|
||||
|
||||
void PerfStop(int fd)
|
||||
{
|
||||
(void)ioctl(fd, PERF_STOP, NULL);
|
||||
}
|
||||
|
||||
int PerfConfig(int fd, PerfConfigAttr *attr)
|
||||
{
|
||||
if (attr == NULL) {
|
||||
return -1;
|
||||
}
|
||||
PerfSetPeriod(attr);
|
||||
PerfDumpAttr(attr);
|
||||
return write(fd, attr, sizeof(PerfConfigAttr));
|
||||
}
|
||||
|
||||
ssize_t PerfRead(int fd, char *buf, size_t size)
|
||||
{
|
||||
ssize_t len;
|
||||
if (buf == NULL) {
|
||||
printf("Read buffer is null.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
len = read(fd, buf, size);
|
||||
return len;
|
||||
}
|
||||
129
apps/perf/src/perf_list.c
Normal file
129
apps/perf/src/perf_list.c
Normal file
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "perf.h"
|
||||
#include "perf_list.h"
|
||||
|
||||
static const char *g_eventTypeStr[] = {
|
||||
"[Hardware event]",
|
||||
"[Timed event]",
|
||||
"[Software event]",
|
||||
};
|
||||
|
||||
const PerfEvent g_events[] = {
|
||||
#ifdef LOSCFG_PERF_HW_PMU
|
||||
{
|
||||
.name = "cycles",
|
||||
.event = PERF_COUNT_HW_CPU_CYCLES,
|
||||
.type = PERF_EVENT_TYPE_HW,
|
||||
},
|
||||
{
|
||||
.name = "instruction",
|
||||
.event = PERF_COUNT_HW_INSTRUCTIONS,
|
||||
.type = PERF_EVENT_TYPE_HW,
|
||||
},
|
||||
{
|
||||
.name = "dcache",
|
||||
.event = PERF_COUNT_HW_DCACHE_REFERENCES,
|
||||
.type = PERF_EVENT_TYPE_HW,
|
||||
},
|
||||
{
|
||||
.name = "dcache-miss",
|
||||
.event = PERF_COUNT_HW_DCACHE_MISSES,
|
||||
.type = PERF_EVENT_TYPE_HW,
|
||||
},
|
||||
{
|
||||
.name = "icache",
|
||||
.event = PERF_COUNT_HW_ICACHE_REFERENCES,
|
||||
.type = PERF_EVENT_TYPE_HW,
|
||||
},
|
||||
{
|
||||
.name = "icache-miss",
|
||||
.event = PERF_COUNT_HW_ICACHE_MISSES,
|
||||
.type = PERF_EVENT_TYPE_HW,
|
||||
},
|
||||
{
|
||||
.name = "branch",
|
||||
.event = PERF_COUNT_HW_BRANCH_INSTRUCTIONS,
|
||||
.type = PERF_EVENT_TYPE_HW,
|
||||
},
|
||||
{
|
||||
.name = "branch-miss",
|
||||
.event = PERF_COUNT_HW_BRANCH_MISSES,
|
||||
.type = PERF_EVENT_TYPE_HW,
|
||||
},
|
||||
#endif
|
||||
#ifdef LOSCFG_PERF_TIMED_PMU
|
||||
{
|
||||
.name = "clock",
|
||||
.event = PERF_COUNT_CPU_CLOCK,
|
||||
.type = PERF_EVENT_TYPE_TIMED,
|
||||
},
|
||||
#endif
|
||||
#ifdef LOSCFG_PERF_SW_PMU
|
||||
{
|
||||
.name = "task-switch",
|
||||
.event = PERF_COUNT_SW_TASK_SWITCH,
|
||||
.type = PERF_EVENT_TYPE_SW,
|
||||
},
|
||||
{
|
||||
.name = "irq-in",
|
||||
.event = PERF_COUNT_SW_IRQ_RESPONSE,
|
||||
.type = PERF_EVENT_TYPE_SW,
|
||||
},
|
||||
{
|
||||
.name = "mem-alloc",
|
||||
.event = PERF_COUNT_SW_MEM_ALLOC,
|
||||
.type = PERF_EVENT_TYPE_SW,
|
||||
},
|
||||
{
|
||||
.name = "mux-pend",
|
||||
.event = PERF_COUNT_SW_MUX_PEND,
|
||||
.type = PERF_EVENT_TYPE_SW,
|
||||
},
|
||||
#endif
|
||||
{
|
||||
.name = "",
|
||||
.event = -1,
|
||||
.type = PERF_EVENT_TYPE_MAX,
|
||||
}
|
||||
};
|
||||
|
||||
void PerfList(void)
|
||||
{
|
||||
const PerfEvent *evt = &g_events[0];
|
||||
printf("\n");
|
||||
for (; evt->event != -1; evt++) {
|
||||
printf("\t %-25s%30s\n", evt->name, g_eventTypeStr[evt->type]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
204
apps/perf/src/perf_record.c
Normal file
204
apps/perf/src/perf_record.c
Normal file
@@ -0,0 +1,204 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/wait.h>
|
||||
#include <securec.h>
|
||||
|
||||
#ifdef LOSCFG_FS_VFS
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#endif
|
||||
|
||||
#include "perf.h"
|
||||
#include "option.h"
|
||||
#include "perf_record.h"
|
||||
|
||||
#define PERF_FILE_MODE 0644
|
||||
static PerfConfigAttr g_recordAttr;
|
||||
static const char *g_savePath = "/storage/data/perf.data";
|
||||
|
||||
static inline int GetEvents(const char *argv)
|
||||
{
|
||||
return ParseEvents(argv, &g_recordAttr.eventsCfg, &g_recordAttr.eventsCfg.eventsNr);
|
||||
}
|
||||
|
||||
static inline int GetTids(const char *argv)
|
||||
{
|
||||
return ParseIds(argv, (int *)g_recordAttr.taskIds, &g_recordAttr.taskIdsNr);
|
||||
}
|
||||
|
||||
static inline int GetPids(const char *argv)
|
||||
{
|
||||
return ParseIds(argv, (int *)g_recordAttr.processIds, &g_recordAttr.processIdsNr);
|
||||
}
|
||||
|
||||
static PerfOption g_recordOpts[] = {
|
||||
OPTION_CALLBACK("-e", GetEvents),
|
||||
OPTION_CALLBACK("-t", GetTids),
|
||||
OPTION_CALLBACK("-P", GetPids),
|
||||
OPTION_STRING("-o", &g_savePath),
|
||||
OPTION_UINT("-p", &g_recordAttr.eventsCfg.events[0].period),
|
||||
OPTION_UINT("-s", &g_recordAttr.sampleType),
|
||||
OPTION_UINT("-d", &g_recordAttr.eventsCfg.predivided),
|
||||
};
|
||||
|
||||
static int PerfRecordAttrInit(void)
|
||||
{
|
||||
PerfConfigAttr attr = {
|
||||
.eventsCfg = {
|
||||
#ifdef LOSCFG_PERF_HW_PMU
|
||||
.type = PERF_EVENT_TYPE_HW,
|
||||
.events = {
|
||||
[0] = {PERF_COUNT_HW_CPU_CYCLES, 0xFFFF},
|
||||
},
|
||||
#elif defined LOSCFG_PERF_TIMED_PMU
|
||||
.type = PERF_EVENT_TYPE_TIMED,
|
||||
.events = {
|
||||
[0] = {PERF_COUNT_CPU_CLOCK, 100},
|
||||
},
|
||||
#elif defined LOSCFG_PERF_SW_PMU
|
||||
.type = PERF_EVENT_TYPE_SW,
|
||||
.events = {
|
||||
[0] = {PERF_COUNT_SW_TASK_SWITCH, 1},
|
||||
},
|
||||
#endif
|
||||
.eventsNr = 1, /* 1 event */
|
||||
.predivided = 0,
|
||||
},
|
||||
.taskIds = {0},
|
||||
.taskIdsNr = 0,
|
||||
.processIds = {0},
|
||||
.processIdsNr = 0,
|
||||
.needSample = 1,
|
||||
.sampleType = PERF_RECORD_IP | PERF_RECORD_CALLCHAIN,
|
||||
};
|
||||
|
||||
return memcpy_s(&g_recordAttr, sizeof(PerfConfigAttr), &attr, sizeof(PerfConfigAttr)) != EOK ? -1 : 0;
|
||||
}
|
||||
|
||||
ssize_t PerfWriteFile(const char *filePath, const char *buf, ssize_t bufSize)
|
||||
{
|
||||
#ifdef LOSCFG_FS_VFS
|
||||
int fd = -1;
|
||||
ssize_t totalToWrite = bufSize;
|
||||
ssize_t totalWrite = 0;
|
||||
|
||||
if (filePath == NULL || buf == NULL || bufSize == 0) {
|
||||
printf("filePath: %p, buf: %p, bufSize: %u!\n", filePath, buf, bufSize);
|
||||
return -1;
|
||||
}
|
||||
|
||||
fd = open(filePath, O_CREAT | O_RDWR | O_TRUNC, PERF_FILE_MODE);
|
||||
if (fd < 0) {
|
||||
printf("create file [%s] failed, fd: %d, %s!\n", filePath, fd, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
while (totalToWrite > 0) {
|
||||
ssize_t writeThisTime = write(fd, buf, totalToWrite);
|
||||
if (writeThisTime < 0) {
|
||||
printf("failed to write file [%s], %s!\n", filePath, strerror(errno));
|
||||
(void)close(fd);
|
||||
return -1;
|
||||
}
|
||||
buf += writeThisTime;
|
||||
totalToWrite -= writeThisTime;
|
||||
totalWrite += writeThisTime;
|
||||
}
|
||||
(void)fsync(fd);
|
||||
(void)close(fd);
|
||||
|
||||
return (totalWrite == bufSize) ? 0 : -1;
|
||||
#else
|
||||
(void)filePath;
|
||||
PerfPrintBuffer(buf, bufSize);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void PerfRecord(int fd, int argc, char **argv)
|
||||
{
|
||||
int ret;
|
||||
int child;
|
||||
char *buf;
|
||||
ssize_t len;
|
||||
SubCmd cmd = {0};
|
||||
|
||||
if (argc < 3) { /* perf record argc is at least 3 */
|
||||
return;
|
||||
}
|
||||
|
||||
ret = PerfRecordAttrInit();
|
||||
if (ret != 0) {
|
||||
printf("perf record attr init failed\n");
|
||||
return;
|
||||
}
|
||||
|
||||
ret = ParseOptions(argc - 2, &argv[2], g_recordOpts, &cmd); /* parse option and cmd begin at index 2 */
|
||||
if (ret != 0) {
|
||||
printf("parse error\n");
|
||||
return;
|
||||
}
|
||||
|
||||
ret = PerfConfig(fd, &g_recordAttr);
|
||||
if (ret != 0) {
|
||||
printf("perf config failed\n");
|
||||
return;
|
||||
}
|
||||
|
||||
PerfStart(fd, 0);
|
||||
child = fork();
|
||||
if (child < 0) {
|
||||
printf("fork error\n");
|
||||
PerfStop(fd);
|
||||
return;
|
||||
} else if (child == 0) {
|
||||
(void)execve(cmd.path, cmd.params, NULL);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
waitpid(child, 0, 0);
|
||||
PerfStop(fd);
|
||||
|
||||
buf = (char *)malloc(LOSCFG_PERF_BUFFER_SIZE);
|
||||
if (buf == NULL) {
|
||||
printf("no memory for read perf 0x%x\n", LOSCFG_PERF_BUFFER_SIZE);
|
||||
return;
|
||||
}
|
||||
len = PerfRead(fd, buf, LOSCFG_PERF_BUFFER_SIZE);
|
||||
ret = PerfWriteFile(g_savePath, buf, len);
|
||||
if (ret == 0) {
|
||||
printf("save perf data success at %s\n", g_savePath);
|
||||
} else {
|
||||
printf("save perf data failed at %s\n", g_savePath);
|
||||
}
|
||||
free(buf);
|
||||
}
|
||||
149
apps/perf/src/perf_stat.c
Normal file
149
apps/perf/src/perf_stat.c
Normal file
@@ -0,0 +1,149 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <securec.h>
|
||||
#include <sys/wait.h>
|
||||
#include "perf.h"
|
||||
#include "option.h"
|
||||
#include "perf_stat.h"
|
||||
|
||||
static PerfConfigAttr g_statAttr;
|
||||
|
||||
static inline int GetEvents(const char *argv)
|
||||
{
|
||||
return ParseEvents(argv, &g_statAttr.eventsCfg, &g_statAttr.eventsCfg.eventsNr);
|
||||
}
|
||||
|
||||
static inline int GetTids(const char *argv)
|
||||
{
|
||||
return ParseIds(argv, (int *)g_statAttr.taskIds, &g_statAttr.taskIdsNr);
|
||||
}
|
||||
|
||||
static inline int GetPids(const char *argv)
|
||||
{
|
||||
return ParseIds(argv, (int *)g_statAttr.processIds, &g_statAttr.processIdsNr);
|
||||
}
|
||||
|
||||
static PerfOption g_statOpts[] = {
|
||||
OPTION_CALLBACK("-e", GetEvents),
|
||||
OPTION_CALLBACK("-t", GetTids),
|
||||
OPTION_CALLBACK("-P", GetPids),
|
||||
OPTION_UINT("-p", &g_statAttr.eventsCfg.events[0].period),
|
||||
OPTION_UINT("-s", &g_statAttr.sampleType),
|
||||
OPTION_UINT("-d", &g_statAttr.eventsCfg.predivided),
|
||||
};
|
||||
|
||||
static int PerfStatAttrInit(void)
|
||||
{
|
||||
PerfConfigAttr attr = {
|
||||
.eventsCfg = {
|
||||
#ifdef LOSCFG_PERF_HW_PMU
|
||||
.type = PERF_EVENT_TYPE_HW,
|
||||
.events = {
|
||||
[0] = {PERF_COUNT_HW_CPU_CYCLES, 0xFFFF},
|
||||
[1] = {PERF_COUNT_HW_INSTRUCTIONS, 0xFFFFFF00},
|
||||
[2] = {PERF_COUNT_HW_ICACHE_REFERENCES, 0xFFFF},
|
||||
[3] = {PERF_COUNT_HW_DCACHE_REFERENCES, 0xFFFF},
|
||||
},
|
||||
.eventsNr = 4, /* 4 events */
|
||||
#elif defined LOSCFG_PERF_TIMED_PMU
|
||||
.type = PERF_EVENT_TYPE_TIMED,
|
||||
.events = {
|
||||
[0] = {PERF_COUNT_CPU_CLOCK, 100},
|
||||
},
|
||||
.eventsNr = 1, /* 1 event */
|
||||
#elif defined LOSCFG_PERF_SW_PMU
|
||||
.type = PERF_EVENT_TYPE_SW,
|
||||
.events = {
|
||||
[0] = {PERF_COUNT_SW_TASK_SWITCH, 1},
|
||||
[1] = {PERF_COUNT_SW_IRQ_RESPONSE, 1},
|
||||
[2] = {PERF_COUNT_SW_MEM_ALLOC, 1},
|
||||
[3] = {PERF_COUNT_SW_MUX_PEND, 1},
|
||||
},
|
||||
.eventsNr = 4, /* 4 events */
|
||||
#endif
|
||||
.predivided = 0,
|
||||
},
|
||||
.taskIds = {0},
|
||||
.taskIdsNr = 0,
|
||||
.processIds = {0},
|
||||
.processIdsNr = 0,
|
||||
.needSample = 0,
|
||||
.sampleType = 0,
|
||||
};
|
||||
|
||||
return memcpy_s(&g_statAttr, sizeof(PerfConfigAttr), &attr, sizeof(PerfConfigAttr)) != EOK ? -1 : 0;
|
||||
}
|
||||
|
||||
void PerfStat(int fd, int argc, char **argv)
|
||||
{
|
||||
int ret;
|
||||
int child;
|
||||
SubCmd cmd = {0};
|
||||
|
||||
if (argc < 3) { /* perf stat argc is at least 3 */
|
||||
return;
|
||||
}
|
||||
|
||||
ret = PerfStatAttrInit();
|
||||
if (ret != 0) {
|
||||
printf("perf stat attr init failed\n");
|
||||
return;
|
||||
}
|
||||
|
||||
ret = ParseOptions(argc - 2, &argv[2], g_statOpts, &cmd); /* parse option and cmd begin at index 2 */
|
||||
if (ret != 0) {
|
||||
printf("parse error\n");
|
||||
return;
|
||||
}
|
||||
|
||||
ret = PerfConfig(fd, &g_statAttr);
|
||||
if (ret != 0) {
|
||||
printf("perf config failed\n");
|
||||
return;
|
||||
}
|
||||
|
||||
PerfStart(fd, 0);
|
||||
child = fork();
|
||||
if (child < 0) {
|
||||
printf("fork error\n");
|
||||
goto EXIT;
|
||||
} else if (child == 0) {
|
||||
(void)execve(cmd.path, cmd.params, NULL);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
(void)waitpid(child, 0, 0);
|
||||
EXIT:
|
||||
PerfStop(fd);
|
||||
}
|
||||
|
||||
@@ -29,9 +29,7 @@
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
|
||||
#include "unistd.h"
|
||||
#include "shcmd.h"
|
||||
@@ -48,7 +46,7 @@ int Chdir(const char *tgtDir)
|
||||
|
||||
ret = chdir(tgtDir);
|
||||
if (ret == 0) {
|
||||
ret = OsShellSetWorkingDirtectory(tgtDir, strlen(tgtDir) + 1); /* 1: the length of '\0' */
|
||||
ret = OsShellSetWorkingDirectory(tgtDir, strlen(tgtDir) + 1); /* 1: the length of '\0' */
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
@@ -53,7 +53,7 @@ typedef struct {
|
||||
} CmdKeyLink;
|
||||
|
||||
#define NEED_NEW_LINE(timesPrint, lineCap) ((timesPrint) % (lineCap) == 0)
|
||||
#define SCREEN_IS_FULL(timesPrint, lineCap) ((timesPrint) >= ((lineCap) * DEFAULT_SCREEN_HEIGNT))
|
||||
#define SCREEN_IS_FULL(timesPrint, lineCap) ((timesPrint) >= ((lineCap) * DEFAULT_SCREEN_HEIGHT))
|
||||
|
||||
extern unsigned int OsCmdExec(CmdParsed *cmdParsed, char *cmdStr);
|
||||
extern unsigned int OsCmdKeyShift(const char *cmdKey, char *cmdOut, unsigned int size);
|
||||
@@ -62,7 +62,7 @@ extern void OsShellCmdPush(const char *string, CmdKeyLink *cmdKeyLink);
|
||||
extern void OsShellHistoryShow(unsigned int value, ShellCB *shellCB);
|
||||
extern unsigned int OsShellKeyInit(ShellCB *shellCB);
|
||||
extern void OsShellKeyDeInit(CmdKeyLink *cmdKeyLink);
|
||||
extern int OsShellSetWorkingDirtectory(const char *dir, size_t len);
|
||||
extern int OsShellSetWorkingDirectory(const char *dir, size_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
|
||||
@@ -54,7 +54,7 @@ extern "C" {
|
||||
#define CMD_HISTORY_LEN 10
|
||||
#define CMD_MAX_PATH 256
|
||||
#define DEFAULT_SCREEN_WIDTH 80
|
||||
#define DEFAULT_SCREEN_HEIGNT 24
|
||||
#define DEFAULT_SCREEN_HEIGHT 24
|
||||
|
||||
#define SWITCH_QUOTES_STATUS(qu) do { \
|
||||
if ((qu) == TRUE) { \
|
||||
|
||||
@@ -32,10 +32,6 @@
|
||||
#ifndef _SHELL_PRI_H
|
||||
#define _SHELL_PRI_H
|
||||
|
||||
#include "sys/types.h"
|
||||
#include "bits/alltypes.h"
|
||||
#include "shcmd.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@@ -32,9 +32,6 @@
|
||||
#ifndef _SHERR_H
|
||||
#define _SHERR_H
|
||||
|
||||
#include "sys/types.h"
|
||||
#include "bits/alltypes.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@@ -43,8 +43,13 @@ extern "C" {
|
||||
#define SHELL_ENTRY_STACKSIZE 0x1000
|
||||
#define SHELL_TASK_STACKSIZE 0x3000
|
||||
|
||||
#define SHELL_EXEC_COMMAND "exec "
|
||||
#define SHELL_EXEC_COMMAND_BYTES 5
|
||||
#define SHELL_EXEC_COMMAND "exec"
|
||||
#define SHELL_EXEC_COMMAND_BYTES 4
|
||||
#define CMD_EXEC_COMMAND SHELL_EXEC_COMMAND" "
|
||||
#define CMD_EXEC_COMMAND_BYTES (SHELL_EXEC_COMMAND_BYTES + 1)
|
||||
#define CMD_EXIT_COMMAND "exit"
|
||||
#define CMD_EXIT_COMMAND_BYTES 4
|
||||
#define CMD_EXIT_CODE_BASE_DEC 10
|
||||
|
||||
#define CONSOLE_IOC_MAGIC 'c'
|
||||
#define CONSOLE_CONTROL_REG_USERTASK _IO(CONSOLE_IOC_MAGIC, 7)
|
||||
@@ -54,9 +59,10 @@ extern "C" {
|
||||
#define COLOR_L_RED "\e[1;31m"
|
||||
#define SHELL_PROMPT COLOR_L_RED"OHOS # "COLOR_NONE
|
||||
|
||||
typedef void (*OutputFunc)(const char *fmt, ...);
|
||||
typedef void (* OutputFunc)(const char *fmt, ...);
|
||||
extern int ShellTaskInit(ShellCB *shellCB);
|
||||
extern int ShellEntryInit(ShellCB *shellCB);
|
||||
extern void ChildExec(const char *cmdName, char *const paramArray[]);
|
||||
extern void ShellCmdLineParse(char c, OutputFunc outputFunc, ShellCB *shellCB);
|
||||
extern int ShellNotify(ShellCB *shellCB);
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
extern char *OsShellGetWorkingDirtectory(void);
|
||||
extern char *OsShellGetWorkingDirectory(void);
|
||||
extern unsigned int OsShellInit(void);
|
||||
extern int OsShellDeinit(ShellCB *shellCB);
|
||||
extern ShellCB *OsGetShellCb(void);
|
||||
|
||||
@@ -29,6 +29,8 @@
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
|
||||
#include "show.h"
|
||||
#include "shmsg.h"
|
||||
#include "shcmd.h"
|
||||
@@ -95,6 +97,9 @@ static int DoShellExec(char **argv)
|
||||
int ret = SH_NOK;
|
||||
char *cmdLine = NULL;
|
||||
|
||||
if (strncmp(argv[0], SHELL_EXEC_COMMAND, SHELL_EXEC_COMMAND_BYTES) == 0) {
|
||||
ChildExec(argv[1], argv + 1);
|
||||
}
|
||||
for (i = 0; argv[i]; i++) {
|
||||
len += strlen(argv[i]);
|
||||
}
|
||||
@@ -105,12 +110,12 @@ static int DoShellExec(char **argv)
|
||||
}
|
||||
memset_s(cmdLine, len, 0, len);
|
||||
|
||||
for(j = 0; j < i; j++) {
|
||||
for (j = 0; j < i; j++) {
|
||||
strcat_s(cmdLine, len, argv[j]);
|
||||
strcat_s(cmdLine, len, " ");
|
||||
}
|
||||
|
||||
cmdLine[len - 2] = '\0';
|
||||
cmdLine[len - 2] = '\0'; /* 2, (len - 2) is the end of cmdline buf */
|
||||
ret = syscall(__NR_shellexec, argv[0], cmdLine);
|
||||
free(cmdLine);
|
||||
return ret;
|
||||
@@ -121,7 +126,7 @@ int main(int argc, char **argv)
|
||||
int ret = SH_NOK;
|
||||
ShellCB *shellCB = NULL;
|
||||
|
||||
if (!strcmp(argv[0], "shell") && argv[1]) {
|
||||
if (argc > 1) {
|
||||
ret = DoShellExec(argv + 1);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -91,12 +91,12 @@ static int OsStrSeparateTabStrGet(const char **tabStr, CmdParsed *parsed, unsign
|
||||
return SH_OK;
|
||||
}
|
||||
|
||||
char *OsShellGetWorkingDirtectory()
|
||||
char *OsShellGetWorkingDirectory(void)
|
||||
{
|
||||
return OsGetShellCb()->shellWorkingDirectory;
|
||||
}
|
||||
|
||||
int OsShellSetWorkingDirtectory(const char *dir, size_t len)
|
||||
int OsShellSetWorkingDirectory(const char *dir, size_t len)
|
||||
{
|
||||
if (dir == NULL) {
|
||||
return SH_NOK;
|
||||
@@ -115,7 +115,7 @@ static int OsStrSeparate(const char *tabStr, char *strPath, char *nameLooking, u
|
||||
char *strEnd = NULL;
|
||||
char *cutPos = NULL;
|
||||
CmdParsed parsed = {0};
|
||||
char *shellWorkingDirectory = OsShellGetWorkingDirtectory();
|
||||
char *shellWorkingDirectory = OsShellGetWorkingDirectory();
|
||||
int ret;
|
||||
|
||||
ret = OsStrSeparateTabStrGet(&tabStr, &parsed, tabStrLen);
|
||||
@@ -223,7 +223,7 @@ static int OsPrintMatchList(unsigned int count, const char *strPath, const char
|
||||
return (int)SH_ERROR;
|
||||
}
|
||||
|
||||
if (count > (lineCap * DEFAULT_SCREEN_HEIGNT)) {
|
||||
if (count > (lineCap * DEFAULT_SCREEN_HEIGHT)) {
|
||||
ret = OsSurePrintAll(count);
|
||||
if (ret != 1) {
|
||||
return ret;
|
||||
@@ -375,10 +375,10 @@ static int OsTabMatchFile(char *cmdKey, unsigned int *len)
|
||||
}
|
||||
|
||||
/*
|
||||
* Description: Pass in the string and clear useless space ,which inlcude:
|
||||
* Description: Pass in the string and clear useless space ,which include:
|
||||
* 1) The overmatch space which is not be marked by Quote's area
|
||||
* Squeeze the overmatch space into one space
|
||||
* 2) Clear all space before first vaild charatctor
|
||||
* 2) Clear all space before first valid charatctor
|
||||
* Input: cmdKey : Pass in the buff string, which is ready to be operated
|
||||
* cmdOut : Pass out the buffer string ,which has already been operated
|
||||
* size : cmdKey length
|
||||
@@ -407,7 +407,7 @@ unsigned int OsCmdKeyShift(const char *cmdKey, char *cmdOut, unsigned int size)
|
||||
|
||||
/* Backup the 'output' start address */
|
||||
outputBak = output;
|
||||
/* Scan each charactor in 'cmdKey',and squeeze the overmuch space and ignore invaild charactor */
|
||||
/* Scan each charactor in 'cmdKey',and squeeze the overmuch space and ignore invalid charactor */
|
||||
for (; *cmdKey != '\0'; cmdKey++) {
|
||||
/* Detected a Double Quotes, switch the matching status */
|
||||
if (*(cmdKey) == '\"') {
|
||||
@@ -417,7 +417,7 @@ unsigned int OsCmdKeyShift(const char *cmdKey, char *cmdOut, unsigned int size)
|
||||
/* 1) Quotes matching status is FALSE (which said that the space is not been marked by double quotes) */
|
||||
/* 2) Current charactor is a space */
|
||||
/* 3) Next charactor is a space too, or the string is been seeked to the end already(\0) */
|
||||
/* 4) Invaild charactor, such as single quotes */
|
||||
/* 4) Invalid charactor, such as single quotes */
|
||||
if ((*cmdKey == ' ') && ((*(cmdKey + 1) == ' ') || (*(cmdKey + 1) == '\0')) && QUOTES_STATUS_CLOSE(quotes)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -29,6 +29,8 @@
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
|
||||
#include "stdlib.h"
|
||||
#include "stdio.h"
|
||||
#include "unistd.h"
|
||||
@@ -42,7 +44,10 @@
|
||||
#include "shell_pri.h"
|
||||
#include "shcmd.h"
|
||||
|
||||
#define CHAR_CTRL_C '\x03'
|
||||
#define CHAR_CTRL_DEL '\x7F'
|
||||
|
||||
#define VISIABLE_CHAR(ch) ((ch) > 0x1F && (ch) < 0x7F)
|
||||
|
||||
char *GetCmdline(ShellCB *shellCB)
|
||||
{
|
||||
@@ -128,7 +133,7 @@ int ShellNotify(ShellCB *shellCB)
|
||||
}
|
||||
|
||||
enum {
|
||||
STAT_NOMAL_KEY,
|
||||
STAT_NORMAL_KEY,
|
||||
STAT_ESC_KEY,
|
||||
STAT_MULTI_KEY
|
||||
};
|
||||
@@ -147,23 +152,23 @@ static int ShellCmdLineCheckUDRL(const char ch, ShellCB *shellCB)
|
||||
} else if (ch == 0x41) { /* up */
|
||||
if (shellCB->shellKeyType == STAT_MULTI_KEY) {
|
||||
OsShellHistoryShow(CMD_KEY_UP, shellCB);
|
||||
shellCB->shellKeyType = STAT_NOMAL_KEY;
|
||||
shellCB->shellKeyType = STAT_NORMAL_KEY;
|
||||
return ret;
|
||||
}
|
||||
} else if (ch == 0x42) { /* down */
|
||||
if (shellCB->shellKeyType == STAT_MULTI_KEY) {
|
||||
shellCB->shellKeyType = STAT_NOMAL_KEY;
|
||||
shellCB->shellKeyType = STAT_NORMAL_KEY;
|
||||
OsShellHistoryShow(CMD_KEY_DOWN, shellCB);
|
||||
return ret;
|
||||
}
|
||||
} else if (ch == 0x43) { /* right */
|
||||
if (shellCB->shellKeyType == STAT_MULTI_KEY) {
|
||||
shellCB->shellKeyType = STAT_NOMAL_KEY;
|
||||
shellCB->shellKeyType = STAT_NORMAL_KEY;
|
||||
return ret;
|
||||
}
|
||||
} else if (ch == 0x44) { /* left */
|
||||
if (shellCB->shellKeyType == STAT_MULTI_KEY) {
|
||||
shellCB->shellKeyType = STAT_NOMAL_KEY;
|
||||
shellCB->shellKeyType = STAT_NORMAL_KEY;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
@@ -200,7 +205,21 @@ void ParseEnterKey(OutputFunc outputFunc, ShellCB *shellCB)
|
||||
shellCB->shellBuf[shellCB->shellBufOffset] = '\0';
|
||||
}
|
||||
NOTIFY:
|
||||
outputFunc("\n");
|
||||
shellCB->shellBufOffset = 0;
|
||||
ShellTaskNotify(shellCB);
|
||||
}
|
||||
|
||||
void ParseCancelKey(OutputFunc outputFunc, ShellCB *shellCB)
|
||||
{
|
||||
if ((shellCB == NULL) || (outputFunc == NULL)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (shellCB->shellBufOffset <= (SHOW_MAX_LEN - 1)) {
|
||||
shellCB->shellBuf[0] = CHAR_CTRL_C;
|
||||
shellCB->shellBuf[1] = '\0';
|
||||
}
|
||||
|
||||
shellCB->shellBufOffset = 0;
|
||||
ShellTaskNotify(shellCB);
|
||||
}
|
||||
@@ -236,7 +255,7 @@ void ParseTabKey(OutputFunc outputFunc, ShellCB *shellCB)
|
||||
|
||||
void ParseNormalChar(char ch, OutputFunc outputFunc, ShellCB *shellCB)
|
||||
{
|
||||
if ((shellCB == NULL) || (outputFunc == NULL)) {
|
||||
if ((shellCB == NULL) || (outputFunc == NULL) || !VISIABLE_CHAR(ch)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -246,7 +265,7 @@ void ParseNormalChar(char ch, OutputFunc outputFunc, ShellCB *shellCB)
|
||||
outputFunc("%c", ch);
|
||||
}
|
||||
|
||||
shellCB->shellKeyType = STAT_NOMAL_KEY;
|
||||
shellCB->shellKeyType = STAT_NORMAL_KEY;
|
||||
}
|
||||
|
||||
void ShellCmdLineParse(char c, OutputFunc outputFunc, ShellCB *shellCB)
|
||||
@@ -254,7 +273,7 @@ void ShellCmdLineParse(char c, OutputFunc outputFunc, ShellCB *shellCB)
|
||||
const char ch = c;
|
||||
int ret;
|
||||
|
||||
if ((shellCB->shellBufOffset == 0) && (ch != '\n') && (ch != '\0')) {
|
||||
if ((shellCB->shellBufOffset == 0) && (ch != '\n') && (ch != CHAR_CTRL_C) && (ch != '\0')) {
|
||||
(void)memset_s(shellCB->shellBuf, SHOW_MAX_LEN, 0, SHOW_MAX_LEN);
|
||||
}
|
||||
|
||||
@@ -263,8 +282,11 @@ void ShellCmdLineParse(char c, OutputFunc outputFunc, ShellCB *shellCB)
|
||||
case '\n': /* enter */
|
||||
ParseEnterKey(outputFunc, shellCB);
|
||||
break;
|
||||
case CHAR_CTRL_C: /* ctrl + c */
|
||||
ParseCancelKey(outputFunc, shellCB);
|
||||
break;
|
||||
case '\b': /* backspace */
|
||||
case 0x7F: /* delete(0x7F) */
|
||||
case CHAR_CTRL_DEL: /* delete(0x7F) */
|
||||
ParseDeleteKey(outputFunc, shellCB);
|
||||
break;
|
||||
case '\t': /* tab */
|
||||
@@ -329,40 +351,80 @@ char *GetCmdName(const char *cmdline, unsigned int len)
|
||||
return cmdName;
|
||||
}
|
||||
|
||||
void ChildExec(const char *cmdName, char *const paramArray[])
|
||||
{
|
||||
int ret;
|
||||
pid_t gid;
|
||||
|
||||
ret = setpgrp();
|
||||
if (ret == -1) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
gid = getpgrp();
|
||||
if (gid < 0) {
|
||||
printf("get group id failed, pgrpid %d, errno %d\n", gid, errno);
|
||||
}
|
||||
|
||||
ret = tcsetpgrp(STDIN_FILENO, gid);
|
||||
if (ret != 0) {
|
||||
printf("tcsetpgrp failed, errno %d\n", errno);
|
||||
}
|
||||
|
||||
ret = execve(cmdName, paramArray, NULL);
|
||||
if (ret == -1) {
|
||||
perror("execve");
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
int CheckExit(const char *cmdName, const CmdParsed *cmdParsed)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if (strlen(cmdName) != CMD_EXIT_COMMAND_BYTES || strncmp(cmdName, CMD_EXIT_COMMAND, CMD_EXIT_COMMAND_BYTES) != 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (cmdParsed->paramCnt > 1) {
|
||||
printf("exit: too many arguments\n");
|
||||
return -1;
|
||||
}
|
||||
if (cmdParsed->paramCnt == 1) {
|
||||
char *p = NULL;
|
||||
ret = strtol(cmdParsed->paramArray[0], &p, CMD_EXIT_CODE_BASE_DEC);
|
||||
if (*p != '\0') {
|
||||
printf("exit: bad number: %s\n", cmdParsed->paramArray[0]);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
exit(ret);
|
||||
}
|
||||
|
||||
static void DoCmdExec(const char *cmdName, const char *cmdline, unsigned int len, const CmdParsed *cmdParsed)
|
||||
{
|
||||
int ret;
|
||||
pid_t forkPid;
|
||||
pid_t gid;
|
||||
|
||||
if (strncmp(cmdline, SHELL_EXEC_COMMAND, SHELL_EXEC_COMMAND_BYTES) == 0) {
|
||||
if (strncmp(cmdline, CMD_EXEC_COMMAND, CMD_EXEC_COMMAND_BYTES) == 0) {
|
||||
forkPid = fork();
|
||||
if (forkPid < 0) {
|
||||
printf("Faild to fork from shell\n");
|
||||
return;
|
||||
} else if (forkPid == 0) {
|
||||
ret = setpgrp();
|
||||
if (ret == -1) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
gid = getpgrp();
|
||||
if (gid < 0) {
|
||||
printf("get group id failed, pgrpid %d, errno %d\n", gid, errno);
|
||||
}
|
||||
|
||||
ret = tcsetpgrp(STDIN_FILENO, gid);
|
||||
ChildExec(cmdParsed->paramArray[0], cmdParsed->paramArray);
|
||||
} else {
|
||||
waitpid(forkPid, 0, 0);
|
||||
ret = tcsetpgrp(STDIN_FILENO, getpid());
|
||||
if (ret != 0) {
|
||||
printf("tcsetpgrp failed, errno %d\n", errno);
|
||||
}
|
||||
|
||||
ret = execve((const char *)cmdParsed->paramArray[0], (char * const *)cmdParsed->paramArray, NULL);
|
||||
if (ret == -1) {
|
||||
perror("execve");
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (CheckExit(cmdName, cmdParsed) < 0) {
|
||||
return;
|
||||
}
|
||||
(void)syscall(__NR_shellexec, cmdName, cmdline);
|
||||
}
|
||||
}
|
||||
@@ -397,7 +459,7 @@ static void ParseAndExecCmdline(CmdParsed *cmdParsed, const char *cmdline, unsig
|
||||
DoCmdExec(cmdName, cmdlineOrigin, len, cmdParsed);
|
||||
|
||||
if (getcwd(shellWorkingDirectory, PATH_MAX) != NULL) {
|
||||
(void)OsShellSetWorkingDirtectory(shellWorkingDirectory, (PATH_MAX + 1));
|
||||
(void)OsShellSetWorkingDirectory(shellWorkingDirectory, (PATH_MAX + 1));
|
||||
}
|
||||
|
||||
OUT:
|
||||
@@ -417,7 +479,7 @@ unsigned int PreHandleCmdline(const char *input, char **output, unsigned int *ou
|
||||
unsigned int removeLen = strlen("./"); /* "./" needs to be removed if it exists */
|
||||
unsigned int ret;
|
||||
char *newCmd = NULL;
|
||||
char *execCmd = SHELL_EXEC_COMMAND;
|
||||
char *execCmd = CMD_EXEC_COMMAND;
|
||||
const char *cmdBuf = input;
|
||||
unsigned int cmdBufLen = strlen(cmdBuf);
|
||||
char *shiftStr = (char *)malloc(cmdBufLen + 1);
|
||||
@@ -520,7 +582,11 @@ static void ShellCmdProcess(ShellCB *shellCB)
|
||||
if (buf == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (buf[0] == CHAR_CTRL_C) {
|
||||
printf("^C");
|
||||
buf[0] = '\n';
|
||||
}
|
||||
printf("\n");
|
||||
ExecCmdline(buf);
|
||||
ShellSaveHistoryCmd(buf, shellCB);
|
||||
shellCB->cmdMaskKeyLink = shellCB->cmdHistoryKeyLink;
|
||||
|
||||
@@ -46,7 +46,10 @@ copy("copy_toybox_config") {
|
||||
}
|
||||
|
||||
build_ext_component("build_toybox") {
|
||||
deps = [ ":copy_toybox_src", ":copy_toybox_config" ]
|
||||
deps = [
|
||||
":copy_toybox_config",
|
||||
":copy_toybox_src",
|
||||
]
|
||||
deps += [ "//prebuilts/lite/sysroot" ]
|
||||
exec_path = rebase_path("$target_out_dir/toybox_build")
|
||||
|
||||
|
||||
@@ -31,4 +31,4 @@ import("//kernel/liteos_a/liteos.gni")
|
||||
|
||||
executable("trace") {
|
||||
sources = [ "src/trace.c" ]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,11 +88,13 @@ static void TraceWrite(int fd, int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
UsrEventInfo info = {0};
|
||||
info.eventType = strtoul(argv[2], NULL, 0);
|
||||
info.identity = strtoul(argv[3], NULL, 0);
|
||||
info.eventType = strtoul(argv[2], NULL, 0); /* 2, argv number */
|
||||
info.identity = strtoul(argv[3], NULL, 0); /* 3, argv number */
|
||||
/* 4, argc -4 means user argv that does not contain argv[0]~argv[3] */
|
||||
int paramNum = (argc - 4) > TRACE_USR_MAX_PARAMS ? TRACE_USR_MAX_PARAMS : (argc - 4);
|
||||
|
||||
|
||||
for (i = 0; i < paramNum; i++) {
|
||||
/* 4, argc -4 means user argv that does not contain argv[0]~argv[3] */
|
||||
info.params[i] = strtoul(argv[4 + i], NULL, 0);
|
||||
}
|
||||
(void)write(fd, &info, sizeof(UsrEventInfo));
|
||||
@@ -108,22 +110,22 @@ int main(int argc, char **argv)
|
||||
|
||||
if (argc == 1) {
|
||||
TraceUsage();
|
||||
} else if (argc == 2 && strcmp(argv[1], "start") == 0) {
|
||||
} else if (argc == 2 && strcmp(argv[1], "start") == 0) { /* 2, argv num, no special meaning */
|
||||
ioctl(fd, TRACE_START, NULL);
|
||||
} else if (argc == 2 && strcmp(argv[1], "stop") == 0) {
|
||||
} else if (argc == 2 && strcmp(argv[1], "stop") == 0) { /* 2, argv num, no special meaning */
|
||||
ioctl(fd, TRACE_STOP, NULL);
|
||||
} else if (argc == 2 && strcmp(argv[1], "reset") == 0) {
|
||||
} else if (argc == 2 && strcmp(argv[1], "reset") == 0) { /* 2, argv num, no special meaning */
|
||||
ioctl(fd, TRACE_RESET, NULL);
|
||||
} else if (argc == 3 && strcmp(argv[1], "mask") == 0) {
|
||||
} else if (argc == 3 && strcmp(argv[1], "mask") == 0) { /* 3, argv num, no special meaning */
|
||||
size_t mask = strtoul(argv[2], NULL, 0);
|
||||
ioctl(fd, TRACE_SET_MASK, mask);
|
||||
} else if (argc == 3 && strcmp(argv[1], "dump") == 0) {
|
||||
} else if (argc == 3 && strcmp(argv[1], "dump") == 0) { /* 3, argv num, no special meaning */
|
||||
size_t flag = strtoul(argv[2], NULL, 0);
|
||||
ioctl(fd, TRACE_DUMP, flag);
|
||||
} else if (argc == 3 && strcmp(argv[1], "read") == 0) {
|
||||
} else if (argc == 3 && strcmp(argv[1], "read") == 0) { /* 3, argv num, no special meaning */
|
||||
size_t size = strtoul(argv[2], NULL, 0);
|
||||
TraceRead(fd, size);
|
||||
} else if (argc >= 4 && strcmp(argv[1], "write") == 0) {
|
||||
} else if (argc >= 4 && strcmp(argv[1], "write") == 0) { /* 4, argv num, no special meaning */
|
||||
TraceWrite(fd, argc, argv);
|
||||
} else {
|
||||
printf("Unsupported trace command.\n");
|
||||
|
||||
@@ -74,12 +74,3 @@ ARCH_INCLUDE := -I $(LITEOSTOPDIR)/arch/arm/include \
|
||||
-I $(LITEOSTOPDIR)/arch/arm/$(ARCH)/src/include
|
||||
|
||||
LITEOS_PLATFORM_INCLUDE += $(ARCH_INCLUDE)
|
||||
|
||||
# expose FPU info to assembly code
|
||||
ifeq ($(LOSCFG_ARCH_FPU_DISABLE), y)
|
||||
LITEOS_CMACRO += -DLOSCFG_ARCH_FPU_DISABLE
|
||||
else ifeq ($(LOSCFG_ARCH_FPU_VFP_D16), y)
|
||||
LITEOS_CMACRO += -DLOSCFG_ARCH_FPU_VFP_D16
|
||||
else ifeq ($(LOSCFG_ARCH_FPU_VFP_D32), y)
|
||||
LITEOS_CMACRO += -DLOSCFG_ARCH_FPU_VFP_D32
|
||||
endif
|
||||
|
||||
@@ -46,10 +46,10 @@ kernel_module(module_name) {
|
||||
"src/los_hw_runstop.S",
|
||||
"src/los_hw_tick.c",
|
||||
"src/los_hwi.c",
|
||||
"src/smp.c",
|
||||
"src/strncpy_from_user.c",
|
||||
"src/strnlen_user.c",
|
||||
"src/user_copy.c",
|
||||
"src/smp.c",
|
||||
]
|
||||
|
||||
if (LOSCFG_ARCH_ARM_VER == "armv7-a") {
|
||||
@@ -64,6 +64,10 @@ kernel_module(module_name) {
|
||||
|
||||
include_dirs = [ "src/include" ]
|
||||
|
||||
if (defined(LOSCFG_PERF_HW_PMU)) {
|
||||
sources += [ "src/pmu/armv7_pmu.c" ]
|
||||
}
|
||||
|
||||
if (defined(LOSCFG_GDB)) {
|
||||
configs += [ ":as_objs_libc_flags" ]
|
||||
}
|
||||
@@ -82,9 +86,11 @@ config("as_objs_libc_flags") {
|
||||
defines = [ "__ASSEMBLY__" ]
|
||||
|
||||
# linux style macros
|
||||
if (defined(LOSCFG_ARCH_ARM_V7A) || defined(LOSCFG_ARCH_ARM_V7R) || defined(LOSCFG_ARCH_ARM_V7M)) {
|
||||
if (defined(LOSCFG_ARCH_ARM_V7A) || defined(LOSCFG_ARCH_ARM_V7R) ||
|
||||
defined(LOSCFG_ARCH_ARM_V7M)) {
|
||||
defines += [ "__LINUX_ARM_ARCH__=7" ]
|
||||
} else if (defined(LOSCFG_ARCH_ARM_V8A) || defined(LOSCFG_ARCH_ARM_V8R) || defined(LOSCFG_ARCH_ARM_V8M)) {
|
||||
} else if (defined(LOSCFG_ARCH_ARM_V8A) || defined(LOSCFG_ARCH_ARM_V8R) ||
|
||||
defined(LOSCFG_ARCH_ARM_V8M)) {
|
||||
defines += [ "__LINUX_ARM_ARCH__=8" ]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,11 +32,6 @@ include $(LITEOSTOPDIR)/config.mk
|
||||
MODULE_NAME := $(LOSCFG_ARCH_CPU)
|
||||
|
||||
LOCAL_SRCS := $(wildcard src/*.c) $(wildcard src/*.S)
|
||||
LOCAL_INCLUDE := \
|
||||
-I $(LITEOSTOPDIR)/kernel/base/include \
|
||||
-I $(LITEOSTOPDIR)/kernel/extended/include \
|
||||
-I $(LITEOSTOPDIR)/kernel/extended/dynload/include \
|
||||
-I $(LITEOSTOPDIR)/arch/arm/arm/include \
|
||||
|
||||
ifeq ($(LOSCFG_ARCH_ARM_VER), "armv7-a")
|
||||
LOCAL_SRCS += $(wildcard src/armv7a/*.S)
|
||||
@@ -48,7 +43,11 @@ else
|
||||
LOCAL_SRCS += src/startup/reset_vector_up.S
|
||||
endif
|
||||
|
||||
LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS)
|
||||
ifeq ($(LOSCFG_PERF_HW_PMU), y)
|
||||
LOCAL_SRCS += src/pmu/armv7_pmu.c
|
||||
endif
|
||||
|
||||
LOCAL_FLAGS := $(LOCAL_INCLUDE)
|
||||
|
||||
AS_OBJS_LIBC_FLAGS = -D__ASSEMBLY__
|
||||
# linux style macros
|
||||
|
||||
@@ -71,5 +71,5 @@ VADDR_T *OsGFirstTableGet(VOID);
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* __LOS_VM_PAGE_H__ */
|
||||
#endif /* __LOS_ARCH_MMU_H__ */
|
||||
|
||||
|
||||
108
arch/arm/arm/src/include/armv7_pmu_pri.h
Normal file
108
arch/arm/arm/src/include/armv7_pmu_pri.h
Normal file
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _ARMV7_PMU_PRI_H
|
||||
#define _ARMV7_PMU_PRI_H
|
||||
|
||||
#include "los_typedef.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* counters overflow flag status reg */
|
||||
#define ARMV7_FLAG_MASK 0xffffffff /* Mask for writable bits */
|
||||
#define ARMV7_OVERFLOWED_MASK ARMV7_FLAG_MASK /* Mask for pmu overflowed */
|
||||
|
||||
/* pmnc config reg */
|
||||
#define ARMV7_PMNC_E (1U << 0) /* Enable all counters */
|
||||
#define ARMV7_PMNC_P (1U << 1) /* Reset all counters */
|
||||
#define ARMV7_PMNC_C (1U << 2) /* Cycle counter reset */
|
||||
#define ARMV7_PMNC_D (1U << 3) /* CCNT counts every 64th cpu cycle */
|
||||
#define ARMV7_PMNC_X (1U << 4) /* Export to ETM */
|
||||
#define ARMV7_PMNC_DP (1U << 5) /* Disable CCNT if non-invasive debug */
|
||||
#define ARMV7_PMNC_MASK 0x3f /* Mask for writable bits */
|
||||
|
||||
/* pmxevtyper event selection reg */
|
||||
#define ARMV7_EVTYPE_MASK 0xc80000ff /* Mask for writable bits */
|
||||
|
||||
/* armv7 counters index */
|
||||
#define ARMV7_IDX_COUNTER0 1
|
||||
#define ARMV7_IDX_CYCLE_COUNTER 0
|
||||
#define ARMV7_IDX_MAX_COUNTER 9
|
||||
|
||||
#define ARMV7_MAX_COUNTERS 32
|
||||
#define ARMV7_IDX_COUNTER_LAST (ARMV7_IDX_CYCLE_COUNTER + ARMV7_MAX_COUNTERS - 1)
|
||||
#define ARMV7_COUNTER_MASK (ARMV7_MAX_COUNTERS - 1)
|
||||
|
||||
/* armv7 event counter index mapping */
|
||||
#define ARMV7_CNT2BIT(x) (1UL << (x))
|
||||
#define ARMV7_IDX2CNT(x) (((x) - ARMV7_IDX_COUNTER0) & ARMV7_COUNTER_MASK)
|
||||
|
||||
enum PmuEventType {
|
||||
ARMV7_PERF_HW_CYCLES = 0xFF, /* cycles */
|
||||
ARMV7_PERF_HW_INSTRUCTIONS = 0x08, /* instructions */
|
||||
ARMV7_PERF_HW_DCACHES = 0x04, /* dcache */
|
||||
ARMV7_PERF_HW_DCACHE_MISSES = 0x03, /* dcache-misses */
|
||||
ARMV7_PERF_HW_ICACHES = 0x14, /* icache */
|
||||
ARMV7_PERF_HW_ICACHE_MISSES = 0x01, /* icache-misses */
|
||||
ARMV7_PERF_HW_BRANCHES = 0x0C, /* software change of pc */
|
||||
ARMV7_PERF_HW_BRANCE_MISSES = 0x10, /* branch-misses */
|
||||
ARMV7_PERF_HW_PRED_BRANCH = 0x12, /* predictable branches */
|
||||
ARMV7_PERF_HW_NUM_CYC_IRQ = 0x50, /* number of cycles Irqs are interrupted */
|
||||
ARMV7_PERF_HW_EXC_TAKEN = 0x09, /* exception_taken */
|
||||
ARMV7_PERF_HW_DATA_READ = 0x06, /* data read */
|
||||
ARMV7_PERF_HW_DATA_WRITE = 0x07, /* data write */
|
||||
ARMV7_PERF_HW_STREX_PASSED = 0x80, /* strex passed */
|
||||
ARMV7_PERF_HW_STREX_FAILED = 0x81, /* strex failed */
|
||||
ARMV7_PERF_HW_LP_IN_TCM = 0x82, /* literal pool in TCM region */
|
||||
ARMV7_PERF_HW_DMB_STALL = 0x90, /* DMB stall */
|
||||
ARMV7_PERF_HW_ITCM_ACCESS = 0x91, /* ITCM access */
|
||||
ARMV7_PERF_HW_DTCM_ACCESS = 0x92, /* DTCM access */
|
||||
ARMV7_PERF_HW_DATA_EVICTION = 0x93, /* data eviction */
|
||||
ARMV7_PERF_HW_SCU = 0x94, /* SCU coherency operation */
|
||||
ARMV7_PERF_HW_INSCACHE_DEP_DW = 0x95, /* instruction cache dependent stall */
|
||||
ARMV7_PERF_HW_DATA_CACHE_DEP_STALL = 0x96, /* data cache dependent stall */
|
||||
ARMV7_PERF_HW_NOCACHE_NO_PER_DEP_STALL = 0x97, /* non-cacheable no peripheral dependent stall */
|
||||
ARMV7_PERF_HW_NOCACHE_PER_DEP_STALL = 0x98, /* non-Cacheable peripheral dependent stall */
|
||||
ARMV7_PERF_HW_DATA_CACHE_HP_DEP_STALL = 0x99, /* data cache high priority dependent stall */
|
||||
ARMV7_PERF_HW_AXI_FAST_PERIPHERAL = 0x9A, /* Accesses_to_AXI_fast_peripheral_port(reads_and_writes) */
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _ARMV7_PMU_PRI_H */
|
||||
@@ -44,10 +44,24 @@ extern "C" {
|
||||
#define OS_SYSTEM_EXC_CURR_CPU 1
|
||||
#define OS_SYSTEM_EXC_OTHER_CPU 2
|
||||
|
||||
#define REGION_PATH_MAX 32
|
||||
|
||||
typedef struct {
|
||||
#ifdef LOSCFG_KERNEL_VM
|
||||
UINTPTR ip;
|
||||
UINT32 len; /* f_path length */
|
||||
CHAR f_path[REGION_PATH_MAX];
|
||||
#else
|
||||
UINTPTR ip;
|
||||
#endif
|
||||
} IpInfo;
|
||||
|
||||
extern UINT32 OsGetSystemStatus(VOID);
|
||||
extern VOID BackTraceSub(UINTPTR regFP);
|
||||
extern VOID OsExcInit(VOID);
|
||||
extern BOOL OsSystemExcIsReset(VOID);
|
||||
extern UINT32 BackTraceGet(UINTPTR regFP, IpInfo *callChain, UINT32 maxDepth);
|
||||
extern BOOL OsGetUsrIpInfo(UINTPTR ip, IpInfo *info);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
|
||||
@@ -177,7 +177,7 @@ STATIC VOID OsTryUnmapL1PTE(const LosArchMmu *archMmu, vaddr_t vaddr, UINT32 sca
|
||||
/*
|
||||
* Check if all pages related to this l1 entry are deallocated.
|
||||
* We only need to check pages that we did not clear above starting
|
||||
* from page_idx and wrapped around SECTION.
|
||||
* from scanIndex and wrapped around SECTION.
|
||||
*/
|
||||
UINT32 l1Index;
|
||||
PTE_T l1Entry;
|
||||
@@ -618,7 +618,7 @@ STATIC UINT32 OsCvtPte2FlagsToAttrs(UINT32 flags)
|
||||
return mmuFlags;
|
||||
}
|
||||
|
||||
STATIC UINT32 OsMapL2PageContinous(PTE_T pte1, UINT32 flags, VADDR_T *vaddr, PADDR_T *paddr, UINT32 *count)
|
||||
STATIC UINT32 OsMapL2PageContinuous(PTE_T pte1, UINT32 flags, VADDR_T *vaddr, PADDR_T *paddr, UINT32 *count)
|
||||
{
|
||||
PTE_T *pte2BasePtr = NULL;
|
||||
UINT32 archFlags;
|
||||
@@ -662,9 +662,9 @@ status_t LOS_ArchMmuMap(LosArchMmu *archMmu, VADDR_T vaddr, PADDR_T paddr, size_
|
||||
l1Entry = OsGetPte1(archMmu->virtTtb, vaddr);
|
||||
if (OsIsPte1Invalid(l1Entry)) {
|
||||
OsMapL1PTE(archMmu, &l1Entry, vaddr, flags);
|
||||
saveCounts = OsMapL2PageContinous(l1Entry, flags, &vaddr, &paddr, &count);
|
||||
saveCounts = OsMapL2PageContinuous(l1Entry, flags, &vaddr, &paddr, &count);
|
||||
} else if (OsIsPte1PageTable(l1Entry)) {
|
||||
saveCounts = OsMapL2PageContinous(l1Entry, flags, &vaddr, &paddr, &count);
|
||||
saveCounts = OsMapL2PageContinuous(l1Entry, flags, &vaddr, &paddr, &count);
|
||||
} else {
|
||||
LOS_Panic("%s %d, unimplemented tt_entry %x\n", __FUNCTION__, __LINE__, l1Entry);
|
||||
}
|
||||
@@ -716,7 +716,7 @@ STATUS_T LOS_ArchMmuMove(LosArchMmu *archMmu, VADDR_T oldVaddr, VADDR_T newVaddr
|
||||
PADDR_T paddr = 0;
|
||||
|
||||
if ((archMmu == NULL) || (oldVaddr == 0) || (newVaddr == 0) || (count == 0)) {
|
||||
VM_ERR("invalid args: archMmu %p, oldVaddr %p, newVddr %p, count %d",
|
||||
VM_ERR("invalid args: archMmu %p, oldVaddr %p, newVaddr %p, count %d",
|
||||
archMmu, oldVaddr, newVaddr, count);
|
||||
return LOS_NOK;
|
||||
}
|
||||
@@ -790,7 +790,7 @@ STATUS_T LOS_ArchMmuDestroy(LosArchMmu *archMmu)
|
||||
LOS_PhysPageFree(page);
|
||||
}
|
||||
|
||||
OsArmWriteTlbiasid(archMmu->asid);
|
||||
OsArmWriteTlbiasidis(archMmu->asid);
|
||||
OsFreeAsid(archMmu->asid);
|
||||
#endif
|
||||
(VOID)LOS_MuxDestroy(&archMmu->mtx);
|
||||
|
||||
@@ -147,6 +147,14 @@ OsIrqHandler:
|
||||
/* disable irq, switch to svc mode */
|
||||
CPSID i, #0x13
|
||||
|
||||
#ifdef LOSCFG_KERNEL_PERF
|
||||
PUSH {R0-R3, R12, LR}
|
||||
MOV R0, LR
|
||||
MOV R1, FP
|
||||
BL OsPerfSetIrqRegs
|
||||
POP {R0-R3, R12, LR}
|
||||
#endif
|
||||
|
||||
STMFD SP!, {R0-R3, R12, LR}
|
||||
STMFD SP, {R13, R14}^
|
||||
SUB SP, SP, #(4 * 4)
|
||||
|
||||
@@ -228,7 +228,8 @@ UINT32 OsArmSharedPageFault(UINT32 excType, ExcContext *frame, UINT32 far, UINT3
|
||||
break;
|
||||
}
|
||||
default:
|
||||
ret = LOS_ERRNO_VM_NOT_FOUND;
|
||||
OsArmWriteTlbimvaais(ROUNDDOWN(far, PAGE_SIZE));
|
||||
ret = LOS_OK;
|
||||
break;
|
||||
}
|
||||
#if defined(LOSCFG_KERNEL_SMP) && defined(LOSCFG_DEBUG_VERSION)
|
||||
@@ -244,7 +245,7 @@ UINT32 OsArmSharedPageFault(UINT32 excType, ExcContext *frame, UINT32 far, UINT3
|
||||
|
||||
STATIC VOID OsExcType(UINT32 excType, ExcContext *excBufAddr, UINT32 far, UINT32 fsr)
|
||||
{
|
||||
/* undefinited exception handling or software interrupt */
|
||||
/* undefined exception handling or software interrupt */
|
||||
if ((excType == OS_EXCEPT_UNDEF_INSTR) || (excType == OS_EXCEPT_SWI)) {
|
||||
if ((excBufAddr->regCPSR & INSTR_SET_MASK) == 0) { /* work status: ARM */
|
||||
excBufAddr->PC = excBufAddr->PC - ARM_INSTR_LEN;
|
||||
@@ -276,8 +277,8 @@ STATIC const CHAR *g_excTypeString[] = {
|
||||
#ifdef LOSCFG_KERNEL_VM
|
||||
STATIC VADDR_T OsGetTextRegionBase(LosVmMapRegion *region, LosProcessCB *runProcess)
|
||||
{
|
||||
struct file *curFilep = NULL;
|
||||
struct file *lastFilep = NULL;
|
||||
struct Vnode *curVnode = NULL;
|
||||
struct Vnode *lastVnode = NULL;
|
||||
LosVmMapRegion *curRegion = NULL;
|
||||
LosVmMapRegion *lastRegion = NULL;
|
||||
|
||||
@@ -296,9 +297,9 @@ STATIC VADDR_T OsGetTextRegionBase(LosVmMapRegion *region, LosProcessCB *runProc
|
||||
if ((lastRegion == NULL) || !LOS_IsRegionFileValid(lastRegion)) {
|
||||
goto DONE;
|
||||
}
|
||||
curFilep = curRegion->unTypeData.rf.file;
|
||||
lastFilep = lastRegion->unTypeData.rf.file;
|
||||
} while (!strcmp(curFilep->f_path, lastFilep->f_path));
|
||||
curVnode = curRegion->unTypeData.rf.vnode;
|
||||
lastVnode = lastRegion->unTypeData.rf.vnode;
|
||||
} while (curVnode == lastVnode);
|
||||
|
||||
DONE:
|
||||
#ifdef LOSCFG_KERNEL_DYNLOAD
|
||||
@@ -479,7 +480,7 @@ STATIC VOID OsDumpProcessUsedMemRegion(LosProcessCB *runProcess, LosVmSpace *run
|
||||
RB_SCAN_SAFE_END(&space->regionRbTree, pstRbNodeTemp, pstRbNodeNext)
|
||||
}
|
||||
|
||||
STATIC VOID OsDumpProcessUsedMemNode(UINT16 vmmFalgs)
|
||||
STATIC VOID OsDumpProcessUsedMemNode(UINT16 vmmFlags)
|
||||
{
|
||||
LosProcessCB *runProcess = NULL;
|
||||
LosVmSpace *runspace = NULL;
|
||||
@@ -500,7 +501,7 @@ STATIC VOID OsDumpProcessUsedMemNode(UINT16 vmmFalgs)
|
||||
return;
|
||||
}
|
||||
|
||||
OsDumpProcessUsedMemRegion(runProcess, runspace, vmmFalgs);
|
||||
OsDumpProcessUsedMemRegion(runProcess, runspace, vmmFlags);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
@@ -563,7 +564,6 @@ STATIC VOID OsUserExcHandle(ExcContext *excBufAddr)
|
||||
#else
|
||||
g_currHandleExcCpuID = INVALID_CPUID;
|
||||
#endif
|
||||
runProcess->processStatus &= ~OS_PROCESS_FLAG_EXIT;
|
||||
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
#ifdef LOSCFG_FS_VFS
|
||||
@@ -580,10 +580,10 @@ STATIC VOID OsUserExcHandle(ExcContext *excBufAddr)
|
||||
#endif
|
||||
OsProcessExitCodeSignalSet(runProcess, SIGUSR2);
|
||||
|
||||
/* An exception was raised by a task that is not the current main thread during the exit process of
|
||||
/* An exception was raised by a task during the exit process of
|
||||
* the current process.
|
||||
*/
|
||||
if ((runProcess->processStatus & OS_PROCESS_FLAG_EXIT) && (runProcess->threadGroupID != runTask->taskID)) {
|
||||
if (runProcess->processStatus & OS_PROCESS_FLAG_EXIT) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
/* Exception handling All operations should be kept prior to that operation */
|
||||
OsExcRestore();
|
||||
@@ -690,20 +690,66 @@ FOUND:
|
||||
return found;
|
||||
}
|
||||
|
||||
VOID BackTraceSub(UINTPTR regFP)
|
||||
BOOL OsGetUsrIpInfo(UINTPTR ip, IpInfo *info)
|
||||
{
|
||||
if (info == NULL) {
|
||||
return FALSE;
|
||||
}
|
||||
#ifdef LOSCFG_KERNEL_VM
|
||||
BOOL ret = FALSE;
|
||||
const CHAR *name = NULL;
|
||||
LosVmMapRegion *region = NULL;
|
||||
LosProcessCB *runProcess = OsCurrProcessGet();
|
||||
|
||||
if (LOS_IsUserAddress((VADDR_T)ip) == FALSE) {
|
||||
info->ip = ip;
|
||||
name = "kernel";
|
||||
ret = FALSE;
|
||||
goto END;
|
||||
}
|
||||
|
||||
region = LOS_RegionFind(runProcess->vmSpace, (VADDR_T)ip);
|
||||
if (region == NULL) {
|
||||
info->ip = ip;
|
||||
name = "invalid";
|
||||
ret = FALSE;
|
||||
goto END;
|
||||
}
|
||||
|
||||
info->ip = ip - OsGetTextRegionBase(region, runProcess);
|
||||
name = OsGetRegionNameOrFilePath(region);
|
||||
ret = TRUE;
|
||||
if (strcmp(name, "/lib/libc.so") != 0) {
|
||||
PRINT_ERR("ip = 0x%x, %s\n", info->ip, name);
|
||||
}
|
||||
END:
|
||||
info->len = strlen(name);
|
||||
if (strncpy_s(info->f_path, REGION_PATH_MAX, name, REGION_PATH_MAX - 1) != EOK) {
|
||||
info->f_path[0] = '\0';
|
||||
info->len = 0;
|
||||
PRINT_ERR("copy f_path failed, %s\n", name);
|
||||
}
|
||||
return ret;
|
||||
#else
|
||||
info->ip = ip;
|
||||
return FALSE;
|
||||
#endif
|
||||
}
|
||||
|
||||
UINT32 BackTraceGet(UINTPTR regFP, IpInfo *callChain, UINT32 maxDepth)
|
||||
{
|
||||
UINTPTR tmpFP, backLR;
|
||||
UINTPTR stackStart, stackEnd;
|
||||
UINTPTR backFP = regFP;
|
||||
UINT32 count = 0;
|
||||
BOOL ret;
|
||||
VADDR_T kvaddr;
|
||||
#ifdef LOSCFG_KERNEL_VM
|
||||
LosProcessCB *runProcess = OsCurrProcessGet();
|
||||
#endif
|
||||
|
||||
if (FindSuitableStack(regFP, &stackStart, &stackEnd, &kvaddr) == FALSE) {
|
||||
PrintExcInfo("traceback error fp = 0x%x\n", regFP);
|
||||
return;
|
||||
if (callChain == NULL) {
|
||||
PrintExcInfo("traceback error fp = 0x%x\n", regFP);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -715,7 +761,9 @@ VOID BackTraceSub(UINTPTR regFP)
|
||||
tmpFP = *(UINTPTR *)(UINTPTR)kvaddr;
|
||||
if (IsValidFP(tmpFP, stackStart, stackEnd, NULL) == TRUE) {
|
||||
backFP = tmpFP;
|
||||
PrintExcInfo("traceback fp fixed, trace using fp = 0x%x\n", backFP);
|
||||
if (callChain == NULL) {
|
||||
PrintExcInfo("traceback fp fixed, trace using fp = 0x%x\n", backFP);
|
||||
}
|
||||
}
|
||||
|
||||
while (IsValidFP(backFP, stackStart, stackEnd, &kvaddr) == TRUE) {
|
||||
@@ -723,38 +771,49 @@ VOID BackTraceSub(UINTPTR regFP)
|
||||
#ifdef LOSCFG_COMPILER_CLANG_LLVM
|
||||
backFP = *(UINTPTR *)(UINTPTR)kvaddr;
|
||||
if (IsValidFP(tmpFP + POINTER_SIZE, stackStart, stackEnd, &kvaddr) == FALSE) {
|
||||
PrintExcInfo("traceback backLR check failed, backLP: 0x%x\n", tmpFP + POINTER_SIZE);
|
||||
return;
|
||||
if (callChain == NULL) {
|
||||
PrintExcInfo("traceback backLR check failed, backLP: 0x%x\n", tmpFP + POINTER_SIZE);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
backLR = *(UINTPTR *)(UINTPTR)kvaddr;
|
||||
#else
|
||||
backLR = *(UINTPTR *)(UINTPTR)kvaddr;
|
||||
if (IsValidFP(tmpFP - POINTER_SIZE, stackStart, stackEnd, &kvaddr) == FALSE) {
|
||||
PrintExcInfo("traceback backFP check failed, backFP: 0x%x\n", tmpFP - POINTER_SIZE);
|
||||
return;
|
||||
if (callChain == NULL) {
|
||||
PrintExcInfo("traceback backFP check failed, backFP: 0x%x\n", tmpFP - POINTER_SIZE);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
backFP = *(UINTPTR *)(UINTPTR)kvaddr;
|
||||
#endif
|
||||
IpInfo info = {0};
|
||||
ret = OsGetUsrIpInfo((VADDR_T)backLR, &info);
|
||||
if (callChain == NULL) {
|
||||
PrintExcInfo("traceback %u -- lr = 0x%x fp = 0x%x ", count, backLR, backFP);
|
||||
if (ret) {
|
||||
#ifdef LOSCFG_KERNEL_VM
|
||||
LosVmMapRegion *region = NULL;
|
||||
if (LOS_IsUserAddress((VADDR_T)backLR) == TRUE) {
|
||||
region = LOS_RegionFind(runProcess->vmSpace, (VADDR_T)backLR);
|
||||
}
|
||||
if (region != NULL) {
|
||||
PrintExcInfo("traceback %u -- lr = 0x%x fp = 0x%x lr in %s --> 0x%x\n", count, backLR, backFP,
|
||||
OsGetRegionNameOrFilePath(region),
|
||||
backLR - OsGetTextRegionBase(region, runProcess));
|
||||
region = NULL;
|
||||
} else
|
||||
PrintExcInfo("lr in %s --> 0x%x\n", info.f_path, info.ip);
|
||||
#else
|
||||
PrintExcInfo("\n");
|
||||
#endif
|
||||
{
|
||||
PrintExcInfo("traceback %u -- lr = 0x%x fp = 0x%x\n", count, backLR, backFP);
|
||||
} else {
|
||||
PrintExcInfo("\n");
|
||||
}
|
||||
} else {
|
||||
(VOID)memcpy_s(&callChain[count], sizeof(IpInfo), &info, sizeof(IpInfo));
|
||||
}
|
||||
count++;
|
||||
if ((count == OS_MAX_BACKTRACE) || (backFP == tmpFP)) {
|
||||
if ((count == maxDepth) || (backFP == tmpFP)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
VOID BackTraceSub(UINTPTR regFP)
|
||||
{
|
||||
(VOID)BackTraceGet(regFP, NULL, OS_MAX_BACKTRACE);
|
||||
}
|
||||
|
||||
VOID BackTrace(UINT32 regFP)
|
||||
@@ -989,15 +1048,17 @@ STATIC VOID OsCheckAllCpuStatus(VOID)
|
||||
LOCKDEP_CLEAR_LOCKS();
|
||||
|
||||
LOS_SpinLock(&g_excSerializerSpin);
|
||||
/* Only the current nuclear anomaly */
|
||||
/* Only the current CPU anomaly */
|
||||
if (g_currHandleExcCpuID == INVALID_CPUID) {
|
||||
g_currHandleExcCpuID = currCpuID;
|
||||
g_currHandleExcPID = OsCurrProcessGet()->processID;
|
||||
LOS_SpinUnlock(&g_excSerializerSpin);
|
||||
#ifndef LOSCFG_SAVE_EXCINFO
|
||||
if (g_excFromUserMode[currCpuID] == FALSE) {
|
||||
target = (UINT32)(OS_MP_CPU_ALL & ~CPUID_TO_AFFI_MASK(currCpuID));
|
||||
HalIrqSendIpi(target, LOS_MP_IPI_HALT);
|
||||
}
|
||||
#endif
|
||||
} else if (g_excFromUserMode[currCpuID] == TRUE) {
|
||||
/* Both cores raise exceptions, and the current core is a user-mode exception.
|
||||
* Both cores are abnormal and come from the same process
|
||||
@@ -1022,11 +1083,12 @@ STATIC VOID OsCheckAllCpuStatus(VOID)
|
||||
while (1) {}
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef LOSCFG_SAVE_EXCINFO
|
||||
/* use halt ipi to stop other active cores */
|
||||
if (g_excFromUserMode[ArchCurrCpuid()] == FALSE) {
|
||||
WaitAllCpuStop(currCpuID);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1176,10 +1238,10 @@ __attribute__((noinline)) VOID LOS_Panic(const CHAR *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
UartVprintf(fmt, ap);
|
||||
OsVprintf(fmt, ap, EXC_OUTPUT);
|
||||
va_end(ap);
|
||||
__asm__ __volatile__("swi 0");
|
||||
while (1);
|
||||
while (1) {}
|
||||
}
|
||||
|
||||
/* stack protector */
|
||||
|
||||
373
arch/arm/arm/src/pmu/armv7_pmu.c
Normal file
373
arch/arm/arm/src/pmu/armv7_pmu.c
Normal file
@@ -0,0 +1,373 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "armv7_pmu_pri.h"
|
||||
#include "perf_pmu_pri.h"
|
||||
#include "los_hw_cpu.h"
|
||||
#include "asm/platform.h"
|
||||
|
||||
OS_PMU_INTS(LOSCFG_KERNEL_CORE_NUM, g_pmuIrqNr);
|
||||
STATIC HwPmu g_armv7Pmu;
|
||||
|
||||
STATIC INLINE UINT32 Armv7PmncRead(VOID)
|
||||
{
|
||||
UINT32 value = 0;
|
||||
__asm__ volatile("mrc p15, 0, %0, c9, c12, 0" : "=r"(value));
|
||||
return value;
|
||||
}
|
||||
|
||||
STATIC INLINE VOID Armv7PmncWrite(UINT32 value)
|
||||
{
|
||||
value &= ARMV7_PMNC_MASK;
|
||||
__asm__ volatile("mcr p15, 0, %0, c9, c12, 0" : : "r"(value));
|
||||
ISB;
|
||||
}
|
||||
|
||||
STATIC INLINE UINT32 Armv7PmuOverflowed(UINT32 pmnc)
|
||||
{
|
||||
return pmnc & ARMV7_OVERFLOWED_MASK;
|
||||
}
|
||||
|
||||
STATIC INLINE UINT32 Armv7PmuCntOverflowed(UINT32 pmnc, UINT32 index)
|
||||
{
|
||||
return pmnc & ARMV7_CNT2BIT(ARMV7_IDX2CNT(index));
|
||||
}
|
||||
|
||||
STATIC INLINE UINT32 Armv7CntValid(UINT32 index)
|
||||
{
|
||||
return index <= ARMV7_IDX_COUNTER_LAST;
|
||||
}
|
||||
|
||||
STATIC INLINE VOID Armv7PmuSelCnt(UINT32 index)
|
||||
{
|
||||
UINT32 counter = ARMV7_IDX2CNT(index);
|
||||
__asm__ volatile("mcr p15, 0, %0, c9, c12, 5" : : "r" (counter));
|
||||
ISB;
|
||||
}
|
||||
|
||||
STATIC INLINE VOID Armv7PmuSetCntPeriod(UINT32 index, UINT32 period)
|
||||
{
|
||||
if (!Armv7CntValid(index)) {
|
||||
PRINT_ERR("CPU writing wrong counter %u\n", index);
|
||||
} else if (index == ARMV7_IDX_CYCLE_COUNTER) {
|
||||
__asm__ volatile("mcr p15, 0, %0, c9, c13, 0" : : "r" (period));
|
||||
} else {
|
||||
Armv7PmuSelCnt(index);
|
||||
__asm__ volatile("mcr p15, 0, %0, c9, c13, 2" : : "r" (period));
|
||||
}
|
||||
}
|
||||
|
||||
STATIC INLINE VOID Armv7BindEvt2Cnt(UINT32 index, UINT32 value)
|
||||
{
|
||||
PRINT_DEBUG("bind event: %u to counter: %u\n", value, index);
|
||||
Armv7PmuSelCnt(index);
|
||||
value &= ARMV7_EVTYPE_MASK;
|
||||
__asm__ volatile("mcr p15, 0, %0, c9, c13, 1" : : "r" (value));
|
||||
}
|
||||
|
||||
STATIC INLINE VOID Armv7EnableCnt(UINT32 index)
|
||||
{
|
||||
UINT32 counter = ARMV7_IDX2CNT(index);
|
||||
PRINT_DEBUG("index : %u, counter: %u\n", index, counter);
|
||||
__asm__ volatile("mcr p15, 0, %0, c9, c12, 1" : : "r" (ARMV7_CNT2BIT(counter)));
|
||||
}
|
||||
|
||||
STATIC INLINE VOID Armv7DisableCnt(UINT32 index)
|
||||
{
|
||||
UINT32 counter = ARMV7_IDX2CNT(index);
|
||||
PRINT_DEBUG("index : %u, counter: %u\n", index, counter);
|
||||
__asm__ volatile("mcr p15, 0, %0, c9, c12, 2" : : "r" (ARMV7_CNT2BIT(counter)));
|
||||
}
|
||||
|
||||
STATIC INLINE VOID Armv7EnableCntInterrupt(UINT32 index)
|
||||
{
|
||||
UINT32 counter = ARMV7_IDX2CNT(index);
|
||||
__asm__ volatile("mcr p15, 0, %0, c9, c14, 1" : : "r" (ARMV7_CNT2BIT(counter)));
|
||||
ISB;
|
||||
}
|
||||
|
||||
STATIC INLINE VOID Armv7DisableCntInterrupt(UINT32 index)
|
||||
{
|
||||
UINT32 counter = ARMV7_IDX2CNT(index);
|
||||
__asm__ volatile("mcr p15, 0, %0, c9, c14, 2" : : "r" (ARMV7_CNT2BIT(counter)));
|
||||
/* Clear the overflow flag in case an interrupt is pending. */
|
||||
__asm__ volatile("mcr p15, 0, %0, c9, c12, 3" : : "r" (ARMV7_CNT2BIT(counter)));
|
||||
ISB;
|
||||
}
|
||||
|
||||
STATIC INLINE UINT32 Armv7PmuGetOverflowStatus(VOID)
|
||||
{
|
||||
UINT32 value;
|
||||
|
||||
__asm__ volatile("mrc p15, 0, %0, c9, c12, 3" : "=r" (value));
|
||||
value &= ARMV7_FLAG_MASK;
|
||||
__asm__ volatile("mcr p15, 0, %0, c9, c12, 3" : : "r" (value));
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
STATIC VOID Armv7EnableEvent(Event *event)
|
||||
{
|
||||
UINT32 cnt = event->counter;
|
||||
|
||||
if (!Armv7CntValid(cnt)) {
|
||||
PRINT_ERR("CPU enabling wrong PMNC counter IRQ enable %u\n", cnt);
|
||||
return;
|
||||
}
|
||||
|
||||
if (event->period == 0) {
|
||||
PRINT_INFO("event period value not valid, counter: %u\n", cnt);
|
||||
return;
|
||||
}
|
||||
/*
|
||||
* Enable counter and interrupt, and set the counter to count
|
||||
* the event that we're interested in.
|
||||
*/
|
||||
UINT32 intSave = LOS_IntLock();
|
||||
|
||||
Armv7DisableCnt(cnt);
|
||||
|
||||
/*
|
||||
* Set event (if destined for PMNx counters)
|
||||
* We only need to set the event for the cycle counter if we
|
||||
* have the ability to perform event filtering.
|
||||
*/
|
||||
if (cnt != ARMV7_IDX_CYCLE_COUNTER) {
|
||||
Armv7BindEvt2Cnt(cnt, event->eventId);
|
||||
}
|
||||
|
||||
/* Enable interrupt for this counter */
|
||||
Armv7EnableCntInterrupt(cnt);
|
||||
Armv7EnableCnt(cnt);
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
PRINT_DEBUG("enabled event: %u cnt: %u\n", event->eventId, cnt);
|
||||
}
|
||||
|
||||
STATIC VOID Armv7DisableEvent(Event *event)
|
||||
{
|
||||
UINT32 cnt = event->counter;
|
||||
|
||||
if (!Armv7CntValid(cnt)) {
|
||||
PRINT_ERR("CPU enabling wrong PMNC counter IRQ enable %u\n", cnt);
|
||||
return;
|
||||
}
|
||||
|
||||
UINT32 intSave = LOS_IntLock();
|
||||
Armv7DisableCnt(cnt);
|
||||
Armv7DisableCntInterrupt(cnt);
|
||||
LOS_IntRestore(intSave);
|
||||
}
|
||||
|
||||
|
||||
STATIC VOID Armv7StartAllCnt(VOID)
|
||||
{
|
||||
PRINT_DEBUG("starting pmu...\n");
|
||||
|
||||
/* Enable all counters */
|
||||
UINT32 reg = Armv7PmncRead() | ARMV7_PMNC_E;
|
||||
if (g_armv7Pmu.cntDivided) {
|
||||
reg |= ARMV7_PMNC_D;
|
||||
} else {
|
||||
reg &= ~ARMV7_PMNC_D;
|
||||
}
|
||||
|
||||
Armv7PmncWrite(reg);
|
||||
HalIrqUnmask(g_pmuIrqNr[ArchCurrCpuid()]);
|
||||
}
|
||||
|
||||
STATIC VOID Armv7StopAllCnt(VOID)
|
||||
{
|
||||
PRINT_DEBUG("stopping pmu...\n");
|
||||
/* Disable all counters */
|
||||
Armv7PmncWrite(Armv7PmncRead() & ~ARMV7_PMNC_E);
|
||||
|
||||
HalIrqMask(g_pmuIrqNr[ArchCurrCpuid()]);
|
||||
}
|
||||
|
||||
STATIC VOID Armv7ResetAllCnt(VOID)
|
||||
{
|
||||
UINT32 index;
|
||||
|
||||
/* The counter and interrupt enable registers are unknown at reset. */
|
||||
for (index = ARMV7_IDX_CYCLE_COUNTER; index < ARMV7_IDX_MAX_COUNTER; index++) {
|
||||
Armv7DisableCnt(index);
|
||||
Armv7DisableCntInterrupt(index);
|
||||
}
|
||||
|
||||
/* Initialize & Reset PMNC: C and P bits and D bits */
|
||||
UINT32 reg = ARMV7_PMNC_P | ARMV7_PMNC_C | (g_armv7Pmu.cntDivided ? ARMV7_PMNC_D : 0);
|
||||
Armv7PmncWrite(reg);
|
||||
}
|
||||
|
||||
STATIC VOID Armv7SetEventPeriod(Event *event)
|
||||
{
|
||||
if (event->period != 0) {
|
||||
PRINT_INFO("counter: %u, period: 0x%x\n", event->counter, event->period);
|
||||
Armv7PmuSetCntPeriod(event->counter, PERIOD_CALC(event->period));
|
||||
}
|
||||
}
|
||||
|
||||
STATIC UINTPTR Armv7ReadEventCnt(Event *event)
|
||||
{
|
||||
UINT32 value = 0;
|
||||
UINT32 index = event->counter;
|
||||
|
||||
if (!Armv7CntValid(index)) {
|
||||
PRINT_ERR("CPU reading wrong counter %u\n", index);
|
||||
} else if (index == ARMV7_IDX_CYCLE_COUNTER) {
|
||||
__asm__ volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (value));
|
||||
} else {
|
||||
Armv7PmuSelCnt(index);
|
||||
__asm__ volatile("mrc p15, 0, %0, c9, c13, 2" : "=r" (value));
|
||||
}
|
||||
|
||||
if (value < PERIOD_CALC(event->period)) {
|
||||
if (Armv7PmuCntOverflowed(Armv7PmuGetOverflowStatus(), event->counter)) {
|
||||
value += event->period;
|
||||
}
|
||||
} else {
|
||||
value -= PERIOD_CALC(event->period);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
STATIC const UINT32 g_armv7Map[] = {
|
||||
[PERF_COUNT_HW_CPU_CYCLES] = ARMV7_PERF_HW_CYCLES,
|
||||
[PERF_COUNT_HW_INSTRUCTIONS] = ARMV7_PERF_HW_INSTRUCTIONS,
|
||||
[PERF_COUNT_HW_DCACHE_REFERENCES] = ARMV7_PERF_HW_DCACHES,
|
||||
[PERF_COUNT_HW_DCACHE_MISSES] = ARMV7_PERF_HW_DCACHE_MISSES,
|
||||
[PERF_COUNT_HW_ICACHE_REFERENCES] = ARMV7_PERF_HW_ICACHES,
|
||||
[PERF_COUNT_HW_ICACHE_MISSES] = ARMV7_PERF_HW_ICACHE_MISSES,
|
||||
[PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = ARMV7_PERF_HW_BRANCHES,
|
||||
[PERF_COUNT_HW_BRANCH_MISSES] = ARMV7_PERF_HW_BRANCE_MISSES,
|
||||
};
|
||||
|
||||
UINT32 Armv7PmuMapEvent(UINT32 eventType, BOOL reverse)
|
||||
{
|
||||
if (!reverse) { /* Common event to armv7 real event */
|
||||
if (eventType < ARRAY_SIZE(g_armv7Map)) {
|
||||
return g_armv7Map[eventType];
|
||||
}
|
||||
return eventType;
|
||||
} else { /* Armv7 real event to common event */
|
||||
UINT32 i;
|
||||
for (i = 0; i < ARRAY_SIZE(g_armv7Map); i++) {
|
||||
if (g_armv7Map[i] == eventType) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return PERF_HW_INVALID_EVENT_TYPE;
|
||||
}
|
||||
}
|
||||
|
||||
STATIC VOID Armv7PmuIrqHandler(VOID)
|
||||
{
|
||||
UINT32 index;
|
||||
PerfRegs regs;
|
||||
|
||||
PerfEvent *events = &(g_armv7Pmu.pmu.events);
|
||||
UINT32 eventNum = events->nr;
|
||||
|
||||
/* Get and reset the IRQ flags */
|
||||
UINT32 pmnc = Armv7PmuGetOverflowStatus();
|
||||
if (!Armv7PmuOverflowed(pmnc)) {
|
||||
return;
|
||||
}
|
||||
|
||||
(VOID)memset_s(®s, sizeof(PerfRegs), 0, sizeof(PerfRegs));
|
||||
OsPerfFetchIrqRegs(®s);
|
||||
|
||||
Armv7StopAllCnt();
|
||||
|
||||
for (index = 0; index < eventNum; index++) {
|
||||
Event *event = &(events->per[index]);
|
||||
/*
|
||||
* We have a single interrupt for all counters. Check that
|
||||
* each counter has overflowed before we process it.
|
||||
*/
|
||||
if (!Armv7PmuCntOverflowed(pmnc, event->counter) || (event->period == 0)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Armv7PmuSetCntPeriod(event->counter, PERIOD_CALC(event->period));
|
||||
|
||||
OsPerfUpdateEventCount(event, event->period);
|
||||
OsPerfHandleOverFlow(event, ®s);
|
||||
}
|
||||
Armv7StartAllCnt();
|
||||
}
|
||||
|
||||
UINT32 OsGetPmuMaxCounter(VOID)
|
||||
{
|
||||
return ARMV7_IDX_MAX_COUNTER;
|
||||
}
|
||||
|
||||
UINT32 OsGetPmuCycleCounter(VOID)
|
||||
{
|
||||
return ARMV7_IDX_CYCLE_COUNTER;
|
||||
}
|
||||
|
||||
UINT32 OsGetPmuCounter0(VOID)
|
||||
{
|
||||
return ARMV7_IDX_COUNTER0;
|
||||
}
|
||||
|
||||
STATIC HwPmu g_armv7Pmu = {
|
||||
.canDivided = TRUE,
|
||||
.enable = Armv7EnableEvent,
|
||||
.disable = Armv7DisableEvent,
|
||||
.start = Armv7StartAllCnt,
|
||||
.stop = Armv7StopAllCnt,
|
||||
.clear = Armv7ResetAllCnt,
|
||||
.setPeriod = Armv7SetEventPeriod,
|
||||
.readCnt = Armv7ReadEventCnt,
|
||||
.mapEvent = Armv7PmuMapEvent,
|
||||
};
|
||||
|
||||
UINT32 OsHwPmuInit(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
UINT32 index;
|
||||
|
||||
for (index = 0; index < LOSCFG_KERNEL_CORE_NUM; index++) {
|
||||
ret = LOS_HwiCreate(g_pmuIrqNr[index], 0, 0, Armv7PmuIrqHandler, 0);
|
||||
if (ret != LOS_OK) {
|
||||
PRINT_ERR("pmu %u irq handler register failed\n", g_pmuIrqNr[index]);
|
||||
return ret;
|
||||
}
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
HalIrqSetAffinity(g_pmuIrqNr[index], CPUID_TO_AFFI_MASK(index));
|
||||
#endif
|
||||
}
|
||||
ret = OsPerfHwInit(&g_armv7Pmu);
|
||||
return ret;
|
||||
}
|
||||
@@ -35,7 +35,6 @@
|
||||
#include "los_hw.h"
|
||||
#include "los_atomic.h"
|
||||
#include "los_arch_mmu.h"
|
||||
#include "los_init_pri.h"
|
||||
#include "gic_common.h"
|
||||
#include "los_task_pri.h"
|
||||
|
||||
@@ -55,7 +54,7 @@ VOID HalArchCpuOn(UINT32 cpuNum, ArchCpuStartFunc func, struct SmpOps *ops, VOID
|
||||
{
|
||||
struct OsCpuInit *cpuInit = &g_cpuInit[cpuNum - 1];
|
||||
UINTPTR startEntry = (UINTPTR)&reset_vector - KERNEL_VMM_BASE + SYS_MEM_BASE;
|
||||
INT32 ret = 0;
|
||||
INT32 ret;
|
||||
|
||||
cpuInit->cpuStart = func;
|
||||
cpuInit->arg = arg;
|
||||
@@ -94,7 +93,6 @@ VOID HalSecondaryCpuStart(VOID)
|
||||
/* store each core's hwid */
|
||||
CPU_MAP_SET(cpuid, OsHwIDGet());
|
||||
HalIrqInitPercpu();
|
||||
OsInitCall(LOS_INIT_LEVEL_ARCH);
|
||||
|
||||
cpuInit->cpuStart(cpuInit->arg);
|
||||
|
||||
|
||||
@@ -31,18 +31,10 @@ include $(LITEOSTOPDIR)/config.mk
|
||||
|
||||
MODULE_NAME := $(notdir $(shell pwd))
|
||||
|
||||
# LOCAL_SRCS := $(wildcard *.c)
|
||||
|
||||
ifeq ($(LOSCFG_ARCH_GIC_V2), y)
|
||||
LOCAL_SRCS := gic_v2.c
|
||||
else ifeq ($(LOSCFG_ARCH_GIC_V3), y)
|
||||
LOCAL_SRCS := gic_v3.c
|
||||
endif
|
||||
|
||||
LOCAL_INCLUDE := \
|
||||
-I $(LITEOSTOPDIR)/kernel/base/include \
|
||||
-I $(LITEOSTOPDIR)/arch/arm/include \
|
||||
-I $(LITEOSTOPDIR)/arch/arm/arm/src/include \
|
||||
|
||||
LOCAL_FLAGS := $(LOCAL_INCLUDE)
|
||||
include $(MODULE)
|
||||
|
||||
@@ -149,6 +149,9 @@ VOID HalIrqInit(VOID)
|
||||
(VOID)LOS_HwiCreate(LOS_MP_IPI_WAKEUP, 0xa0, 0, OsMpWakeHandler, 0);
|
||||
(VOID)LOS_HwiCreate(LOS_MP_IPI_SCHEDULE, 0xa0, 0, OsMpScheduleHandler, 0);
|
||||
(VOID)LOS_HwiCreate(LOS_MP_IPI_HALT, 0xa0, 0, OsMpHaltHandler, 0);
|
||||
#ifdef LOSCFG_KERNEL_SMP_CALL
|
||||
(VOID)LOS_HwiCreate(LOS_MP_IPI_FUNC_CALL, 0xa0, 0, OsMpFuncCallHandler, 0);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -169,7 +172,7 @@ VOID HalIrqHandler(VOID)
|
||||
|
||||
OsInterrupt(vector);
|
||||
|
||||
/* use orignal iar to do the EOI */
|
||||
/* use original iar to do the EOI */
|
||||
GIC_REG_32(GICC_EOIR) = iar;
|
||||
}
|
||||
|
||||
|
||||
@@ -401,9 +401,12 @@ VOID HalIrqInit(VOID)
|
||||
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
/* register inter-processor interrupt */
|
||||
LOS_HwiCreate(LOS_MP_IPI_WAKEUP, 0xa0, 0, OsMpWakeHandler, 0);
|
||||
LOS_HwiCreate(LOS_MP_IPI_SCHEDULE, 0xa0, 0, OsMpScheduleHandler, 0);
|
||||
LOS_HwiCreate(LOS_MP_IPI_HALT, 0xa0, 0, OsMpScheduleHandler, 0);
|
||||
(VOID)LOS_HwiCreate(LOS_MP_IPI_WAKEUP, 0xa0, 0, OsMpWakeHandler, 0);
|
||||
(VOID)LOS_HwiCreate(LOS_MP_IPI_SCHEDULE, 0xa0, 0, OsMpScheduleHandler, 0);
|
||||
(VOID)LOS_HwiCreate(LOS_MP_IPI_HALT, 0xa0, 0, OsMpScheduleHandler, 0);
|
||||
#ifdef LOSCFG_KERNEL_SMP_CALL
|
||||
(VOID)LOS_HwiCreate(LOS_MP_IPI_FUNC_CALL, 0xa0, 0, OsMpFuncCallHandler, 0);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -1,65 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _SYS_CONFIG_H
|
||||
#define _SYS_CONFIG_H
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#ifndef LOSCFG_MACRO_CONFIG
|
||||
#define LOSCFG_MACRO_CONFIG
|
||||
|
||||
#ifdef LOSCFG_LIB_LIBC
|
||||
#define CONFIG_STRERROR
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_NET_LWIP_SACK
|
||||
#define LWIP_BSD_API 1
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_DRIVERS_USB
|
||||
#define SUPPORT_LOS_USB_NEW_DRIVER
|
||||
#define USB_DEBUG_VAR 5
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _SYS_CONFIG_H */
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _PERF_H
|
||||
#define _PERF_H
|
||||
|
||||
#include "los_typedef.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define OsPerfArchFetchCallerRegs(regs) \
|
||||
do { \
|
||||
(regs)->pc = (UINTPTR)__builtin_return_address(0); \
|
||||
(regs)->fp = (UINTPTR)__builtin_frame_address(0); \
|
||||
} while (0)
|
||||
|
||||
#define OsPerfArchFetchIrqRegs(regs, tcb) \
|
||||
do { \
|
||||
(regs)->pc = (tcb)->pc; \
|
||||
(regs)->fp = (tcb)->fp; \
|
||||
} while (0)
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _PERF_H */
|
||||
@@ -41,14 +41,6 @@ LOCAL_SRCS += $(wildcard crypto/rijndael/*.c) \
|
||||
$(wildcard crypto/sha2/*.c) \
|
||||
$(wildcard dev/random/*.c) \
|
||||
$(wildcard libkern/*.c)
|
||||
|
||||
endif
|
||||
|
||||
LOCAL_INCLUDE := \
|
||||
-I $(LITEOSTOPDIR)/kernel/base/include \
|
||||
-I $(LITEOSTOPDIR)/bsd \
|
||||
-I $(LITEOSTOPDIR)/bsd/kern \
|
||||
|
||||
LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS)
|
||||
|
||||
include $(MODULE)
|
||||
|
||||
@@ -37,10 +37,4 @@ ifneq ($(LOSCFG_HRTIMER_ENABLE), y)
|
||||
LOCAL_SRCS := $(filter-out src/linux_hrtimer.c, $(LOCAL_SRCS))
|
||||
endif
|
||||
|
||||
LOCAL_INCLUDE := \
|
||||
-I $(LITEOSTOPDIR)/kernel/base/include \
|
||||
-I $(LITEOSTOPDIR)/bsd/compat/linuxkpi/include
|
||||
|
||||
LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS)
|
||||
|
||||
include $(MODULE)
|
||||
|
||||
@@ -137,14 +137,13 @@ kernel_module(module_name) {
|
||||
]
|
||||
}
|
||||
|
||||
configs += [
|
||||
"$HDFTOPDIR:hdf_config"
|
||||
]
|
||||
configs += [ "$HDFTOPDIR:hdf_config" ]
|
||||
|
||||
public_configs = [ ":public" ]
|
||||
}
|
||||
|
||||
config("public") {
|
||||
defines = [ "USB_DEBUG_VAR=5" ]
|
||||
include_dirs = [ "." ]
|
||||
include_dirs += [ "$LITEOSTHIRDPARTY/FreeBSD/sys/dev/evdev" ]
|
||||
}
|
||||
|
||||
@@ -135,6 +135,4 @@ LOCAL_SRCS += $(INPUT_SRC)/uhid.c \
|
||||
$(CORE_SRC)/usb_hid.c
|
||||
endif
|
||||
|
||||
LOCAL_FLAGS += $(LITEOS_GCOV_OPTS)
|
||||
|
||||
include $(HDF_DRIVER)
|
||||
|
||||
@@ -33,10 +33,8 @@ MODULE_NAME := $(notdir $(shell pwd))
|
||||
|
||||
LOCAL_SRCS := $(wildcard src/*.c)
|
||||
|
||||
LOCAL_INCLUDE := \
|
||||
-I $(LITEOSTOPDIR)/compat/posix/src \
|
||||
-I $(LITEOSTOPDIR)/kernel/base/include \
|
||||
LOCAL_INCLUDE := -I $(LITEOSTOPDIR)/compat/posix/src
|
||||
|
||||
LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS)
|
||||
LOCAL_FLAGS := $(LOCAL_INCLUDE)
|
||||
|
||||
include $(MODULE)
|
||||
|
||||
@@ -86,6 +86,7 @@ STATIC INLINE VOID OsTick2TimeSpec(struct timespec *tp, UINT32 tick)
|
||||
}
|
||||
|
||||
int OsTimerCreate(clockid_t, struct ksigevent *__restrict, timer_t *__restrict);
|
||||
void OsAdjTime(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
#include "los_process_pri.h"
|
||||
#include "los_hw.h"
|
||||
|
||||
static struct rlimit g_defaultLimit = { 0 };
|
||||
/*
|
||||
* Supply some suitable values for constants that may not be present
|
||||
* in all configurations.
|
||||
@@ -154,7 +155,9 @@ pid_t getpid(void)
|
||||
|
||||
int getrlimit(int resource, struct rlimit *rlim)
|
||||
{
|
||||
unsigned int intSave;
|
||||
LosProcessCB *pcb = OsCurrProcessGet();
|
||||
struct rlimit *resourceLimit = pcb->resourceLimit;
|
||||
|
||||
switch (resource) {
|
||||
case RLIMIT_NOFILE:
|
||||
@@ -163,8 +166,15 @@ int getrlimit(int resource, struct rlimit *rlim)
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
rlim->rlim_cur = pcb->pl_rlimit[resource].rlim_cur;
|
||||
rlim->rlim_max = pcb->pl_rlimit[resource].rlim_max;
|
||||
|
||||
if (resourceLimit == NULL) {
|
||||
resourceLimit = &g_defaultLimit;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
rlim->rlim_cur = resourceLimit[resource].rlim_cur;
|
||||
rlim->rlim_max = resourceLimit[resource].rlim_max;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -175,6 +185,8 @@ int getrlimit(int resource, struct rlimit *rlim)
|
||||
#endif
|
||||
int setrlimit(int resource, const struct rlimit *rlim)
|
||||
{
|
||||
unsigned int intSave;
|
||||
struct rlimit *resourceLimit = NULL;
|
||||
LosProcessCB *pcb = OsCurrProcessGet();
|
||||
|
||||
if (rlim->rlim_cur > rlim->rlim_max) {
|
||||
@@ -194,8 +206,23 @@ int setrlimit(int resource, const struct rlimit *rlim)
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
pcb->pl_rlimit[resource].rlim_cur = rlim->rlim_cur;
|
||||
pcb->pl_rlimit[resource].rlim_max = rlim->rlim_max;
|
||||
|
||||
if (pcb->resourceLimit == NULL) {
|
||||
resourceLimit = LOS_MemAlloc((VOID *)m_aucSysMem0, RLIM_NLIMITS * sizeof(struct rlimit));
|
||||
if (resourceLimit == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if (pcb->resourceLimit == NULL) {
|
||||
pcb->resourceLimit = resourceLimit;
|
||||
resourceLimit = NULL;
|
||||
}
|
||||
pcb->resourceLimit[resource].rlim_cur = rlim->rlim_cur;
|
||||
pcb->resourceLimit[resource].rlim_max = rlim->rlim_max;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
||||
(VOID)LOS_MemFree((VOID *)m_aucSysMem0, resourceLimit);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -248,7 +248,7 @@ int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
|
||||
taskInitParam.uwResved = LOS_TASK_STATUS_DETACHED;
|
||||
} else {
|
||||
/* Set the pthread default joinable */
|
||||
taskInitParam.uwResved = 0;
|
||||
taskInitParam.uwResved = LOS_TASK_ATTR_JOINABLE;
|
||||
}
|
||||
|
||||
PthreadReap();
|
||||
|
||||
@@ -47,7 +47,7 @@ void srand(unsigned s)
|
||||
|
||||
int rand(void)
|
||||
{
|
||||
return random();
|
||||
return random();
|
||||
}
|
||||
|
||||
void _exit(int status)
|
||||
|
||||
@@ -509,7 +509,11 @@ static int ProcessGetCputime(clockid_t clockID, struct timespec *ats)
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
runtime = spcb->processCpup.allTime;
|
||||
if (spcb->processCpup == NULL) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return -EINVAL;
|
||||
}
|
||||
runtime = spcb->processCpup->allTime;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
||||
ats->tv_sec = runtime / OS_SYS_NS_PER_SECOND;
|
||||
@@ -756,7 +760,7 @@ static VOID SwtmrProc(UINTPTR tmrArg)
|
||||
}
|
||||
return;
|
||||
EXIT:
|
||||
PRINT_ERR("Dsipatch signals failed!, ret: %d\r\n", ret);
|
||||
PRINT_ERR("Dispatch signals failed!, ret: %d\r\n", ret);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
23
config.mk
23
config.mk
@@ -38,7 +38,7 @@ LITEOS_CXXOPTS := $(LITEOS_CXXOPTS_BASE)
|
||||
LITEOS_INCLUDE := $(LITEOS_KERNEL_INCLUDE) $(LITEOS_EXTKERNEL_INCLUDE) \
|
||||
$(LITEOS_COMPAT_INCLUDE) $(LITEOS_FS_INCLUDE) \
|
||||
$(LITEOS_NET_INCLUDE) $(LITEOS_LIB_INCLUDE) \
|
||||
$(LITEOS_DRIVERS_INCLUDE) $(LOSCFG_TOOLS_DEBUG_INCLUDE) \
|
||||
$(LITEOS_DRIVERS_INCLUDE) $(LITEOS_TOOLS_DEBUG_INCLUDE) \
|
||||
$(LITEOS_PLATFORM_INCLUDE) $(LITEOS_DFX_INCLUDE) \
|
||||
$(LITEOS_SECURITY_INCLUDE)
|
||||
LITEOS_LIBDEP := $(LITEOS_BASELIB)
|
||||
@@ -52,10 +52,17 @@ LITEOS_LDFLAGS := $(LITEOS_LD_OPTS) $(LITEOS_LD_PATH) \
|
||||
$(LITEOS_LD_SCRIPT)
|
||||
|
||||
# clear all local variables
|
||||
LOCAL_FLAGS :=
|
||||
LOCAL_CFLAGS :=
|
||||
LOCAL_CPPFLAGS :=
|
||||
LOCAL_ASFLAGS :=
|
||||
LOCAL_SRCS :=
|
||||
LOCAL_CHS :=
|
||||
LOCAL_CPPHS :=
|
||||
LOCAL_FLAGS =
|
||||
LOCAL_CFLAGS =
|
||||
LOCAL_CPPFLAGS =
|
||||
LOCAL_ASFLAGS =
|
||||
LOCAL_SRCS =
|
||||
LOCAL_CHS =
|
||||
LOCAL_CPPHS =
|
||||
|
||||
# basic build flags
|
||||
CFLAGS := $(LITEOS_CFLAGS)
|
||||
CXXFLAGS := $(LITEOS_CXXFLAGS)
|
||||
ASFLAGS := $(LITEOS_ASFLAGS)
|
||||
LDFLAGS := $(LITEOS_LDFLAGS)
|
||||
ARFLAGS := rc
|
||||
|
||||
@@ -29,28 +29,10 @@
|
||||
|
||||
import("//kernel/liteos_a/liteos.gni")
|
||||
|
||||
group("drivers") {
|
||||
deps = [
|
||||
"block/disk",
|
||||
"char/bch",
|
||||
"char/mem",
|
||||
"char/quickstart",
|
||||
"char/random",
|
||||
"char/trace",
|
||||
"char/video",
|
||||
"mtd/multi_partition",
|
||||
]
|
||||
}
|
||||
|
||||
config("public") {
|
||||
configs = [
|
||||
"block/disk:public",
|
||||
"char/bch:public",
|
||||
"char/mem:public",
|
||||
"char/quickstart:public",
|
||||
"char/random:public",
|
||||
"char/video:public",
|
||||
"char/trace:public",
|
||||
"mtd/multi_partition:public",
|
||||
module_group("drivers") {
|
||||
modules = [
|
||||
"block",
|
||||
"char",
|
||||
"mtd",
|
||||
]
|
||||
}
|
||||
|
||||
21
drivers/Kconfig
Normal file
21
drivers/Kconfig
Normal file
@@ -0,0 +1,21 @@
|
||||
config DRIVERS
|
||||
bool "Enable Driver"
|
||||
default y
|
||||
help
|
||||
Answer Y to enable LiteOS support driver.
|
||||
|
||||
source "bsd/dev/usb/Kconfig"
|
||||
source "../../drivers/adapter/khdf/liteos/Kconfig"
|
||||
|
||||
# Device driver Kconfig import
|
||||
source "$(DEVICE_PATH)/drivers/Kconfig"
|
||||
|
||||
source "drivers/char/mem/Kconfig"
|
||||
source "drivers/char/quickstart/Kconfig"
|
||||
source "drivers/char/random/Kconfig"
|
||||
source "drivers/char/video/Kconfig"
|
||||
source "drivers/char/trace/Kconfig"
|
||||
source "drivers/char/perf/Kconfig"
|
||||
|
||||
source "../../drivers/liteos/tzdriver/Kconfig"
|
||||
source "../../drivers/liteos/hievent/Kconfig"
|
||||
34
drivers/block/BUILD.gn
Normal file
34
drivers/block/BUILD.gn
Normal file
@@ -0,0 +1,34 @@
|
||||
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
# conditions and the following disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
# of conditions and the following disclaimer in the documentation and/or other materials
|
||||
# provided with the distribution.
|
||||
#
|
||||
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
# to endorse or promote products derived from this software without specific prior written
|
||||
# permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
import("//kernel/liteos_a/liteos.gni")
|
||||
|
||||
module_group("block") {
|
||||
modules = [ "disk" ]
|
||||
}
|
||||
@@ -33,8 +33,4 @@ MODULE_NAME := $(notdir $(shell pwd))
|
||||
|
||||
LOCAL_SRCS := $(wildcard src/*.c)
|
||||
|
||||
LOCAL_INCLUDE := \
|
||||
|
||||
LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS)
|
||||
|
||||
include $(MODULE)
|
||||
|
||||
@@ -165,6 +165,10 @@ extern "C" {
|
||||
#define DISK_ATA_GET_MODEL 21 /* Get model name */
|
||||
#define DISK_ATA_GET_SN 22 /* Get serial number */
|
||||
|
||||
#ifdef LOSCFG_FS_FAT_CACHE
|
||||
#define DISK_DIRECT_BUFFER_SIZE 4 /* los_disk direct io buffer when bcache is off */
|
||||
#endif
|
||||
|
||||
typedef enum _disk_status_ {
|
||||
STAT_UNUSED,
|
||||
STAT_INUSED,
|
||||
@@ -187,6 +191,9 @@ typedef struct _los_disk_ {
|
||||
CHAR *disk_name;
|
||||
LOS_DL_LIST head; /* link head of all the partitions */
|
||||
struct pthread_mutex disk_mutex;
|
||||
#ifndef LOSCFG_FS_FAT_CACHE
|
||||
UINT8 *buff;
|
||||
#endif
|
||||
} los_disk;
|
||||
|
||||
typedef struct _los_part_ {
|
||||
|
||||
@@ -36,6 +36,10 @@
|
||||
#include "sys/mount.h"
|
||||
#include "linux/spinlock.h"
|
||||
#include "path_cache.h"
|
||||
#ifndef LOSCFG_FS_FAT_CACHE
|
||||
#include "los_vm_common.h"
|
||||
#include "user_copy.h"
|
||||
#endif
|
||||
|
||||
los_disk g_sysDisk[SYS_MAX_DISK];
|
||||
los_part g_sysPart[SYS_MAX_PART];
|
||||
@@ -799,6 +803,78 @@ INT32 DiskPartitionRegister(los_disk *disk)
|
||||
return ENOERR;
|
||||
}
|
||||
|
||||
#ifndef LOSCFG_FS_FAT_CACHE
|
||||
static INT32 disk_read_directly(los_disk *disk, VOID *buf, UINT64 sector, UINT32 count)
|
||||
{
|
||||
INT32 result = VFS_ERROR;
|
||||
struct block_operations *bops = (struct block_operations *)((struct drv_data *)disk->dev->data)->ops;
|
||||
if ((bops == NULL) || (bops->read == NULL)) {
|
||||
return VFS_ERROR;
|
||||
}
|
||||
if (LOS_IsUserAddressRange((VADDR_T)buf, count * disk->sector_size)) {
|
||||
UINT32 cnt = 0;
|
||||
UINT8 *buffer = disk->buff;
|
||||
for (; count != 0; count -= cnt) {
|
||||
cnt = (count > DISK_DIRECT_BUFFER_SIZE) ? DISK_DIRECT_BUFFER_SIZE : count;
|
||||
result = bops->read(disk->dev, buffer, sector, cnt);
|
||||
if (result == (INT32)cnt) {
|
||||
result = ENOERR;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
if (LOS_CopyFromKernel(buf, disk->sector_size * cnt, buffer, disk->sector_size * cnt)) {
|
||||
result = VFS_ERROR;
|
||||
break;
|
||||
}
|
||||
buf = (UINT8 *)buf + disk->sector_size * cnt;
|
||||
sector += cnt;
|
||||
}
|
||||
} else {
|
||||
result = bops->read(disk->dev, buf, sector, count);
|
||||
if (result == count) {
|
||||
result = ENOERR;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static INT32 disk_write_directly(los_disk *disk, const VOID *buf, UINT64 sector, UINT32 count)
|
||||
{
|
||||
struct block_operations *bops = (struct block_operations *)((struct drv_data *)disk->dev->data)->ops;
|
||||
INT32 result = VFS_ERROR;
|
||||
if ((bops == NULL) || (bops->read == NULL)) {
|
||||
return VFS_ERROR;
|
||||
}
|
||||
if (LOS_IsUserAddressRange((VADDR_T)buf, count * disk->sector_size)) {
|
||||
UINT32 cnt = 0;
|
||||
UINT8 *buffer = disk->buff;
|
||||
for (; count != 0; count -= cnt) {
|
||||
cnt = (count > DISK_DIRECT_BUFFER_SIZE) ? DISK_DIRECT_BUFFER_SIZE : count;
|
||||
if (LOS_CopyToKernel(buffer, disk->sector_size * cnt, buf, disk->sector_size * cnt)) {
|
||||
result = VFS_ERROR;
|
||||
break;
|
||||
}
|
||||
result = bops->write(disk->dev, buffer, sector, cnt);
|
||||
if (result == (INT32)cnt) {
|
||||
result = ENOERR;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
buf = (UINT8 *)buf + disk->sector_size * cnt;
|
||||
sector += cnt;
|
||||
}
|
||||
} else {
|
||||
result = bops->write(disk->dev, buf, sector, count);
|
||||
if (result == count) {
|
||||
result = ENOERR;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
INT32 los_disk_read(INT32 drvID, VOID *buf, UINT64 sector, UINT32 count, BOOL useRead)
|
||||
{
|
||||
#ifdef LOSCFG_FS_FAT_CACHE
|
||||
@@ -837,21 +913,14 @@ INT32 los_disk_read(INT32 drvID, VOID *buf, UINT64 sector, UINT32 count, BOOL us
|
||||
PRINT_ERR("los_disk_read read err = %d, sector = %llu, len = %u\n", result, sector, len);
|
||||
}
|
||||
} else {
|
||||
#endif
|
||||
result = VFS_ERROR;
|
||||
}
|
||||
#else
|
||||
if (disk->dev == NULL) {
|
||||
goto ERROR_HANDLE;
|
||||
}
|
||||
struct block_operations *bops = (struct block_operations *)((struct drv_data *)disk->dev->data)->ops;
|
||||
if ((bops != NULL) && (bops->read != NULL)) {
|
||||
result = bops->read(disk->dev, (UINT8 *)buf, sector, count);
|
||||
if (result == (INT32)count) {
|
||||
result = ENOERR;
|
||||
}
|
||||
}
|
||||
#ifdef LOSCFG_FS_FAT_CACHE
|
||||
}
|
||||
result = disk_read_directly(disk, buf, sector, count);
|
||||
#endif
|
||||
|
||||
if (result != ENOERR) {
|
||||
goto ERROR_HANDLE;
|
||||
}
|
||||
@@ -900,18 +969,14 @@ INT32 los_disk_write(INT32 drvID, const VOID *buf, UINT64 sector, UINT32 count)
|
||||
PRINT_ERR("los_disk_write write err = %d, sector = %llu, len = %u\n", result, sector, len);
|
||||
}
|
||||
} else {
|
||||
#endif
|
||||
struct block_operations *bops = (struct block_operations *)((struct drv_data *)disk->dev->data)->ops;
|
||||
if ((bops != NULL) && (bops->write != NULL)) {
|
||||
result = bops->write(disk->dev, (UINT8 *)buf, sector, count);
|
||||
if (result == (INT32)count) {
|
||||
result = ENOERR;
|
||||
}
|
||||
result = VFS_ERROR;
|
||||
}
|
||||
#ifdef LOSCFG_FS_FAT_CACHE
|
||||
#else
|
||||
if (disk->dev == NULL) {
|
||||
goto ERROR_HANDLE;
|
||||
}
|
||||
result = disk_write_directly(disk, buf, sector, count);
|
||||
#endif
|
||||
|
||||
if (result != ENOERR) {
|
||||
goto ERROR_HANDLE;
|
||||
}
|
||||
@@ -998,7 +1063,7 @@ INT32 los_part_read(INT32 pt, VOID *buf, UINT64 sector, UINT32 count, BOOL useRe
|
||||
}
|
||||
|
||||
if (count > part->sector_count) {
|
||||
PRINT_ERR("los_part_read failed, invaild count, count = %u\n", count);
|
||||
PRINT_ERR("los_part_read failed, invalid count, count = %u\n", count);
|
||||
goto ERROR_HANDLE;
|
||||
}
|
||||
|
||||
@@ -1007,7 +1072,7 @@ INT32 los_part_read(INT32 pt, VOID *buf, UINT64 sector, UINT32 count, BOOL useRe
|
||||
if ((disk->sector_count - part->sector_start) > sector) {
|
||||
sector += part->sector_start;
|
||||
} else {
|
||||
PRINT_ERR("los_part_read failed, invaild sector, sector = %llu\n", sector);
|
||||
PRINT_ERR("los_part_read failed, invalid sector, sector = %llu\n", sector);
|
||||
goto ERROR_HANDLE;
|
||||
}
|
||||
}
|
||||
@@ -1054,7 +1119,7 @@ INT32 los_part_write(INT32 pt, const VOID *buf, UINT64 sector, UINT32 count)
|
||||
}
|
||||
|
||||
if (count > part->sector_count) {
|
||||
PRINT_ERR("los_part_write failed, invaild count, count = %u\n", count);
|
||||
PRINT_ERR("los_part_write failed, invalid count, count = %u\n", count);
|
||||
goto ERROR_HANDLE;
|
||||
}
|
||||
|
||||
@@ -1063,7 +1128,7 @@ INT32 los_part_write(INT32 pt, const VOID *buf, UINT64 sector, UINT32 count)
|
||||
if ((disk->sector_count - part->sector_start) > sector) {
|
||||
sector += part->sector_start;
|
||||
} else {
|
||||
PRINT_ERR("los_part_write failed, invaild sector, sector = %llu\n", sector);
|
||||
PRINT_ERR("los_part_write failed, invalid sector, sector = %llu\n", sector);
|
||||
goto ERROR_HANDLE;
|
||||
}
|
||||
}
|
||||
@@ -1153,7 +1218,8 @@ ERROR_HANDLE:
|
||||
|
||||
INT32 los_disk_cache_clear(INT32 drvID)
|
||||
{
|
||||
INT32 result;
|
||||
INT32 result = ENOERR;
|
||||
#ifdef LOSCFG_FS_FAT_CACHE
|
||||
los_part *part = get_part(drvID);
|
||||
los_disk *disk = NULL;
|
||||
|
||||
@@ -1161,7 +1227,7 @@ INT32 los_disk_cache_clear(INT32 drvID)
|
||||
return VFS_ERROR;
|
||||
}
|
||||
result = OsSdSync(part->disk_id);
|
||||
if (result != 0) {
|
||||
if (result != ENOERR) {
|
||||
PRINTK("[ERROR]disk_cache_clear SD sync failed!\n");
|
||||
return result;
|
||||
}
|
||||
@@ -1174,7 +1240,7 @@ INT32 los_disk_cache_clear(INT32 drvID)
|
||||
DISK_LOCK(&disk->disk_mutex);
|
||||
result = BcacheClearCache(disk->bcache);
|
||||
DISK_UNLOCK(&disk->disk_mutex);
|
||||
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1324,6 +1390,10 @@ static INT32 DiskDeinit(los_disk *disk)
|
||||
|
||||
#ifdef LOSCFG_FS_FAT_CACHE
|
||||
DiskCacheDeinit(disk);
|
||||
#else
|
||||
if (disk->buff != NULL) {
|
||||
free(disk->buff);
|
||||
}
|
||||
#endif
|
||||
|
||||
disk->dev = NULL;
|
||||
@@ -1344,12 +1414,15 @@ static INT32 DiskDeinit(los_disk *disk)
|
||||
return ENOERR;
|
||||
}
|
||||
|
||||
static VOID OsDiskInitSub(const CHAR *diskName, INT32 diskID, los_disk *disk,
|
||||
struct geometry *diskInfo, struct Vnode *blkDriver)
|
||||
static UINT32 OsDiskInitSub(const CHAR *diskName, INT32 diskID, los_disk *disk,
|
||||
struct geometry *diskInfo, struct Vnode *blkDriver)
|
||||
{
|
||||
pthread_mutexattr_t attr;
|
||||
#ifdef LOSCFG_FS_FAT_CACHE
|
||||
OsBcache *bc = DiskCacheInit((UINT32)diskID, diskInfo, blkDriver);
|
||||
if (bc == NULL) {
|
||||
return VFS_ERROR;
|
||||
}
|
||||
disk->bcache = bc;
|
||||
#endif
|
||||
|
||||
@@ -1358,6 +1431,16 @@ static VOID OsDiskInitSub(const CHAR *diskName, INT32 diskID, los_disk *disk,
|
||||
(VOID)pthread_mutex_init(&disk->disk_mutex, &attr);
|
||||
|
||||
DiskStructInit(diskName, diskID, diskInfo, blkDriver, disk);
|
||||
|
||||
#ifndef LOSCFG_FS_FAT_CACHE
|
||||
disk->buff = malloc(diskInfo->geo_sectorsize * DISK_DIRECT_BUFFER_SIZE);
|
||||
if (disk->buff == NULL) {
|
||||
PRINT_ERR("OsDiskInitSub: direct buffer of disk init failed\n");
|
||||
return VFS_ERROR;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ENOERR;
|
||||
}
|
||||
|
||||
INT32 los_disk_init(const CHAR *diskName, const struct block_operations *bops,
|
||||
@@ -1382,14 +1465,12 @@ INT32 los_disk_init(const CHAR *diskName, const struct block_operations *bops,
|
||||
ret = VnodeLookup(diskName, &blkDriver, 0);
|
||||
if (ret < 0) {
|
||||
VnodeDrop();
|
||||
PRINT_ERR("disk_init : find %s fail!\n", diskName);
|
||||
ret = ENOENT;
|
||||
goto DISK_FIND_ERROR;
|
||||
}
|
||||
struct block_operations *bops2 = (struct block_operations *)((struct drv_data *)blkDriver->data)->ops;
|
||||
|
||||
if ((bops2 == NULL) || (bops2->geometry == NULL) ||
|
||||
(bops2->geometry(blkDriver, &diskInfo) != 0)) {
|
||||
if ((bops2 == NULL) || (bops2->geometry == NULL) || (bops2->geometry(blkDriver, &diskInfo) != 0)) {
|
||||
goto DISK_BLKDRIVER_ERROR;
|
||||
}
|
||||
|
||||
@@ -1397,7 +1478,12 @@ INT32 los_disk_init(const CHAR *diskName, const struct block_operations *bops,
|
||||
goto DISK_BLKDRIVER_ERROR;
|
||||
}
|
||||
|
||||
OsDiskInitSub(diskName, diskID, disk, &diskInfo, blkDriver);
|
||||
ret = OsDiskInitSub(diskName, diskID, disk, &diskInfo, blkDriver);
|
||||
if (ret != ENOERR) {
|
||||
(VOID)DiskDeinit(disk);
|
||||
VnodeDrop();
|
||||
return VFS_ERROR;
|
||||
}
|
||||
VnodeDrop();
|
||||
if (DiskDivideAndPartitionRegister(info, disk) != ENOERR) {
|
||||
(VOID)DiskDeinit(disk);
|
||||
|
||||
42
drivers/char/BUILD.gn
Normal file
42
drivers/char/BUILD.gn
Normal file
@@ -0,0 +1,42 @@
|
||||
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
# conditions and the following disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
# of conditions and the following disclaimer in the documentation and/or other materials
|
||||
# provided with the distribution.
|
||||
#
|
||||
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
# to endorse or promote products derived from this software without specific prior written
|
||||
# permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
import("//kernel/liteos_a/liteos.gni")
|
||||
|
||||
module_group("char") {
|
||||
modules = [
|
||||
"bch",
|
||||
"mem",
|
||||
"perf",
|
||||
"quickstart",
|
||||
"random",
|
||||
"trace",
|
||||
"video",
|
||||
]
|
||||
}
|
||||
@@ -34,9 +34,8 @@ MODULE_NAME := $(notdir $(shell pwd))
|
||||
LOCAL_SRCS := $(wildcard $(LITEOSTHIRDPARTY)/NuttX/drivers/bch/*.c)
|
||||
|
||||
LOCAL_INCLUDE := \
|
||||
-I $(LITEOSTHIRDPARTY)/NuttX/drivers/bch \
|
||||
-I $(LITEOSTOPDIR)/fs/include \
|
||||
-I $(LITEOSTHIRDPARTY)/NuttX/drivers/bch
|
||||
|
||||
LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS)
|
||||
LOCAL_FLAGS := $(LOCAL_INCLUDE)
|
||||
|
||||
include $(MODULE)
|
||||
|
||||
42
drivers/char/perf/BUILD.gn
Normal file
42
drivers/char/perf/BUILD.gn
Normal file
@@ -0,0 +1,42 @@
|
||||
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
# conditions and the following disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
# of conditions and the following disclaimer in the documentation and/or other materials
|
||||
# provided with the distribution.
|
||||
#
|
||||
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
# to endorse or promote products derived from this software without specific prior written
|
||||
# permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
import("//kernel/liteos_a/liteos.gni")
|
||||
|
||||
module_switch = defined(LOSCFG_DRIVERS_PERF)
|
||||
module_name = "perf_dev"
|
||||
kernel_module(module_name) {
|
||||
sources = [ "src/perf.c" ]
|
||||
|
||||
public_configs = [ ":public" ]
|
||||
}
|
||||
|
||||
config("public") {
|
||||
include_dirs = [ "include" ]
|
||||
}
|
||||
6
drivers/char/perf/Kconfig
Normal file
6
drivers/char/perf/Kconfig
Normal file
@@ -0,0 +1,6 @@
|
||||
config DRIVERS_PERF
|
||||
bool "Enable PERF DRIVER"
|
||||
default y
|
||||
depends on DRIVERS && FS_VFS && KERNEL_PERF
|
||||
help
|
||||
Answer Y to enable LiteOS support perf in userspace.
|
||||
36
drivers/char/perf/Makefile
Normal file
36
drivers/char/perf/Makefile
Normal file
@@ -0,0 +1,36 @@
|
||||
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
# conditions and the following disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
# of conditions and the following disclaimer in the documentation and/or other materials
|
||||
# provided with the distribution.
|
||||
#
|
||||
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
# to endorse or promote products derived from this software without specific prior written
|
||||
# permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
include $(LITEOSTOPDIR)/config.mk
|
||||
|
||||
MODULE_NAME := perf_dev
|
||||
|
||||
LOCAL_SRCS := $(wildcard src/*.c)
|
||||
|
||||
include $(MODULE)
|
||||
@@ -29,10 +29,8 @@
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _LOS_TIMER_PRI_H
|
||||
#define _LOS_TIMER_PRI_H
|
||||
|
||||
#include "los_typedef.h"
|
||||
#ifndef __LOS_DEV_PERF_H__
|
||||
#define __LOS_DEV_PERF_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
@@ -40,11 +38,12 @@ extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
extern VOID OsAdjTime(VOID);
|
||||
int DevPerfRegister(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
#endif /* _LOS_TIMER_PRI_H */
|
||||
|
||||
#endif
|
||||
153
drivers/char/perf/src/perf.c
Normal file
153
drivers/char/perf/src/perf.c
Normal file
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "fcntl.h"
|
||||
#include "user_copy.h"
|
||||
#include "sys/ioctl.h"
|
||||
#include "fs/driver.h"
|
||||
#include "los_dev_perf.h"
|
||||
#include "los_perf.h"
|
||||
#include "los_init.h"
|
||||
|
||||
#define PERF_DRIVER "/dev/perf"
|
||||
#define PERF_DRIVER_MODE 0666
|
||||
|
||||
/* perf ioctl */
|
||||
#define PERF_IOC_MAGIC 'T'
|
||||
#define PERF_START _IO(PERF_IOC_MAGIC, 1)
|
||||
#define PERF_STOP _IO(PERF_IOC_MAGIC, 2)
|
||||
|
||||
static int PerfOpen(struct file *filep)
|
||||
{
|
||||
(void)filep;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int PerfClose(struct file *filep)
|
||||
{
|
||||
(void)filep;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static ssize_t PerfRead(struct file *filep, char *buffer, size_t buflen)
|
||||
{
|
||||
/* perf record buffer read */
|
||||
(void)filep;
|
||||
int ret;
|
||||
int realLen;
|
||||
|
||||
char *records = LOS_MemAlloc(m_aucSysMem0, buflen);
|
||||
if (records == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
realLen = LOS_PerfDataRead(records, buflen); /* get sample data */
|
||||
if (realLen == 0) {
|
||||
PRINT_ERR("Perf read failed, check whether perf is configured to sample mode.\n");
|
||||
ret = -EINVAL;
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
ret = LOS_CopyFromKernel((void *)buffer, buflen, (void *)records, realLen);
|
||||
if (ret != 0) {
|
||||
ret = -EINVAL;
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
ret = realLen;
|
||||
EXIT:
|
||||
LOS_MemFree(m_aucSysMem0, records);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static ssize_t PerfConfig(struct file *filep, const char *buffer, size_t buflen)
|
||||
{
|
||||
(void)filep;
|
||||
int ret;
|
||||
PerfConfigAttr attr = {0};
|
||||
int attrlen = sizeof(PerfConfigAttr);
|
||||
|
||||
if (buflen != attrlen) {
|
||||
PRINT_ERR("PerfConfigAttr is %d bytes not %d\n", attrlen, buflen);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = LOS_CopyToKernel(&attr, attrlen, buffer, buflen);
|
||||
if (ret != 0) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = LOS_PerfConfig(&attr);
|
||||
if (ret != LOS_OK) {
|
||||
PRINT_ERR("perf config error %u\n", ret);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int PerfIoctl(struct file *filep, int cmd, unsigned long arg)
|
||||
{
|
||||
(void)filep;
|
||||
switch (cmd) {
|
||||
case PERF_START:
|
||||
LOS_PerfStart((UINT32)arg);
|
||||
break;
|
||||
case PERF_STOP:
|
||||
LOS_PerfStop();
|
||||
break;
|
||||
default:
|
||||
PRINT_ERR("Unknown perf ioctl cmd:%d\n", cmd);
|
||||
return -EINVAL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct file_operations_vfs g_perfDevOps = {
|
||||
PerfOpen, /* open */
|
||||
PerfClose, /* close */
|
||||
PerfRead, /* read */
|
||||
PerfConfig, /* write */
|
||||
NULL, /* seek */
|
||||
PerfIoctl, /* ioctl */
|
||||
NULL, /* mmap */
|
||||
#ifndef CONFIG_DISABLE_POLL
|
||||
NULL, /* poll */
|
||||
#endif
|
||||
NULL, /* unlink */
|
||||
};
|
||||
|
||||
int DevPerfRegister(void)
|
||||
{
|
||||
return register_driver(PERF_DRIVER, &g_perfDevOps, PERF_DRIVER_MODE, 0); /* 0666: file mode */
|
||||
}
|
||||
|
||||
LOS_MODULE_INIT(DevPerfRegister, LOS_INIT_LEVEL_KMOD_EXTENDED);
|
||||
@@ -5,7 +5,7 @@ config DRIVERS_RANDOM
|
||||
help
|
||||
Answer Y to support random.
|
||||
config HW_RANDOM_ENABLE
|
||||
depends on DRIVERS_RANDOM && (PLATFORM_HI3518EV300 || PLATFORM_HI3516CV300 || PLATFORM_HI3516DV300 || PLATFORM_HI3556V200)
|
||||
depends on DRIVERS_RANDOM && (PLATFORM_HI3518EV300 || PLATFORM_HI3516CV300 || PLATFORM_HI3516DV300 || PLATFORM_HI3556V200 || PLATFORM_QEMU_ARM_VIRT_CA7)
|
||||
bool "Select hw random"
|
||||
default y
|
||||
help
|
||||
|
||||
@@ -37,9 +37,4 @@ ifdef LOSCFG_HW_RANDOM_ENABLE
|
||||
LOCAL_SRCS += $(wildcard src/random_hw.c)
|
||||
endif
|
||||
|
||||
LOCAL_INCLUDE := -I $(LITEOSTOPDIR)/drivers/char/random/include \
|
||||
-I $(LITEOSTOPDIR)/../../$(LOSCFG_BOARD_CONFIG_PATH)/include
|
||||
|
||||
LOCAL_FLAGS := $(LOCAL_INCLUDE)
|
||||
|
||||
include $(MODULE)
|
||||
|
||||
@@ -35,6 +35,6 @@ LOCAL_SRCS := $(wildcard src/*.c)
|
||||
|
||||
LOCAL_INCLUDE := -I $(LITEOSTOPDIR)/drivers/char/trace/include
|
||||
|
||||
LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS)
|
||||
LOCAL_FLAGS := $(LOCAL_INCLUDE)
|
||||
|
||||
include $(MODULE)
|
||||
|
||||
34
drivers/mtd/BUILD.gn
Normal file
34
drivers/mtd/BUILD.gn
Normal file
@@ -0,0 +1,34 @@
|
||||
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
# conditions and the following disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
# of conditions and the following disclaimer in the documentation and/or other materials
|
||||
# provided with the distribution.
|
||||
#
|
||||
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
# to endorse or promote products derived from this software without specific prior written
|
||||
# permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
import("//kernel/liteos_a/liteos.gni")
|
||||
|
||||
module_group("mtd") {
|
||||
modules = [ "multi_partition" ]
|
||||
}
|
||||
@@ -37,10 +37,7 @@ kernel_module(module_name) {
|
||||
"src/mtd_shellcmd.c",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
"$LITEOSTOPDIR/fs/jffs2/include",
|
||||
"//device/hisilicon/drivers/include/mtd/common/include",
|
||||
]
|
||||
include_dirs = [ "$LITEOSTOPDIR/fs/jffs2/include" ]
|
||||
|
||||
if (defined(LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7)) {
|
||||
include_dirs += [ "//device/qemu/drivers/cfiflash" ]
|
||||
|
||||
@@ -34,14 +34,12 @@ MODULE_NAME := $(notdir $(shell pwd))
|
||||
LOCAL_SRCS := $(wildcard src/*.c)
|
||||
|
||||
LOCAL_INCLUDE := \
|
||||
-I $(LITEOSTOPDIR)/fs/jffs2/include \
|
||||
-I $(LITEOSTOPDIR)/drivers/mtd/multi_partition/include \
|
||||
-I $(LITEOSTOPDIR)/../../device/hisilicon/drivers/include/mtd/common/include
|
||||
-I $(LITEOSTOPDIR)/fs/jffs2/include
|
||||
|
||||
ifeq ($(LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7), y)
|
||||
LOCAL_INCLUDE += -I $(LITEOSTOPDIR)/../../device/qemu/drivers/cfiflash
|
||||
endif
|
||||
|
||||
LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS)
|
||||
LOCAL_FLAGS := $(LOCAL_INCLUDE)
|
||||
|
||||
include $(MODULE)
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
#include "los_config.h"
|
||||
#include "los_mux.h"
|
||||
#include "fs/driver.h"
|
||||
#include "mtd_common.h"
|
||||
#include "mtd/mtd_legacy_lite.h"
|
||||
|
||||
#ifdef LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7
|
||||
#include "cfiflash.h"
|
||||
|
||||
@@ -35,9 +35,11 @@ group("fs") {
|
||||
"fat/virpart",
|
||||
"jffs2",
|
||||
"nfs",
|
||||
"patchfs",
|
||||
"proc",
|
||||
"ramfs",
|
||||
"romfs",
|
||||
"rootfs",
|
||||
"vfs",
|
||||
"vfs/bcache",
|
||||
"zpfs",
|
||||
@@ -52,5 +54,7 @@ config("public") {
|
||||
"fat:public",
|
||||
"fat/virpart:public",
|
||||
"proc:public",
|
||||
"patchfs:public",
|
||||
"rootfs:public",
|
||||
]
|
||||
}
|
||||
|
||||
10
fs/Kconfig
Normal file
10
fs/Kconfig
Normal file
@@ -0,0 +1,10 @@
|
||||
source "fs/vfs/Kconfig"
|
||||
source "fs/fat/Kconfig"
|
||||
source "fs/ramfs/Kconfig"
|
||||
source "fs/romfs/Kconfig"
|
||||
source "fs/nfs/Kconfig"
|
||||
source "fs/proc/Kconfig"
|
||||
source "fs/jffs2/Kconfig"
|
||||
source "fs/rootfs/Kconfig"
|
||||
source "fs/patchfs/Kconfig"
|
||||
source "fs/zpfs/Kconfig"
|
||||
@@ -27,7 +27,7 @@ config FS_FAT_CHINESE
|
||||
Answer Y to enable LiteOS fat filesystem support Chinese.
|
||||
|
||||
config FS_FAT_VIRTUAL_PARTITION
|
||||
bool "Enabel Virtual Partition"
|
||||
bool "Enable Virtual Partition"
|
||||
default n
|
||||
depends on FS_FAT
|
||||
|
||||
|
||||
@@ -34,13 +34,9 @@ MODULE_NAME := $(notdir $(shell pwd))
|
||||
LOCAL_SRCS := $(wildcard os_adapt/*.c)
|
||||
LOCAL_SRCS += $(wildcard $(LITEOSTHIRDPARTY)/FatFs/source/*.c)
|
||||
|
||||
LOCAL_INCLUDE := \
|
||||
-I $(LITEOSTHIRDPARTY)/FatFs/source \
|
||||
-I $(LITEOSTOPDIR)/fs/fat/os_adapt \
|
||||
-I $(LITEOSTOPDIR)/fs/fat/virpart/include \
|
||||
-I $(LITEOSTOPDIR)/fs/vfs \
|
||||
LOCAL_INCLUDE := -I $(LITEOSTOPDIR)/fs/fat/os_adapt
|
||||
|
||||
LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS)
|
||||
LOCAL_FLAGS := $(LOCAL_INCLUDE)
|
||||
|
||||
include $(MODULE)
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include "ff.h"
|
||||
#include "disk_pri.h"
|
||||
#include "diskio.h"
|
||||
#include "fs/file.h"
|
||||
#include "fs/fs.h"
|
||||
#include "fs/dirent_fs.h"
|
||||
#include "fs/mount.h"
|
||||
@@ -47,6 +48,7 @@
|
||||
#include "user_copy.h"
|
||||
#include "los_vm_filemap.h"
|
||||
#include "los_hash.h"
|
||||
#include "los_vm_common.h"
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
#include <dirent.h>
|
||||
@@ -604,7 +606,7 @@ int fatfs_open(struct file *filep)
|
||||
FIL *fp;
|
||||
int ret;
|
||||
|
||||
fp = (FIL *)zalloc(sizeof(FIL));
|
||||
fp = (FIL *)zalloc(sizeof(FIL) + SS(fs));
|
||||
if (fp == NULL) {
|
||||
ret = ENOMEM;
|
||||
goto ERROR_EXIT;
|
||||
@@ -628,19 +630,13 @@ int fatfs_open(struct file *filep)
|
||||
fp->err = 0;
|
||||
fp->sect = 0;
|
||||
fp->fptr = 0;
|
||||
fp->buf = (BYTE*) ff_memalloc(SS(fs));
|
||||
if (fp->buf == NULL) {
|
||||
ret = ENOMEM;
|
||||
goto ERROR_UNLOCK;
|
||||
}
|
||||
fp->buf = (BYTE *)fp + sizeof(FIL);
|
||||
LOS_ListAdd(&finfo->fp_list, &fp->fp_entry);
|
||||
unlock_fs(fs, FR_OK);
|
||||
|
||||
filep->f_priv = fp;
|
||||
return fatfs_sync(vp->originMount->mountFlags, fs);
|
||||
return 0;
|
||||
|
||||
ERROR_UNLOCK:
|
||||
unlock_fs(fs, FR_OK);
|
||||
ERROR_FREE:
|
||||
free(fp);
|
||||
ERROR_EXIT:
|
||||
@@ -670,7 +666,6 @@ int fatfs_close(struct file *filep)
|
||||
}
|
||||
#endif
|
||||
LOS_ListDelete(&fp->fp_entry);
|
||||
ff_memfree(fp->buf);
|
||||
free(fp);
|
||||
filep->f_priv = NULL;
|
||||
EXIT:
|
||||
@@ -1297,6 +1292,29 @@ int fatfs_umount(struct Mount *mnt, struct Vnode **blkdriver)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fatfs_sync_adapt(struct Mount *mnt)
|
||||
{
|
||||
(void)mnt;
|
||||
int ret = 0;
|
||||
#ifdef LOSCFG_FS_FAT_CACHE
|
||||
struct Vnode *dev = NULL;
|
||||
los_part *part = NULL;
|
||||
|
||||
if (mnt == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
dev = mnt->vnodeDev;
|
||||
part = los_part_find(dev);
|
||||
if (part == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = OsSdSync(part->disk_id);
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
int fatfs_statfs(struct Mount *mnt, struct statfs *info)
|
||||
{
|
||||
FATFS *fs = (FATFS *)mnt->data;
|
||||
@@ -1848,6 +1866,7 @@ int fatfs_mkfs (struct Vnode *device, int sectors, int option)
|
||||
BYTE *work_buff = NULL;
|
||||
los_part *part = NULL;
|
||||
FRESULT result;
|
||||
MKFS_PARM opt = {0};
|
||||
int ret;
|
||||
|
||||
part = los_part_find(device);
|
||||
@@ -1872,7 +1891,9 @@ int fatfs_mkfs (struct Vnode *device, int sectors, int option)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
result = _mkfs(part, sectors, option, work_buff, FF_MAX_SS);
|
||||
opt.n_sect = sectors;
|
||||
opt.fmt = (BYTE)option;
|
||||
result = _mkfs(part, &opt, work_buff, FF_MAX_SS);
|
||||
free(work_buff);
|
||||
if (result != FR_OK) {
|
||||
return -fatfs_2_vfs(result);
|
||||
@@ -2032,45 +2053,18 @@ static UINT get_oldest_time(DIR_FILE df[], DWORD *oldest_time, UINT len)
|
||||
return index;
|
||||
}
|
||||
|
||||
int fatfs_fscheck(struct Vnode* vp, struct fs_dirent_s *dir)
|
||||
static FRESULT fscheck(DIR *dp)
|
||||
{
|
||||
FATFS *fs = (FATFS *)vp->originMount->data;
|
||||
DIR_FILE df[CHECK_FILE_NUM] = {0};
|
||||
DIR *dp = NULL;
|
||||
FILINFO *finfo = &(((DIR_FILE *)(vp->data))->fno);
|
||||
FILINFO fno;
|
||||
DWORD old_time = -1;
|
||||
DWORD time;
|
||||
UINT count;
|
||||
UINT index = 0;
|
||||
los_part *part = NULL;
|
||||
UINT count;
|
||||
DWORD time;
|
||||
DWORD old_time = -1;
|
||||
FRESULT result;
|
||||
int ret;
|
||||
|
||||
if (fs->fs_type != FS_FAT32) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if ((finfo->fattrib & AM_DIR) == 0) {
|
||||
return -ENOTDIR;
|
||||
}
|
||||
|
||||
ret = fatfs_opendir(vp, dir);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = lock_fs(fs);
|
||||
if (ret == FALSE) {
|
||||
result = FR_TIMEOUT;
|
||||
goto ERROR_WITH_DIR;
|
||||
}
|
||||
|
||||
dp = (DIR *)dir->u.fs_dir;
|
||||
dp->obj.id = fs->id;
|
||||
for (count = 0; count < CHECK_FILE_NUM; count++) {
|
||||
if ((result = f_readdir(dp, &fno)) != FR_OK) {
|
||||
goto ERROR_UNLOCK;
|
||||
return result;
|
||||
} else {
|
||||
if (fno.fname[0] == 0 || fno.fname[0] == (TCHAR)0xFF) {
|
||||
break;
|
||||
@@ -2095,15 +2089,50 @@ int fatfs_fscheck(struct Vnode* vp, struct fs_dirent_s *dir)
|
||||
index = get_oldest_time(df, &old_time, CHECK_FILE_NUM);
|
||||
}
|
||||
}
|
||||
if (result != FR_OK) {
|
||||
goto ERROR_UNLOCK;
|
||||
index = 0;
|
||||
while (result == FR_OK && index < count) {
|
||||
result = f_fcheckfat(&df[index]);
|
||||
++index;
|
||||
}
|
||||
|
||||
for (index = 0; index < count; index++) {
|
||||
result = f_fcheckfat(&df[index]);
|
||||
if (result != FR_OK) {
|
||||
goto ERROR_UNLOCK;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int fatfs_fscheck(struct Vnode* vp, struct fs_dirent_s *dir)
|
||||
{
|
||||
FATFS *fs = (FATFS *)vp->originMount->data;
|
||||
DIR *dp = NULL;
|
||||
FILINFO *finfo = &(((DIR_FILE *)(vp->data))->fno);
|
||||
#ifdef LOSCFG_FS_FAT_CACHE
|
||||
los_part *part = NULL;
|
||||
#endif
|
||||
FRESULT result;
|
||||
int ret;
|
||||
|
||||
if (fs->fs_type != FS_FAT32) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if ((finfo->fattrib & AM_DIR) == 0) {
|
||||
return -ENOTDIR;
|
||||
}
|
||||
|
||||
ret = fatfs_opendir(vp, dir);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = lock_fs(fs);
|
||||
if (ret == FALSE) {
|
||||
result = FR_TIMEOUT;
|
||||
goto ERROR_WITH_DIR;
|
||||
}
|
||||
|
||||
dp = (DIR *)dir->u.fs_dir;
|
||||
dp->obj.id = fs->id;
|
||||
result = fscheck(dp);
|
||||
if (result != FR_OK) {
|
||||
goto ERROR_UNLOCK;
|
||||
}
|
||||
|
||||
unlock_fs(fs, FR_OK);
|
||||
@@ -2180,6 +2209,207 @@ ERROUT:
|
||||
return -fatfs_2_vfs(res);
|
||||
}
|
||||
|
||||
ssize_t fatfs_readpage(struct Vnode *vnode, char *buff, off_t pos)
|
||||
{
|
||||
FATFS *fs = (FATFS *)(vnode->originMount->data);
|
||||
DIR_FILE *dfp = (DIR_FILE *)(vnode->data);
|
||||
FILINFO *finfo = &(dfp->fno);
|
||||
FAT_ENTRY *ep = &(dfp->fat_entry);
|
||||
DWORD clust;
|
||||
DWORD sclust;
|
||||
QWORD sect;
|
||||
QWORD step;
|
||||
QWORD n;
|
||||
size_t position; /* byte offset */
|
||||
BYTE *buf = (BYTE *)buff;
|
||||
size_t buflen = PAGE_SIZE;
|
||||
FRESULT result;
|
||||
int ret;
|
||||
|
||||
ret = lock_fs(fs);
|
||||
if (ret == FALSE) {
|
||||
result = FR_TIMEOUT;
|
||||
goto ERROR_OUT;
|
||||
}
|
||||
|
||||
if (finfo->fsize <= pos) {
|
||||
result = FR_OK;
|
||||
goto ERROR_UNLOCK;
|
||||
}
|
||||
|
||||
if (ep->clst == 0) {
|
||||
ep->clst = finfo->sclst;
|
||||
}
|
||||
|
||||
if (pos >= ep->pos) {
|
||||
clust = ep->clst;
|
||||
position = ep->pos;
|
||||
} else {
|
||||
clust = finfo->sclst;
|
||||
position = 0;
|
||||
}
|
||||
|
||||
/* Get to the current cluster */
|
||||
n = pos / SS(fs) / fs->csize - position / SS(fs) / fs->csize;
|
||||
while (n--) {
|
||||
clust = get_fat(&(dfp->f_dir.obj), clust);
|
||||
if ((clust == BAD_CLUSTER) || (clust == DISK_ERROR)) {
|
||||
result = FR_DISK_ERR;
|
||||
goto ERROR_UNLOCK;
|
||||
}
|
||||
}
|
||||
|
||||
/* Get to the currnet sector */
|
||||
sect = clst2sect(fs, clust);
|
||||
sect += (pos / SS(fs)) & (fs->csize - 1);
|
||||
|
||||
/* How many sectors do we need to read once */
|
||||
if (fs->csize < buflen / SS(fs)) {
|
||||
step = fs->csize;
|
||||
} else {
|
||||
step = buflen / SS(fs);
|
||||
}
|
||||
|
||||
n = 0;
|
||||
sclust = clust;
|
||||
while (n < buflen / SS(fs)) {
|
||||
if (disk_read(fs->pdrv, buf, sect, step) != RES_OK) {
|
||||
result = FR_DISK_ERR;
|
||||
goto ERROR_UNLOCK;
|
||||
}
|
||||
n += step;
|
||||
if (n >= buflen / SS(fs)) {
|
||||
break;
|
||||
}
|
||||
|
||||
/* As cluster size is aligned, it must jump to next cluster when cluster size is less than pagesize */
|
||||
clust = get_fat(&(dfp->f_dir.obj), clust);
|
||||
if ((clust == BAD_CLUSTER) || (clust == DISK_ERROR)) {
|
||||
result = FR_DISK_ERR;
|
||||
goto ERROR_UNLOCK;
|
||||
} else if (fatfs_is_last_cluster(fs, clust)) {
|
||||
break; /* read end */
|
||||
}
|
||||
sect = clst2sect(fs, clust);
|
||||
buf += step * SS(fs);
|
||||
}
|
||||
|
||||
ep->clst = sclust;
|
||||
ep->pos = pos;
|
||||
|
||||
unlock_fs(fs, FR_OK);
|
||||
|
||||
return (ssize_t)min(finfo->fsize - pos, n * SS(fs));
|
||||
|
||||
ERROR_UNLOCK:
|
||||
unlock_fs(fs, result);
|
||||
ERROR_OUT:
|
||||
return -fatfs_2_vfs(result);
|
||||
}
|
||||
|
||||
ssize_t fatfs_writepage(struct Vnode *vnode, char *buff, off_t pos, size_t buflen)
|
||||
{
|
||||
FATFS *fs = (FATFS *)(vnode->originMount->data);
|
||||
DIR_FILE *dfp = (DIR_FILE *)(vnode->data);
|
||||
FILINFO *finfo = &(dfp->fno);
|
||||
FAT_ENTRY *ep = &(dfp->fat_entry);
|
||||
DWORD clust;
|
||||
DWORD sclst;
|
||||
QWORD sect;
|
||||
QWORD step;
|
||||
QWORD n;
|
||||
size_t position; /* byte offset */
|
||||
BYTE *buf = (BYTE *)buff;
|
||||
FRESULT result;
|
||||
FIL fil;
|
||||
int ret;
|
||||
|
||||
ret = lock_fs(fs);
|
||||
if (ret == FALSE) {
|
||||
result = FR_TIMEOUT;
|
||||
goto ERROR_OUT;
|
||||
}
|
||||
|
||||
if (finfo->fsize <= pos) {
|
||||
result = FR_OK;
|
||||
goto ERROR_UNLOCK;
|
||||
}
|
||||
|
||||
if (ep->clst == 0) {
|
||||
ep->clst = finfo->sclst;
|
||||
}
|
||||
|
||||
if (pos >= ep->pos) {
|
||||
clust = ep->clst;
|
||||
position = ep->pos;
|
||||
} else {
|
||||
clust = finfo->sclst;
|
||||
position = 0;
|
||||
}
|
||||
|
||||
/* Get to the current cluster */
|
||||
n = pos / SS(fs) / fs->csize - position / SS(fs) / fs->csize;
|
||||
while (n--) {
|
||||
clust = get_fat(&(dfp->f_dir.obj), clust);
|
||||
if ((clust == BAD_CLUSTER) || (clust == DISK_ERROR)) {
|
||||
result = FR_DISK_ERR;
|
||||
goto ERROR_UNLOCK;
|
||||
}
|
||||
}
|
||||
|
||||
/* Get to the currnet sector */
|
||||
sect = clst2sect(fs, clust);
|
||||
sect += (pos / SS(fs)) & (fs->csize - 1);
|
||||
|
||||
/* How many sectors do we need to read once */
|
||||
if (fs->csize < buflen / SS(fs)) {
|
||||
step = fs->csize;
|
||||
} else {
|
||||
step = buflen / SS(fs);
|
||||
}
|
||||
|
||||
n = 0;
|
||||
sclst = clust;
|
||||
while (n < buflen / SS(fs)) {
|
||||
if (disk_write(fs->pdrv, buf, sect, step) != RES_OK) {
|
||||
result = FR_DISK_ERR;
|
||||
goto ERROR_UNLOCK;
|
||||
}
|
||||
n += step;
|
||||
if (n >= buflen / SS(fs)) {
|
||||
break;
|
||||
}
|
||||
|
||||
/* As cluster size is aligned, it must jump to next cluster when cluster size is less than pagesize */
|
||||
clust = get_fat(&(dfp->f_dir.obj), clust);
|
||||
if ((clust == BAD_CLUSTER) || (clust == DISK_ERROR)) {
|
||||
result = FR_DISK_ERR;
|
||||
goto ERROR_UNLOCK;
|
||||
} else if (fatfs_is_last_cluster(fs, clust)) {
|
||||
break; /* read end */
|
||||
}
|
||||
sect = clst2sect(fs, clust);
|
||||
buf += step * SS(fs);
|
||||
}
|
||||
|
||||
ep->clst = sclst;
|
||||
ep->pos = pos;
|
||||
|
||||
fil.obj.fs = fs;
|
||||
if (update_filbuff(finfo, &fil, NULL) < 0) {
|
||||
result = FR_DISK_ERR;
|
||||
goto ERROR_UNLOCK;
|
||||
}
|
||||
|
||||
unlock_fs(fs, FR_OK);
|
||||
|
||||
return (ssize_t)min(finfo->fsize - pos, n * SS(fs));
|
||||
ERROR_UNLOCK:
|
||||
unlock_fs(fs, result);
|
||||
ERROR_OUT:
|
||||
return -fatfs_2_vfs(result);
|
||||
}
|
||||
|
||||
struct VnodeOps fatfs_vops = {
|
||||
/* file ops */
|
||||
.Getattr = fatfs_stat,
|
||||
@@ -2187,6 +2417,8 @@ struct VnodeOps fatfs_vops = {
|
||||
.Lookup = fatfs_lookup,
|
||||
.Rename = fatfs_rename,
|
||||
.Create = fatfs_create,
|
||||
.ReadPage = fatfs_readpage,
|
||||
.WritePage = fatfs_writepage,
|
||||
.Unlink = fatfs_unlink,
|
||||
.Reclaim = fatfs_reclaim,
|
||||
.Truncate = fatfs_truncate,
|
||||
@@ -2207,6 +2439,7 @@ struct MountOps fatfs_mops = {
|
||||
.Mount = fatfs_mount,
|
||||
.Unmount = fatfs_umount,
|
||||
.Statfs = fatfs_statfs,
|
||||
.Sync = fatfs_sync_adapt,
|
||||
};
|
||||
|
||||
struct file_operations_vfs fatfs_fops = {
|
||||
|
||||
@@ -146,7 +146,7 @@ int fatfs_fscheck(struct Vnode* vnode, struct fs_dirent_s *dir);
|
||||
|
||||
FRESULT find_fat_partition(FATFS *fs, los_part *part, BYTE *format, QWORD *start_sector);
|
||||
FRESULT init_fatobj(FATFS *fs, BYTE fmt, QWORD start_sector);
|
||||
FRESULT _mkfs(los_part *partition, int sector, int opt, BYTE *work, UINT len);
|
||||
FRESULT _mkfs(los_part *partition, const MKFS_PARM *opt, BYTE *work, UINT len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
|
||||
@@ -33,10 +33,8 @@ MODULE_NAME := $(notdir $(shell pwd))
|
||||
|
||||
LOCAL_SRCS := $(wildcard src/*.c)
|
||||
|
||||
LOCAL_INCLUDE := \
|
||||
-I $(LITEOSTOPDIR)/fs/fat/virpart/include \
|
||||
-I $(LITEOSTOPDIR)/fs/fat/os_adapt
|
||||
LOCAL_INCLUDE := -I $(LITEOSTOPDIR)/fs/fat/os_adapt
|
||||
|
||||
LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS)
|
||||
LOCAL_FLAGS := $(LOCAL_INCLUDE)
|
||||
|
||||
include $(MODULE)
|
||||
|
||||
@@ -267,7 +267,7 @@ static FRESULT FatfsScanClear(INT vol)
|
||||
* Acceptable Return Value:
|
||||
* - FR_OK : The root directory is completely clean.
|
||||
* - FR_OCCUPIED : The virtual partition entry has been occupied by the same name file.
|
||||
* - FR_CHAIN_ERR : The virtual partition entry has been rebuilt along the invaild cluster
|
||||
* - FR_CHAIN_ERR : The virtual partition entry has been rebuilt along the invalid cluster
|
||||
* chain.
|
||||
* Others Return Value:
|
||||
* Followed the by the lower API
|
||||
|
||||
@@ -53,7 +53,7 @@ extern FATFS *FatFs[FF_VOLUMES];
|
||||
* follow_virentry:
|
||||
* Compare the top segment with the virtual partition entry and replace it to its CHILD FATFS
|
||||
*
|
||||
* Acceptable return vaule:
|
||||
* Acceptable return value:
|
||||
* - FR_OK : The top segment matches one of the virtual partition entries, and the FATFS
|
||||
* has been replaced to the corresponding FATFS.
|
||||
* - FR_DENIED : The top segment does not matched any of the virtual partition entries, and
|
||||
@@ -291,7 +291,7 @@ static void FatfsSetParentFs(FATFS *pfs, FATFS *fs)
|
||||
* - FR_DENIED : The virtual partition feature has been shut down by switcher
|
||||
* - FR_DISK_ERR : A disk error happened
|
||||
* - FR_NOT_ENOUGH_CORE : Not enough memory for allocate space for CHILD FATFS
|
||||
* - FR_INVALID_PARAMETER : There is a invaild value in current setting
|
||||
* - FR_INVALID_PARAMETER : There is a invalid value in current setting
|
||||
*/
|
||||
FRESULT f_regvirfs(FATFS *fs)
|
||||
{
|
||||
@@ -507,7 +507,7 @@ static void FatfsSetChildClst(BYTE *work, FATFS *fs, WORD i)
|
||||
* - FR_INVAILD_FATFS : The FATFS object has error or the info in it has been occuried
|
||||
* - FR_DENIED : The virtual partition feature has been shut down by switcher
|
||||
* - FR_INVALID_DRIVE : The drive index is error
|
||||
* - FR_DISK_ERR : A Disk error happend
|
||||
* - FR_DISK_ERR : A Disk error happened
|
||||
*/
|
||||
FRESULT f_checkvirpart(FATFS *fs, const TCHAR *path, BYTE vol)
|
||||
{
|
||||
@@ -525,7 +525,7 @@ FRESULT f_checkvirpart(FATFS *fs, const TCHAR *path, BYTE vol)
|
||||
}
|
||||
|
||||
/* Lock the filesystem object */
|
||||
res = find_volume(&path, &fs, FA_WRITE); /* Update the filesystem info to the parent fs */
|
||||
res = mount_volume(&path, &fs, FA_WRITE); /* Update the filesystem info to the parent fs */
|
||||
if (res != FR_OK) {
|
||||
LEAVE_FF(fs, res);
|
||||
}
|
||||
@@ -663,7 +663,7 @@ static void FatfsClacPartInfo(FATFS *fs, DOUBLE virpartper, UINT i)
|
||||
* - FR_INVAILD_FATFS : The FATFS object has error or the info in it has been occuried
|
||||
* - FR_DENIED : The virtual partition feature has been shut down by switcher
|
||||
* - FR_INVALID_DRIVE : The drive index is error
|
||||
* - FR_DISK_ERR : A Disk error happend
|
||||
* - FR_DISK_ERR : A Disk error happened
|
||||
*/
|
||||
FRESULT f_makevirpart(FATFS *fs, const TCHAR *path, BYTE vol)
|
||||
{
|
||||
@@ -683,7 +683,7 @@ FRESULT f_makevirpart(FATFS *fs, const TCHAR *path, BYTE vol)
|
||||
}
|
||||
|
||||
/* Lock the filesystem object */
|
||||
res = find_volume(&path, &fs, FA_WRITE); /* Update the filesystem info to the parent fs */
|
||||
res = mount_volume(&path, &fs, FA_WRITE); /* Update the filesystem info to the parent fs */
|
||||
if (res != FR_OK) {
|
||||
LEAVE_FF(fs, res);
|
||||
}
|
||||
@@ -774,7 +774,7 @@ FRESULT f_getvirfree(const TCHAR *path, DWORD *nclst, DWORD *cclst)
|
||||
DIR dj;
|
||||
|
||||
/* Find volume to Update the global FSINFO */
|
||||
res = find_volume(&path, &fs, 0);
|
||||
res = mount_volume(&path, &fs, 0);
|
||||
if (res != FR_OK) {
|
||||
LEAVE_FF(fs, res);
|
||||
}
|
||||
@@ -797,7 +797,7 @@ FRESULT f_getvirfree(const TCHAR *path, DWORD *nclst, DWORD *cclst)
|
||||
|
||||
/* If current FATFS is a CHILD FATFS */
|
||||
if (ISCHILD(fs)) {
|
||||
/* If CHILD FATFS' free_clst is invaild, the scan the FAT and update it */
|
||||
/* If CHILD FATFS' free_clst is invalid, the scan the FAT and update it */
|
||||
if (fs->free_clst > fs->ct_clst) {
|
||||
dj.obj.fs = fs;
|
||||
fs->free_clst = fs->ct_clst;
|
||||
|
||||
@@ -41,81 +41,6 @@ extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* vfs/fs_file_mapping.c ****************************************************/
|
||||
/****************************************************************************
|
||||
* Name: init_file_mapping
|
||||
*
|
||||
* Description:
|
||||
* Init the global management structure of path <-> page_mapping
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
extern UINT32 init_file_mapping(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: add_mapping
|
||||
*
|
||||
* Description:
|
||||
* Create a new path <-> page_mapping mapping and add to global list.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
extern void add_mapping(struct file *filep, const char *fullpath);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: find_mapping
|
||||
*
|
||||
* Description:
|
||||
* Find the page_mapping for path in global list.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
extern struct page_mapping *find_mapping(const char *path);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: remove_mapping
|
||||
*
|
||||
* Description:
|
||||
* Drop all the page-caches for the file, and then remove mapping between
|
||||
* the file and pagecache.
|
||||
* ex_filp NULL: do not exclude any file, just matching the fullpath;
|
||||
* ex_filp not NULL: exclude it, which means, ex_filp can be open.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
extern int remove_mapping(const char *fullpath);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: rename_mapping
|
||||
*
|
||||
* Description:
|
||||
* Rename the mapping from global path <-> page_mapping list.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
extern void rename_mapping(const char *src, const char *dst);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: dec_mapping
|
||||
*
|
||||
* Description:
|
||||
* Decrease the refcnt of mapping.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
extern void dec_mapping_nolock(struct page_mapping *mapping);
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Name: update_file_path
|
||||
*
|
||||
* Description:
|
||||
* Update the path in file descriptors when do renaming.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
extern int update_file_path(const char *old_path, const char *new_path);
|
||||
|
||||
/**
|
||||
* @ingroup fs
|
||||
* @brief Initializes the vfs filesystem
|
||||
|
||||
@@ -61,6 +61,7 @@ struct MountOps {
|
||||
int (*Mount)(struct Mount *mount, struct Vnode *vnode, const void *data);
|
||||
int (*Unmount)(struct Mount *mount, struct Vnode **blkdriver);
|
||||
int (*Statfs)(struct Mount *mount, struct statfs *sbp);
|
||||
int (*Sync)(struct Mount *mount);
|
||||
};
|
||||
|
||||
typedef int (*foreach_mountpoint_t)(const char *devpoint,
|
||||
|
||||
@@ -44,14 +44,14 @@ extern "C" {
|
||||
#define PATH_MAX 256
|
||||
#define CONFIG_DISABLE_MQUEUE // disable posix mqueue inode configure
|
||||
|
||||
/* file system configur */
|
||||
/* file system config */
|
||||
|
||||
#define CONFIG_FS_WRITABLE // enable file system can be written
|
||||
#define CONFIG_FS_READABLE // enable file system can be read
|
||||
#define CONFIG_DEBUG_FS // enable vfs debug function
|
||||
|
||||
|
||||
/* fatfs cache configur */
|
||||
/* fatfs cache config */
|
||||
/* config block size for fat file system, only can be 0,32,64,128,256,512,1024 */
|
||||
#define CONFIG_FS_FAT_SECTOR_PER_BLOCK 64
|
||||
|
||||
@@ -96,6 +96,7 @@ extern "C" {
|
||||
#define CONFIG_NEXPANED_DESCRIPTORS (CONFIG_NTIME_DESCRIPTORS + CONFIG_NQUEUE_DESCRIPTORS)
|
||||
#define TIMER_FD_OFFSET FD_SETSIZE
|
||||
#define MQUEUE_FD_OFFSET (FD_SETSIZE + CONFIG_NTIME_DESCRIPTORS)
|
||||
#define EPOLL_FD_OFFSET (FD_SETSIZE + CONFIG_NTIME_DESCRIPTORS + CONFIG_NQUEUE_DESCRIPTORS)
|
||||
|
||||
/* net configure */
|
||||
|
||||
@@ -129,6 +130,8 @@ extern "C" {
|
||||
|
||||
#define VFS_USING_WORKDIR // enable current working directory
|
||||
|
||||
#define CONFIG_EPOLL_DESCRIPTORS 32
|
||||
|
||||
/* permission configure */
|
||||
#define DEFAULT_DIR_MODE 0777
|
||||
#define DEFAULT_FILE_MODE 0666
|
||||
|
||||
@@ -35,10 +35,9 @@ LOCAL_SRCS := $(wildcard src/*.c) \
|
||||
$(wildcard $(LITEOSTHIRDPARTY)/Linux_Kernel/fs/jffs2/*.c)
|
||||
LOCAL_INCLUDE := \
|
||||
-I $(LITEOSTOPDIR)/fs/jffs2/include \
|
||||
-I $(LITEOSTOPDIR)/drivers/mtd/multi_partition/include \
|
||||
-I $(LITEOSTHIRDPARTY)/Linux_Kernel/fs/jffs2 \
|
||||
-I $(LITEOSTHIRDPARTY)/Linux_Kernel/fs
|
||||
LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS)
|
||||
LOCAL_FLAGS := $(LOCAL_INCLUDE)
|
||||
|
||||
include $(MODULE)
|
||||
|
||||
|
||||
@@ -201,13 +201,13 @@ int VfsJffs2Lookup(struct Vnode *parentVnode, const char *path, int len, struct
|
||||
}
|
||||
|
||||
(void)VfsHashGet(parentVnode->originMount, node->i_ino, &newVnode, NULL, NULL);
|
||||
LOS_MuxUnlock(&g_jffs2FsLock);
|
||||
if (newVnode) {
|
||||
if (newVnode->data == NULL) {
|
||||
LOS_Panic("#####VfsHashGet error#####\n");
|
||||
}
|
||||
newVnode->parent = parentVnode;
|
||||
*ppVnode = newVnode;
|
||||
LOS_MuxUnlock(&g_jffs2FsLock);
|
||||
return 0;
|
||||
}
|
||||
ret = VnodeAlloc(&g_jffs2Vops, &newVnode);
|
||||
@@ -276,7 +276,7 @@ int VfsJffs2Close(struct file *filep)
|
||||
return 0;
|
||||
}
|
||||
|
||||
ssize_t VfsJffs2Read(struct file *filep, char *buffer, size_t bufLen)
|
||||
ssize_t VfsJffs2ReadPage(struct Vnode *vnode, char *buffer, off_t off)
|
||||
{
|
||||
struct jffs2_inode *node = NULL;
|
||||
struct jffs2_inode_info *f = NULL;
|
||||
@@ -285,6 +285,32 @@ ssize_t VfsJffs2Read(struct file *filep, char *buffer, size_t bufLen)
|
||||
|
||||
LOS_MuxLock(&g_jffs2FsLock, (uint32_t)JFFS2_WAITING_FOREVER);
|
||||
|
||||
node = (struct jffs2_inode *)vnode->data;
|
||||
f = JFFS2_INODE_INFO(node);
|
||||
c = JFFS2_SB_INFO(node->i_sb);
|
||||
|
||||
off_t pos = min(node->i_size, off);
|
||||
ssize_t len = min(PAGE_SIZE, (node->i_size - pos));
|
||||
ret = jffs2_read_inode_range(c, f, (unsigned char *)buffer, off, len);
|
||||
if (ret) {
|
||||
LOS_MuxUnlock(&g_jffs2FsLock);
|
||||
return ret;
|
||||
}
|
||||
node->i_atime = Jffs2CurSec();
|
||||
|
||||
LOS_MuxUnlock(&g_jffs2FsLock);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
ssize_t VfsJffs2Read(struct file *filep, char *buffer, size_t bufLen)
|
||||
{
|
||||
struct jffs2_inode *node = NULL;
|
||||
struct jffs2_inode_info *f = NULL;
|
||||
struct jffs2_sb_info *c = NULL;
|
||||
int ret;
|
||||
|
||||
LOS_MuxLock(&g_jffs2FsLock, (uint32_t)JFFS2_WAITING_FOREVER);
|
||||
node = (struct jffs2_inode *)filep->f_vnode->data;
|
||||
f = JFFS2_INODE_INFO(node);
|
||||
c = JFFS2_SB_INFO(node->i_sb);
|
||||
@@ -293,7 +319,6 @@ ssize_t VfsJffs2Read(struct file *filep, char *buffer, size_t bufLen)
|
||||
off_t len = min(bufLen, (node->i_size - pos));
|
||||
ret = jffs2_read_inode_range(c, f, (unsigned char *)buffer, filep->f_pos, len);
|
||||
if (ret) {
|
||||
PRINTK("VfsJffs2Read(): read_inode_range failed %d\n", ret);
|
||||
LOS_MuxUnlock(&g_jffs2FsLock);
|
||||
return ret;
|
||||
}
|
||||
@@ -305,6 +330,59 @@ ssize_t VfsJffs2Read(struct file *filep, char *buffer, size_t bufLen)
|
||||
return len;
|
||||
}
|
||||
|
||||
ssize_t VfsJffs2WritePage(struct Vnode *vnode, char *buffer, off_t pos, size_t buflen)
|
||||
{
|
||||
struct jffs2_inode *node = NULL;
|
||||
struct jffs2_inode_info *f = NULL;
|
||||
struct jffs2_sb_info *c = NULL;
|
||||
struct jffs2_raw_inode ri = {0};
|
||||
struct IATTR attr = {0};
|
||||
int ret;
|
||||
uint32_t writtenLen;
|
||||
|
||||
LOS_MuxLock(&g_jffs2FsLock, (uint32_t)JFFS2_WAITING_FOREVER);
|
||||
|
||||
node = (struct jffs2_inode *)vnode->data;
|
||||
f = JFFS2_INODE_INFO(node);
|
||||
c = JFFS2_SB_INFO(node->i_sb);
|
||||
|
||||
if (pos < 0) {
|
||||
LOS_MuxUnlock(&g_jffs2FsLock);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ri.ino = cpu_to_je32(f->inocache->ino);
|
||||
ri.mode = cpu_to_jemode(node->i_mode);
|
||||
ri.uid = cpu_to_je16(node->i_uid);
|
||||
ri.gid = cpu_to_je16(node->i_gid);
|
||||
ri.atime = ri.ctime = ri.mtime = cpu_to_je32(Jffs2CurSec());
|
||||
|
||||
if (pos > node->i_size) {
|
||||
int err;
|
||||
attr.attr_chg_valid = CHG_SIZE;
|
||||
attr.attr_chg_size = pos;
|
||||
err = jffs2_setattr(node, &attr);
|
||||
if (err) {
|
||||
LOS_MuxUnlock(&g_jffs2FsLock);
|
||||
return err;
|
||||
}
|
||||
}
|
||||
ri.isize = cpu_to_je32(node->i_size);
|
||||
|
||||
ret = jffs2_write_inode_range(c, f, &ri, (unsigned char *)buffer, pos, buflen, &writtenLen);
|
||||
if (ret) {
|
||||
node->i_mtime = node->i_ctime = je32_to_cpu(ri.mtime);
|
||||
LOS_MuxUnlock(&g_jffs2FsLock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
node->i_mtime = node->i_ctime = je32_to_cpu(ri.mtime);
|
||||
|
||||
LOS_MuxUnlock(&g_jffs2FsLock);
|
||||
|
||||
return (ssize_t)writtenLen;
|
||||
}
|
||||
|
||||
ssize_t VfsJffs2Write(struct file *filep, const char *buffer, size_t bufLen)
|
||||
{
|
||||
struct jffs2_inode *node = NULL;
|
||||
@@ -686,7 +764,6 @@ int VfsJffs2Symlink(struct Vnode *parentVnode, struct Vnode **newVnode, const ch
|
||||
|
||||
ssize_t VfsJffs2Readlink(struct Vnode *vnode, char *buffer, size_t bufLen)
|
||||
{
|
||||
ssize_t ret = 0;
|
||||
struct jffs2_inode *inode = NULL;
|
||||
struct jffs2_inode_info *f = NULL;
|
||||
ssize_t targetLen;
|
||||
@@ -705,14 +782,12 @@ ssize_t VfsJffs2Readlink(struct Vnode *vnode, char *buffer, size_t bufLen)
|
||||
cnt = (bufLen - 1) < targetLen ? (bufLen - 1) : targetLen;
|
||||
if (LOS_CopyFromKernel(buffer, bufLen, (const char *)f->target, cnt) != 0) {
|
||||
cnt = 0;
|
||||
ret = -EFAULT;
|
||||
LOS_MuxUnlock(&g_jffs2FsLock);
|
||||
return -EFAULT;
|
||||
}
|
||||
buffer[cnt] = '\0';
|
||||
|
||||
LOS_MuxUnlock(&g_jffs2FsLock);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return cnt;
|
||||
}
|
||||
@@ -878,6 +953,8 @@ const struct MountOps jffs_operations = {
|
||||
struct VnodeOps g_jffs2Vops = {
|
||||
.Lookup = VfsJffs2Lookup,
|
||||
.Create = VfsJffs2Create,
|
||||
.ReadPage = VfsJffs2ReadPage,
|
||||
.WritePage = VfsJffs2WritePage,
|
||||
.Rename = VfsJffs2Rename,
|
||||
.Mkdir = VfsJffs2Mkdir,
|
||||
.Getattr = VfsJffs2Stat,
|
||||
|
||||
@@ -33,6 +33,6 @@ MODULE_NAME := $(notdir $(shell pwd))
|
||||
|
||||
LOCAL_SRCS := $(wildcard $(LITEOSTHIRDPARTY)/NuttX/fs/nfs/*.c)
|
||||
|
||||
LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS)
|
||||
LOCAL_FLAGS := $(LOCAL_INCLUDE)
|
||||
|
||||
include $(MODULE)
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user