17008SN/A/*
27008SN/A * Copyright (c) 2007 Mark D. Hill and David A. Wood
310970Sdavid.hashe@amd.com * Copyright (c) 2013 Advanced Micro Devices, Inc
47008SN/A * All rights reserved.
57008SN/A *
67008SN/A * Redistribution and use in source and binary forms, with or without
77008SN/A * modification, are permitted provided that the following conditions are
87008SN/A * met: redistributions of source code must retain the above copyright
97008SN/A * notice, this list of conditions and the following disclaimer;
107008SN/A * redistributions in binary form must reproduce the above copyright
117008SN/A * notice, this list of conditions and the following disclaimer in the
127008SN/A * documentation and/or other materials provided with the distribution;
137008SN/A * neither the name of the copyright holders nor the names of its
147008SN/A * contributors may be used to endorse or promote products derived from
157008SN/A * this software without specific prior written permission.
167008SN/A *
177008SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
187008SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
197008SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
207008SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
217008SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
227008SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
237008SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
247008SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
257008SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
267008SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
277008SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
287008SN/A */
296145SN/A
3010441Snilay@cs.wisc.edu#ifndef __MEM_RUBY_STRUCTURES_PSEUDOLRUPOLICY_HH__
3110441Snilay@cs.wisc.edu#define __MEM_RUBY_STRUCTURES_PSEUDOLRUPOLICY_HH__
326145SN/A
3310301Snilay@cs.wisc.edu#include "mem/ruby/structures/AbstractReplacementPolicy.hh"
3410970Sdavid.hashe@amd.com#include "params/PseudoLRUReplacementPolicy.hh"
356145SN/A
366145SN/A/**
376145SN/A * Implementation of tree-based pseudo-LRU replacement
386145SN/A *
396145SN/A * Works for any associativity between 1 and 128.
406145SN/A *
416145SN/A * Also implements associativities that are not a power of 2 by
426145SN/A * ignoring paths that lead to a larger index (i.e. truncating the
436145SN/A * tree).  Note that when this occurs, the algorithm becomes less
446145SN/A * fair, as it will favor indicies in the larger (by index) half of
456145SN/A * the associative set. This is most unfair when the nearest power of
466145SN/A * 2 is one below the associativy, and most fair when it is one above.
476145SN/A */
486145SN/A
497039SN/Aclass PseudoLRUPolicy : public AbstractReplacementPolicy
507039SN/A{
517039SN/A  public:
5210970Sdavid.hashe@amd.com    typedef PseudoLRUReplacementPolicyParams Params;
5310970Sdavid.hashe@amd.com    PseudoLRUPolicy(const Params * p);
547039SN/A    ~PseudoLRUPolicy();
556145SN/A
5611061Snilay@cs.wisc.edu    void touch(int64_t set, int64_t way, Tick time);
5711061Snilay@cs.wisc.edu    int64_t getVictim(int64_t set) const;
586145SN/A
597039SN/A  private:
607039SN/A    unsigned int m_effective_assoc;    /** nearest (to ceiling) power of 2 */
617039SN/A    unsigned int m_num_levels;         /** number of levels in the tree */
6211061Snilay@cs.wisc.edu    uint64_t* m_trees;                   /** bit representation of the
637039SN/A                                        * trees, one for each set */
646145SN/A};
656145SN/A
6610441Snilay@cs.wisc.edu#endif // __MEM_RUBY_STRUCTURES_PSEUDOLRUPOLICY_HH__
67