gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
base.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 Inria
3  * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met: redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer;
10  * redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution;
13  * neither the name of the copyright holders nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  *
29  * Authors: Daniel Carvalho
30  */
31 
32 #ifndef __BASE_FILTERS_BASE_HH__
33 #define __BASE_FILTERS_BASE_HH__
34 
35 #include <vector>
36 
37 #include "base/intmath.hh"
38 #include "base/sat_counter.hh"
39 #include "base/types.hh"
40 #include "params/BloomFilterBase.hh"
41 #include "sim/sim_object.hh"
42 
43 namespace BloomFilter {
44 
45 class Base : public SimObject
46 {
47  protected:
49  const unsigned offsetBits;
50 
53 
55  const int sizeBits;
56 
58  const int setThreshold;
59 
60  public:
64  Base(const BloomFilterBaseParams* p)
65  : SimObject(p), offsetBits(p->offset_bits),
66  filter(p->size, SatCounter(p->num_bits)),
67  sizeBits(floorLog2(p->size)), setThreshold(p->threshold)
68  {
69  clear();
70  }
71  virtual ~Base() {};
72 
76  virtual void clear()
77  {
78  for (auto& entry : filter) {
79  entry.reset();
80  }
81  }
82 
89  virtual void
90  merge(const Base* other)
91  {
92  assert(filter.size() == other->filter.size());
93  for (int i = 0; i < filter.size(); ++i){
94  filter[i] += other->filter[i];
95  }
96  }
97 
104  virtual void set(Addr addr) = 0;
105 
113  virtual void unset(Addr addr) {};
114 
122  virtual bool
123  isSet(Addr addr) const
124  {
125  return getCount(addr) >= setThreshold;
126  }
127 
134  virtual int getCount(Addr addr) const { return 0; }
135 
141  virtual int getTotalCount() const
142  {
143  int count = 0;
144  for (const auto& entry : filter) {
145  count += entry;
146  }
147  return count;
148  }
149 };
150 
151 } // namespace BloomFilter
152 
153 #endif // __BASE_FILTERS_BASE_HH__
count
Definition: misc.hh:705
Bitfield< 7 > i
virtual void merge(const Base *other)
Merges the contents of both filters into this&#39; (Bloom Filter union).
Definition: base.hh:90
Base(const BloomFilterBaseParams *p)
Create and clear the filter.
Definition: base.hh:64
ip6_addr_t addr
Definition: inet.hh:335
virtual bool isSet(Addr addr) const
Check if the corresponding filter entries of an address should be considered as set.
Definition: base.hh:123
virtual void unset(Addr addr)
Perform the filter specific function to clear the corresponding entries (can be multiple) of an addre...
Definition: base.hh:113
std::vector< SatCounter > filter
The filter itself.
Definition: base.hh:52
virtual ~Base()
Definition: base.hh:71
const int sizeBits
Number of bits needed to represent the size of the filter.
Definition: base.hh:55
Implements an n bit saturating counter and provides methods to increment, decrement, and read it.
Definition: sat_counter.hh:57
const unsigned offsetBits
Number of LSB bits to ignore from the the addresses.
Definition: base.hh:49
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,16,32,64}_t.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
virtual void clear()
Clear the filter by resetting all values.
Definition: base.hh:76
int floorLog2(unsigned x)
Definition: intmath.hh:61
virtual int getCount(Addr addr) const
Get the value stored in the corresponding filter entry of an address.
Definition: base.hh:134
const int setThreshold
Threshold at which a filter entry starts being considered as set.
Definition: base.hh:58
Bitfield< 0 > p
Abstract superclass for simulation objects.
Definition: sim_object.hh:96
virtual int getTotalCount() const
Get the total value stored in the filter entries.
Definition: base.hh:141

Generated on Fri Feb 28 2020 16:26:58 for gem5 by doxygen 1.8.13