Exemplo n.º 1
0
/* check simulator-specific option values */
void
sim_check_options(void)	/* command line arguments */
{
  /* use a level 1 D-cache? */
  if (mystricmp(cache_dl1_opt.opt, "none"))
    {
      cache_check_options(&cache_dl1_opt);
      cache_dl1 = cache_create(&cache_dl1_opt);
    }

  /* use a level 1 I-cache? */
  if (mystricmp(cache_il1_opt.opt, "none"))
    {
      if (!mystricmp(cache_il1_opt.opt, "dl1"))
	{
	  if (!cache_dl1)
	    fatal("L1 I-cache cannot access L1 D-cache as it's undefined");
	  cache_il1 = cache_dl1;
	}
      else /* il1 is defined */
	{
	  cache_check_options(&cache_il1_opt);
	  cache_il1 = cache_create(&cache_il1_opt);
	}
    }

  if (mystricmp(cache_l2_opt.opt, "none"))
    {
      if (!cache_dl1 && !cache_il1)
	fatal("can't have an L2 D-cache without an L1 D-cache or I-cache!");

      cache_check_options(&cache_l2_opt);
      cache_l2 = cache_create(&cache_l2_opt);
    }

  /* use a D-TLB? */
  if (mystricmp(dtlb_opt.opt, "none"))
    {
      cache_check_options(&dtlb_opt);
      dtlb = cache_create(&dtlb_opt);
    }

  /* use an I-TLB? */
  if (mystricmp(itlb_opt.opt, "none"))
    {
      if (!mystricmp(itlb_opt.opt, "dtlb"))
	{
	  if (!dtlb)
	    fatal("I-TLB cannot use D-TLB as it is undefined");
	  itlb = dtlb;
	}
      else
	{
	  cache_check_options(&itlb_opt);
	  itlb = cache_create(&itlb_opt);
	}
    }
}
Exemplo n.º 2
0
/*
 * Set up a thread's information.
 */
static void setup_thread(LIBEVENT_THREAD *me) {
#if defined(LIBEVENT_VERSION_NUMBER) && LIBEVENT_VERSION_NUMBER >= 0x02000101
    struct event_config *ev_config;
    ev_config = event_config_new();
    event_config_set_flag(ev_config, EVENT_BASE_FLAG_NOLOCK);
    me->base = event_base_new_with_config(ev_config);
    event_config_free(ev_config);
#else
    me->base = event_init();
#endif

    if (! me->base) {
        fprintf(stderr, "Can't allocate event base\n");
        exit(1);
    }

    /* Listen for notifications from other threads */
    event_set(&me->notify_event, me->notify_receive_fd,
              EV_READ | EV_PERSIST, thread_libevent_process, me);
    event_base_set(me->base, &me->notify_event);

    if (event_add(&me->notify_event, 0) == -1) {
        fprintf(stderr, "Can't monitor libevent notify pipe\n");
        exit(1);
    }

    me->new_conn_queue = malloc(sizeof(struct conn_queue));
    if (me->new_conn_queue == NULL) {
        perror("Failed to allocate memory for connection queue");
        exit(EXIT_FAILURE);
    }
    cq_init(me->new_conn_queue);

    if (pthread_mutex_init(&me->stats.mutex, NULL) != 0) {
        perror("Failed to initialize mutex");
        exit(EXIT_FAILURE);
    }

    me->suffix_cache = cache_create("suffix", SUFFIX_SIZE, sizeof(char*),
                                    NULL, NULL);
    if (me->suffix_cache == NULL) {
        fprintf(stderr, "Failed to create suffix cache\n");
        exit(EXIT_FAILURE);
    }
#ifdef EXTSTORE
    me->io_cache = cache_create("io", sizeof(io_wrap), sizeof(char*), NULL, NULL);
    if (me->io_cache == NULL) {
        fprintf(stderr, "Failed to create IO object cache\n");
        exit(EXIT_FAILURE);
    }
#endif
}
Exemplo n.º 3
0
void
init_block_list(int firewall)
{
    // Initialize cache
#ifdef __linux__
    if (firewall)
        init_firewall();
    else
        mode = NO_FIREWALL_MODE;
    cache_create(&block_list, 256, free_firewall_rule);
#else
    cache_create(&block_list, 256, NULL);
#endif
}
Exemplo n.º 4
0
static int callback_open(const char *path, struct fuse_file_info *finfo) {
    Node *node;


mylog("::open(%s)\n", path);
    /* We allow opens, unless they're tring to write, sneaky
     * people. */
    int flags = finfo->flags;

    if ((flags & O_WRONLY) || (flags & O_RDWR) || (flags & O_CREAT) || (flags & O_EXCL) || (flags & O_TRUNC) || (flags & O_APPEND)) {
        return(-EROFS);
    }

    node = get_node_path(path);
    if (node == NULL) {
        return(-ENOENT);
    }
  
    /* create the associated cache */
    if ((node->file)&&(!node->special)) {  /* only handle cache for files */
        /* do not create cache for empty files */
	if (node->size > 0) {
            if (cache_create(path, node->size) == NULL) {
		/* something goes wrong. Refuse open */
		return(-EBUSY);
	    }
	}
    }
    stat_open++;
    stat_used++;

    /* ok */
    return(0);
}
Exemplo n.º 5
0
static EventEntry* skeleton_init_driver(void)
{
    struct skeleton_entry *e = calloc(1, sizeof(struct skeleton_entry));
    if (e == NULL) return NULL;
    NEOERR *err;

    e->base.name = (unsigned char*)strdup(PLUGIN_NAME);
    e->base.ksize = strlen(PLUGIN_NAME);
    e->base.process_driver = skeleton_process_driver;
    e->base.stop_driver = skeleton_stop_driver;
    //mevent_add_timer(&e->base.timers, 60, true, hint_timer_up_term);

    //char *s = hdf_get_value(g_cfg, CONFIG_PATH".dbsn", NULL);
    //err = mdb_init(&e->db, s);
    //JUMP_NOK(err, error);
    
    e->cd = cache_create(hdf_get_int_value(g_cfg, CONFIG_PATH".numobjs", 1024), 0);
    if (e->cd == NULL) {
        wlog("init cache failure");
        goto error;
    }
    
    return (EventEntry*)e;
    
error:
    if (e->base.name) free(e->base.name);
    if (e->db) mdb_destroy(e->db);
    if (e->cd) cache_free(e->cd);
    free(e);
    return NULL;
}
/*
** **********************************************************************
** * PUBLIC INTERFACE
** * See protocol_handler.h for function description
** **********************************************************************
*/
struct memcached_protocol_st *memcached_protocol_create_instance(void)
{
  struct memcached_protocol_st *ret= calloc(1, sizeof(*ret));
  if (ret != NULL)
  {
    ret->recv= default_recv;
    ret->send= default_send;
    ret->drain= drain_output;
    ret->spool= spool_output;
    ret->input_buffer_size= 1 * 1024 * 1024;
    ret->input_buffer= malloc(ret->input_buffer_size);
    if (ret->input_buffer == NULL)
    {
      free(ret);
      ret= NULL;

      return NULL;
    }

    ret->buffer_cache= cache_create("protocol_handler",
                                     CHUNK_BUFFERSIZE + sizeof(struct chunk_st),
                                     0, NULL, NULL);
    if (ret->buffer_cache == NULL)
    {
      free(ret->input_buffer);
      free(ret);
    }
  }

  return ret;
}
Exemplo n.º 7
0
static struct event_entry* aic_init_driver(void)
{
    struct aic_entry *e = calloc(1, sizeof(struct aic_entry));
    if (e == NULL) return NULL;
    NEOERR *err;

    e->base.name = (unsigned char*)strdup(PLUGIN_NAME);
    e->base.ksize = strlen(PLUGIN_NAME);
    e->base.process_driver = aic_process_driver;
    e->base.stop_driver = aic_stop_driver;

    char *dbsn = hdf_get_value(g_cfg, CONFIG_PATH".dbsn", NULL);
    err = mdb_init(&e->db, dbsn);
    JUMP_NOK(err, error);
    
    e->cd = cache_create(hdf_get_int_value(g_cfg, CONFIG_PATH".numobjs", 1024), 0);
    if (e->cd == NULL) {
        wlog("init cache failure");
        goto error;
    }
    
    return (struct event_entry*)e;
    
error:
    if (e->base.name) free(e->base.name);
    if (e->db) mdb_destroy(e->db);
    if (e->cd) cache_free(e->cd);
    free(e);
    return NULL;
}
Exemplo n.º 8
0
/**
 * Package init and quit functions
 */
void
sylvan_init_package(size_t tablesize, size_t maxsize, size_t cachesize, size_t max_cachesize)
{
    if (tablesize > maxsize) tablesize = maxsize;
    if (cachesize > max_cachesize) cachesize = max_cachesize;

    if (maxsize > 0x000003ffffffffff) {
        fprintf(stderr, "sylvan_init_package error: tablesize must be <= 42 bits!\n");
        exit(1);
    }

    nodes = llmsset_create(tablesize, maxsize);
    cache_create(cachesize, max_cachesize);

    gc = 0;
    barrier_init(&gcbar, lace_workers());
#if SYLVAN_AGGRESSIVE_RESIZE
    gc_hook = TASK(sylvan_gc_aggressive_resize);
#else
    gc_hook = TASK(sylvan_gc_default_hook);
#endif
    sylvan_gc_add_mark(10, TASK(sylvan_gc_mark_cache));
    sylvan_gc_add_mark(19, TASK(sylvan_gc_destroy_unmarked));
    sylvan_gc_add_mark(20, TASK(sylvan_gc_call_hook));
    sylvan_gc_add_mark(30, TASK(sylvan_gc_rehash));

    LACE_ME;
    sylvan_stats_init();
}
Exemplo n.º 9
0
/* cache_sim_init */
cache_handle_t* cache_sim_init(const unsigned int total_size,
                               const unsigned int line_size, const unsigned int associativity,
                               const char *policy) {
    /* safety checks */
    if ((0 >= total_size) || (0 >= line_size) || (0 >= associativity)) {
        return NULL;
    }

    /* variables declaration and initialization */
    cache_handle_t *cache = NULL;

    printf("--------------------------------\n");

    /* create the cache */
    if (NULL == (cache = cache_create(total_size, line_size, associativity))) {
        return NULL;
    }

    /* set the cache replacement policy (or algorithm) */
    if (CACHE_SIM_SUCCESS != (set_policy(cache, policy))) {
        cache_destroy(cache);
        return NULL;
    }

    printf(" Cache initialized successfully \n");
    printf("--------------------------------\n");

    return cache;
}
Exemplo n.º 10
0
int main(int argc, char **argv)
{
	FILE *swp;
	struct cache *c;
	struct matrix *m;	
	FILE *matrix_shared;

	readargs(argc, argv);

	if ((swp = fopen(swapfile, "w+")) == NULL)
		error("cannot open swap file");

	c = cache_create(&access_info, swp, CACHE_SIZE);

	/* Read traces. */
	for (int i = 0; i < ntraces; i++)
	{
		FILE *trace;
		
		if ((trace = fopen(tracefiles[i], "r")) == NULL)
			error("cannot open trace file");
		
		trace_read(c, trace, i);
		fclose(trace);
		
		fprintf(stderr, "\nFechado arquivo de trace da thread %d\n\n", i);
		
	}
	
	/* Flushe traces on swap file. */
	cache_flush(c);
	
	/* Create communication matrix. */
	fseek(swp, 0, SEEK_SET); 
	m  = matrix_create(QTD_THREADS, QTD_THREADS);
	
	fprintf(stderr, "\nMatriz criada\n");
	
	matrix_generate(swp, m);
	
	
	if ((matrix_shared = fopen(outfile, "w")) == NULL)
		error("cannot open output file");
	
	fprintf(stderr, "\nGravar matriz no arquivo\n");
	
	for (int i = 0; i < ntraces; i++)
	{
		for(int j = 0; j < ntraces; j++)
			fprintf(matrix_shared, "%d;%d;%d\n", i, j, (int) matrix_get(m, i, j));	
	}

	/* House keeping. */
	fclose(matrix_shared);
	fclose(swp);
	
	fprintf(stderr, "\n\n FIM!\n");
		
	return (EXIT_SUCCESS);
}
Exemplo n.º 11
0
static enum test_return cache_create_test(void)
{
    cache_t *cache = cache_create("test", sizeof(uint32_t), sizeof(char*),
                                  NULL, NULL);
    assert(cache != NULL);
    cache_destroy(cache);
    return TEST_PASS;
}
Exemplo n.º 12
0
// Numeric caches use number+1 as the id.
error_t numeric_cache_create(cache_t* c, int cache_size,
                     int data_size, void* context,
                     cache_fault_t fault, cache_evict_t evict
                     )
{
  return cache_create(c, cache_size, numeric_hash, numeric_cmp,
                      data_size, context, fault, evict, numeric_copy_id, numeric_free_id);
}
Exemplo n.º 13
0
void
init_block_list()
{
    // Initialize cache
#ifdef __linux__
    init_firewall();
#endif
    cache_create(&block_list, 256, NULL);
}
Exemplo n.º 14
0
/* Load cached font */
static struct font* font_load_cached(struct font* pf)
{
    uint32_t noffset, nwidth;
    unsigned char* oldfileptr = pf->buffer_position;

    if (!HAVEBYTES(2 * sizeof(int32_t)))
        return NULL;

    /* # longs of offset*/
    noffset = readlong(pf);

    /* # bytes of width*/
    nwidth = readlong(pf);

    /* We are now at the bitmap data, this is fixed at 36.. */
    pf->bits = NULL;

    /* Calculate offset to offset data */
    pf->buffer_position += pf->bits_size * sizeof(unsigned char);

    if (pf->bits_size < MAX_FONTSIZE_FOR_16_BIT_OFFSETS)
    {
        pf->long_offset = 0;
        /* pad to 16-bit boundary */
        pf->buffer_position = (unsigned char *)(((intptr_t)pf->buffer_position + 1) & ~1);
    }
    else
    {
        pf->long_offset = 1;
        /* pad to 32-bit boundary*/
        pf->buffer_position = (unsigned char *)(((intptr_t)pf->buffer_position + 3) & ~3);
    }

    if (noffset)
        pf->file_offset_offset = (uint32_t)(pf->buffer_position - pf->buffer_start);
    else
        pf->file_offset_offset = 0;

    /* Calculate offset to widths data */
    if (pf->bits_size < MAX_FONTSIZE_FOR_16_BIT_OFFSETS)
        pf->buffer_position += noffset * sizeof(uint16_t);
    else
        pf->buffer_position += noffset * sizeof(uint32_t);

    if (nwidth)
        pf->file_width_offset = (uint32_t)(pf->buffer_position - pf->buffer_start);
    else
        pf->file_width_offset = 0;

    pf->buffer_position = oldfileptr;

    /* Create the cache */
    cache_create(pf, pf->maxwidth, pf->height);

    return pf;
}
Exemplo n.º 15
0
bool crowd_cache_create(apr_pool_t *pool, apr_time_t max_age, unsigned int max_entries) {
    auth_cache = cache_create("auth", pool, max_age, max_entries, copy_string, free);
    if (auth_cache == NULL) {
        return false;
    }
    groups_cache = cache_create("groups", pool, max_age, max_entries, copy_groups, free_groups);
    if (groups_cache == NULL) {
        return false;
    }
    cookie_config_cache = cache_create("cookie config", pool, max_age, max_entries, copy_cookie_config, free_cookie_config);
    if (cookie_config_cache == NULL) {
        return false;
    }
    session_cache = cache_create("session", pool, max_age, max_entries, copy_string, free);
    if (session_cache == NULL) {
        return false;
    }
    return true;
}
Exemplo n.º 16
0
int
init_udprelay(const char *server_host, const char *server_port,
#ifdef MODULE_LOCAL
              const struct sockaddr *remote_addr, const int remote_addr_len,
#ifdef MODULE_TUNNEL
              const ss_addr_t tunnel_addr,
#endif
#endif
              int mtu, crypto_t *crypto, int timeout, const char *iface)
{
    // Initialize ev loop
    struct ev_loop *loop = EV_DEFAULT;

    // Initialize MTU
    if (mtu > 0) {
        packet_size = mtu - 1 - 28 - 2 - 64;
        buf_size    = packet_size * 2;
    }

    // Initialize cache
    struct cache *conn_cache;
    cache_create(&conn_cache, MAX_UDP_CONN_NUM, free_cb);

    // ////////////////////////////////////////////////
    // Setup server context

    // Bind to port
    int serverfd = create_server_socket(server_host, server_port);
    if (serverfd < 0) {
        FATAL("[udp] bind() error");
    }
    setnonblocking(serverfd);

    server_ctx_t *server_ctx = new_server_ctx(serverfd);
#ifdef MODULE_REMOTE
    server_ctx->loop = loop;
#endif
    server_ctx->timeout    = max(timeout, MIN_UDP_TIMEOUT);
    server_ctx->crypto     = crypto;
    server_ctx->iface      = iface;
    server_ctx->conn_cache = conn_cache;
#ifdef MODULE_LOCAL
    server_ctx->remote_addr     = remote_addr;
    server_ctx->remote_addr_len = remote_addr_len;
#ifdef MODULE_TUNNEL
    server_ctx->tunnel_addr = tunnel_addr;
#endif
#endif

    ev_io_start(loop, &server_ctx->io);

    server_ctx_list[server_num++] = server_ctx;

    return serverfd;
}
Exemplo n.º 17
0
static int external_cache_init(void)
{
	external = cache_create("external",
				STATE_SYNC(sync)->external_cache_flags,
				NULL);
	if (external == NULL) {
		dlog(LOG_ERR, "can't allocate memory for the external cache");
		return -1;
	}
	return 0;
}
Exemplo n.º 18
0
/*
 * Creates a child of a GapIO. The child can basically be considered as a
 * read-through but write-sticky cache. By that I mean that using the child
 * GapIO works as if the parent was used instead, but writes to the
 * child GapIO are not propagated through to the parent until an
 * explicit request is made.
 *
 * The purpose for this mechanism is to allow tools like the contig editor
 * be able to read and write to a local cached copy of the database with
 * the ability to cancel and effectively rollback all local changes made.
 */
GapIO *gio_child(GapIO *io_p) {
    GapIO *io = (GapIO *)calloc(1, sizeof(*io));

    io->iface = get_iface_g();
    cache_create(io);
    
    io->base = io_p;
    io->dbh = io->base->dbh;
    io->read_only = io->base->read_only;
    io->min_bin_size = io->base->min_bin_size;
    return io;
}
Exemplo n.º 19
0
Arquivo: thread.c Projeto: zbase/moxi
/*
 * Set up a thread's information.
 */
static void setup_thread(LIBEVENT_THREAD *me) {
    if (! me->base) {
        me->base = event_init();
        if (! me->base) {
            moxi_log_write("Can't allocate event base\n");
            exit(1);
        }
    }

    /* Listen for notifications from other threads */
    event_set(&me->notify_event, me->notify_receive_fd,
              EV_READ | EV_PERSIST, thread_libevent_process, me);
    event_base_set(me->base, &me->notify_event);

    if (event_add(&me->notify_event, 0) == -1) {
        moxi_log_write("Can't monitor libevent notify pipe\n");
        exit(1);
    }

    me->new_conn_queue = malloc(sizeof(struct conn_queue));
    if (me->new_conn_queue == NULL) {
        perror("Failed to allocate memory for connection queue");
        exit(EXIT_FAILURE);
    }
    cq_init(me->new_conn_queue);

    // TODO: Merge new_conn_queue with work_queue.
    //
    me->work_queue = calloc(1, sizeof(work_queue));
    if (me->work_queue == NULL) {
        perror("Failed to allocate memory for work queue");
        exit(EXIT_FAILURE);
    }
    work_queue_init(me->work_queue, me->base);

    if (pthread_mutex_init(&me->stats.mutex, NULL) != 0) {
        perror("Failed to initialize mutex");
        exit(EXIT_FAILURE);
    }

    me->suffix_cache = cache_create("suffix", SUFFIX_SIZE, sizeof(char*),
                                    NULL, NULL);
    if (me->suffix_cache == NULL) {
        moxi_log_write("Failed to create suffix cache\n");
        exit(EXIT_FAILURE);
    }

    me->conn_hash = genhash_init(512, strhash_ops);
    if (me->conn_hash == NULL) {
        moxi_log_write("Failed to create connection hash\n");
        exit(EXIT_FAILURE);
    }
}
Exemplo n.º 20
0
static enum test_return cache_destructor_test(void)
{
    cache_t *cache = cache_create("test", sizeof(uint32_t), sizeof(char*),
                                  NULL, cache_destructor);
    char *ptr;

    assert(cache != NULL);
    ptr = cache_alloc(cache);
    cache_free(cache, ptr);
    cache_destroy(cache);

    return (ptr == destruct_data) ? TEST_PASS : TEST_FAIL;
}
Exemplo n.º 21
0
static enum test_return cache_constructor_test(void)
{
    uint64_t *ptr;
    uint64_t pattern;
    cache_t *cache = cache_create("test", sizeof(uint64_t), sizeof(uint64_t),
                                  cache_constructor, NULL);
    assert(cache != NULL);
    ptr = cache_alloc(cache);
    pattern = *ptr;
    cache_free(cache, ptr);
    cache_destroy(cache);
    return (pattern == constructor_pattern) ? TEST_PASS : TEST_FAIL;
}
Exemplo n.º 22
0
int udprelay_init(const char *server_host, const char *server_port,
#ifdef UDPRELAY_LOCAL
             const char *remote_host, const char *remote_port,
#ifdef UDPRELAY_TUNNEL
             const ss_addr_t tunnel_addr,
#endif
#endif
#ifdef UDPRELAY_REMOTE
             asyncns_t *asyncns,
#endif
             int method, int timeout, const char *iface)
{

    // Inilitialize ev loop
    struct ev_loop *loop = EV_DEFAULT;

    // Inilitialize cache
    struct cache *conn_cache;
    cache_create(&conn_cache, MAX_UDP_CONN_NUM, free_cb);

    //////////////////////////////////////////////////
    // Setup server context

    // Bind to port
    int serverfd = create_server_socket(server_host, server_port);
    if (serverfd < 0)
    {
        FATAL("udprelay bind() error..");
    }
    setnonblocking(serverfd);

    struct server_ctx *server_ctx = new_server_ctx(serverfd);
    server_ctx->timeout = timeout;
    server_ctx->method = method;
    server_ctx->iface = iface;
    server_ctx->conn_cache = conn_cache;
#ifdef UDPRELAY_LOCAL
    server_ctx->remote_host = remote_host;
    server_ctx->remote_port = remote_port;
#ifdef UDPRELAY_TUNNEL
    server_ctx->tunnel_addr = tunnel_addr;
#endif
#endif
#ifdef UDPRELAY_REMOTE
    server_ctx->asyncns = asyncns;
#endif

    ev_io_start(loop, &server_ctx->io);

    return 0;
}
Exemplo n.º 23
0
/* Helper to create all icache and iTLB structures and attach them to core->memory. */
void core_fetch_t::create_caches() {
    struct core_knobs_t* knobs = core->knobs;

    char name[256];
    int sets, assoc, linesize, latency, banks, bank_width, MSHR_entries;
    char rp;

    /* IL1 */
    if (sscanf(knobs->memory.IL1_opt_str, "%[^:]:%d:%d:%d:%d:%d:%d:%c:%d", name, &sets, &assoc,
               &linesize, &banks, &bank_width, &latency, &rp, &MSHR_entries) != 9)
        fatal("invalid IL1 options: "
              "<name:sets:assoc:linesize:banks:bank_width:latency:repl-policy:num-MSHR>\n\t(%s)",
              knobs->memory.IL1_opt_str);

    /* the write-related options don't matter since the IL1 will(should) never see any stores */
    struct cache_t* next_level = (core->memory.DL2) ? core->memory.DL2.get() : uncore->LLC.get();
    struct bus_t* next_bus = (core->memory.DL2) ? core->memory.DL2_bus.get() : uncore->LLC_bus.get();
    core->memory.IL1 = cache_create(core, name, CACHE_READONLY, sets, assoc, linesize, rp, 'w', 't',
                                    'n', banks, bank_width, latency, MSHR_entries, 4, 1, next_level,
                                    next_bus, knobs->memory.IL1_magic_hit_rate,
                                    knobs->memory.IL1_sample_misses, nullptr);

    prefetchers_create(core->memory.IL1.get(), knobs->memory.IL1_pf);

    /* ITLB */
    if (sscanf(knobs->memory.ITLB_opt_str, "%[^:]:%d:%d:%d:%d:%c:%d", name, &sets, &assoc, &banks,
               &latency, &rp, &MSHR_entries) != 7)
        fatal("invalid ITLB options: <name:sets:assoc:banks:latency:repl-policy:num-MSHR>");

    core->memory.ITLB =
            cache_create(core, name, CACHE_READONLY, sets, assoc, 1, rp, 'w', 't', 'n', banks, 1,
                         latency, MSHR_entries, 4, 1, next_level, next_bus, -1.0, false, nullptr);

    core->memory.IL1->controller =
            controller_create(knobs->memory.IL1_controller_opt_str, core, core->memory.IL1.get());
    core->memory.ITLB->controller =
            controller_create(knobs->memory.ITLB_controller_opt_str, core, core->memory.ITLB.get());
}
Exemplo n.º 24
0
int init_udprelay(const char *server_host, const char *server_port,
#ifdef UDPRELAY_LOCAL
                  const struct sockaddr *remote_addr, const int remote_addr_len,
#ifdef UDPRELAY_TUNNEL
                  const ss_addr_t tunnel_addr,
#endif
#endif
                  int method, int auth, int timeout, const char *iface)
{
    // Inilitialize ev loop
    struct ev_loop *loop = EV_DEFAULT;

    // Inilitialize cache
    struct cache *conn_cache;
    cache_create(&conn_cache, MAX_UDP_CONN_NUM, free_cb);

    //////////////////////////////////////////////////
    // Setup server context

    // Bind to port
    int serverfd = create_server_socket(server_host, server_port);
    if (serverfd < 0) {
        FATAL("[udp] bind() error");
    }
    setnonblocking(serverfd);

    struct server_ctx *server_ctx = new_server_ctx(serverfd);
#ifdef UDPRELAY_REMOTE
    server_ctx->loop = loop;
#endif
    server_ctx->auth = auth;
    server_ctx->timeout = max(timeout, MIN_UDP_TIMEOUT);
    server_ctx->method = method;
    server_ctx->iface = iface;
    server_ctx->conn_cache = conn_cache;
#ifdef UDPRELAY_LOCAL
    server_ctx->remote_addr = remote_addr;
    server_ctx->remote_addr_len = remote_addr_len;
#ifdef UDPRELAY_TUNNEL
    server_ctx->tunnel_addr = tunnel_addr;
#endif
#endif

    ev_io_start(loop, &server_ctx->io);

    server_ctx_list[server_num++] = server_ctx;

    return 0;
}
Exemplo n.º 25
0
void testCreateCached() {
    char *name = "imichael";
    cache_t *cache = cache_create(name ,sizeof(uint32_t),sizeof(char*),NULL,NULL);
    assert(cache != NULL);
    printf("uunit32_t :%i\n",sizeof(uint32_t));
    printf("char* size :%i\n",sizeof(char*));
    printf("name :%s\n",cache->name );
    printf("bufsize:%i\n",cache->bufsize);
    printf("freetotal:%i\n",cache->freetotal);
    printf("freecurr:%i\n",cache->freecurr);

    cache_destroy(cache);
    return ;

}
Exemplo n.º 26
0
static enum test_return cache_reuse_test(void)
{
    int ii;
    cache_t *cache = cache_create("test", sizeof(uint32_t), sizeof(char*),
                                  NULL, NULL);
    char *ptr = cache_alloc(cache);
    cache_free(cache, ptr);
    for (ii = 0; ii < 100; ++ii) {
        char *p = cache_alloc(cache);
        assert(p == ptr);
        cache_free(cache, ptr);
    }
    cache_destroy(cache);
    return TEST_PASS;
}
Exemplo n.º 27
0
static enum test_return cache_fail_constructor_test(void)
{
    enum test_return ret = TEST_PASS;

    cache_t *cache = cache_create("test", sizeof(uint64_t), sizeof(uint64_t),
                                  cache_fail_constructor, NULL);
    uint64_t *ptr;

    assert(cache != NULL);
    ptr = cache_alloc(cache);
    if (ptr != NULL) {
        ret = TEST_FAIL;
    }
    cache_destroy(cache);
    return ret;
}
NSAPI_PUBLIC int
dns_cache_init(int dns_cache_size, int timeout)
{
	/* Check if cache already initialized */
	if (dns_cache)
		return -1;

	dns_expire_time = timeout;

	if ( (dns_cache = cache_create(dns_cache_size, 2*dns_cache_size, 
		&dns_cache_functions)) ==NULL){
		return -1;
	}

	return 0;
}
Exemplo n.º 29
0
/*
 * Setup a worker thread
 */
static rstatus_t
thread_setup(struct thread_worker *t)
{
    size_t suffix_size;
    rstatus_t status;

    t->base = event_base_new();
    if (t->base == NULL) {
        log_error("event init failed: %s", strerror(errno));
        return MC_ERROR;
    }

    /* listen for notifications from other threads */
    event_set(&t->notify_event, t->notify_receive_fd, EV_READ | EV_PERSIST,
              thread_libevent_process, t);
    event_base_set(t->base, &t->notify_event);

    status = event_add(&t->notify_event, NULL);
    if (status < 0) {
        log_error("event add failed: %s", strerror(errno));
        return MC_ERROR;
    }

    status = thread_setup_stats(t);
    if (status != MC_OK) {
        return status;
    }

    t->kbuf = klog_buf_create();
    if (t->kbuf == NULL) {
        log_error("klog buf create failed: %s", strerror(errno));
        return MC_ENOMEM;
    }

    conn_cq_init(&t->new_cq);

    suffix_size = settings.use_cas ? (CAS_SUFFIX_SIZE + SUFFIX_SIZE + 1) :
                  (SUFFIX_SIZE + 1);
    t->suffix_cache = cache_create("suffix", suffix_size, sizeof(char *));
    if (t->suffix_cache == NULL) {
        log_error("cache create of suffix cache failed: %s", strerror(errno));
        return MC_ENOMEM;
    }

    return MC_OK;
}
Exemplo n.º 30
0
/*
 * Set up a thread's information.
 */
static void setup_thread(LIBEVENT_THREAD *me, bool tap) {
    me->type = tap ? TAP : GENERAL;
    me->base = event_init();
    if (! me->base) {
        settings.extensions.logger->log(EXTENSION_LOG_WARNING, NULL,
                                        "Can't allocate event base\n");
        exit(1);
    }

    /* Listen for notifications from other threads */
    event_set(&me->notify_event, me->notify[0],
              EV_READ | EV_PERSIST,
              tap ? libevent_tap_process : thread_libevent_process, me);
    event_base_set(me->base, &me->notify_event);

    if (event_add(&me->notify_event, 0) == -1) {
        settings.extensions.logger->log(EXTENSION_LOG_WARNING, NULL,
                                        "Can't monitor libevent notify pipe\n");
        exit(1);
    }

    if (!tap) {
        me->new_conn_queue = malloc(sizeof(struct conn_queue));
        if (me->new_conn_queue == NULL) {
            settings.extensions.logger->log(EXTENSION_LOG_WARNING, NULL,
                                            "Failed to allocate memory for connection queue");
            exit(EXIT_FAILURE);
        }
        cq_init(me->new_conn_queue);
    }

    if ((pthread_mutex_init(&me->mutex, NULL) != 0)) {
        settings.extensions.logger->log(EXTENSION_LOG_WARNING, NULL,
                                        "Failed to initialize mutex: %s\n",
                                        strerror(errno));
        exit(EXIT_FAILURE);
    }

    me->suffix_cache = cache_create("suffix", SUFFIX_SIZE, sizeof(char*),
                                    NULL, NULL);
    if (me->suffix_cache == NULL) {
        settings.extensions.logger->log(EXTENSION_LOG_WARNING, NULL,
                                        "Failed to create suffix cache\n");
        exit(EXIT_FAILURE);
    }
}