fifo_rp.hh revision 12685:dcf85db6ec5c
12929Sktlim@umich.edu/**
22929Sktlim@umich.edu * Copyright (c) 2018 Inria
32932Sktlim@umich.edu * All rights reserved.
42929Sktlim@umich.edu *
52929Sktlim@umich.edu * Redistribution and use in source and binary forms, with or without
62929Sktlim@umich.edu * modification, are permitted provided that the following conditions are
72929Sktlim@umich.edu * met: redistributions of source code must retain the above copyright
82929Sktlim@umich.edu * notice, this list of conditions and the following disclaimer;
92929Sktlim@umich.edu * redistributions in binary form must reproduce the above copyright
102929Sktlim@umich.edu * notice, this list of conditions and the following disclaimer in the
112929Sktlim@umich.edu * documentation and/or other materials provided with the distribution;
122929Sktlim@umich.edu * neither the name of the copyright holders nor the names of its
132929Sktlim@umich.edu * contributors may be used to endorse or promote products derived from
142929Sktlim@umich.edu * this software without specific prior written permission.
152929Sktlim@umich.edu *
162929Sktlim@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172929Sktlim@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182929Sktlim@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192929Sktlim@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202929Sktlim@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212929Sktlim@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222929Sktlim@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232929Sktlim@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242929Sktlim@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252929Sktlim@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262929Sktlim@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272929Sktlim@umich.edu *
282932Sktlim@umich.edu * Authors: Daniel Carvalho
292932Sktlim@umich.edu */
302932Sktlim@umich.edu
312929Sktlim@umich.edu/**
326007Ssteve.reinhardt@amd.com * @file
337735SAli.Saidi@ARM.com * Declaration of a First In First Out replacement policy.
342929Sktlim@umich.edu * The victim is chosen using the timestamp. The oldest entry is always chosen
352929Sktlim@umich.edu * to be evicted, regardless of the amount of times it has been touched.
362929Sktlim@umich.edu */
372929Sktlim@umich.edu
382929Sktlim@umich.edu#ifndef __MEM_CACHE_REPLACEMENT_POLICIES_FIFO_RP_HH__
392929Sktlim@umich.edu#define __MEM_CACHE_REPLACEMENT_POLICIES_FIFO_RP_HH__
402929Sktlim@umich.edu
412929Sktlim@umich.edu#include "mem/cache/replacement_policies/base.hh"
422929Sktlim@umich.edu#include "params/FIFORP.hh"
432929Sktlim@umich.edu
442929Sktlim@umich.educlass FIFORP : public BaseReplacementPolicy
452929Sktlim@umich.edu{
462929Sktlim@umich.edu  protected:
476007Ssteve.reinhardt@amd.com    /** FIFO-specific implementation of replacement data. */
486007Ssteve.reinhardt@amd.com    struct FIFOReplData : ReplacementData
496007Ssteve.reinhardt@amd.com    {
506007Ssteve.reinhardt@amd.com        /** Tick on which the entry was inserted. */
516007Ssteve.reinhardt@amd.com        Tick tickInserted;
526007Ssteve.reinhardt@amd.com
536007Ssteve.reinhardt@amd.com        /**
546007Ssteve.reinhardt@amd.com         * Default constructor. Invalidate data.
556007Ssteve.reinhardt@amd.com         */
566007Ssteve.reinhardt@amd.com        FIFOReplData() : tickInserted(0) {}
576007Ssteve.reinhardt@amd.com    };
586007Ssteve.reinhardt@amd.com
596007Ssteve.reinhardt@amd.com  public:
606007Ssteve.reinhardt@amd.com    /** Convenience typedef. */
616007Ssteve.reinhardt@amd.com    typedef FIFORPParams Params;
626007Ssteve.reinhardt@amd.com
636007Ssteve.reinhardt@amd.com    /**
646007Ssteve.reinhardt@amd.com     * Construct and initiliaze this replacement policy.
656007Ssteve.reinhardt@amd.com     */
666007Ssteve.reinhardt@amd.com    FIFORP(const Params *p);
676007Ssteve.reinhardt@amd.com
686007Ssteve.reinhardt@amd.com    /**
696007Ssteve.reinhardt@amd.com     * Destructor.
706007Ssteve.reinhardt@amd.com     */
716007Ssteve.reinhardt@amd.com    ~FIFORP() {}
726007Ssteve.reinhardt@amd.com
736007Ssteve.reinhardt@amd.com    /**
746007Ssteve.reinhardt@amd.com     * Invalidate replacement data to set it as the next probable victim.
756007Ssteve.reinhardt@amd.com     * Reset insertion tick to 0.
762929Sktlim@umich.edu     *
772929Sktlim@umich.edu     * @param replacement_data Replacement data to be invalidated.
782929Sktlim@umich.edu     */
796007Ssteve.reinhardt@amd.com    void invalidate(const std::shared_ptr<ReplacementData>& replacement_data)
806007Ssteve.reinhardt@amd.com                                                              const override;
816007Ssteve.reinhardt@amd.com
826007Ssteve.reinhardt@amd.com    /**
836007Ssteve.reinhardt@amd.com     * Touch an entry to update its replacement data.
846007Ssteve.reinhardt@amd.com     * Does not modify the replacement data.
852929Sktlim@umich.edu     *
862929Sktlim@umich.edu     * @param replacement_data Replacement data to be touched.
872929Sktlim@umich.edu     */
882929Sktlim@umich.edu    void touch(const std::shared_ptr<ReplacementData>& replacement_data) const
892929Sktlim@umich.edu                                                                     override;
906011Ssteve.reinhardt@amd.com
916007Ssteve.reinhardt@amd.com    /**
926007Ssteve.reinhardt@amd.com     * Reset replacement data. Used when an entry is inserted.
936007Ssteve.reinhardt@amd.com     * Sets its insertion tick.
946007Ssteve.reinhardt@amd.com     *
956007Ssteve.reinhardt@amd.com     * @param replacement_data Replacement data to be reset.
966007Ssteve.reinhardt@amd.com     */
976007Ssteve.reinhardt@amd.com    void reset(const std::shared_ptr<ReplacementData>& replacement_data) const
986007Ssteve.reinhardt@amd.com                                                                     override;
996007Ssteve.reinhardt@amd.com
1006007Ssteve.reinhardt@amd.com    /**
1016007Ssteve.reinhardt@amd.com     * Find replacement victim using insertion timestamps.
1026007Ssteve.reinhardt@amd.com     *
1036007Ssteve.reinhardt@amd.com     * @param cands Replacement candidates, selected by indexing policy.
1046007Ssteve.reinhardt@amd.com     * @return Replacement entry to be replaced.
1057735SAli.Saidi@ARM.com     */
1066011Ssteve.reinhardt@amd.com    ReplaceableEntry* getVictim(const ReplacementCandidates& candidates) const
1076007Ssteve.reinhardt@amd.com                                                                     override;
1086007Ssteve.reinhardt@amd.com
1096007Ssteve.reinhardt@amd.com    /**
1106007Ssteve.reinhardt@amd.com     * Instantiate a replacement data entry.
1117735SAli.Saidi@ARM.com     *
1127735SAli.Saidi@ARM.com     * @return A shared pointer to the new replacement data.
1137735SAli.Saidi@ARM.com     */
1147735SAli.Saidi@ARM.com    std::shared_ptr<ReplacementData> instantiateEntry() override;
1157735SAli.Saidi@ARM.com};
1167735SAli.Saidi@ARM.com
1177735SAli.Saidi@ARM.com#endif // __MEM_CACHE_REPLACEMENT_POLICIES_FIFO_RP_HH__
1187735SAli.Saidi@ARM.com