Project

General

Profile

[logo] 
 
Home
News
Activity
About/Contact
Major Tools
  Dinotrace
  Verilator
  Verilog-mode
  Verilog-Perl
Other Tools
  BugVise
  CovVise
  Force-Gate-Sim
  Gspice
  IPC::Locker
  Rsvn
  SVN::S4
  Voneline
  WFH
General Info
  Papers

Issue #1332

Verilator 4.00 multi-threading on OS X

Added by Florian Zaruba about 1 year ago. Updated about 1 year ago.

Status:
Closed
Priority:
High
Assignee:
-
Category:
Configure/Make/Compiling
% Done:

0%


Description

Thanks for your awesome work on Verilator and related tools.

I just wanted to let you know I am running into issues when translating my model with verilator 4.00 and multi-threading enabled. Apparently on OS X
#include <sched.h>  // For sched_getcpu()
is not available.

Thanks again, Florian

History

#1 Updated by Wilson Snyder about 1 year ago

  • Category set to Configure/Make/Compiling
  • Status changed from New to Confirmed
  • Priority changed from Low to High

Thanks for trying this out!

I'd really like OSX to work out of the box, so made this high priority.

I don't have access to OS X, would you mind suggesting an alternative function to get the CPU number a process is running on? Then replace using that and see if the rest works. With that I can wrap the function in a OS specific ifdef.

This may help... https://stackoverflow.com/questions/33745364/sched-getcpu-equivalent-for-os-x

#2 Updated by Florian Zaruba about 1 year ago

Thanks for getting back to me. Yes that seems to fix the problem of sched_getcpu:
#include <cpuid.h>

#define CPUID(INFO, LEAF, SUBLEAF) __cpuid_count(LEAF, SUBLEAF, INFO[0], INFO[1], INFO[2], INFO[3])
class VlProfileRec {
private:
    int sched_getcpu() {
        uint32_t CPUInfo[4];
        CPUID(CPUInfo, 1, 0);
        /* CPUInfo[1] is EBX, bits 24-31 are APIC ID */
        if ((CPUInfo[3] & (1 << 9)) == 0) {
            return -1;  /* no APIC on chip */
        } else {
            return (unsigned)CPUInfo[1] >> 24;
        }
   }
...
Furthermore I had problems with randomisation. In particular clang doesn't like the re-entrant version of rand. My (non-semantically identical) workaround (verilated.cc):
IData VL_RAND32() VL_MT_SAFE {
#ifdef VL_THREADED
    static VL_THREAD_LOCAL bool t_seeded = false;
    // static VL_THREAD_LOCAL drand48_data t_buffer;
    static VerilatedMutex s_mutex;
    if (VL_UNLIKELY(!t_seeded)) {
    t_seeded = true;
    long seedval;
    {
        VerilatedLockGuard lock(s_mutex);
        seedval = lrand48()<<16 ^ lrand48();
        if (!seedval) seedval++;
    }
    srand48(seedval);
    }
    long v0; v0 = lrand48();
    long v1; v1 = lrand48();
    return (v0<<16) ^ v1;
#elif defined(_WIN32) && !defined(__CYGWIN__)
    // Windows doesn't have lrand48(), although Cygwin does.
    return (rand()<<16) ^ rand();
#else
    return (lrand48()<<16) ^ lrand48();
#endif
}
That compiles for me.

Still I am having some SEGFAULTS on my DPI calls which I probably need to debug further (I enabled --threads-dpi none) so I can't tell you more about the functional state at the moment :(.

#3 Updated by Wilson Snyder about 1 year ago

Great, thanks, please check the git change I committed for sched_getcpu is good.

I don't understand your proposed VL_RAND. lrand() without the _r is not reentrant, it won't work when multithreaded.

#4 Updated by Wilson Snyder about 1 year ago

In git, I updated the random code to use its own algorithm, please try it.

#5 Updated by Florian Zaruba about 1 year ago

The random number problem is solved. You forgot to add the macro and the include which is needed on OS X:
#include <cpuid.h>
#define CPUID(INFO, LEAF, SUBLEAF) __cpuid_count(LEAF, SUBLEAF, INFO[0], INFO[1], INFO[2], INFO[3])

Thanks

#6 Updated by Wilson Snyder about 1 year ago

Try, try again please.

#7 Updated by Florian Zaruba about 1 year ago

Almost:

/usr/local/share/verilator/include/verilated_threads.h:200:64: error: expected ';' after asm statement
        __cpuid_count(1, 0, info[0], info[1], info[2], info[3])

#8 Updated by Wilson Snyder about 1 year ago

  • Status changed from Confirmed to Closed

All set then, thanks for your work.

Also available in: Atom