Exemple #1
0
static void connect(coreid_t idx)
{
    errval_t err;
    char id[100];
    snprintf(id, sizeof(id), "%s%d", my_name, idx);

    iref_t iref;
    err = nameservice_blocking_lookup(id, &iref);
    if (err_is_fail(err)) {
        DEBUG_ERR(err, "nameservice_blocking_lookup failed");
        abort();
    }
    assert(iref != 0);

    struct rcce_state *st = malloc(sizeof(struct rcce_state));
    assert(st != NULL);
    memset(st, 0, sizeof(struct rcce_state));
    st->index = idx;
    st->request_done = false;

    /* printf("%s: rcce_bind\n", my_name); */

    err = rcce_bind(iref, client_connected, st, get_default_waitset(),
                    IDC_BIND_FLAGS_DEFAULT);
    assert(err_is_ok(err));

    /* printf("%s: waiting\n", my_name); */

    while (!st->request_done) {
        messages_wait_and_handle_next();
    }

    /* printf("%s: done\n", my_name); */
}
errval_t blockdevfs_ahci_init(void)
{
    errval_t err;
    iref_t iref;

    err = nameservice_blocking_lookup("ahcid", &iref);
    if (err_is_fail(err)) {
        DEBUG_ERR(err, "nameservice_blocking_lookup for ahcid");
        return err; // FIXME
    }

    err = ahci_mgmt_bind(iref, ahci_mgmt_bind_cb, NULL, get_default_waitset(),
                  IDC_BIND_FLAG_RPC_CAP_TRANSFER);

    // init DMA pool
    ahci_dma_pool_init(1024*1024);

    if (err_is_fail(err)) {
        DEBUG_ERR(err, "ahci_mgmt bind failed");
        return err; // FIXME
    }

    // XXX: block for bind completion (broken API!)
    while (!ahci_mgmt_bound) {
        messages_wait_and_handle_next();
    }

    return SYS_ERR_OK;
}
/**
 * \brief Connects the lwip instance with net_ports daemon.
 *  Code inspired (ie. copied) from "start_client" function.
 */
static void init_net_ports_connection(char *service_name)
{
    LWIPBF_DEBUG("init_net_ports_connection: called\n");
    assert(service_name != NULL);
    LWIPBF_DEBUG("init_net_ports_connection: connecting to [%s]\n", service_name);

    errval_t err;
    iref_t iref;

    LWIPBF_DEBUG("init_net_ports_connection: resolving driver %s\n", service_name);

    err = nameservice_blocking_lookup(service_name, &iref);
    if (err_is_fail(err)) {
        DEBUG_ERR(err, "lwip: could not connect to the net_ports driver.\n"
                  "Terminating.\n");
        abort();
    }
    assert(iref != 0);

    LWIPBF_DEBUG("init_net_ports_connection: connecting\n");

    err = net_ports_bind(iref, net_ports_bind_cb, NULL, lwip_waitset,
                    IDC_BIND_FLAGS_DEFAULT);
    if (!err_is_ok(err)) {
        printf("net_ports_bind_cb failed in init\n");
        abort();
    }

    LWIPBF_DEBUG("init_net_ports_connection: terminated\n");
}
Exemple #4
0
int main(int argc, char *argv[])
{
    errval_t err;

    /* Set my core id */
    my_core_id = disp_get_core_id();
    strcpy(my_name, argv[0]);

    printf("entered\n");
    bench_init();
    printf("bench_init done\n");

    if (argc == 1) { /* server */

        /*
         1. spawn domain,
         2. setup a server,
         3. wait for client to connect,
         4. run experiment
         */

        char *xargv[] = { my_name, "dummy", "dummy", "dummy", NULL };
        err = spawn_program(1, my_name, xargv, NULL, SPAWN_FLAGS_DEFAULT, NULL);
        assert(err_is_ok(err));

        /* Setup a server */
        err = bench_export(NULL, export_cb, connect_cb, get_default_waitset(),
                IDC_BIND_FLAGS_DEFAULT);
        assert(err_is_ok(err));

    } else {
        /* Connect to the server */

        printf("ns lookup\n");
        err = nameservice_blocking_lookup("multihop_server", &iref);
        if (err_is_fail(err)) {
            DEBUG_ERR(err, "nameservice_blocking_lookup failed");
            abort();
        }

        printf("bench_bind\n");
        // bind a first time for signaling
        err = bench_bind(iref, bind_signal_cb, NULL, get_default_waitset(),
                IDC_BIND_FLAGS_DEFAULT);
        if (err_is_fail(err)) {
            DEBUG_ERR(err, "bind failed");
            abort();
        }
    }
    messages_handler_loop();
    return 0;
}
Exemple #5
0
static void pixels_init(void)
{
    // ensure pixels is up
    if (!pixels_started) {
        printf("Starting pixels...\n");
        spawnpixels(0, NULL);
    }

    pixels_connected = 0;

    for (int core = 0; core < NUM_PIXELS; core ++) {
        char name[16];
        iref_t serv_iref;
        errval_t err;
        
        sprintf(name, "pixels.%d", core);
        
        /* Connect to the server */
        err = nameservice_blocking_lookup(name, &serv_iref);
        if (err_is_fail(err)) {
            DEBUG_ERR(err, "failed to lookup server");
            exit(EXIT_FAILURE);
        }

	if (serv_iref == 0) {
	    DEBUG_ERR(err, "failed to get a valid iref back from lookup");
	    exit(EXIT_FAILURE);
	}
  
	err = pixels_bind(serv_iref, 
			  my_pixels_bind_cb, 
			  &my_pixels_bindings[core],
			  get_default_waitset(),
			  IDC_BIND_FLAGS_DEFAULT);
	if (err_is_fail(err)) {
	    DEBUG_ERR(err, "bind request to pixels server failed immediately");
	    exit(EXIT_FAILURE);
	}
    }

    while (pixels_connected < NUM_PIXELS) 
	messages_wait_and_handle_next();
    
    printf("connected to pixels server\n");
    pixels_inited = true;
}
Exemple #6
0
static void
slaves_connect(struct task_graph *tg)
{
    char name[128];
    iref_t iref;
    int err;

    for (int sid=0; sid < SlState.num_slaves; sid++) {
        int r = snprintf(name, 128, "replay_slave.%u", sid + 1);
        struct slave *sl = SlState.slaves + sid;
        assert(r != -1);

        err = nameservice_blocking_lookup(name, &iref);
        if (err_is_fail(err)) {
            DEBUG_ERR(err, "could not lookup IREF for replay slave");
            abort();
        }

        /* bound to slave  */
        bound = false;
        err = replay_bind(iref, replay_bind_cont, NULL,
                          get_default_waitset(),
                          IDC_BIND_FLAGS_DEFAULT);
        if(err_is_fail(err)) {
            DEBUG_ERR(err, "replay_bind");
        }
        while(!bound) {
            err = event_dispatch(get_default_waitset());
            assert(err_is_ok(err));
        }
        msg("Bound to slave %d\n", sid);

        /* initialize bulk transfer for slave */
        init_ok = false;
        err = bulk_create(BULK_TOTAL_SIZE, BULK_BLOCK_SIZE, &sl->frame, &sl->bt, false);
        assert(err_is_ok(err));
        err = sl->b->tx_vtbl.slave_init(sl->b, NOP_CONT, sl->frame, BULK_TOTAL_SIZE);
        assert(err_is_ok(err));
        while (!init_ok) {
            err = event_dispatch(get_default_waitset());
            assert(err_is_ok(err));
        }

        msg("Slave %d initialized\n", sid);
    }
}
static void bind_core(coreid_t core) {
    errval_t err;
    iref_t iref;
    char core_service_name[128];
    get_service_name(core_service_name, 128, core);
    err = nameservice_blocking_lookup(core_service_name, &iref);
    if (err_is_fail(err)) {
        fprintf(stderr, "could not connect to the xcorecapbench.\n"
                "Terminating.\n");
        abort();
    }
    err = xcorecapbench_bind(iref, bind_cb, (void*)(uintptr_t)core, 
                             get_default_waitset(), IDC_BIND_FLAGS_DEFAULT);
    if (err_is_fail(err)) {
        DEBUG_ERR(err, "bind failed");
        abort();
    }
}
Exemple #8
0
static void start_client(void)
{
    errval_t err;
    iref_t iref;

    err = nameservice_blocking_lookup(service_name, &iref);
    if (err_is_fail(err)) {
        USER_PANIC_ERR(err, "nameservice_blocking_lookup failed");
    }

    err = xmplrpc_bind(iref,
                       bind_cb,
                       NULL /* state for bind_cb */,
                       get_default_waitset(),
                       IDC_BIND_FLAGS_DEFAULT);
    if (err_is_fail(err)) {
        USER_PANIC_ERR(err, "bind failed");
    }
}
Exemple #9
0
/** Connect to the management interface */
static void connect_to_mngif(void)
{
    errval_t r;
    iref_t iref;
    const char *suffix = "_e10kmng";
    char name[strlen(service_name) + strlen(suffix) + 1];

    // Build label for interal management service
    sprintf(name, "%s%s", service_name, suffix);

    // Connect to service
    INITDEBUG("Looking up management interface (%s)\n", name);
    r = nameservice_blocking_lookup(name, &iref);
    assert(err_is_ok(r));

    INITDEBUG("Binding to management interface\n");
    r = e10k_bind(iref, bind_cb, NULL, get_default_waitset(),
            IDC_BIND_FLAGS_DEFAULT);
    assert(err_is_ok(r));
}
/**
 * \brief binds to the Xeon Phi Manager service
 *
 * \returns SYS_ERR_OK on success
 *          FLOUNDER_ERR_* on failure
 */
static errval_t xpm_bind(void)
{
    errval_t err;

    if (xpm_binding != NULL) {
        return SYS_ERR_OK;
    }

    assert(conn_state == XPM_STATE_INVALID);

    conn_state = XPM_STATE_NSLOOKUP;

    DEBUG_XPMC("nameservice lookup: "XEON_PHI_MANAGER_SERVICE_NAME"\n");

    err = nameservice_blocking_lookup(XEON_PHI_MANAGER_SERVICE_NAME, &xpm_iref);
    if (err_is_fail(err)) {
        return err;
    }

    conn_state = XPM_STATE_BINDING;

    DEBUG_XPMC("binding: "XEON_PHI_MANAGER_SERVICE_NAME" @ iref:%u\n", xpm_iref);

    err = xeon_phi_manager_bind(xpm_iref, xpm_bind_cb, NULL, get_default_waitset(),
    IDC_BIND_FLAGS_DEFAULT);
    if (err_is_fail(err)) {
        return err;
    }

    while (conn_state == XPM_STATE_BINDING) {
        messages_wait_and_handle_next();
    }

    if (conn_state == XPM_STATE_BIND_FAIL) {
        return FLOUNDER_ERR_BIND;
    }

    return SYS_ERR_OK;
}
Exemple #11
0
static inline errval_t wait_for_pci(void)
{
    iref_t iref;
    return nameservice_blocking_lookup("pci_discovery_done", &iref);
}
Exemple #12
0
int main(int argc,
         char *argv[])
{
    debug_printf("Xeon Phi module started on node [%u].\n", disp_xeon_phi_id());

    errval_t err;

    mmio_cap.cnode = cnode_task;
    sysmem_cap.cnode = cnode_task;

    assert(!capref_is_null(mmio_cap));
    assert(!capref_is_null(sysmem_cap));

    xphi.is_client = 0x1;
    xphi.id = disp_xeon_phi_id();

    for (uint32_t i = 0; i < XEON_PHI_NUM_MAX; ++i) {
        xphi.topology[i].id = i;
        xphi.topology[i].local = &xphi;
    }

    XDEBUG("Initializing system memory cap manager...\n");
    err = sysmem_cap_manager_init(sysmem_cap);
    if (err_is_fail(err)) {
        USER_PANIC_ERR(err, "Could not initialize the cap manager.\n");
    }

    err = map_mmio_space(&xphi);
    if (err_is_fail(err)) {
        USER_PANIC_ERR(err, "could not map the mmio space");
    }

    err = xdma_service_init(&xphi);
    if (err_is_fail(err)) {
        USER_PANIC_ERR(err, "Could not initialize the dma engine.\n");
    }

    err = smpt_init(&xphi);
    if (err_is_fail(err)) {
        USER_PANIC_ERR(err, "Could not initialize the SMTP.\n");
    }

    /* wait until the kernels are booted and spawnds are ready */
    err = nameservice_blocking_lookup("all_spawnds_up", NULL);
    if (err_is_fail(err)) {
        USER_PANIC_ERR(err, "all_spawnds_up.\n");
    }

    //dma_impl_test(&xphi);

    lpaddr_t host_msg_base = strtol(argv[0], NULL, 16);
    uint8_t host_msg_size = strtol(argv[1], NULL, 16);

    XMESSAGING_DEBUG("Getting the host messaging cap...[%016lx, %02x]\n",
                     host_msg_base, host_msg_size);

    err = sysmem_cap_request(host_msg_base, host_msg_size, &host_cap);
    if (err_is_fail(err)) {
        USER_PANIC_ERR(err, "Could not obtain the system messsaging cap\n");
    }

    err = interphi_init(&xphi, host_cap);
    if (err_is_fail(err)) {
        USER_PANIC_ERR(err, "Could not initialize the interphi communication\n");
    }

    err = xeon_phi_service_init(&xphi);
    if (err_is_fail(err)) {
        USER_PANIC_ERR(err, "could not initialize the messaging service");
    }

    XMESSAGING_DEBUG("Start polling for messages...\n");
    while (1) {
        uint8_t idle = 0x1;
        err = xdma_service_poll(&xphi);
        idle = idle && (err_no(err) == DMA_ERR_DEVICE_IDLE);
        err = event_dispatch_non_block(get_default_waitset());
        if (err_is_fail(err)) {
            if ((err_no(err) == LIB_ERR_NO_EVENT) && idle) {
                thread_yield();
                continue;
            }
            if (err_no(err) != LIB_ERR_NO_EVENT) {
                USER_PANIC_ERR(err, "msg loop");
            }
        }
    }

    XDEBUG("Messaging loop terminated...\n");
    return 0;
}
Exemple #13
0
/**
 * @brief initialized a descriptor queue
 */
errval_t descq_create(struct descq** q,
                      size_t slots,
                      char* name,
                      bool exp,
                      bool notifications,
                      uint8_t role,
                      uint64_t *queue_id,
                      struct descq_func_pointer* f)
{
    DESCQ_DEBUG("create start\n");
    errval_t err;
    struct descq* tmp;
    struct capref rx;
    struct capref tx;

    // Init basic struct fields
    tmp = malloc(sizeof(struct descq));
    assert(tmp != NULL);
    tmp->name = strdup(name);
    assert(tmp->name != NULL);

    if (exp) {  // exporting
        struct descq_endpoint_state* state = malloc(sizeof(struct descq_endpoint_state));
        state->name = strdup(name);
        assert(state->name);

        state->f.notify = f->notify;
        state->f.dereg = f->dereg;
        state->f.reg = f->reg;
        state->f.create = f->create;
        state->f.destroy = f->destroy;
        state->f.control = f->control;

        err = descq_export(state, export_cb, connect_cb,
                                get_default_waitset(), IDC_BIND_FLAGS_DEFAULT);
        if (err_is_fail(err)) {
            goto cleanup1;
        }

        while(!state->exp_done) {
            event_dispatch(get_default_waitset());
        }
    
    } else {

        tmp->f.notify = f->notify;
        tmp->f.dereg = f->dereg;
        tmp->f.reg = f->reg;
        tmp->f.create = f->create;
        tmp->f.destroy = f->destroy;
        tmp->f.control = f->control;
        size_t bytes;

        err = frame_alloc(&rx, DESCQ_ALIGNMENT*slots, &bytes);
        if (err_is_fail(err)) {
            goto cleanup1;
        }

        assert(bytes >= DESCQ_ALIGNMENT*slots);

        err = frame_alloc(&tx, DESCQ_ALIGNMENT*slots, &bytes);
        if (err_is_fail(err)) {
            goto cleanup2;
        }

        assert(bytes >= DESCQ_ALIGNMENT*slots);

        err = vspace_map_one_frame_attr((void**) &(tmp->rx_descs),
                                        slots*DESCQ_ALIGNMENT, rx,
                                        VREGION_FLAGS_READ_WRITE, NULL, NULL);
        if (err_is_fail(err)) {
            goto cleanup3;
        }

        err = vspace_map_one_frame_attr((void**) &(tmp->tx_descs),
                                        slots*DESCQ_ALIGNMENT, tx,
                                        VREGION_FLAGS_READ_WRITE, NULL, NULL);
        if (err_is_fail(err)) {
            goto cleanup4;
        }

        memset(tmp->tx_descs, 0, slots*DESCQ_ALIGNMENT);
        memset(tmp->rx_descs, 0, slots*DESCQ_ALIGNMENT);

        tmp->bound_done = false;
        iref_t iref;

        err = nameservice_blocking_lookup(name, &iref);
        if (err_is_fail(err)) {
            goto cleanup5;
        }

        err = descq_bind(iref, bind_cb, tmp, get_default_waitset(),
                              IDC_BIND_FLAGS_DEFAULT);
        if (err_is_fail(err)) {
            goto cleanup5;
        }
 
        while(!tmp->bound_done) {
            event_dispatch(get_default_waitset());
        }

        tmp->local_bind = tmp->binding->local_binding != NULL;

        errval_t err2;
        err = tmp->binding->rpc_tx_vtbl.create_queue(tmp->binding, slots, rx, tx,
            notifications, role, &err2, queue_id);
        if (err_is_fail(err) || err_is_fail(err2)) {
            err = err_is_fail(err) ? err: err2;
            goto cleanup5;
        }

        tmp->tx_seq_ack = (void*)tmp->tx_descs;
        tmp->rx_seq_ack = (void*)tmp->rx_descs;
        tmp->tx_seq_ack->value = 0;
        tmp->rx_seq_ack->value = 0;
        tmp->tx_descs++;
        tmp->rx_descs++;
        tmp->slots = slots-1;
        tmp->rx_seq = 1;
        tmp->tx_seq = 1;

        devq_init(&tmp->q, false);

        tmp->q.f.enq = descq_enqueue;
        tmp->q.f.deq = descq_dequeue;
        tmp->q.f.notify = descq_notify;
        tmp->q.f.reg = descq_register;
        tmp->q.f.dereg = descq_deregister;
        tmp->q.f.ctrl = descq_control;

        tmp->notifications = notifications;

        notificator_init(&tmp->notificator, tmp, descq_can_read, descq_can_write);
        err = waitset_chan_register(get_default_waitset(), &tmp->notificator.ready_to_read, MKCLOSURE(mp_notify, tmp));
        assert(err_is_ok(err));
    }


    *q = tmp;

    DESCQ_DEBUG("create end %p \n", *q);
    return SYS_ERR_OK;

cleanup5:
    vspace_unmap(tmp->rx_descs);
cleanup4:
    vspace_unmap(tmp->rx_descs);
cleanup3:
    cap_destroy(tx);
cleanup2:
    cap_destroy(rx);
cleanup1:
    free(tmp->name);
    free(tmp);

    return err;

}
/**
 * \brief initializes a DMA client device with the giving capability
 *
 * \param info stores information how to find the device driver service
 * \param dev  returns a pointer to the device structure
 *
 * \returns SYS_ERR_OK on success
 *          errval on error
 */
errval_t dma_client_device_init(struct dma_client_info *info,
                                struct dma_client_device **dev)
{
    errval_t err;

    struct dma_client_device *cdev = calloc(1, sizeof(*cdev));
    if (cdev == NULL) {
        return LIB_ERR_MALLOC_FAIL;
    }

#if DMA_BENCH_ENABLED
     bench_init();
#endif

    struct dma_device *dma_dev = (struct dma_device *) cdev;

    CLIENTDEV_DEBUG("initialzing new client device\n", device_id);

    iref_t service_iref = 0;

    switch (info->type) {
        case DMA_CLIENT_INFO_TYPE_ADDR:
            assert(!"NYI: lookup based on physical address range");
            break;
        case DMA_CLIENT_INFO_TYPE_IREF:
            service_iref = info->args.iref;
            break;
        case DMA_CLIENT_INFO_TYPE_NAME:
            CLIENTDEV_DEBUG("looking up iref for name {%s}\n", device_id,
                            info->args.name);
            err = nameservice_blocking_lookup(info->args.name, &service_iref);
            if (err_is_fail(err)) {
                free(cdev);
                return err;
            }
            CLIENTDEV_DEBUG("driver service {%s} @ iref:%"PRIxIREF"\n", device_id,
                            info->args.name, service_iref);
            break;
        default:
            return DMA_ERR_DEVICE_UNSUPPORTED;
            break;
    }

    if (cdev->info.iref == 0) {
        err = dma_manager_lookup_by_iref(service_iref, &cdev->info);
        if (err_is_fail(err)) {
            CLIENTDEV_DEBUG("ERROR: obtaining driver info from DMA manager: %s\n",
                            device_id, err_getstring(err));
            free(cdev);
            return err;
        }
    }

    assert(service_iref != 0);
    dma_dev->type = DMA_DEV_TYPE_CLIENT;
    dma_dev->id = device_id++;
    dma_dev->channels.count = DMA_CLIENT_DEVICE_CONNECTIONS;
    dma_dev->channels.c = calloc(dma_dev->channels.count,
                                 sizeof(*dma_dev->channels.c));
    if (dma_dev->channels.c == NULL) {
        free(cdev);
        return LIB_ERR_MALLOC_FAIL;
    }

    /* channel enumeration */

    CLIENTDEV_DEBUG("doing channel enumeration. discovered %u channels\n",
                    cdev->common.id, cdev->common.channels.count);

    for (uint8_t i = 0; i < dma_dev->channels.count; ++i) {
        struct dma_channel **chan = &dma_dev->channels.c[i];
        err = dma_client_channel_init(cdev, i, service_iref,
                                      (struct dma_client_channel **) chan);
        if (err_is_fail(err)) {
            free(cdev->common.channels.c);
            free(cdev);
            return err;
        }
    }

    dma_dev->f.deregister_memory = dma_client_deregister_memory;
    dma_dev->f.register_memory = dma_client_register_memory;
    dma_dev->f.poll = dma_client_device_poll;

    *dev = cdev;

    return SYS_ERR_OK;
}
Exemple #15
0
int main(int argc, char *argv[])
{
    errval_t err;
    my_core_id = disp_get_core_id();
    bench_init();

    if (argc == 1) { /* server */
        struct monitor_binding *mb = get_monitor_binding();
        mb->rx_vtbl.num_cores_reply = num_cores_reply;

        // Get number of cores in the system
        err = mb->tx_vtbl.num_cores_request(mb, NOP_CONT);
        if (err_is_fail(err)) {
            USER_PANIC_ERR(err, "error sending num_core_request");
        }

        // Spawn client on another core
        char *xargv[] = {"shared_mem_clock_bench", "dummy", NULL};
        err = spawn_program_on_all_cores(false, xargv[0], xargv, NULL,
                                         SPAWN_FLAGS_DEFAULT, NULL);
        if (err_is_fail(err)) {
            USER_PANIC_ERR(err, "error spawning on other cores");
        }

        // Export service
        err = bench_export(NULL, export_cb, connect_cb, get_default_waitset(),
                          IDC_EXPORT_FLAGS_DEFAULT);
        if (err_is_fail(err)) {
            USER_PANIC_ERR(err, "export failed");
        }

        // Allocate a cap for the shared memory
        err = frame_alloc(&clock_frame, BASE_PAGE_SIZE, NULL);
        if (err_is_fail(err)) {
            USER_PANIC_ERR(err, "frame_alloc failed");
        }
        err = clock_init(clock_frame);
        if (err_is_fail(err)) {
            USER_PANIC_ERR(err, "clock_init failed");
        }

        // Wait for all connections to be established
        start_experiment_flag = false;
        while(!start_experiment_flag) {
            messages_wait_and_handle_next();
        }

        // Start experiments
        start_experiment();

    } else { /* client */
        // Lookup service
        iref_t iref;
        err = nameservice_blocking_lookup("server", &iref);
        if (err_is_fail(err)) {
            USER_PANIC_ERR(err, "nameservice_blocking_lookup failed");
        }

        // Bind to service
        err = bench_bind(iref, bind_cb, NULL, get_default_waitset(),
                         IDC_BIND_FLAGS_DEFAULT);
        if (err_is_fail(err)) {
            USER_PANIC_ERR(err, "bind failed");
        }
    }

    messages_handler_loop();
}