xref: /spdk/test/scheduler/rdmsr.pl (revision 588dfe314bb83d86effdf67ec42837b11c2620bf)
1#!/usr/bin/env perl
2#  SPDX-License-Identifier: BSD-3-Clause
3#  Copyright (C) 2020 Intel Corporation.
4#  All rights reserved.
5
6
7use strict;
8use warnings;
9
10use constant SEEK_CUR => 1;
11
12( @ARGV == 2 ) || exit(1);
13
14my $cpu_path = sprintf( "/dev/cpu/%u/msr", shift() );
15my $msr      = hex( shift() );
16my $reg_size = 8;
17my ( @msr, $msr_buf, $reg );
18
19unless ( -e $cpu_path ) {
20    printf STDERR "$cpu_path doesn't exist\n";
21    exit(1);
22}
23
24open( MSR, "<", $cpu_path );
25sysseek( MSR, $msr, SEEK_CUR );
26sysread( MSR, $msr_buf, $reg_size );
27@msr = unpack( "C*", $msr_buf );
28
29unless ( @msr == $reg_size ) {
30    printf STDERR "Failed to read $cpu_path\n";
31    exit(1);
32}
33
34for ( my $byte = @msr - 1 ; $byte >= 0 ; $byte-- ) {
35    $reg |= $msr[$byte] << ( $byte * 8 );
36}
37
38printf( "0x%x\n", $reg );
39