SolarCapture C Bindings
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups
ext_packet.h
Go to the documentation of this file.
1 
8 #ifndef __SOLAR_CAPTURE_EXT_PACKET_H__
9 #define __SOLAR_CAPTURE_EXT_PACKET_H__
10 
11 #include <stdlib.h>
12 #include <stdint.h>
13 #include <sys/uio.h>
14 
15 
16 #if defined(__x86_64__) || defined(__i386__)
17 # define SC_CACHE_LINE_SIZE 64
18 #elif defined(__PPC__)
19 # define SC_CACHE_LINE_SIZE 128
20 #else
21 # error "Need to define SC_CACHE_LINE_SIZE"
22 #endif
23 
29 #define SC_MEMBER_OFFSET(c_type, mbr_name) \
30  ((uint32_t) (uintptr_t)(&((c_type*)0)->mbr_name))
31 
37 #define SC_MEMBER_SIZE(c_type, mbr_name) \
38  (sizeof(((c_type*)0)->mbr_name))
39 
40 
56 struct sc_packet {
57  uint64_t ts_sec;
58  uint32_t ts_nsec;
60  uint16_t flags;
61  uint16_t frame_len;
62  uint8_t frags_n;
63  uint8_t iovlen;
65  uint16_t reserved1;
66  uint32_t reserved2;
67 
68  struct iovec* iov;
69  struct sc_packet* next;
70  struct sc_packet* frags;
72  uintptr_t* metadata;
73 };
74 
79 #define SC_FRAME_LEN_LARGE UINT16_MAX
80 
85 #define SC_CSUM_ERROR (1 << 0)
86 
91 #define SC_CRC_ERROR (1 << 1)
92 
97 #define SC_TRUNCATED (1 << 2)
98 
103 #define SC_MCAST_MISMATCH (1 << 3)
104 
109 #define SC_UCAST_MISMATCH (1 << 4)
110 
111 
116 #define SC_RESERVED_3 (1 << 13)
117 #define SC_RESERVED_2 (1 << 14)
118 #define SC_RESERVED_1 (1 << 15)
119 
125 static inline int sc_packet_bytes(struct sc_packet* p)
126 {
127  int i, bytes = 0;
128  for( i = 0; i < p->iovlen; ++i )
129  bytes += p->iov[i].iov_len;
130  return bytes;
131 }
132 
133 
141 static inline struct sc_packet* sc_packet_frags_tail(struct sc_packet* p)
142 {
143  return (struct sc_packet*)
144  ((char*) p->frags_tail - SC_MEMBER_OFFSET(struct sc_packet, next));
145 }
146 
153 static inline void sc_packet_prefetch_r(struct sc_packet* p)
154 {
155  __builtin_prefetch(p, 0, 2);
156  __builtin_prefetch((char *) p + SC_CACHE_LINE_SIZE, 0, 2);
157 }
158 
165 static inline void sc_packet_prefetch_rw(struct sc_packet* p)
166 {
167  __builtin_prefetch(p, 1, 2);
168  __builtin_prefetch((char *) p + SC_CACHE_LINE_SIZE, 1, 2);
169 }
170 
175 static inline struct timespec sc_packet_timespec(const struct sc_packet* p)
176 {
177  struct timespec ts = { (time_t)p->ts_sec, p->ts_nsec };
178  return ts;
179 }
180 
181 
182 #endif /* __SOLAR_CAPTURE_EXT_PACKET_H__ */
183 
static void sc_packet_prefetch_r(struct sc_packet *p)
Prefetch a packet for reading.
Definition: ext_packet.h:153
uint16_t flags
Definition: ext_packet.h:60
uint8_t frags_n
Definition: ext_packet.h:62
uintptr_t * metadata
Definition: ext_packet.h:72
struct iovec * iov
Definition: ext_packet.h:68
uint16_t frame_len
Definition: ext_packet.h:61
static struct timespec sc_packet_timespec(const struct sc_packet *p)
Return the timestamp of the packet in timespec format.
Definition: ext_packet.h:175
uint64_t ts_sec
Definition: ext_packet.h:57
Representation of a packet.
Definition: ext_packet.h:56
struct sc_packet * frags
Definition: ext_packet.h:70
struct sc_packet ** frags_tail
Definition: ext_packet.h:71
static int sc_packet_bytes(struct sc_packet *p)
Return the size of the packet data in bytes.
Definition: ext_packet.h:125
uint8_t iovlen
Definition: ext_packet.h:63
#define SC_MEMBER_OFFSET(c_type, mbr_name)
Calculate memory offset of a field within a struct.
Definition: ext_packet.h:29
uint32_t ts_nsec
Definition: ext_packet.h:58
struct sc_packet * next
Definition: ext_packet.h:69
static struct sc_packet * sc_packet_frags_tail(struct sc_packet *p)
Return a packet's last fragment.
Definition: ext_packet.h:141
static void sc_packet_prefetch_rw(struct sc_packet *p)
Prefetch a packet for reading and writing.
Definition: ext_packet.h:165