Skip to content

Commit a519e01

Browse files
committed
适配 arm 架构
1 parent c5a4bda commit a519e01

8 files changed

Lines changed: 102 additions & 7 deletions

File tree

components/lwp/arch/common/vdso_kernel.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ static union
5353
uint8_t raw[RT_VDSO_DATA_PAGE_COUNT * ARCH_PAGE_SIZE];
5454
} rt_vdso_data_page_store RT_VDSO_DATA_PAGE_ALIGNED;
5555
struct rt_vdso_data_page *rt_vdso_kernel_data_page = &rt_vdso_data_page_store.data_page;
56+
RT_DEFINE_HW_SPINLOCK(rt_vdso_data_page_lock);
5657
static int rt_vdso_runtime_status = RT_EOK;
5758

5859
static struct timespec rt_vdso_realtime_offset;
@@ -143,7 +144,7 @@ static int rt_vdso_read_monotonic_snapshot(struct timespec *monotonic_time,
143144

144145
static void rt_vdso_update_data_page_flags(void)
145146
{
146-
rt_uint32_t flags = 0;
147+
rt_uint64_t flags = 0;
147148

148149
if (rt_vdso_realtime_offset_ready)
149150
{
@@ -188,11 +189,13 @@ void rt_vdso_set_realtime(const struct timespec *realtime)
188189
return;
189190
}
190191

192+
rt_hw_spin_lock(&rt_vdso_data_page_lock);
191193
rt_vdso_data_page_write_begin(rt_vdso_kernel_data_page);
192194
rt_vdso_realtime_offset = rt_vdso_timespec_subtract(realtime, &monotonic);
193195
rt_vdso_realtime_offset_ready = RT_TRUE;
194196
rt_vdso_store_clock_snapshot(&monotonic, counter, freq);
195197
rt_vdso_data_page_write_end(rt_vdso_kernel_data_page);
198+
rt_hw_spin_unlock(&rt_vdso_data_page_lock);
196199
}
197200

198201
static void *rt_vdso_map_physical_pages(struct rt_lwp *lwp, void *user_va,
@@ -309,9 +312,11 @@ void rt_vdso_sync_clock_data(void)
309312
return;
310313
}
311314

315+
rt_hw_spin_lock(&rt_vdso_data_page_lock);
312316
rt_vdso_data_page_write_begin(rt_vdso_kernel_data_page);
313317
rt_vdso_store_clock_snapshot(&monotonic, counter, freq);
314318
rt_vdso_data_page_write_end(rt_vdso_kernel_data_page);
319+
rt_hw_spin_unlock(&rt_vdso_data_page_lock);
315320
}
316321

317322
static int rt_vdso_validate_image(void)

components/lwp/vdso/SConscript

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ src = Glob('kernel/*.c') + Glob('kernel/*.S')
1212
if not GetDepend(['RT_USING_VDSO']):
1313
Return('group')
1414

15-
if rtconfig.ARCH != "aarch64" and rtconfig.ARCH != "risc-v":
15+
if rtconfig.ARCH != "aarch64" and rtconfig.ARCH != "risc-v" and rtconfig.ARCH != "arm":
16+
# not supported arch
17+
src = []
18+
elif rtconfig.ARCH == "arm" and rtconfig.CPU != "cortex-a":
1619
# not supported arch
1720
src = []
1821
else:

components/lwp/vdso/kernel/vdso_kernel_internal.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#ifndef RT_VDSO_KERNEL_INTERNAL_H
1212
#define RT_VDSO_KERNEL_INTERNAL_H
1313

14-
#include <rtatomic.h>
14+
#include <rthw.h>
1515
#include <vdso_data_page.h>
1616

1717
#ifdef __cplusplus
@@ -27,14 +27,14 @@ rt_inline struct rt_vdso_data_page *rt_vdso_get_kernel_data_page(void)
2727

2828
rt_inline void rt_vdso_data_page_write_begin(struct rt_vdso_data_page *data_page)
2929
{
30-
rt_atomic_add(&data_page->seq_counter, 1);
30+
data_page->seq_counter += 1;
3131
rt_hw_dmb();
3232
}
3333

3434
rt_inline void rt_vdso_data_page_write_end(struct rt_vdso_data_page *data_page)
3535
{
3636
rt_hw_dmb();
37-
rt_atomic_add(&data_page->seq_counter, 1);
37+
data_page->seq_counter += 1;
3838
}
3939

4040
#ifdef __cplusplus

components/lwp/vdso/user/SConstruct

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ arch_def_config = {
1111
'device': '-march=armv8-a -mtune=cortex-a53',
1212
'linker': os.path.join(user_dir, 'arch', 'aarch64', 'vdso.lds.S'),
1313
},
14+
'arm': {
15+
'prefix': 'arm-none-eabi-',
16+
'device': '-march=armv7-a -marm',
17+
'linker': os.path.join(user_dir, 'arch', 'arm', 'vdso.lds.S'),
18+
},
1419
'risc-v': {
1520
'prefix': 'riscv64-none-elf-',
1621
'device': '-march=rv64imafdc -mabi=lp64',
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include <vdso_constants.h>
2+
3+
OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
4+
OUTPUT_ARCH(arm)
5+
6+
SECTIONS
7+
{
8+
PROVIDE(__rt_vdso_data_page = . - (RT_VDSO_DATA_PAGE_COUNT * RT_VDSO_PAGE_SIZE));
9+
. = SIZEOF_HEADERS;
10+
11+
.hash : { *(.hash) } :text
12+
.gnu.hash : { *(.gnu.hash) } :text
13+
.dynsym : { *(.dynsym) } :text
14+
.dynstr : { *(.dynstr) } :text
15+
.gnu.version : { *(.gnu.version) } :text
16+
.gnu.version_d : { *(.gnu.version_d) } :text
17+
.gnu.version_r : { *(.gnu.version_r) } :text
18+
.dynamic : { *(.dynamic) } :text :dynamic
19+
.rodata : ALIGN(16) { *(.rodata*) } :text
20+
.text : ALIGN(16) { *(.text*) } :text
21+
22+
/DISCARD/ : {
23+
*(.data .data.* .sdata*)
24+
*(.bss .bss.* .sbss .sbss.*)
25+
*(.comment*)
26+
*(.note*)
27+
*(.eh_frame*)
28+
*(.interp)
29+
}
30+
}
31+
32+
PHDRS
33+
{
34+
text PT_LOAD FLAGS(5) FILEHDR PHDRS;
35+
dynamic PT_DYNAMIC FLAGS(4);
36+
}
37+
38+
VERSION
39+
{
40+
LINUX_2.6 {
41+
global:
42+
__vdso_clock_gettime;
43+
local:
44+
*;
45+
};
46+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#ifndef RT_VDSO_ARCH_H
2+
#define RT_VDSO_ARCH_H
3+
4+
#include <stdint.h>
5+
6+
#define __RT_STRINGIFY(x...) #x
7+
#define RT_STRINGIFY(x...) __RT_STRINGIFY(x)
8+
9+
#define rt_vdso_arch_barrier(cmd, ...) \
10+
__asm__ volatile(RT_STRINGIFY(cmd) " " RT_STRINGIFY(__VA_ARGS__)::: "memory")
11+
12+
static inline uint64_t rt_vdso_arch_read_counter(void)
13+
{
14+
uint32_t lo;
15+
uint32_t hi;
16+
17+
__asm__ volatile("mrrc p15, 1, %0, %1, c14" : "=r"(lo), "=r"(hi));
18+
rt_vdso_arch_barrier(dmb, ish);
19+
20+
return ((uint64_t)hi << 32) | lo;
21+
}
22+
23+
static inline void rt_vdso_arch_cpu_relax(void)
24+
{
25+
__asm__ volatile("yield" ::: "memory");
26+
}
27+
28+
static inline void rt_vdso_arch_rmb(void)
29+
{
30+
rt_vdso_arch_barrier(dmb, ish);
31+
}
32+
33+
#endif

components/lwp/vdso/vdso_constants.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ extern "C" {
3232

3333
#if defined(__aarch64__)
3434
#define RT_VDSO_IMAGE_PATH "../user/build/aarch64/libvdso.so"
35+
#elif defined(__arm__)
36+
#define RT_VDSO_IMAGE_PATH "../user/build/arm/libvdso.so"
3537
#elif defined(__riscv)
3638
#define RT_VDSO_IMAGE_PATH "../user/build/risc-v/libvdso.so"
3739
#else

components/lwp/vdso/vdso_data_page.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ extern "C" {
2222

2323
#define RT_VDSO_CLOCK_ID_MAX 16
2424
#define RT_VDSO_NSEC_PER_SEC 1000000000ULL
25-
#define RT_VDSO_FLAG_REALTIME_VALID (1U << 0)
25+
#define RT_VDSO_FLAG_REALTIME_VALID (1ULL << 0)
2626

2727
enum rt_vdso_clock_data_index
2828
{
@@ -34,7 +34,8 @@ enum rt_vdso_clock_data_index
3434
struct rt_vdso_data_page
3535
{
3636
uint32_t seq_counter;
37-
uint32_t flags;
37+
uint32_t reserved0;
38+
uint64_t flags;
3839
uint64_t counter_last;
3940
uint64_t counter_freq;
4041
struct timespec base_time[RT_VDSO_CLOCK_DATA_COUNT];

0 commit comments

Comments
 (0)