-
Notifications
You must be signed in to change notification settings - Fork 45
/
homa.h
211 lines (178 loc) · 6.21 KB
/
homa.h
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
202
203
204
205
206
207
208
209
210
211
/* SPDX-License-Identifier: BSD-2-Clause */
/* This file defines the kernel call interface for the Homa
* transport protocol.
*/
#ifndef _UAPI_LINUX_HOMA_H
#define _UAPI_LINUX_HOMA_H
#include <linux/types.h>
#ifndef __KERNEL__
#include <netinet/in.h>
#include <sys/socket.h>
#endif
#ifdef __cplusplus
extern "C"
{
#endif
/* IANA-assigned Internet Protocol number for Homa. */
#define IPPROTO_HOMA 146
/**
* define HOMA_MAX_MESSAGE_LENGTH - Maximum bytes of payload in a Homa
* request or response message.
*/
#define HOMA_MAX_MESSAGE_LENGTH 1000000
/**
* define HOMA_BPAGE_SIZE - Number of bytes in pages used for receive
* buffers. Must be power of two.
*/
#define HOMA_BPAGE_SIZE (1 << HOMA_BPAGE_SHIFT)
#define HOMA_BPAGE_SHIFT 16
/**
* define HOMA_MAX_BPAGES - The largest number of bpages that will be required
* to store an incoming message.
*/
#define HOMA_MAX_BPAGES ((HOMA_MAX_MESSAGE_LENGTH + HOMA_BPAGE_SIZE - 1) \
>> HOMA_BPAGE_SHIFT)
/**
* define HOMA_MIN_DEFAULT_PORT - The 16-bit port space is divided into
* two nonoverlapping regions. Ports 1-32767 are reserved exclusively
* for well-defined server ports. The remaining ports are used for client
* ports; these are allocated automatically by Homa. Port 0 is reserved.
*/
#define HOMA_MIN_DEFAULT_PORT 0x8000
/**
* struct homa_sendmsg_args - Provides information needed by Homa's
* sendmsg; passed to sendmsg using the msg_control field.
*/
struct homa_sendmsg_args {
/**
* @id: (in/out) An initial value of 0 means a new request is
* being sent; nonzero means the message is a reply to the given
* id. If the message is a request, then the value is modified to
* hold the id of the new RPC.
*/
uint64_t id;
/**
* @completion_cookie: (in) Used only for request messages; will be
* returned by recvmsg when the RPC completes. Typically used to
* locate app-specific info about the RPC.
*/
uint64_t completion_cookie;
};
#if !defined(__cplusplus)
_Static_assert(sizeof(struct homa_sendmsg_args) >= 16,
"homa_sendmsg_args shrunk");
_Static_assert(sizeof(struct homa_sendmsg_args) <= 16,
"homa_sendmsg_args grew");
#endif
/**
* struct homa_recvmsg_args - Provides information needed by Homa's
* recvmsg; passed to recvmsg using the msg_control field.
*/
struct homa_recvmsg_args {
/**
* @id: (in/out) Initially specifies the id of the desired RPC, or 0
* if any RPC is OK; returns the actual id received.
*/
uint64_t id;
/**
* @completion_cookie: (out) If the incoming message is a response,
* this will return the completion cookie specified when the
* request was sent. For requests this will always be zero.
*/
uint64_t completion_cookie;
/**
* @flags: (in) OR-ed combination of bits that control the operation.
* See below for values.
*/
uint32_t flags;
/**
* @num_bpages: (in/out) Number of valid entries in @bpage_offsets.
* Passes in bpages from previous messages that can now be
* recycled; returns bpages from the new message.
*/
uint32_t num_bpages;
/**
* @bpage_offsets: (in/out) Each entry is an offset into the buffer
* region for the socket pool. When returned from recvmsg, the
* offsets indicate where fragments of the new message are stored. All
* entries but the last refer to full buffer pages (HOMA_BPAGE_SIZE
* bytes) and are bpage-aligned. The last entry may refer to a bpage
* fragment and is not necessarily aligned. The application now owns
* these bpages and must eventually return them to Homa, using
* bpage_offsets in a future recvmsg invocation.
*/
uint32_t bpage_offsets[HOMA_MAX_BPAGES];
};
#if !defined(__cplusplus)
_Static_assert(sizeof(struct homa_recvmsg_args) >= 88,
"homa_recvmsg_args shrunk");
_Static_assert(sizeof(struct homa_recvmsg_args) <= 88,
"homa_recvmsg_args grew");
#endif
/* Flag bits for homa_recvmsg_args.flags (see man page for documentation):
*/
#define HOMA_RECVMSG_REQUEST 0x01
#define HOMA_RECVMSG_RESPONSE 0x02
#define HOMA_RECVMSG_NONBLOCKING 0x04
#define HOMA_RECVMSG_VALID_FLAGS 0x07
/**
* struct homa_abort_args - Structure that passes arguments and results
* between user space and the HOMAIOCABORT ioctl.
*/
struct homa_abort_args {
/** @id: Id of RPC to abort, or zero to abort all RPCs on socket. */
uint64_t id;
/**
* @error: Zero means destroy and free RPCs; nonzero means complete
* them with this error (recvmsg will return the RPCs).
*/
int error;
int _pad1;
uint64_t _pad2[2];
};
#if !defined(__cplusplus)
_Static_assert(sizeof(struct homa_abort_args) >= 32, "homa_abort_args shrunk");
_Static_assert(sizeof(struct homa_abort_args) <= 32, "homa_abort_args grew");
#endif
/** define SO_HOMA_RCVBUF: setsockopt option for specifying buffer region. */
#define SO_HOMA_RCVBUF 10
/** struct homa_rcvbuf_args - setsockopt argument for SO_HOMA_RCVBUF. */
struct homa_rcvbuf_args {
/** @start: First byte of buffer region. */
void *start;
/** @length: Total number of bytes available at @start. */
size_t length;
};
/* Meanings of the bits in Homa's flag word, which can be set using
* "sysctl /net/homa/flags".
*/
/**
* define HOMA_FLAG_DONT_THROTTLE - disable the output throttling mechanism:
* always send all packets immediately.
*/
#define HOMA_FLAG_DONT_THROTTLE 2
/**
* I/O control calls on Homa sockets. These are mapped into the
* SIOCPROTOPRIVATE range of 0x89e0 through 0x89ef.
*/
#define HOMAIOCABORT _IOWR(0x89, 0xe3, struct homa_abort_args)
#define HOMAIOCFREEZE _IO(0x89, 0xef)
#ifndef __STRIP__ /* See strip.py */
int homa_abort(int sockfd, uint64_t id, int error);
int homa_send(int sockfd, const void *message_buf,
size_t length, const struct sockaddr *dest_addr,
uint32_t addrlen, uint64_t *id, uint64_t completion_cookie);
int homa_sendv(int sockfd, const struct iovec *iov,
int iovcnt, const struct sockaddr *dest_addr,
uint32_t addrlen, uint64_t *id, uint64_t completion_cookie);
ssize_t homa_reply(int sockfd, const void *message_buf,
size_t length, const struct sockaddr *dest_addr,
uint32_t addrlen, uint64_t id);
ssize_t homa_replyv(int sockfd, const struct iovec *iov,
int iovcnt, const struct sockaddr *dest_addr,
uint32_t addrlen, uint64_t id);
#endif /* See strip.py */
#ifdef __cplusplus
}
#endif
#endif /* _UAPI_LINUX_HOMA_H */