Skip to content

Commit

Permalink
Use tcdm global barrier in exit
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerbarton committed Jan 16, 2024
1 parent de9817d commit 3d1080e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
5 changes: 5 additions & 0 deletions target/sim/sw/device/runtime/src/occamy_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

// Could become cluster-local to save storage
// Aligned to 8-byte boundary so we can reuse the multicast function
// based on the SD instruction
__thread volatile uint32_t ct_barrier_cnt __attribute__((aligned(8)));

extern void post_wakeup_cl();

extern comm_buffer_t* get_communication_buffer();
Expand Down
20 changes: 15 additions & 5 deletions target/sim/sw/device/runtime/src/occamy_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

typedef enum { SYNC_ALL, SYNC_CLUSTERS, SYNC_NONE } sync_t;

// Could become cluster-local to save storage
extern __thread volatile uint32_t ct_barrier_cnt __attribute__((aligned(8)));

inline void ocrt_compute_thread_num(uint32_t* tnum) {
tnum[0] = SNRT_CLUSTER_CORE_NUM - SNRT_CLUSTER_DM_CORE_NUM;
tnum[1] = N_CLUSTERS_PER_QUAD;
Expand Down Expand Up @@ -55,17 +58,24 @@ inline void return_to_cva6(sync_t sync) {
// Optionally synchronize clusters
if (sync != SYNC_NONE) {
if (snrt_is_dm_core()) {
uint32_t cnt =
__atomic_add_fetch(&(_snrt_barrier.cnt), 1, __ATOMIC_RELAXED);
// Only the first cluster holds the barrier counter
uint32_t barrier_ptr = (uint32_t)(&ct_barrier_cnt);
barrier_ptr -= cluster_offset * snrt_cluster_idx();
uint32_t cnt = __atomic_add_fetch((volatile uint32_t*)barrier_ptr,
1, __ATOMIC_RELAXED);
#ifdef N_CLUSTERS_TO_USE
if (cnt == N_CLUSTERS_TO_USE) {
#else
if (cnt == snrt_cluster_num()) {
_snrt_barrier.cnt = 0;
snrt_int_sw_set(0);
#endif
*((volatile uint32_t*)barrier_ptr) = 0;
set_host_sw_interrupt();
}
}
}
// Otherwise assume cores are already synchronized and only
// one core calls this function
else {
snrt_int_sw_set(0);
set_host_sw_interrupt();
}
}

0 comments on commit 3d1080e

Please sign in to comment.