112600Sodanrc@yahoo.com.br/**
212600Sodanrc@yahoo.com.br * Copyright (c) 2018 Inria
312600Sodanrc@yahoo.com.br * All rights reserved.
412600Sodanrc@yahoo.com.br *
512600Sodanrc@yahoo.com.br * Redistribution and use in source and binary forms, with or without
612600Sodanrc@yahoo.com.br * modification, are permitted provided that the following conditions are
712600Sodanrc@yahoo.com.br * met: redistributions of source code must retain the above copyright
812600Sodanrc@yahoo.com.br * notice, this list of conditions and the following disclaimer;
912600Sodanrc@yahoo.com.br * redistributions in binary form must reproduce the above copyright
1012600Sodanrc@yahoo.com.br * notice, this list of conditions and the following disclaimer in the
1112600Sodanrc@yahoo.com.br * documentation and/or other materials provided with the distribution;
1212600Sodanrc@yahoo.com.br * neither the name of the copyright holders nor the names of its
1312600Sodanrc@yahoo.com.br * contributors may be used to endorse or promote products derived from
1412600Sodanrc@yahoo.com.br * this software without specific prior written permission.
1512600Sodanrc@yahoo.com.br *
1612600Sodanrc@yahoo.com.br * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1712600Sodanrc@yahoo.com.br * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1812600Sodanrc@yahoo.com.br * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1912600Sodanrc@yahoo.com.br * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2012600Sodanrc@yahoo.com.br * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2112600Sodanrc@yahoo.com.br * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2212600Sodanrc@yahoo.com.br * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2312600Sodanrc@yahoo.com.br * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2412600Sodanrc@yahoo.com.br * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2512600Sodanrc@yahoo.com.br * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2612600Sodanrc@yahoo.com.br * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2712600Sodanrc@yahoo.com.br *
2812600Sodanrc@yahoo.com.br * Authors: Daniel Carvalho
2912600Sodanrc@yahoo.com.br */
3012600Sodanrc@yahoo.com.br
3112600Sodanrc@yahoo.com.br/**
3212600Sodanrc@yahoo.com.br * @file
3312600Sodanrc@yahoo.com.br * Declaration of a random replacement policy.
3412600Sodanrc@yahoo.com.br * The victim is chosen at random, if there are no invalid entries.
3512600Sodanrc@yahoo.com.br */
3612600Sodanrc@yahoo.com.br
3712600Sodanrc@yahoo.com.br#ifndef __MEM_CACHE_REPLACEMENT_POLICIES_RANDOM_RP_HH__
3812600Sodanrc@yahoo.com.br#define __MEM_CACHE_REPLACEMENT_POLICIES_RANDOM_RP_HH__
3912600Sodanrc@yahoo.com.br
4012600Sodanrc@yahoo.com.br#include "mem/cache/replacement_policies/base.hh"
4112727Snikos.nikoleris@arm.com
4212727Snikos.nikoleris@arm.comstruct RandomRPParams;
4312600Sodanrc@yahoo.com.br
4412600Sodanrc@yahoo.com.brclass RandomRP : public BaseReplacementPolicy
4512600Sodanrc@yahoo.com.br{
4612684Sodanrc@yahoo.com.br  protected:
4712684Sodanrc@yahoo.com.br    /** MRU-specific implementation of replacement data. */
4812684Sodanrc@yahoo.com.br    struct RandomReplData : ReplacementData
4912684Sodanrc@yahoo.com.br    {
5012684Sodanrc@yahoo.com.br        /**
5112684Sodanrc@yahoo.com.br         * Flag informing if the replacement data is valid or not.
5212684Sodanrc@yahoo.com.br         * Invalid entries are prioritized to be evicted.
5312684Sodanrc@yahoo.com.br         */
5412684Sodanrc@yahoo.com.br        bool valid;
5512684Sodanrc@yahoo.com.br
5612684Sodanrc@yahoo.com.br        /**
5712684Sodanrc@yahoo.com.br         * Default constructor. Invalidate data.
5812684Sodanrc@yahoo.com.br         */
5912684Sodanrc@yahoo.com.br        RandomReplData() : valid(false) {}
6012684Sodanrc@yahoo.com.br    };
6112684Sodanrc@yahoo.com.br
6212600Sodanrc@yahoo.com.br  public:
6312600Sodanrc@yahoo.com.br    /** Convenience typedef. */
6412600Sodanrc@yahoo.com.br    typedef RandomRPParams Params;
6512600Sodanrc@yahoo.com.br
6612600Sodanrc@yahoo.com.br    /**
6712600Sodanrc@yahoo.com.br     * Construct and initiliaze this replacement policy.
6812600Sodanrc@yahoo.com.br     */
6912600Sodanrc@yahoo.com.br    RandomRP(const Params *p);
7012600Sodanrc@yahoo.com.br
7112600Sodanrc@yahoo.com.br    /**
7212600Sodanrc@yahoo.com.br     * Destructor.
7312600Sodanrc@yahoo.com.br     */
7412600Sodanrc@yahoo.com.br    ~RandomRP() {}
7512600Sodanrc@yahoo.com.br
7612600Sodanrc@yahoo.com.br    /**
7712684Sodanrc@yahoo.com.br     * Invalidate replacement data to set it as the next probable victim.
7812684Sodanrc@yahoo.com.br     * Prioritize replacement data for victimization.
7912684Sodanrc@yahoo.com.br     *
8012684Sodanrc@yahoo.com.br     * @param replacement_data Replacement data to be invalidated.
8112684Sodanrc@yahoo.com.br     */
8212684Sodanrc@yahoo.com.br    void invalidate(const std::shared_ptr<ReplacementData>& replacement_data)
8312684Sodanrc@yahoo.com.br                                                               const override;
8412684Sodanrc@yahoo.com.br
8512684Sodanrc@yahoo.com.br    /**
8612684Sodanrc@yahoo.com.br     * Touch an entry to update its replacement data.
8712684Sodanrc@yahoo.com.br     * Does not do anything.
8812684Sodanrc@yahoo.com.br     *
8912684Sodanrc@yahoo.com.br     * @param replacement_data Replacement data to be touched.
9012684Sodanrc@yahoo.com.br     */
9112684Sodanrc@yahoo.com.br    void touch(const std::shared_ptr<ReplacementData>& replacement_data) const
9212684Sodanrc@yahoo.com.br                                                                     override;
9312684Sodanrc@yahoo.com.br
9412684Sodanrc@yahoo.com.br    /**
9512684Sodanrc@yahoo.com.br     * Reset replacement data. Used when an entry is inserted.
9612684Sodanrc@yahoo.com.br     * Unprioritize replacement data for victimization.
9712684Sodanrc@yahoo.com.br     *
9812684Sodanrc@yahoo.com.br     * @param replacement_data Replacement data to be reset.
9912684Sodanrc@yahoo.com.br     */
10012684Sodanrc@yahoo.com.br    void reset(const std::shared_ptr<ReplacementData>& replacement_data) const
10112684Sodanrc@yahoo.com.br                                                                     override;
10212684Sodanrc@yahoo.com.br
10312684Sodanrc@yahoo.com.br    /**
10412600Sodanrc@yahoo.com.br     * Find replacement victim at random.
10512684Sodanrc@yahoo.com.br     *
10612600Sodanrc@yahoo.com.br     * @param candidates Replacement candidates, selected by indexing policy.
10712684Sodanrc@yahoo.com.br     * @return Replacement entry to be replaced.
10812600Sodanrc@yahoo.com.br     */
10912684Sodanrc@yahoo.com.br    ReplaceableEntry* getVictim(const ReplacementCandidates& candidates) const
11012684Sodanrc@yahoo.com.br                                                                     override;
11112684Sodanrc@yahoo.com.br
11212684Sodanrc@yahoo.com.br    /**
11312684Sodanrc@yahoo.com.br     * Instantiate a replacement data entry.
11412684Sodanrc@yahoo.com.br     *
11512684Sodanrc@yahoo.com.br     * @return A shared pointer to the new replacement data.
11612684Sodanrc@yahoo.com.br     */
11712684Sodanrc@yahoo.com.br    std::shared_ptr<ReplacementData> instantiateEntry() override;
11812600Sodanrc@yahoo.com.br};
11912600Sodanrc@yahoo.com.br
12012600Sodanrc@yahoo.com.br#endif // __MEM_CACHE_REPLACEMENT_POLICIES_RANDOM_RP_HH__
121