112607Sodanrc@yahoo.com.br/**
212607Sodanrc@yahoo.com.br * Copyright (c) 2018 Inria
312607Sodanrc@yahoo.com.br * All rights reserved.
412607Sodanrc@yahoo.com.br *
512607Sodanrc@yahoo.com.br * Redistribution and use in source and binary forms, with or without
612607Sodanrc@yahoo.com.br * modification, are permitted provided that the following conditions are
712607Sodanrc@yahoo.com.br * met: redistributions of source code must retain the above copyright
812607Sodanrc@yahoo.com.br * notice, this list of conditions and the following disclaimer;
912607Sodanrc@yahoo.com.br * redistributions in binary form must reproduce the above copyright
1012607Sodanrc@yahoo.com.br * notice, this list of conditions and the following disclaimer in the
1112607Sodanrc@yahoo.com.br * documentation and/or other materials provided with the distribution;
1212607Sodanrc@yahoo.com.br * neither the name of the copyright holders nor the names of its
1312607Sodanrc@yahoo.com.br * contributors may be used to endorse or promote products derived from
1412607Sodanrc@yahoo.com.br * this software without specific prior written permission.
1512607Sodanrc@yahoo.com.br *
1612607Sodanrc@yahoo.com.br * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1712607Sodanrc@yahoo.com.br * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1812607Sodanrc@yahoo.com.br * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1912607Sodanrc@yahoo.com.br * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2012607Sodanrc@yahoo.com.br * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2112607Sodanrc@yahoo.com.br * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2212607Sodanrc@yahoo.com.br * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2312607Sodanrc@yahoo.com.br * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2412607Sodanrc@yahoo.com.br * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2512607Sodanrc@yahoo.com.br * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2612607Sodanrc@yahoo.com.br * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2712607Sodanrc@yahoo.com.br *
2812607Sodanrc@yahoo.com.br * Authors: Daniel Carvalho
2912607Sodanrc@yahoo.com.br */
3012607Sodanrc@yahoo.com.br
3112607Sodanrc@yahoo.com.br/**
3212607Sodanrc@yahoo.com.br * @file
3312607Sodanrc@yahoo.com.br * Declaration of a First In First Out replacement policy.
3412684Sodanrc@yahoo.com.br * The victim is chosen using the timestamp. The oldest entry is always chosen
3512607Sodanrc@yahoo.com.br * to be evicted, regardless of the amount of times it has been touched.
3612607Sodanrc@yahoo.com.br */
3712607Sodanrc@yahoo.com.br
3812607Sodanrc@yahoo.com.br#ifndef __MEM_CACHE_REPLACEMENT_POLICIES_FIFO_RP_HH__
3912607Sodanrc@yahoo.com.br#define __MEM_CACHE_REPLACEMENT_POLICIES_FIFO_RP_HH__
4012607Sodanrc@yahoo.com.br
4112727Snikos.nikoleris@arm.com#include "base/types.hh"
4212607Sodanrc@yahoo.com.br#include "mem/cache/replacement_policies/base.hh"
4312727Snikos.nikoleris@arm.com
4412727Snikos.nikoleris@arm.comstruct FIFORPParams;
4512607Sodanrc@yahoo.com.br
4612607Sodanrc@yahoo.com.brclass FIFORP : public BaseReplacementPolicy
4712607Sodanrc@yahoo.com.br{
4812685Sodanrc@yahoo.com.br  protected:
4912684Sodanrc@yahoo.com.br    /** FIFO-specific implementation of replacement data. */
5012684Sodanrc@yahoo.com.br    struct FIFOReplData : ReplacementData
5112684Sodanrc@yahoo.com.br    {
5212684Sodanrc@yahoo.com.br        /** Tick on which the entry was inserted. */
5312684Sodanrc@yahoo.com.br        Tick tickInserted;
5412684Sodanrc@yahoo.com.br
5512684Sodanrc@yahoo.com.br        /**
5612684Sodanrc@yahoo.com.br         * Default constructor. Invalidate data.
5712684Sodanrc@yahoo.com.br         */
5812684Sodanrc@yahoo.com.br        FIFOReplData() : tickInserted(0) {}
5912684Sodanrc@yahoo.com.br    };
6012684Sodanrc@yahoo.com.br
6112607Sodanrc@yahoo.com.br  public:
6212607Sodanrc@yahoo.com.br    /** Convenience typedef. */
6312607Sodanrc@yahoo.com.br    typedef FIFORPParams Params;
6412607Sodanrc@yahoo.com.br
6512607Sodanrc@yahoo.com.br    /**
6612607Sodanrc@yahoo.com.br     * Construct and initiliaze this replacement policy.
6712607Sodanrc@yahoo.com.br     */
6812607Sodanrc@yahoo.com.br    FIFORP(const Params *p);
6912607Sodanrc@yahoo.com.br
7012607Sodanrc@yahoo.com.br    /**
7112607Sodanrc@yahoo.com.br     * Destructor.
7212607Sodanrc@yahoo.com.br     */
7312607Sodanrc@yahoo.com.br    ~FIFORP() {}
7412607Sodanrc@yahoo.com.br
7512607Sodanrc@yahoo.com.br    /**
7612684Sodanrc@yahoo.com.br     * Invalidate replacement data to set it as the next probable victim.
7712684Sodanrc@yahoo.com.br     * Reset insertion tick to 0.
7812684Sodanrc@yahoo.com.br     *
7912684Sodanrc@yahoo.com.br     * @param replacement_data Replacement data to be invalidated.
8012684Sodanrc@yahoo.com.br     */
8112684Sodanrc@yahoo.com.br    void invalidate(const std::shared_ptr<ReplacementData>& replacement_data)
8212684Sodanrc@yahoo.com.br                                                              const override;
8312684Sodanrc@yahoo.com.br
8412684Sodanrc@yahoo.com.br    /**
8512684Sodanrc@yahoo.com.br     * Touch an entry to update its replacement data.
8612684Sodanrc@yahoo.com.br     * Does not modify the replacement data.
8712684Sodanrc@yahoo.com.br     *
8812684Sodanrc@yahoo.com.br     * @param replacement_data Replacement data to be touched.
8912684Sodanrc@yahoo.com.br     */
9012684Sodanrc@yahoo.com.br    void touch(const std::shared_ptr<ReplacementData>& replacement_data) const
9112684Sodanrc@yahoo.com.br                                                                     override;
9212684Sodanrc@yahoo.com.br
9312684Sodanrc@yahoo.com.br    /**
9412684Sodanrc@yahoo.com.br     * Reset replacement data. Used when an entry is inserted.
9512684Sodanrc@yahoo.com.br     * Sets its insertion tick.
9612684Sodanrc@yahoo.com.br     *
9712684Sodanrc@yahoo.com.br     * @param replacement_data Replacement data to be reset.
9812684Sodanrc@yahoo.com.br     */
9912684Sodanrc@yahoo.com.br    void reset(const std::shared_ptr<ReplacementData>& replacement_data) const
10012684Sodanrc@yahoo.com.br                                                                     override;
10112684Sodanrc@yahoo.com.br
10212684Sodanrc@yahoo.com.br    /**
10312607Sodanrc@yahoo.com.br     * Find replacement victim using insertion timestamps.
10412607Sodanrc@yahoo.com.br     *
10512607Sodanrc@yahoo.com.br     * @param cands Replacement candidates, selected by indexing policy.
10612684Sodanrc@yahoo.com.br     * @return Replacement entry to be replaced.
10712607Sodanrc@yahoo.com.br     */
10812684Sodanrc@yahoo.com.br    ReplaceableEntry* getVictim(const ReplacementCandidates& candidates) const
10912684Sodanrc@yahoo.com.br                                                                     override;
11012684Sodanrc@yahoo.com.br
11112684Sodanrc@yahoo.com.br    /**
11212684Sodanrc@yahoo.com.br     * Instantiate a replacement data entry.
11312684Sodanrc@yahoo.com.br     *
11412684Sodanrc@yahoo.com.br     * @return A shared pointer to the new replacement data.
11512684Sodanrc@yahoo.com.br     */
11612684Sodanrc@yahoo.com.br    std::shared_ptr<ReplacementData> instantiateEntry() override;
11712607Sodanrc@yahoo.com.br};
11812607Sodanrc@yahoo.com.br
11912607Sodanrc@yahoo.com.br#endif // __MEM_CACHE_REPLACEMENT_POLICIES_FIFO_RP_HH__
120