Ejemplo n.º 1
0
/*  inbyte
 *
 *  This routine reads a character from the SOURCE.
 */
static char inbyte( void )
{
  char buf[10];

  /*
   *  If polling, wait until a character is available.
   */

  mon_read(0, buf, 1);    /* stdin is fd=0, read 1 byte */

  return (buf[0]);
}
Ejemplo n.º 2
0
/**
 * @brief Reads monitoring event data from given core
 *
 * @param p pointer to monitoring structure
 *
 * @return Operation status
 * @retval PQOS_RETVAL_OK on success
 */
static int
pqos_core_poll(struct pqos_mon_data *p)
{
    struct pqos_event_values *pv = &p->values;
    int retval = PQOS_RETVAL_OK;
    unsigned i;

    if (p->event & PQOS_MON_EVENT_L3_OCCUP) {
        uint64_t total = 0;

        for (i = 0; i < p->num_poll_ctx; i++) {
            uint64_t tmp = 0;
            int ret;

            ret = mon_read(p->poll_ctx[i].lcore,
                           p->poll_ctx[i].rmid,
                           get_event_id(PQOS_MON_EVENT_L3_OCCUP),
                           &tmp);
            if (ret != PQOS_RETVAL_OK) {
                retval = PQOS_RETVAL_ERROR;
                goto pqos_core_poll__exit;
            }
            total += tmp;
        }
        pv->llc = total;
    }
    if (p->event & (PQOS_MON_EVENT_LMEM_BW | PQOS_MON_EVENT_RMEM_BW)) {
        uint64_t total = 0, old_value = pv->mbm_local;

        for (i = 0; i < p->num_poll_ctx; i++) {
            uint64_t tmp = 0;
            int ret;

            ret = mon_read(p->poll_ctx[i].lcore,
                           p->poll_ctx[i].rmid,
                           get_event_id(PQOS_MON_EVENT_LMEM_BW),
                           &tmp);
            if (ret != PQOS_RETVAL_OK) {
                retval = PQOS_RETVAL_ERROR;
                goto pqos_core_poll__exit;
            }
            total += tmp;
        }
        pv->mbm_local = total;
        pv->mbm_local_delta = get_delta(old_value, pv->mbm_local);
    }
    if (p->event & (PQOS_MON_EVENT_TMEM_BW | PQOS_MON_EVENT_RMEM_BW)) {
        uint64_t total = 0, old_value = pv->mbm_total;

        for (i = 0; i < p->num_poll_ctx; i++) {
            uint64_t tmp = 0;
            int ret;

            ret = mon_read(p->poll_ctx[i].lcore,
                           p->poll_ctx[i].rmid,
                           get_event_id(PQOS_MON_EVENT_TMEM_BW),
                           &tmp);
            if (ret != PQOS_RETVAL_OK) {
                retval = PQOS_RETVAL_ERROR;
                goto pqos_core_poll__exit;
            }
            total += tmp;
        }
        pv->mbm_total = total;
        pv->mbm_total_delta = get_delta(old_value, pv->mbm_total);
    }
    if (p->event & PQOS_MON_EVENT_RMEM_BW) {
        pv->mbm_remote = 0;
        if (pv->mbm_total > pv->mbm_local)
            pv->mbm_remote = pv->mbm_total - pv->mbm_local;
        pv->mbm_remote_delta = 0;
        if (pv->mbm_total_delta > pv->mbm_local_delta)
            pv->mbm_remote_delta =
                pv->mbm_total_delta - pv->mbm_local_delta;
    }
    if (p->event & PQOS_PERF_EVENT_IPC) {
        /**
         * If multiple cores monitored in one group
         * then we have to accumulate the values in the group.
         */
        uint64_t unhalted = 0, retired = 0;
        unsigned n;

        for (n = 0; n < p->num_cores; n++) {
            uint64_t tmp = 0;
            int ret = msr_read(p->cores[n],
                               IA32_MSR_INST_RETIRED_ANY, &tmp);
            if (ret != MACHINE_RETVAL_OK) {
                retval = PQOS_RETVAL_ERROR;
                goto pqos_core_poll__exit;
            }
            retired += tmp;

            ret = msr_read(p->cores[n],
                           IA32_MSR_CPU_UNHALTED_THREAD, &tmp);
            if (ret != MACHINE_RETVAL_OK) {
                retval = PQOS_RETVAL_ERROR;
                goto pqos_core_poll__exit;
            }
            unhalted += tmp;
        }

        pv->ipc_unhalted_delta = unhalted - pv->ipc_unhalted;
        pv->ipc_retired_delta = retired - pv->ipc_retired;
        pv->ipc_unhalted = unhalted;
        pv->ipc_retired = retired;
        if (pv->ipc_unhalted_delta == 0)
            pv->ipc = 0.0;
        else
            pv->ipc = (double) pv->ipc_retired_delta /
                      (double) pv->ipc_unhalted_delta;
    }
    if (p->event & PQOS_PERF_EVENT_LLC_MISS) {
        /**
         * If multiple cores monitored in one group
         * then we have to accumulate the values in the group.
         */
        uint64_t missed = 0;
        unsigned n;

        for (n = 0; n < p->num_cores; n++) {
            uint64_t tmp = 0;
            int ret = msr_read(p->cores[n],
                               IA32_MSR_PMC0, &tmp);
            if (ret != MACHINE_RETVAL_OK) {
                retval = PQOS_RETVAL_ERROR;
                goto pqos_core_poll__exit;
            }
            missed += tmp;
        }

        pv->llc_misses_delta = missed - pv->llc_misses;
        pv->llc_misses = missed;
    }

pqos_core_poll__exit:
    return retval;
}