Skip to content

Commit 9e6a072

Browse files
add DMA by offset feature, SHM POSIX example, and support for args with benchmarking (#158)
* add SHM POSIX example * refactor POSIX example * adjust CI test for refactor * make example variables unique * refactor examples from feedback, provide arguments for benchmark application, add dma posix transport * remove debug prints and usleep call * add -lm to client build for DH and initialize variable value * fix for address set after rebase * account for potential overflow and resolve syntax * fix initialization of config structs in test case * simplify DMA feature and move NVM+RAMSIM into cfg file * add macro guard for example * revert comment out of no malloc define in example user settings header * format fixes from git-clang-format * update example README and change DMA ADDR macro to be generic * remove unnecessary includes * refactor out common DMA code sections * rename example functions and run test all * add sanity check on benchnark transport type * additional macro guards after rebase * remove explicit set of dma config in test app, void return on functions that are intentionally not checked * update examples Makefile and comments * fixes to examples README * re-run git-clang-format * function and file rename, endif comments, fix examples README, macro guard on include * rename example functions for better clarity * narrow scope of heap hint set and get functions, make it specific to posix + shm + dma * adjustments to example Makefiles * fix typo in benchmark printf and run git-clang-format * run clang-format on posix_transport_shm.c to help out git-clang-format CI test
1 parent 53df12a commit 9e6a072

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+2642
-1045
lines changed

.github/workflows/build-and-run-examples.yml

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ on:
88

99
jobs:
1010
build:
11-
11+
strategy:
12+
matrix:
13+
transport: [ 'tcp', 'shm', 'dma' ]
1214
runs-on: ubuntu-latest
15+
timeout-minutes: 5
1316

1417
steps:
1518
- uses: actions/checkout@master
@@ -22,28 +25,38 @@ jobs:
2225
path: wolfssl
2326

2427
# Build examples
25-
- name: Build POSIX TCP server
26-
run: cd examples/posix/tcp/wh_server_tcp && make -j WOLFSSL_DIR=../../../../wolfssl
27-
- name: Build POSIX TCP client
28-
run: cd examples/posix/tcp/wh_client_tcp && make -j WOLFSSL_DIR=../../../../wolfssl
28+
- name: Build POSIX server
29+
run: |
30+
if [ "${{ matrix.transport }}" = "dma" ]; then
31+
cd examples/posix/wh_posix_server && DMA=1 make -j WOLFSSL_DIR=../../../wolfssl
32+
else
33+
cd examples/posix/wh_posix_server && make -j WOLFSSL_DIR=../../../wolfssl
34+
fi
35+
- name: Build POSIX client
36+
run: |
37+
if [ "${{ matrix.transport }}" = "dma" ]; then
38+
cd examples/posix/wh_posix_client && DMA=1 make -j WOLFSSL_DIR=../../../wolfssl
39+
else
40+
cd examples/posix/wh_posix_client && make -j WOLFSSL_DIR=../../../wolfssl
41+
fi
2942
3043
# Start the server in the background
31-
- name: Run POSIX TCP server
44+
- name: Run POSIX server
3245
run: |
33-
cd examples/posix/tcp/wh_server_tcp
34-
./Build/wh_server_tcp.elf &
35-
TCP_SERVER_PID=$!
36-
echo "TCP_SERVER_PID=$TCP_SERVER_PID" >> $GITHUB_ENV
46+
cd examples/posix/wh_posix_server
47+
./Build/wh_posix_server.elf --type ${{ matrix.transport }} &
48+
POSIX_SERVER_PID=$!
49+
echo "POSIX_SERVER_PID=$POSIX_SERVER_PID" >> $GITHUB_ENV
3750
3851
# Run the client that connects to the server
39-
- name: Run POSIX TCP client
52+
- name: Run POSIX client
4053
run: |
41-
cd examples/posix/tcp/wh_client_tcp
42-
./Build/wh_client_tcp.elf
54+
cd examples/posix/wh_posix_client
55+
./Build/wh_posix_client.elf --type ${{ matrix.transport }}
4356
4457
# Optional: Kill the server process if it doesn't exit on its own
45-
- name: Cleanup POSIX TCP server
58+
- name: Cleanup POSIX server
4659
if: always()
47-
run: kill $TCP_SERVER_PID || true
60+
run: kill $POSIX_SERVER_PID || true
4861

4962

.github/workflows/build-and-test-clientonly.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,18 @@ jobs:
2828
with:
2929
repository: wolfssl/wolfssl
3030
path: wolfssl
31-
31+
3232
# Build example server
33-
- name: Build POSIX TCP server
33+
- name: Build POSIX server
3434
run: |
35-
cd examples/posix/tcp/wh_server_tcp
36-
make -j SHE=1 WOLFSSL_DIR=../../../../wolfssl
35+
cd examples/posix/wh_posix_server
36+
make -j SHE=1 WOLFSSL_DIR=../../../wolfssl
3737
3838
# Start the server in the background
39-
- name: Run POSIX TCP server
39+
- name: Run POSIX server
4040
run: |
41-
cd examples/posix/tcp/wh_server_tcp
42-
./Build/wh_server_tcp.elf &
41+
cd examples/posix/wh_posix_server
42+
./Build/wh_posix_server.elf &
4343
TCP_SERVER_PID=$!
4444
echo "TCP_SERVER_PID=$TCP_SERVER_PID" >> $GITHUB_ENV
4545
@@ -54,4 +54,4 @@ jobs:
5454
- name: Cleanup POSIX TCP server
5555
if: always()
5656
run: kill $TCP_SERVER_PID || true
57-
57+

benchmark/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ CFLAGS += $(DBGFLAGS)
7373
LDFLAGS += $(DBGFLAGS)
7474
endif
7575

76+
ifneq ($(DEBUG),1)
77+
CFLAGS += -O2
78+
endif
79+
80+
7681
# Add address sanitizer option
7782
ifeq ($(ASAN),1)
7883
CFLAGS += -fsanitize=address
@@ -133,7 +138,6 @@ SRC_C += $(wildcard $(PROJECT_DIR)/*.c)
133138
SRC_C += $(wildcard $(MODULES_DIR)/*.c)
134139

135140
## Automated processing below
136-
137141
FILENAMES_C = $(notdir $(SRC_C))
138142
OBJS_C = $(addprefix $(BUILD_DIR)/, $(FILENAMES_C:.c=.o))
139143
vpath %.c $(dir $(SRC_C))

benchmark/bench_modules/wh_bench_mod_sha2.c

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,17 @@
1919
#include "wh_bench_mod.h"
2020

2121
#include "wolfhsm/wh_error.h"
22+
#include "wolfhsm/wh_client_crypto.h"
2223

2324
#include "wolfssl/wolfcrypt/hash.h"
2425
#include "wolfssl/wolfcrypt/sha256.h"
2526

2627
#if defined(WOLFHSM_CFG_BENCH_ENABLE)
2728

29+
#if defined(WOLFHSM_CFG_DMA) && defined(WOLFHSM_CFG_TEST_POSIX)
30+
#include "port/posix/posix_transport_shm.h"
31+
#endif /* WOLFHSM_CFG_DMA && WOLFHSM_CFG_POSIX_TRANSPORT */
32+
2833
#if !defined(NO_SHA256)
2934

3035
int _benchSha256(whClientContext* client, whBenchOpContext* ctx, int id,
@@ -33,17 +38,39 @@ int _benchSha256(whClientContext* client, whBenchOpContext* ctx, int id,
3338
(void)client;
3439

3540
int ret = 0;
36-
wc_Sha256 sha256[1];
37-
uint8_t out[WC_SHA256_DIGEST_SIZE];
41+
wc_Sha256* sha256 = NULL;
42+
wc_Sha256 sha256Stack;
43+
uint8_t outStack[WC_SHA256_DIGEST_SIZE];
44+
uint8_t* out;
3845
int i = 0;
3946
int sha256Initialized = 0;
4047
const uint8_t* in;
4148
size_t inLen;
4249

50+
sha256 = &sha256Stack;
51+
out = outStack;
52+
4353
#if defined(WOLFHSM_CFG_DMA)
4454
if (devId == WH_DEV_ID_DMA) {
45-
in = WH_BENCH_DMA_BUFFER;
4655
inLen = WOLFHSM_CFG_BENCH_DMA_BUFFER_SIZE;
56+
if (ctx->transportType == WH_BENCH_TRANSPORT_POSIX_DMA) {
57+
/* if static memory was used with DMA then use XMALLOC */
58+
void* heap =
59+
posixTransportShm_GetDmaHeap(client->comm->transport_context);
60+
in = XMALLOC(inLen, heap, DYNAMIC_TYPE_TMP_BUFFER);
61+
if (in == NULL) {
62+
WH_BENCH_PRINTF("Failed to allocate memory for DMA\n");
63+
return WH_ERROR_NOSPACE;
64+
}
65+
out = XMALLOC(WC_SHA256_DIGEST_SIZE, heap, DYNAMIC_TYPE_TMP_BUFFER);
66+
if (out == NULL) {
67+
WH_BENCH_PRINTF("Failed to allocate memory for DMA\n");
68+
return WH_ERROR_NOSPACE;
69+
}
70+
}
71+
else {
72+
in = WH_BENCH_DMA_BUFFER;
73+
}
4774
}
4875
else
4976
#endif
@@ -111,6 +138,16 @@ int _benchSha256(whClientContext* client, whBenchOpContext* ctx, int id,
111138
(void)wc_Sha256Free(sha256);
112139
}
113140

141+
#if defined(WOLFHSM_CFG_DMA)
142+
if (devId == WH_DEV_ID_DMA &&
143+
ctx->transportType == WH_BENCH_TRANSPORT_POSIX_DMA) {
144+
/* if static memory was used with DMA then use XFREE */
145+
void* heap =
146+
posixTransportShm_GetDmaHeap(client->comm->transport_context);
147+
XFREE((uint8_t*)in, heap, DYNAMIC_TYPE_TMP_BUFFER);
148+
XFREE(out, heap, DYNAMIC_TYPE_TMP_BUFFER);
149+
}
150+
#endif
114151
return ret;
115152
}
116153

benchmark/config/user_settings.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,11 @@ extern "C" {
197197
#endif
198198
#endif
199199

200+
#ifdef WOLFHSM_CFG_DMA
201+
/* use static memory to divide up DMA shared buffer */
202+
#undef WOLFSSL_STATIC_MEMORY
203+
#define WOLFSSL_STATIC_MEMORY
204+
#endif
200205

201206
#ifdef __cplusplus
202207
}

benchmark/config/wolfhsm_cfg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#define WOLFHSM_CFG_SERVER_KEYCACHE_BUFSIZE 300
3636
#define WOLFHSM_CFG_SERVER_KEYCACHE_BIG_COUNT 2
3737
#define WOLFHSM_CFG_SERVER_KEYCACHE_BIG_BUFSIZE WOLFHSM_CFG_COMM_DATA_LEN
38-
#define WOLFHSM_CFG_SERVER_DMAADDR_COUNT 8
38+
#define WOLFHSM_CFG_DMAADDR_COUNT 8
3939
#define WOLFHSM_CFG_SERVER_CUSTOMCB_COUNT 6
4040

4141
#define WOLFHSM_CFG_CERTIFICATE_MANAGER

0 commit comments

Comments
 (0)