Esempio n. 1
0
/**
 * @brief Given a table of interfaces, initialize and enable all associated
 *        power supplies
 * @param interfaces table of interfaces to initialize
 * @param nr_ints number of interfaces to initialize
 * @param nr_spring_ints number of spring interfaces
 * @returns: 0 on success, <0 on error
 * @sideeffects: leaves interfaces powered off on error.
 */
int interface_init(struct interface **ints,
                   size_t nr_ints, size_t nr_spring_ints) {
    unsigned int i;
    int rc;

    dbg_info("Initializing all interfaces\n");

    if (!ints) {
        return -ENODEV;
    }

    interfaces = ints;
    nr_interfaces = nr_ints;
    nr_spring_interfaces = nr_spring_ints;

    for (i = 0; i < nr_interfaces; i++) {
        rc = interface_pwr_enable(interfaces[i]);
        if (rc < 0) {
            dbg_error("Failed to enable interface %s\n", interfaces[i]->name);
            interface_exit();
            return rc;
        }
        rc = interface_generate_wakeout(interfaces[i], true);
        if (rc < 0) {
            dbg_error("Failed to generate wakeout on interface %s\n",
                      interfaces[i]->name);
            interface_exit();
            return rc;
        }
    }

    return 0;
}
Esempio n. 2
0
/**
 * @brief           Return sampled data of a given power rail.
 * @return          0 on success, standard error codes otherwise.
 * @param[in]       bdbpm_r: power rail device structure
 * @param[out]      m: power measurement data (voltage, current, power)
 */
int bdbpm_measure_rail(bdbpm_rail *bdbpm_r, pwr_measure *m)
{
    int ret;

    if ((!bdbpm_r) || (!m)) {
        dbg_error("%s(): NULL pointer!\n", __func__);
        return -EINVAL;
    }
    dbg_verbose("%s(): measuring %s rail...\n", __func__, bdbpm_r->rail_name);

    /* Configure I2C Mux */
    ret = bdbpm_ina230_select(bdbpm_r->dev);
    if (ret) {
        dbg_error("%s(): failed to configure i2c mux! (%d)\n",
                  __func__, ret);
        return ret;
    }
    /* Get measurement data */
    ret = ina230_get_data(bdbpm_r->ina230_dev, m);
    if (ret) {
        dbg_error("%s(): failed to retrieve measurement data! (%d)\n",
                  __func__, ret);
    } else {
        dbg_verbose("%s(): %s measurement: %duV %duA %duW\n", __func__,
                    bdbpm_r->rail_name, m->uV, m->uA, m->uW);
    }

    return ret;
}
Esempio n. 3
0
static bool
rexec_remote( char *host, int port, char *c )
{
    int     ret, sockfd;
    char    *cmd=NULL;

    cmd = (char*)malloc( strlen(c) + 10);
    sockfd = sock_connectTo( host, port );
    if(sockfd==-1)
        return false;
    sprintf( cmd, "EXECUTE %s", c );
    dbg_verbose( "%s\n", cmd );
    sock_sendLine( sockfd, cmd );
    ret = sock_getStatus( sockfd );
    if( ret < 0 )
    {   dbg_error( "rexec: No remote confirmation!\n");
        free(cmd);
        return false;
    }

    if( ret > 0 )
    {   dbg_error("rexec: Error: '%s'\n", strerror( ret ) );
        dbg_error("rexec: Can't execute [%s].\n", c );
        free(cmd);
        shutdown( sockfd, 2);
        close( sockfd );
        return false;
    }
    free(cmd);
    shutdown( sockfd, 2);
    close( sockfd );
    return true;
}
Esempio n. 4
0
gas_t *gas_pgas_new(const config_t *cfg, boot_t *boot) {
  size_t heap_size = cfg->heapsize;

  if (global_heap) {
    return &_pgas_vtable;
  }

  global_heap = malloc(sizeof(*global_heap));
  if (!global_heap) {
    dbg_error("could not allocate global heap\n");
    return NULL;
  }

  if (heap_init(global_heap, heap_size) != LIBHPX_OK) {
    dbg_error("failed to allocate global heap\n");
    free(global_heap);
    return NULL;
  }

  global_allocator_init();
  if (here->rank == 0) {
    cyclic_allocator_init();
  }

  return &_pgas_vtable;
}
Esempio n. 5
0
// Responsible for drawing the Timeline, NOT the contents of the frames (use Timeline::drawCurFrame for that)
// We draw in the middle of the Timeline the current frame
// We start by drawing cur frame and it's layer in the middle.  We color it to indicate it is cur frame
void Timeline::drawTimeline() {
    //draw background of Timeline
    ofSetColor(COLOR_TIMELINE_BRACKGROUND);
//    ofDrawRectangle(_x, _y, width, height);

    // calculate what the frame num of the left-most frame and right-most frame
    int pot_right = (width / 2) / FRAME_SIZE; // potential right. max number of frames that fit to right of middle frame
    int pot_left = (width / 2) / FRAME_SIZE; // potential left. max number of frames that fit to left of middle frame
    pot_right -= 1;           // potential right. adjust because we don't count cur frame
    
    int act_left = MIN(curFrame, pot_left); // actual left. number of frames to draw left
    int act_right = MIN(frames.size() - curFrame - 1, pot_right); // actual right. number of frames to draw right
    int low_frame = curFrame - act_left;
    int high_frame = curFrame + act_right;
    
    // calculate the coordinates of the middle of the Timeline in x dimension, bottom of Timeline in y
    int init_x = _x + width / 2;
    init_x += -((curFrame - low_frame) * FRAME_SIZE);  // adjust for whatever the left most frame to be drawn is
    int init_y = _y + height - EDGE_SPACER - FRAME_SIZE- NUM_SPACER;
    int cur_x = init_x;
    int cur_y = init_y;

    // TODO: Should f be < or <= s
    for(int f = low_frame; f <= high_frame; f++) {
        drawFrameNum(cur_x, f);
        for(int l = 0;  l < numLayers; l++) {
            // the selected frame should be a different color from all the other frames
            // and the selected layer in that frame should be an even different color
            if((l == curlayerNum) && (f == curFrame)) {
                ofSetColor(COLOR_CUR_DRAWSPACE);
            } else if(f == curFrame){
                ofSetColor(COLOR_CUR_FRAME);
            } else {
                ofSetColor(COLOR_FRAME);
            }
            
            ofFill();
            ofDrawCircle(cur_x, cur_y, FRAME_SIZE/3, FRAME_SIZE/3);
            ofSetColor(ofColor::black);
            ofFill();
            
            // draw the next layer above the current one
            cur_y -= FRAME_SIZE;
            
            // check to make sure we aren't drawing off of the Timeline
            if (cur_y < (_y + EDGE_SPACER + NUM_SPACER)) {
                dbg_error("About to draw off the edge of the Timeline!");
            }
        }
        // reset y to the bottom of the Timeline, and iterate x to the right by one frame
        cur_y = init_y;
        cur_x += FRAME_SIZE;
        if(cur_x > (_x + width - EDGE_SPACER - FRAME_SIZE)) {
            dbg_error("About to draw off the edge of the Timeline in x direction!");
            break;
        }
    }
}
Esempio n. 6
0
struct scheduler *scheduler_new(const config_t *cfg) {
    const int workers = cfg->threads;

    struct scheduler *s = malloc(sizeof(*s));
    if (!s) {
        dbg_error("could not allocate a scheduler.\n");
        return NULL;
    }

    size_t r = HPX_CACHELINE_SIZE - sizeof(s->workers[0]) % HPX_CACHELINE_SIZE;
    size_t padded_size = sizeof(s->workers[0]) + r;
    size_t total = workers * padded_size;
    int e = posix_memalign((void**)&s->workers, HPX_CACHELINE_SIZE, total);
    if (e) {
        dbg_error("could not allocate a worker array.\n");
        scheduler_delete(s);
        return NULL;
    }

    for (int i = 0; i < workers; ++i) {
        e = worker_init(&s->workers[i], i, i, 64);
        if (e) {
            dbg_error("failed to initialize a worker.\n");
            scheduler_delete(s);
            return NULL;
        }
    }

    e = system_barrier_init(&s->barrier, NULL, workers);
    if (e) {
        dbg_error("failed to allocate the scheduler barrier.\n");
        scheduler_delete(s);
        return NULL;
    }

    // initialize the run state.
    sync_store(&s->stopped, SCHED_STOP, SYNC_RELEASE);
    s->run_state.state = SCHED_STOP;
    s->run_state.lock = (pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER;
    s->run_state.running = (pthread_cond_t)PTHREAD_COND_INITIALIZER;

    sync_store(&s->next_tls_id, 0, SYNC_RELEASE);
    s->n_workers    = workers;
    s->n_active_workers = workers;
    s->wf_threshold = cfg->sched_wfthreshold;

    thread_set_stack_size(cfg->stacksize);
    log_sched("initialized a new scheduler.\n");

    // bind a worker for this thread so that we can spawn lightweight threads
    _bind_self(&s->workers[0]);

    log_sched("worker 0 ready.\n");
    return s;
}
Esempio n. 7
0
gas_t *gas_new(config_t *cfg, struct boot *boot) {
#ifndef HAVE_NETWORK
  // if we didn't build a network we need to default to SMP
  cfg->gas = HPX_GAS_SMP;
#endif

  int ranks = boot_n_ranks(boot);
  gas_t *gas = NULL;
  libhpx_gas_t type = cfg->gas;

  // if we built a network, we might want to optimize for SMP
  if (ranks == 1 && cfg->opt_smp) {
    if (type != HPX_GAS_SMP && type != HPX_GAS_DEFAULT) {
      log_level(LEVEL, "GAS %s overridden to SMP.\n", HPX_GAS_TO_STRING[type]);
      cfg->gas = HPX_GAS_SMP;
    }
    type = HPX_GAS_SMP;
  }

  if (ranks > 1 && type == HPX_GAS_SMP) {
    dbg_error("SMP GAS selection fails for %d ranks\n", ranks);
  }

  switch (type) {
   case HPX_GAS_SMP:
    gas = gas_smp_new();
    break;

   case HPX_GAS_AGAS:
#if defined(HAVE_AGAS) && defined(HAVE_NETWORK)
    gas = gas_agas_new(cfg, boot);
#endif
    break;

   case HPX_GAS_PGAS:
#ifdef HAVE_NETWORK
    gas = gas_pgas_new(cfg, boot);
#endif
    break;

   default:
    dbg_error("unexpected configuration value for --hpx-gas\n");
  }

  if (!gas) {
    log_error("GAS %s failed to initialize\n", HPX_GAS_TO_STRING[type]);
  }
  else {
    log_gas("GAS %s initialized\n", HPX_GAS_TO_STRING[type]);
  }

  return gas;
}
Esempio n. 8
0
/* EVT1 */
static int evt1_board_init(struct ara_board_info *board_info) {
    int rc;

    /* For now, just always enable REFCLK_MAIN and the buffers. */
    rc = vreg_config(&refclk_main_vreg) || vreg_get(&refclk_main_vreg);
    if (rc) {
        dbg_error("%s: can't start REFCLK_MAIN: %d\n", __func__, rc);
        return ERROR;
    }

    /* Configure the switch power supply lines. */
    rc = vreg_config(&sw_vreg);
    if (rc) {
        dbg_error("%s: can't configure switch regulators: %d\n", __func__, rc);
        return ERROR;
    }
    stm32_configgpio(evt1_board_info.sw_data.gpio_reset);
    up_udelay(POWER_SWITCH_OFF_STAB_TIME_US);

    /* Configure the wake/detect lines. */
    stm32_configgpio(WD_1_DET_IN_GPIO);
    stm32_configgpio(WD_2_DET_IN_GPIO);
    stm32_configgpio(WD_3A_DET_IN_GPIO);
    stm32_configgpio(WD_3B_DET_IN_GPIO);
    stm32_configgpio(WD_4A_DET_IN_GPIO);
    stm32_configgpio(WD_4B_DET_IN_GPIO);
    stm32_configgpio(WD_5_DET_IN_GPIO);
    stm32_configgpio(WD_8A_DET_IN_GPIO);
    stm32_configgpio(WD_8B_DET_IN_GPIO);

    /* Configure the module release pins */
    stm32_configgpio(MOD_RELEASE_1_CONFIG);
    stm32_configgpio(MOD_RELEASE_2_CONFIG);
    stm32_configgpio(MOD_RELEASE_3A_CONFIG);
    stm32_configgpio(MOD_RELEASE_3B_CONFIG);
    stm32_configgpio(MOD_RELEASE_4A_CONFIG);
    stm32_configgpio(MOD_RELEASE_4B_CONFIG);
    stm32_configgpio(MOD_RELEASE_5_CONFIG);

    /* Configure ARA key input pin */
    stm32_configgpio(ARA_KEY_CONFIG);

    /*
     * (Module hotplug pins unconfigured. TODO, part of SW-1942.)
     */

    return 0;
}
Esempio n. 9
0
/**
 * @brief           Initialize dedicated HW (GPIO, ADC) and configure averaging
 *                  to enable current measurement of a given spring.
 * @warning         Shall be called prior to any other spwrm_* call.
 * warning          'spring' index starts at 1, not 0.
 * @return          0 on success, standard error codes otherwise.
 * @param[in]       spring: selected spring ([1..SPRING_COUNT])
 * @param[in]       count: averaging sample count
 *                  ([1..ADC_MAX_AVG_SAMPLE_COUNT])
 */
int spwrm_init(uint8_t spring, uint8_t count)
{
    uint8_t adc, chan;
    uint32_t spin;
    int ret;

    CHECK_SPRING(spring);
    CHECK_ARG_AVG_COUNT(count);

    adc = spwrm_get_adc_device(spring);
    chan = spwrm_get_adc_channel(spring);
    spin = spwrm_get_sign_pin(spring);

    dbg_verbose("%s(): Configuring %s... (adc=%u, spin=0x%08X)\n",
                __func__, spwrm_get_name(spring), adc, spin);

    /* Configure SIGN pin as input */
    stm32_configgpio(spin);

    ret = adc_init(adc, chan, count);
    if (ret) {
        dbg_error("%s(): %s initialization failed!!! (%d).\n", __func__,
                    spwrm_get_name(spring), ret);
    } else {
        dbg_verbose("%s(): %s initialization done.\n", __func__,
                    spwrm_get_name(spring));
    }

    return ret;
}
Esempio n. 10
0
enum hwid board_get_hwid(void) {
    int hwid_read;

    hwid_read = ((read_hwid_bit(HWID_0) << 0) |
                 (read_hwid_bit(HWID_1) << 1) |
                 (read_hwid_bit(HWID_2) << 2) |
                 (read_hwid_bit(HWID_3) << 3));

    switch (hwid_read) {
    case 0b1111:
        return HWID_DB3_0_1;
    case 0b1110:
        return HWID_DB3_2;
    case 0b0001:
        return HWID_DB3_5;
    case 0b0010:
        return HWID_EVT1;
    case 0b0011:
        return HWID_EVT1_5;
    case 0b0100:
        return HWID_EVT1_6;
    default:
        dbg_error("Unknown HWID 0x%x, aborting\n", hwid_read);
        break;
    }

    return ERROR;
}
Esempio n. 11
0
int ara_key_enable(const struct ara_board_info *info,
                   int (*longpress_callback)(void *priv), bool enable)
{
    if (enable) {
        if (!info->ara_key_configured) {
            dbg_error("%s: no ara key gpio defined\n", __func__);
            return -EINVAL;
        }

        the_ara_key.longpress_callback = longpress_callback;
        the_ara_key.db.gpio = info->ara_key_gpio;
	the_ara_key.db.ms = ARA_KEY_DEBOUNCE_TIME_MS;
        the_ara_key.db.isr = ara_key_irqhandler;
        the_ara_key.db.db_state = DB_ST_INVALID;
        the_ara_key.rising_edge = info->ara_key_rising_edge;

        gpio_activate(info->ara_key_gpio);
        gpio_direction_in(info->ara_key_gpio);
        gpio_irq_mask(info->ara_key_gpio);
        gpio_irq_settriggering(info->ara_key_gpio, IRQ_TYPE_EDGE_BOTH);
        gpio_irq_attach(info->ara_key_gpio, ara_key_irqhandler);
    } else {
        gpio_irq_mask(info->ara_key_gpio);
        gpio_deactivate(info->ara_key_gpio);
    }

    return OK;
}
Esempio n. 12
0
int scheduler_startup(struct scheduler *sched, const config_t *cfg) {
    worker_t *worker = NULL;
    int status = LIBHPX_OK;

    // start all of the other worker threads
    for (int i = 1, e = sched->n_workers; i < e; ++i) {
        worker = scheduler_get_worker(sched, i);
        status = _create(worker, cfg);

        if (status != LIBHPX_OK) {
            dbg_error("could not start worker %d.\n", i);

            for (int j = 1; j < i; ++j) {
                worker = scheduler_get_worker(sched, j);
                _cancel(worker);
            }

            for (int j = 1; j < i; ++j) {
                worker = scheduler_get_worker(sched, j);
                _join(worker);
            }

            return status;
        }
    }

    // wait for the other slave worker threads to launch
    system_barrier_wait(&sched->barrier);

    return status;
}
Esempio n. 13
0
/// Invoke an operation on the user-defined LCO's buffer.
static int _user_lco_set(lco_t *lco, int size, const void *from) {
  int set = 0;
  lco_lock(lco);
  _user_lco_t *u = (_user_lco_t *)lco;

  if (lco_get_triggered(&u->lco)) {
    dbg_error("cannot set an already set user_lco.\n");
    goto unlock;
  }

  // perform the op()
  handler_t f = actions[u->op].handler;
  hpx_monoid_op_t op = (hpx_monoid_op_t)f;
  op(u->buffer, from, size);

  f = actions[u->predicate].handler;
  hpx_predicate_t predicate = (hpx_predicate_t)f;
  if (predicate(u->buffer, u->size)) {
    lco_set_triggered(&u->lco);
    scheduler_signal_all(&u->cvar);
    set = 1;
  }

  unlock:
   lco_unlock(lco);
   return set;
}
Esempio n. 14
0
/**
 * @brief           Measure the current consumption of a given spring.
 * @return          current consumption of a given spring (in microamps)
 * warning          'spring' index starts at 1, not 0.
 * @param[in]       spring: selected spring ([1..SPRING_COUNT])
 * @param[out]      uA: selected spring current measurement, in microamps)
 */
int spwrm_get_current(uint8_t spring, int32_t *uA)
{
    int ret;
    uint8_t adc, chan;
    uint32_t spin, uV;

    CHECK_SPRING(spring);
    CHECK_NULL_ARG(uA);

    adc = spwrm_get_adc_device(spring);
    chan = spwrm_get_adc_channel(spring);
    spin = spwrm_get_sign_pin(spring);
    *uA = 0;

    ret = adc_get_data(adc, chan, &uV);
    if (ret) {
        dbg_error("%s(): failed to get %s data! (%d)\n", __func__,
                  spwrm_get_name(spring), ret);
        return ret;
    }
    /* Convert to uV */
    uV = adc_get_uV(uV);
    /* Get data sign */
    if (stm32_gpioread(spin) == 0) {
        dbg_verbose("%s(): pin=0 => sign=-\n", __func__);
        *uA = -((int32_t) max9929f_get_Iload(uV));
    } else {
        dbg_verbose("%s(): pin=1 => sign=+\n", __func__);
        *uA = (int32_t) max9929f_get_Iload(uV);
    }
    dbg_verbose("%s(): measured voltage=%uuV => current=%duA\n",
                __func__, uV, *uA);

    return 0;
}
Esempio n. 15
0
/**
 * @brief           Deinitialize dedicated current measurement HW
 *                  (GPIO, ADC) of a given spring.
 * warning          'spring' index starts at 1, not 0.
 * @return          0 on success, standard error otherwise.
 * @param[in]       spring: selected spring ([1..SPRING_COUNT])
 */
int spwrm_deinit(uint8_t spring)
{
    int ret;
    uint8_t adc, chan;
    uint32_t spin;

    CHECK_SPRING(spring);

    dbg_verbose("%s(): De-initializing %s...\n", __func__,
                spwrm_get_name(spring));

    adc = spwrm_get_adc_device(spring);
    chan = spwrm_get_adc_channel(spring);
    spin = spwrm_get_sign_pin(spring);

    /* Unconfigure GPIO ADC channel pin */
    stm32_unconfiggpio(spin);
    /* Shutdown ADC */
    ret = adc_deinit(adc, chan);
    if (ret) {
        dbg_error("%s(): %s de-initialization failed!!! (%d)\n", __func__,
                  spwrm_get_name(spring), ret);
    } else {
        dbg_verbose("%s(): %s de-initialization done.\n", __func__,
                    spwrm_get_name(spring));
    }
    return ret;
}
Esempio n. 16
0
/// Cancel a worker thread.
static void _cancel(const worker_t *worker) {
    dbg_assert(worker);
    dbg_assert(worker->thread != pthread_self());
    if (pthread_cancel(worker->thread)) {
        dbg_error("cannot cancel worker thread %d.\n", worker->id);
    }
}
Esempio n. 17
0
/// A simple mmap wrapper that guarantees alignment.
///
/// This calls munmap at least once, and will attempt to allocate more data than
/// is always necessary, so it should only be used on a fallback path. This
/// implementation simply over allocates space so that we are guaranteed that
/// there is a properly aligned region inside of the mapping. It then munmaps
/// the parts of the allocation that aren't part of this region.
///
/// @param         addr A "suggested" address. This is most likely ignored.
/// @param            n The number of bytes to map, must be 2^n.
/// @param         prot The protection flags.
/// @param        flags Additional flags for the mapping.
/// @param           fd A file descriptor to map from.
/// @param          off The file offset to map at.
/// @param        align The alignment, must be 2^n.
///
/// @returns The properly-aligned mapped region, or NULL if there was an error.
static void *_mmap_aligned(void *addr, size_t n, int prot, int flags, int fd,
                           int off, size_t align) {
  char *buffer = mmap(addr, n + align, prot, flags, fd, off);
  if (buffer == MAP_FAILED) {
    dbg_error("could not map %zu bytes with %zu alignment\n", n, align);
  }

  // find the range in the allocation that matches what we want
  uintptr_t   bits = (uintptr_t)buffer;
  uintptr_t   mask = (align - 1);
  uintptr_t suffix = bits & mask;
  uintptr_t prefix = align - suffix;

  // return the overallocated pages back to the OS, system_munmap here is fine
  // because we know our sizes are okay even for huge allocations
  if (prefix) {
    dbg_check( munmap(buffer, prefix) );
  }
  if (suffix) {
    dbg_check( munmap(buffer + prefix + n, suffix) );
  }

  // and return the correctly aligned range
  return buffer + prefix;
}
Esempio n. 18
0
/**
 * @brief Configure all the voltage regulators associated with an interface
 * to their default states.
 * @param iface interface to configure
 */
static int interface_config(struct interface *iface)
{
    int rc = 0;

    dbg_verbose("Configuring interface %s.\n",
            iface->name ? iface->name : "unknown");

    /* Configure default state for the regulator pins */
    rc = vreg_config(iface->vreg);

    /*
     * Configure WAKEOUT as input, floating so that it does not interfere
     * with the wake and detect input pin
     */
    if (iface->wake_out) {
        if (stm32_configgpio(iface->wake_out | GPIO_INPUT) < 0) {
            dbg_error("%s: Failed to configure WAKEOUT pin for interface %s\n",
                      __func__, iface->name ? iface->name : "unknown");
            rc = -1;
        }
    }

    iface->power_state = false;

    return rc;
}
Esempio n. 19
0
/**
 * @brief Given a table of interfaces, power off all associated
 *        power supplies
 * @param interfaces table of interfaces to initialize
 * @param nr_ints number of interfaces to initialize
 * @param nr_spring_ints number of spring interfaces
 * @returns: 0 on success, <0 on error
 */
int interface_early_init(struct interface **ints,
                         size_t nr_ints, size_t nr_spring_ints) {
    unsigned int i;
    int rc;
    int fail = 0;

    dbg_info("Power off all interfaces\n");

    if (!ints) {
        return -ENODEV;
    }

    interfaces = ints;
    nr_interfaces = nr_ints;
    nr_spring_interfaces = nr_spring_ints;

    for (i = 0; i < nr_interfaces; i++) {
        rc = interface_config(interfaces[i]);
        if (rc < 0) {
            dbg_error("Failed to power interface %s\n", interfaces[i]->name);
            fail = 1;
            /* Continue configuring remaining interfaces */
            continue;
        }
    }

    if (fail) {
        return -1;
    }

    /* Let everything settle for a good long while.*/
    up_udelay(POWER_OFF_TIME_IN_US);

    return 0;
}
Esempio n. 20
0
void _bitmap_bounds_check(bitmap_t *b, uint32_t page, uint32_t word) {
  assert(word < _bitmap_num_words);

  // check if the page has been allocated or not
  for (;;) {
    _bitmap_page_t p = sync_load(&b[page].page, SYNC_ACQUIRE);
    if (!p) {
      void *newp = NULL;
      int e = posix_memalign((void**)&newp, HPX_CACHELINE_SIZE,
                             _bitmap_num_words * sizeof(_bitmap_word_t));
      if (e) {
        dbg_error("failed to allocate a page for %u words\n",
                  _bitmap_num_words);
      }
      memset(newp, 0, _bitmap_num_words * sizeof(_bitmap_word_t));

      if (!sync_cas(&b[page].page, &p, newp, SYNC_RELEASE, SYNC_RELAXED)) {
        free(newp);
        // try again..
        continue;
      } else {
        // move on to the previous page
        page--;
        continue;
      }
    }
    break;
  }
}
Esempio n. 21
0
static void _join(worker_t *worker) {
    dbg_assert(worker);
    dbg_assert(worker->thread != pthread_self());
    int e = pthread_join(worker->thread, NULL);
    if (e) {
        dbg_error("cannot join worker thread %d (%s).\n", worker->id, strerror(e));
    }
}
Esempio n. 22
0
/// Update the protections on the first and last page in the stack.
///
/// @param         base The base address.
/// @param         prot The new permissions.
static void _mprotect_boundary_pages(void *base, int prot) {
  dbg_assert(_protect_stacks());

  if ((uintptr_t)base & (HPX_PAGE_SIZE - 1)) {
    dbg_error("stack must be page aligned for mprotect\n");
  }

  char *p1 = base;
  char *p2 = p1 + _thread_size + HPX_PAGE_SIZE;
  int e1 = mprotect(p1, HPX_PAGE_SIZE, prot);
  int e2 = mprotect(p2, HPX_PAGE_SIZE, prot);

  if (e1 || e2) {
    dbg_error("Mprotect error: %d (EACCES %d, EINVAL %d, ENOMEM %d)\n", errno,
              EACCES, EINVAL, ENOMEM);
  }
}
Esempio n. 23
0
/**
 * @brief           Initialize the power measurement HW and SW library.
 *                  To be called once, before any other call to the library.
 * @return          0 on success, standard error codes otherwise.
 * @param[in]       current_lsb_uA: current measurement precision (LSB) in uA
 * @param[in]       ct: sampling conversion time to be used
 * @param[in]       avg_count: averaging sample count (>0)
 */
int bdbpm_init(uint32_t current_lsb_uA,
               ina230_conversion_time ct,
               ina230_avg_count avg_count)
{
    dbg_verbose("%s(): Initializing with options lsb=%uuA, ct=%u, avg_count=%u...\n",
                __func__, current_lsb_uA, ct, avg_count);
    /* Initialize I2C internal structs */
    i2c_dev = up_i2cinitialize(PWRM_I2C_BUS);
    if (!i2c_dev) {
        dbg_error("%s(): Failed to get I2C bus %u\n", __func__, PWRM_I2C_BUS);
        return -ENXIO;
    }

    bdbpm_current_lsb = current_lsb_uA;
    if (ct >= ina230_ct_count) {
        dbg_error("%s(): invalid conversion time! (%u)\n", __func__, ct);
        up_i2cuninitialize(i2c_dev);
        return -EINVAL;
    }
    if (avg_count >= ina230_avg_count_max) {
        dbg_error("%s(): invalid average count! (%u)\n", __func__, avg_count);
        up_i2cuninitialize(i2c_dev);
        return -EINVAL;
    }
    bdbpm_ct = ct;
    bdbpm_avg_count = avg_count;

    current_dev = -1;

    /*
     * Setup I/O selection pins on U135
     *
     * Note: U135 is registered to gpio_chip from the board code
     */
    gpio_direction_out(I2C_INA230_SEL1_A, 1);
    gpio_direction_out(I2C_INA230_SEL1_B, 1);
    gpio_direction_out(I2C_INA230_SEL1_INH, 1);
    gpio_direction_out(I2C_INA230_SEL2_A, 1);
    gpio_direction_out(I2C_INA230_SEL2_B, 1);
    gpio_direction_out(I2C_INA230_SEL2_INH, 1);

    dbg_verbose("%s(): done.\n", __func__);

    return OK;
}
Esempio n. 24
0
void system_munmap(void *UNUSED, void *addr, size_t size) {
  int e = munmap(addr, size);
  if (e < 0) {
    dbg_error("munmap failed: %s.  addr is %p, and size is %zu\n",
          strerror(errno), addr, size);
  }
  log_mem("munmapped %zu bytes for a total of %zu\n", size,
          _update_total(-size));
}
Esempio n. 25
0
static void _bind_self(worker_t *worker) {
    dbg_assert(worker);

    if (self && self != worker) {
        dbg_error("HPX does not permit worker structure switching.\n");
    }
    self = worker;
    self->thread = pthread_self();
}
Esempio n. 26
0
ssize_t um_consume_one_message(um_parser_t* um_parser,
                               const uint8_t* buf, size_t nbuf,
                               uint64_t* reqid_out,
                               mc_msg_t** msg_out) {
  FBI_ASSERT(um_parser && buf && nbuf > 0 && reqid_out && msg_out);
  *msg_out = NULL;

  ssize_t consumed = entry_list_preparer_read(&um_parser->prep,
                                              (const char*)buf,
                                              nbuf);
  if (consumed <= 0) {
    goto error;
  }

  /* Because the rank of the unsigned integer is equal to the rank of the
   * signed integer, the signed integer is converted to the type of the
   * unsigned integer, and this assertion triggers on error.  To get around
   * this, we do the cast ourselves.
   */
  FBI_ASSERT(consumed <= (ssize_t)nbuf);

  if (entry_list_preparer_finished(&um_parser->prep)) {
    entry_list_t elist;
    if (entry_list_consume_preparer(&elist, &um_parser->prep) < 0) {
      goto error;
    }
    mc_msg_t base;
    mc_msg_init_not_refcounted(&base);
    _parse_info_t parse_info;
    if (_fill_base_msg(&elist, &base, &parse_info) != 0) {
      goto error;
    }
    *reqid_out = parse_info.reqid;

    *msg_out = _msg_create(&base, &elist, &parse_info);
    if (*msg_out == NULL) {
      dbg_error("msg_create failed");
      goto error;
    }

    FBI_ASSERT((*msg_out)->op != mc_op_end);

    entry_list_cleanup(&elist);
  } else {
    FBI_ASSERT(consumed == nbuf);
  }

  return consumed;

error:
  entry_list_preparer_reset_after_failure(&um_parser->prep);

  // Function that return an error must have not left any messages around
  FBI_ASSERT(*msg_out == NULL);
  return -1;
}
Esempio n. 27
0
static int _create(worker_t *worker, const config_t *cfg) {
    pthread_t thread;

    int e = pthread_create(&thread, NULL, _run, worker);
    if (e) {
        dbg_error("failed to start a scheduler worker pthread.\n");
        return e;
    }
    return LIBHPX_OK;
}
Esempio n. 28
0
void mbc_init(u32 loaded_size) {
	u8 cart_type = mem_rom[0x147];
	// Si la taille n'est pas celle définie dans l'en-tête, il y a probablement une erreur
	rom_size = calc_rom_size(mem_rom[0x148]);
	if (rom_size != loaded_size)
		dbg_error("Invalid ROM size. Please check that it is not corrupt.");
	rom_size = min(rom_size, loaded_size);		// Pour ne pas dépasser...
	// Taille de la RAM
	ram_size = calc_ram_size(mem_rom[0x149]);
	memset(ram_data, 0, ram_size);
	// Initialisation; la bank 0 est toujours mappée à 0000 - 3FFF
	// rom_bank concerne uniquement les accès à 4000 - 7FFF
	params.rom_bank = 1;		// 4000-7FFF
	params.ram_bank = 0;
	params.bank_mode = 0;		// ROM bank select
	params.ram_enable = 0;		// RAM désactivée
	// MBC selon le types de carte: voir pandocs
	switch (cart_type) {
		case 0x00:		// ROM only
		case 0x08:		// ROM + RAM
		case 0x09:		// ROM + RAM + BATTERY
			mbc_read = direct_read;
			mbc_write = null_write;
			params.ram_enable = 1;		// RAM toujours activée si pas de MBC
			dbg_info("No mapper");
			break;
		case 0x01:		// MBC1
		case 0x02:		// MBC1 + RAM
		case 0x03:		// MBC1 + RAM + BATTERY
			mbc_read = mbc1_read;
			mbc_write = mbc1_write;
			dbg_info("MBC1 mapper");
			break;
		case 0x05:		// MBC2
		case 0x06:		// MBC2 + BATTERY
			mbc_read = mbc1_read;
			mbc_write = mbc2_write;
			dbg_info("MBC2 mapper");
			break;
		case 0x0f:		// MBC3 + TIMER + BATTERY
		case 0x10:		// MBC3 + TIMER + RAM + BATTERY
		case 0x11:		// MBC3
		case 0x12:		// MBC3 + RAM
		case 0x13:		// MBC3 + RAM + BATTERY
			mbc_read = mbc1_read;
			mbc_write = mbc3_write;
			dbg_info("MBC3 mapper");
			break;
		default:
			dbg_warning("Unknown cartridge type %02x. Will be emulated as MBC3", cart_type);
			mbc_read = mbc1_read;
			mbc_write = mbc3_write;
			break;
	}
}
Esempio n. 29
0
static void* dbgs(void* arg) {
  EXPECT_EQ(0, sem_wait(&dbg_lock));

  uint saved_lvl = fbi_get_debug();
  fbi_set_debug(UINT_MAX);

  long unsigned exp_tid = (long unsigned) pthread_self();
  long unsigned tid = 0;

#define TID_SCAN_STR "%20lu%*[^\n]"
  dbg_critical("Test dbg");
  EXPECT_EQ(1, fscanf(redir, TID_SCAN_STR, &tid));
  EXPECT_EQ(exp_tid, tid);

  dbg_error("Test dbg");
  EXPECT_EQ(1, fscanf(redir, TID_SCAN_STR, &tid));
  EXPECT_EQ(exp_tid, tid);

  dbg_warning("Test dbg");
  EXPECT_EQ(1, fscanf(redir, TID_SCAN_STR, &tid));
  EXPECT_EQ(exp_tid, tid);

  dbg_notify("Test dbg");
  EXPECT_EQ(1, fscanf(redir, TID_SCAN_STR, &tid));
  EXPECT_EQ(exp_tid, tid);

  dbg_info("Test dbg");
  EXPECT_EQ(1, fscanf(redir, TID_SCAN_STR, &tid));
  EXPECT_EQ(exp_tid, tid);

  dbg_debug("Test dbg");
  EXPECT_EQ(1, fscanf(redir, TID_SCAN_STR, &tid));
  EXPECT_EQ(exp_tid, tid);

  dbg_spew("Test dbg");
  EXPECT_EQ(1, fscanf(redir, TID_SCAN_STR, &tid));
  EXPECT_EQ(exp_tid, tid);

  dbg_low("Test dbg");
  EXPECT_EQ(1, fscanf(redir, TID_SCAN_STR, &tid));
  EXPECT_EQ(exp_tid, tid);

  dbg_medium("Test dbg");
  EXPECT_EQ(1, fscanf(redir, TID_SCAN_STR, &tid));
  EXPECT_EQ(exp_tid, tid);

  dbg_high("Test dbg");
  EXPECT_EQ(1, fscanf(redir, TID_SCAN_STR, &tid));
  EXPECT_EQ(exp_tid, tid);

  fbi_set_debug(saved_lvl);
  EXPECT_EQ(0, sem_post(&dbg_lock));
  return nullptr;
}
Esempio n. 30
0
/**
 * @brief           Return the time between 2 measurement samples.
 * @return          time between 2 measurement samples in microseconds
 *                  0 in case of error
 * @param[in]       bdbpm_r: power rail device structure
 */
uint32_t bdbpm_get_sampling_time(bdbpm_rail *bdbpm_r)
{
    if (!bdbpm_r) {
        dbg_error("%s(): invalid bdbpm_r!\n", __func__);
        return 0;
    }

    return ina230_get_sampling_time(bdbpm_r->ina230_dev->ct,
                                    bdbpm_r->ina230_dev->count,
                                    ina230_shunt_bus_cont);
}