Beispiel #1
0
bool Stressor::addFault(const Fault & f) {


#if CXX0X_UP_SUPPORTED
    std::lock_guard<std::mutex> lock(faults_sync());
#endif

    std::map<int32_t,Fault>::iterator find = faults().find(f.id_);
    if (find != faults().end())
        return false;

    faults().insert(std::pair<int32_t,Fault>(f.id_,f));

    for (std::vector<Trigger>::const_iterator iter = f.triggers.begin(); iter != f.triggers.end(); ++iter) {
        Injector::ptr iptr = iter->getInjector();
        if (iptr) {
            iptr->addTrigger(*iter,f.id_);
            std::cout << "added trigger " << iter->toString() << std::endl;
        } else {
            /// TODO signal error and roll back
        }
    }

    return true;

}
Beispiel #2
0
bool Stressor::firedTrigger(const Trigger & triggered,int32_t fault_id,Injector * injector,uint64_t time_ps)
{

#if CXX0X_UP_SUPPORTED
    std::lock_guard<std::mutex> lock(faults_sync());
#endif
    std::map<int32_t,Fault>::iterator find = faults().find(fault_id);
    if (find != faults().end()) {
        for (std::vector<etiss::fault::Action>::iterator iter = find->second.actions.begin(); iter != find->second.actions.end(); ++iter) {
            if (iter->getType() == etiss::fault::Action::INJECTION) {
                addFault(iter->getFault());
            } else {
                if (iter->getInjectorAddress().getInjector()) {
#if CXX0X_UP_SUPPORTED
                    if (iter->getInjectorAddress().getInjector().get() != injector)
#else
                    if (iter->getInjectorAddress().getInjector() != injector)
#endif
                    {
#ifndef NO_ETISS
                        etiss::log(etiss::WARNING,"action injector is not the injector that triggered this event. threadsafety must be ensured by user.",find->second,*iter);
#endif
                    }
                    std::string err;
                    if (!iter->getInjectorAddress().getInjector()->applyAction(find->second,*iter,err)) {
#ifdef NO_ETISS
                        std::cout << "Failed to apply action. Fault: " << fault_id  << " [" << err << "]"<< std::endl;
#else
                        etiss::log(etiss::ERROR,std::string("Failed to apply action "),find->second,*iter,err);
#endif
                    }
                    return true;
                } else {
#ifdef NO_ETISS
                    std::cout << "Failed to find action target. Fault: " << fault_id << std::endl;
#else
                    etiss::log(etiss::ERROR,std::string("Failed to find action target"),find->second,*iter);
#endif
                }
            }
        }
    } else {
#ifdef NO_ETISS
        std::cout << "Failed to find triggered Fault: " << fault_id << std::endl;
#else
        etiss::log(etiss::ERROR,std::string("Failed to find triggered Fault: "),fault_id);
#endif
    }

    return true;
}
Beispiel #3
0
void Stressor::clear() {
#if CXX0X_UP_SUPPORTED
    std::lock_guard<std::mutex> lock(faults_sync());
#endif
    faults().clear();
}
int main(int argc, char *argv[])
{
	int i, j, l;
	int **matrix;               // N x N matrix
	Node *lpart, *rpart;        // left and right partition
	int p, r, c;
	int k = 0, k_temp;
	float res;
	int res1;
	int *consistency;
	struct timeval tv1,tv2; 
    struct timezone tzone;
    long elapsed_utime;    /* elapsed time in microseconds */
    long elapsed_mtime;    /* elapsed time in milliseconds */
    long elapsed_seconds;  /* diff between seconds counter */
    long elapsed_useconds; /* diff between microseconds counter */
		
	if( argc != 4 ) /* checks the inputs from the command line */
	{
		printf("Invalid input!! Please try again.\n");
		return 0;
	}
		
	N = atoi(argv[1]); // get N (NxN partially-defective crossbar)
	P = atoi(argv[2]); // get P (defect rate)
	T = atoi(argv[3]); // get number of samples
   
	matrix = (int **)malloc(N*sizeof(int*));
	for(i = 0; i < N; i++)
		matrix[i]=(int *)calloc(N, sizeof(int)); // all values are set to zero
	
	lpart = (Node *)malloc(N*sizeof(Node));
	rpart = (Node *)malloc(N*sizeof(Node));
	
	consistency = (int *)calloc(N+1, sizeof(int));
   
	srand( time(NULL) );
	p = faults();
    
    gettimeofday(&tv1, NULL); 
	for(l = 0; l < T; l++) 
	{
		for(i = 0; i < N; i++)
		{
			for(j = 0; j < N; j++)
				matrix[i][j] = 0;
		}
        
		/* random faults */
    		for(i = 0; i < p; i++)
		{
			r = rand()%N;
			c = rand()%N;
       	
			if(matrix[r][c] == 0)
				matrix[r][c] = 1;
			else
				i--;
		}
		
		construct_partitions(lpart, rpart, matrix);
  
		k_temp = find_k(lpart, rpart, matrix, N, N);
		consistency[k_temp]++;
		k += k_temp;
	}
	
	gettimeofday(&tv2, &tzone);
	elapsed_seconds  = tv2.tv_sec  - tv1.tv_sec;
    elapsed_useconds = tv2.tv_usec - tv1.tv_usec;

    //printf("Elapsed time = %f seconds + %f microseconds\n",
    //        (double)elapsed_seconds/(double)T, (double)elapsed_useconds/(double)T);

    elapsed_utime = (elapsed_seconds) * 1000000 + elapsed_useconds;
    //lapsed_mtime = ((elapsed_seconds) * 1000 + elapsed_useconds/1000.0) + 0.5;
    printf("%f ",(double)elapsed_utime/(double)T);
    //printf("Elapsed time = %f microseconds\n", (double)elapsed_utime/(double)T);
    //printf("Elapsed time = %f milliseconds\n", (double)elapsed_mtime/(double)T);
	
	res = (float)k/(float)T;
	
	res1 = (int)res;
		if((res - (float)res1 >= 0.5))
			res1++;
         
	//printf("K = %d (%.2f %%), #crosspoints = %d (%.2f %%)\n", res1, (double)res1*100/(double)N, res1*res1, (double)(res1*res1*100)/(double)(N*N) );
	printf("%d",res1);

	for(i = 0; i < N; i++)
	      if(consistency[i])
              printf(" %d %d",i, consistency[i]);
             
	free(consistency);
	free(lpart);
	free(rpart);
	for(i = 0; i < N; i++)
		free(matrix[i]);
	free(matrix);
	//system("PAUSE");
	
	return 0;
}