1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
/*
* Copyright (c) 2013-2014, NVIDIA CORPORATION. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/sysedp.h>
#include <linux/debugfs.h>
#include "sysedp_internal.h"
struct dentry *edp_debugfs_dir;
struct dentry *sysedp_debugfs_dir;
static int sysedp_status_show(struct seq_file *file, void *data)
{
struct sysedp_consumer *c;
int limit; /* Amount of power available when OC=1*/
int oc_relax; /* Additional power available when OC=0 */
int pmax_sum = 0; /* sum of peak values (OC=1) */
int pthres_sum = 0; /* sum of peak values (OC=0) */
mutex_lock(&sysedp_lock);
list_for_each_entry(c, ®istered_consumers, link) {
pmax_sum += _cur_oclevel(c);
pthres_sum += _cur_level(c);
}
limit = (int)avail_budget - pmax_sum - margin;
limit = limit >= min_budget ? limit : min_budget;
oc_relax = pmax_sum - pthres_sum;
oc_relax = oc_relax >= 0 ? oc_relax : 0;
seq_printf(file, " avail_budget : %u\n", avail_budget);
seq_printf(file, "- pmax_sum : %u\n", pmax_sum);
seq_printf(file, "- margin : %d\n", margin);
seq_printf(file, "( minimum budget : %d)\n", min_budget);
seq_printf(file, "= remaining (OC=1) : %d\n", limit);
seq_printf(file, "+ oc_relax : %d\n", oc_relax);
seq_printf(file, "= remaining (OC=0) : %d\n", limit + oc_relax);
seq_puts(file, "------------------------------------------\n");
seq_printf(file, "%-16s %7s %7s\n", "consumer", "pmax", "pthresh" );
seq_puts(file, "------------------------------------------\n");
list_for_each_entry(c, ®istered_consumers, link)
seq_printf(file, "%-16s %7u %7u\n", c->name, _cur_oclevel(c),
_cur_level(c));
mutex_unlock(&sysedp_lock);
return 0;
}
static int sysedp_status_open(struct inode *inode, struct file *file)
{
return single_open(file, sysedp_status_show, inode->i_private);
}
static const struct file_operations sysedp_status_fops = {
.open = sysedp_status_open,
.read = seq_read,
};
static int sysedp_min_budget_set(void *data, u64 val)
{
int old;
old = min_budget;
min_budget = (((int)val) < 0) ? 0 : (int)val;
if (old != min_budget) {
mutex_lock(&sysedp_lock);
/* Changes to min_budget require sysedp refresh */
_sysedp_refresh();
mutex_unlock(&sysedp_lock);
}
return 0;
}
static int sysedp_min_budget_get(void *data, u64 *val)
{
*val = min_budget;
return 0;
}
DEFINE_SIMPLE_ATTRIBUTE(sysedp_min_budget_fops,
sysedp_min_budget_get,
sysedp_min_budget_set, "%lld\n");
void sysedp_init_debugfs(void)
{
struct dentry *d;
d = debugfs_create_dir("edp", NULL);
if (IS_ERR_OR_NULL(d)) {
WARN_ON(1);
return;
}
edp_debugfs_dir = d;
d = debugfs_create_dir("sysedp", edp_debugfs_dir);
if (IS_ERR_OR_NULL(d)) {
WARN_ON(1);
return;
}
sysedp_debugfs_dir = d;
d = debugfs_create_file("status", S_IRUGO, sysedp_debugfs_dir, NULL,
&sysedp_status_fops);
WARN_ON(IS_ERR_OR_NULL(d));
d = debugfs_create_file("min_budget", S_IRUGO | S_IWUSR,
sysedp_debugfs_dir, NULL,
&sysedp_min_budget_fops);
WARN_ON(IS_ERR_OR_NULL(d));
}
|