random_rp.hh revision 12684
12068SN/A/**
22068SN/A * Copyright (c) 2018 Inria
32188SN/A * All rights reserved.
42068SN/A *
52068SN/A * Redistribution and use in source and binary forms, with or without
62068SN/A * modification, are permitted provided that the following conditions are
72068SN/A * met: redistributions of source code must retain the above copyright
82068SN/A * notice, this list of conditions and the following disclaimer;
92068SN/A * redistributions in binary form must reproduce the above copyright
102068SN/A * notice, this list of conditions and the following disclaimer in the
112068SN/A * documentation and/or other materials provided with the distribution;
122068SN/A * neither the name of the copyright holders nor the names of its
132068SN/A * contributors may be used to endorse or promote products derived from
142068SN/A * this software without specific prior written permission.
152068SN/A *
162068SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172068SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182068SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192068SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202068SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212068SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222068SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232068SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242068SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252068SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262068SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272068SN/A *
282665Ssaidi@eecs.umich.edu * Authors: Daniel Carvalho
292665Ssaidi@eecs.umich.edu */
302068SN/A
312649Ssaidi@eecs.umich.edu/**
322649Ssaidi@eecs.umich.edu * @file
332649Ssaidi@eecs.umich.edu * Declaration of a random replacement policy.
342649Ssaidi@eecs.umich.edu * The victim is chosen at random, if there are no invalid entries.
352649Ssaidi@eecs.umich.edu */
362068SN/A
372068SN/A#ifndef __MEM_CACHE_REPLACEMENT_POLICIES_RANDOM_RP_HH__
382068SN/A#define __MEM_CACHE_REPLACEMENT_POLICIES_RANDOM_RP_HH__
392068SN/A
402068SN/A#include "mem/cache/replacement_policies/base.hh"
412068SN/A#include "params/RandomRP.hh"
422068SN/A
432068SN/Aclass RandomRP : public BaseReplacementPolicy
442075SN/A{
452075SN/A  protected:
462075SN/A    /** MRU-specific implementation of replacement data. */
472075SN/A    struct RandomReplData : ReplacementData
486076Sgblack@eecs.umich.edu    {
496076Sgblack@eecs.umich.edu        /**
502068SN/A         * Flag informing if the replacement data is valid or not.
512068SN/A         * Invalid entries are prioritized to be evicted.
522068SN/A         */
532075SN/A        bool valid;
542075SN/A
552068SN/A        /**
562068SN/A         * Default constructor. Invalidate data.
572075SN/A         */
582075SN/A        RandomReplData() : valid(false) {}
592068SN/A    };
602068SN/A
612068SN/A  public:
622075SN/A    /** Convenience typedef. */
632075SN/A    typedef RandomRPParams Params;
642075SN/A
652075SN/A    /**
662075SN/A     * Construct and initiliaze this replacement policy.
672075SN/A     */
682075SN/A    RandomRP(const Params *p);
692068SN/A
702068SN/A    /**
712068SN/A     * Destructor.
722075SN/A     */
732068SN/A    ~RandomRP() {}
742069SN/A
752068SN/A    /**
762068SN/A     * Invalidate replacement data to set it as the next probable victim.
774027Sstever@eecs.umich.edu     * Prioritize replacement data for victimization.
784027Sstever@eecs.umich.edu     *
794027Sstever@eecs.umich.edu     * @param replacement_data Replacement data to be invalidated.
806076Sgblack@eecs.umich.edu     */
812075SN/A    void invalidate(const std::shared_ptr<ReplacementData>& replacement_data)
822068SN/A                                                               const override;
832069SN/A
842068SN/A    /**
852068SN/A     * Touch an entry to update its replacement data.
862068SN/A     * Does not do anything.
872068SN/A     *
882068SN/A     * @param replacement_data Replacement data to be touched.
892068SN/A     */
902068SN/A    void touch(const std::shared_ptr<ReplacementData>& replacement_data) const
912068SN/A                                                                     override;
924027Sstever@eecs.umich.edu
934027Sstever@eecs.umich.edu    /**
944027Sstever@eecs.umich.edu     * Reset replacement data. Used when an entry is inserted.
954027Sstever@eecs.umich.edu     * Unprioritize replacement data for victimization.
964027Sstever@eecs.umich.edu     *
974027Sstever@eecs.umich.edu     * @param replacement_data Replacement data to be reset.
986076Sgblack@eecs.umich.edu     */
992068SN/A    void reset(const std::shared_ptr<ReplacementData>& replacement_data) const
1002068SN/A                                                                     override;
1012068SN/A
1022068SN/A    /**
1037799Sgblack@eecs.umich.edu     * Find replacement victim at random.
1042068SN/A     *
1052068SN/A     * @param candidates Replacement candidates, selected by indexing policy.
1062068SN/A     * @return Replacement entry to be replaced.
1076227Snate@binkert.org     */
1082068SN/A    ReplaceableEntry* getVictim(const ReplacementCandidates& candidates) const
1092068SN/A                                                                     override;
1102068SN/A
1112147SN/A    /**
1122068SN/A     * Instantiate a replacement data entry.
1132068SN/A     *
1142068SN/A     * @return A shared pointer to the new replacement data.
1152068SN/A     */
1162068SN/A    std::shared_ptr<ReplacementData> instantiateEntry() override;
1172068SN/A};
1182068SN/A
1192068SN/A#endif // __MEM_CACHE_REPLACEMENT_POLICIES_RANDOM_RP_HH__
1202068SN/A