Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 5661

General • Re: How can I ensure memory coherence between cores?

$
0
0
I don't think this would be the cause of your problem but I would have thought that

Code:

uint8_t* array[ARRAY_BYTE_COUNT] = {};
should be

Code:

uint8_t array[ARRAY_BYTE_COUNT] = {};
based on what I see from other parts of the code. It seems like you are allocating ARRAY_BYTE_COUNT count of 32-bit pointers on the stack and not ARRAY_BYTE_COUNT bytes as expected.

Your synchronization problem looks like the first call to multicore_fifo_pop_blocking() works as expected but maybe the second one returns while the code on Core1 is still running. Could your try using a global g_core1Done variable to track the completion state of Core1 instead?

Code:

static volatile int g_core1Done = 0;...void multi_core_worker(void) {    write_coords_row_wise(g_array, ARRAY_WIDTH, ARRAY_HEIGHT, ARRAY_HALF_WIDTH, ARRAY_WIDTH);    g_core1Done = 1;}...void test_multi_core() {    // Allocate a zero-initialized array on the stack.    uint8_t array[ARRAY_BYTE_COUNT] = {};    multicore_reset_core1();    // Fill in the second half of the array on the second core.    g_array = array;    g_core1Done = 0;    multicore_launch_core1(multi_core_worker);    // Fill in the first half of the array on the first core.    write_coords_row_wise(array, ARRAY_WIDTH, ARRAY_HEIGHT, 0, ARRAY_HALF_WIDTH);    while (g_core1Done == 0)    {    // Busy wait for Core1 to complete.    }    ...}

Statistics: Posted by adam_green — Mon Jan 01, 2024 2:48 am



Viewing all articles
Browse latest Browse all 5661

Trending Articles