Skip to content

Commit ca65e50

Browse files
committed
[smart] code cleanup for vdso.
1 parent c5c3c96 commit ca65e50

File tree

10 files changed

+73
-101
lines changed

10 files changed

+73
-101
lines changed

components/lwp/Kconfig

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
menuconfig RT_USING_LWP
2-
bool "light-weight process"
2+
bool "lwP(light weight Process)"
33
depends on RT_USING_SMART
44
default y
55
help
@@ -87,4 +87,3 @@ if RT_USING_LWP
8787
rsource "terminal/Kconfig"
8888
rsource "vdso/Kconfig"
8989
endif
90-

components/lwp/vdso/Kconfig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
menuconfig RT_USING_VDSO
2-
bool "vDSO"
1+
config RT_USING_VDSO
2+
bool "vDSO (​​Virtual Dynamic Shared Object)"
3+
depends on (ARCH_ARMV8 || ARCH_RISCV)
34
default y
4-
depends on RT_USING_SMART && (ARCH_ARMV8 || ARCH_RISCV)

components/lwp/vdso/SConscript

Lines changed: 31 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,59 +2,49 @@ import os
22
import rtconfig
33
import subprocess
44
from building import *
5-
Import('RTT_ROOT')
65

7-
group = []
8-
9-
cwd = GetCurrentDir()
6+
group = []
7+
cwd = GetCurrentDir()
108
CPPPATH = [cwd, cwd + "/kernel"]
9+
list = os.listdir(cwd)
10+
src = Glob('kernel/*.c') + Glob('kernel/*.S')
1111

1212
if not GetDepend(['RT_USING_VDSO']):
1313
Return('group')
1414

1515
if rtconfig.ARCH != "aarch64" and rtconfig.ARCH != "risc-v":
16-
src = Glob('*.c')
17-
group = DefineGroup('VDSO', src, depend = ['RT_USING_SMART','RT_USING_VDSO'], CPPPATH = CPPPATH)
18-
Return('group')
19-
20-
list = os.listdir(cwd)
21-
src = Glob('kernel/*.c')
22-
src +=Glob('kernel/*.S')
23-
24-
25-
if not hasattr(rtconfig, 'CPP') or rtconfig.CPP is None:
26-
rtconfig.CPP = rtconfig.PREFIX + 'cpp'
27-
if not hasattr(rtconfig, 'CPPFLAGS') or rtconfig.CPPFLAGS is None:
28-
rtconfig.CPPFLAGS = ' -E -P -x assembler-with-cpp'
16+
# not supported arch
17+
src = []
18+
else:
19+
if not hasattr(rtconfig, 'CPP') or rtconfig.CPP is None:
20+
rtconfig.CPP = rtconfig.PREFIX + 'cpp'
21+
if not hasattr(rtconfig, 'CPPFLAGS') or rtconfig.CPPFLAGS is None:
22+
rtconfig.CPPFLAGS = ' -E -P -x assembler-with-cpp'
2923

30-
if not os.path.exists(cwd + "/user" + "/arch" +"/" + rtconfig.ARCH + "/vdso.lds"):
31-
Preprocessing("user/arch/" + rtconfig.ARCH + "/vdso.lds.S", ".lds", CPPPATH=[cwd])
24+
if not os.path.exists(cwd + "/user" + "/arch" +"/" + rtconfig.ARCH + "/vdso.lds"):
25+
Preprocessing("user/arch/" + rtconfig.ARCH + "/vdso.lds.S", ".lds", CPPPATH=[cwd])
3226

33-
#aarch64 vdso xmake
34-
# vdso_file = os.path.join(cwd, 'usr', 'xmake.lua')
35-
# command = ["xmake", "-F", vdso_file]
36-
# clean = ["xmake", "clean"]
27+
vdso_file = os.path.join(cwd, 'user',"arch", rtconfig.ARCH, 'SConstruct')
3728

38-
vdso_file = os.path.join(cwd, 'user',"arch", rtconfig.ARCH, 'SConstruct')
29+
process_env = os.environ.copy()
30+
if hasattr(rtconfig, 'EXEC_PATH') and rtconfig.EXEC_PATH is not None:
31+
process_env['EXEC_PATH'] = rtconfig.EXEC_PATH
32+
if hasattr(rtconfig, 'PREFIX') and rtconfig.PREFIX is not None:
33+
process_env['CC_PREFIX'] = rtconfig.PREFIX
3934

40-
process_env = os.environ.copy()
41-
if hasattr(rtconfig, 'EXEC_PATH') and rtconfig.EXEC_PATH is not None:
42-
process_env['EXEC_PATH'] = rtconfig.EXEC_PATH
43-
if hasattr(rtconfig, 'PREFIX') and rtconfig.PREFIX is not None:
44-
process_env['CC_PREFIX'] = rtconfig.PREFIX
45-
command = ["scons", "-f", vdso_file]
46-
clean_command = ["scons", "-f", vdso_file, "--clean"]
35+
command = ["scons", "-f", vdso_file]
36+
clean_command = ["scons", "-f", vdso_file, "--clean"]
4737

48-
if not GetOption('clean'):
49-
result = subprocess.run(command, env=process_env, check=True)
50-
else:
51-
result = subprocess.run(clean_command, env=process_env, check=True)
38+
if not GetOption('clean'):
39+
result = subprocess.run(command, env=process_env, check=True)
40+
else:
41+
result = subprocess.run(clean_command, env=process_env, check=True)
5242

53-
if result.returncode == 0:
54-
print("Command executed successfully")
55-
else:
56-
print("Command failed with exit code:", result.returncode)
57-
exit(1)
43+
if result.returncode == 0:
44+
print("Command executed successfully")
45+
else:
46+
print("Command failed with exit code:", result.returncode)
47+
exit(1)
5848

59-
group = DefineGroup('VDSO', src, depend = ['RT_USING_SMART','RT_USING_VDSO'], CPPPATH = CPPPATH)
49+
group = DefineGroup('vDSO', src, depend = ['RT_USING_SMART','RT_USING_VDSO'], CPPPATH = CPPPATH)
6050
Return('group')

components/lwp/vdso/kernel/vdso_text.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* 2024-07-04 rcitach init ver.
99
*/
1010

11-
#include <vdso_config.h>
11+
#include <vdso_config.h>
1212

1313
.globl __vdso_text_start, __vdso_text_end
1414
.section .rodata
Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,33 @@
11
import os
22
import sys
3-
import subprocess
43

54
arguments = sys.argv[2]
6-
vdso_usr = os.path.dirname(arguments)
7-
user_path = os.path.dirname(vdso_usr)
8-
user_path = os.path.dirname(user_path)
9-
user_path = os.path.dirname(user_path)
5+
vdso_usr = os.path.dirname(arguments)
6+
vdso_path = os.path.join(vdso_usr, '..', '..', '..')
107

11-
12-
EXEC_PATH = os.getenv('RTT_EXEC_PATH') or '/usr/bin'
13-
PREFIX = os.getenv('RTT_CC_PREFIX') or 'aarch64-none-elf-'
8+
EXEC_PATH = os.getenv('RTT_EXEC_PATH') or '/usr/bin'
9+
PREFIX = os.getenv('RTT_CC_PREFIX') or 'aarch64-none-elf-'
1410

1511
CC = PREFIX + 'gcc'
16-
CXX = PREFIX + 'g++'
1712
CPP = PREFIX + 'cpp'
1813
AS = PREFIX + 'gcc'
1914
AR = PREFIX + 'ar'
2015
LINK = PREFIX + 'gcc'
2116

22-
DEVICE = ' -march=armv8-a -mtune=cortex-a53 -ftree-vectorize -ffast-math -funwind-tables -fno-strict-aliasing'
23-
CXXFLAGS = DEVICE + ' -Wall -fdiagnostics-color=always'
24-
AFLAGS = ' -x assembler-with-cpp'
17+
DEVICE = ' -march=armv8-a -mtune=cortex-a53 -ftree-vectorize -ffast-math -funwind-tables -fno-strict-aliasing'
18+
AFLAGS = ' -x assembler-with-cpp'
2519
CFLAGS = DEVICE + ' -Wall -Wno-cpp -std=gnu99 -fdiagnostics-color=always -fPIC -O2'
2620
LFLAGS = DEVICE + ' -Bsymbolic -Wl,--gc-sections,-u,system_vectors -T {path}/vdso.lds'.format(path=vdso_usr)
27-
CFLAGS += " -I {path} -I {upath} ".format(path=vdso_usr ,upath=user_path)
21+
CFLAGS += " -I . -I {vdso_path} ".format(vdso_path=vdso_path)
22+
23+
src = Glob('*.c')
2824
env = Environment(tools=['gcc', 'link'],
2925
AS = AS, ASFLAGS = AFLAGS,
30-
CC = CC, CFLAGS = CFLAGS,
31-
CXX = CXX, CXXFLAGS = CXXFLAGS,
32-
AR = AR,
26+
CC = CC, CFLAGS = CFLAGS,
27+
CPP = CPP, AR = AR,
3328
LINK = LINK, LINKFLAGS = LFLAGS)
3429
env.PrependENVPath('PATH', EXEC_PATH)
3530

36-
src = os.path.join(vdso_usr,'vdso_sys.c')
37-
target_name = 'librtos_vdso.so'
38-
target = os.path.join(user_path + "/user", "build", target_name)
31+
target = os.path.join(vdso_path, 'user', 'build', 'libvdso.so')
3932
shared_lib = env.SharedLibrary(target=target, source=src)
4033
env.Default(shared_lib)
Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,33 @@
11
import os
22
import sys
3-
import subprocess
4-
from PIL.SpiderImagePlugin import iforms
53

64
arguments = sys.argv[2]
7-
vdso_usr = os.path.dirname(arguments)
8-
user_path = os.path.dirname(vdso_usr)
9-
user_path = os.path.dirname(user_path)
10-
user_path = os.path.dirname(user_path)
11-
rt_root_path = os.path.abspath(os.path.join(vdso_usr, "../../../../../../"))
12-
include_path = os.path.join(rt_root_path, "include")
13-
rtconfig_path = os.path.join(rt_root_path, "bsp", "qemu-virt64-riscv")
5+
vdso_usr = os.path.dirname(arguments)
6+
vdso_path = os.path.join(vdso_usr, '..', '..', '..')
7+
8+
EXEC_PATH = os.getenv('RTT_EXEC_PATH') or '/usr/bin'
9+
PREFIX = os.getenv('RTT_CC_PREFIX') or 'aarch64-none-elf-'
1410

15-
EXEC_PATH = os.getenv('EXEC_PATH')
16-
if not EXEC_PATH:
17-
EXEC_PATH = os.getenv('RTT_EXEC_PATH') or '/usr/bin'
18-
PREFIX = os.getenv('CC_PREFIX')
19-
if not PREFIX:
20-
PREFIX = os.getenv('RTT_CC_PREFIX') or 'riscv64-unknown-linux-gnu-'
2111
CC = PREFIX + 'gcc'
22-
CXX = PREFIX + 'g++'
2312
CPP = PREFIX + 'cpp'
2413
AS = PREFIX + 'gcc'
2514
AR = PREFIX + 'ar'
2615
LINK = PREFIX + 'gcc'
27-
DEVICE = ' -march=rv64imafdc -mabi=lp64'
28-
CXXFLAGS = DEVICE + ' -Wall -fdiagnostics-color=always -fPIC -O0 -g'
29-
AFLAGS = ' -x assembler-with-cpp'
16+
17+
DEVICE = ' -march=rv64imafdc -mabi=lp64'
18+
AFLAGS = ' -x assembler-with-cpp'
3019
CFLAGS = DEVICE + ' -Wall -Wno-cpp -std=gnu99 -fdiagnostics-color=always -fPIC -O2'
3120
LFLAGS = DEVICE + ' -Bsymbolic -Wl,--gc-sections -T {path}/vdso.lds'.format(path=vdso_usr)
32-
CFLAGS += " -I {path} -I {upath} -I {include_path} -I {rtconfig_path} ".format(path=vdso_usr, upath=user_path, include_path=include_path, rtconfig_path=rtconfig_path)
21+
CFLAGS += " -I . -I {vdso_path} ".format(vdso_path=vdso_path)
3322

23+
src = Glob('*.c')
3424
env = Environment(tools=['gcc', 'link'],
3525
AS = AS, ASFLAGS = AFLAGS,
3626
CC = CC, CFLAGS = CFLAGS,
37-
CXX = CXX, CXXFLAGS = CXXFLAGS,
38-
AR = AR,
27+
CPP = CPP, AR = AR,
3928
LINK = LINK, LINKFLAGS = LFLAGS)
4029
env.PrependENVPath('PATH', EXEC_PATH)
4130

42-
src = os.path.join(vdso_usr,'vdso_sys.c')
43-
target_name = 'librtos_vdso.so'
44-
target = os.path.join(user_path + "/user", "build", target_name)
31+
target = os.path.join(vdso_path, 'user', 'build', 'libvdso.so')
4532
shared_lib = env.SharedLibrary(target=target, source=src)
4633
env.Default(shared_lib)

components/lwp/vdso/user/arch/risc-v/vdso_sys.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
* Change Logs:
77
* Date Author Notes
88
* 2025-04-22 ScuDays Add VDSO functionality under the riscv64 architecture.
9+
* 2025-05-10 Bernard Move __arch_get_hw_frq() to vdso_sys.c as a weak function.
910
*/
1011

1112
#include <stdio.h>
1213
#include <time.h>
1314
#include <errno.h>
1415
#include <stdbool.h>
16+
1517
#include <vdso_sys.h>
1618

1719
#ifndef rt_vdso_cycles_ready
@@ -22,6 +24,12 @@ static inline bool rt_vdso_cycles_ready(uint64_t cycles)
2224
#endif
2325

2426
#ifndef rt_vdso_get_ns
27+
/* Implement as a weak function because there is no CPU cycle for RISCV */
28+
__attribute__((weak)) uint64_t __arch_get_hw_frq()
29+
{
30+
return 10000000;
31+
}
32+
2533
static inline uint64_t rt_vdso_get_ns(uint64_t cycles, uint64_t last)
2634
{
2735
return (cycles - last) * NSEC_PER_SEC / __arch_get_hw_frq();

components/lwp/vdso/user/arch/risc-v/vdso_sys.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
#include <time.h>
1515
#include <unistd.h>
1616
#include <sys/types.h>
17+
1718
#include <vdso_config.h>
1819
#include <vdso_datapage.h>
19-
#include <rtcompiler.h>
2020

2121
#define __always_unused __attribute__((__unused__))
2222
#define __maybe_unused __attribute__((__unused__))
@@ -34,11 +34,6 @@ static inline uint64_t __arch_get_hw_counter()
3434
arch_counter_enforce_ordering;
3535
return res;
3636
}
37-
// 使用了rt_weak弱符号标记该函数,默认为10000000,请根据对应平台实现这个函数。
38-
rt_weak inline uint64_t __arch_get_hw_frq()
39-
{
40-
return 10000000;
41-
}
4237

4338
static inline uint32_t
4439
__iter_div_u64_rem(uint64_t dividend, uint32_t divisor, uint64_t *remainder)

components/lwp/vdso/vdso_config.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
extern "C" {
1616
#endif
1717

18-
#define __VVAR_PAGES 2
18+
#define __VVAR_PAGES 2
1919
#define VDSO_PAGE_SHIFT 12
2020
#define VDSO_PAGE_SIZE (1 << VDSO_PAGE_SHIFT)
2121

22-
#define BIT_MASK(nr) ((1) << (nr))
22+
#define BIT_MASK(nr) ((1) << (nr))
2323

2424
#ifndef read_barrier_depends
2525
#define read_barrier_depends() do { } while (0)
@@ -29,7 +29,7 @@ extern "C" {
2929
#define smp_read_barrier_depends() read_barrier_depends()
3030
#endif
3131

32-
#define VDSO_PATH "../user/build/librtos_vdso.so"
32+
#define VDSO_PATH "../user/build/libvdso.so"
3333

3434
#ifdef __cplusplus
3535
}

components/lwp/vdso/vdso_weak.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ rt_weak int arch_setup_additional_pages(struct rt_lwp *lwp)
1919

2020
rt_weak void rt_vdso_update_glob_time(void)
2121
{
22-
22+
return ;
2323
}

0 commit comments

Comments
 (0)