Anonymous avatar Anonymous committed c5bfa82

First working auto-throttle. Needs code-cleanup.

Comments (0)

Files changed (7)

+
+ /*
+ * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
+ * 
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. The rights granted to you under the License
+ * may not be used to create, or enable the creation or redistribution of,
+ * unlawful or unlicensed copies of an Apple operating system, or to
+ * circumvent, violate, or enable the circumvention or violation of, any
+ * terms of an Apple operating system software license agreement.
+ * 
+ * Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
+ * 
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ * 
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
+ */
+/*
+ * Copyright (c) 1999 Apple Computer, Inc.  All rights reserved.
+ *
+ *  DRI: Josh de Cesare
+ *
+ */
+
+#ifndef _IOKIT_CPU_H
+#define _IOKIT_CPU_H
+
+extern "C" {
+#include <machine/machine_routines.h>
+#include <pexpert/pexpert.h>
+}
+
+#include <IOKit/IOService.h>
+#include <IOKit/IOInterruptController.h>
+
+enum {
+	kIOCPUStateUnregistered = 0,
+	kIOCPUStateUninitalized,
+	kIOCPUStateStopped,
+	kIOCPUStateRunning,
+	kIOCPUStateCount
+};
+
+class IOCPUInterruptController;
+
+extern IOCPUInterruptController *gIOCPUInterruptController;
+
+class IOCPU : public IOService
+	{
+		OSDeclareAbstractStructors(IOCPU);
+		
+	private:
+		OSArray                *_cpuGroup;
+		UInt32                 _cpuNumber;
+		UInt32                 _cpuState;
+		
+	protected:
+		IOService              *cpuNub;
+		processor_t            machProcessor;
+		ipi_handler_t          ipi_handler;
+		
+		struct ExpansionData { };
+		ExpansionData *reserved;
+		
+		virtual void           setCPUNumber(UInt32 cpuNumber);
+		virtual void           setCPUState(UInt32 cpuState);
+		
+	public:
+		static  void           initCPUs(void);
+		
+		virtual bool           start(IOService *provider);
+		virtual OSObject       *getProperty(const OSSymbol *aKey) const;
+		virtual bool           setProperty(const OSSymbol *aKey, OSObject *anObject);
+		virtual bool           serializeProperties(OSSerialize *serialize) const;
+		virtual IOReturn       setProperties(OSObject *properties);
+		virtual void           initCPU(bool boot) = 0;
+		virtual void           quiesceCPU(void) = 0;
+		virtual kern_return_t  startCPU(vm_offset_t start_paddr,
+						vm_offset_t arg_paddr) = 0;
+		virtual void           haltCPU(void) = 0;
+		virtual void           signalCPU(IOCPU *target);
+		virtual void           enableCPUTimeBase(bool enable);
+		
+		virtual UInt32         getCPUNumber(void);
+		virtual UInt32         getCPUState(void);
+		virtual OSArray        *getCPUGroup(void);
+		virtual UInt32         getCPUGroupSize(void);
+		virtual processor_t    getMachProcessor(void);
+		
+		virtual const OSSymbol *getCPUName(void) = 0;
+		
+		OSMetaClassDeclareReservedUnused(IOCPU, 0);
+		OSMetaClassDeclareReservedUnused(IOCPU, 1);
+		OSMetaClassDeclareReservedUnused(IOCPU, 2);
+		OSMetaClassDeclareReservedUnused(IOCPU, 3);
+		OSMetaClassDeclareReservedUnused(IOCPU, 4);
+		OSMetaClassDeclareReservedUnused(IOCPU, 5);
+		OSMetaClassDeclareReservedUnused(IOCPU, 6);
+		OSMetaClassDeclareReservedUnused(IOCPU, 7);
+	};
+
+void IOCPUSleepKernel(void);
+extern "C" kern_return_t IOCPURunPlatformQuiesceActions(void);
+extern "C" kern_return_t IOCPURunPlatformActiveActions(void);
+
+class IOCPUInterruptController : public IOInterruptController
+	{
+		OSDeclareDefaultStructors(IOCPUInterruptController);
+		
+	private:
+		int   enabledCPUs;
+		
+	protected:  
+		int   numCPUs;
+		IOCPU **cpus;
+		
+		struct ExpansionData { };
+		ExpansionData *reserved;
+		
+	public:
+		virtual IOReturn initCPUInterruptController(int sources);
+		virtual void     registerCPUInterruptController(void);
+		virtual void     setCPUInterruptProperties(IOService *service);
+		virtual void     enableCPUInterrupt(IOCPU *cpu);
+		
+		virtual IOReturn registerInterrupt(IOService *nub, int source,
+						   void *target,
+						   IOInterruptHandler handler,
+						   void *refCon);
+		
+		virtual IOReturn getInterruptType(IOService *nub, int source,
+						  int *interruptType);
+		
+		virtual IOReturn enableInterrupt(IOService *nub, int source);
+		virtual IOReturn disableInterrupt(IOService *nub, int source);
+		virtual IOReturn causeInterrupt(IOService *nub, int source);
+		
+		virtual IOReturn handleInterrupt(void *refCon, IOService *nub,
+						 int source);
+		
+		OSMetaClassDeclareReservedUnused(IOCPUInterruptController, 0);
+		OSMetaClassDeclareReservedUnused(IOCPUInterruptController, 1);
+		OSMetaClassDeclareReservedUnused(IOCPUInterruptController, 2);
+		OSMetaClassDeclareReservedUnused(IOCPUInterruptController, 3);
+		OSMetaClassDeclareReservedUnused(IOCPUInterruptController, 4);
+		OSMetaClassDeclareReservedUnused(IOCPUInterruptController, 5);
+	};
+
+#endif /* ! _IOKIT_CPU_H */

Source/Info.plist

 			<key>KernelFeatures</key>
 			<integer>-1</integer>
 			<key>DefaultPState</key>
-			<integer>-1</integer>
-			<key>PStateTableDisabled</key>
+			<integer>0</integer>
+			<key>PStateTable</key>
 			<array>
 				<array>
 					<integer>1733</integer>
 		<key>com.apple.kpi.libkern</key>
 		<string>8.4.1</string>
 	</dict>
+	<key>OSBundleRequired</key>
+	<string>Root</string>
 </dict>
 </plist>

Source/IntelEnhancedSpeedStep.cpp

 
 
 OSDefineMetaClassAndStructors(net_mercurysquad_driver_IntelEnhancedSpeedStep, IOService)
-
+OSDefineMetaClassAndStructors(AutoThrottler, OSObject)
 
 /**********************************************************************************/
 /* sysctl interface for compatibility with Niall Douglas' ACPICPUThrottle.kext    */
 		dbg("Supported Intel processor found on your system\n");
 		res = this;
 	} else {
-		warn("No Intel processor found! You have %s. Kext will not load\n", cpuid_info()->cpuid_vendor);
+		warn("No Intel processor found, or your processor does not support SpeedStep."
+		     "Kext will not load\n");
 		res = NULL;
 	}
 	
 	if (!isConstantTSC()) {
 		ConstantTSC = false;
 		if (RtcFixKernel)
-			info("Your processor doesn't support constant_tsc, but you have a kernel which can compensate for it.\n");
+			dbg("Your processor doesn't support constant_tsc, but you have a kernel which can compensate for it.\n");
 		else
-			warn("Your processor doesn't support constant_tsc and your kernel doesn't know how to compensate - Expect timing issues or switch to a kernel with RTC fix.\n");
+			warn("Your processor doesn't support constant_tsc and your kernel doesn't " 
+			     "know how to compensate - Expect timing issues or switch to a kernel with RTC fix.\n");
 	} else {
 		ConstantTSC = true;
 		Below1Ghz = true; // blindly, because we're not gonna recalibrate the clock so no fear of panic
 	
 	if (DefaultPState != -1 && DefaultPState < NumberOfPStates) // If a default Pstate was specified in info.plist
 	{
-		info("Throttling to default PState %d as specified in Info.plist\n", DefaultPState);
+		dbg("Throttling to default PState %d as specified in Info.plist\n", DefaultPState);
 		throttleAllCPUs(PStates[DefaultPState]); // then throttle to that value
 	}
 	
 	// Now turn on our auto-throttler
-	if (Throttler.setup(this) == false)
+	Throttler = new AutoThrottler;
+	if (Throttler) {
+		dbg("Throttler instantiated.\n");
+	}
+	else {
+		warn("Throttler could not be created\n");
+		return true;
+	}
+	if (Throttler->setup((OSObject*) Throttler) == false)
 		warn("Auto-throttler could not be setup\n");
 	else
-		Throttler.setEnabled(true);
+		Throttler->setEnabled(true);
 	
 	return true;
 }
 
 void net_mercurysquad_driver_IntelEnhancedSpeedStep::stop(IOService *provider) {
 	dbg("Shutting down\n");
-	
+	if (Throttler) Throttler->release();
 	sysctl_unregister_oid(&sysctl__kern_cputhrottle_curfreq); 
 	sysctl_unregister_oid(&sysctl__kern_cputhrottle_freqs);
 	sysctl_unregister_oid(&sysctl__kern_cputhrottle_curvolt);
 	uint8_t cpumodel = (cpuid_info()->cpuid_extmodel << 4) + cpuid_info()->cpuid_model;
 	Is45nmPenryn = (cpuid_info()->cpuid_family == 6) && (cpumodel >= 0x17);
 	if (Is45nmPenryn)
-		info("On your processor, voltages can be changed in 12.5 mV steps\n");
+		dbg("On your processor, voltages can be changed in 12.5 mV steps\n");
 	else
-		info("On your processor, voltages can be changed in 16 mV steps\n");
+		dbg("On your processor, voltages can be changed in 16 mV steps\n");
 }
 
 void checkForNby2Ratio() {
 	return realfid * (FSB / 1000000ULL);
 }
 
+static inline uint32_t FID_to_Hz(uint8_t x) {
+	bool nby2 = x & 0x80;
+	uint8_t realfid = x & 0x7f;
+	if (nby2)
+		realfid /= 2;
+	return realfid * FSB;
+}
+
 inline uint8_t MHz_to_FID(uint16_t x) {
 	uint8_t realfid = x / (FSB / 1000000ULL);
 	if (Nby2Ratio && x < 1000) // FIXME: use n/2 for only <1ghz frequencies?
 	/* Here we load the override pstate table from the given array */
 	NumberOfPStates = dict->getCount();
 	for (int i = 0; i < NumberOfPStates; i++) {
-		OSArray* onePstate			= (OSArray*) dict->getObject(i);
-		PStates[i].AcpiFreq			= ((OSNumber*) onePstate->getObject(0))->unsigned16BitValue();
+		OSArray* onePstate		= (OSArray*) dict->getObject(i);
+		PStates[i].AcpiFreq		= ((OSNumber*) onePstate->getObject(0))->unsigned16BitValue();
 		PStates[i].Frequency		= MHz_to_FID(PStates[i].AcpiFreq); // this accounts for N/2 automatically
 		PStates[i].OriginalVoltage	= mV_to_VID(((OSNumber*) onePstate->getObject(1))->unsigned16BitValue());
-		PStates[i].Voltage			= PStates[i].OriginalVoltage;
+		PStates[i].Voltage		= PStates[i].OriginalVoltage;
 		dbg("P-State %d: %d MHz at %d mV\n", i, PStates[i].AcpiFreq, VID_to_mV(PStates[i].OriginalVoltage));
 	}
 	info("Loaded %d PStates from Info.plist\n", NumberOfPStates);
 		return false;
 	}
 	
+	/* Get number of CPUs, used to calculate CPU load */
+	NumberOfProcessors = 1; // FIXME
+	
 	/* Get the first CPU - we assume all CPUs share the same P-State */
 	IOACPIPlatformDevice* cpu = (IOACPIPlatformDevice*) ioreg->getChildEntry(IORegistryEntry::getPlane("IODeviceTree"));
 	if (cpu == 0) {
 	
 	while (c < PSSArray->getCount()) {
 		onestate = ( OSArray* )(PSSArray->getObject(c));
-		ctl		 = ((OSNumber*) onestate->getObject(4))->unsigned32BitValue();
+		ctl      = ((OSNumber*) onestate->getObject(4))->unsigned32BitValue();
 		acpifreq = ((OSNumber*) onestate->getObject(0))->unsigned32BitValue();
 		power	 = ((OSNumber*) onestate->getObject(1))->unsigned32BitValue();
 		latency	 = ((OSNumber*) onestate->getObject(2))->unsigned32BitValue();
 			continue;
 		}
 		
-		PStates[i].AcpiFreq			= acpifreq; // cosmetic only
+		PStates[i].AcpiFreq		= acpifreq; // cosmetic only
 		PStates[i].Frequency		= FID(ctl); // if it's N/2 then this will be (x*2 | 80h) already.
 		PStates[i].OriginalVoltage	= VID(ctl);
-		PStates[i].Voltage			= PStates[i].OriginalVoltage; // initially same
-		PStates[i].Latency			= latency;
+		PStates[i].Voltage		= PStates[i].OriginalVoltage; // initially same
+		PStates[i].Latency		= latency;
 		
 		if (latency > MaxLatency) MaxLatency = latency; 
 		
 	IOSimpleLockLock(Lock);
 	
 	mp_rendezvous(disableInterrupts, throttleCPU, enableInterrupts, &p);
+	IODelay(p.Latency); // maybe wait longer?
 	
 	IOSimpleLockUnlock(Lock);
 	dbg("Throttle done.\n");
 	msr = rdmsr64(INTEL_MSR_PERF_STS); // read current MSR
 	
 	// For clock recalibration
-
-	oldfreq = ((FID(msr)&0x80)?(FID(msr)/2):(FID(msr))) * FSB;
+	oldfreq = FID_to_Hz(FID(msr));
 	msr = (msr & 0xffffffffffff0000ULL) | CTL(p.Frequency, p.Voltage); // blank out last 32 bits and put our ctl there
-	newfreq = ((FID(msr)&0x80)?(FID(msr)/2):(FID(msr))) * FSB; // after setting ctl in msr
+	newfreq = FID_to_Hz(FID(msr)); // after setting ctl in msr
+	
 	if (RtcFixKernel && !ConstantTSC) {
 		rtc_clock_stepping(newfreq, oldfreq);
 	}
 	
 	if (RtcFixKernel && !ConstantTSC)
 		rtc_clock_stepped(newfreq, oldfreq);
-	
-	IODelay(p.Latency); // maybe wait longer?
 }
 
 void disableInterrupts(__unused void *t) {
 	InterruptsEnabled = ml_set_interrupts_enabled(false);
 }
 
-void enableInterrupts(void *t) {
+void enableInterrupts(__unused void *t) {
 	ml_set_interrupts_enabled(InterruptsEnabled);
 }
 
 		int whetherOn;
 		err = SYSCTL_IN(req, &whetherOn, sizeof(int));
 		if (err) return err;
+		if (!Throttler) return kIOReturnError;
 		dbg("Setting autothrottle to %d\n", whetherOn);
-		Throttler.setEnabled(whetherOn != 0);
+		Throttler->setEnabled(whetherOn != 0);
 				
 	} else {
-		int sts = Throttler.getEnabled() ? 1 : 0;
+		if (!Throttler) return kIOReturnError;
+		int sts = Throttler->getEnabled() ? 1 : 0;
 		err = SYSCTL_OUT(req, &sts, sizeof(int));
 	}
 	return err;
 	perfTimer = IOTimerEventSource::timerEventSource(owner, (IOTimerEventSource::Action) &perfTimerWrapper);
 	if (perfTimer == 0) return false;
 	
+	/* from Superhai */
+	cpu_count = 0;
+	OSDictionary* service = IOService::serviceMatching("IOCPU");
+	if (!service) {
+		warn("IOKit CPUs not found. Auto-throttle may not work.\n");
+		return false;
+	}
+	
+	OSIterator* iterator = IOService::getMatchingServices(service);
+	
+	if (!iterator) {
+		warn("IOKit CPU iterator couldn't be created. Auto-throttle may not work.\n");
+		return false;
+	}
+
+	IOCPU * cpu;
+	while (cpu = OSDynamicCast(IOCPU, iterator->getNextObject()))
+	{
+		dbg("Got I/O Kit CPU %d (%d) named %s", cpu_count, cpu->getCPUNumber(), cpu->getCPUName()->getCStringNoCopy());
+		mach_cpu[cpu_count] = cpu->getMachProcessor();
+		if (cpu_count++ > max_cpus) break;
+	}
+	selfHost = host_priv_self();
 	if (workLoop->addEventSource(perfTimer) != kIOReturnSuccess) return false;
 	currentPState = NumberOfPStates - 1;
 	perfTimer->setTimeoutMS(1024);
 	// Settle time in case we were just stepping
 	IOSleep(1024);
 	if (workLoop) workLoop->removeEventSource(perfTimer);	// Remove our event sources
+	dbg("Autothrottler stopped.\n");
 	setupDone = false;
 }
 
 	return enabled;
 }
 
-AutoThrottler::~AutoThrottler() {
+void AutoThrottler::free() {
 	if (enabled) enabled = false;
 	if (setupDone) stop();
 	sysctl_unregister_oid(&sysctl__kern_cputhrottle_ctl);
 }
 
 
-static void GetCPUTicks(long* idle, long* total) {
-    host_cpu_load_info_data_t loadinfo;
+void AutoThrottler::GetCPUTicks(long* idle, long* total) {
+	mach_msg_type_number_t cpu_count_type;
+	unsigned int cpu_maxload = 0;
+	/* Superhai method */
+	unsigned int temp_ticks = 0;
+	for (int i = 0; i < cpu_count; i++)
+	{
+		cpu_count_type = PROCESSOR_CPU_LOAD_INFO_COUNT;
+		total_ticks[i] = 0;
+		kern_return_t kret = processor_info(mach_cpu[i], PROCESSOR_CPU_LOAD_INFO, &selfHost, (processor_info_t) &cpu_load[i], &cpu_count_type);
+		if (kret == KERN_SUCCESS)
+		{
+			cpu_load_temp[i] = cpu_load[i];
+			for (int t = 0; t < CPU_STATE_MAX; t++)
+			{
+				(cpu_load_temp[i].cpu_ticks[t]) -= (cpu_load_last[i].cpu_ticks[t]);
+				total_ticks[i] += (cpu_load_temp[i].cpu_ticks[t]);
+			}
+			load_ticks[i] = total_ticks[i] - cpu_load_temp[i].cpu_ticks[CPU_STATE_IDLE];
+			if ((load_ticks[i]) > temp_ticks)
+			{
+				temp_ticks = load_ticks[i];
+				cpu_maxload = i;
+			}
+			cpu_load_last[i] = cpu_load[i];
+		}
+		else
+		{
+			dbg("Error when reading cpu load on cpu %d (%x)", i, kret);
+		}
+	}
+	
+	*total = (total_ticks[cpu_maxload] + 1);
+	*idle  = (*total - load_ticks[cpu_maxload] + 1);
+	
+	dbg("Autothrottle: CPU load %d /10 pc\n", (1000 * (*idle - *total)) / *total);
+/*
+ Original method
+	host_cpu_load_info_data_t loadinfo;
 	static long idle_old, total_old;
 	long total_new;
 	mach_msg_type_number_t count;
 	
 	idle_old = loadinfo.cpu_ticks[CPU_STATE_IDLE];
 	total_old = total_new;
+*/
 }
 
 

Source/IntelEnhancedSpeedStep.h

 #include <IOKit/IOService.h>
 #include <IOKit/acpi/IOACPIPlatformDevice.h>
 #include <IOKit/IORegistryEntry.h>
+#include <IOKit/IODeviceTreeSupport.h>
 #include <IOKit/IOWorkLoop.h>
 #include <IOKit/IOTimerEventSource.h>
 #include <IOKit/IOLib.h>
+#include "IOCPU.h" // This is not in Kernel IOKit framework, so have to redefine.
 
 #include <i386/proc_reg.h>
 #include <i386/cpuid.h>
 #include <sys/sysctl.h>
 #include <sys/types.h>
 
+#include <kern/host.h>
+
 #include <mach/mach_interface.h>
 #include <mach/mach_vm.h>
 #include <mach/mach_host.h>
 #include <mach/vm_region.h>
 #include <mach/vm_statistics.h>
+#include <mach/processor.h>
+#include <mach/processor_info.h>
 
 /*
  * This class holds information about each throttle state
  */
 class PState {
 public:
-	uint16_t Frequency;			// processor clock speed (FID, not MHz)
-	uint16_t AcpiFreq;			// as reported by ACPI (nice rounded) for display purposes
-	uint16_t Voltage;			// wanted voltage ID while on AC
+	uint16_t Frequency;		// processor clock speed (FID, not MHz)
+	uint16_t AcpiFreq;		// as reported by ACPI (nice rounded) for display purposes
+	uint16_t Voltage;		// wanted voltage ID while on AC
 	uint16_t OriginalVoltage;	// The factory default voltage ID for this frequency
-	uint32_t Latency;			// how long to wait after writing to msr
+	uint32_t Latency;		// how long to wait after writing to msr
 };
 
 
 /*
  * Our auto-throttle controller
  */
-class AutoThrottler {
+class AutoThrottler : public OSObject {
+OSDeclareDefaultStructors(AutoThrottler)
 private:
-	IOWorkLoop*			workLoop;
+	IOWorkLoop*	workLoop;
 	IOTimerEventSource* perfTimer;
-	bool				setupDone; // setup has been done, ready to throttle
-	bool				enabled; // driver is autothrottling
-	uint8_t				currentPState;
-	uint64_t			lastTime;
-	uint16_t			targetCPULoad;
-	
+	bool		setupDone;	// setup has been done, ready to throttle
+	bool		enabled;	// driver is autothrottling
+	uint8_t		currentPState;
+	uint64_t	lastTime;
+	uint16_t	targetCPULoad;
+	host_t		selfHost;
+#define max_cpus 32
+	processor_t	mach_cpu[max_cpus];
+	uint8_t		cpu_count;
+	uint32_t	total_ticks[max_cpus];
+	uint32_t	load_ticks[max_cpus];
+	uint32_t	current_cpuload;
+	processor_cpu_load_info cpu_load[max_cpus];
+	processor_cpu_load_info cpu_load_temp[max_cpus];
+	processor_cpu_load_info cpu_load_last[max_cpus];
+
 public:
-	bool setup(OSObject* owner); // Initialize the throttler
+	bool setup(OSObject* owner);	// Initialize the throttler
 	void stop();
 	void setEnabled(bool _enabled);
 	bool getEnabled();
-	~AutoThrottler();
+	virtual void free();
 	
+	void GetCPUTicks(long* idle, long* total);
 	bool perfTimerEvent(IOTimerEventSource* src, int count);
 };
 
 bool perfTimerWrapper(OSObject* owner, IOTimerEventSource* src, int count);
-static void GetCPUTicks(long* idle, long* total);
 
 /*********************************************************************************************************
 /*
  */
 void disableInterrupts	(__unused void* t);
 void enableInterrupts	(__unused void* t);
-void throttleCPU		(void* fidvid);
+void throttleCPU	(void* fidvid);
 
 /*
  * Rendezvous
  */
-extern "C" void mp_rendezvous(	void (*setup_func)		(void *),
-								void (*action_func)		(void *),
-								void (*teardown_func)	(void *),
-								void *arg);
+extern "C" void mp_rendezvous(	void (*setup_func) (void *),
+			void (*action_func) (void *),
+			void (*teardown_func) (void *),
+			void *arg);
 
 /*
  * For timer fix
 /* Sysctl stuff */
 char*	getFreqList();
 char*	getVoltageList(bool original);
-int		FindClosestPState(int wantedFreq);
-char	frequencyList	[1024] = "";
-char	originalVoltages[1024] = "";
+int	FindClosestPState(int wantedFreq);
+char	frequencyList		[1024] = "";
+char	originalVoltages	[1024] = "";
 
 /*
  * Certain (pseudo)global variables
  */
-PState			PStates[16];		// 16 states max
-AutoThrottler	Throttler;			// Our autothrottle controller
+PState		PStates[16];		// 16 states max
+AutoThrottler*	Throttler;		// Our autothrottle controller
 unsigned int	NumberOfPStates;	// How many this processor supports
-IOSimpleLock*	Lock;				// lock to use while throttling
-bool			InterruptsEnabled;	// to save state of interrupts before throttling
-bool			Is45nmPenryn;		// so that we can use proper VID -> mV calculation
-bool			RtcFixKernel;		// to indicate if this kernel has rtc fix
-bool			Below1Ghz;			// whether kernel is patched to support < 1Ghz freqs
-bool			ConstantTSC;		// whether processor supports constant tsc
-bool			Nby2Ratio;			// Whether cpu supports N/2 fsb ratio
-bool			DebugOn;			// whether to print debug messages
-uint64_t		FSB;				// as reported by EFI
-uint32_t		MaxLatency;			// how long to wait after switching pstate
-int				DefaultPState;		// set at startup
+IOSimpleLock*	Lock;			// lock to use while throttling
+bool		InterruptsEnabled;	// to save state of interrupts before throttling
+bool		Is45nmPenryn;		// so that we can use proper VID -> mV calculation
+bool		RtcFixKernel;		// to indicate if this kernel has rtc fix
+bool		Below1Ghz;		// whether kernel is patched to support < 1Ghz freqs
+bool		ConstantTSC;		// whether processor supports constant tsc
+bool		Nby2Ratio;		// Whether cpu supports N/2 fsb ratio
+bool		DebugOn;		// whether to print debug messages
+uint64_t	FSB;			// as reported by EFI
+uint32_t	MaxLatency;		// how long to wait after switching pstate
+int		DefaultPState;		// set at startup
+int		NumberOfProcessors;	// # of cores/ACPI cpus actually
 
 /*
  * The IOKit driver class
 OSDeclareDefaultStructors(net_mercurysquad_driver_IntelEnhancedSpeedStep)
 	
 private:
-	IOWorkLoop*			workLoop;
+	IOWorkLoop*	workLoop;
 
 public:
-    virtual bool		init	(OSDictionary *dictionary = 0);
-    virtual void		free	(void);
-    virtual IOService*	probe	(IOService *provider, SInt32 *score);
-    virtual bool		start	(IOService *provider);
-    virtual void		stop	(IOService *provider);
+	virtual bool		init	(OSDictionary *dictionary = 0);
+	virtual void		free	(void);
+	virtual IOService*	probe	(IOService *provider, SInt32 *score);
+	virtual bool		start	(IOService *provider);
+	virtual void		stop	(IOService *provider);
 };
 
 #endif // _INTELENHANCEDSPEEDSTEP_H

Source/IntelEnhancedSpeedStep.xcodeproj/project.pbxproj

 	objects = {
 
 /* Begin PBXBuildFile section */
+		2FD8A8E30EAA15BC00C0116F /* IOCPU.h in Headers */ = {isa = PBXBuildFile; fileRef = 2FD8A8E20EAA15BC00C0116F /* IOCPU.h */; };
 		32D94FC60562CBF700B6AF17 /* IntelEnhancedSpeedStep.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A224C3EFF42367911CA2CB7 /* IntelEnhancedSpeedStep.h */; };
 		32D94FC80562CBF700B6AF17 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C167DFE841241C02AAC07 /* InfoPlist.strings */; };
 		32D94FCA0562CBF700B6AF17 /* IntelEnhancedSpeedStep.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A224C3FFF42367911CA2CB7 /* IntelEnhancedSpeedStep.cpp */; settings = {ATTRIBUTES = (); }; };
 		089C167EFE841241C02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = "<group>"; };
 		1A224C3EFF42367911CA2CB7 /* IntelEnhancedSpeedStep.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IntelEnhancedSpeedStep.h; sourceTree = "<group>"; };
 		1A224C3FFF42367911CA2CB7 /* IntelEnhancedSpeedStep.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IntelEnhancedSpeedStep.cpp; sourceTree = "<group>"; };
+		2FD8A8E20EAA15BC00C0116F /* IOCPU.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IOCPU.h; sourceTree = "<group>"; };
 		32D94FCF0562CBF700B6AF17 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
 		32D94FD00562CBF700B6AF17 /* IntelEnhancedSpeedStep.kext */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = IntelEnhancedSpeedStep.kext; sourceTree = BUILT_PRODUCTS_DIR; };
 		8DA8362C06AD9B9200E5AC22 /* Kernel.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Kernel.framework; path = /System/Library/Frameworks/Kernel.framework; sourceTree = "<absolute>"; };
 		8F81F6890E4132350025A326 /* Utility.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Utility.h; sourceTree = "<group>"; };
-		8FA83AE80E54176900A6787A /* TurboEIST.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TurboEIST.cpp; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
 		247142CAFF3F8F9811CA285C /* Source */ = {
 			isa = PBXGroup;
 			children = (
-				8FA83AE80E54176900A6787A /* TurboEIST.cpp */,
 				1A224C3EFF42367911CA2CB7 /* IntelEnhancedSpeedStep.h */,
 				1A224C3FFF42367911CA2CB7 /* IntelEnhancedSpeedStep.cpp */,
 				8F81F6890E4132350025A326 /* Utility.h */,
+				2FD8A8E20EAA15BC00C0116F /* IOCPU.h */,
 			);
 			name = Source;
 			sourceTree = "<group>";
 			files = (
 				32D94FC60562CBF700B6AF17 /* IntelEnhancedSpeedStep.h in Headers */,
 				8F81F68A0E4132350025A326 /* Utility.h in Headers */,
+				2FD8A8E30EAA15BC00C0116F /* IOCPU.h in Headers */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
 
 #define LOGPREFIX "IntelEnhancedSpeedStep: "
 
-#define dbg(args...)    do { if (DebugOn) { IOLog (LOGPREFIX "DBG   " args); } } while(0)
-#define warn(args...)   do { IOLog (LOGPREFIX "WARN  " args);  } while(0)
-#define info(args...)   do { IOLog (LOGPREFIX "INFO  " args);  } while(0)
+#define dbg(args...)	do { if (DebugOn) { IOLog (LOGPREFIX "DBG   " args); } } while(0)
+#define warn(args...)	do { IOLog (LOGPREFIX "WARN  " args);  } while(0)
+#define info(args...)	do { IOLog (LOGPREFIX "INFO  " args);  } while(0)
 
 
 #define releaseObj(x)	{ if (x) { (x)->release(); x = 0; } }
 
-#define INTEL_MSR_PERF_CTL		0x199
-#define INTEL_MSR_PERF_STS		0x198
+#define INTEL_MSR_PERF_CTL	0x199
+#define INTEL_MSR_PERF_STS	0x198
 
-#define CTL(fid, vid)   (((fid) << 8) | (vid))
-#define FID(ctl)        (((ctl) & 0xff00) >> 8)
-#define VID(ctl)        ((ctl) & 0x00ff)
+#define CTL(fid, vid)	(((fid) << 8) | (vid))
+#define FID(ctl)		(((ctl) & 0xff00) >> 8)
+#define VID(ctl)		((ctl) & 0x00ff)
 
-#define	abs(x)			(((x)<0)?(-(x)):(x))
+#define abs(x)		(((x)<0)?(-(x)):(x))
 
 #endif // _UTILITY_H
 #/bin/sh
 kextunload /tmp/IntelEnhancedSpeedStep.kext
-cp -R IntelEnhancedSpeedStep/build/Debug/IntelEnhancedSpeedStep.kext /tmp
+cp -R Source/build/Debug/IntelEnhancedSpeedStep.kext /tmp
 /usr/sbin/chown -R root:wheel /tmp/IntelEnhancedSpeedStep.kext
 find /tmp/IntelEnhancedSpeedStep.kext -type d -exec /bin/chmod 0755 {} \;
 find /tmp/IntelEnhancedSpeedStep.kext -type f -exec /bin/chmod 0644 {} \;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.