VoodooTSCSync

VoodooTSCSync Svn Source Tree

Root/VoodooTSCSync.cpp

Source at commit HEAD created 5 years 9 months ago.
By cosmo1t, moved from googlecode to here
1#include "VoodooTSCSync.h"
2
3// Define my superclass
4
5#define super IOService
6
7OSDefineMetaClassAndStructors(org_voodoo_driver_VoodooTSCSync, IOService)
8
9//stamp the tsc
10extern "C" void stamp_tsc(void *tscp) {
11//IOLockLock(lock);
12//countCalled++;
13//IOLockUnlock(lock);
14wrmsr64(MSR_IA32_TSC,*(uint64_t*)tscp);
15}
16
17
18bool org_voodoo_driver_VoodooTSCSync::init(OSDictionary *dictionary){
19if (!super::init(dictionary)){ return false; }
20
21//lock = IOLockAlloc();
22//if (lock == 0){
23//IOLog("Failed to alloc lock");
24//return false;
25//}
26
27return true;
28}
29
30static IOPMPowerState powerStates[2] = {
31 {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
32 {1, kIOPMPowerOn, kIOPMPowerOn, kIOPMPowerOn, 0, 0, 0, 0, 0, 0, 0, 0}
33};
34
35IOReturn org_voodoo_driver_VoodooTSCSync::setPowerState(unsigned long powerStateOrdinal, IOService *whatDevice ) {
36 if (powerStateOrdinal)
37 this->doTSC();
38 return IOPMAckImplied;
39}
40
41void org_voodoo_driver_VoodooTSCSync::stop(IOService *provider)
42{
43 PMstop();
44 super::stop(provider);
45}
46
47
48bool org_voodoo_driver_VoodooTSCSync::start(IOService *provider)
49
50{
51if (!super::start(provider)){ return false; }
52//countCalled = 0;
53 PMinit();
54 registerPowerDriver(this, powerStates, 2);
55 provider->joinPMtree(this);
56return true;
57
58}
59
60
61/*
62 Update MSR on all processors.
63 */
64void org_voodoo_driver_VoodooTSCSync::doTSC(){
65
66
67uint64_t tsc = rdtsc64();
68IOLog("Current tsc from rdtsc64() is %lld. Rendezvouing..\n",tsc);
69
70//now call the kernel function that will call this "action" on all cores/processors
71mp_rendezvous_no_intrs(stamp_tsc, (void*)&tsc);
72
73//IOLog("VoodooTSCSyn::doTsc(): stamp_tsc was called: %d times\n",countCalled);
74//countCalled=0;
75}
76

Archive Download this file

Revision: HEAD