Skip to content

Commit 9870d78

Browse files
committed
perf ordered_samples: Remove references to perf_{evlist,tool} and machines
As these can be obtained from the ordered_events pointer, via container_of, reducing the cross section of ordered_samples. These were added to ordered_samples in: commit b7b61cb Author: Arnaldo Carvalho de Melo <[email protected]> Date: Tue Mar 3 11:58:45 2015 -0300 perf ordered_events: Shorten function signatures By keeping pointers to machines, evlist and tool in ordered_events. But that was more a transitional patch while moving stuff out from perf_session.c to ordered_events.c and possibly not even needed by then, as we could use the container_of() method and instead of having the nr_unordered_samples stats in events_stats, we can have it in ordered_samples. Based-on-a-patch-by: Jiri Olsa <[email protected]> Acked-by: Jiri Olsa <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: David Ahern <[email protected]> Cc: Don Zickus <[email protected]> Cc: Frederic Weisbecker <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Stephane Eranian <[email protected]> Link: http://lkml.kernel.org/n/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent aae59fa commit 9870d78

File tree

5 files changed

+37
-47
lines changed

5 files changed

+37
-47
lines changed

tools/perf/util/event.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ struct events_stats {
242242
u32 nr_invalid_chains;
243243
u32 nr_unknown_id;
244244
u32 nr_unprocessable_samples;
245-
u32 nr_unordered_events;
246245
};
247246

248247
struct attr_event {

tools/perf/util/ordered-events.c

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#include <linux/compiler.h>
33
#include <linux/string.h>
44
#include "ordered-events.h"
5-
#include "evlist.h"
65
#include "session.h"
76
#include "asm/bug.h"
87
#include "debug.h"
@@ -167,7 +166,7 @@ int ordered_events__queue(struct ordered_events *oe, union perf_event *event,
167166
pr_oe_time(oe->last_flush, "last flush, last_flush_type %d\n",
168167
oe->last_flush_type);
169168

170-
oe->evlist->stats.nr_unordered_events++;
169+
oe->nr_unordered_events++;
171170
}
172171

173172
oevent = ordered_events__new_event(oe, timestamp, event);
@@ -187,7 +186,6 @@ static int __ordered_events__flush(struct ordered_events *oe)
187186
{
188187
struct list_head *head = &oe->events;
189188
struct ordered_event *tmp, *iter;
190-
struct perf_sample sample;
191189
u64 limit = oe->next_flush;
192190
u64 last_ts = oe->last ? oe->last->timestamp : 0ULL;
193191
bool show_progress = limit == ULLONG_MAX;
@@ -206,15 +204,9 @@ static int __ordered_events__flush(struct ordered_events *oe)
206204

207205
if (iter->timestamp > limit)
208206
break;
209-
210-
ret = perf_evlist__parse_sample(oe->evlist, iter->event, &sample);
207+
ret = oe->deliver(oe, iter);
211208
if (ret)
212-
pr_err("Can't parse sample, err = %d\n", ret);
213-
else {
214-
ret = oe->deliver(oe, iter, &sample);
215-
if (ret)
216-
return ret;
217-
}
209+
return ret;
218210

219211
ordered_events__delete(oe, iter);
220212
oe->last_flush = iter->timestamp;
@@ -292,18 +284,13 @@ int ordered_events__flush(struct ordered_events *oe, enum oe_flush how)
292284
return err;
293285
}
294286

295-
void ordered_events__init(struct ordered_events *oe, struct machines *machines,
296-
struct perf_evlist *evlist, struct perf_tool *tool,
297-
ordered_events__deliver_t deliver)
287+
void ordered_events__init(struct ordered_events *oe, ordered_events__deliver_t deliver)
298288
{
299289
INIT_LIST_HEAD(&oe->events);
300290
INIT_LIST_HEAD(&oe->cache);
301291
INIT_LIST_HEAD(&oe->to_free);
302292
oe->max_alloc_size = (u64) -1;
303293
oe->cur_alloc_size = 0;
304-
oe->evlist = evlist;
305-
oe->machines = machines;
306-
oe->tool = tool;
307294
oe->deliver = deliver;
308295
}
309296

tools/perf/util/ordered-events.h

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33

44
#include <linux/types.h>
55

6-
struct perf_tool;
7-
struct perf_evlist;
86
struct perf_sample;
9-
struct machines;
107

118
struct ordered_event {
129
u64 timestamp;
@@ -25,8 +22,7 @@ enum oe_flush {
2522
struct ordered_events;
2623

2724
typedef int (*ordered_events__deliver_t)(struct ordered_events *oe,
28-
struct ordered_event *event,
29-
struct perf_sample *sample);
25+
struct ordered_event *event);
3026

3127
struct ordered_events {
3228
u64 last_flush;
@@ -39,23 +35,19 @@ struct ordered_events {
3935
struct list_head to_free;
4036
struct ordered_event *buffer;
4137
struct ordered_event *last;
42-
struct machines *machines;
43-
struct perf_evlist *evlist;
44-
struct perf_tool *tool;
4538
ordered_events__deliver_t deliver;
4639
int buffer_idx;
4740
unsigned int nr_events;
4841
enum oe_flush last_flush_type;
42+
u32 nr_unordered_events;
4943
bool copy_on_queue;
5044
};
5145

5246
int ordered_events__queue(struct ordered_events *oe, union perf_event *event,
5347
struct perf_sample *sample, u64 file_offset);
5448
void ordered_events__delete(struct ordered_events *oe, struct ordered_event *event);
5549
int ordered_events__flush(struct ordered_events *oe, enum oe_flush how);
56-
void ordered_events__init(struct ordered_events *oe, struct machines *machines,
57-
struct perf_evlist *evlsit, struct perf_tool *tool,
58-
ordered_events__deliver_t deliver);
50+
void ordered_events__init(struct ordered_events *oe, ordered_events__deliver_t deliver);
5951
void ordered_events__free(struct ordered_events *oe);
6052

6153
static inline

tools/perf/util/session.c

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,20 @@ static void perf_session__set_comm_exec(struct perf_session *session)
9393
}
9494

9595
static int ordered_events__deliver_event(struct ordered_events *oe,
96-
struct ordered_event *event,
97-
struct perf_sample *sample)
96+
struct ordered_event *event)
9897
{
99-
return machines__deliver_event(oe->machines, oe->evlist, event->event,
100-
sample, oe->tool, event->file_offset);
98+
struct perf_sample sample;
99+
struct perf_session *session = container_of(oe, struct perf_session,
100+
ordered_events);
101+
int ret = perf_evlist__parse_sample(session->evlist, event->event, &sample);
102+
103+
if (ret) {
104+
pr_err("Can't parse sample, err = %d\n", ret);
105+
return ret;
106+
}
107+
108+
return machines__deliver_event(&session->machines, session->evlist, event->event,
109+
&sample, session->tool, event->file_offset);
101110
}
102111

103112
struct perf_session *perf_session__new(struct perf_data_file *file,
@@ -109,9 +118,9 @@ struct perf_session *perf_session__new(struct perf_data_file *file,
109118
goto out;
110119

111120
session->repipe = repipe;
121+
session->tool = tool;
112122
machines__init(&session->machines);
113-
ordered_events__init(&session->ordered_events, &session->machines,
114-
session->evlist, tool, ordered_events__deliver_event);
123+
ordered_events__init(&session->ordered_events, ordered_events__deliver_event);
115124

116125
if (file) {
117126
if (perf_data_file__open(file))
@@ -940,7 +949,7 @@ static s64 perf_session__process_user_event(struct perf_session *session,
940949
u64 file_offset)
941950
{
942951
struct ordered_events *oe = &session->ordered_events;
943-
struct perf_tool *tool = oe->tool;
952+
struct perf_tool *tool = session->tool;
944953
int fd = perf_data_file__fd(session->file);
945954
int err;
946955

@@ -981,7 +990,7 @@ int perf_session__deliver_synth_event(struct perf_session *session,
981990
struct perf_sample *sample)
982991
{
983992
struct perf_evlist *evlist = session->evlist;
984-
struct perf_tool *tool = session->ordered_events.tool;
993+
struct perf_tool *tool = session->tool;
985994

986995
events_stats__inc(&evlist->stats, event->header.type);
987996

@@ -1059,7 +1068,7 @@ static s64 perf_session__process_event(struct perf_session *session,
10591068
union perf_event *event, u64 file_offset)
10601069
{
10611070
struct perf_evlist *evlist = session->evlist;
1062-
struct perf_tool *tool = session->ordered_events.tool;
1071+
struct perf_tool *tool = session->tool;
10631072
struct perf_sample sample;
10641073
int ret;
10651074

@@ -1116,10 +1125,12 @@ static struct thread *perf_session__register_idle_thread(struct perf_session *se
11161125
return thread;
11171126
}
11181127

1119-
static void perf_tool__warn_about_errors(const struct perf_tool *tool,
1120-
const struct events_stats *stats)
1128+
static void perf_session__warn_about_errors(const struct perf_session *session)
11211129
{
1122-
if (tool->lost == perf_event__process_lost &&
1130+
const struct events_stats *stats = &session->evlist->stats;
1131+
const struct ordered_events *oe = &session->ordered_events;
1132+
1133+
if (session->tool->lost == perf_event__process_lost &&
11231134
stats->nr_events[PERF_RECORD_LOST] != 0) {
11241135
ui__warning("Processed %d events and lost %d chunks!\n\n"
11251136
"Check IO/CPU overload!\n\n",
@@ -1155,16 +1166,16 @@ static void perf_tool__warn_about_errors(const struct perf_tool *tool,
11551166
stats->nr_unprocessable_samples);
11561167
}
11571168

1158-
if (stats->nr_unordered_events != 0)
1159-
ui__warning("%u out of order events recorded.\n", stats->nr_unordered_events);
1169+
if (oe->nr_unordered_events != 0)
1170+
ui__warning("%u out of order events recorded.\n", oe->nr_unordered_events);
11601171
}
11611172

11621173
volatile int session_done;
11631174

11641175
static int __perf_session__process_pipe_events(struct perf_session *session)
11651176
{
11661177
struct ordered_events *oe = &session->ordered_events;
1167-
struct perf_tool *tool = oe->tool;
1178+
struct perf_tool *tool = session->tool;
11681179
int fd = perf_data_file__fd(session->file);
11691180
union perf_event *event;
11701181
uint32_t size, cur_size = 0;
@@ -1247,7 +1258,7 @@ static int __perf_session__process_pipe_events(struct perf_session *session)
12471258
err = ordered_events__flush(oe, OE_FLUSH__FINAL);
12481259
out_err:
12491260
free(buf);
1250-
perf_tool__warn_about_errors(tool, &session->evlist->stats);
1261+
perf_session__warn_about_errors(session);
12511262
ordered_events__free(&session->ordered_events);
12521263
return err;
12531264
}
@@ -1297,7 +1308,7 @@ static int __perf_session__process_events(struct perf_session *session,
12971308
u64 file_size)
12981309
{
12991310
struct ordered_events *oe = &session->ordered_events;
1300-
struct perf_tool *tool = oe->tool;
1311+
struct perf_tool *tool = session->tool;
13011312
int fd = perf_data_file__fd(session->file);
13021313
u64 head, page_offset, file_offset, file_pos, size;
13031314
int err, mmap_prot, mmap_flags, map_idx = 0;
@@ -1393,7 +1404,7 @@ static int __perf_session__process_events(struct perf_session *session,
13931404
err = ordered_events__flush(oe, OE_FLUSH__FINAL);
13941405
out_err:
13951406
ui_progress__finish();
1396-
perf_tool__warn_about_errors(tool, &session->evlist->stats);
1407+
perf_session__warn_about_errors(session);
13971408
ordered_events__free(&session->ordered_events);
13981409
session->one_mmap = false;
13991410
return err;

tools/perf/util/session.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ struct perf_session {
2626
u64 one_mmap_offset;
2727
struct ordered_events ordered_events;
2828
struct perf_data_file *file;
29+
struct perf_tool *tool;
2930
};
3031

3132
#define PRINT_IP_OPT_IP (1<<0)

0 commit comments

Comments
 (0)