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
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
15 \brief QueueReadWritePolicy internal header */
17 #ifndef IH_SENF_senf_Socket_QueueReadWritePolicy_
18 #define IH_SENF_senf_Socket_QueueReadWritePolicy_ 1
22 //-/////////////////////////////////////////////////////////////////////////////////////////////////
27 // older kernel includes don't define this
28 # if !defined(TP_STATUS_VLAN_VALID)
29 # define TP_STATUS_VLAN_VALID (1<<4)
34 static constexpr std::uint16_t NUM_SAMPLES = 9;
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
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];
66 void dump(std::ostream & os) const;
74 void dump(std::ostream & os) const;
80 void inc(unsigned char * & ptr, Queue const & q);
82 void init(unsigned rxqlen, unsigned txqlen);
83 unsigned usageRx() const;
84 unsigned usageTx() const;
86 bool interfaceDead() const;
89 struct QueuePolicyBase
90 : private FileHandleAccess
92 static detail::QueueInfo * qinfo(FileHandle & handle);
97 //-/////////////////////////////////////////////////////////////////////////////////////////////////
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"