Last active
May 15, 2019 16:05
-
-
Save cyring/8219a57178670f7a0003c5198e103c7e to your computer and use it in GitHub Desktop.
cpufreq driver
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
corefreq-api.h | |
--- | |
struct { | |
signed int AutoClock, | |
Experimental, | |
hotplug, | |
pci, | |
nmi; | |
struct { | |
unsigned int | |
cpuidle: 1-0, | |
cpufreq: 2-1; | |
} Driver; | |
} Registration; | |
--- | |
corefreqk.c | |
--- | |
static signed short CPU_Idle_Enable = -1; | |
module_param(CPU_Idle_Enable, short, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); | |
MODULE_PARM_DESC(CPU_Idle_Enable, "Enable the Kernel cpuidle driver"); | |
static signed short CPU_Freq_Enable = -1; | |
module_param(CPU_Freq_Enable, short, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); | |
MODULE_PARM_DESC(CPU_Freq_Enable, "Enable the Kernel cpufreq driver"); | |
#if FEAT_DBG > 1 /*TODO: LEVEL 2 */ | |
static int CoreFreqK_Policy_Exit(struct cpufreq_policy *policy) ; | |
static int CoreFreqK_Policy_Init(struct cpufreq_policy *policy) ; | |
static int CoreFreqK_Policy_Verify(struct cpufreq_policy *policy) ; | |
static int CoreFreqK_SetPolicy(struct cpufreq_policy *policy) ; | |
static unsigned int CoreFreqK_GetFreq(unsigned int cpu) ; | |
#endif /* FEAT_DBG */ | |
static struct { | |
signed int Major; | |
struct cdev *kcdev; | |
dev_t nmdev, mkdev; | |
struct class *clsdev; | |
#if FEAT_DBG > 1 /*TODO: LEVEL 2 */ | |
struct cpuidle_driver IdleDriver; | |
struct cpufreq_driver FreqDriver; | |
#endif /* FEAT_DBG */ | |
} CoreFreqK = { | |
#if FEAT_DBG > 1 /*TODO: LEVEL 2 */ | |
.IdleDriver = { | |
.name = "corefreqk-idle", | |
.owner = THIS_MODULE | |
}, | |
.FreqDriver = { | |
.name = "corefreqk-perf", | |
.flags = CPUFREQ_CONST_LOOPS, | |
.exit = CoreFreqK_Policy_Exit, | |
/*MANDATORY*/ .init = CoreFreqK_Policy_Init, | |
/*MANDATORY*/ .verify = CoreFreqK_Policy_Verify, | |
/*MANDATORY*/ .setpolicy = CoreFreqK_SetPolicy, | |
.get = CoreFreqK_GetFreq | |
} | |
#endif /* FEAT_DBG */ | |
}; | |
#if FEAT_DBG > 1 /*TODO: LEVEL 2 */ | |
static int CoreFreqK_Policy_Exit(struct cpufreq_policy *policy) | |
{ | |
return(0); | |
} | |
static int CoreFreqK_Policy_Init(struct cpufreq_policy *policy) | |
{ | |
if (policy != NULL) { | |
unsigned int cpu = policy->cpu; | |
if ((cpu >= 0) && (cpu < Proc->CPU.Count)) { | |
policy->cpuinfo.min_freq =(Proc->Boost[BOOST(MIN)] | |
* KPublic->Core[cpu]->Clock.Hz) | |
/ 1000LLU; | |
policy->cpuinfo.max_freq =(Proc->Boost[BOOST(MAX)] | |
* KPublic->Core[cpu]->Clock.Hz) | |
/ 1000LLU; | |
policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL; | |
policy->min = policy->cpuinfo.min_freq; | |
policy->max = policy->cpuinfo.max_freq; | |
} | |
} | |
return(0); | |
} | |
static int CoreFreqK_Policy_Verify(struct cpufreq_policy *policy) | |
{ | |
if (policy != NULL) { | |
cpufreq_verify_within_cpu_limits(policy); | |
} | |
return(0); | |
} | |
static int CoreFreqK_SetPolicy(struct cpufreq_policy *policy) | |
{ | |
if (policy != NULL) { | |
} | |
return(0); | |
} | |
static unsigned int CoreFreqK_GetFreq(unsigned int cpu) | |
{ | |
if ((cpu >= 0) && (cpu < Proc->CPU.Count)) { | |
if (Proc->Features.HWP_Enable) | |
return((Proc->Boost[BOOST(HWP_TGT)] | |
* KPublic->Core[cpu]->Clock.Hz) | |
/ 1000LLU); | |
else | |
return((Proc->Boost[BOOST(TGT)] | |
* KPublic->Core[cpu]->Clock.Hz) | |
/ 1000LLU); | |
} else { | |
return(0); | |
} | |
} | |
static void CoreFreqK_FreqDriver_UnInit(void) | |
{ | |
cpufreq_unregister_driver(&CoreFreqK.FreqDriver); | |
} | |
static int CoreFreqK_FreqDriver_Init(void) | |
{ | |
int rc = -EPERM; | |
rc = cpufreq_register_driver(&CoreFreqK.FreqDriver); | |
return(rc); | |
} | |
#endif /* FEAT_DBG */ | |
static int __init CoreFreqK_init(void) | |
{ | |
#if FEAT_DBG > 1 /*TODO: LEVEL 2 */ | |
if (CPU_Idle_Enable == 1) { | |
Proc->Registration.Driver.cpuidle = CoreFreqK_IdleDriver_Init() == 0; | |
} | |
if (CPU_Freq_Enable == 1) { | |
Proc->Registration.Driver.cpufreq = CoreFreqK_FreqDriver_Init() == 0; | |
} | |
#endif | |
} | |
static void __exit CoreFreqK_cleanup(void) | |
{ | |
#if FEAT_DBG > 1 /*TODO: LEVEL 2 */ | |
if (Proc->Registration.Driver.cpufreq) { | |
CoreFreqK_FreqDriver_UnInit(); | |
} | |
if (Proc->Registration.Driver.cpuidle) { | |
CoreFreqK_IdleDriver_UnInit(); | |
} | |
#endif | |
} |
Author
cyring
commented
May 15, 2019
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment