QueueReadWritePolicy.ih
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
14 /** \file
15  \brief QueueReadWritePolicy internal header */
16 
17 #ifndef IH_SENF_senf_Socket_QueueReadWritePolicy_
18 #define IH_SENF_senf_Socket_QueueReadWritePolicy_ 1
19 
20 // Custom includes
21 
22 //-/////////////////////////////////////////////////////////////////////////////////////////////////
23 
24 namespace senf {
25 namespace detail {
26 
27 // older kernel includes don't define this
28 # if !defined(TP_STATUS_VLAN_VALID)
29 # define TP_STATUS_VLAN_VALID (1<<4)
30 # endif
31 
32  struct QueueInfo
33  {
34  static constexpr std::uint16_t NUM_SAMPLES = 9;
35 
36  unsigned char * map;
37  unsigned hdrlen;
38  unsigned frameSize;
39  unsigned reserveSize;
40 
41  struct Queue {
42  unsigned qlen; // number of blocks in queue
43  unsigned char * begin; // first buffer in queue
44  unsigned char * end; // after last buffer in queue
45  unsigned char * head; // next buffer in queue
46  // (after first buffer in queue still held by user-space)
47  unsigned char * tail; // last buffer in queue still held by user-space
48  bool idle; // set to true when the range from head -> tail is empty. needed
49  // to differentiate between empty and full head/tail range
50 
51  // we devide the ring buffer in NUM_SAMPLES slices and keep a pointer to tp_status
52  // of the first frame of each slide. In usageRx/Tx() we check how many of those samples report 'used by kernel'.
53  // This provides a rough estimate of ring buffer usage by the kernel
54  std::uint32_t * samples[NUM_SAMPLES];
55  };
56 
57  Queue rx;
58  Queue tx;
59 
60  struct TxStats {
61  unsigned sent;
62  unsigned wrongFormat;
63  unsigned dropped;
64  unsigned overrun;
65  unsigned red;
66  void dump(std::ostream & os) const;
67  };
68  struct RxStats {
69  unsigned received;
70  unsigned extMemory;
71  unsigned ignored;
72  unsigned noop;
73  unsigned red;
74  void dump(std::ostream & os) const;
75  };
76 
77  TxStats txStats;
78  RxStats rxStats;
79 
80  void inc(unsigned char * & ptr, Queue const & q);
81 
82  void init(unsigned rxqlen, unsigned txqlen);
83  unsigned usageRx() const;
84  unsigned usageTx() const;
85 
86  bool interfaceDead() const;
87  };
88 
89  struct QueuePolicyBase
90  : private FileHandleAccess
91  {
92  static detail::QueueInfo * qinfo(FileHandle & handle);
93  };
94 
95 }}
96 
97 //-/////////////////////////////////////////////////////////////////////////////////////////////////
98 #endif
99 
100 
101 // Local Variables:
102 // mode: c++
103 // fill-column: 100
104 // comment-column: 40
105 // c-file-style: "senf"
106 // indent-tabs-mode: nil
107 // ispell-local-dictionary: "american"
108 // compile-command: "scons -u test"
109 // End: