Software Tuning, Performance Optimization & Platform Monitoring
Discussion regarding monitoring and software tuning methodologies, Performance Monitoring Unit (PMU) of Intel microprocessors, and platform updating.

How can I compile the MSR driver?

Antonio_v_
Beginner
4,685 Views

Hi all,

I'm just staritng using PCM on Windows 7. I was reading the WINDOWS_HOWTO.rtf file included in the library. I know that I have to compile and sign the driver, but I dont know how I have to do it. The only thing that i know I should use the DDK software from Microsoft. And I was looking for this software but I couldn´t find it, anyway I found another one called WDK.

So If you know how should I compile this driver, please give some tips.

Thanks in advance.

0 Kudos
26 Replies
Bernard
Valued Contributor I
4,117 Views

Antonio v. wrote:

Hi all,

I'm just staritng using PCM on Windows 7. I was reading the WINDOWS_HOWTO.rtf file included in the library. I know that I have to compile and sign the driver, but I dont know how I have to do it. The only thing that i know I should use the DDK software from Microsoft. And I was looking for this software but I couldn´t find it, anyway I found another one called WDK.

So If you know how should I compile this driver, please give some tips.

Thanks in advance.

DDK now is called WDK.Please download and install this package.Unfortunetly you will not be given nice IDE like VS2010  and you will be forced to use command prompt build utility.Starting from VS2012 there is full integration of driver development with the VS2012 IDE.Even IntelliSense has been given the ability to auto complete kernel mode functions.Navigate from the WDK free or checked build command prompt environment to the directory where is PCM driver and issue this command "build -Zz" (without quotes) if everything is successful in your directory .sys file will be created.

0 Kudos
Antonio_v_
Beginner
4,117 Views

Hi Iliapolak,

I have installed "Microsoft Visual Studio Ultimate 2012", later I have installed WDK 8. Then I tried to execute the "build-Zz" command in the WINMSRDriver folder, and I'm getting an error message with "unrecognized build command".  Am I missing any additional step?

Thanks.

0 Kudos
Bernard
Valued Contributor I
4,117 Views

Antonio v. wrote:

Hi Iliapolak,

I have installed "Microsoft Visual Studio Ultimate 2012", later I have installed WDK 8. Then I tried to execute the "build-Zz" command in the WINMSRDriver folder, and I'm getting an error message with "unrecognized build command".  Am I missing any additional step?

Thanks.

Hi Antonio!

My advise was related to command line build utility which is part of WDK 7.I have never done any driver programming with the newest IDE environment like VS2012 and WDK 8.Build utility used for previous releases of WDK prior to WDK 8 is not supported when building drivers with VS2012.There is new tool named MSBuild.I'm posting below a detailed link on how to build the drivers in VS2012.

msdn.microsoft.com/en-us/library/windows/hardware/ff554644(v=vs.85).aspx

0 Kudos
Antonio_v_
Beginner
4,117 Views

Hi Iliapolak,

I just want to compile the driver in the easyest way. So I'm going to install the WDK 7 and I will try to compile it in the same way as you did. So Once I have the WDK 7 installed, Will I be able to execute the "build -Zz" command in the CMD? or should I do any other intermediate action?

Thanks again.

0 Kudos
Bernard
Valued Contributor I
4,117 Views

Antonio v. wrote:

Hi Iliapolak,

I just want to compile the driver in the easyest way. So I'm going to install the WDK 7 and I will try to compile it in the same way as you did. So Once I have the WDK 7 installed, Will I be able to execute the "build -Zz" command in the CMD? or should I do any other intermediate action?

Thanks again.

You should check if two files exist in your build directory.Those files are named sources and makefile.Simply navigate to your build directory from the WDK 7 command prompt and issue this command build -Zz if two compilation was completed with the errors you should have sys file(your driver).

0 Kudos
Antonio_v_
Beginner
4,117 Views

Hi Iliapolak,

Following your advices, I have installed WDK 7, then I executed as an Administrator "Win 7 IA- 64 checked Build Environment". Later I navigated to my build folder and execute the following:

C:\intelperformancecountermonitor-v2.35\WinMSRDriver\Win7>build -Zz

path contains nonexistant c:\program files (x86)\intel\opencl sdk\2.0\bin\x86, removing

path contains nonexistant c:\program files (x86)\intel\opencl sdk\2.0\bin\x64, removing

BUILD: Compile and Link for IA64 BUILD: Start time: Sun Feb 24 18:54:14 2013

BUILD: Examining c:\intelperformancecountermonitor-v2.35\winmsrdriver\win7 direc tory for files to compile. BUILD: Compiling and Linking c:\intelperformancecountermonitor-v2.35\winmsrdrive r\win7 directory Precompiling - msr.h Compiling - msrmain.c 1>errors in directory c:\intelperformancecountermonitor-v2.35\winmsrdriver\win7 1>

c:\intelperformancecountermonitor-v2.35\winmsrdriver\win7\msrmain.c(179) : error C4013: '__writemsr' undefined; assuming extern returning int 1>c:\intelperformancecountermonitor-v2.35\winmsrdriver\win7\msrmain.c(199) : err or C4013: '__readmsr' undefined; assuming extern returning int

Linking Executable - objchk_win7_ia64\ia64\msr.sys 1>link : error LNK1181: cannot open input file 'c:\intelperformancecountermonito r- 2.35\winmsrdriver\win7\objchk_win7_ia64\ia64\msrmain.obj'

BUILD: Finish time: Sun Feb 24 18:54:15 2013 BUILD: Done 5 files compiled - 2 Warnings - 2 Errors 1 executable built - 1 Error

Do you know how can I solve this building errors?, I think It should work without making any changes, so maybe I have to use another parameters.

PS: Additionaly I have created two Env Variable: (DDK_LIB_PATH and DDK_INC_PATH)

Kind Regards.

0 Kudos
Patrick_F_Intel1
Employee
4,117 Views

Hello Antonio,

Before going to the trouble of building the driver, you might want think about 'signing' the driver.

Only signed drivers can be used on 64bit Windows (except in Test mode). To sign the driver you need certificates from a signing authority. Usually (always?) these certificates cost money. If you are not going to sign your driver, you might consider using the WinRing0 driver on Windows. PCM has options to use this driver instead.

Pat

0 Kudos
Antonio_v_
Beginner
4,117 Views

Hello Patrick,

What is it about 32 bits? Should I need to sign it too? If yes, Does it cost money?, Because I just want to test PCM, and I don't have too much budget ;).

Thanks for the input!

0 Kudos
Bernard
Valued Contributor I
4,117 Views

Those dreaded compiler errors:)

Did you add all header files?Particulary those which define __writemsr and __readmsr functions?Do you have a sys file in the build directory?Please read header file and source of the driver in order to check declarations for the two functions mentioned above.Those functions must be declared(prototype) before their first usage.

0 Kudos
Antonio_v_
Beginner
4,117 Views

hi iliyapolak,

No, I haven't added any extra header files, I supposed that everything is well suited. In order to get the driver (msr.sys). I don't have any .sys file because the building proccess is breaking. I'm going to check this files but they should be defined!, if not where could I get the correct headers?

0 Kudos
Bernard
Valued Contributor I
4,117 Views

__writemsr and __readmsr functions should be defined in one of the header file(s).Please search through those files for the functions declarations.Those functions are crucial because they are used to write to and read from MSR registers.

0 Kudos
Bernard
Valued Contributor I
4,117 Views

@Antonio

Do you have any updates?

0 Kudos
Antonio_v_
Beginner
4,117 Views

Hi Ilyapolak,

In order to make clear what are my impediments and the issues which are struggling me, I'm going to describe the following scenario:

I'm running on a Windows 7 (64 bits), the proccessor is an IvyBridge I5-3450. So I want to analyse the power consumption when I execute some codes.
For this reason, I have downloaded PCM version 2.35, then I saw that I need to compile the required WinMSRDriver and get the msr.sys file.

I did the next steps in order to compile the driver:

Download and install WDK 8 package(previously called DDK). This new version is able to make drivers for windows 8. Microsoft's developers have changed the way this package works. So now, this tool works as a plugin for VisualStudio. I wanted to compile the driver as it was specified in the included Windows_How_To tutorial  in PCM, so I downloaded the previous WDK 7 version which let me cimpile the driver in the old way.

After I have installed WDK7, I got the following items in the start menu:

Windows Driver Kits
    WDK 7600.16386.1
        Build Environments
            Windows 7
                IA64 Checked Build Environment
                IA64 Free Build Environment
                x64 Checked Build Environment
                x64 Free Build Environment
                x86 Checked Build Environment
                x86 Free Build Environment
            Win XP
                x86 Free Build Environment
                x86 Checked Build Environment

Each of this Build Environments is a CMD console with some additional functions which let us to compile drivers.

Once The WDK 7 was installed, I try to compile the driver in every single Build Environment. To do that, I navigated to the build folder in each of them, an then I executed:
    build -Zz
    
I only got the compiled driver mrs.sys in the following envs:

Win XP
    x86 Free Build Environment
    x86 Checked Build Environment

Windows 7
    x64 Free Build Environment
    x86 Free Build Environment
    
Now, my questions are:

Can I use the PCM package for the IvyBridge 3450 processor with the drivers that I got under Win 7? Or Do I need the others?
Will I need to sign this drivers to make them able for execution?

Thanks in advance,

0 Kudos
Antonio_v_
Beginner
4,117 Views

Hi iliapolak,

I sent a previous post with a summary of my compiling drivers steps, but this post is pending for approval.Finally, I could compile the driver. to do that I have used WDK 7 package. Right now, I'm trying to sigh the msr.sys files, after being in google for a while, I found the next page: http://www.rage3d.com/board/showthread.php?t=33920573.

I did the following steps:

makecert.exe -$ individual  -r -pe -ss "SomeName Certificate Store" -n CN="SomeName Certificate" "SomeName Certificate.cer"
certmgr.exe /add "SomeName Certificate.cer" /s /r localMachine root
signtool.exe sign /v /s "SomeName Certificate Store" /n "SomeName Certificate" msr.sys
signtool.exe verify /pa /v msr.sys

bcdedit.exe /set TESTSIGNING ON  (Putting the machine in testing mode, just to be able to run the certificated msr.sys file)

Then reeboting the machine. But when I try to execute PCM I got the next message:

Num (logical) cores: 4
Num sockets: 1
Threads per core: 1
Core PMU (perfmon) version: 3
Number of core PMU generic (programmable) counters: 8
Width of generic (programmable) counters: 48 bits
Number of core PMU fixed counters: 3
Width of fixed counters: 48 bits
Can not access CPUs Model Specific Registers (MSRs).
You must have signed msr.sys driver in your current directory and have administrator rights to run this program.

Does anyone know if the certification process is well done? or should I use othre commands?

Thanks in advance,

0 Kudos
Bernard
Valued Contributor I
4,117 Views

>>>Can I use the PCM package for the IvyBridge 3450 processor with the drivers that I got under Win 7? Or Do I need the others? Will I need to sign this drivers to make them able for execution>>>

Your CPU is supported by PCM package.Regarding signing the driver I tell you truth I have never writen any driver for 64-bit Windows and never tried to install one.In order to disable driver signing at the boot time press F8 and disable driver signing functionality.IIRC you will some watermark on the desktop and some DRM relatede features will be disabled.It is not clear to me how to proceed with the driver signing proceddure.I suppose that you must pay for the certificate issueing authority.Here is official Microsoft link :http://msdn.microsoft.com/en-us/library/ms537361(VS.85).aspx

Here is the info on how to disable driver signing check :http://superuser.com/questions/124112/use-an-unsigned-driver-in-windows-7-x64

0 Kudos
Bernard
Valued Contributor I
4,117 Views

>>>Does anyone know if the certification process is well done? or should I use othre commands?>>>

Plesase try what I advised you in my previous post.If you are interested there are more procedures to disable driver signinig check.I'm posting a few links with the methods which describe how to load unsigned drivers.Please let me know if this helps.

http://www.ngohq.com/?page=dseo

http://social.technet.microsoft.com/Forums/en-US/w7itprohardware/thread/9b6eee60-855d-47cc-9927-acae3fb6f971

0 Kudos
Antonio_v_
Beginner
4,117 Views

Hi ilyapolak,

I`m trying to do what you have suggested me in the previous post, I will let you know what are my improvements. Anyway, I saw in a earlier post, there is some kind of drivers which are already built. Do you know where can I download them?, I was checking the included How_TO_ windows doc  in the PCM package, and the links don't work anymore. So Does anyone know if the msr.sys file is prebuilt in any other library? 

Thanks in advance, 

0 Kudos
Bernard
Valued Contributor I
4,117 Views

 >>>Anyway, I saw in a earlier post, there is some kind of drivers which are already built. Do you know where can I download them?,>>>

I suppose that you need to build everything in the PCM directory.I have never used nor built PCM package so I can only help you on generic question related to driver compilation and signing.By inspecting PCM directory it is clear that you need to build msr.sys.

0 Kudos
Antonio_v_
Beginner
4,117 Views

Hi Ilyapolak,

Finally, I have signed the driver (msr.sys), I just wanted to say thanks, due to all your support. I will describe what I did, so maybe other people can find this information useful. Once I compiled the driver:

First, To open the amd64 build console in Administrator mode, and execute the followings commands:

c:\>makecert.exe -$ individual -r -pe -ss "Caveman Certificate Store" -n CN="Caveman Certificate" "Caveman Certificate.cer"

c:\>certmgr.exe /add "Caveman Certificate.cer" /s /r localMachine root

c:\> signtool.exe sign /v /s "Caveman Certificate Store" /n "Caveman Certificate" msr.sys

c:\> signtool.exe verify /pa /v msr.sys

Then put the system in test mode:

c:\> bcdedit.exe verify /set TESTSIGNING ON

And restart the machine, Now you can execute PCM if you put the driver in the pcm.exe's folder.

And run the pcm.exe in administrator mode. 

I hope this post will help people.

See you,

0 Kudos
Bernard
Valued Contributor I
3,498 Views

Hi Antonio,

glad to hear that you were able to sign the driver.Have you proceeded accordingly to the last two links from my previous post?

Afaik you can disable driver signing at boot time.

0 Kudos
Reply