Beispiel #1
0
int read_msr_by_coord(unsigned socket, unsigned core, unsigned thread, off_t msr, uint64_t *val)
{
    static uint64_t coresPerSocket = 0;
    static uint64_t threadsPerCore = 0;

#ifdef LIBMSR_DEBUG
    fprintf(stderr, "%s %s %s::%d (read_msr_by_coord) socket=%d core=%d thread=%d msr=%lu (0x%lx)\n", getenv("HOSTNAME"), LIBMSR_DEBUG_TAG, __FILE__, __LINE__, socket, core, thread, msr, msr);
#endif
    sockets_assert(&socket, __LINE__, __FILE__);
    cores_assert(&core, __LINE__, __FILE__);
    threads_assert(&thread, __LINE__, __FILE__);
    if (val == NULL)
    {
        libmsr_error_handler("read_msr_by_coord(): Received NULL pointer", LIBMSR_ERROR_MSR_READ, getenv("HOSTNAME"), __FILE__, __LINE__);
    }
    if (coresPerSocket == 0 || threadsPerCore == 0)
    {
        core_config(&coresPerSocket, &threadsPerCore, NULL, NULL);
    }
    return read_msr_by_idx(devidx(socket, core, thread), msr, val);
}
Beispiel #2
0
/// @brief Default to pread/pwrite if msr_batch driver does not exist.
///
/// @param [in] batchnum libmsr_data_type_e data type of batch operation.
///
/// @param [in] type libmsr_batch_op_type_e type of batch operation.
///
/// @return 0 if successful, else -1 if batch_storage() fails.
static int compatibility_batch(int batchnum, int type)
{
    struct msr_batch_array *batch = NULL;
    int i;

    fprintf(stderr, "Warning: <libmsr> No /dev/cpu/msr_batch, using compatibility batch: compatibility_batch(): %s: %s:%s::%d\n", strerror(errno), getenv("HOSTNAME"), __FILE__, __LINE__);
    if (batch_storage(&batch, batchnum, NULL))
    {
        return -1;
    }
    for (i = 0; i < batch->numops; i++)
    {
        if (type == BATCH_READ)
        {
            read_msr_by_idx(batch->ops[i].cpu, batch->ops[i].msr, (uint64_t *) &batch->ops[i].msrdata);
        }
        else
        {
            write_msr_by_idx(batch->ops[i].cpu, batch->ops[i].msr, (uint64_t)batch->ops[i].msrdata);
        }
    }
    return 0;
}
Beispiel #3
0
int main(int argc, char ** argv)
{
    short israpl = 0;
    char next = '\0';
    ISVERBOSE = 0;
    init_msr();
    uint64_t msr_data;
    uint64_t msr;
    unsigned thread;
    int i;
    for (i = 0; i < argc; i++)
    {
        if (argv[i][0] == '-')
        {
            switch(argv[i][1])
            {
                case 'v':
                    // do verbose stuff
                    ISVERBOSE = 1;
                    break;
                case 'r':
                    // read an msr
                    if (argc - i < 3)
                    {
                        fprintf(stderr, "Error: not enough parameters to read flag\n");
                        generic_error(i, argv);
                    }
                    thread = atoi(argv[++i]);
                    msr = strtol(argv[++i], NULL, 16);
                    read_msr_by_idx(thread, msr, &msr_data);
                    fprintf(stdout, "%lx\n", msr_data);
                    break;
                case 'w':
                    // write an msr
                    if (argc - i < 4)
                    {
                        fprintf(stderr, "Error: not enough parameters to write flag\n");
                        generic_error(i, argv);
                    }
                    thread = atoi(argv[++i]);
                    msr = strtol(argv[++i], NULL, 16);
                    msr_data = strtol(argv[++i], NULL, 16);
                    write_msr_by_idx(thread, msr, msr_data);
                    break;
                case 'i':
                    // do interactive stuff
                    fprintf(stdout, "Interactive mode is not yet available\n");
                    break;
                case '-':
                    // go deeper down the rabbit hole
                    switch(argv[i][2])
                    {
                        case 'h':
                            // print help stuff
                            help_stuff();
                            break;
                    }
                    return 0;
                case 'p':
                    // print out stuff
                    printing_functions(&i, argc, argv);
                    break;
                case 's':
                    // set a socket limit or set to default
                    set_functions(&i, argc, argv);
                    break;
                case 'l':
                    // list available events
                    list_functions(&i, argc, argv);
                    
                    return 0;
            }
        }
    }
 //   if (israpl)
 //   {
//        do_rapl_stuff(isverbose);
 //   }
    return 0;
}