t-crest / patmos

Patmos is a time-predictable VLIW processor, and the processor for the T-CREST project
http://patmos.compute.dtu.dk
BSD 2-Clause "Simplified" License
134 stars 72 forks source link

Patmos emulator hangs when starting a core thread on a CPU with index >= 8 in a 16-core config #110

Closed michael-platzer closed 2 years ago

michael-platzer commented 2 years ago

Steps to reproduce:

  1. Edit patmos/hardware/config/altde2-115.xml and uncomment lines 7 and 8 and change the core count to 16 as follows to build a multicore system (note that Argo is not used since it produces an error, see #104 ):
    <!-- Default is single core -->
    <pipeline dual="false" />
    <cores count="16"/>
    <!-- <CmpDevs>
    <CmpDev name="Argo" />
    </CmpDevs> -->
  2. After rebuilding with misc/build.sh, save the following code to a file called test.c:
    
    #include <stdio.h>
    #include "libcorethread/corethread.h"

void work(void* arg) { }

int main() { int i; for (i = 1; i < 16; i++) { corethread_create(i, &work, NULL); printf("started thread on core %d\n", i); } return 0; }

3. Compile and execute as follows:

$ patmos-clang test.c libcorethread/corethread.c $ patemu a.out started thread on core 1 started thread on core 2 started thread on core 3 started thread on core 4 started thread on core 5 started thread on core 6 started thread on core 7 ^C


After starting threads on CPUs 1, 2, 3, 4, 5, 6, and 7, the emulator hangs indefinitely.
schoeberl commented 2 years ago

That is an artifact of flattening arrays in the generated Verilog/C code. We need to manually enumerate the cores in Patmos-harness.cpp. And that enumeration is hardcoded to 8 cores. Feel free to copy that code to extend it to 16 cores and make a pull request.

michael-platzer commented 2 years ago

That is an artifact of flattening arrays in the generated Verilog/C code. We need to manually enumerate the cores in Patmos-harness.cpp. And that enumeration is hardcoded to 8 cores. Feel free to copy that code to extend it to 16 cores and make a pull request.

Thanks for pointing me to this, I extended the code to support 16 cores and created a pull request. Also added a warning in case someone wants to use even more cores.