Example #1
0
void readTest()
{
    // Because src is volatile, the loads below will not be optimized away
    volatile veci16_t *src = (veci16_t*) region1Base + getCurrentThreadId() * LOOP_UNROLL;
    veci16_t result;
    int transferCount = kTransferSize / (64 * NUM_THREADS * LOOP_UNROLL);
    int unrollCount;

    int startTime = getCycleCount();
    startParallel();
    do
    {
        // The compiler will automatically unroll this
        for (unrollCount = 0; unrollCount < LOOP_UNROLL; unrollCount++)
            result = src[unrollCount];

        src += NUM_THREADS * LOOP_UNROLL;
    }
    while (--transferCount);
    endParallel();
    if (getCurrentThreadId() == 0)
    {
        int endTime = getCycleCount();
        printf("read: %g bytes/cycle\n", (float) kTransferSize / (endTime - startTime));
    }
}
Example #2
0
void copyTest()
{
    veci16_t *dest = (veci16_t*) region1Base + getCurrentThreadId() * LOOP_UNROLL;
    veci16_t *src = (veci16_t*) region2Base + getCurrentThreadId() * LOOP_UNROLL;
    veci16_t values = __builtin_nyuzi_makevectori(0xdeadbeef);
    int transferCount = kTransferSize / (64 * NUM_THREADS * LOOP_UNROLL);
    int unrollCount;

    int startTime = getCycleCount();
    startParallel();
    do
    {
        // The compiler will automatically unroll this
        for (unrollCount = 0; unrollCount < LOOP_UNROLL; unrollCount++)
            dest[unrollCount] = src[unrollCount];

        dest += NUM_THREADS * LOOP_UNROLL;
        src += NUM_THREADS * LOOP_UNROLL;
    }
    while (--transferCount);
    endParallel();
    if (getCurrentThreadId() == 0)
    {
        int endTime = getCycleCount();
        printf("copy: %g bytes/cycle\n", (float) kTransferSize / (endTime - startTime));
    }
}
Example #3
0
void writeTest()
{
    veci16_t *dest = (veci16_t*) region1Base + getCurrentThreadId() * LOOP_UNROLL;
    const veci16_t values = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 11, 14, 15 };
    int transferCount = kTransferSize / (64 * NUM_THREADS * LOOP_UNROLL);
    int unrollCount;

    int startTime = getCycleCount();
    startParallel();
    do
    {
        // The compiler will automatically unroll this
        for (unrollCount = 0; unrollCount < LOOP_UNROLL; unrollCount++)
            dest[unrollCount] = values;

        dest += NUM_THREADS * LOOP_UNROLL;
    }
    while (--transferCount);
    endParallel();
    if (getCurrentThreadId() == 0)
    {
        int endTime = getCycleCount();
        printf("write: %g bytes/cycle\n", (float) kTransferSize / (endTime - startTime));
    }
}
Example #4
0
void client()
{
	Message_t msg, reply;
	int reply_port, status, code, func, packet_no = 0;
	char precoded_string[15] = "+++--*+*-+--*-*";
	int op = 0;
	reply_port = getCurrentThreadId();

	openPort(reply_port);

	msg = (Message_t)malloc(sizeof(struct message));
    reply = (Message_t)malloc(sizeof(struct message));

    srand(getCurrentThreadId());

	while(1)
	{
		if(precoded_string[op] == '+')
			func = ADD;
		else if(precoded_string[op] == '-')
			func = DELETE;
		else
			func = MODIFY;

		do
		{
			code = createPacket(msg, func, rand() % 10, packet_no++);
			printf("\n[Client_on_port_%d]:Sent message:\t", getCurrentThreadId());
			if((status = Send(SERVER_PORT, msg))<0)
			{
                 printf("\n[Client_%d]:Send error",getCurrentThreadId());
                 exit(-1);
			}
			if((status = Receive(reply_port, reply))<0)
			{
				printf("\n[Client_%d]:Receive error",getCurrentThreadId());
				exit(-1);
			}
			if(reply->error_code == -1) break;
		}while(code);

		if(++op == 15)
			op=0;

		packet_no = 0;
		sleep(1);
	}
	closePort(reply_port);
}
Example #5
0
void ioWriteTest()
{
    volatile uint32_t * const ioBase = (volatile uint32_t*) 0xffff0004;
    int transferCount;
    int startTime;
    int endTime;
    int total;

    startTime = getCycleCount();
    startParallel();
    for (transferCount = 0; transferCount < 1024; transferCount += 8)
    {
        *ioBase = 0;
        *ioBase = 0;
        *ioBase = 0;
        *ioBase = 0;
        *ioBase = 0;
        *ioBase = 0;
        *ioBase = 0;
        *ioBase = 0;
    }
    endParallel();

    if (getCurrentThreadId() == 0)
    {
        endTime = getCycleCount();
        printf("ioWrite: %g cycles/transfer\n", (float)(endTime - startTime)
               / (transferCount * NUM_THREADS));
    }
}
Example #6
0
bool Thread::waitForThreadToExit (const int timeOutMilliseconds) const
{
    // Doh! So how exactly do you expect this thread to wait for itself to stop??
    bassert (getThreadId() != getCurrentThreadId() || getCurrentThreadId() == 0);

    const std::uint32_t timeoutEnd = Time::getMillisecondCounter() + (std::uint32_t) timeOutMilliseconds;

    while (isThreadRunning())
    {
        if (timeOutMilliseconds >= 0 && Time::getMillisecondCounter() > timeoutEnd)
            return false;

        sleep (2);
    }

    return true;
}
void ReadWriteLockTester::doWrite() {
    printf("Write task of thread %ld before get lock\n", getCurrentThreadId());
    LockScoper scoper(m_pWriteLock);
    scoper.lock();
    
    try {
        
        //printf("In write lock of thread %ld\n", getCurrentThreadId());
        //Block forvever
        //while (1) {
        //    ;
        //}
        
        m_valueToTestRead += 10;
        printf("Write value %d at thread %ld\n", m_valueToTestRead, getCurrentThreadId());
    } catch (std::exception& e) {
        printf("Exception occurred %s\n", e.what());
    }
}
Example #8
0
void endParallel()
{
    __sync_fetch_and_add(&gActiveThreadCount, -1);
    while (gActiveThreadCount > 0)
        ;

    if (getCurrentThreadId() == 0)
    {
        // Stop all but me
        *((unsigned int*) 0xffff0064) = ~1;
    }
}
Example #9
0
void TracePrint(int level, const char* szMessage, ...)
{
    va_list VAList;
    char szMsgBuf[2048] = {0};
    va_start(VAList, szMessage);
    VSNPRINTF(szMsgBuf, sizeof(szMsgBuf)-1, szMessage, VAList);
    
    //std::thread::id tid = std::this_thread::get_id();
    std::stringstream ss;
    //ss << tid << ":" << getCurrentThreadId();
    ss << getCurrentThreadId();
    std::string stid = ss.str();
    
    std::string str_log;
    switch(level)
    {
        case KUMA_TRACE_LEVEL_INFO:
            str_log = "INFO: ";
            //printf("INFO: [%s] %s\n", stid.c_str(), szMsgBuf);
            break;
        case KUMA_TRACE_LEVEL_WARN:
            str_log = "WARN: ";
            //printf("WARN: [%s] %s\n", stid.c_str(), szMsgBuf);
            break;
        case KUMA_TRACE_LEVEL_ERROR:
            str_log = "ERROR: ";
            //printf("ERROR: [%s] %s\n", stid.c_str(), szMsgBuf);
            break;
        case KUMA_TRACE_LEVEL_DEBUG:
            str_log = "DEBUG: ";
            //printf("DEBUG: [%s] %s\n", stid.c_str(), szMsgBuf);
            break;
        default:
            str_log = "INFO: ";
            //printf("INFO: [%s] %s\n", stid.c_str(), szMsgBuf);
            break;
    }
    str_log += "[" + stid + "] " + szMsgBuf;
    /*ss.str("");
    ss.clear();
    ss << str_log << "[" << stid << "] " << szMsgBuf;
    str_log = ss.str();*/
    if (trace_func) {
        trace_func(level, str_log.c_str());
    } else {
#ifdef KUMA_OS_WIN
        str_log += "\n";
        OutputDebugString(str_log.c_str());
#else
        printf("%s\n", str_log.c_str());
#endif
    }
}
Example #10
0
void client_printer()
{
 	Message_t msg, reply;
    int reply_port, status, i, received = 0;
    char * all_strings;

    reply_port = getCurrentThreadId();

    openPort(reply_port);

    msg = (Message_t)malloc(sizeof(struct message));
    reply = (Message_t)malloc(sizeof(struct message));

    srand(getCurrentThreadId());

    while(1)
    {
        if(rand() % 3 == 0)
        {
            createPacket(msg, PRINT, 10, 0);

            printf("\n[Client_on_port_%d]:Sent message:\t", getCurrentThreadId());
            if((status = Send(SERVER_PORT, msg))<0)
            {
                     printf("\n[Client_%d]:Send error",getCurrentThreadId());
                     exit(-1);
            }

            if((status = Receive(reply_port, reply))<0)
            {
                printf("\n[Client_%d]:Receive error",getCurrentThreadId());
                exit(-1);
            }

            all_strings = malloc((reply->total_size) * sizeof(char));

            while(reply->error_code == 1)
            {
                for(i = 0; i < MESSAGE_LENGTH; i++)
                    all_strings[received++] = reply->msg[i];

                if((status = Receive(reply_port, reply))<0)
                {
                    printf("\n[Client_%d]:Receive error",getCurrentThreadId());
                    exit(-1);
                }

            }
			if(reply->error_code != -1)
			{
				i=0;
				while(received < reply->total_size)
					all_strings[received++] = reply->msg[i++];

				printf("Table Entries: \n %s", all_strings);
			}
        }
    }

}
Example #11
0
unsigned long OpenSslLib::threadIdCallback(void)
{
#if 0
    unsigned long ret = 0;
    std::thread::id thread_id = std::this_thread::get_id();
    std::stringstream ss;
    ss << thread_id;
    ss >> ret;
    return ret;
#else
    return getCurrentThreadId();
#endif
}
Example #12
0
void TracePrint(int level, const char* szMessage, ...)
{
    va_list VAList;
    char szMsgBuf[2048] = {0};
    va_start(VAList, szMessage);
    VSNPRINTF(szMsgBuf, sizeof(szMsgBuf)-1, szMessage, VAList);
    
    std::stringstream ss;
    
    /*auto now_p = std::chrono::system_clock::now();
    auto now_ms = std::chrono::duration_cast<std::chrono::milliseconds>(now_p.time_since_epoch());
    auto now_c = std::chrono::system_clock::to_time_t(now_p);
    struct tm tm_buf;
    LOCALTIME_R(&now_c, &tm_buf);
    ss << std::put_time(&tm_buf, "%F %T.");
    ss.width(3);
    ss.fill('0');
    ss << (now_ms.count()%1000) << " ";*/
    switch(level)
    {
        case KUMA_TRACE_LEVEL_INFO:
            ss << "INFO: ";
            break;
        case KUMA_TRACE_LEVEL_WARN:
            ss << "WARN: ";
            break;
        case KUMA_TRACE_LEVEL_ERROR:
            ss << "ERROR: ";
            break;
        case KUMA_TRACE_LEVEL_DEBUG:
            ss << "DEBUG: ";
            break;
        default:
            ss << "INFO: ";
            break;
    }
    ss << "[" << getCurrentThreadId() << "] " << szMsgBuf;
    if (trace_func) {
        trace_func(level, ss.str().c_str());
    } else {
#ifdef KUMA_OS_WIN
        auto str(ss.str());
        str += "\n";
        OutputDebugString(str.c_str());
#else
        ss << std::endl;
        printf("%s", ss.str().c_str());
#endif
    }
}
Example #13
0
/**
 * @brief Get the statistics and print them if necessary
 */
static Files &files() {
  static std::ofstream log(logFileName);
  static Files sinceLast;
  static Files total;
  // print the final statistics on exit
  static DestructionExecutor finalExecutor([&]() {
    log << "Statistics for thread " << getCurrentThreadId() << "\n";
    printStatistics(log, sinceLast);
    log << "Total statistics for thread " << getCurrentThreadId() << ":\n";
    total += sinceLast;
    printStatistics(log, total);
  });
  static DeltaTimeExecutor executor([&]() {
                                      log << "Statistics for thread "
                                          << getCurrentThreadId() << "\n";
                                      printStatistics(log, sinceLast);
                                      total += sinceLast;
                                      sinceLast.resetStatistics();
                                    },
                                    std::chrono::microseconds(1000 * 1000 *
                                                              10));
  executor.callIfTimeOver();
  return sinceLast;
}
void ReadWriteLockTester::doRead() {
    LockScoper scoper(m_pReadLock);
    scoper.lock();
    try {
        
        //printf("In read lock of thread %ld\n", getCurrentThreadId());
        //Block forvever
        //while (1) {
        //    ;
        //}
        
        printf("Read value %d at thread %ld\n", m_valueToTestRead, getCurrentThreadId());
    } catch (std::exception& e) {
        printf("Exception occurred %s\n", e.what());
    }
}
Example #15
0
int createPacket(Message_t msg, int operation, int row, int packet_no)
{
	int i,code = 1; //Extended transmission
	msg->reply_port = getCurrentThreadId();
	msg->operation = operation;
	msg->row = row;
	char line[50] = "";
	char msg_line[MESSAGE_LENGTH] = "";
	char dig[2];
	dig[0] = (char)(((int)'0')+ msg->reply_port);
	dig[1] = '\0';
	if(operation == ADD)
	{
		strcat(line,"Added by client \0");
		strcat(line, dig);
	}
	else if(operation == MODIFY)
	{
		strcat(line,"Modified by client \0");
		strcat(line, dig);
	}
	else if(operation == DELETE)
	{
		strcat(line,"Deleted \0");
		dig[0] = (char)(((int)'0')+ msg->row);
		strcat(line, dig);
	}
    else
    {
        strcat(line, "PRINT\0");
    }

	for( i = 0; i < MESSAGE_LENGTH ; i++)
	{
		msg_line[i] = line[(packet_no * 10) + i];
		if(msg_line[i] == '\0')
		{
			code = 0; //End transmission
			break;
		}
	}
	memcpy(msg->msg, msg_line, MESSAGE_LENGTH * sizeof(char));
	msg->error_code = code;
	msg->total_size = strlen(line);
	return code;
}
Example #16
0
//==============================================================================
bool Thread::setPriority (const int newPriority)
{
    // NB: deadlock possible if you try to set the thread prio from the thread itself,
    // so using setCurrentThreadPriority instead in that case.
    if (getCurrentThreadId() == getThreadId())
        return setCurrentThreadPriority (newPriority);

    const RecursiveMutex::ScopedLockType sl (startStopLock);

    if (setThreadPriority (threadHandle, newPriority))
    {
        threadPriority = newPriority;
        return true;
    }

    return false;
}
Example #17
0
bool Thread::stopThread (const int timeOutMilliseconds)
{
    bool cleanExit = true;

    // agh! You can't stop the thread that's calling this method! How on earth
    // would that work??
    bassert (getCurrentThreadId() != getThreadId());

    const RecursiveMutex::ScopedLockType sl (startStopLock);

    if (isThreadRunning())
    {
        signalThreadShouldExit();
        notify();

        if (timeOutMilliseconds != 0)
        {
            cleanExit = waitForThreadToExit (timeOutMilliseconds);
        }

        if (isThreadRunning())
        {
            bassert (! cleanExit);

            // very bad karma if this point is reached, as there are bound to be
            // locks and events left in silly states when a thread is killed by force..
            killThread();

            threadHandle = nullptr;
            threadId = 0;

            cleanExit = false;
        }
        else
        {
            cleanExit = true;
        }
    }

    return cleanExit;
}
Example #18
0
void Thread::threadEntryPoint()
{
    const CurrentThreadHolder::Ptr currentThreadHolder (getCurrentThreadHolder());
    currentThreadHolder->value = this;

    if (threadName.isNotEmpty())
        setCurrentThreadName (threadName);

    if (startSuspensionEvent.wait (10000))
    {
        bassert (getCurrentThreadId() == threadId);

        if (affinityMask != 0)
            setCurrentThreadAffinityMask (affinityMask);

        run();
    }

    currentThreadHolder->value.releaseCurrentThreadStorage();
    closeThreadHandle();
}