Exemple #1
0
int main(int argc, char *argv[])
{
	umask(0);

        buffer_cache = create_cache(4096*3*10,4096*3,WRITE_BUFFER);
        
        meta_data_cache = create_cache(100,1,METADATA_CACHE);
//	printf("meta_data_cache : %p\n",meta_data_cache);
	pthread_t tid;
	pthread_create(&tid,NULL,periodic_cache_flush,NULL);


	return fuse_main(argc, argv, &lfs_oper, NULL);
}
void test_gets(uint8_t* keys, uint32_t* values, uint64_t numpairs)
{
  cache_t cache = create_cache(numpairs*10);

  char **keystrings = calloc(numpairs,sizeof(char*));
  char **valstrings = calloc(numpairs,sizeof(char*));

  for(int i = 0; i < numpairs; ++i)
    {
      keystrings[i] = calloc(keys[i],1);
      valstrings[i] = calloc(values[i],1);
      memset(keystrings[i],'K',keys[i]);
      memset(valstrings[i],'V',values[i]);
      keystrings[i][keys[i] - 1] = '\0';
      valstrings[i][values[i] - 1] = '\0';
      cache_set(cache,keystrings[i],valstrings[i],values[i]);
      free(valstrings[i]);
    }
  free(valstrings);

  uint32_t val_size = 0;

  // Get the timebase info
  // mach_timebase_info_data_t info;
  // mach_timebase_info(&info);

  uint64_t errors = 0;
  const uint64_t requests = numpairs;
  const double nsToSec = 1000000000;
  const uint32_t nsToms = 1000000;
  // uint64_t start = mach_absolute_time();
  struct timespec start, end;
  clock_gettime(CLOCK_MONOTONIC,&start);
  for(int i = 0; i < requests; ++i)
    {
      if( cache_get(cache,keystrings[i],&val_size) == -1) ++errors;
      //if( val_size == 0) ++errors;
      //val_size = 0;
    }
  // uint64_t end = mach_absolute_time();
  clock_gettime(CLOCK_MONOTONIC,&end);
  // uint64_t duration = end - start;
  uint64_t duration = (end.tv_sec * nsToSec + end.tv_nsec) - (start.tv_sec * nsToSec + start.tv_nsec);

  // Convert to nanoseconds
  // duration *= info.numer;
  // duration /= info.denom;

  uint64_t ns = duration;
  double time_elapsed_sec = (double) duration / nsToSec;

  double requests_per_second = (double) requests / time_elapsed_sec;
  double ms = (double) ns / (requests * nsToms);

  printf("Time per Get: %f milliseconds\n",ms);
  printf("Requests per second: %f requests\n",requests_per_second);
  printf("Percent of Requests that failed: %f,%d,%d\n",((double)errors/requests),errors,requests);

  destroy_cache(cache);
}
Exemple #3
0
void test_basics()
{
    cache_t cache = create_cache(65536, NULL);
    uint32_t val_size = 0;

    const uint8_t
        *key1 = (uint8_t*)"One key",
        *key2 = (uint8_t*)"Two key",
        *key3 = (uint8_t*)"Red key";

    uint8_t *value1 = (uint8_t*) "First value";
    uint64_t value2 = 20039;
    int32_t value3 = -12;

    cache_set(cache, key1, value1, strlen((char *)value1) + 1);
    cache_set(cache, key2, &value2, sizeof(value2));
    cache_set(cache, key3, &value3, sizeof(value3));

    uint8_t *result1 = (uint8_t *)cache_get(cache, key1, &val_size);
    uint64_t *result2 = (uint64_t *)cache_get(cache, key2, &val_size);
    int32_t *result3 = (int32_t *)cache_get(cache, key3, &val_size);

    bool results_not_null = result1 != NULL && result2 != NULL && result3 != NULL;
    bool string_result_correct = strcmp((const char*)value1, (const char*)result1) == 0;
    bool uint64_result_correct = *result2 == value2;
    bool int32_result_correct = *result3 == value3;
        
    test(results_not_null, "Get returns non null pointers when retrieving valid entries.");
    test(string_result_correct, "Cache can store and retrieve strings");
    test(uint64_result_correct, "Cache can store and retrieve uint64_t integers correctly.");
    test(int32_result_correct, "Cache can store and retrieve int32_t integers correctly.");
    test(val_size == sizeof(value3), "cache_get sets val_size pointer to value size.");

    destroy_cache(cache);
}
void init(){
    create_cache();
    init_plru();
    printTableLeafs();
    if(strategy_type==PLRU)
        printPRLUTree();
}
static int
add_tcp_cache(struct list* cache_list, const char* host, const char* port)
{
  struct tr_tcp_config* tcp_config_p;
  struct tr_socket* tr_socket_p;
  cache* cache_p;
  if ((tr_socket_p = XMALLOC(MTYPE_BGP_RPKI_CACHE, sizeof(struct tr_socket))) == NULL )
    {
      return ERROR;
    }
  if ((tcp_config_p = XMALLOC(MTYPE_BGP_RPKI_CACHE, sizeof(struct tr_tcp_config)))
      == NULL )
    {
      return ERROR;
    }
  tcp_config_p->host = XSTRDUP(MTYPE_BGP_RPKI_CACHE, host);
  tcp_config_p->port = XSTRDUP(MTYPE_BGP_RPKI_CACHE, port);
  tr_tcp_init(tcp_config_p, tr_socket_p);
  if ((cache_p = create_cache(tr_socket_p)) == NULL )
    {
      return ERROR;
    }
  cache_p->tr_config.tcp_config = tcp_config_p;
  cache_p->type = TCP;
  listnode_add(cache_list, cache_p);
  return SUCCESS;
}
Exemple #6
0
void LRU_cache::create_cache_starter() {
  while (true)
  {
    wait(create_cache_event);
    LRU_TRACE("SC_THREAD create_cache_starter starts create_cache()!");
    create_cache(true);
  }
}
Exemple #7
0
//Checks if a custom hash at least doesn't crash the cache (since some didn't have this customization)
//Sets a value with the custome hash and gets it to see if it was set properly
void custom_hash()
{
    uint8_t key[2] = {'a', '\0'};
    uint8_t value[6] = "12345";
    uint32_t val_size = 0;
    cache_t cache = create_cache(100 * sizeof(value));

    cache_set(cache, key, value, sizeof(value));
    uint8_t *ret = (uint8_t*)cache_get(cache, key, &val_size);
    test(!strcmp(key,"12345"), "cache_get works when given a custom hash (doesn't have to use custom hash)");

    destroy_cache(cache);
}
Exemple #8
0
//Tests if cache returns val_size from cache
//sets a value and checks if the val_size from get is equal to the set value size
void test_get_valsize()
{
    uint8_t key[2] = {'a', '\0'};
    uint8_t *value = "size me";
    uint32_t val_size = 0;
    cache_t cache = create_cache(100 * sizeof(value));

    cache_set(cache, key, value, strlen(value) + 1);
    cache_get(cache, key, &val_size);
    test(val_size == 8, "cache_get sets val_size pointer");

    destroy_cache(cache);
}
void doit(int fd)
{
    int clientfd;
    char buf[MAXLINE], method[MAXLINE], uri[MAXLINE];
    char host[MAXLINE], port[MAXLINE];
    char filename[MAXLINE];
    char cache_buf[MAX_OBJECT_SIZE];
    size_t buflen;
    struct cache *cache;
    int cache_size = 0, cache_flag = 1;
    rio_t c_rio, s_rio;

    /* Read request line and headers */
    Rio_readinitb(&c_rio, fd);
    if (!Rio_readlineb(&c_rio, buf, MAXLINE))
	return;
    printf("%s", buf);

    sscanf(buf, "%s %s", method, uri);
    if (strcasecmp(method, "GET")) {
	printf("this proxy can handle only \"GET\"\n");
	return;
    }
    construct_requesthdrs(&c_rio, buf, filename, uri, host, port);

    if (find_cache(&cache, uri) == 1) {
	Rio_writen(fd, cache->data, strlen(cache->data));
    } else {
	clientfd = Open_clientfd(host, port);
	if (clientfd < 0) {
	    printf("there is no such server\n");
	    return;
	}
	Rio_readinitb(&s_rio, clientfd);
	Rio_writen(clientfd, buf, strlen(buf));

	while ((buflen = Rio_readlineb(&s_rio, buf, MAXLINE)) != 0) {
	    Rio_writen(fd, buf, buflen);
	    if (cache_size + buflen > MAX_OBJECT_SIZE) {
		cache_flag = 0;
	    } else {
		memcpy(cache_buf + cache_size, buf, buflen);
		cache_size += buflen;
	    }
	}
	if (cache_flag == 1)
	    create_cache(cache_buf, uri);
	Close(clientfd);
    }
}
static int
add_ssh_cache(struct list* cache_list, const char* host,
    const unsigned int port, const char* username,
    const char* client_privkey_path, const char* client_pubkey_path,
    const char* server_pubkey_path)
{
#if defined(FOUND_SSH)
  struct tr_ssh_config* ssh_config_p;
  struct tr_socket* tr_socket_p;
  cache* cache_p;
  if ((tr_socket_p = XMALLOC(MTYPE_BGP_RPKI_CACHE, sizeof(struct tr_socket))) == NULL )
    {
      return ERROR;
    }
  if ((ssh_config_p = XMALLOC(MTYPE_BGP_RPKI_CACHE, sizeof(struct tr_ssh_config)))
      == NULL )
    {
      return ERROR;
    }

  memcpy(&(ssh_config_p->port), &port, sizeof(int));
  ssh_config_p->host = XSTRDUP(MTYPE_BGP_RPKI_CACHE, host);

  ssh_config_p->username = XSTRDUP(MTYPE_BGP_RPKI_CACHE, username);
  ssh_config_p->client_privkey_path = XSTRDUP(MTYPE_BGP_RPKI_CACHE,
      client_privkey_path);

  if (server_pubkey_path != NULL )
    {
      ssh_config_p->server_hostkey_path = XSTRDUP(MTYPE_BGP_RPKI_CACHE,
          server_pubkey_path);
      ;
    }
  else
    {
      ssh_config_p->server_hostkey_path = NULL;
    }

  tr_ssh_init(ssh_config_p, tr_socket_p);
  if ((cache_p = create_cache(tr_socket_p)) == NULL )
    {
      return ERROR;
    }
  cache_p->tr_config.ssh_config = ssh_config_p;
  cache_p->type = SSH;
  listnode_add(cache_list, cache_p);
  return SUCCESS;
#endif
  return ERROR;
}
Exemple #11
0
void PlaybackEngine::perform_change()
{
	switch(command->change_type)
	{
		case CHANGE_ALL:
			create_cache();
		case CHANGE_EDL:
			create_render_engine();
		case CHANGE_PARAMS:
			if(command->change_type != CHANGE_EDL &&
				(uint32_t)command->change_type != CHANGE_ALL)
				render_engine->get_edl()->synchronize_params(command->get_edl());
		case CHANGE_NONE:
			break;
	}
}
Exemple #12
0
void test_get_nonexistant()
{
    cache_t cache = create_cache(65536, NULL);
    uint32_t val_size = 1;

    const uint8_t *key = (uint8_t *)"weather";

    uint8_t *result = (uint8_t *)cache_get(cache, key, &val_size);

    bool get_nothing_gives_null = result == NULL;
    bool nonexistant_val_size_is_zero = val_size == 0;

    test(get_nothing_gives_null, "Get return NULL when key is missing.");
    test(nonexistant_val_size_is_zero, "Get sets value size to zero when key is missing.");

    destroy_cache(cache);
}
Exemple #13
0
void test_too_big()
{
    cache_t cache = create_cache(10, NULL);
    uint32_t val_size = 0;

    const uint8_t *key = (uint8_t *)"chrome";
    uint8_t *value = (uint8_t *)"This is supposed to be too big to fit into this cache";

    cache_set(cache, key, value, strlen((char *)value) + 1);
    uint8_t *result = (uint8_t *)cache_get(cache, key, &val_size);

    bool large_val_wasnt_saved = result == NULL;

    test(large_val_wasnt_saved, "Cache does not store large values.");

    destroy_cache(cache);
}
Exemple #14
0
void test_gets(uint8_t* keys, uint32_t* values, uint64_t numpairs)
{
  cache_t cache = create_cache(numpairs*10);

  struct timespec start, end;
  const uint64_t requests = numpairs;
  const double nsToSec = 1000000000;
  const uint32_t nsToms = 1000000;

  char **keystrings = calloc(numpairs,sizeof(char*));
  char **valstrings = calloc(numpairs,sizeof(char*));

  for(int i = 0; i < numpairs; ++i)
    {
      keystrings[i] = calloc(keys[i],1);
      valstrings[i] = calloc(values[i],1);
      memset(keystrings[i],'K',keys[i]);
      memset(valstrings[i],'V',values[i]);
      keystrings[i][keys[i] - 1] = '\0';
      valstrings[i][values[i] - 1] = '\0';
    }

  clock_gettime(CLOCK_MONOTONIC,&start);
  for(int i = 0; i < numpairs; ++i)
      cache_set(cache,keystrings[i],valstrings[i],values[i]);
  clock_gettime(CLOCK_MONOTONIC,&end);

  uint64_t duration = (end.tv_sec * nsToSec + end.tv_nsec) - (start.tv_sec * nsToSec + start.tv_nsec);

  uint64_t ns = duration;
  double time_elapsed_sec = (double) duration / nsToSec;

  double requests_per_second = (double) requests / time_elapsed_sec;
  double ms = (double) ns / (requests * nsToms);

  printf("Time per Get: %f milliseconds\n",ms);
  printf("Requests per second: %f requests\n",requests_per_second);

  for(int i = 0; i < numpairs; ++i)
    free(valstrings[i]);
  free(valstrings);
}
Exemple #15
0
void test_copying_keys()
{
    cache_t cache = create_cache(65536, NULL);
    uint32_t val_size = 0;

    uint8_t *key1 = (uint8_t *)"original";
    uint8_t *key2 = (uint8_t *)"original";
    uint8_t *value = (uint8_t *)"nothing seemed to turn out right";

    cache_set(cache, key1, value, strlen((char *)value) + 1);

    key1 = (uint8_t *)"fake";

    uint8_t *result = (uint8_t *)cache_get(cache, key2, &val_size);

    bool key_still_valid = result != NULL;

    test(key_still_valid, "Changing original key does not change key in cache");

    destroy_cache(cache);
}
Exemple #16
0
//Copies all "in-use" key/values to a new cache and reassigns the cache pointer
//If expand == 1, this also doubles the size of the cache
void defrag(cache_t cache, uint8_t expand)
{
  cache_real_obj *c = cache->cache;
  uint64_t maxmem = (expand == 1) ? c->size * 2 : c->size;
  printf("   ");
  cache_t new_cache = create_cache(maxmem, NULL, NULL, NULL);
  int i;
  for (i=0; i < c->num_buckets; i++)
    {
      node* current = c->buckets[i]->head;
      while (current != NULL)
	{
	  cache_set(new_cache, current->meta->key, current->meta->address, current->meta->size);
	  current = current->next;
	}
    };
  printf("   ");
  destroy_cache_obj(c);
  cache->cache = new_cache->cache;
  free(new_cache);
}
Exemple #17
0
cache_t initialize_cache(uint64_t memsize, uint32_t store_num){
    cache_t cache = create_cache(memsize);
    //Open input files
    /*FILE * fp_key, * fp_value;
     char key_filename[256] = {0};
     char value_filename[256] = {0};
     sprintf(key_filename,"/Users/ZiyuanZhong/微云同步盘/课程教材/16spring/CS442/MATH442_HW6/input_data/store_num_key.in");
     sprintf(value_filename,"/Users/ZiyuanZhong/微云同步盘/课程教材/16spring/CS442/MATH442_HW6/input_data/store_num_value.in");
     fp_key = fopen(key_filename, "r");
     fp_value = fopen(value_filename, "r");
     if (fp_key==NULL){fprintf(stderr, "fail to open file:%s\n",key_filename);exit(EXIT_FAILURE);}
     if (fp_value==NULL){fprintf(stderr, "fail to open file:%s\n",key_filename);exit(EXIT_FAILURE);}
     
     size_t len = 0;
     size_t len2 = 0;
     ssize_t read;
     ssize_t read2;
     char * line = malloc(MAXDATASIZE+1);
     char * line2 = malloc(MAXDATASIZE+1);
     bzero(line,MAXDATASIZE+1);
     bzero(line2,MAXDATASIZE+1);
     for (uint32_t i=0;i<STORENUM;i++){
     read = getline(&line, &len, fp_key);
     read2 = getline(&line2, &len2, fp_value);
     //printf("read:%zd,read2:%zd\n",read,read2);
     if (read!=-1&&read2!=-1){
     line[len-1] = '\0';
     line2[len2-1] = '\0';
     strtok(line,"\n");
     strtok(line2,"\n");
     cache_set(cache,(key_type)line,(val_type)line2,(uint32_t)len2);
     }
     else {
     fprintf(stderr, "fail to read line\n");
     }
     }
     free(line);
     free(line2);*/
    return cache;
}
Exemple #18
0
void test_get_modified()
{
    cache_t cache = create_cache(65536, NULL);
    uint32_t val_size = 0;

    const uint8_t *key = (uint8_t *)"weather";
    uint8_t *value = (uint8_t *)"sunny";

    cache_set(cache, key, value, strlen((char *)value) + 1);

    value = (uint8_t *)"pouring rain forever";
    cache_set(cache, key, value, strlen((char *)value) + 1);

    uint8_t *result = (uint8_t *)cache_get(cache, key, &val_size);

    bool value_is_updated = result != NULL && strcmp((const char*)value, (const char*)result) == 0;
    bool val_size_updated = val_size == strlen((char *)value) + 1;

    test(value_is_updated, "Setting to same key updates the value.");
    test(val_size_updated, "Value size from get is updated by cache_set.");
    
    destroy_cache(cache);
}
Exemple #19
0
//cache evicts keys to make room for new ones (jmcosel has a memsize min of 64)
//creates a cache with memsize of 64 and sets 4 values so that the 3rd will
//cause an eviction (if they didn't mess with the maxmem)
void eviction_couple()
{
  cache_t cache = create_cache(64);
  key_type
    key0 = (const uint8_t*) "hello",
    key1 = (const uint8_t*) "thenumber3",
    key2 = (const uint8_t*) "goodbye",
    key3 = (const uint8_t*) "wow";
  uint8_t
    *value0 = "a",
    *value1 = "b";
  uint8_t *chararray = "01234567890123456789012345678901234567890123456789012345678";
  uint8_t *value3 = "c";

  cache_set(cache,key0,value0,strlen(value0) + 1);
  cache_set(cache,key1,value1,strlen(value1) + 1);
  cache_set(cache,key2,chararray,60);
  cache_set(cache,key3,value3,strlen(value3) + 1);

  uint32_t val_size = 0;
  uint8_t *val = (uint8_t*) cache_get(cache,key3,&val_size);
  test(!strcmp(val,"c"),"keys are evicted to make space for new values");
  destroy_cache(cache);
}
Exemple #20
0
//sets 4 values, gets the first value set, and sets a new value
//big enough to force an eviction, checks if the second key (least recently used)
//is removed, the third is removed, and finally if the first value added is still there
void evict_after_get()
{
  cache_t cache = create_cache(64);
  key_type
    key0 = (const uint8_t*) "hello",
    key1 = (const uint8_t*) "thenumber3",
    key2 = (const uint8_t*) "goodbye",
    key3 = (const uint8_t*) "wow";
  uint8_t
    *value0 = "1",
    *value1 = "3";
  uint8_t value2[60] = "01234567890123456789012345678901234567890123456789012345678";
  uint8_t *value3 = "123123124";

  cache_set(cache,key0,value0,strlen(value0) + 1);
  cache_set(cache,key1,value1,strlen(value1) + 1);
  cache_set(cache,key2,value2,60);

  uint32_t val_size = 0;
  uint8_t *val;

  // access first input
  val = (uint8_t*) cache_get(cache,key0,&val_size);

  // Set something that will require an eviction
  cache_set(cache,key3,value3,strlen(value3) + 1);

  // now get the last used value
  uint8_t *val0 = (uint8_t*) cache_get(cache,key0,&val_size);
  uint8_t *val1 = (uint8_t*) cache_get(cache,key1,&val_size);
  uint8_t *val2 = (uint8_t*) cache_get(cache,key2,&val_size);
  uint8_t *val3 = (uint8_t*) cache_get(cache,key3,&val_size);

  test(!strcmp(val0,"1") && val1 == NULL && val2 == NULL && !strcmp(val3,"123123124"),"Last accessed key is evicted");
  destroy_cache(cache);
}
/**
 * hls_progress_buffer_init()
 *
 * Initializer.  Automatically declared in the GST_BOILERPLATE macro above.  Should be
 * only called by GStreamer.
 */
static void hls_progress_buffer_init(HLSProgressBuffer *element, HLSProgressBufferClass *element_klass)
{
    GstElementClass *klass = GST_ELEMENT_CLASS (element_klass);
    int i = 0;

    element->sinkpad = gst_pad_new_from_template (gst_element_class_get_pad_template (klass, "sink"), "sink");
    gst_pad_set_chain_function(element->sinkpad, hls_progress_buffer_chain);
    gst_pad_set_event_function(element->sinkpad, hls_progress_buffer_sink_event);
    gst_element_add_pad (GST_ELEMENT (element), element->sinkpad);

    element->srcpad = gst_pad_new_from_template (gst_element_class_get_pad_template (GST_ELEMENT_GET_CLASS(element), "src"), "src");
    gst_pad_set_activatepush_function(element->srcpad, hls_progress_buffer_activatepush_src);
    gst_pad_set_event_function(element->srcpad, hls_progress_buffer_src_event);
    gst_element_add_pad (GST_ELEMENT (element), element->srcpad);

    element->lock = g_mutex_new();
    element->add_cond = g_cond_new();
    element->del_cond = g_cond_new();

    for (i = 0; i < NUM_OF_CACHED_SEGMENTS; i++)
    {
        element->cache[i] = create_cache();
        element->cache_size[i] = 0;
        element->cache_write_ready[i] = TRUE;
    }

    element->cache_write_index = -1;
    element->cache_read_index = 0;

    element->send_new_segment = TRUE;

    element->is_flushing = FALSE;
    element->is_eos = FALSE;

    element->srcresult = GST_FLOW_OK;
}
Exemple #22
0
int
main(int argc, const char **argv)
{
    int res = 0;
    int optCount = 0;

    dbgIn = stdin;
    conOut = stdout;
    (void)conIn;
    (void)dbgOut;

    memset(&cache, 0, sizeof(LIST));
    memset(&sources, 0, sizeof(LIST));
    stat_clear(&summ);
    memset(&revinfo, 0, sizeof(REVINFO));
    clearLastLine();

    optionInit(argc, argv);
    optCount = optionParse(argc, argv);
    if (optCount < 0)
    {
        return optCount;
    }

    argc -= optCount;

    if (opt_Revision && (strcmp(opt_Revision, "update") == 0))
    {
        res = updateSvnlog();
        return res;
    }

    if (check_directory(opt_force))
        return 3;

    create_cache(opt_force, 0);
    if (opt_exit)
        return 0;

    read_cache();
    l2l_dbg(4, "Cache read complete\n");

    if (set_LogFile(&logFile))
        return 2;
    l2l_dbg(4, "opt_logFile processed\n");

    if (opt_Pipe)
    {
        l2l_dbg(3, "Command line: \"%s\"\n",opt_Pipe);

        if (!(dbgIn = POPEN(opt_Pipe, "r")))
        {
            dbgIn = stdin; //restore
            l2l_dbg(0, "Could not popen '%s' (%s)\n", opt_Pipe, strerror(errno));
            free(opt_Pipe); opt_Pipe = NULL;
        }
    }
    l2l_dbg(4, "opt_Pipe processed\n");

    if (argc > 1)
    {   // translate {<exefile> <offset>}
        int i = 1;
        const char *exefile = NULL;
        const char *offset = NULL;
        char Line[LINESIZE + 1];

        while (i < argc)
        {
            Line[0] = '\0';
            offset = argv[optCount + i++];
            if (isOffset(offset))
            {
                if (exefile)
                {
                    l2l_dbg(2, "translating %s %s\n", exefile, offset);
                    translate_file(exefile, my_atoi(offset), Line);
                    printf("%s\n", Line);
                    report(conOut);
                }
                else
                {
                    l2l_dbg(0, "<exefile> expected\n");
                    res = 3;
                    break;
                }
            }
            else
            {
                // Not an offset so must be an exefile:
                exefile = offset;
            }
        }
    }
    else
    {   // translate logging from stdin
        translate_files(dbgIn, conOut);
    }

    if (logFile)
        fclose(logFile);

    if (opt_Pipe)
        PCLOSE(dbgIn);

    return res;
}
/* Run Command:  ./sim_cache <Block Size> <L1 Size> <L1 Associativity> <Victim Cache Number of Blocks> <L2 Size> <L2 Associativity> <Trace File> */
int main(int argc, char *argv[])
{
        if(argc <= 7)
        {
                printf("Usage: ./sim_cache <Block Size> <L1 Size> <L1 Associativity> <Victim Cache Number of Blocks> <L2 Size> <L2 Associativity> <Trace File>.\n");
                return 0;
        }

        unsigned int blocksize = atoi(argv[1]);
        unsigned int L1_size = atoi(argv[2]);
        unsigned int L1_assoc = atoi(argv[3]);
        unsigned int L1_vc_blocks = atoi(argv[4]);
        unsigned int L2_size = atoi(argv[5]);
        unsigned int L2_assoc = atoi(argv[6]);
        
        struct cache *L1 = (struct cache*)malloc(sizeof(struct cache));
        struct cache *L2 = NULL;
        struct cache *vc = NULL;
        L1 = create_cache(blocksize,L1_assoc,L1_size,"L1");
        
        if(L1_vc_blocks > 0)
        {
             vc = (struct cache*)malloc(sizeof(struct cache));
             vc = create_cache(blocksize,L1_vc_blocks,L1_vc_blocks*blocksize,"VC");
             L1->vc = vc;
        }

        if(L2_size > 0 && L2_assoc >= 1)
        {
            L2 = (struct cache*)malloc(sizeof(struct cache));
            L2 = create_cache(blocksize,L2_assoc,L2_size,"L2");
            L1->next = L2;
        }

        if(L1_vc_blocks > 0 && L2_size > 0 && L2_assoc >= 1)
        {
            vc->next = L2;
        }

        strcpy(L1->trace,argv[7]);
        FILE *trace = fopen(argv[7],"r");
        if(trace == NULL)
        {
                printf("Error: Could not open file.\n");
                return 0;
        }
        
        char str[12],address[12];
        unsigned long num_addr;
        int i;
        unsigned int instr = 0;
        print_simulator_config(L1);
        while(fgets(str, 12, trace) != NULL)
        {
                for(i=0;i<strlen(str);i++)
                    if(str[i] == '\n')
                      str[i] = '\0';

                for(i=2;i<=strlen(str);i++)
                {
                        address[i-2] = str[i];
                }
                address[i-2] = '\0';
                num_addr = (int)strtoul(address, NULL, 16);
                
                instr++;
                if(str[0] == 'r')
                {
                        if (DEBUG == 1 ) {printf("----------------------------------------\n");}
                        if (DEBUG == 1 ) {printf("# %d: read %lx\n",instr,num_addr);}
                        access_cache(L1,num_addr, str[0]);
                }
                else if(str[0] == 'w')
                {
                        if (DEBUG == 1 ) {printf("----------------------------------------\n");}
                        if (DEBUG == 1 ) {printf("# %d: write %lx\n",instr,num_addr);}
                        access_cache(L1,num_addr, str[0]);
                }
                else if(str[0] == ' ')
                {
                        printf("Null character in trace");
                }
                //DEBUG HELP: print_cache(L1);
                //DEBUG HELP: print_cache(L1->vc);
                //DEBUG HELP: print_cache(L2);
        }
        fclose(trace);

        printf("===== L1 contents =====\n");
        print_cache(L1);
        
        if(L1_vc_blocks > 0)
        {
            printf("\n===== VC contents =====\n");
            print_cache(vc);
        }
    
        if(L2_size >= 0 && L2_assoc >= 1)
        {
            printf("\n===== L2 contents =====\n");
            print_cache(L1->next);
        }
        print_simulation_summary(L1);

        if(L2_size > 0 && L2_assoc >= 1)
        {
            delete_cache(L2);
        }
        else
        {
            free(L2);
        }
        
        if(L1_vc_blocks > 0)
        {
            delete_cache(vc);
        }
        else
        {
            free(vc);
        }
        delete_cache(L1);
        
        return 0;
}
Exemple #24
0
//For those who have more than two paras in their create_cache functions:
//1.442-HW-3
//4.Hash_it_Out
//5.Master
//6.MATH442_HW3
//7.sysHW3
cache_t create_cache_hash_fake(uint64_t maxmem, hash_func hash){
    return create_cache(maxmem, hash, NULL);
}
Exemple #25
0
//Customization
//For 3.hw3
//#define key_type _key_t;
//#define val_type val_t;
cache_t create_cache_fake(uint64_t maxmem){
    return create_cache(maxmem, NULL, NULL);
}
cache_simulator_t::cache_simulator_t(const cache_simulator_knobs_t &knobs_) :
    simulator_t(knobs_.num_cores, knobs_.skip_refs, knobs_.warmup_refs,
                knobs_.warmup_fraction, knobs_.sim_refs,
                knobs_.cpu_scheduling, knobs_.verbose),
    knobs(knobs_),
    icaches(NULL),
    dcaches(NULL),
    is_warmed_up(false)
{
    // XXX i#1703: get defaults from hardware being run on.

    llcache = create_cache(knobs.replace_policy);
    if (llcache == NULL) {
        success = false;
        return;
    }

    if (knobs.data_prefetcher != PREFETCH_POLICY_NEXTLINE &&
        knobs.data_prefetcher != PREFETCH_POLICY_NONE) {
        // Unknown value.
        success = false;
        return;
    }

    bool warmup_enabled = ((knobs.warmup_refs > 0) || (knobs.warmup_fraction > 0.0));

    if (!llcache->init(knobs.LL_assoc, (int)knobs.line_size,
                       (int)knobs.LL_size, NULL,
                       new cache_stats_t(knobs.LL_miss_file, warmup_enabled))) {
        ERRMSG("Usage error: failed to initialize LL cache.  Ensure sizes and "
               "associativity are powers of 2, that the total size is a multiple "
               "of the line size, and that any miss file path is writable.\n");
        success = false;
        return;
    }

    icaches = new cache_t* [knobs.num_cores];
    dcaches = new cache_t* [knobs.num_cores];
    for (unsigned int i = 0; i < knobs.num_cores; i++) {
        icaches[i] = create_cache(knobs.replace_policy);
        if (icaches[i] == NULL) {
            success = false;
            return;
        }
        dcaches[i] = create_cache(knobs.replace_policy);
        if (dcaches[i] == NULL) {
            success = false;
            return;
        }

        if (!icaches[i]->init(knobs.L1I_assoc, (int)knobs.line_size,
                              (int)knobs.L1I_size, llcache,
                              new cache_stats_t("", warmup_enabled)) ||
            !dcaches[i]->init(knobs.L1D_assoc, (int)knobs.line_size,
                              (int)knobs.L1D_size, llcache,
                              new cache_stats_t("", warmup_enabled),
                              knobs.data_prefetcher == PREFETCH_POLICY_NEXTLINE ?
                              new prefetcher_t((int)knobs.line_size) : nullptr)) {
            ERRMSG("Usage error: failed to initialize L1 caches.  Ensure sizes and "
                   "associativity are powers of 2 "
                   "and that the total sizes are multiples of the line size.\n");
            success = false;
            return;
        }
    }
}
Exemple #27
0
/**
 * progress_buffer_enqueue_item()
 *
 * Add an item in the queue. Must be called in the locked context.  Item may be event or data.
 */
static GstFlowReturn progress_buffer_enqueue_item(ProgressBuffer *element, GstMiniObject *item)
{
    gboolean signal = FALSE;

    if (GST_IS_BUFFER (item))
    {
        gdouble elapsed;
        // update sink segment position
        element->sink_segment.position = GST_BUFFER_OFFSET(GST_BUFFER(item)) + gst_buffer_get_size (GST_BUFFER(item));

        if(element->sink_segment.stop < element->sink_segment.position) // This must never happen.
            return  GST_FLOW_ERROR;

        cache_write_buffer(element->cache, GST_BUFFER(item));

        elapsed = g_timer_elapsed(element->bandwidth_timer, NULL);
        element->subtotal += gst_buffer_get_size (GST_BUFFER(item));

        if (elapsed > 1.0)
        {
            element->bandwidth = element->subtotal/elapsed;
            element->subtotal = 0;
            g_timer_start(element->bandwidth_timer);
        }

        // send buffer progress position up (used to track buffer fill, etc.)
        signal = send_position_message(element, signal);
    }
    else if (GST_IS_EVENT (item))
    {
        GstEvent *event = GST_EVENT_CAST (item);

        switch (GST_EVENT_TYPE (event))
        {
            case GST_EVENT_EOS:
                element->eos_status.eos = TRUE;
                if (element->sink_segment.position < element->sink_segment.stop)
                    element->sink_segment.stop = element->sink_segment.position;

                progress_buffer_set_pending_event(element, NULL);

                signal = send_position_message(element, TRUE);
                gst_event_unref(event); // INLINE - gst_event_unref()
                break;

            case GST_EVENT_SEGMENT:
            {
                GstSegment segment;

                element->unexpected = FALSE;

                gst_event_copy_segment (event, &segment);

                if (segment.format != GST_FORMAT_BYTES)
                {
                    gst_element_message_full(GST_ELEMENT(element), GST_MESSAGE_ERROR, GST_STREAM_ERROR, GST_STREAM_ERROR_FORMAT,
                                             g_strdup("GST_FORMAT_BYTES buffers expected."), NULL,
                                             ("progressbuffer.c"), ("progress_buffer_enqueue_item"), 0);
                    gst_event_unref(event); // INLINE - gst_event_unref()
                    return GST_FLOW_ERROR;
                 }

                if (segment.stop - segment.start <= 0)
                {
                    gst_element_message_full(GST_ELEMENT(element), GST_MESSAGE_ERROR, GST_STREAM_ERROR, GST_STREAM_ERROR_WRONG_TYPE,
                                             g_strdup("Only limited content is supported by progressbuffer."), NULL,
                                             ("progressbuffer.c"), ("progress_buffer_enqueue_item"), 0);
                    gst_event_unref(event); // INLINE - gst_event_unref()
                    return GST_FLOW_ERROR;
                }

                if ((segment.flags & GST_SEGMENT_FLAG_UPDATE) == GST_SEGMENT_FLAG_UPDATE) // Updating segments create new cache.
                {
                    if (element->cache)
                        destroy_cache(element->cache);

                    element->cache = create_cache();
                    if (!element->cache)
                    {
                        gst_element_message_full(GST_ELEMENT(element), GST_MESSAGE_ERROR, GST_RESOURCE_ERROR, GST_RESOURCE_ERROR_OPEN_READ_WRITE,
                                                 g_strdup("Couldn't create backing cache"), NULL,
                                                 ("progressbuffer.c"), ("progress_buffer_enqueue_item"), 0);
                        gst_event_unref(event); // INLINE - gst_event_unref()
                        return GST_FLOW_ERROR;
                    }
                }
                else
                {
                    cache_set_write_position(element->cache, 0);
                    cache_set_read_position(element->cache, 0);
                    element->cache_read_offset = segment.start;
                }

                gst_segment_copy_into (&segment, &element->sink_segment);
                progress_buffer_set_pending_event(element, event);
                element->instant_seek = TRUE;

                signal = send_position_message(element, TRUE);
                break;
            }

            default:
                gst_event_unref(event); // INLINE - gst_event_unref()
                break;
        }
    }

    if (signal)
        g_cond_signal(&element->add_cond);

    return GST_FLOW_OK;
}
Exemple #28
0
static int __init aufs_init(void)
{
	int err, i;
	char *p;

	au_debug_init();
#ifdef CONFIG_AUFS_INO_T_64
	BUILD_BUG_ON(sizeof(ino_t) != sizeof(long long));
#else
	BUILD_BUG_ON(sizeof(ino_t) != sizeof(int));
#endif

	p = au_esc_chars;
	for (i = 1; i <= ' '; i++)
		*p++ = i;
	*p++ = '\\';
	*p++ = '\x7f';
	*p = 0;

	au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);

	err = -EINVAL;
	if (unlikely(aufs_nwkq <= 0))
		goto out;

	err = sysaufs_init();
	if (unlikely(err))
		goto out;
	err = au_wkq_init();
	if (unlikely(err))
		goto out_sysaufs;
	err = au_inotify_init();
	if (unlikely(err))
		goto out_wkq;
	err = au_sysrq_init();
	if (unlikely(err))
		goto out_inotify;

	err = create_cache();
	if (unlikely(err))
		goto out_sysrq;

	err = register_filesystem(&aufs_fs_type);
	if (unlikely(err))
		goto out_cache;
	pr_info(AUFS_NAME " " AUFS_VERSION "\n");
	return 0; /* success */

 out_cache:
	destroy_cache();
 out_sysrq:
	au_sysrq_fin();
 out_inotify:
	au_inotify_fin();
 out_wkq:
	au_wkq_fin();
 out_sysaufs:
	sysaufs_fin();
 out:
	AuTraceErr(err);
	return err;
}
Exemple #29
0
static krb5_error_code KRB5_CALLCONV
scc_initialize(krb5_context context,
	       krb5_ccache id,
	       krb5_principal primary_principal)
{
    krb5_scache *s = SCACHE(id);
    krb5_error_code ret;

    ret = make_database(context, s);
    if (ret)
	return ret;

    ret = exec_stmt(context, s->db, "BEGIN IMMEDIATE TRANSACTION", KRB5_CC_IO);
    if (ret) return ret;

    if (s->cid == SCACHE_INVALID_CID) {
	ret = create_cache(context, s);
	if (ret)
	    goto rollback;
    } else {
	sqlite3_bind_int(s->dcred, 1, s->cid);
	do {
	    ret = sqlite3_step(s->dcred);
	} while (ret == SQLITE_ROW);
	sqlite3_reset(s->dcred);
	if (ret != SQLITE_DONE) {
	    ret = KRB5_CC_IO;
	    krb5_set_error_message(context, ret,
				   N_("Failed to delete old "
				      "credentials: %s", ""),
				   sqlite3_errmsg(s->db));
	    goto rollback;
	}
    }

    ret = bind_principal(context, s->db, s->ucachep, 1, primary_principal);
    if (ret)
	goto rollback;
    sqlite3_bind_int(s->ucachep, 2, s->cid);

    do {
	ret = sqlite3_step(s->ucachep);
    } while (ret == SQLITE_ROW);
    sqlite3_reset(s->ucachep);
    if (ret != SQLITE_DONE) {
	ret = KRB5_CC_IO;
	krb5_set_error_message(context, ret,
			       N_("Failed to bind principal to cache %s", ""),
			       sqlite3_errmsg(s->db));
	goto rollback;
    }

    ret = exec_stmt(context, s->db, "COMMIT", KRB5_CC_IO);
    if (ret) return ret;

    return 0;

rollback:
    exec_stmt(context, s->db, "ROLLBACK", 0);

    return ret;

}
Exemple #30
0
 /// Returns a complete byte array of this OSC message as a ByteArray type.
 /// The byte array is constructed lazily and is cached until the cache is
 /// obsolete. Call to |data| and |size| perform the same caching.
 ///
 /// @return The OSC message as a ByteArray.
 /// @see data
 /// @see size
 const ByteArray& byte_array() const {
   if (is_cached_) return cache_;
   else return create_cache(); }