• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  drivers/cpufreq/cpufreq_stats.c
3  *
4  *  Copyright (C) 2003-2004 Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>.
5  *  (C) 2004 Zou Nan hai <nanhai.zou@intel.com>.
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  */
11 
12 #include <linux/cpu.h>
13 #include <linux/cpufreq.h>
14 #include <linux/module.h>
15 #include <linux/slab.h>
16 
17 #define to_attr(a) container_of(a, struct freq_attr, attr)
18 
19 static unsigned long long fake_time;
20 
21 static DEFINE_PER_CPU(struct kobject *, cpufreq_kobj);
22 
time_in_state_show(struct kobject * kobj,struct kobj_attribute * attr,char * buf)23 static ssize_t time_in_state_show(struct kobject *kobj,
24 		struct kobj_attribute *attr, char *buf)
25 {
26 	ssize_t len = 0;
27 
28 	len = sprintf(buf, "%lu %llu\n", 3000000000, ++fake_time);
29 	return len;
30 }
31 
32 static struct kobj_attribute time_in_state =
33 	__ATTR_RO_MODE(time_in_state, 0444);
34 
35 static struct attribute *cpufreq_stats_attrs[] = {
36 	&time_in_state.attr,
37 	NULL
38 };
39 static struct attribute_group stats_attr_group = {
40 	.attrs = cpufreq_stats_attrs,
41 	.name = "stats"
42 };
43 
cpufreq_stats_free(unsigned int cpu)44 static void cpufreq_stats_free(unsigned int cpu)
45 {
46 	struct device *dev = get_cpu_device(cpu);
47 	struct kobject **kobj = &per_cpu(cpufreq_kobj, cpu);
48 
49 	sysfs_remove_group(&dev->kobj, &stats_attr_group);
50 	kobject_put(*kobj);
51 	*kobj=NULL;
52 }
53 
cpufreq_stats_create(unsigned int cpu)54 static void cpufreq_stats_create(unsigned int cpu)
55 {
56 	int ret;
57 	struct device *dev = get_cpu_device(cpu);
58 	struct kobject **kobj = &per_cpu(cpufreq_kobj, cpu);
59 
60 	*kobj = kobject_create_and_add("cpufreq", &dev->kobj);
61 	ret = sysfs_create_group(*kobj, &stats_attr_group);
62 }
63 
goldfish_cpufreq_stats_init(void)64 static int __init goldfish_cpufreq_stats_init(void)
65 {
66 	unsigned int cpu;
67 
68 	for_each_online_cpu(cpu)
69 		cpufreq_stats_create(cpu);
70 
71 	return 0;
72 }
73 
goldfish_cpufreq_stats_exit(void)74 static void __exit goldfish_cpufreq_stats_exit(void)
75 {
76 	unsigned int cpu;
77 
78 	for_each_online_cpu(cpu)
79 		cpufreq_stats_free(cpu);
80 }
81 
82 module_init(goldfish_cpufreq_stats_init);
83 module_exit(goldfish_cpufreq_stats_exit);
84