Skip to content

Commit

Permalink
RISCV: Patch ST and libsrtp. #3115
Browse files Browse the repository at this point in the history
  • Loading branch information
T-bagwell authored and winlinvip committed Jul 20, 2022
1 parent 8a6fa30 commit 08c4b25
Show file tree
Hide file tree
Showing 6 changed files with 186 additions and 37 deletions.
6 changes: 0 additions & 6 deletions trunk/3rdparty/libsrtp-2-fit/config.guess
Original file line number Diff line number Diff line change
Expand Up @@ -1032,12 +1032,6 @@ EOF
ppcle:Linux:*:*)
echo powerpcle-unknown-linux-${LIBC}
exit ;;
riscv:Linux:*:*)
echo riscv-unknown-linux-${LIBC}
exit ;;
riscv64:Linux:*:*)
echo riscv64-unknown-linux-${LIBC}
exit ;;
s390:Linux:*:* | s390x:Linux:*:*)
echo ${UNAME_MACHINE}-ibm-linux-${LIBC}
exit ;;
Expand Down
7 changes: 7 additions & 0 deletions trunk/3rdparty/patches/srtp/config.guess-02.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
1034a1035,1040
> riscv:Linux:*:*)
> echo riscv-unknown-linux-${LIBC}
> exit ;;
> riscv64:Linux:*:*)
> echo riscv64-unknown-linux-${LIBC}
> exit ;;
129 changes: 98 additions & 31 deletions trunk/3rdparty/st-srs/README.md
Original file line number Diff line number Diff line change
@@ -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).

Expand All @@ -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:

Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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

> 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-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

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 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:

Expand All @@ -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
bash auto/coverage.sh
```

## Mac: 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
mkdir -p coverage &&
gcovr -r . -e LINUX -e DARWIN -e examples --html --html-details -o coverage/st.html &&
open coverage/st.html
make darwin-debug-gcov && ./obj/st_utest
```

> Note: We ignore `LINUX*` and `DARWIN*` which is `obj` actually.
Then, install [gcovr](https://gcovr.com/en/stable/guide.html) for coverage:

```bash
pip install gcovr
```

Or just run locally:
Finally, run test and get the report:

```bash
bash auto/coverage.sh
Expand All @@ -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
4 changes: 4 additions & 0 deletions trunk/3rdparty/st-srs/md.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
76 changes: 76 additions & 0 deletions trunk/3rdparty/st-srs/md_linux.S
Original file line number Diff line number Diff line change
Expand Up @@ -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

/****************************************************************/




Expand Down
1 change: 1 addition & 0 deletions trunk/auto/depends.sh
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,7 @@ if [[ $SRS_RTC == YES ]]; then
rm -rf ${SRS_OBJS}/srtp2 && cd ${SRS_OBJS}/${SRS_PLATFORM} &&
rm -rf libsrtp-2-fit && cp -R ../../3rdparty/libsrtp-2-fit . && cd libsrtp-2-fit &&
patch -p0 crypto/math/datatypes.c ../../../3rdparty/patches/srtp/gcc10-01.patch &&
patch -p0 config.guess ../../../3rdparty/patches/srtp/config.guess-02.patch &&
$SRTP_CONFIGURE ${SRTP_OPTIONS} --prefix=`pwd`/_release &&
make ${SRS_JOBS} && make install &&
cd .. && rm -rf srtp2 && ln -sf libsrtp-2-fit/_release srtp2
Expand Down

0 comments on commit 08c4b25

Please sign in to comment.