Skip to content

Commit dbd3fbd

Browse files
Li Zefanfweisbec
authored andcommitted
tracing/stat: do some cleanups
- remove duplicate code in stat_seq_init() - update comments to reflect the change from stat list to stat rbtree [ Impact: clean up ] Signed-off-by: Li Zefan <lizf@cn.fujitsu.com> Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
1 parent e162280 commit dbd3fbd

1 file changed

Lines changed: 21 additions & 33 deletions

File tree

‎kernel/trace/trace_stat.c‎

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,15 @@ static void destroy_session(struct stat_session *session)
9393

9494
typedef int (*cmp_stat_t)(void *, void *);
9595

96-
static void
97-
insert_stat(struct rb_root *root, struct stat_node *data, cmp_stat_t cmp)
96+
static int insert_stat(struct rb_root *root, void *stat, cmp_stat_t cmp)
9897
{
9998
struct rb_node **new = &(root->rb_node), *parent = NULL;
99+
struct stat_node *data;
100+
101+
data = kzalloc(sizeof(*data), GFP_KERNEL);
102+
if (!data)
103+
return -ENOMEM;
104+
data->stat = stat;
100105

101106
/*
102107
* Figure out where to put new node
@@ -118,28 +123,28 @@ insert_stat(struct rb_root *root, struct stat_node *data, cmp_stat_t cmp)
118123

119124
rb_link_node(&data->node, parent, new);
120125
rb_insert_color(&data->node, root);
126+
return 0;
121127
}
122128

123129
/*
124130
* For tracers that don't provide a stat_cmp callback.
125-
* This one will force an immediate insertion on tail of
126-
* the list.
131+
* This one will force an insertion as right-most node
132+
* in the rbtree.
127133
*/
128134
static int dummy_cmp(void *p1, void *p2)
129135
{
130136
return -1;
131137
}
132138

133139
/*
134-
* Initialize the stat list at each trace_stat file opening.
140+
* Initialize the stat rbtree at each trace_stat file opening.
135141
* All of these copies and sorting are required on all opening
136142
* since the stats could have changed between two file sessions.
137143
*/
138144
static int stat_seq_init(struct stat_session *session)
139145
{
140146
struct tracer_stat *ts = session->ts;
141-
struct stat_node *new_entry;
142-
struct rb_root *root;
147+
struct rb_root *root = &session->stat_root;
143148
void *stat;
144149
int ret = 0;
145150
int i;
@@ -154,23 +159,12 @@ static int stat_seq_init(struct stat_session *session)
154159
if (!stat)
155160
goto exit;
156161

157-
/*
158-
* The first entry. Actually this is the second, but the first
159-
* one (the stat_list head) is pointless.
160-
*/
161-
new_entry = kzalloc(sizeof(*new_entry), GFP_KERNEL);
162-
if (!new_entry) {
163-
ret = -ENOMEM;
162+
ret = insert_stat(root, stat, ts->stat_cmp);
163+
if (ret)
164164
goto exit;
165-
}
166-
root = &session->stat_root;
167-
insert_stat(root, new_entry, dummy_cmp);
168-
169-
new_entry->stat = stat;
170165

171166
/*
172-
* Iterate over the tracer stat entries and store them in a sorted
173-
* list.
167+
* Iterate over the tracer stat entries and store them in an rbtree.
174168
*/
175169
for (i = 1; ; i++) {
176170
stat = ts->stat_next(stat, i);
@@ -179,22 +173,16 @@ static int stat_seq_init(struct stat_session *session)
179173
if (!stat)
180174
break;
181175

182-
new_entry = kzalloc(sizeof(*new_entry), GFP_KERNEL);
183-
if (!new_entry) {
184-
ret = -ENOMEM;
185-
goto exit_free_list;
186-
}
187-
188-
new_entry->stat = stat;
189-
190-
insert_stat(root, new_entry, ts->stat_cmp);
176+
ret = insert_stat(root, stat, ts->stat_cmp);
177+
if (ret)
178+
goto exit_free_rbtree;
191179
}
192180

193181
exit:
194182
mutex_unlock(&session->stat_mutex);
195183
return ret;
196184

197-
exit_free_list:
185+
exit_free_rbtree:
198186
reset_stat_session(session);
199187
mutex_unlock(&session->stat_mutex);
200188
return ret;
@@ -207,7 +195,7 @@ static void *stat_seq_start(struct seq_file *s, loff_t *pos)
207195
struct rb_node *node;
208196
int i;
209197

210-
/* Prevent from tracer switch or stat_list modification */
198+
/* Prevent from tracer switch or rbtree modification */
211199
mutex_lock(&session->stat_mutex);
212200

213201
/* If we are in the beginning of the file, print the headers */
@@ -280,7 +268,7 @@ static int tracing_stat_open(struct inode *inode, struct file *file)
280268
}
281269

282270
/*
283-
* Avoid consuming memory with our now useless list.
271+
* Avoid consuming memory with our now useless rbtree.
284272
*/
285273
static int tracing_stat_release(struct inode *i, struct file *f)
286274
{

0 commit comments

Comments
 (0)