Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 12 additions & 20 deletions tsc_freq_khz.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/cpu.h>
//#include <linux/arch/x86/include/asm/tsc.h>
extern unsigned int tsc_khz;
#include <asm/tsc.h> // extern unsigned int tsc_khz;
#include <linux/printk.h>
#include <linux/kobject.h>
#include <linux/sysfs.h>
Expand All @@ -21,22 +20,15 @@ static ssize_t tsc_freq_khz_show(struct kobject *kobj, struct kobj_attribute *at
char *buf)
{
ssize_t r;
r = sprintf(buf, "%d\n", tsc_khz);
r = sprintf(buf, "%u\n", tsc_khz);
return r;
}

static ssize_t tsc_freq_khz_store(struct kobject *kobj, struct kobj_attribute *attr,
const char *buf, size_t count)
{
// unimplemented
return count;
}

static struct kobj_attribute tsc_freq_khz_attribute =
__ATTR(tsc_freq_khz,
S_IRUGO, // world readable, unchangeable
tsc_freq_khz_show,
tsc_freq_khz_store);
NULL); // store not implemented

static int __init tsc_khz_init(void){
struct device *dev;
Expand All @@ -62,15 +54,15 @@ static int __init tsc_khz_init(void){
}

static void __exit tsc_khz_exit(void) {
struct device *dev;
printk(KERN_INFO DRIVER_NAME ": unloading driver\n");
dev = get_cpu_device(0); // assumes always a cpu0
if (!dev) {
printk(KERN_INFO DRIVER_NAME ": could not get device for CPU %d\n", 0);
return;
}
sysfs_remove_file(&dev->kobj, &tsc_freq_khz_attribute.attr);
struct device *dev;
printk(KERN_INFO DRIVER_NAME ": unloading driver\n");
dev = get_cpu_device(0); // assumes always a cpu0
if (!dev) {
printk(KERN_INFO DRIVER_NAME ": could not get device for CPU %d\n", 0);
return;
}
sysfs_remove_file(&dev->kobj, &tsc_freq_khz_attribute.attr);
}

module_init(tsc_khz_init);
module_exit(tsc_khz_exit);
module_exit(tsc_khz_exit);