ring-channel.h 6.36 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/*
 * common/ring-channel.c
 *
 * This file is part of the Flux deterministic time-travel infrastructure.
 * Ring channels provide a general producer-consumer interface for relaying
 * data from to the guest components. Specifically ring channels are used for
 * establishing a high-performance communication channels between Xen microkernel
 * and loggin, replay, and devd daemons.
 *
 * Authors: Anton Burtsev Scotty Bauer
 * Date:    October 2011 Feburary 2015
 *
 */

Scotty Bauer's avatar
Scotty Bauer committed
15
#ifndef __XEN_RING_CHANNEL_H__
16
17
#define __XEN_RING_CHANNEL_H__

Scotty Bauer's avatar
Scotty Bauer committed
18
#include <linux/string.h>
19
20
21
22
23
24
25


/*
 * This structure contains the metadata for a single trace buffer.  The head
 * field, indexes into an array of struct t_rec's.
 */
struct ttd_buf {
Scotty Bauer's avatar
Scotty Bauer committed
26
27
	unsigned long   cons;      /* Next item to be consumed by control tools. */
	unsigned long   prod;      /* Next item to be produced by Xen.           */
28

Scotty Bauer's avatar
Scotty Bauer committed
29
30
31
	/* Shape of the buffer */
	unsigned long      payload_buffer_mfn;
	unsigned long      payload_buffer_size;
32

Scotty Bauer's avatar
Scotty Bauer committed
33
	unsigned long      size_of_a_rec;        /* size of a single record */
34

Scotty Bauer's avatar
Scotty Bauer committed
35
	unsigned long      size_in_recs;         /* size of the buffer in recs */
36

Scotty Bauer's avatar
Scotty Bauer committed
37
	/* Stats for the buffer */
38

Scotty Bauer's avatar
Scotty Bauer committed
39
40
41
42
43
44
45
46
47
48
	unsigned long long avg_queue_size;      /* average size of the request queue in the buffer */
	unsigned long long msgs_sent;            /* total number of messages sent */
	unsigned long msgs_by_type[128];          /* count how many messages of individual type we record */
	unsigned long long tx_notifications;     /* total number of TX notifications */
	unsigned long long tx_hit_emergency_margin; /* total number of times the channel gets emergently full */
	unsigned long long rx_notifications;     /* total number of RX notifications */
	unsigned long long msgs_with_extra_reg_space; /* total number of messages which asked for extra space in registers */
	unsigned long msgs_with_extra_reg_space_by_type[128]; /* count how many times an individual event type asks for more space */
	unsigned long long msgs_with_extra_data_space; /* total number of messages which asked for extra space for data */
	unsigned long msgs_with_extra_data_space_by_type[128]; /* count how many times an individual event type asks for more space */
49

Scotty Bauer's avatar
Scotty Bauer committed
50
	/* 'ttd_nr_recs' records follow immediately after the meta-data header.    */
51
52
53
54
};


struct ttd_ring_channel {
Scotty Bauer's avatar
Scotty Bauer committed
55
56
57
	struct ttd_buf   *buf;                  /* pointer to the buffer metadata   */
	unsigned long     buf_mfn;
	unsigned long     buf_order;
58

Scotty Bauer's avatar
Scotty Bauer committed
59
60
61
	void             *priv_metadata;        /* pointer to the private buffer metadata  */
	unsigned long     priv_metadata_size;   /* size of the private buffer metadata  */
	unsigned long     header_order;   /* size of the private buffer metadata  */
62

Scotty Bauer's avatar
Scotty Bauer committed
63
	char             *recs;                 /* pointer to buffer data areas      */
64

Scotty Bauer's avatar
Scotty Bauer committed
65
	unsigned long     size_of_a_rec;        /* size of a single record */
66
67


Scotty Bauer's avatar
Scotty Bauer committed
68
	unsigned long     size_in_recs;         /* size of the buffer in recs */
69

Scotty Bauer's avatar
Scotty Bauer committed
70
71
	unsigned long     highwater;            /* buffer is quite full, time to notify other end */ 
	unsigned long     emergency_margin;     /* buffer is nearly full, time to freeze everything */
72
73
74
75
76

};

static inline void ttd_ring_channel_reinit_stats(struct ttd_buf *buf)
{
Scotty Bauer's avatar
Scotty Bauer committed
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
	buf->avg_queue_size = 0;
	buf->msgs_sent = 0;
	buf->tx_notifications = 0;
	buf->rx_notifications = 0;
	buf->tx_hit_emergency_margin = 0;
	buf->msgs_with_extra_reg_space = 0;
	buf->msgs_with_extra_data_space = 0;

	memset(buf->msgs_by_type, 0,
	       sizeof(buf->msgs_by_type));

	memset(buf->msgs_with_extra_reg_space_by_type, 0,
	       sizeof(buf->msgs_with_extra_reg_space_by_type));

	memset(buf->msgs_with_extra_data_space_by_type, 0,
	       sizeof(buf->msgs_with_extra_data_space_by_type));
93
94
95
96
}

static inline void ttd_ring_channel_init(struct ttd_ring_channel *ring_channel)
{
Scotty Bauer's avatar
Scotty Bauer committed
97
98
	memset(ring_channel, 0, sizeof(*ring_channel));
	return;
99
100
101
102
}

static inline void ttd_ring_channel_buf_init(struct ttd_buf *buf)
{
Scotty Bauer's avatar
Scotty Bauer committed
103
104
	memset(buf, 0, sizeof(*buf));
	return;
105
106
107
108
109
110
111
112
113
114
115
116
117
}

int ttd_ring_channel_alloc(struct ttd_ring_channel *ring_channel,
			   unsigned long size_in_pages,
			   unsigned long size_of_a_rec);

int ttd_ring_channel_alloc_with_metadata(struct ttd_ring_channel *ring_channel,
					 unsigned long size_in_pages,
					 unsigned long size_of_a_rec,
					 unsigned long priv_metadata_size);

void ttd_ring_channel_free(struct ttd_ring_channel *ring_channel);

Scotty Bauer's avatar
Scotty Bauer committed
118
119
static inline void
*ttd_ring_channel_get_priv_metadata(struct ttd_ring_channel *ring_channel)
120
{
Scotty Bauer's avatar
Scotty Bauer committed
121
	return ring_channel->priv_metadata;
122
123
}

Scotty Bauer's avatar
Scotty Bauer committed
124
125
126
static inline unsigned long
ttd_ring_channel_get_prod(struct ttd_ring_channel *ring_channel) {
	return ring_channel->buf->prod;
127
128
};

Scotty Bauer's avatar
Scotty Bauer committed
129
130
131
static inline unsigned long
ttd_ring_channel_inc_prod(struct ttd_ring_channel *ring_channel) {
	return (ring_channel->buf->prod++);
132
133
};

Scotty Bauer's avatar
Scotty Bauer committed
134
135
136
137
static inline void
ttd_ring_channel_set_prod(struct ttd_ring_channel *ring_channel, unsigned long prod) {
	ring_channel->buf->prod = prod;
	return;
138
139
};

Scotty Bauer's avatar
Scotty Bauer committed
140
141
142
static inline unsigned long
ttd_ring_channel_get_cons(struct ttd_ring_channel *ring_channel) {
	return ring_channel->buf->cons;
143
144
};

Scotty Bauer's avatar
Scotty Bauer committed
145
146
147
static inline unsigned long
ttd_ring_channel_inc_cons(struct ttd_ring_channel *ring_channel) {
	return (ring_channel->buf->cons++);
148
149
150
};


Scotty Bauer's avatar
Scotty Bauer committed
151
152
153
154
static inline void ttd_ring_channel_set_cons(struct ttd_ring_channel *ring_channel,
					     unsigned long cons) {
	ring_channel->buf->cons = cons;
	return;
155
156
};

Scotty Bauer's avatar
Scotty Bauer committed
157
158
static inline char *ttd_ring_channel_get_rec_slow(struct ttd_ring_channel *ring_channel,
						  unsigned long cons) {
Scotty Bauer's avatar
Scotty Bauer committed
159
160
161

	//return (ring_channel->recs + (cons % 1024) * 64);
		return (ring_channel->recs
Scotty Bauer's avatar
Scotty Bauer committed
162
163
		+ (cons % ring_channel->size_in_recs)
		* ring_channel->size_of_a_rec);
164
165
166
167
};


static inline unsigned long ttd_ring_channel_get_index_mod_slow(struct ttd_ring_channel *ring_channel, unsigned long index) {
Scotty Bauer's avatar
Scotty Bauer committed
168
	return (index % ring_channel->size_in_recs);
169
170
171
172
}


static inline unsigned long ttd_ring_channel_size_in_recs(struct ttd_ring_channel *ring_channel) {
Scotty Bauer's avatar
Scotty Bauer committed
173
	return ring_channel->size_in_recs;
174
175
176
}

static inline unsigned long ttd_ring_channel_size_of_a_rec(struct ttd_ring_channel *ring_channel) {
Scotty Bauer's avatar
Scotty Bauer committed
177
	return ring_channel->size_of_a_rec;
178
179
180
}

static inline unsigned long ttd_ring_channel_size(struct ttd_ring_channel *ring_channel) {
Scotty Bauer's avatar
Scotty Bauer committed
181
	return ring_channel->size_in_recs * ring_channel->size_of_a_rec;
182
183
184
185
}


static inline unsigned long ttd_ring_channel_highwater(struct ttd_ring_channel *ring_channel) {
Scotty Bauer's avatar
Scotty Bauer committed
186
	return ring_channel->highwater;
187
188
189
}

static inline unsigned long ttd_ring_channel_emergency_margin(struct ttd_ring_channel *ring_channel) {
Scotty Bauer's avatar
Scotty Bauer committed
190
	return ring_channel->emergency_margin;
191
192
193
194
}

#endif