Esempio n. 1
0
File: heap.c Progetto: SnookEE/nvc
void *heap_min(heap_t h)
{
   if (unlikely(h->size < 1))
      fatal_trace("heap underflow");

   return USER(h, 1);
}
Esempio n. 2
0
lts_file_t lts_file_bare(const char* name,lts_type_t ltstype,int segments,lts_file_t settings,size_t user_size){
    lts_file_t lts=(lts_file_t)HREmallocZero(hre_heap,system_size+user_size);
    lts->states=(uint32_t*)HREmallocZero(hre_heap,segments*sizeof(uint32_t));
    lts->edges=(uint64_t*)HREmallocZero(hre_heap,segments*sizeof(uint64_t));
    lts->max_src_p1=(uint32_t*)HREmallocZero(hre_heap,segments*sizeof(uint32_t));
    lts->max_dst_p1=(uint32_t*)HREmallocZero(hre_heap,segments*sizeof(uint32_t));
    lts->expected_values=(uint32_t*)HREmallocZero(hre_heap,segments*sizeof(uint32_t));
    lts->ctx=lts_file_context(settings) ? lts_file_context(settings) : HREglobal();
    lts->name=strdup(name);
    lts->user_size=user_size;
    lts->ltstype=ltstype;
    int N=lts_type_get_type_count(ltstype);
    lts->values=(value_table_t*)HREmallocZero(hre_heap,N*sizeof(value_table_t));
    lts->segments=segments;
    if (settings){
        settings=SYSTEM(settings);
        lts->edge_owner=settings->edge_owner;
        lts->init_mode=settings->init_mode;
        lts->src_mode=settings->src_mode;
        lts->dst_mode=settings->dst_mode;
    }
    lts->write_init=no_write_init;
    lts->write_state=no_write_state;
    lts->write_edge=no_write_edge;
    return USER(lts);
}
Esempio n. 3
0
lts_file_t lts_vset_template(){
    lts_file_t lts=(lts_file_t)HREmallocZero(hre_heap,system_size);
    lts->edge_owner=SourceOwned;
    lts->init_mode=SegVector;
    lts->src_mode=Index;
    lts->dst_mode=SegVector;
    return USER(lts);
}
Esempio n. 4
0
lts_file_t lts_index_template(){
    lts_file_t lts=(lts_file_t)HREmallocZero(hre_heap,system_size);
    lts->edge_owner=DestOwned;
    lts->init_mode=Index;
    lts->src_mode=Index;
    lts->dst_mode=Index;
    return USER(lts);
}
Esempio n. 5
0
lts_file_t lts_get_template(lts_file_t file){
    file=SYSTEM(file);
    lts_file_t lts=(lts_file_t)HREmallocZero(hre_heap,system_size);
    lts->init_mode=file->init_mode;
    lts->edge_owner=file->edge_owner;
    lts->src_mode=file->src_mode;
    lts->dst_mode=file->dst_mode;
    return USER(lts);
}
Esempio n. 6
0
File: heap.c Progetto: SnookEE/nvc
void *heap_extract_min(heap_t h)
{
   if (unlikely(h->size < 1))
      fatal_trace("heap underflow");

   void *min = USER(h, 1);
   NODE(h, 1) = NODE(h, h->size);
   --(h->size);
   min_heapify(h, 1);
   return min;
}
Esempio n. 7
0
File: heap.c Progetto: SnookEE/nvc
void heap_insert(heap_t h, uint64_t key, void *user)
{
   if (unlikely(h->size == h->max_size)) {
      h->max_size *= 2;
      h->nodes = xrealloc(h->nodes, h->max_size * sizeof(struct node));
   }

   ++(h->size);

   KEY(h, h->size) = UINT64_MAX;
   USER(h, h->size) = user;

   heap_decrease_key(h, h->size, key);
}
Esempio n. 8
0
   // ----------------------------------------------------------------------
   void
   SimulationTaskLocalizationEvaluation::
   print( const HeaderInfo& header, const Results& results )
      const throw()
   {
	  std::stringstream oss;
	  
	  oss << "Distance algorithm: \t" << header.dist_algo << std::endl
            << "Position algorithm: \t" << header.pos_algo << std::endl
            << "Refinement algorithm: \t" << header.ref_algo << std::endl
            << std::endl
            << results.has_pos_cnt << " nodes know their position, "
            << results.no_pos_cnt << " are still unknowning. "
            << "That's a coverage of " << results.coverage() << "%." << std::endl
            << std::endl
            << "Relative anchor distances (real): "
            << "mean is " << results.stat_real_err_anchor_dist.mean()
            << ", std-dev is " << results.stat_real_err_anchor_dist.std_dev()
            << " ( from " << results.stat_real_err_anchor_dist.min()
            << " to " << results.stat_real_err_anchor_dist.max() << " )" << std::endl
            << "Relative anchor distances (comm_range): "
            << "mean is " << results.stat_comm_err_anchor_dist.mean()
            << ", std-dev is " << results.stat_comm_err_anchor_dist.std_dev()
            << " ( from " << results.stat_comm_err_anchor_dist.min()
            << " to " << results.stat_comm_err_anchor_dist.max() << " )" << std::endl
            << "Average absolute distance from real pos: "
            << results.stat_abs_position.mean()
            << " ( " << ( results.stat_abs_position.mean() / header.comm_range ) * 100
            << "% of communication range )"
            << " ( from " << results.stat_abs_position.min()
            << " to " << results.stat_abs_position.max() << " )" << std::endl
            << "Average relative neighbor distance error is "
            <<  results.stat_real_neighbor_dist.mean()
            << " ( from " << results.stat_real_neighbor_dist.min()
            << " to " << results.stat_real_neighbor_dist.max() << " )" << std::endl
            << std::endl
            << "Average number of neighbors per node is " << results.stat_neighbor_cnt.mean()
            << " ( from " << results.stat_neighbor_cnt.min()
            << " to " << results.stat_neighbor_cnt.max() << " )";

	  USER( oss.str() );
   }
Esempio n. 9
0
void
randomCons(char *buf, sccs *s, ser_t d)
{
	u32	date;
	u32	crc1, crc2;
	char	*item;

	/*
	 * We don't want to hash realuser or realhost as that would
	 * make prevent these random bits from being stable.
	 */
	item = USER(s, d);	/* user or user/realuser */
	crc1 = crc32c(0, item, strcspn(item, "/"));
	item = HOSTNAME(s, d);	/* host or host/realhost */
	crc1 = crc32c(crc1, item, strcspn(item, "/["));

	crc2 = crc32c(0, PATHNAME(s, d), strlen(PATHNAME(s, d)));
	date = DATE(s, d);
	crc2 = crc32c(crc2, &date, sizeof(date));
	sprintf(buf, "%x%x", crc1, crc2);
}
Esempio n. 10
0
/**
 * Called when a pagefault occurs, is in charge of fixing the fault and swapping
 * if necessary.
 */
void cPageFault(isrVal_t registers)
{
	addr_t page = getCR2();
	addr_t page_addr = page & ~(0xFFF);

#ifdef PAGEDBG
	printf("PG!\n");
	printf("Fault addr: %X\nPage index: %X\n", page, page_addr);
	printf("Fault type: %X\n", registers.errCode);
	printf("EIP: %X\nESP: %X\nESP: %X\n",
			       registers.eip, registers.procesp, registers.esp);
	printf("eax: %X\tebx: %X\necx: %X\tedx: %X\n",
		    registers.eax, registers.ebx, registers.ecx, registers.edx);
#endif

	if (registers.cs != 0x8 && registers.cs != 0x18)
		panic("Incorrect frame!");
	if (USER(registers.errCode))
		panic("Userspace isn't implemented yet!");
	if (RESERVED(registers.errCode))
		panic("A reserved bit has been set!\n");
	if (PRESENT(registers.errCode))
		panic("Illegal operation!");

	addr_t pd = getPageDir();

	/**
	* The data bit only works if a specific bit is set. See intel docs volume 3
	* for more information.
	*/

	if (DATA(registers.errCode))
	{
#ifdef PAGEDBG
		printf("Trying to access unimplemented data!\n");
#endif
		if (WRITE(registers.errCode))
		{
#ifdef PAGEDBG
		printf("Faulted a write attempt!\n");
		printf("Adding page!\n");
#endif
		if (USER(registers.errCode))
		{
			//Add a user page!
		}
		else
		{
#ifdef PAGEDBG
			printf("Adding a kernel page!\n");
#endif
			if (idx_kernel_space == MAP_NOMAP)
				panic("Kernel page map not correctly initialised!");

			int ret = page_alloc_page
				(idx_kernel_space, page_addr, (void*)pd, FALSE);
			if (ret != -E_SUCCESS)
			{
				printf("ERRCODE: %X\n", -ret);
				panic("Couldn't alloc page!");
			}
#ifdef PAGEDBG
			printf("Phys of %X = %X\n", page, page_phys_addr(page, (void*)pd));
#endif
			}
		}
		else
		{
#ifdef PAGEDBG
			printf("Faulted a read attempt!\n");
#endif
			// Assume the page may be read!
			if (idx_kernel_space == MAP_NOMAP)
			    panic("Kernel page map not correctly initialised!");
			int ret = page_alloc_page(idx_kernel_space, page_addr,
							      (void*)pd, FALSE);
			if (ret != -E_SUCCESS)
			{
				printf("ERRCODE: %X\n", -ret);
				panic("Couldn't alloc page!");
			}
#ifdef PAGEDBG
			printf("Phys of %X = %X\n", page, page_phys_addr(page, (void*)pd));
#endif
		}
	}
	else
	{
#ifdef PAGEDBG
	panic("Trying to run unimplemented code!\n");
#endif
	}
#ifdef UNDEFINED
	printf("Page faults currently under construction!\n");
#endif
}
Esempio n. 11
0
File: heap.c Progetto: SnookEE/nvc
void heap_walk(heap_t h, heap_walk_fn_t fn, void *context)
{
   for (size_t i = 1; i <= h->size; i++)
      (*fn)(KEY(h, i), USER(h, i), context);
}
Esempio n. 12
0
File: main.cpp Progetto: madf/stg
//-----------------------------------------------------------------------------
int main(int argc, char *argv[])
{
SETTINGS settings;

if (argc == 2)
    {
    settings.SetConfFile(argv[1]);
    }

if (settings.ReadSettings())
    {
    std::cerr << "Failed to read settings: '"
              << settings.GetStrError() << "'" << std::endl;
    Usage();
    return -1;
    }

SetSignalHandlers();

PROTO proto(settings.GetServerName(),
            settings.GetServerPort(),
            settings.GetLocalPort(),
            10);

STORE_LOADER storeLoader(settings.GetModulesPath(), settings.GetStoreModuleSettings());
if (storeLoader.Load())
    {
    std::cerr << "Failed to load storage plugin: '" << storeLoader.GetStrError() << "'" << std::endl;
    return -1;
    }

STORE * dataStore = storeLoader.GetStore();

std::vector<std::string> userList;
if (dataStore->GetUsersList(&userList))
    {
    std::cerr << "Failed to get user list: '" << dataStore->GetStrError() << "'" << std::endl;
    return -1;
    }

std::list<uint32_t> ips;
    {
    std::vector<std::string>::const_iterator it;
    for (it = userList.begin(); it != userList.end(); ++it)
        {
        USER_CONF userConf;
        if (dataStore->RestoreUserConf(&userConf, *it))
            {
            std::cerr << "Failed to read user conf: '" << dataStore->GetStrError() << "'" << std::endl;
            return -1;
            }
        proto.AddUser(
                USER(
                    *it,
                    userConf.password,
                    userConf.ips[0].ip
                )
        );
        ips.push_back(userConf.ips[0].ip);
        }
    }

if (!proto.Start())
    {
    std::cerr << "Failed to start listening thread: '" << proto.GetStrError() << "'" << std::endl;
    return -1;
    }

std::list<uint32_t>::const_iterator it;
for (it = ips.begin(); it != ips.end(); ++it)
    {
    proto.Connect(*it);
    }

std::cout << "Successfully loaded " << proto.UserCount() << " users" << std::endl;

running = true;
while (running)
    {
    struct timespec ts = {0, 200000000};
    nanosleep(&ts, NULL);
    }

proto.Stop();

storeLoader.Unload();

return 0;
}