aboutsummaryrefslogtreecommitdiffstats
path: root/rt-plot-vtask.c
blob: 16bb942897a34cdf968d5d26afcebeec6af4a2d9 (plain) (blame)
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#include <stdio.h>
#include <string.h>
#include "trace-graph.h"

#define DEBUG_LEVEL 0
#if DEBUG_LEVEL > 0
#define dprintf(l, x...)			\
	do {					\
		if (l <= DEBUG_LEVEL)		\
			printf(x);		\
	} while (0)
#else
#define dprintf(l, x...)	do { if (0) printf(x); } while (0)
#endif

static void update_job(struct vcpu_info *info, int job)
{
	info->fresh = FALSE;

	if (job > info->last_job) {
		info->last_job = job;
		snprintf(info->label, LLABEL, "%d:%d",
			 info->sid, info->last_job);
	}
}

static int
try_server_switch_away(struct graph_info *ginfo, struct vcpu_info *vcpu_info,
		struct record *record, struct plot_info *info)
{
	int job, sid, tid, tjob, match, ret = 0;
	unsigned long long ts;

	match = rt_graph_check_server_switch_away(ginfo, record,
						  &sid, &job,
						  &tid, &tjob, &ts);
	if (match && tid == vcpu_info->sid) {
		update_job(vcpu_info, tjob);

		if (vcpu_info->run_time && vcpu_info->run_time < ts) {
			info->box = TRUE;
			info->bcolor = hash_cpu(sid - 1);
			info->bfill = TRUE;
			info->bstart = vcpu_info->run_time;
			info->bend = ts;
			info->blabel = vcpu_info->label;
		}

		dprintf(3, "VCPU switch away from %d on %d:%d at %llu\n",
			tid, sid, job, ts);
		vcpu_info->run_time = 0ULL;
		vcpu_info->run_cpu = NO_CPU;
		vcpu_info->run_tid = 0;

		ret = 1;
	}

	return ret;
}

static int try_server_switch_to(struct graph_info *ginfo, struct vcpu_info *vcpu_info,
				struct record *record, struct plot_info *info)
{
	int job, sid, tid, tjob, match, ret = 0;
	unsigned long long ts;

	match = rt_graph_check_server_switch_to(ginfo, record,
						&sid, &job, &tid, &tjob, &ts);
	if (match && tid == vcpu_info->sid) {
		update_job(vcpu_info, tjob);
		vcpu_info->run_time = ts;
		vcpu_info->run_cpu = record->cpu;
		vcpu_info->run_tid = tid;
		dprintf(3, "Switch to %d for %d:%d at %llu\n",
			tid, sid, job, ts);
		ret = 1;
	}
	return ret;
}

/* static int try_switch_to(struct graph_info *ginfo, struct vcpu_info *vcpu_info, */
/* 			 struct record *record, struct plot_info *info) */
/* { */
/* 	int job, pid, match, ret = 0; */
/* 	unsigned long long ts; */

/* 	match = rt_graph_check_switch_to(ginfo, record, &pid, &job, &ts); */
/* 	if (match && pid && pid == vcpu_info->run_tid && vcpu_info->run_time) { */
/* 		info->line = TRUE; */
/* 		info->lcolor = hash_pid(pid); */
/* 		ret = 1; */
/* 	} */
/* 	return ret; */
/* } */

/* static int try_switch_away(struct graph_info *ginfo, struct vcpu_info *vcpu_info, */
/* 			   struct record *record, struct plot_info *info) */
/* { */
/* 	int job, pid, match, ret = 0; */
/* 	unsigned long long ts; */

/* 	match = rt_graph_check_switch_away(ginfo, record, &pid, &job, &ts); */
/* 	if (match && pid && pid == vcpu_info->run_tid) { */
/* 		info->line = TRUE; */
/* 		info->lcolor = hash_pid(pid); */
/* 		ret = 1; */
/* 	} */
/* 	return ret; */
/* } */

static void do_plot_end(struct graph_info *ginfo, struct vcpu_info *vcpu_info,
			struct plot_info *info)
{
	int tid, job, is_running, tjob;
	unsigned long long deadline, release;
	struct record *record;

	if (ginfo->view_end_time == ginfo->end_time)
		return;

	if (vcpu_info->run_time && vcpu_info->run_cpu != NO_CPU) {
		info->box = TRUE;
		info->bcolor = hash_pid(vcpu_info->sid);
		info->bfill = TRUE;
		info->bstart = vcpu_info->run_time;
		info->bend = ginfo->view_end_time;
		info->blabel = vcpu_info->label;
	} else if (vcpu_info->fresh) {
		is_running = get_server_info(ginfo,
					     (struct rt_plot_common*)vcpu_info,
					     vcpu_info->sid,
					     ginfo->view_end_time,
					     &release, &deadline,
					     &job, &tid, &tjob, &record);
		if (is_running) {
			update_job(vcpu_info, job);
			info->box = TRUE;
			info->bcolor = hash_pid(vcpu_info->sid);
			info->bfill = TRUE;
			info->bstart = vcpu_info->run_time;
			info->bend = ginfo->view_end_time;
			info->blabel = vcpu_info->label;
		}
	}
}

static int rt_vtask_plot_event(struct graph_info *ginfo, struct graph_plot *plot,
			     struct record *record, struct plot_info *info)
{
	int match;
	struct vcpu_info *vcpu_info = plot->private;

	if (!record) {
		do_plot_end(ginfo, vcpu_info, info);
		return 0;
	}

	match = try_server_switch_away(ginfo, vcpu_info, record, info) ||
		try_server_switch_to(ginfo, vcpu_info, record, info) ||
		/* vcpu_try_block(ginfo, vcpu_info, record, info) || */
		/* vcpu_try_resume(ginfo, vcpu_info, record, info) || */
		vcpu_try_release(ginfo, vcpu_info, record, info) ||
		vcpu_try_completion(ginfo, vcpu_info, record, info);
		/* try_switch_to(ginfo, vcpu_info, record, info) || */
		/* try_switch_away(ginfo, vcpu_info, record, info); */
	return match;
}

const struct plot_callbacks rt_vtask_cb = {
	.start			= rt_vcpu_plot_start,
	.destroy		= rt_vcpu_plot_destroy,
	.plot_event		= rt_vtask_plot_event,
	.display_last_event	= rt_plot_display_last_event,
	.display_info		= rt_plot_display_info,
	.match_time		= rt_plot_match_time,
	.find_record		= rt_plot_find_record,
};

void insert_vtask(struct graph_info *ginfo, struct cont_list *cont,
		  struct vcpu_list *vcpu_info)
{
	struct graph_plot *plot;
	struct vcpu_info *vtask;
	char *label;

	vtask = malloc_or_die(sizeof(*vtask));
	vtask->sid = vcpu_info->sid;
	vtask->label = malloc_or_die(LLABEL);
	vtask->cont = cont;

	vtask->common.record_matches = rt_vcpu_plot_record_matches;
	vtask->common.is_drawn = rt_vcpu_plot_is_drawn;
	vtask->common.write_header = rt_vcpu_plot_write_header;

	label = malloc_or_die(1);
	snprintf(label, 2, " ");

	plot = trace_graph_plot_append(ginfo, label, PLOT_TYPE_SERVER_TASK,
				       TIME_TYPE_RT, &rt_vtask_cb, vtask);
	trace_graph_plot_add_all_recs(ginfo, plot);
}