Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial support for embedded sandboxed code #174

Merged
merged 6 commits into from
Jun 30, 2024

Conversation

fwsGonzo
Copy link
Owner

@fwsGonzo fwsGonzo commented Jun 29, 2024

This allows platforms with no support for dynamic linking to ship with full binary translation performance

$ VERBOSE=1 ./rvlinux -v ~/github/coremark/coremark-rv32g_b
* Loading program of size 75145 from 0x7402800d1010 to virtual 0x10000 -> 0x22589
* Program segment readable: 1 writable: 0  executable: 1
* Loading program of size 1864 from 0x7402800e359c to virtual 0x2358c -> 0x23cd4
* Program segment readable: 1 writable: 1  executable: 0
Checking for embedded translations
Found embedded translation for hash 808A7861
* Entry is at 0x109f4
2K performance run parameters for coremark.
CoreMark Size    : 666
Total ticks      : 17261
Total time (secs): 17.261000
Iterations/Sec   : 34760.442616
Iterations       : 600000
Compiler version : GCC13.2.0
Compiler flags   : -O3 -DPERFORMANCE_RUN=1  
Memory location  : Please put data memory location here
			(e.g. code in flash, data on heap etc)
seedcrc          : 0xe9f5
[0]crclist       : 0xe714
[0]crcmatrix     : 0x1fd7
[0]crcstate      : 0x8e3a
[0]crcfinal      : 0xa14c
Correct operation validated. See README.md for run and reporting rules.
CoreMark 1.0 : 34760.442616 / GCC13.2.0 -O3 -DPERFORMANCE_RUN=1   / Static
>>> Program exited, exit code = 0 (0x0)
Runtime: 20463.291ms   (Use --accurate for instruction counting)
Pages in use: 25 (100 kB virtual memory, total 318 kB)

$ rm /tmp/rvbintr-*
rm: cannot remove '/tmp/rvbintr-*': No such file or directory

This feature is not done yet. What's missing:

  • Even though many embeddings are supported, in practice they need some prefixing to avoid collisions
  • When emitting code, sometimes there are several execute segments, and currently only one file is output. Change back to using hash in filename?
  • Some polishing needed, eg. Machine doesn't report using binary translation when this is enabled, unfortunately
  • Explore ways to make this mode faster, as we are embedding sandboxed code. It may be possible to apply more optimizations

This allows platforms with no support for dynamic linking to ship with full binary translation performance
@fwsGonzo fwsGonzo added the enhancement New feature or request label Jun 29, 2024
@fire
Copy link
Contributor

fire commented Jun 30, 2024

Would it help if i got this compiling on the mac?

Edited:

What do you need help on? I am not very familiar with the code base.

@fire
Copy link
Contributor

fire commented Jun 30, 2024

git clone https://github.com/fwsGonzo/libriscv.git -b embedded_sandbox_code
cd libriscv
cd emulator
./build.sh
./rvlinux -o test.cpp ~/github/coremark/coremark-rv32g_b
./build.sh --embed test.cpp
VERBOSE=1 ./rvlinux -v ~/github/coremark/coremark-rv32g_b

Testing on windows pending.

@fwsGonzo
Copy link
Owner Author

If you can test on Windows and MacOS, that would be great. Otherwise, I don't need much help with this part. It just needs some time to complete.

Embeddable generated files now use prefix/suffix
Also, store MachineOptions in the Machine in order to create the correct future segments
@fwsGonzo
Copy link
Owner Author

fwsGonzo commented Jun 30, 2024

$ file stream.dyn 
stream.dyn: ELF 64-bit LSB pie executable, UCB RISC-V, RVC, double-float ABI, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-riscv64-lp64d.so.1, BuildID[sha1]=3285afbf8540c5a92c050372cb4a2b201f7de4b3, for GNU/Linux 4.15.0, not stripped

$ VERBOSE=1 ./rvlinux -v ../binaries/STREAM/stream.dyn
* Loading program of size 122176 from 0x733f04f2c010 to virtual 0x40000 -> 0x5dd40
* Program segment readable: 1 writable: 0  executable: 1
* Loading program of size 9432 from 0x733f04f4ac38 to virtual 0x5fc28 -> 0x62100
* Program segment readable: 1 writable: 1  executable: 0
Checking for embedded translations
Found embedded translation for hash 4B857279
* Entry is at 0x515a4
Guest wanted to open: /etc/ld.so.cache (denied)
Guest wanted to open: /lib/riscv64-linux-gnu/tls/RISC-V 64-bit/libc.so.6 (denied)
Guest wanted to open: /lib/riscv64-linux-gnu/tls/libc.so.6 (denied)
Guest wanted to open: /lib/riscv64-linux-gnu/RISC-V 64-bit/libc.so.6 (denied)
Checking for embedded translations
Found embedded translation for hash E4FF3F9D
Checking for embedded translations
Found embedded translation for hash D2C89D07
-------------------------------------------------------------
STREAM version $Revision: 5.10 $
-------------------------------------------------------------
This system uses 4 bytes per array element.
-------------------------------------------------------------
Array size = 20000000 (elements), Offset = 0 (elements)
Memory per array = 76.3 MiB (= 0.1 GiB).
Total memory required = 228.9 MiB (= 0.2 GiB).
Each kernel will be executed 10 times.
 The *best* time for each kernel (excluding the first iteration)
 will be used to compute the reported bandwidth.
-------------------------------------------------------------
Your clock granularity/precision appears to be 1 microseconds.
Each test below will take on the order of 7565 microseconds.
   (= 7565 clock ticks)
Increase the size of the arrays if this shows that
you are not getting at least 20 clock ticks per test.
-------------------------------------------------------------
WARNING -- The above is only a rough guideline.
For best results, please be sure you know the
precision of your system timer.
-------------------------------------------------------------
Function    Best Rate MB/s  Avg time     Min time     Max time
Copy:           35265.6     0.004624     0.004537     0.004805
Scale:          33016.9     0.004874     0.004846     0.004937
Add:            32515.9     0.007476     0.007381     0.007555
Triad:          31545.7     0.007706     0.007608     0.007775
-------------------------------------------------------------
Solution Validates: avg error less than 1.000000e-06 on all three arrays
-------------------------------------------------------------
>>> Program exited, exit code = 0 (0x0)
Runtime: 339.739ms   (Use --accurate for instruction counting)
Pages in use: 58945 (235780 kB virtual memory, total 245025 kB)

This is an embedded dynamic executable with 3 execute segments. The first one is the dynamic linker loader, and the other two are the program and libc.so.

@fwsGonzo fwsGonzo merged commit ee1e831 into master Jun 30, 2024
22 checks passed
@fwsGonzo fwsGonzo deleted the embedded_sandbox_code branch June 30, 2024 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants