#include <pthread.h>
I use this line code in Arm Development Studio built-in sve_array_subtract example and has build errors that "pthread.h" file not found. How to solve it, I wanna use both multi-thread and sve instrinsics in the project.
HiMy name is Stephen and I work at Arm.The "sve_array_subtract" example in Arm Development Studio is a bare-metal example that compiles with "Arm Compiler for Embedded 6", so is not designed to work with pthreads.To use pthreads with it, you would need to convert the example from bare-metal to a Linux Application, and change the compiler from Arm Compiler for Embedded 6 to GCC for Linux (e.g. aarch64-none-linux-gnu), which you can download from developer.arm.com/.../arm-gnu-toolchain-downloadsThe "threads_v8A" example in Arm Development Studio shows the use of pthreads in a gcc-built Linux Application, so you could use that as a starting point for your conversion.Hope this helpsStephen
Thks, I met another mistake. I changed a simple Hello-World project, the target CPU choose armv9.2, and the FVP is AEMvAx1, and set semihosting-enable = 0 in model parameter, and when using memcpy to copy a struct to another destination struct, the value is incorrect, the code is
typedef struct { int width; int height; } init_param; typedef struct { init_param param; int flag; } test_handle; int main(int argc, char *argv[]) { uint8_t *a_buf = (uint8_t *)malloc(300000); printf("a_buf:%p\n", a_buf); printf("argc:%d\n", argc); for(int i=0; i<argc; i++) { printf("[%d] is %s\n", i, argv[i]); } init_param param22; param22.width = 3000; param22.height = 4000; test_handle *pHandle = (test_handle *)calloc(1, sizeof(test_handle)); printf("sizeof(test_handle) = %zu\n", sizeof(test_handle)); printf("offsetof(param):%zu\n", offsetof(test_handle, param)); printf("offsetof(flag):%zu\n", offsetof(test_handle, flag)); printf("pHandle:%p\n", pHandle); printf("param:%p\n", &pHandle->param); printf("flag:%p\n", &pHandle->flag); printf("sizeof(init_param):%zu\n", sizeof(init_param)); printf("param22:%p\n", ¶m22); printf("width:%p\n", ¶m22.width); test_handle pHandle1; pHandle1.param=param22; pHandle->param=param22; memcpy(&pHandle->param, ¶m22, sizeof(init_param)); cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!! return 0; }
The struct offset and address seems right, offset of flag in test_handle is 8, equals to the sizeof init_param. And the project links scatter file(semihosting-enable=0 needs a scatter file to ensure heap malloc is ok) writes
; my_400mb_heap.sct ; 加载区域(通常放在 Flash,但代码也可放 RAM) LR_CODE 0x80000000 0x10000000 ; 256MB 用于代码和数据(可调整) { ; 可执行代码和只读数据 ER_RO 0x80000000 { *(+RO) } ; 可读写数据(全局变量、堆栈前的数据) RW_IRAM +0 { *(+RW +ZI) } ; 关键:定义 400MB 的 HEAP 区域 ARM_LIB_HEAP +0 EMPTY 0x19000000 {} ; 0x19000000 = 400MB (400 * 1024 * 1024) ; 栈(假设 1MB,向下增长) ARM_LIB_STACK 0xA0000000 EMPTY -0x100000 {} ; 栈顶放在 2.5GB 处(0x80000000 + 0x20000000) }
Is there something wrong in the project setting?
Hi againI assume you are using Arm Compiler for Embedded 6, but you don't say which value is incorrect after the memcpy.I think the best way to investigate what is going wrong is for you to use the Arm DS Debugger. Try single-stepping through the code, and check that the variables, structs and memory change as expected as code execution progresses by using the Variables, Registers and Memory views in the Debugger.In particular, take a close look at the addresses being passed into memcpy. You can watch the execution of memcpy if you open two Memory views - one open on the source address and the other open at the destination address - and then single-step through it, instruction by instruction.Hope this helpsStephen
the breakpoint is after the memcpy,but the memory of these two struct address is not same.What's the reason?
Hi againI suspect that the issue here relates to "unaligned accesses". By default, the compiler assumes that the target platform supports unaligned accesses, so will generate code containing e.g. LDUR & STUR instructions. However, to run such code reliably, target platforms (FVP_Base_AEMvA model in this case) must have unaligned accesses enabled. To ensure this, you must configure the core in the FVP model to allow unaligned accesses, by setting the A bit in the SCTLR, either using assembler code, or by using the Debugger. I suspect that your original code would have crashed before reaching memcpy without it.As an alternative temporary workaround, you can prevent the compiler from generating code that depends on unaligned accesses by compiling with "-mno-unaligned-access". There may be a performance and/or code size impact for this. See:developer.arm.com/.../-munaligned-access---mno-unaligned-accessI was able to build and run your test case, and it worked for me - see screenshot.I used Arm DS 2025.1 to compile/link your code with:armclang --target=aarch64-arm-none-eabi -march=armv8-a -xc++ -fno-exceptions -O0 -g -mno-unaligned-access -c -o test.o test.cpparmlink --scatter=scatter.scat -o test.axf test.o Then ran/debugged the executable via Arm Debugger on the FVP_Base_AEMvA model with these parameters:-C cluster0.NUM_CORES=0x1 -C bp.secure_memory=falseI could see the struct data being copied correctly from param22 at 0x9FFFFFCC (on the stack) to pHandle->param at 0x8006EEE0 (in calloc'd memory).Note that sizeof(init_param) is 8. Being such a small value, the Arm Compiler 6 code-generator optimizes-away the call to memcpy, and replaces it with a simple load/store sequence:EL3:0x00000000800203D8 : LDR w8,[sp,#0x3c]EL3:0x00000000800203DC : LDR w10,[sp,#0x40]EL3:0x00000000800203E0 : STR w10,[x9,#4]EL3:0x00000000800203E4 : STR w8,[x9,#0]Note that you can have multiple Memory views (and other views), side-by-side, open simultaneously in the Arm DS GUI.
Hope this helps
Stephen