1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

RISCV: Patch ST and libsrtp. #3115

This commit is contained in:
Steven Liu 2022-07-20 21:53:39 +08:00 committed by winlin
parent 8a6fa30992
commit 08c4b25030
6 changed files with 187 additions and 38 deletions

View file

@ -1,9 +1,9 @@
# state-threads
![](http://ossrs.net:8000/gif/v1/sls.gif?site=github.com&path=/srs/srsst)
[![](https://circleci.com/gh/ossrs/state-threads/tree/srs.svg?style=svg&circle-token=1ef1d5b5b0cde6c8c282ed856a18199f9e8f85a9)](https://circleci.com/gh/ossrs/state-threads/tree/srs)
[![](https://github.com/ossrs/state-threads/actions/workflows/test.yml/badge.svg?branch=srs)](https://github.com/ossrs/state-threads/actions?query=workflow%3ATest+branch%3Asrs)
[![](https://codecov.io/gh/ossrs/state-threads/branch/srs/graph/badge.svg)](https://codecov.io/gh/ossrs/state-threads/branch/srs)
[![](https://cloud.githubusercontent.com/assets/2777660/22814959/c51cbe72-ef92-11e6-81cc-32b657b285d5.png)](https://github.com/ossrs/srs/wiki/v1_CN_Contact#wechat)
[![](https://cloud.githubusercontent.com/assets/2777660/22814959/c51cbe72-ef92-11e6-81cc-32b657b285d5.png)](https://github.com/ossrs/srs/wiki/Contact#wechat)
Fork from http://sourceforge.net/projects/state-threads, patched for [SRS](https://github.com/ossrs/srs/tree/2.0release).
@ -15,7 +15,7 @@ For original ST without any changes, checkout the [ST master branch](https://git
[state-threads](https://github.com/ossrs/state-threads/blob/srs/README#L68) is licenced under [MPL or GPLv2](https://github.com/ossrs/srs/wiki/LicenseMixing#state-threads).
## Usage
## Linux: Usage
Get code:
@ -29,18 +29,6 @@ For Linux:
make linux-debug
```
For OSX:
```bash
make darwin-debug
```
For Cygwin(Windows):
```
make cygwin64-debug
```
For Linux aarch64, which fail with `Unknown CPU architecture`:
```bash
@ -61,13 +49,43 @@ Linux with valgrind and epoll:
make linux-debug EXTRA_CFLAGS="-DMD_HAVE_EPOLL -DMD_VALGRIND"
```
## Mac: Usage
Get code:
```bash
git clone -b srs https://github.com/ossrs/state-threads.git
```
For OSX:
```bash
make darwin-debug
```
For OSX, user must specifies the valgrind header files:
```bash
make darwin-debug EXTRA_CFLAGS="-DMD_HAVE_KQUEUE -DMD_VALGRIND -I/usr/local/include"
```
> Remark: Latest OSX does not support ST, please use docker to run ST.
> Remark: M1 is unsupported by ST, please use docker to run, please read [SRS#2747](https://github.com/ossrs/srs/issues/2747).
## Windows: Usage
Get code:
```bash
git clone -b srs https://github.com/ossrs/state-threads.git
```
For Cygwin(Windows):
```
make cygwin64-debug
```
> Remark: Windows native build is unsupported right now.
## Branch SRS
@ -89,7 +107,10 @@ The branch [srs](https://github.com/ossrs/state-threads/tree/srs) will be patche
- [x] System: Improve the performance of timer. [9fe8cfe5b](https://github.com/ossrs/state-threads/commit/9fe8cfe5b1c9741a2e671a46215184f267fba400), [7879c2b](https://github.com/ossrs/state-threads/commit/7879c2b), [387cddb](https://github.com/ossrs/state-threads/commit/387cddb)
- [x] Windows: Support Windows 64bits. [#20](https://github.com/ossrs/state-threads/issues/20).
- [x] MIPS: Support Linux/MIPS for OpenWRT, [#21](https://github.com/ossrs/state-threads/issues/21).
- [ ] System: Support Multiple Threads for Linux and Darwin. [#19](https://github.com/ossrs/state-threads/issues/19), [srs#2188](https://github.com/ossrs/srs/issues/2188).
- [x] LOONGARCH: Support loongarch for loongson CPU, [#24](https://github.com/ossrs/state-threads/issues/24).
- [x] System: Support Multiple Threads for Linux and Darwin. [#19](https://github.com/ossrs/state-threads/issues/19), [srs#2188](https://github.com/ossrs/srs/issues/2188).
- [x] RISCV: Support RISCV for RISCV CPU, [#24](https://github.com/ossrs/state-threads/pull/28).
- [ ] IDE: Support CLion for debugging and learning.
- [ ] System: Support sendmmsg for UDP, [#12](https://github.com/ossrs/state-threads/issues/12).
## GDB Tools
@ -110,23 +131,51 @@ Important cli options:
1. `--track-origins=<yes|no> [default: no]`, Controls whether Memcheck tracks the origin of uninitialised values. By default, it does not, which means that although it can tell you that an uninitialised value is being used in a dangerous way, it cannot tell you where the uninitialised value came from. This often makes it difficult to track down the root problem.
1. `--show-reachable=<yes|no> , --show-possibly-lost=<yes|no>`, to show the using memory.
## UTest and Coverage
## Linux: UTest
First of all, download [google test](https://github.com/google/googletest/releases/tag/release-1.6.0) to `utest/gtest`, check by:
> Note: We use [Google test](https://github.com/google/googletest/releases/tag/release-1.11.0) in `utest/gtest-fit`.
To make ST with utest and run it:
```bash
ls -lh utest/gtest/include/gtest/gtest.h >/dev/null && echo yes
make linux-debug-utest && ./obj/st_utest
```
Note that the gcc(4.8) of CentOS is too old, please use docker(`ossrs/srs:dev-gcc7`) to run:
```bash
docker run --rm -it -v $(pwd):/state-threads -w /state-threads \
registry.cn-hangzhou.aliyuncs.com/ossrs/srs:dev-gcc7 \
bash -c 'make linux-debug-utest && ./obj/st_utest'
```
## Mac: UTest
> Note: We use [Google test](https://github.com/google/googletest/releases/tag/release-1.11.0) in `utest/gtest-fit`.
To make ST with utest and run it:
```bash
make darwin-debug-utest && ./obj/st_utest
```
## Linux: Coverage
> Note: We use [Google test](https://github.com/google/googletest/releases/tag/release-1.11.0) in `utest/gtest-fit`.
To make ST with utest and run it:
```bash
make linux-debug-gcov && ./obj/st_utest
```
> For macOS: `make darwin-debug-gcov && ./obj/st_utest`
Note that the gcc(4.8) of CentOS is too old, please use docker(`ossrs/srs:dev-gcc7`) to run:
> Run utest without coverage: `make darwin-debug-utest && ./obj/st_utest`
```bash
docker run --rm -it -v $(pwd):/state-threads -w /state-threads \
registry.cn-hangzhou.aliyuncs.com/ossrs/srs:dev-gcc7 \
bash -c 'make linux-debug-gcov && ./obj/st_utest'
```
Then, install [gcovr](https://gcovr.com/en/stable/guide.html) for coverage:
@ -135,19 +184,29 @@ yum install -y python2-pip &&
pip install lxml && pip install gcovr
```
> For macOS: `pip3 install gcovr`
Finally, run test and get the report
Finally, run test and get the report:
```bash
mkdir -p coverage &&
gcovr -r . -e LINUX -e DARWIN -e examples --html --html-details -o coverage/st.html &&
open coverage/st.html
bash auto/coverage.sh
```
> Note: We ignore `LINUX*` and `DARWIN*` which is `obj` actually.
## Mac: Coverage
Or just run locally:
> Note: We use [Google test](https://github.com/google/googletest/releases/tag/release-1.11.0) in `utest/gtest-fit`.
To make ST with utest and run it:
```bash
make darwin-debug-gcov && ./obj/st_utest
```
Then, install [gcovr](https://gcovr.com/en/stable/guide.html) for coverage:
```bash
pip install gcovr
```
Finally, run test and get the report:
```bash
bash auto/coverage.sh
@ -160,11 +219,19 @@ bash auto/coverage.sh
* Programming notes: http://ossrs.github.io/state-threads/docs/notes.html
* [How to porting ST to other OS/CPU?](https://github.com/ossrs/state-threads/issues/22)
* About setjmp and longjmp, read [setjmp](https://ossrs.net/wiki/images/st-setjmp.jpg).
* About the stack structure, read [stack](https://ossrs.net/wiki/images/st-stack.jpg)
* About setjmp and longjmp, read [setjmp](https://gitee.com/winlinvip/srs-wiki/raw/master/images/st-setjmp.jpg).
* About the stack structure, read [stack](https://gitee.com/winlinvip/srs-wiki/raw/master/images/st-stack.jpg)
* About asm code comments, read [#91d530e](https://github.com/ossrs/state-threads/commit/91d530e#diff-ed9428b14ff6afda0e9ab04cc91d4445R25).
* About the scheduler, read [#13-scheduler](https://github.com/ossrs/state-threads/issues/13#issuecomment-616025527).
* About the IO event system, read [#13-IO](https://github.com/ossrs/state-threads/issues/13#issuecomment-616096568).
* Code analysis, please read [#15](https://github.com/ossrs/state-threads/issues/15).
## CLion
Use [CLion](https://www.jetbrains.com/clion/) to open directory state-threads.
Then, open `ide/st_clion/CMakeLists.txt` and click `Load CMake project`.
Finally, select a configuration to run or debug.
Winlin 2016

View file

@ -186,6 +186,10 @@
/* https://github.com/ossrs/state-threads/issues/21 */
#define MD_USE_BUILTIN_SETJMP
#define MD_GET_SP(_t) *((long *)&((_t)->context[0].__jb[0]))
#elif defined(__riscv)
/* https://github.com/ossrs/state-threads/pull/28 */
#define MD_USE_BUILTIN_SETJMP
#define MD_GET_SP(_t) *((long *)&((_t)->context[0].__jmpbuf[0]))
#elif defined(__loongarch__)
/* https://github.com/ossrs/state-threads/issues/24 */

View file

@ -352,6 +352,82 @@
#elif defined(__riscv)
/****************************************************************/
/*
* Internal __jmp_buf layout
* riscv-asm: https://github.com/riscv/riscv-asm-manual/blob/master/riscv-asm.md
*/
#define JB_SP 0 /* A0, SP, Stack pointer */
#define JB_RA 1 /* RA, Return address */
#define JB_FP 2 /* FP/S0 Frame pointer */
#define JB_S1 3 /* S1 Saved register*/
#define JB_S2 4 /* S2-S11, Saved register */
#define JB_S3 5 /* S2-S11, Saved register */
#define JB_S4 6 /* S2-S11, Saved register */
#define JB_S5 7 /* S2-S11, Saved register */
#define JB_S6 8 /* S2-S11, Saved register */
#define JB_S7 9 /* S2-S11, Saved register */
#define JB_S8 10 /* S2-S11, Saved register */
#define JB_S9 11 /* S2-S11, Saved register */
#define JB_S10 12 /* S2-S11, Saved register */
#define JB_S11 13 /* S2-S11, Saved register */
.file "md_linux.S"
.text
/* _st_md_cxt_save(__jmp_buf env) */ /* The env is $a0, https://en.wikipedia.org/wiki/RISC-V#Register_sets */
.globl _st_md_cxt_save
.type _st_md_cxt_save, %function
.align 2
_st_md_cxt_save:
sd sp, JB_SP * 8(a0)
sd ra, JB_RA * 8(a0)
sd s0, JB_FP * 8(a0)
sd s1, JB_S1 * 8(a0)
sd s2, JB_S2 * 8(a0)
sd s3, JB_S3 * 8(a0)
sd s4, JB_S4 * 8(a0)
sd s5, JB_S5 * 8(a0)
sd s6, JB_S6 * 8(a0)
sd s7, JB_S7 * 8(a0)
sd s8, JB_S8 * 8(a0)
sd s9, JB_S9 * 8(a0)
sd s10, JB_S10 * 8(a0)
sd s11, JB_S11 * 8(a0)
li a0, 0
jr ra
.size _st_md_cxt_save, .-_st_md_cxt_save
/****************************************************************/
/* _st_md_cxt_restore(__jmp_buf env, int val) */
.globl _st_md_cxt_restore
.type _st_md_cxt_restore, %function
.align 2
_st_md_cxt_restore:
ld sp, JB_SP * 8(a0)
ld ra, JB_RA * 8(a0)
ld s0, JB_FP * 8(a0)
ld s1, JB_S1 * 8(a0)
ld s2, JB_S2 * 8(a0)
ld s3, JB_S3 * 8(a0)
ld s4, JB_S4 * 8(a0)
ld s5, JB_S5 * 8(a0)
ld s6, JB_S6 * 8(a0)
ld s7, JB_S7 * 8(a0)
ld s8, JB_S8 * 8(a0)
ld s9, JB_S9 * 8(a0)
ld s10, JB_S10 * 8(a0)
ld s11, JB_S11 * 8(a0)
li a0, 1
jr ra
.size _st_md_cxt_restore, .-_st_md_cxt_restore
/****************************************************************/